mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(agent): add SQLite storage conformance coverage
This commit is contained in:
parent
893d82525f
commit
75bb6a0fcd
2 changed files with 63 additions and 0 deletions
|
|
@ -0,0 +1,59 @@
|
|||
import {
|
||||
type ConformanceCase,
|
||||
createStorageConformance,
|
||||
type StorageFixture,
|
||||
} from "@earendil-works/pi-agent-core/session/testing";
|
||||
import { describe, it } from "vitest";
|
||||
import { createNodeSqliteFactory, SQLITE_STORAGE_VERSION, SqliteStorage, sql } from "../src/index.ts";
|
||||
import { applyInitialSchema } from "../src/sqlite/migrations.ts";
|
||||
|
||||
const NOW = 1_700_000_000_000;
|
||||
const EMPTY_USAGE = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
totalTokens: 0,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
||||
};
|
||||
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
registerConformance(
|
||||
"SqliteStorage conformance",
|
||||
createStorageConformance(async () => {
|
||||
const db = await createNodeSqliteFactory().open(":memory:");
|
||||
try {
|
||||
await applyInitialSchema(db);
|
||||
sql`INSERT INTO session
|
||||
(created_at, parent_session_id, storage_version, metadata, message_count, usage_payload, next_seq)
|
||||
VALUES (${NOW}, ${null}, ${SQLITE_STORAGE_VERSION}, ${null}, ${0}, ${JSON.stringify(EMPTY_USAGE)}, ${1})`.run(
|
||||
db,
|
||||
);
|
||||
const storage = new SqliteStorage(db, { now: () => NOW });
|
||||
return {
|
||||
storage,
|
||||
async [Symbol.asyncDispose]() {
|
||||
try {
|
||||
await storage.close();
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
},
|
||||
} satisfies StorageFixture;
|
||||
} catch (error) {
|
||||
db.close();
|
||||
throw error;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -5,6 +5,9 @@ const telemetryIndex = fileURLToPath(new URL("../../telemetry/src/index.ts", imp
|
|||
const aiIndex = fileURLToPath(new URL("../../ai/src/index.ts", import.meta.url));
|
||||
const agentIndex = fileURLToPath(new URL("../../agent/src/index.ts", import.meta.url));
|
||||
const agentNode = fileURLToPath(new URL("../../agent/src/node.ts", import.meta.url));
|
||||
const agentSessionTesting = fileURLToPath(
|
||||
new URL("../../agent/src/harness/session/testing/index.ts", import.meta.url),
|
||||
);
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
|
|
@ -24,6 +27,7 @@ export default defineConfig({
|
|||
alias: [
|
||||
{ find: /^@earendil-works\/pi-telemetry$/, replacement: telemetryIndex },
|
||||
{ find: /^@earendil-works\/pi-agent-core\/node$/, replacement: agentNode },
|
||||
{ find: /^@earendil-works\/pi-agent-core\/session\/testing$/, replacement: agentSessionTesting },
|
||||
{ find: /^@earendil-works\/pi-agent-core$/, replacement: agentIndex },
|
||||
{ find: /^@earendil-works\/pi-ai$/, replacement: aiIndex },
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue