From 495cd8d6e242590fb28ece73089e9221e1d50c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 22 Oct 2026 08:39:29 +0200 Subject: [PATCH] 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 --- packages/host-kit/src/internal/exec-trace.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/host-kit/src/internal/exec-trace.test.ts b/packages/host-kit/src/internal/exec-trace.test.ts index 1657912904..90dff5e3bb 100644 --- a/packages/host-kit/src/internal/exec-trace.test.ts +++ b/packages/host-kit/src/internal/exec-trace.test.ts @@ -1,5 +1,7 @@ import { ChildProcess, spawn } from 'node:child_process'; import fs from 'node:fs'; +// oxlint-disable-next-line no-restricted-imports -- vi.spyOn(os,'homedir'): os.homedir() ignores a stubbed HOME in worker threads +import os from 'node:os'; import path from 'node:path'; import { PassThrough } from 'node:stream'; import { afterEach, expect, test, vi } from 'vitest'; @@ -199,7 +201,7 @@ for (const fixedLogPath of [true, false]) { vi.useFakeTimers(); const fixture = processFixture(); const home = mkdtempForTestSync('exec-late-close-'); - vi.stubEnv('HOME', home); + const homedir = vi.spyOn(os, 'homedir').mockReturnValue(home); const logPath = fixedLogPath ? path.join(home, 'request.ndjson') : undefined; try { await withCommandHost( @@ -242,7 +244,7 @@ for (const fixedLogPath of [true, false]) { }), ); } finally { - vi.unstubAllEnvs(); + homedir.mockRestore(); } }); }