diff --git a/cli/src/modules/common/cursorModels.test.ts b/cli/src/modules/common/cursorModels.test.ts index 0a759bb4..2d87da66 100644 --- a/cli/src/modules/common/cursorModels.test.ts +++ b/cli/src/modules/common/cursorModels.test.ts @@ -1,13 +1,23 @@ -import { afterEach, describe, expect, test, vi } from 'vitest' +import { afterAll, afterEach, describe, expect, test, vi } from 'vitest' import { setCursorAcpModelsSnapshot } from '@/cursor/utils/cursorAcpModelsBridge' -import { mkdtempSync } from 'node:fs' +import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' // Isolate the on-disk cursor-models cache to this file's own HAPI_HOME so // parallel vitest workers don't race on the shared $HAPI_HOME/cache path // (see heavygee/hapi#101). -process.env.HAPI_HOME = mkdtempSync(join(tmpdir(), 'hapi-cursor-models-')) +const previousHapiHome = process.env.HAPI_HOME +const testHapiHome = mkdtempSync(join(tmpdir(), 'hapi-cursor-models-')) +process.env.HAPI_HOME = testHapiHome + +// Remove the per-file temp root after the suite so runs don't leak dirs into +// the system temp dir (afterEach only clears the cache file inside it). +afterAll(() => { + if (previousHapiHome === undefined) delete process.env.HAPI_HOME + else process.env.HAPI_HOME = previousHapiHome + rmSync(testHapiHome, { recursive: true, force: true }) +}) const { spawnMock } = vi.hoisted(() => ({ spawnMock: vi.fn() diff --git a/cli/src/modules/common/cursorModelsSharedCache.test.ts b/cli/src/modules/common/cursorModelsSharedCache.test.ts index 821f4904..d9394587 100644 --- a/cli/src/modules/common/cursorModelsSharedCache.test.ts +++ b/cli/src/modules/common/cursorModelsSharedCache.test.ts @@ -1,5 +1,5 @@ -import { afterEach, describe, expect, test } from 'vitest'; -import { mkdtempSync } from 'node:fs'; +import { afterAll, afterEach, describe, expect, test } from 'vitest'; +import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { @@ -11,12 +11,22 @@ import { // Isolate the on-disk cursor-models cache to this file's own HAPI_HOME so // parallel vitest workers don't race on the shared $HAPI_HOME/cache path // (see heavygee/hapi#101). -process.env.HAPI_HOME = mkdtempSync(join(tmpdir(), 'hapi-cursor-models-shared-cache-')); +const previousHapiHome = process.env.HAPI_HOME; +const testHapiHome = mkdtempSync(join(tmpdir(), 'hapi-cursor-models-shared-cache-')); +process.env.HAPI_HOME = testHapiHome; afterEach(() => { _resetSharedCursorModelsCacheForTests(); }); +// Remove the per-file temp root after the suite so runs don't leak dirs into +// the system temp dir (afterEach only clears the cache file inside it). +afterAll(() => { + if (previousHapiHome === undefined) delete process.env.HAPI_HOME; + else process.env.HAPI_HOME = previousHapiHome; + rmSync(testHapiHome, { recursive: true, force: true }); +}); + describe('cursorModelsSharedCache', () => { test('round-trips a usable models response', () => { const payload = { diff --git a/cli/src/modules/common/cursorModelsStaleLock.test.ts b/cli/src/modules/common/cursorModelsStaleLock.test.ts index 552f94c4..119dff9e 100644 --- a/cli/src/modules/common/cursorModelsStaleLock.test.ts +++ b/cli/src/modules/common/cursorModelsStaleLock.test.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; +import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; import { tmpdir } from 'node:os'; import { afterEach, describe, expect, test, vi } from 'vitest'; @@ -46,6 +46,9 @@ describe('listCursorModels stale ACP lock', () => { } else { process.env.HAPI_HOME = previousHome; } + // Remove the per-file temp home so runs don't leak dirs into the system + // temp dir (the test creates it under tmpdir() but never cleaned it up). + rmSync(testHome, { recursive: true, force: true }); }); test('runs cold ACP probe after clearing a stale cross-process lock', async () => {