Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import {
|
|
type ConformanceCase,
|
|
createSessionRepoConformance,
|
|
} from "@earendil-works/pi-agent-core/harness/session/testing";
|
|
import { describe, it } from "vitest";
|
|
import { createNodeSqliteFactory, SqliteSessionRepo } from "../src/index.ts";
|
|
|
|
const NOW = 1_700_000_000_000;
|
|
|
|
function registerConformance(name: string, cases: readonly ConformanceCase[]): void {
|
|
describe(name, () => {
|
|
for (const group of new Set(cases.map((testCase) => testCase.group))) {
|
|
describe(group, () => {
|
|
for (const testCase of cases.filter((candidate) => candidate.group === group)) {
|
|
it(testCase.name, () => testCase.run());
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
let currentDirectory: string | undefined;
|
|
let currentSharedDirectory: string | undefined;
|
|
|
|
async function createConformanceRepo() {
|
|
currentDirectory = await mkdtemp(join(tmpdir(), "pi-sqlite-session-repo-conformance-"));
|
|
return new SqliteSessionRepo({
|
|
directory: currentDirectory,
|
|
databaseFactory: createNodeSqliteFactory(),
|
|
now: () => NOW,
|
|
});
|
|
}
|
|
|
|
async function createSharedContainerConformanceRepo() {
|
|
currentSharedDirectory = await mkdtemp(join(tmpdir(), "pi-sqlite-session-repo-shared-conformance-"));
|
|
return new SqliteSessionRepo({
|
|
directory: currentSharedDirectory,
|
|
databasePath: join(currentSharedDirectory, "sessions.sqlite"),
|
|
databaseFactory: createNodeSqliteFactory(),
|
|
now: () => NOW,
|
|
});
|
|
}
|
|
|
|
async function cleanupConformanceRepo() {
|
|
if (currentDirectory === undefined) return;
|
|
await rm(currentDirectory, { recursive: true, force: true });
|
|
currentDirectory = undefined;
|
|
}
|
|
|
|
async function cleanupSharedContainerConformanceRepo() {
|
|
if (currentSharedDirectory === undefined) return;
|
|
await rm(currentSharedDirectory, { recursive: true, force: true });
|
|
currentSharedDirectory = undefined;
|
|
}
|
|
|
|
registerConformance(
|
|
"SqliteSessionRepo conformance",
|
|
createSessionRepoConformance(createConformanceRepo, cleanupConformanceRepo),
|
|
);
|
|
|
|
registerConformance(
|
|
"SqliteSessionRepo shared-container conformance",
|
|
createSessionRepoConformance(createSharedContainerConformanceRepo, cleanupSharedContainerConformanceRepo),
|
|
);
|