Repository navigation
test(cli): isolate the exec image tests from the models.dev refresh - #1161
Conversation
runExec starts a background models.dev download unless ZERO_DISABLE_MODELS_FETCH is set. TestRunExecImageAttachmentHistory moved the user directories into a TempDir by hand but left the fetch on, so a 5.7 MB download landed in the TempDir while its cleanup ran, and the macOS runner failed with "unlinkat ... directory not empty". The two older image tests had no isolation and fetched into the real user cache. Use isolateCLIUserState in all three, which also points the cache path into the fixture and turns the fetch off.
|
@lhk0504 for your awareness: this is the test from #1152. Nothing wrong with the change itself. |
Zero automated PR reviewVerdict: No blockers found Blockers
Validation
ScopeHead: This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality. |
Thanks for tracking this down and fixing it! I missed the background models.dev refresh when setting up the test isolation. I’ll use isolateCLIUserState(t) for future CLI tests. |
What changed
The three tests in
internal/cli/exec_streamjson_images_test.gonow start withisolateCLIUserState(t). InTestRunExecImageAttachmentHistoryit replaces the hand-written loop that pointedHOME,APPDATAand the XDG variables at a temporary directory. The other two tests had no isolation at all.Why
runExeccallsmodelregistry.StartModelsDevRefresh(), which downloads the models.dev catalog in the background unlessZERO_DISABLE_MODELS_FETCHis set. The hand-written loop moved the cache under the test's temporary home but didn't turn the fetch off. So the test downloaded about 5.7 MB from the network, and the write raced thet.TempDircleanup. On the macOS runner the cleanup lost:That was on #886, whose only change since its last green run was a comment, so the flake comes from the test on main (#1152). The two older tests in the file had the same background fetch, and with no isolation it wrote to the real user cache.
isolateCLIUserStateis the shared helper for this. It redirects the same user directories, pointsZERO_MODELS_CACHE_PATHinto the fixture, setsZERO_DISABLE_MODELS_FETCHand keeps credentials off the OS keyring.Verification
TestRunExecImageAttachmentHistory(not committed) showed the mechanism. On main,modelsdev.jsonappeared in the test's home 3 seconds after the run, 5,756,570 bytes, for all three cases. With this change, no cache file is written.internal/clipasses on Windows.go vet ./internal/cli/for windows, linux and darwin,gofmt,git diff HEAD --check, andgo run ./cmd/zero-release buildandsmokeare clean.Summary by CodeRabbit