test: dedupe fixtures and test harness setup

This commit is contained in:
Peter Steinberger
2026-02-23 05:43:30 +00:00
parent 8af19ddc5b
commit 1c753ea786
75 changed files with 1886 additions and 2136 deletions

View File

@@ -1,28 +1,21 @@
import crypto from "node:crypto";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createFixtureSuite } from "../../test-utils/fixture-suite.js";
import { capEntryCount, pruneStaleEntries, rotateSessionFile } from "./store.js";
import type { SessionEntry } from "./types.js";
const DAY_MS = 24 * 60 * 60 * 1000;
let fixtureRoot = "";
let fixtureCount = 0;
async function createCaseDir(prefix: string): Promise<string> {
const dir = path.join(fixtureRoot, `${prefix}-${fixtureCount++}`);
await fs.mkdir(dir, { recursive: true });
return dir;
}
const fixtureSuite = createFixtureSuite("openclaw-pruning-suite-");
beforeAll(async () => {
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-pruning-suite-"));
await fixtureSuite.setup();
});
afterAll(async () => {
await fs.rm(fixtureRoot, { recursive: true, force: true });
await fixtureSuite.cleanup();
});
function makeEntry(updatedAt: number): SessionEntry {
@@ -82,7 +75,7 @@ describe("rotateSessionFile", () => {
let storePath: string;
beforeEach(async () => {
testDir = await createCaseDir("rotate");
testDir = await fixtureSuite.createCaseDir("rotate");
storePath = path.join(testDir, "sessions.json");
});