mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -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]>
101 lines
3.8 KiB
Go
101 lines
3.8 KiB
Go
package vm
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
"github.com/devvmhq/devvm/internal/platform"
|
|
"github.com/devvmhq/devvm/internal/state"
|
|
)
|
|
|
|
// How long a lookup of a folder's volume waits (Env.Volumes, macOS's diskutil): a launch's, for
|
|
// a VM whose state records no volume yet, briefly, as it records one at a later launch when this
|
|
// one can't; an adopt's or a move's longer, as it records the folder anew.
|
|
const (
|
|
volumeWaitLaunch = time.Second
|
|
volumeWaitMove = 5 * time.Second
|
|
)
|
|
|
|
// volumeCache is a run's answers of Env.Volumes, by mount point and device, and whether one
|
|
// failed, after which the run asks no more, so a diskutil that hangs costs one wait a run.
|
|
type volumeCache struct {
|
|
mu sync.Mutex
|
|
got map[string]string
|
|
failed bool
|
|
}
|
|
|
|
// volumeOf is the volume of the folder s describes: s.Volume where the system gives it in the
|
|
// process (Linux), else Env.Volumes', within wait, asked once a run for each mount, under a status
|
|
// line; "" when it can't be told, which matches nothing and records nothing.
|
|
func (e *Env) volumeOf(ctx context.Context, s platform.FolderStat, wait time.Duration) string {
|
|
if volumeFree(e, s) {
|
|
return s.Volume
|
|
}
|
|
c := e.volumes
|
|
if c == nil {
|
|
c = new(volumeCache)
|
|
}
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
key := s.Mount + "\x00" + s.Device
|
|
if v, ok := c.got[key]; ok {
|
|
return v
|
|
}
|
|
if c.failed {
|
|
return "" // a lookup failed earlier in this run, so this one isn't tried
|
|
}
|
|
ctx, cancel := context.WithTimeout(ctx, wait)
|
|
defer cancel()
|
|
stop := e.Status(msg.LookingUpVolume(s.Mount))
|
|
v, err := e.Volumes(ctx, s)
|
|
stop()
|
|
if err != nil {
|
|
c.failed = !errors.Is(err, errors.ErrUnsupported)
|
|
return "" // no volume: the folder's record keeps none, and a later launch asks again
|
|
}
|
|
if c.got == nil {
|
|
c.got = map[string]string{}
|
|
}
|
|
c.got[key] = v
|
|
return v
|
|
}
|
|
|
|
// volumeFree reports whether volumeOf tells s's volume without asking e's Volumes, so it costs
|
|
// nothing: on Linux, where the system gives it in the process, and wherever there's none to ask
|
|
// for (read-only, not unique, no Volumes). It's a function, not a method, as Env has the most
|
|
// methods the structure test allows.
|
|
func volumeFree(e *Env, s platform.FolderStat) bool {
|
|
return s.ReadOnly || !s.Unique || e.Volumes == nil || s.Volume != "" && !e.VolumesOnly
|
|
}
|
|
|
|
// keepsVolume reports whether the folder s describes, which SameOpenFolder took for st's
|
|
// folder, is on the volume st records for it (platform.KeepsVolume), which a renumbering alone
|
|
// can't tell from a clone of the disk mounted at the folder's path. It looks the volume up when
|
|
// the folder's disk was numbered anew since it was recorded, when the record's volume wasn't
|
|
// checked since a renumbering (state.VM.FolderUnchecked), and at every launch where it costs
|
|
// nothing (volumeFree: Linux). It's true when the state records no volume, or the volume can't
|
|
// be told.
|
|
func (e *Env) keepsVolume(ctx context.Context, st *state.VM, s platform.FolderStat) bool {
|
|
if platform.RecordedVolume(st.Folder(), st.FolderVolume()) == "" {
|
|
return true
|
|
}
|
|
if platform.RecordedAs(st.Folder(), s) && !st.FolderUnchecked() && !volumeFree(e, s) {
|
|
return true
|
|
}
|
|
return platform.KeepsVolume(st.Folder(), st.FolderVolume(), e.volumeOf(ctx, s, volumeWaitMove))
|
|
}
|
|
|
|
// recordedVolume is what a state records of the volume of the folder at dir, whose identity is
|
|
// id (platform.VolumeOf): the volume of the folder opened there with no link on its path, when
|
|
// that's the folder id names, its identity its alone; "" otherwise.
|
|
func (e *Env) recordedVolume(ctx context.Context, dir, id string, wait time.Duration) string {
|
|
s, err := platform.StatFolder(dir)
|
|
if err != nil || !platform.RecordedAs(id, s) {
|
|
return "" // no volume a launch could vouch for: none recorded, and today's rule applies
|
|
}
|
|
return platform.VolumeOf(e.volumeOf(ctx, s, wait), s.ID)
|
|
}
|