59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { StateStore } from "../core/state-store.js";
|
|
import { PersistentMemory } from "./persistent-memory.js";
|
|
|
|
function tmpStore() {
|
|
return new StateStore(fs.mkdtempSync(path.join(os.tmpdir(), "fable-memory-")));
|
|
}
|
|
|
|
describe("persistent memory provenance", () => {
|
|
it("ranks receipt-backed verified memories before stale unverified memory", () => {
|
|
const memory = new PersistentMemory(tmpStore());
|
|
memory.recordEpisode({
|
|
sessionId: "old",
|
|
task: "factory containers",
|
|
summary: "stale memory says 25 containers",
|
|
iterations: 1,
|
|
finalQuality: 0.5,
|
|
keyEvents: [],
|
|
tags: ["factory"],
|
|
observed_at: "2026-06-18T00:00:00.000Z",
|
|
verification: "unverified",
|
|
});
|
|
memory.recordEpisode({
|
|
sessionId: "new",
|
|
task: "factory containers",
|
|
summary: "live receipt says 16 containers",
|
|
iterations: 1,
|
|
finalQuality: 1,
|
|
keyEvents: [],
|
|
tags: ["factory"],
|
|
observed_at: "2026-06-26T00:00:00.000Z",
|
|
verification: "verified",
|
|
receipt_id: "verify-cycle:live",
|
|
});
|
|
|
|
const [first] = memory.queryEpisodic({ tags: ["factory"] });
|
|
expect(first.summary).toContain("16 containers");
|
|
expect(first.receipt_id).toBe("verify-cycle:live");
|
|
});
|
|
|
|
it("filters superseded memories from recall", () => {
|
|
const memory = new PersistentMemory(tmpStore());
|
|
memory.recordEpisode({
|
|
sessionId: "old",
|
|
task: "deploy route",
|
|
summary: "8098 is deploy authority",
|
|
iterations: 1,
|
|
finalQuality: 0.1,
|
|
keyEvents: [],
|
|
tags: ["deploy"],
|
|
status: "superseded",
|
|
});
|
|
expect(memory.queryEpisodic({ tags: ["deploy"] })).toEqual([]);
|
|
});
|
|
});
|