File size: 1,785 Bytes
eabe4e2 d7b7920 eabe4e2 4885488 d7b7920 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import test from "node:test";
import assert from "node:assert/strict";
import { parseTrace, compareBranch, parseExchange, toExchange, attachFindings } from "../replay-core.js";
const trace = { schema_version: "deltastore-replay-trace-v1", trace_id: "t", original_trajectory: [{event_id:"e1"},{event_id:"e2"}], checkpoints: [{checkpoint_id:"c1",event_id:"e2"}], branches: [{branch_id:"b",parent_checkpoint_id:"c1",events:[{event_id:"b1"}],final_outcome:{task_success:true}}], final_outcome:{task_success:false} };
test("parses and compares a checkpoint branch", () => {
const parsed = parseTrace(trace);
const comparison = compareBranch(parsed, "b");
assert.equal(comparison.sharedPrefix.length, 2);
assert.equal(comparison.alternate[0].event_id, "b1");
});
test("rejects unsupported traces", () => {
assert.throws(() => parseTrace({ schema_version: "wrong" }));
});
test("validates exchange findings locally", () => {
const exchange = { schema_version: "solstice-agent-trace-exchange/v1", trace_id: "t", events: [{event_id:"e1",sequence:1,event_type:"message"}], findings: [], checkpoints: [], branches: [], source:{}, task:{}, outcomes:{}, redaction:{}, provenance:{} };
const enriched = attachFindings(parseExchange(exchange), [{trace_id:"t", category:"injection", evidence_refs:["e1"]}]);
assert.equal(enriched.findings.length, 1);
assert.throws(() => attachFindings(exchange, [{trace_id:"other", evidence_refs:["e1"]}]));
});
test("converts the bundled legacy demo to exchange v1", () => {
const exchange = toExchange(trace);
assert.equal(exchange.schema_version, "solstice-agent-trace-exchange/v1");
assert.equal(exchange.events[0].event_id, "e1");
assert.equal(exchange.branches[0].branch_id, "b");
assert.equal(exchange.findings.length, 0);
});
|