test(host-kit): stub os.homedir for the exec-trace late-close test

Merged
TH
2d ago
+4-2

Summary

The advisory Mutation Harness Canary (kernel-errors) has failed since #3846 added the "environment-only late close" exec-trace test. Stryker's vitest runner forces the thread pool, where vi.stubEnv('HOME') only changes the worker's copy of process.env. os.homedir() reads the real process HOME, so the diagnostics homedir fallback wrote outside the temp home and the test read undefined.

The test now redirects os.homedir() with vi.spyOn, as replay-port/source-discovery.test.ts does. Production code and the assertions are unchanged: the late close must still append to the finalized record with no second file. 1 file touched (test only). No linked issue.

Validation

  • Reproduced at origin/main (9935ef51c2): vitest run exec-trace.test.ts --pool=threads fails with ENOENT .../undefined. At head 495cd8d6e2 it passes under both --pool=threads and the default pool.
  • Mutation check: forcing event === 'close' && false in exec-trace.ts fails both late-close tests (and the other flush tests); reverted.
  • pnpm gate mutation --modules kernel-errors --shard 1/5 at 495cd8d6e2: dry run passes, lane envelope pass.
  • pnpm check:affected --run at 495cd8d6e2 fails lint only on snapshot-route.test.ts (1003 lines) already on main; #3890 fixes it. With #3890 merged into a throwaway local branch, all 6 checks pass (exit 0). This PR's lint will stay red until #3890 merges.
  • Canary (run 39736033426, throwaway branch = this head + a no-op comment in mutation-affected.yml, because a diff without lane sources selects no kernels): kernel-errors shards 1-5 and snapshot-occlusion all succeeded.

🤖 Generated with Claude Code