Skip to content

test(ci): keep module mocks in isolated test projects - #5886

Merged
kaoru0822-kitauji merged 4 commits into
mainfrom
test/isolate-module-mocks
Oct 21, 2026
Merged

kaoru0822-kitauji merged 4 commits into
mainfrom
test/isolate-module-mocks

Conversation

@kaoru0822-kitauji

@kaoru0822-kitauji kaoru0822-kitauji commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

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 the environmentExport.test.ts source 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.doMock to belong to an isolated project. The last shared-graph case, DirectAnalysisStatFailure.test.ts, moves to process-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 environmentExport failures 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.mock takes effect only if no earlier file in the same worker already loaded the mocked module. The services, domain, composition, conformance, evaluation, cli-boundary and mcp-boundary projects share their graph for speed. vitest.config.ts already 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: new test module isolation check. It loads vitest.config.ts the same way the existing worker-policy check does to read each project's isolate. It then uses projectForTest to map every tracked *.test.ts that calls vi.mock( or vi.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 mocks node:fs/promises in services.
  • Not included: rewriting that test without mocks (as c324d31 did for environment export), or changing any project's isolation policy.
  • Scope decision: not applicable (test infrastructure only).

Contract and boundary impact

  • Semantic owner and earliest changed stage: test-project policy (scripts/lib/test-projects.mjs ownership plus vitest.config.ts isolation).
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: the guard above; the moved test is otherwise unchanged.
  • Base reproduction (executed, macOS arm64, on 5eebe2f before c324d31): npx vitest run --project services --maxWorkers=1 --sequence.shuffle --sequence.seed=<1|2|3> src/application/environment/ failed the same four environmentExport.test.ts cases as hosted CI. These were the manifest/evidence snapshot-change refusals and the two heap-admission refusals; they passed when run alone.
  • Guard verification (executed): with environmentExport.test.ts temporarily moved back under services, the guard failed and listed exactly src/application/environment/environmentExport.test.ts. With the final layout it passes.
  • DirectAnalysisStatFailure (executed): in its old location, four shuffled single-worker services runs (seeds 1–4) all passed. It is a latent case under the rule, not an observed flake.
  • Remaining proof gaps: the guard detects 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 passed
  • npx vitest run --project services — 118 files passed (1732 tests, 2 skipped)
  • npm run check:fast — passed
  • npm run format:check — passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS arm64 locally; hosted Linux via CI.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none needed (tests only).

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

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>
@kaoru0822-kitauji kaoru0822-kitauji added bug Something isn't working track:bugs Small-bug loop track PRs labels Oct 21, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T12:37:03.292655Z 4738cd2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The current changes appear safe to merge; no blocking issue was found.

Summary

The current diff adds a check that keeps direct module mocks out of shared-graph projects and moves the remaining mock-using service test into process-global.

  • Mock-using tests are checked against isolation, and the filesystem test runs in process-global.

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>
@kaoru0822-kitauji kaoru0822-kitauji changed the title test(ci): keep module mocks in isolated test projects test(ci): remove scheduling-dependent failures from main CI Oct 21, 2026
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator Author

Main is currently red on every run from this test: tests/acceptance/applications/peResources.test.ts timed out at 30 s in both CI runs on c324d31 (runs 39584670117 and 39585605001, Test shard 7/8 and 5/6 plus Portable tests). Earlier main runs took 24.1 s and 27.4 s. eb1e835 in this PR moves its five CLI inspections onto the fixture's shared compiled CLI process; locally the test goes from 8.5 s to ~3.9 s with the same assertions. The hosted timing will show in this PR's run.

…ocks

# Conflicts:
#	tests/acceptance/applications/peResources.test.ts
…ocks

# Conflicts:
#	tests/acceptance/applications/peResources.test.ts
@kaoru0822-kitauji kaoru0822-kitauji changed the title test(ci): remove scheduling-dependent failures from main CI test(ci): keep module mocks in isolated test projects Oct 21, 2026
@kaoru0822-kitauji
kaoru0822-kitauji merged commit 6d356b8 into main Oct 21, 2026
40 of 42 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the test/isolate-module-mocks branch October 21, 2026 12:51
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
3 tasks done
@morluto morluto added the area: build Build, CI, packaging, and publishing label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build, CI, packaging, and publishing bug Something isn't working track:bugs Small-bug loop track PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants