From a349de82dbd32932057ad8b354cda6ea459f5f56 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 11 Oct 2026 04:21:01 +0800 Subject: [PATCH] gateway tests: the package sets testenv's marker, so a late CLI-identity ask can't write into the next test's folder again (#1524 after 9c377231) 9c377231 stopped a test binary keeping a CLI identity on disk by reading MAGPIE_TEST_SANDBOX, which testenv.Run sets. internal/gateway isolates itself in its own TestMain (isolatedTests) and never set it, so the identity was still written there: CI on 9c377231 failed the ubuntu Race shard in TestRequestTailAfterOldLimit with "directory not empty", #1524's failure. isolatedTests now sets the marker to its home, as testenv does, and TestRunsAsAnIsolatedTestBinary fails if it doesn't. Ran: the new test with the Setenv removed (red: "TestMain left MAGPIE_TEST_SANDBOX unset") and restored (green); go vet on darwin, GOOS=linux and GOOS=windows for internal/gateway; go test -count=1 ./internal/gateway/ (ok, 433s, on a machine at load ~80). --- internal/gateway/main_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/gateway/main_test.go b/internal/gateway/main_test.go index cb6e2ab24..9e325f358 100644 --- a/internal/gateway/main_test.go +++ b/internal/gateway/main_test.go @@ -44,6 +44,16 @@ func isolatedTests(m *testing.M) (int, error) { return 1, err } } + // The package isolates itself rather than through testenv.Run, so it + // says so as testenv does: what reads the marker (a CLI identity kept + // on disk, provider.keepsIdentities; the machine's own folders, + // proc.SystemDirs) then acts as in any isolated test binary. Without it + // an ask still going when its test ended wrote cli-identity.json into + // the next test's folder as that was removed (#1524, again after + // 9c377231 dropped this package's own switch). + if err := os.Setenv(testenv.Marker, home); err != nil { + return 1, err + } for _, name := range agentenv.Vars { if err := os.Unsetenv(name); err != nil { return 1, err @@ -82,3 +92,11 @@ func isolatedTests(m *testing.M) (int, error) { testenv.Offline() return m.Run(), nil } + +// The package's tests run as an isolated test binary: nothing the marker +// turns off (a CLI identity kept on disk, #1524) runs behind a test's back. +func TestRunsAsAnIsolatedTestBinary(t *testing.T) { + if os.Getenv(testenv.Marker) == "" { + t.Fatalf("TestMain left %s unset", testenv.Marker) + } +}