Files
w3cjandClaude Opus 5.5 2b176c92b3 feat(ui): every slow step shows a status line, and messages and questions never land on it
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]>
2026-11-19 11:13:13 -07:00

243 lines
10 KiB
Go

package tools
import (
"bytes"
"net/http"
"net/http/httptest"
"slices"
"strings"
"sync/atomic"
"testing"
"github.com/devvmhq/devvm/internal/backend"
"github.com/devvmhq/devvm/internal/msg"
)
func TestDotnetRID(t *testing.T) {
for platform, want := range map[string]string{
"linux-arm64": "linux-arm64", "linux-x64": "linux-x64",
"linux-arm64-musl": "linux-musl-arm64", "linux-x64-musl": "linux-musl-x64",
} {
if got := dotnetRID(platform); got != want {
t.Errorf("dotnetRID(%s) = %s, want %s", platform, got, want)
}
}
}
// sha512Of is a made-up SHA-512 in hex, one per letter.
func sha512Of(c string) string { return strings.Repeat(c, 128) }
// dotnetChannel is a channel's releases.json as Microsoft writes it, with
// 10.0.402 as a release's SDK and 10.0.110 among its others; 10.0.402's
// files: good ones for arm64 and musl arm64 (an uppercase hash), and for
// x64 one off Microsoft's downloads and one without a SHA-512.
const dotnetChannel = `{"channel-version": "10.0", "releases": [
{"release-version": "10.0.4", "sdk": {"version": "10.0.402", "files": [
{"name": "dotnet-sdk-linux-arm64.tar.gz", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.tar.gz", "hash": "` + "aaaa" + `"},
{"name": "dotnet-sdk-linux-arm64.zip", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.zip", "hash": "HASH_B"},
{"name": "dotnet-sdk-linux-arm64.tar.gz", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.tar.gz", "hash": "HASH_A"},
{"name": "dotnet-sdk-linux-musl-arm64.tar.gz", "rid": "linux-musl-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-musl-arm64.tar.gz", "hash": "HASH_C_UPPER"},
{"name": "dotnet-sdk-linux-x64.tar.gz", "rid": "linux-x64", "url": "https://example.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-x64.tar.gz", "hash": "HASH_D"},
{"name": "dotnet-sdk-linux-musl-x64.tar.gz", "rid": "linux-musl-x64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-musl-x64.tar.gz", "hash": "abc"}
]}, "sdks": [{"version": "10.0.402", "files": []}, {"version": "10.0.110", "files": [
{"name": "dotnet-sdk-linux-arm64.tar.gz", "rid": "linux-arm64", "url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.110/dotnet-sdk-10.0.110-linux-arm64.tar.gz", "hash": "HASH_E"}
]}]},
{"release-version": "10.0.0-rc.1", "sdk": null}
]}`
// channelJSON is dotnetChannel with its made-up hashes.
func channelJSON() string {
return strings.NewReplacer("HASH_A", sha512Of("a"), "HASH_B", sha512Of("b"), "HASH_C_UPPER", strings.ToUpper(sha512Of("c")),
"HASH_D", sha512Of("d"), "HASH_E", sha512Of("e")).Replace(dotnetChannel)
}
// dotnetServer serves channel 10.0's releases.json, counting its requests,
// each of which runs under the resolution's status line; any other
// channel is missing.
func dotnetServer(t *testing.T, e env) *atomic.Int32 {
t.Helper()
var n atomic.Int32
fake, _ := e.Reporter.(*msg.Fake)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
n.Add(1)
if m, _ := fake.Showing(); m.ID() != "resolving_tools" {
t.Errorf("asked for %s under %q, want resolving_tools", r.URL.Path, m.ID())
}
if r.URL.Path != "/10.0/releases.json" {
http.NotFound(w, r)
return
}
_, _ = w.Write([]byte(channelJSON()))
}))
t.Cleanup(srv.Close)
e.dotnetURL = srv.URL + "/%s/releases.json"
return &n
}
// dotnetLock is the fixture with dotnet's entries as mise locks them,
// versions without downloads.
func dotnetLock(t *testing.T, versions ...string) []byte {
t.Helper()
var b bytes.Buffer
in := false
for _, line := range lines(fixture(t)) {
if strings.HasPrefix(line, "[") {
in = strings.HasPrefix(line, "[[tools.dotnet]]") || strings.HasPrefix(line, "[tools.dotnet.")
}
if !in {
b.WriteString(line + "\n")
}
}
for _, v := range versions {
b.WriteString("\n[[tools.dotnet]]\nversion = \"" + v + "\"\nbackend = \"core:dotnet\"\nspecifiers = [\"latest\"]\n")
}
return b.Bytes()
}
// Microsoft's archive and its SHA-512 for each of the VMs' platforms join
// each dotnet entry that has none: from its channel's releases.json, read
// once for all of them, a release's SDK or one of its others; a file off
// Microsoft's downloads, without a SHA-512 or not a tar.gz isn't taken. A
// lock that has them all stays as it is, and so does a version Microsoft
// doesn't list.
func TestWithSDKDownloads(t *testing.T) {
e := newEnv(t)
n := dotnetServer(t, e)
lock, err := e.withSDKDownloads(t.Context(), parsed(t, dotnetLock(t, "10.0.402", "10.0.110", "10.0.499", "10.x")))
if err != nil {
t.Fatal(err)
}
if got := n.Load(); got != 1 {
t.Errorf("%d requests, want 1", got)
}
want := map[string][2]string{
"10.0.402 linux-arm64": {"https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-arm64.tar.gz", "sha512:" + sha512Of("a")},
"10.0.402 linux-arm64-musl": {"https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.402/dotnet-sdk-10.0.402-linux-musl-arm64.tar.gz", "sha512:" + sha512Of("c")},
"10.0.110 linux-arm64": {"https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0.110/dotnet-sdk-10.0.110-linux-arm64.tar.gz", "sha512:" + sha512Of("e")},
}
for _, v := range []string{"10.0.402", "10.0.110", "10.0.499", "10.x"} {
for _, p := range []string{"linux-arm64", "linux-arm64-musl", "linux-x64", "linux-x64-musl"} {
table, _ := lock.versionEntry("dotnet", v)["platforms."+p].(map[string]any)
got := [2]string{str(table, "url"), str(table, "checksum")}
if got != want[v+" "+p] {
t.Errorf("%s on %s: %q, want %q", v, p, got, want[v+" "+p])
}
}
}
if url, sum := lock.Download("dotnet", "linux-arm64"); url != want["10.0.402 linux-arm64"][0] || sum != want["10.0.402 linux-arm64"][1] {
t.Errorf("Download = %s %s", url, sum)
}
if !slices.Equal(lockTools(t, lock.Bytes()), lockTools(t, fixture(t))) || !bytes.Equal(entryOf(t, lock.Bytes(), "node"), entryOf(t, fixture(t), "node")) {
t.Error("the other tools changed")
}
for _, have := range [][]byte{fixture(t), dotnetLock(t)} {
again, err := e.withSDKDownloads(t.Context(), parsed(t, have))
if err != nil || !bytes.Equal(again.Bytes(), have) {
t.Errorf("a lock with every download changed: %v", err)
}
}
if got := n.Load(); got != 1 {
t.Errorf("%d requests for locks with every download", got)
}
// x64's: one off Microsoft's downloads, and one without a SHA-512.
sdks, err := dotnetSDKs([]byte(channelJSON()))
if err != nil || len(sdks) != 3 {
t.Fatalf("dotnetSDKs = %d, %v", len(sdks), err)
}
for _, p := range []string{"linux-x64", "linux-x64-musl"} {
if url, _, ok := sdks[0].download(p); ok {
t.Errorf("%s: %s", p, url)
}
}
}
// A channel Microsoft doesn't answer for fails, and so does Resolve, with
// nothing written; with its downloads, Resolve writes them.
func TestResolveSDKDownloads(t *testing.T) {
e := newEnv(t)
e.locked(t, fixture(t))
n := dotnetServer(t, e)
e.stubLocks(t, dotnetLock(t, "9.0.300"), nil, "")
if err := e.Refresh(t.Context()); msg.NamesOf(err) != "tools_resolve_failed" {
t.Errorf("Refresh with a channel that isn't there = %v", msg.NamesOf(err))
}
if !bytes.Equal(read(t, e.Dirs.ToolLock()), fixture(t)) {
t.Error("the lock changed")
}
if got := n.Load(); got != 1 {
t.Errorf("%d requests for a 404, want 1", got)
}
e.stubLocks(t, dotnetLock(t, "10.0.402"), nil, "")
if err := e.Refresh(t.Context()); err != nil {
t.Fatal(msg.NamesOf(err))
}
lock := parsed(t, read(t, e.Dirs.ToolLock()))
if lock.Version("dotnet") != "10.0.402" || !lock.HasDownload("dotnet", e.platforms()) {
t.Errorf("dotnet = %s, with downloads %v", lock.Version("dotnet"), lock.HasDownload("dotnet", e.platforms()))
}
if url, _ := lock.Download("dotnet", "linux-arm64-musl"); !strings.HasSuffix(url, "-linux-musl-arm64.tar.gz") {
t.Errorf("musl's download = %s", url)
}
}
// The newest SDK without a download for a platform steps back, to an
// older one whose downloads devvm added too.
func TestSDKStepsBack(t *testing.T) {
e := newEnv(t)
e.locked(t, fixture(t))
dotnetServer(t, e)
e.stubLocks(t, dotnetLock(t, "10.0.499"), dotnetLock(t, "10.0.402"), "10.0.300 10.0.402 10.0.499")
if err := e.Refresh(t.Context()); err != nil {
t.Fatal(msg.NamesOf(err))
}
if !slices.Contains(*e.said, "devvm: tool_stepped_back older=10.0.402 tool=dotnet version=10.0.499") {
t.Errorf("said %q", *e.said)
}
if lock := parsed(t, read(t, e.Dirs.ToolLock())); lock.Version("dotnet") != "10.0.402" || !lock.HasDownload("dotnet", e.platforms()) {
t.Errorf("dotnet = %s", lock.Version("dotnet"))
}
}
// build.sh gets dotnet's download for the VM's platform and its SHA-512,
// in hex, after its tool, version and file; a download without a SHA-512
// isn't built.
func TestBuildDotnet(t *testing.T) {
e := newEnv(t)
e.locked(t, fixture(t))
lock := parsed(t, fixture(t))
for _, tg := range []struct {
target Target
base string
platform string
}{{gnuT, baseKey, "linux-arm64"}, {muslT, muslKey, "linux-arm64-musl"}} {
f := fake()
file, err := e.File(lock, "dotnet", tg.target)
if err != nil {
t.Fatal(err)
}
if err := e.Build(t.Context(), backend.Review{}, f, tg.base, tg.target, []string{file}); err != nil {
t.Fatal(msg.NamesOf(err))
}
url, sum := lock.Download("dotnet", tg.platform)
spec, _ := f.Calls()[0].Args[0].(backend.ToolsSpec)
if want := []string{"dotnet", "10.0.401", file, url, strings.TrimPrefix(sum, "sha512:")}; !slices.Equal(spec.Args, want) {
t.Errorf("%s: build.sh's arguments %q, want %q", tg.platform, spec.Args, want)
}
}
e = newEnv(t)
sha256 := bytes.ReplaceAll(fixture(t), []byte(`checksum = "sha512:`), []byte(`checksum = "sha256:`))
e.locked(t, sha256)
file, err := e.File(parsed(t, sha256), "dotnet", gnuT)
if err != nil {
t.Fatal(err)
}
f := fake()
if err := e.Build(t.Context(), backend.Review{}, f, baseKey, gnuT, []string{file}); msg.NamesOf(err) != "tool_unbuilt tool=dotnet version=10.0.401" {
t.Errorf("a download without a SHA-512 = %v", msg.NamesOf(err))
}
if len(f.Calls()) != 0 {
t.Errorf("built: %q", f.Methods())
}
e.noLeftovers(t)
}