From df6e30aadd49ac1532770c230c7b8ef62d4babab Mon Sep 17 00:00:00 2001 From: DavidG Date: Wed, 18 Nov 2026 19:05:34 +0100 Subject: [PATCH] test(lox live): name the workspace by its real path in the exclusion test On macOS a temporary directory is reached through a link (/var -> /private/var). The test took the lock for the raw path while lox live, like every command, names the workspace by its real one: it found no lock, did not refuse and served until the test binary timed out, which broke ci on main (the macOS job does not run on pull requests). The test now goes through a link on every platform, so it fails on Linux too without the canonical path, and bounds its wait. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YF8fKrK1XFPoTRMpemksuX --- cmd/lox/live_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cmd/lox/live_test.go b/cmd/lox/live_test.go index c0ec01a..119d956 100644 --- a/cmd/lox/live_test.go +++ b/cmd/lox/live_test.go @@ -79,10 +79,18 @@ func TestLiveEnrol(t *testing.T) { func TestRunAndLiveExclude(t *testing.T) { t.Setenv("XDG_STATE_HOME", t.TempDir()) t.Setenv("XDG_RUNTIME_DIR", t.TempDir()) - ws := t.TempDir() + // The workspace is reached through a link, as a temporary directory is + // on macOS (/var -> /private/var): lox names a workspace by its real + // path, and so must the lock taken here by hand. + real := t.TempDir() + ws := filepath.Join(t.TempDir(), "ws") + if err := os.Symlink(real, ws); err != nil { + t.Fatal(err) + } abs := filepath.Join(ws, family.Dir, family.FileName) os.MkdirAll(filepath.Dir(abs), 0o755) os.WriteFile(abs, []byte("version: 1\nhub:\n image: ghcr.io/davidgodefroid/lockhub@sha256:"+strings.Repeat("1", 64)+"\n"), 0o644) + abs = family.Canonical(abs) // as lockFile does for every command state := stateDir(family.Project(family.Workspace(abs))) liveHeld, err := servelock.Acquire(state, servelock.Live) @@ -100,7 +108,18 @@ func TestRunAndLiveExclude(t *testing.T) { t.Fatal("lox run once lox live stopped") } var out, errb2 bytes.Buffer - code := run([]string{"live", "--file", abs, "--status-socket", filepath.Join(t.TempDir(), "s.sock")}, os.Stdin, &out, &errb2) + // Given the link, not the real path: lox live must find the same lock. + // A lox live that does not refuse would serve for ever: bound the wait. + done := make(chan int, 1) + go func() { + done <- run([]string{"live", "--file", filepath.Join(ws, family.Dir, family.FileName), "--status-socket", filepath.Join(t.TempDir(), "s.sock")}, os.Stdin, &out, &errb2) + }() + var code int + select { + case code = <-done: + case <-time.After(20 * time.Second): + t.Fatal("lox live started next to a lox run instead of refusing") + } if code != 1 || !strings.Contains(errb2.String(), "lox live: a lox at a terminal holds this workspace") { t.Fatalf("lox live next to lox run: %d %q", code, errb2.String()) }