Repository navigation
test(ci): keep module mocks in isolated test projects - #5886
Conversation
A module mock registered after another file in the same worker loaded the module never applies, so a mocking test in a project that shares one module graph passes or fails with file scheduling. That is how the environment export source tests failed on hosted runs until c324d31 removed their mocks. Guard the rule: every tracked test using vi.mock or vi.doMock must belong to an isolated project. Move the last shared-graph case, DirectAnalysisStatFailure, which mocks node:fs/promises, into process-global beside the other module-mocking workflow tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Low impact] The current changes appear safe to merge; no blocking issue was found. SummaryThe current diff adds a check that keeps direct module mocks out of shared-graph projects and moves the remaining mock-using service test into
Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
The acceptance test started a fresh CLI process for each of its fixtures inside one 30 s test deadline. Hosted runs took 24-27 s and c324d31 timed out. Every inspection there reads no stdin and sets no deadline, so use the fixture's file-scoped compiled CLI process. Local time drops from 8.5 s to about 3.9 s with the same assertions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Main is currently red on every run from this test: |
…ocks # Conflicts: # tests/acceptance/applications/peResources.test.ts
…ocks # Conflicts: # tests/acceptance/applications/peResources.test.ts
What broke: module-mocking tests in Vitest projects with
isolate: false(one module graph shared per worker) pass or fail depending on file scheduling. This made theenvironmentExport.test.tssource tests fail intermittently on hosted runs (e.g. PRs #5852 and #5874) until c324d31 removed those mocks.Fix: a guard test requires every tracked test using
vi.mock/vi.doMockto belong to an isolated project. The last shared-graph case,DirectAnalysisStatFailure.test.ts, moves toprocess-global, where the repository already keeps module-mocking workflow tests.Risk: low. Test layout only; no product code changes. The moved test now runs with the built lane.
Summary
c324d31 fixed the observed
environmentExportfailures by removing those mocks. This PR prevents the same class of failure from returning and moves the one remaining file that breaks the rule. No issue is filed for this CI failure, so none is linked.Problem and expected behavior
In a project with
isolate: false,vi.mocktakes effect only if no earlier file in the same worker already loaded the mocked module. Theservices,domain,composition,conformance,evaluation,cli-boundaryandmcp-boundaryprojects share their graph for speed.vitest.config.tsalready notes that "module mocks belong in process-global", but nothing enforced it.The rule should hold mechanically: a mock's effect should never depend on which file ran first.
Change and scope
An earlier revision also moved the PE resource acceptance test onto the shared compiled CLI process. Main's 905cbaf (#5795) made the same startup reduction while keeping independent wrapper processes for PE32/PE32+, so that part was dropped in favour of main's version.
tests/boundary/filesystem/ciTestProjects.test.ts: newtest module isolationcheck. It loadsvitest.config.tsthe same way the existing worker-policy check does to read each project'sisolate. It then usesprojectForTestto map every tracked*.test.tsthat callsvi.mock(orvi.doMock(to its project. The check fails, naming the files, when one belongs to a shared-graph project.src/application/DirectAnalysisStatFailure.test.ts→tests/process-global/directAnalysisStatFailure.test.ts, with only its relative imports rewritten. It mocksnode:fs/promisesinservices.Contract and boundary impact
scripts/lib/test-projects.mjsownership plusvitest.config.tsisolation).Expected effects:
Evidence and regression coverage
npx vitest run --project services --maxWorkers=1 --sequence.shuffle --sequence.seed=<1|2|3> src/application/environment/failed the same fourenvironmentExport.test.tscases as hosted CI. These were the manifest/evidence snapshot-change refusals and the two heap-admission refusals; they passed when run alone.environmentExport.test.tstemporarily moved back underservices, the guard failed and listed exactlysrc/application/environment/environmentExport.test.ts. With the final layout it passes.DirectAnalysisStatFailure(executed): in its old location, four shuffled single-workerservicesruns (seeds 1–4) all passed. It is a latent case under the rule, not an observed flake.vi.mock(/vi.doMock(call text only, not mocks set up through helpers in other modules.Validation performed
npm run test:focused -- tests/process-global/directAnalysisStatFailure.test.ts tests/boundary/filesystem/ciTestProjects.test.ts— 2 files, 19 tests passednpx vitest run --project services— 118 files passed (1732 tests, 2 skipped)npm run check:fast— passednpm run format:check— passedCompatibility, safety, and release
Author readiness
Human owner: @kaoru0822-kitauji
Before merge
type(scope): outcome.🤖 Generated with Claude Code