Skip to content

test: restore vi.stubEnv stubs automatically after every test - #3206

Merged
thymikee merged 1 commit into
mainfrom
claude/vitest-unstub-envs
Oct 4, 2026
Merged

thymikee merged 1 commit into
mainfrom
claude/vitest-unstub-envs

Conversation

@thymikee

@thymikee thymikee commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Every Vitest project, and the mutation lane, now restores vi.stubEnv stubs after each test (unstubEnvs). The setting comes from one TEST_ISOLATION constant 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.

  • Tests that relied on a stub persisting into later tests now stub where they need it (command-tools-operator-inputs.test.ts).
  • 20 test files drop vi.unstubAllEnvs() calls that only undid vi.stubEnv.
  • Global mockReset/restoreMocks stay off: in Vitest 4.1 a bare vi.fn() resets to returning undefined, 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.md is at 9,980 of its 10,000-byte budget, and the config enforces the rule.

Validation

At f825666c5f: pnpm check:affected --run passes (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 with TEST_ISOLATION on, and leaks with it off.

Review in cubic

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.
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
Installed (including dependencies) 4.97 MB 4.97 MB -522 B
Package (unpacked) 4.97 MB 4.97 MB -522 B
Package (download) 1.49 MB 1.49 MB -146 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 30.5 ms 29.0 ms -1.6 ms
CLI --help 90.4 ms 87.7 ms -2.7 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 23 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread vitest.config.ts
@thymikee

thymikee commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

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.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Oct 4, 2026
@thymikee
thymikee merged commit f2f3afa into main Oct 4, 2026
19 checks passed
@thymikee
thymikee deleted the claude/vitest-unstub-envs branch October 4, 2026 10:20
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-04 10:20 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant