test: restore vi.stubEnv stubs automatically after every test - #3206
Conversation
Enable Vitest unstubEnvs for every project and the mutation lane through one TEST_ISOLATION constant, so env stubs never outlive the test that made them and a new project cannot leave it out. Move stubs that relied on persisting across tests into the tests that need them, and drop vi.unstubAllEnvs() calls that only undid vi.stubEnv. Global mock resets stay off: a bare vi.fn() would reset to returning undefined.
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 23 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
This PR is ready at f825666. The new test cleanup and the vitest config change look correct. Not blocking: the spread order at https://github.com/callstack/agent-device/blob/f825666/vitest.config.ts#L252 lets a project's own test block override the shared isolation constant, so you could spread it last. Take it or leave it. The cubic-dev-ai P3 thread on the same line still applies and is the same nit: #3206 (comment). No project sets unstubEnvs today, so it is a harmless hardening note. I did not run the test suite. The two Smoke Tests jobs were still running when I checked, so their result is unknown. This change only touches unit-test cleanup and vitest config, which the device-level smoke tests do not exercise. Nothing else needs to happen before merge except waiting for Smoke Tests to finish. |
|
Summary
Every Vitest project, and the mutation lane, now restores
vi.stubEnvstubs after each test (unstubEnvs). The setting comes from oneTEST_ISOLATIONconstant applied to all projects, so a new project cannot leave it out. A review of #3173 found Limrun env stubs leaking from one test into the next; this makes that class of leak impossible.command-tools-operator-inputs.test.ts).vi.unstubAllEnvs()calls that only undidvi.stubEnv.mockReset/restoreMocksstay off: in Vitest 4.1 a barevi.fn()resets to returningundefined, which would break hoisted factory mocks. Mock implementation leaks stay a per-file fix.23 files, 72 gross diff lines. No docs change:
docs/agents/testing.mdis at 9,980 of its 10,000-byte budget, and the config enforces the rule.Validation
At
f825666c5f:pnpm check:affected --runpasses (format, lint, typecheck, layering, fallow, build, vitest-related, and the model and contract checks). A throwaway probe confirmed the setting: a stub made in one test is gone in the next withTEST_ISOLATIONon, and leaks with it off.