[PR #5886] [MERGED] test(ci): keep module mocks in isolated test projects #7102

Closed
opened 2026-11-01 21:45:24 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5886
Author: @kaoru0822-kitauji
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: test/isolate-module-mocks


📝 Commits (4)

  • 3f8c78c test(ci): keep module mocks in isolated test projects
  • eb1e835 test(pe): share one compiled CLI process across PE resource inspections
  • dfb2ac6 Merge remote-tracking branch 'origin/main' into test/isolate-module-mocks
  • 4738cd2 Merge remote-tracking branch 'origin/main' into test/isolate-module-mocks

📊 Changes

2 files changed (+46 additions, -5 deletions)

View changed files

📝 tests/boundary/filesystem/ciTestProjects.test.ts (+41 -0)
📝 tests/process-global/directAnalysisStatFailure.test.ts (+5 -5)

📄 Description

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 c324d31b4 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

c324d31b4 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 905cbaf23 (#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 c324d31b4 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 5eebe2fdf before c324d31b4): 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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5886 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `test/isolate-module-mocks` --- ### 📝 Commits (4) - [`3f8c78c`](https://github.com/morluto/rea/commit/3f8c78c78497ead35f225f712a79eaf8c5aa8168) test(ci): keep module mocks in isolated test projects - [`eb1e835`](https://github.com/morluto/rea/commit/eb1e8355ec420e6c6ad697393f3644974a3e5568) test(pe): share one compiled CLI process across PE resource inspections - [`dfb2ac6`](https://github.com/morluto/rea/commit/dfb2ac6c5e8ba9fbf0d5c443927f836cc5ab982c) Merge remote-tracking branch 'origin/main' into test/isolate-module-mocks - [`4738cd2`](https://github.com/morluto/rea/commit/4738cd2b61eabd761a86b6f6c120e7f3b357cc25) Merge remote-tracking branch 'origin/main' into test/isolate-module-mocks ### 📊 Changes **2 files changed** (+46 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `tests/boundary/filesystem/ciTestProjects.test.ts` (+41 -0) 📝 `tests/process-global/directAnalysisStatFailure.test.ts` (+5 -5) </details> ### 📄 Description **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 c324d31b4 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 c324d31b4 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 905cbaf23 (#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 c324d31b4 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. - [x] 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 5eebe2fdf before c324d31b4): `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 - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:45:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7102
No description provided.