diff --git a/src/pairing/pairing-store.test.ts b/src/pairing/pairing-store.test.ts index f858d0f3f..ab6674438 100644 --- a/src/pairing/pairing-store.test.ts +++ b/src/pairing/pairing-store.test.ts @@ -2,13 +2,27 @@ import crypto from "node:crypto"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; import { resolveOAuthDir } from "../config/paths.js"; import { listChannelPairingRequests, upsertChannelPairingRequest } from "./pairing-store.js"; +let fixtureRoot = ""; +let caseId = 0; + +beforeAll(async () => { + fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-pairing-")); +}); + +afterAll(async () => { + if (fixtureRoot) { + await fs.rm(fixtureRoot, { recursive: true, force: true }); + } +}); + async function withTempStateDir(fn: (stateDir: string) => Promise) { const previous = process.env.OPENCLAW_STATE_DIR; - const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-pairing-")); + const dir = path.join(fixtureRoot, `case-${caseId++}`); + await fs.mkdir(dir, { recursive: true }); process.env.OPENCLAW_STATE_DIR = dir; try { return await fn(dir); @@ -18,7 +32,6 @@ async function withTempStateDir(fn: (stateDir: string) => Promise) { } else { process.env.OPENCLAW_STATE_DIR = previous; } - await fs.rm(dir, { recursive: true, force: true }); } }