From c7afc5032193f983afd713ae1af3c0ccf6cb5b59 Mon Sep 17 00:00:00 2001 From: HeavyGee <133152184+heavygee@users.noreply.github.com> Date: Fri, 31 Jul 2026 11:45:34 +0100 Subject: [PATCH] test(cursor): remove per-file temp HAPI homes after cursor-models suites (#1269) Follow-up to #1268. The per-file `mkdtempSync`/`join(tmpdir(), ...)` HAPI homes in the cursor-models test cluster were never removed, so every run leaked a directory into the system temp dir (afterEach only cleared the cache file inside them). Save/restore HAPI_HOME and recursively remove each per-file temp root in teardown across all three cursor-models test files (cursorModels, cursorModelsSharedCache, and the stale-lock test that had the same pattern). No source/runtime change. Co-authored-by: Cursor --- cli/src/modules/common/cursorModels.test.ts | 16 +++++++++++++--- .../common/cursorModelsSharedCache.test.ts | 16 +++++++++++++--- .../modules/common/cursorModelsStaleLock.test.ts | 5 ++++- 3 files changed, 30 insertions(+), 7 deletions(-) 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 () => {