Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 158 to 318

Compare

+66 −0 in 1 place
new file, 66 lines
1+import assert from "node:assert/strict";
2+import { createHash } from "node:crypto";
3+import { test } from "node:test";
4+import { equalJsonValues, jsonValueChunks } from "../json-value-chunks.ts";
5+
6+test("canonical JSON chunks preserve scalar, container and toJSON encoding", () => {
7+ const values = [
8+ null,
9+ true,
10+ false,
11+ 0,
12+ -0,
13+ 1.25,
14+ NaN,
15+ Infinity,
16+ { z: undefined, a: [undefined, null, 'quoted"\n\t\\', "\ud800", "\udc00", "\u2028\u2029"] },
17+ new Array(3),
18+ { 20: "twenty", 2: "two", before: 1, after: 2 },
19+ {
20+ nested: {
21+ toJSON(key: string) {
22+ return { key, value: "converted" };
23+ },
24+ },
25+ },
26+ JSON.parse('{"__proto__":"data","constructor":"also data"}'),
27+ ];
28+ for (const value of values) assert.equal([...jsonValueChunks(value)].join(""), JSON.stringify(value));
29+ for (const left of values)
30+ for (const right of values)
31+ assert.equal(equalJsonValues(left, right), JSON.stringify(left) === JSON.stringify(right));
32+});
34+test("canonical JSON string chunks preserve every surrogate split and bound escaped output", () => {
35+ for (const offset of [16382, 16383, 16384, 16385]) {
36+ const value = { text: `${"a".repeat(offset)}\ud83d\ude80${"\u0000".repeat(40000)}\ud800` };
37+ const hash = createHash("sha256");
38+ for (const chunk of jsonValueChunks(value)) {
39+ assert.ok(chunk.length <= 16384 * 6);
40+ hash.update(chunk);
41+ }
42+ assert.equal(hash.digest("hex"), createHash("sha256").update(JSON.stringify(value)).digest("hex"));
43+ }
44+});
46+test("canonical JSON visits large arrays incrementally and rejects cycles", () => {
47+ let reads = 0;
48+ const values = new Proxy(new Array(10000), {
49+ get(target, key, receiver) {
50+ if (typeof key === "string" && /^[0-9]+$/.test(key)) {
51+ reads++;
52+ return Number(key);
53+ }
54+ return Reflect.get(target, key, receiver);
55+ },
56+ });
57+ const chunks = jsonValueChunks(values);
58+ assert.equal(chunks.next().value, "[");
59+ assert.equal(reads, 0);
60+ assert.equal(chunks.next().value, "0");
61+ assert.equal(reads, 1);
62+ chunks.return?.();
63+ const cyclic: unknown[] = [];
64+ cyclic.push(cyclic);
65+ assert.throws(() => [...jsonValueChunks(cyclic)], /cyclic/);
66+});
MCP
compare on this site's /mcp
CLI
abso diff 158 318 src/engine/test/json-value-chunks.test.ts --json
JSON
/christopher/abso-core/compare/158..318?file=src%2Fengine%2Ftest%2Fjson-value-chunks.test.ts&format=json