mirror of
https://github.com/earendil-works/pi.git
synced 2026-10-02 00:35:27 +08:00
feat(agent): isolate JSONL repository conformance tests
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, it } from "vitest";
|
||||
import { NodeExecutionEnv } from "../../src/harness/env/nodejs.ts";
|
||||
import { type JsonlSessionMetadata, JsonlSessionRepo } from "../../src/harness/session/jsonl/index.ts";
|
||||
import {
|
||||
type ConformanceCase,
|
||||
createSessionRepoLifecycleConformance,
|
||||
createSessionRepoMessageConformance,
|
||||
} from "../../src/harness/session/testing/index.ts";
|
||||
import { createTempDir } from "./session-test-utils.ts";
|
||||
|
||||
const NOW = 1_700_000_000_000;
|
||||
const CONFORMANCE_CWD = "/workspace";
|
||||
|
||||
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 jsonlRepo: JsonlSessionRepo;
|
||||
async function createConformanceRepo() {
|
||||
const fileSystem = new NodeExecutionEnv({ cwd: createTempDir() });
|
||||
jsonlRepo = new JsonlSessionRepo({ fileSystem, sessionsRoot: "sessions", now: () => NOW });
|
||||
return {
|
||||
create: (options: { id?: string; parentSessionId?: string }) =>
|
||||
jsonlRepo.create({ ...options, cwd: CONFORMANCE_CWD }),
|
||||
open: (metadata: JsonlSessionMetadata) => jsonlRepo.open(metadata),
|
||||
list: () => jsonlRepo.list({ cwd: CONFORMANCE_CWD }),
|
||||
delete: (metadata: JsonlSessionMetadata) => jsonlRepo.delete(metadata),
|
||||
};
|
||||
}
|
||||
|
||||
registerConformance("JsonlSessionRepo conformance", [
|
||||
...createSessionRepoLifecycleConformance<JsonlSessionMetadata>(createConformanceRepo, () => jsonlRepo.close()),
|
||||
...createSessionRepoMessageConformance<JsonlSessionMetadata>(createConformanceRepo, () => jsonlRepo.close()),
|
||||
]);
|
||||
@@ -1,50 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { NodeExecutionEnv } from "../../src/harness/env/nodejs.ts";
|
||||
import {
|
||||
JSONL_STORAGE_VERSION,
|
||||
type JsonlSessionMetadata,
|
||||
JsonlSessionRepo,
|
||||
} from "../../src/harness/session/jsonl/index.ts";
|
||||
import {
|
||||
type ConformanceCase,
|
||||
createSessionRepoLifecycleConformance,
|
||||
createSessionRepoMessageConformance,
|
||||
} from "../../src/harness/session/testing/index.ts";
|
||||
import { JSONL_STORAGE_VERSION, JsonlSessionRepo } from "../../src/harness/session/jsonl/index.ts";
|
||||
import { getOrThrow } from "../../src/harness/types.ts";
|
||||
import { createTempDir } from "./session-test-utils.ts";
|
||||
|
||||
const NOW = 1_700_000_000_000;
|
||||
const CONFORMANCE_CWD = "/workspace";
|
||||
|
||||
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 jsonlRepo: JsonlSessionRepo;
|
||||
async function createConformanceRepo() {
|
||||
const fileSystem = new NodeExecutionEnv({ cwd: createTempDir() });
|
||||
jsonlRepo = new JsonlSessionRepo({ fileSystem, sessionsRoot: "sessions", now: () => NOW });
|
||||
return {
|
||||
create: (options: { id?: string; parentSessionId?: string }) =>
|
||||
jsonlRepo.create({ ...options, cwd: CONFORMANCE_CWD }),
|
||||
open: (metadata: JsonlSessionMetadata) => jsonlRepo.open(metadata),
|
||||
list: () => jsonlRepo.list({ cwd: CONFORMANCE_CWD }),
|
||||
delete: (metadata: JsonlSessionMetadata) => jsonlRepo.delete(metadata),
|
||||
};
|
||||
}
|
||||
|
||||
registerConformance("JsonlSessionRepo conformance", [
|
||||
...createSessionRepoLifecycleConformance<JsonlSessionMetadata>(createConformanceRepo, () => jsonlRepo.close()),
|
||||
...createSessionRepoMessageConformance<JsonlSessionMetadata>(createConformanceRepo, () => jsonlRepo.close()),
|
||||
]);
|
||||
|
||||
describe("JsonlSessionRepo cwd-scoped lifecycle", () => {
|
||||
it("persists metadata and filters discovery by cwd", async () => {
|
||||
|
||||
Reference in New Issue
Block a user