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).
This commit is contained in:
yetone
2026-10-11 04:21:01 +08:00
parent 708515245d
commit a349de82db
+18
View File
@@ -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)
}
}