- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/graph-index-dedup.test.ts?format=json
64 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 162, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase, Graph } from "../index.ts";
4import { lineKey } from "../keys.ts";
5import { storedLists } from "../state-source.ts";
6import type { Atom } from "../types.ts";
7import { SqlState } from "./storage-helper.ts";
9test("persistent key indexes deduplicate repeated keys without per-atom key sets", () => {
10 const storage = new SqlState();
11 try {
12 const graph = new Graph({ storage });
13 graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 }));
14 const keys = Array.from({ length: 513 }, () => lineKey("a0.0"));
15 const atom: Atom = {
16 id: "a1",
17 seq: 1,
18 author: "fixture",
19 message: "keys",
20 time: 1,
21 inserts: [],
22 deletes: [],
23 writes: keys,
24 reads: keys,
25 holds: keys,
26 needs: [],
27 resolves: ["a0", "a0"],
28 reasons: [],
29 deps: ["a0"],
30 };
31 graph.add(atom);
32 for (const collection of ["writers", "readers", "holders", "resolvers"]) {
33 const index = storedLists<string>(storage, collection, (key) => key);
34 let matches = 0;
35 for (const key of index.keys()) {
36 const values = [...index.values(key)];
37 const count = values.filter((value) => value === "a1").length;
38 assert.ok(count <= 1);
39 matches += count;
40 }
41 assert.equal(matches, 1, collection);
42 }
43 } finally {
44 storage.db.close();
45 }
46});
48test("last list entry reads only its final page and rejects truncated pages", () => {
49 const storage = new SqlState();
50 try {
51 const list = storedLists<number>(storage, "items");
52 for (let i = 0; i < 513; i++) list.append("key", i);
53 const read = storage.read.bind(storage);
54 storage.read = (collection, key) => {
55 if (collection === "items:pages") assert.equal(key, JSON.stringify(["key", 2]));
56 return read(collection, key);
57 };
58 assert.equal(list.last("key"), 512);
59 storage.write("items:pages", JSON.stringify(["key", 2]), [512, 513]);
60 assert.throws(() => list.last("key"), /incomplete writer list page/);
61 } finally {
62 storage.db.close();
63 }
64});