- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/test/record-stream.test.ts?format=json
44 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 175, 1 version changed it
1import assert from "node:assert/strict";
2import { it } from "node:test";
3import { Repo } from "../../../src/engine/test/helpers.ts";
4import type { AgentState } from "../project-types.ts";
5import { type RecordFileHost, recordFile } from "../record-file.ts";
7it("records replacements without materializing old file text or line arrays", () => {
8 const view = Repo.init({ "large.txt": `${"x".repeat(100000)}\nkeep\n` }).view();
9 view.text = () => {
10 throw Error("whole old text is forbidden");
11 };
12 view.lines = () => {
13 throw Error("old line array is forbidden");
14 };
15 const calls: Parameters<RecordFileHost["addDraft"]>[2][] = [];
16 const host: RecordFileHost = {
17 addDraft(_agent, _view, input) {
18 calls.push(input);
19 },
20 };
21 const agent: AgentState = {
22 name: "writer",
23 space: "",
24 base: 0,
25 synced: true,
26 mine: [],
27 news: [],
28 newsAt: [],
29 told: new Set(),
30 parked: new Map(),
31 marked: [],
32 };
33 assert.equal(recordFile(host, agent, view, "large.txt", "changed\nkeep\n", 1, {}, []), true);
34 assert.deepEqual(calls[0]!.edits, [{ file: "large.txt", start: 0, end: 1, lines: ["changed"] }]);
35 const unchanged = `${"x".repeat(100000)}\nkeep\n`;
36 assert.equal(recordFile(host, agent, view, "large.txt", unchanged, 1, {}, []), false);
37 assert.equal(
38 recordFile(host, agent, view, "large.txt", unchanged, 1, {}, [], {}, undefined, [
39 { start: 0, end: 1, lines: ["ignored"] },
40 ]),
41 false,
42 );
43 assert.equal(calls.length, 1);
44});