Files
devvm/internal/msg/mountcache_test.go
w3cjandClaude Opus 5.5 db26def35b fix(lima): restart once when the folder can't be mounted again
After a cache-mode change, a Linux VM's start mounts its 9p project
folder again in the guest. On an Alpine --from VM (OpenRC) the umount
succeeds but both mounts fail ("already mounted or mount point busy"),
and devvm stopped the VM with mount_cache_unmounted, though a plain
restart boots with the new mode, which lima.yaml already has.

Now a folder left unmounted, still on the old mode, or a check that
fails gets one restart: the Lima backend writes why in the run log,
stops the VM under one status step (remount_restarting) and returns a
backend.RemountError. The caller, starter.start, starts the VM again
once through startOnce, the same path every start takes, so the restart
gets a new proxy following the new hostagent (the old one exits with
it), the .git pins applied in QEMU's new namespace, its host keys read
again for the new start, and its start recorded. That start's
Want.CheckCache asks Lima for the mountinfo check without the remount;
its outcome is final: unmounted or unchecked stops the VM and fails
with today's messages, another mode warns (its text now says to run
devvm restart to try again). An interrupt gets no restart, and the
cleanup stops the VM once.

- backend: RemountError, Want.CheckCache; backendtest.Fake.StartErr.
- Tests: TestStartSetsProjectCacheOnce (each failure a RemountError,
  the run log's line), TestStartRechecksProjectCache (the restart's
  check, no second restart), TestRemountInterrupted (no restart),
  TestRemountRestart in vm (two starts, a proxy each, no third).
- Stubs: remount-fails (the remount fails and leaves the folder
  unmounted until the next start); TestGuestMountOptions covers it.
- mount_cache.txtar: the restart that mounts the folder, and the one
  that doesn't, with no third start.
- e2e: the from section's Alpine check expects the launch to succeed
  through the restart.
- Docs: backends/lima.md's "When the cache mode changes", design.md's
  remount, restart and running-VM paragraphs, tests.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HTFcPrY8FzzQMopN5wgpLQ
2026-11-09 09:57:17 -07:00

38 lines
1.5 KiB
Go

package msg
import "testing"
// The project folder cache's messages put each value in its own field:
// most are said only on a Linux host, where QEMU's 9p mount has a cache
// mode, so this is where a macOS run checks their fields.
func TestMountCacheMessages(t *testing.T) {
for _, tc := range []struct {
m M
want string
}{
{MountCacheInvalid(`"mmap"`), `mount_cache_invalid value="mmap"`},
{MountCacheUnchosen("mmap", "v"), "mount_cache_unchosen mode=mmap vm=v"},
{MountCacheNoChoice("v"), "mount_cache_no_choice vm=v"},
{MountCacheClone("none", "v"), "mount_cache_clone mode=none vm=v"},
{MountCachePending("none", "v"), "mount_cache_pending mode=none vm=v"},
{VMMountCache("none", "v"), "vm_mount_cache mode=none vm=v"},
{MountCacheRemountFailed("mmap", "v", "none"), "mount_cache_remount_failed has=mmap vm=v want=none"},
{MountCacheUnmounted("v"), "mount_cache_unmounted vm=v"},
{MountCacheUnchecked("v"), "mount_cache_unchecked vm=v"},
{ProjectUnmounted("v"), "project_unmounted vm=v"},
{ProjectUnchecked("v"), "project_unchecked vm=v"},
{Remounting("v"), "remounting vm=v"},
{RemountRestarting("v"), "remount_restarting vm=v"},
{NextStartMountCache("v"), "next_start_mount_cache vm=v"},
{NoVMMountCache("/p"), "no_vm_mount_cache dir=/p"},
{MountCacheFailed("x"), "mount_cache_failed reason=x"},
} {
if got := tc.m.Names(); got != tc.want {
t.Errorf("%s, want %s", got, tc.want)
}
if tc.m.Text() == "" {
t.Errorf("%s has no text", tc.want)
}
}
}