- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/packed-files.test.ts?version=261&format=json
56 linescapacity 98% · codex-capacity-chair 2%Last change capacity in version 206, 1 version changed it
You're reading version 261. The newest is 318, and 1 version since then changed this file.
1// Each file's line history packed (abso Capacity, Graph.packedLines): a stored graph lays files out from a few pages,
2// and must give exactly what the in-memory graph gives, through edits, deletes, moves between files and back.
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { Graph, View } from "../index.ts";
7import { StableOverlaySet } from "../state-source.ts";
8import { lines, Repo } from "./helpers.ts";
9import { SqlState } from "./storage-helper.ts";
11test("a packed file lays out as the in-memory graph does, at every step, moves included", () => {
12 const oracle = Repo.init({ "a.txt": lines("one", "two", "three", "four"), "b.txt": lines("bee"), "c.txt": "" });
13 const sets: Set<string>[] = [new Set(oracle.shared)];
14 const step = (change: Parameters<Repo["edit"]>[0]) => {
15 oracle.edit(change);
16 sets.push(new Set(oracle.shared));
17 };
18 step({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
19 step({ move: { file: "a.txt", start: 1, end: 3, to: "b.txt", at: 1 } });
20 step({ edits: [{ file: "b.txt", old: "TWO", new: "two again" }] });
21 step({ edits: [{ file: "a.txt", old: "four", new: "" }] });
22 step({ move: { file: "b.txt", start: 0, end: 2, to: "c.txt", at: 0 } });
23 step({ edits: [{ file: "c.txt", old: "bee", new: "bee\nafter bee" }] });
24 const storage = new SqlState();
25 try {
26 const graph = new Graph({ storage });
27 for (const atom of oracle.graph.atoms()) graph.add(atom);
28 const reopened = new Graph({ storage });
29 assert.equal(reopened.packedFiles, true);
30 for (const [i, set] of sets.entries()) {
31 const packed = new View(reopened, new StableOverlaySet(set));
32 const memory = new View(oracle.graph, set);
33 assert.deepEqual(packed.paths(), memory.paths(), `step ${i}: paths`);
34 for (const path of ["a.txt", "b.txt", "c.txt"]) {
35 assert.equal(packed.text(path), memory.text(path), `step ${i}: ${path}`);
36 assert.deepEqual(packed.sequence(path), memory.sequence(path), `step ${i}: ${path}'s sequence`);
37 assert.deepEqual(packed.attrs(path), memory.attrs(path), `step ${i}: ${path}'s attributes`);
38 }
39 }
40 } finally {
41 storage.db.close();
42 }
43});
45test("a graph made with packFiles off keeps no packed history", () => {
46 const oracle = Repo.init({ "a.txt": lines("one") });
47 const storage = new SqlState();
48 try {
49 const graph = new Graph({ storage, packFiles: false });
50 for (const atom of oracle.graph.atoms()) graph.add(atom);
51 assert.equal(new Graph({ storage }).packedFiles, false);
52 assert.equal(new View(new Graph({ storage }), new StableOverlaySet(oracle.shared)).text("a.txt"), "one\n");
53 } finally {
54 storage.db.close();
55 }
56});