carlos / platform Public

Flaky test: TestShipAPIStaticCleansUpTempFileOnServerError scans the shared TMPDIR closed

TestShipAPIStaticCleansUpTempFileOnServerError (apimode_test.go:1640) failed main CI job 4995 at cf977a227f070718c8f79a99eef1e40a37757352 (shard root@4, 2026-11-06 23:23Z):

--- FAIL: TestShipAPIStaticCleansUpTempFileOnServerError (0.00s)
    apimode_test.go:1685: temp file carlos-ship-3719098490.tar.gz leaked after a failed ship

Cause: the test lists os.TempDir() before and after a failed static ship, and fails on any new carlos-ship-* name. That directory is shared with every other test in the package. Any ship test running at the same moment, or a temp file from another test process using the same TMPDIR, trips it. cf977a22 changes only internal/console, and the test passed 5/5 locally at that commit.

Fix suggestion: give the test its own temp directory (t.Setenv("TMPDIR", t.TempDir()) before the ship, so os.CreateTemp("", ...) lands there) and check that directory is empty afterwards. Note that t.Setenv cannot be used with t.Parallel.

This blocked the v0.34.16 cut (with three #359 "signal: terminated" kills on the same night).

Fix on branch fix-ship-tmp-flake (f5af462e). Cause confirmed: the test diffed the shared os.TempDir() for new carlos-ship-* names. The test now uses its own TMPDIR (t.Setenv to a t.TempDir()). The fake server also records that the temp file existed during the upload, so a pass means "created, then removed", not "never created" or "written elsewhere".

Checked locally:

  • With a background writer making carlos-ship-* files in the shared dir, the old test failed 153 of 200 runs and the new one 0 of 200.
  • Removing defer os.Remove in cli.go turns it red.
  • Pointing CreateTemp at another dir trips the new control.

No sibling tests scan the shared temp dir. One Opus review is running and CI is running. I'll close this on merge.

Merged as 3e1a3752 (squash, CI green on tip f5af462e, Opus review: ship, no findings). Mirrored to GitHub. Closing.