From 743c0a06ec6bc19c0cec82f38dd7ada6590d912a Mon Sep 17 00:00:00 2001 From: HeavyGee <133152184+heavygee@users.noreply.github.com> Date: Fri, 31 Jul 2026 10:43:33 +0100 Subject: [PATCH] test(cursor): isolate cursor-models shared-cache tests per HAPI_HOME (#1268) The four cursorModels* CLI test files share one on-disk cache path ($HAPI_HOME/cache/cursor-models.json, defaulting to /tmp/hapi when HAPI_HOME is unset). Two files already isolate it (cursorModelsStaleLock via a PID-namespaced home; handlers/cursorModels via a unique temp home), but cursorModels.test.ts and cursorModelsSharedCache.test.ts do not. Under vitest's parallel file execution, cursorModelsSharedCache's afterEach(_resetSharedCursorModelsCacheForTests) rmSyncs that shared file between the other file's write and read, so the read returns null and "inherits cliModelSkus from shared cache" fails with `expected undefined to deeply equal [...]`. Passes in isolation; fails at random in the full parallel suite. Give both un-isolated files their own mkdtemp HAPI_HOME at module load so each test file's cache path is unique regardless of worker-process reuse. Fixes heavygee/hapi#101 Co-authored-by: Cursor --- cli/src/modules/common/cursorModels.test.ts | 8 ++++++++ cli/src/modules/common/cursorModelsSharedCache.test.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/cli/src/modules/common/cursorModels.test.ts b/cli/src/modules/common/cursorModels.test.ts index 5fd6ecbc..0a759bb4 100644 --- a/cli/src/modules/common/cursorModels.test.ts +++ b/cli/src/modules/common/cursorModels.test.ts @@ -1,5 +1,13 @@ import { afterEach, describe, expect, test, vi } from 'vitest' import { setCursorAcpModelsSnapshot } from '@/cursor/utils/cursorAcpModelsBridge' +import { mkdtempSync } 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 { 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 db8e1ae8..821f4904 100644 --- a/cli/src/modules/common/cursorModelsSharedCache.test.ts +++ b/cli/src/modules/common/cursorModelsSharedCache.test.ts @@ -1,10 +1,18 @@ import { afterEach, describe, expect, test } from 'vitest'; +import { mkdtempSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; import { readSharedCursorModelsCache, writeSharedCursorModelsCache, _resetSharedCursorModelsCacheForTests } from './cursorModelsSharedCache'; +// 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-')); + afterEach(() => { _resetSharedCursorModelsCacheForTests(); });