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