Files
w3cjandClaude Opus 5.5 90a64a44d1 fix(races): lock order checked, sandboxes' own ports, pins that meet a rename, daemons' groups stopped
- state: test builds and tests check the state locks' order (state.held, CheckLockOrder): a second VM's lock, a VM's lock under the claims lock, or a lock taken again panics before waiting.
- platform: PinBeneath opens the path again when a rename takes the file away before move_mount (ENOENT), so the keeper no longer reports a false lost pin (TestPinsInNamespace's 'f lost / f pinned-again'); TestPinWhileRenamed.
- daemon: Proc.Stop signals the process group (SignalGroup), so forwarders' and link sessions' ssh masters and relays end with them; ui.UI.StopsItsOwn makes _ports and _links wait for their ssh on an outside SIGTERM.
- vm: gc --orphans and devvm space count forwarders' leftover control sockets (vmssh.ControlGlob).
- CLI tests: each sandbox claims a block of ports below devvm's range and the ephemeral range (claimPortBlock, /tmp/devvm-test-ports); free_port, the fixtures' ports and DEVVM_SSH_PORTS come from it, and the sandbox's devvm chooses from its own range (DEVVM_PORT_RANGE override). Fixtures' forwarded ports and settings ports are rewritten too (FIXTURE_PORT_<port>).
- netpolicy and vm tests: the fake proxy's stop waits for its reap, and fake daemons run until the test ends, not 30 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:31 -07:00

45 lines
1.6 KiB
Go

package cli
import (
"strings"
"testing"
"github.com/devvmhq/devvm/internal/build"
"github.com/devvmhq/devvm/internal/msg"
"github.com/devvmhq/devvm/internal/vm"
"github.com/devvmhq/devvm/internal/vmname"
)
// What gc deleted is said in the order it did: an image its backend
// refused with the backend's message, on stderr, and nothing for what it
// had none of; the package cache's sets alone still say it.
func TestShowGCDone(t *testing.T) {
u, out, errOut := testUI()
img := func(name, key string) vm.ListedImage {
return vm.ListedImage{Listed: build.Listed{Image: build.Image{Key: key, Name: name}}}
}
showGCDone(u, vm.GCDone{
Forgot: []vmname.VM{"devvm-a-0123456789abcd"}, Sockets: 2,
Images: []vm.DeletedImage{
{ListedImage: img("base", "0123456789ab")},
{ListedImage: img("", "ba9876543210")},
{ListedImage: img("foo", "aaaaaaaaaaaa"), Refused: true, Why: msg.ImageInUse("aaaaaaaaaaaa", "devvm-p-0123456789abcd")},
},
PackagesDeleted: true, History: 1, ToolsNoVM: 3, NixFiles: 4, NixFreed: 2048,
})
want := "==> forgot_orphan vm=devvm-a-0123456789abcd\n" +
"==> deleted_link_sockets count=2\n" +
"==> deleted_image image=base key=0123456789ab\n" +
"==> deleted_unfinished_build key=ba9876543210\n" +
"==> deleted_packages count=0\n" +
"==> deleted_history count=1\n" +
"==> deleted_tools_no_vm count=3\n" +
"==> deleted_nix_cache count=4 size=2.0K\n"
if out.String() != want {
t.Errorf("stdout\n%s\nwant\n%s", out, want)
}
if !strings.HasPrefix(errOut.String(), "devvm: image_in_use ") {
t.Errorf("stderr %q, want image_in_use", errOut)
}
}