mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
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 <cursoragent@cursor.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user