mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
Any work that can take noticeable time now runs under the UI's status line: a Reporter's Status with a label message, or a LoggedCmd step. The UI: - status lines are a stack: a Status or LoggedCmd inside another shows its own line, then the outer one is drawn again, where before it ended the outer one for good - a message (Info, Warn, Note, Say, data on Stdout/Stderr) clears the line, prints and draws it again below; an unended line holds it - a question (Ask, Confirm, Answer, Secret), the picker and ui.Terminal hold it until they're done - no status line starts once the run is interrupted, as nothing would clear it - the run log's path is read without the log's lock, as the status line reads it under outMu Covered, by site and label: - finder.target: finding_vm; Lima's limactl --version: checking_backend - bringUp's checks (seeds, instance, recordFolder, hostChecks, ssh, requirements) and a running VM's go-on (proxy, pins, mount check): checking_vm; startOnce after the agent: starting; the self-check's probes: checking_network; pinHostKeys: reading_host_keys - setUpVM (sync, ssh config, links, clone seed): setting_up_vm; each devcontainer command: running_script; makeMachine: creating; buildOnce: checking_image; paste's count and rm: reading_pasted - volumeOf's lookup (diskutil), for launch, adopt, move, ls and rm: looking_up_volume - vm.ListAll (devvm ls): reading_vms; devvm doctor's checks: doctor_checking - devvm agent import: agent_import_reading (walk, links, opencode), agent_store_saving (copy, marketplace git checks, tmutil); devvm agent save: agent_save_reading, agent_save_comparing, agent_store_saving - devvm stop (from its pins check on): checking_vm; a delete, an orphan's teardown and Lima's DeleteImage: deleting; devvm git-protect and clone on/off's .git work (leftBehind, mountFolder, unmountFolder): git_protecting; git-protect's re-read: finding_vm - devvm clone add: clone_reading, clone_adding; clone fetch: clone_fetching; planClone: clone_planning; the clone check before rm or a remake: clone_checking; history export and import: history_exporting, history_importing; a remake's home: saving_home, restoring_home - devvm upgrade's install: upgrade_installing; the shared tools' step back and .NET's downloads: resolving_tools; gc's caches: reading_space; the retention settings (daily and in gc): retaining Work that takes the terminal stays off: the shell, ssh-add's passphrase (checkAgent, Agent.Ensure, reloadAgent) and an agent's login. Tests and guard: - msg.Fake: OnStatus and Showing; its LoggedCmd shows its step - backendtest.Fake: OnCall - TestLaunchStatusLines: every backend call of a new, running and stopped VM's launch runs under a status line but the shell's and Running's (pid files) - TestSSHAddOffStatusLine: ssh-add, on the user's agent or devvm's, never runs under one; chflagsCalls fails a .git lock or unlock with none - the structure test's status-lines rule (statusSites, statusFree) - TestStatusLinesNest, TestMessagesClearTheStatusLine, TestQuestionsHoldTheStatusLine, TestSecretAndPickerHoldTheStatusLine, TestTerminalHoldsTheStatusLine, TestNoStatusLineOnceInterrupted, TestFakeStatus, TestAgentImportStatus, TestAgentSaveStatus, TestDoctorReport, TestProblems, TestList, TestListLooksUpVolumesOnce, TestVolumeOfCache, TestWithSDKDownloads, TestRetainStatus, TestSetCloneOn, TestTeardownLeavesNothing The rule is written in the cli skill (rule 14, checklist, review), the codebase-standards skill (Show what devvm waits for, its checklist line and rules.md's row), Contributing's CLI page (Status lines), its tests and structure pages, and the troubleshooting page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
134 lines
4.3 KiB
Go
134 lines
4.3 KiB
Go
package msg
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"os/exec"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// A zero Fake is quiet: it prints nothing, has no terminal, answers no
|
|
// and "", drops what's written, runs a logged command as it is, keeps no
|
|
// cleanup and isn't interrupted.
|
|
func TestFakeQuiet(t *testing.T) {
|
|
var f Fake
|
|
m := NoVM("/x")
|
|
f.Info(m)
|
|
f.Say(m)
|
|
f.Note(m)
|
|
f.Warn(m)
|
|
f.LogNote()
|
|
f.Status(m)()
|
|
f.AddCleanup(func(context.Context) { t.Error("kept") })()
|
|
q := m.AnsweredBy("--force")
|
|
for _, err := range []error{second(f.Ask(q)), second(f.Confirm(q)), second(f.Answer(q))} {
|
|
if r, ok := errors.AsType[*Refusal](err); !ok || r.Msg.Names() != "no_input answer=--force" {
|
|
t.Errorf("not refused: %v", err)
|
|
}
|
|
}
|
|
if f.CanPick() || f.Interrupted() {
|
|
t.Error("a terminal, the picker or an interrupt")
|
|
}
|
|
for _, w := range []io.Writer{f.Stdout(), f.Stderr(), f.LogWriter()} {
|
|
if w != io.Discard {
|
|
t.Errorf("writer %v", w)
|
|
}
|
|
}
|
|
ctx := t.Context()
|
|
if f.WithSteps(ctx, 3) != ctx {
|
|
t.Error("steps counted")
|
|
}
|
|
if err := f.LoggedCmd(ctx, m, exec.CommandContext(ctx, "true")); err != nil {
|
|
t.Errorf("LoggedCmd: %v", err)
|
|
}
|
|
}
|
|
|
|
// A Fake's fields get what its methods are given, and stand for the
|
|
// terminal, the writers and an interrupt.
|
|
func TestFakeRecords(t *testing.T) {
|
|
var kinds, all Recorder
|
|
var asked []string
|
|
var out, errs, log bytes.Buffer
|
|
var cleanups int
|
|
f := &Fake{
|
|
OnInfo: kinds.Add, OnSay: kinds.Add, OnNote: kinds.Add, OnWarn: kinds.Add, OnAny: all.Add,
|
|
OnAsk: func(m M) bool { asked = append(asked, "ask "+m.Names()); return true },
|
|
OnConfirm: func(m M) bool { asked = append(asked, "confirm "+m.Names()); return true },
|
|
OnAnswer: func(m M) string { asked = append(asked, "answer "+m.Names()); return "4" },
|
|
OnCleanup: func(func(context.Context)) func() { cleanups++; return func() {} },
|
|
Terminal: true, Picks: true, Interrupt: true,
|
|
Out: &out, Err: &errs, Log: &log,
|
|
}
|
|
answered := func(v any, err error) bool { return err == nil && (v == true || v == "4") }
|
|
f.Info(NoVM("/i"))
|
|
f.Say(NoVM("/s"))
|
|
f.Note(NoVM("/n"))
|
|
f.Warn(NoVM("/w"))
|
|
want := []string{"no_vm dir=/i", "no_vm dir=/s", "no_vm dir=/n", "no_vm dir=/w"}
|
|
if !slices.Equal(kinds.Names(), want) || !slices.Equal(all.Names(), want) {
|
|
t.Errorf("kinds %q, all %q", kinds.Names(), all.Names())
|
|
}
|
|
kinds = Recorder{}
|
|
if !answered(f.Ask(NoVM("/a").AnsweredBy("--force").About(NoVM("/about")))) ||
|
|
!answered(f.Confirm(NoVM("/c").AnsweredBy("--force"))) || !answered(f.Answer(NoVM("/v").AnsweredBy("--force"))) {
|
|
t.Error("not answered")
|
|
}
|
|
if want := []string{"ask no_vm dir=/a", "confirm no_vm dir=/c", "answer no_vm dir=/v"}; !slices.Equal(asked, want) {
|
|
t.Errorf("asked %q", asked)
|
|
}
|
|
if want := []string{"no_vm dir=/about"}; !slices.Equal(kinds.Names(), want) {
|
|
t.Errorf("context %q, want %q", kinds.Names(), want)
|
|
}
|
|
f.AddCleanup(func(context.Context) {})
|
|
if cleanups != 1 || !f.CanPick() || !f.Interrupted() {
|
|
t.Error("its fields aren't what it says")
|
|
}
|
|
if f.Stdout() != &out || f.Stderr() != &errs || f.LogWriter() != &log {
|
|
t.Error("not its writers")
|
|
}
|
|
}
|
|
|
|
// A Fake gives each status line's label and each logged command's step
|
|
// to OnStatus, and shows the innermost one until it stops, as the UI's
|
|
// status line does.
|
|
func TestFakeStatus(t *testing.T) {
|
|
var labels Recorder
|
|
f := &Fake{OnStatus: labels.Add}
|
|
if _, on := f.Showing(); on {
|
|
t.Fatal("a line showing before any started")
|
|
}
|
|
shows := func(want string) {
|
|
t.Helper()
|
|
got, on := f.Showing()
|
|
if !on && want != "" || on && got.Names() != want {
|
|
t.Errorf("showing %q (%v), want %q", got.Names(), on, want)
|
|
}
|
|
}
|
|
outer := f.Status(NoVM("/outer"))
|
|
inner := f.Status(NoVM("/inner"))
|
|
shows("no_vm dir=/inner")
|
|
inner()
|
|
inner()
|
|
shows("no_vm dir=/outer")
|
|
ctx := t.Context()
|
|
if err := f.LoggedCmd(ctx, NoVM("/step"), exec.CommandContext(ctx, "true")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
shows("no_vm dir=/outer")
|
|
// Stopped out of order, the inner one stays.
|
|
second := f.Status(NoVM("/second"))
|
|
outer()
|
|
shows("no_vm dir=/second")
|
|
second()
|
|
shows("")
|
|
if want := []string{"no_vm dir=/outer", "no_vm dir=/inner", "no_vm dir=/step", "no_vm dir=/second"}; !slices.Equal(labels.Names(), want) {
|
|
t.Errorf("labels %q, want %q", labels.Names(), want)
|
|
}
|
|
}
|
|
|
|
// second is a two-value call's error.
|
|
func second[T any](_ T, err error) error { return err }
|