Skip to content

Commit 495cd8d

Browse files
thymikeeclaude
andcommitted
test(host-kit): stub os.homedir for the exec-trace late-close test
vi.stubEnv('HOME') does not reach os.homedir() in worker threads, which is the pool Stryker's vitest runner forces. The diagnostics homedir fallback then wrote outside the temp home and the test read an undefined path, failing the Mutation Harness Canary dry run. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 9935ef5 commit 495cd8d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎packages/host-kit/src/internal/exec-trace.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ChildProcess, spawn } from 'node:child_process';
22
import fs from 'node:fs';
3+
// oxlint-disable-next-line no-restricted-imports -- vi.spyOn(os,'homedir'): os.homedir() ignores a stubbed HOME in worker threads
4+
import os from 'node:os';
35
import path from 'node:path';
46
import { PassThrough } from 'node:stream';
57
import { afterEach, expect, test, vi } from 'vitest';
@@ -199,7 +201,7 @@ for (const fixedLogPath of [true, false]) {
199201
vi.useFakeTimers();
200202
const fixture = processFixture();
201203
const home = mkdtempForTestSync('exec-late-close-');
202-
vi.stubEnv('HOME', home);
204+
const homedir = vi.spyOn(os, 'homedir').mockReturnValue(home);
203205
const logPath = fixedLogPath ? path.join(home, 'request.ndjson') : undefined;
204206
try {
205207
await withCommandHost(
@@ -242,7 +244,7 @@ for (const fixedLogPath of [true, false]) {
242244
}),
243245
);
244246
} finally {
245-
vi.unstubAllEnvs();
247+
homedir.mockRestore();
246248
}
247249
});
248250
}

0 commit comments

Comments
 (0)