@criogaid/pi-hashline-edit 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -220
- package/README.zh-CN.md +166 -0
- package/package.json +2 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/apply.test.ts +171 -133
- package/src/core/apply.ts +34 -31
- package/src/core/case-fold.test.ts +11 -7
- package/src/core/case-fold.ts +2 -6
- package/src/core/character-set.ts +14 -0
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +25 -7
- package/src/core/ranges.test.ts +49 -9
- package/src/core/ranges.ts +15 -4
- package/src/core/regex.ts +36 -6
- package/src/core/replace-schema.ts +18 -11
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +6 -5
- package/src/core/search-analysis.test.ts +9 -0
- package/src/core/search-analysis.ts +35 -31
- package/src/core/search.ts +1 -1
- package/src/core/types.ts +6 -8
- package/src/index.ts +2 -4
- package/src/integration/config-registration.test.ts +18 -10
- package/src/integration/fusion-dispatch.test.ts +41 -22
- package/src/integration/grep-flags.test.ts +6 -13
- package/src/integration/grep-js-completeness.test.ts +41 -31
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +4 -3
- package/src/integration/grep-regex.test.ts +13 -16
- package/src/integration/grep-rg.test.ts +132 -92
- package/src/integration/grep-scan-budget.test.ts +27 -5
- package/src/integration/large-text.test.ts +4 -5
- package/src/integration/model-budget-lifecycle.test.ts +26 -8
- package/src/integration/mutation-file-types.test.ts +0 -1
- package/src/integration/mutation-file-types.testing.ts +2 -2
- package/src/integration/npm-package.testing.ts +7 -33
- package/src/integration/publication-read-changes.test.ts +60 -28
- package/src/integration/replace-package.testing.ts +4 -1
- package/src/integration/replace-worker-boundary.test.ts +34 -24
- package/src/integration/report-replay.test.ts +3 -3
- package/src/integration/utf8-errors.test.ts +3 -3
- package/src/pi/AGENTS.md +13 -14
- package/src/pi/action-fusion.test.ts +75 -220
- package/src/pi/action-fusion.ts +37 -74
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +7 -3
- package/src/pi/argument-diagnostics.ts +35 -186
- package/src/pi/argument-error.testing.ts +7 -4
- package/src/pi/argument-error.ts +5 -7
- package/src/pi/argument-format.test.ts +25 -38
- package/src/pi/argument-validation.test.ts +446 -420
- package/src/pi/argument-validation.ts +4 -5
- package/src/pi/budgets.ts +5 -7
- package/src/pi/config.test.ts +15 -5
- package/src/pi/config.ts +6 -6
- package/src/pi/diagnostic-buffer.test.ts +2 -3
- package/src/pi/diagnostic-buffer.ts +2 -2
- package/src/pi/edit-tool.ts +175 -121
- package/src/pi/execute.test.ts +170 -227
- package/src/pi/failure-context.test.ts +61 -16
- package/src/pi/failure-context.ts +13 -10
- package/src/pi/failure-path.test.ts +115 -50
- package/src/pi/file-commit.test.ts +30 -46
- package/src/pi/file-commit.ts +11 -40
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +193 -37
- package/src/pi/fusion-card.ts +186 -116
- package/src/pi/grep-candidates.ts +25 -27
- package/src/pi/grep-matrix.test.ts +1 -1
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +62 -69
- package/src/pi/grep-render.ts +4 -1
- package/src/pi/grep-scope.ts +1 -1
- package/src/pi/grep-search.ts +85 -56
- package/src/pi/grep-tool.ts +17 -48
- package/src/pi/grep.test.ts +271 -170
- package/src/pi/mutation-outcome.testing.ts +2 -3
- package/src/pi/mutation-result.test.ts +26 -19
- package/src/pi/mutation-result.ts +25 -40
- package/src/pi/mutation-runner.ts +9 -17
- package/src/pi/output-budgets.test.ts +27 -18
- package/src/pi/path.ts +3 -1
- package/src/pi/pi.test.ts +7 -6
- package/src/pi/read-tool.ts +32 -80
- package/src/pi/read.test.ts +145 -92
- package/src/pi/regex-worker-contract.ts +5 -23
- package/src/pi/regex-worker.ts +4 -10
- package/src/pi/registration.test.ts +106 -67
- package/src/pi/render.test.ts +239 -109
- package/src/pi/render.ts +42 -22
- package/src/pi/replace-regex.ts +3 -5
- package/src/pi/replace-tool.ts +29 -27
- package/src/pi/replace-worker-contract.ts +3 -12
- package/src/pi/replace.test.ts +144 -226
- package/src/pi/report-cause.ts +23 -19
- package/src/pi/report-failure.testing.ts +2 -2
- package/src/pi/report-schema.ts +60 -45
- package/src/pi/report.test.ts +138 -71
- package/src/pi/report.ts +40 -43
- package/src/pi/result-safety.test.ts +186 -131
- package/src/pi/rg-process.test.ts +36 -10
- package/src/pi/rg-process.ts +9 -3
- package/src/pi/rg-regex.test.ts +17 -0
- package/src/pi/rg-regex.ts +28 -22
- package/src/pi/text-stream.test.ts +35 -36
- package/src/pi/text-stream.ts +14 -14
- package/src/pi/tool-call.testing.ts +17 -7
- package/src/pi/write-tool.ts +9 -11
- package/src/pi/write.test.ts +43 -75
- package/src/testing/regex-translation-corpus.ts +16 -0
- package/src/testing/rg-line-listing.fixture.mjs +1 -1
- package/src/integration/forget-grep.test.ts +0 -148
- package/src/pi/forget-tool.ts +0 -367
- package/src/pi/forget.test.ts +0 -630
- package/src/pi/forget.testing.ts +0 -201
package/src/pi/execute.test.ts
CHANGED
|
@@ -15,11 +15,10 @@ import { makeReplaceTool } from "./replace-tool.ts";
|
|
|
15
15
|
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
16
16
|
import { computeLineHash } from "../core/hash.ts";
|
|
17
17
|
import { splitLines } from "../core/lines.ts";
|
|
18
|
-
import { byteRevision } from "./file-commit.ts";
|
|
19
18
|
import { callTool } from "./tool-call.testing.ts";
|
|
20
19
|
import { DEFAULT_CONFIG } from "./config.ts";
|
|
21
|
-
import {
|
|
22
|
-
import { reportOf } from "./report.ts";
|
|
20
|
+
import { formatByteSize, DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
|
|
21
|
+
import { detailsReport, reportOf } from "./report.ts";
|
|
23
22
|
import type { Report } from "./report-schema.ts";
|
|
24
23
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
25
24
|
|
|
@@ -49,11 +48,24 @@ function anchorLine(block: string, line: number) {
|
|
|
49
48
|
|
|
50
49
|
function failureReport(result: AgentToolResult<unknown> & { isError?: boolean }): Report {
|
|
51
50
|
assert.equal(result.isError, true);
|
|
52
|
-
const report =
|
|
51
|
+
const report = detailsReport(result.details);
|
|
53
52
|
assert.ok(report?.error);
|
|
54
53
|
return report;
|
|
55
54
|
}
|
|
56
55
|
|
|
56
|
+
test("edit guidance → refreshes anchors after content changes and line shifts", () => {
|
|
57
|
+
const guidance = makeEditOverride(process.cwd(), DEFAULT_CONFIG).promptGuidelines.join("\n");
|
|
58
|
+
assert.match(guidance, /after edit or replace.*before citing any line it changed/i);
|
|
59
|
+
assert.match(
|
|
60
|
+
guidance,
|
|
61
|
+
/added or removed lines.*refresh anchors below the earliest affected line/i,
|
|
62
|
+
);
|
|
63
|
+
assert.match(
|
|
64
|
+
guidance,
|
|
65
|
+
/affected positions are unknown.*read or grep the lines you intend to cite/i,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
57
69
|
test("edit execute: a file without a final newline stays byte-exact", async () => {
|
|
58
70
|
await withDir(async (dir) => {
|
|
59
71
|
const f = join(dir, "f.txt");
|
|
@@ -65,7 +77,7 @@ test("edit execute: a file without a final newline stays byte-exact", async () =
|
|
|
65
77
|
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
66
78
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
67
79
|
path: "f.txt",
|
|
68
|
-
edits: [{
|
|
80
|
+
edits: [{ action: "replace", anchor: h(text, 2), body: ["new value\u2060"] }],
|
|
69
81
|
});
|
|
70
82
|
assert.equal(r.isError, undefined, "should not be an error");
|
|
71
83
|
assert.equal(await readFile(f, "utf-8"), "guard\nnew value\u2060");
|
|
@@ -77,10 +89,10 @@ test("edit execute: hashline round-trip (read → edit → file changed)", async
|
|
|
77
89
|
const f = join(dir, "f.txt");
|
|
78
90
|
const text = "a\nb\nc\n";
|
|
79
91
|
await writeFile(f, text);
|
|
80
|
-
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
92
|
+
const read = await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
81
93
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
82
94
|
path: "f.txt",
|
|
83
|
-
edits: [{
|
|
95
|
+
edits: [{ action: "replace", anchor: anchorLine(read.content[0].text, 2), body: ["B"] }],
|
|
84
96
|
});
|
|
85
97
|
assert.equal(r.isError, undefined, "should not be an error");
|
|
86
98
|
assert.equal(await readFile(f, "utf-8"), "a\nB\nc\n");
|
|
@@ -96,8 +108,8 @@ test("edit execute: multiple ops in one call", async () => {
|
|
|
96
108
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
97
109
|
path: "f.txt",
|
|
98
110
|
edits: [
|
|
99
|
-
{
|
|
100
|
-
{
|
|
111
|
+
{ action: "insert_after", anchor: h(text, 3), body: ["z"] },
|
|
112
|
+
{ action: "replace", anchor: h(text, 1), body: ["A"] },
|
|
101
113
|
],
|
|
102
114
|
});
|
|
103
115
|
assert.equal(r.isError, undefined);
|
|
@@ -128,7 +140,7 @@ test("successful mutation → returns one report without anchor payload", async
|
|
|
128
140
|
path,
|
|
129
141
|
edits: [
|
|
130
142
|
{
|
|
131
|
-
|
|
143
|
+
action: "replace",
|
|
132
144
|
anchor: anchorLine(rows, 1),
|
|
133
145
|
end: anchorLine(rows, count),
|
|
134
146
|
body: Array.from({ length: count }, () => "new"),
|
|
@@ -139,7 +151,10 @@ test("successful mutation → returns one report without anchor payload", async
|
|
|
139
151
|
: tool === "replace"
|
|
140
152
|
? {
|
|
141
153
|
instance: makeReplaceTool(dir, DEFAULT_CONFIG),
|
|
142
|
-
params: {
|
|
154
|
+
params: {
|
|
155
|
+
path,
|
|
156
|
+
replacements: [{ literal: true, find: "old", replace: "new" }],
|
|
157
|
+
},
|
|
143
158
|
}
|
|
144
159
|
: {
|
|
145
160
|
instance: makeWriteOverride(dir),
|
|
@@ -154,7 +169,10 @@ test("successful mutation → returns one report without anchor payload", async
|
|
|
154
169
|
publication: "PUBLISHED",
|
|
155
170
|
...(tool === "replace" ? { matches: count } : {}),
|
|
156
171
|
});
|
|
157
|
-
if (tool !== "write")
|
|
172
|
+
if (tool !== "write") {
|
|
173
|
+
assert.ok("diff" in result.details && typeof result.details.diff === "string");
|
|
174
|
+
assert.match(result.details.diff, /new/);
|
|
175
|
+
} else assert.deepEqual(result.details, { report: reportOf(result, "write") });
|
|
158
176
|
}),
|
|
159
177
|
);
|
|
160
178
|
}
|
|
@@ -170,7 +188,7 @@ test("unrelated external change does NOT block an edit on a stable line", async
|
|
|
170
188
|
await writeFile(f, "a\nb\nCHANGED\n");
|
|
171
189
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
172
190
|
path: "f.txt",
|
|
173
|
-
edits: [{
|
|
191
|
+
edits: [{ action: "replace", anchor: h(text, 1), body: ["A"] }],
|
|
174
192
|
});
|
|
175
193
|
assert.equal(r.isError, undefined);
|
|
176
194
|
assert.equal(await readFile(f, "utf-8"), "A\nb\nCHANGED\n");
|
|
@@ -186,7 +204,7 @@ test("edit on a line that changed externally → anchor mismatch", async () => {
|
|
|
186
204
|
const report = failureReport(
|
|
187
205
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
188
206
|
path: "f.txt",
|
|
189
|
-
edits: [{
|
|
207
|
+
edits: [{ action: "replace", anchor: h(text, 2), body: ["x"] }],
|
|
190
208
|
}),
|
|
191
209
|
);
|
|
192
210
|
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
@@ -207,7 +225,7 @@ test("unresolved observations require target confirmation before retrying a move
|
|
|
207
225
|
const report = failureReport(
|
|
208
226
|
await call(edit, {
|
|
209
227
|
path: "recover.txt",
|
|
210
|
-
edits: [{
|
|
228
|
+
edits: [{ action: "replace", anchor: h(observed, 5), body: ["updated"] }],
|
|
211
229
|
}),
|
|
212
230
|
);
|
|
213
231
|
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
@@ -218,7 +236,7 @@ test("unresolved observations require target confirmation before retrying a move
|
|
|
218
236
|
const retryAnchor = anchorLine(read.content[0].text, 7);
|
|
219
237
|
await call(edit, {
|
|
220
238
|
path: "recover.txt",
|
|
221
|
-
edits: [{
|
|
239
|
+
edits: [{ action: "replace", anchor: retryAnchor, body: ["updated"] }],
|
|
222
240
|
});
|
|
223
241
|
assert.equal(
|
|
224
242
|
await readFile(file, "utf8"),
|
|
@@ -233,7 +251,7 @@ test("edit execute: no read before edit → anchor verification fails", async ()
|
|
|
233
251
|
const report = failureReport(
|
|
234
252
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
235
253
|
path: "f.txt",
|
|
236
|
-
edits: [{
|
|
254
|
+
edits: [{ action: "replace", anchor: "1#XXXX", body: ["A"] }],
|
|
237
255
|
}),
|
|
238
256
|
);
|
|
239
257
|
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
@@ -241,29 +259,6 @@ test("edit execute: no read before edit → anchor verification fails", async ()
|
|
|
241
259
|
});
|
|
242
260
|
});
|
|
243
261
|
|
|
244
|
-
test("edit execute: empty edits → throws", async () => {
|
|
245
|
-
await withDir(async (dir) => {
|
|
246
|
-
await writeFile(join(dir, "f.txt"), "a\n");
|
|
247
|
-
await assert.rejects(
|
|
248
|
-
call(makeEditOverride(dir, DEFAULT_CONFIG), { path: "f.txt", edits: [] }),
|
|
249
|
-
rejectsArguments("edit"),
|
|
250
|
-
);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test("edit execute: malformed op (replace without body) → throws", async () => {
|
|
255
|
-
await withDir(async (dir) => {
|
|
256
|
-
await writeFile(join(dir, "f.txt"), "a\n");
|
|
257
|
-
await assert.rejects(
|
|
258
|
-
call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
259
|
-
path: "f.txt",
|
|
260
|
-
edits: [{ op: "replace", anchor: "1#XXXX" }],
|
|
261
|
-
}),
|
|
262
|
-
/body/i,
|
|
263
|
-
);
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
262
|
test("edit execute: delete op", async () => {
|
|
268
263
|
await withDir(async (dir) => {
|
|
269
264
|
const f = join(dir, "f.txt");
|
|
@@ -272,37 +267,19 @@ test("edit execute: delete op", async () => {
|
|
|
272
267
|
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
273
268
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
274
269
|
path: "f.txt",
|
|
275
|
-
edits: [{
|
|
270
|
+
edits: [{ action: "delete", anchor: h(text, 2) }],
|
|
276
271
|
});
|
|
277
272
|
assert.equal(r.isError, undefined);
|
|
278
273
|
assert.equal(await readFile(f, "utf-8"), "a\nc\n");
|
|
279
274
|
});
|
|
280
275
|
});
|
|
281
276
|
|
|
282
|
-
// --- renderer regression guards (details.diff must be a string, renderResult must not throw) ---
|
|
283
|
-
|
|
284
277
|
const stubTheme = { fg: (_k: string, s: string) => s, bold: (s: string) => s } as Theme;
|
|
285
278
|
|
|
286
279
|
// renderResult delegates to pi's renderDiff, which reads the global TUI theme
|
|
287
280
|
// singleton — initialize it once for this test process (watcher off by default).
|
|
288
281
|
initTheme();
|
|
289
282
|
|
|
290
|
-
test("edit success: details.diff is a string (not the generateDiffString object)", async () => {
|
|
291
|
-
await withDir(async (dir) => {
|
|
292
|
-
const f = join(dir, "f.txt");
|
|
293
|
-
const text = "a\nb\nc\n";
|
|
294
|
-
await writeFile(f, text);
|
|
295
|
-
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
296
|
-
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
297
|
-
path: "f.txt",
|
|
298
|
-
edits: [{ op: "replace", anchor: h(text, 2), body: ["B"] }],
|
|
299
|
-
});
|
|
300
|
-
assert.equal(typeof r.details.diff, "string", "details.diff must be a string");
|
|
301
|
-
assert.equal(typeof r.details.patch, "string");
|
|
302
|
-
assert.equal(typeof r.details.firstChangedLine, "number");
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
283
|
test("native read and write renderers preserve resource titles, previews, and full errors", async () =>
|
|
307
284
|
withDir(async (dir) => {
|
|
308
285
|
const context = {
|
|
@@ -329,13 +306,7 @@ test("native read and write renderers preserve resource titles, previews, and fu
|
|
|
329
306
|
const error = write.renderResult(
|
|
330
307
|
{
|
|
331
308
|
content: [{ type: "text", text: "first error\nsecond error" }],
|
|
332
|
-
details: {
|
|
333
|
-
path: "preview.txt",
|
|
334
|
-
created: false,
|
|
335
|
-
publication: "NOT_PUBLISHED",
|
|
336
|
-
publishedRevision: "r",
|
|
337
|
-
observedRevision: "r",
|
|
338
|
-
},
|
|
309
|
+
details: {},
|
|
339
310
|
},
|
|
340
311
|
{ isPartial: false, expanded: false },
|
|
341
312
|
stubTheme,
|
|
@@ -352,28 +323,32 @@ test("edit schema rejects misspelled range fields and invalid operation shapes",
|
|
|
352
323
|
const anchor = h(original, 2);
|
|
353
324
|
const callArgs = {
|
|
354
325
|
path: "range.txt",
|
|
355
|
-
edits: [{
|
|
326
|
+
edits: [{ action: "replace", anchor, endd: h(original, 3), body: ["merged"] }],
|
|
356
327
|
};
|
|
357
328
|
await assert.rejects(call(edit, callArgs), rejectsArgument("edits[0].endd", /not allowed/));
|
|
358
329
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
|
|
359
|
-
for (const edits of [
|
|
360
|
-
[],
|
|
361
|
-
[{
|
|
362
|
-
[{
|
|
363
|
-
[{
|
|
364
|
-
[{
|
|
365
|
-
]) {
|
|
366
|
-
await assert.rejects(call(edit, { path: "range.txt", edits }),
|
|
330
|
+
for (const [edits, expected] of [
|
|
331
|
+
[[], rejectsArgument("edits")],
|
|
332
|
+
[[{ action: "replace", anchor }], rejectsArgument("edits[0].body", /required/)],
|
|
333
|
+
[[{ action: "delete", anchor, body: ["bad"] }], rejectsArguments()],
|
|
334
|
+
[[{ action: "insert_after", body: ["bad"] }], rejectsArguments()],
|
|
335
|
+
[[{ action: "append", anchor, body: ["bad"] }], rejectsArguments()],
|
|
336
|
+
] as const) {
|
|
337
|
+
await assert.rejects(call(edit, { path: "range.txt", edits }), expected);
|
|
367
338
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
|
|
368
339
|
}
|
|
369
340
|
const alternates: Parameters<typeof validateToolArguments>[1]["arguments"][] = [
|
|
370
|
-
{ path: "range.txt",
|
|
371
|
-
{ path: "range.txt", edits: JSON.stringify([{
|
|
341
|
+
{ path: "range.txt", action: "replace", anchor, body: ["ok"] },
|
|
342
|
+
{ path: "range.txt", edits: JSON.stringify([{ action: "replace", anchor, body: ["ok"] }]) },
|
|
372
343
|
];
|
|
373
344
|
for (const alternate of alternates) {
|
|
374
|
-
|
|
345
|
+
const before = structuredClone(alternate);
|
|
346
|
+
await assert.rejects(call(edit, alternate), rejectsArguments());
|
|
347
|
+
assert.deepEqual(alternate, before);
|
|
375
348
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
|
|
376
349
|
}
|
|
350
|
+
await call(edit, { path: "range.txt", edits: [{ action: "replace", anchor, body: ["B"] }] });
|
|
351
|
+
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), "a\nB\nc\n");
|
|
377
352
|
}));
|
|
378
353
|
|
|
379
354
|
test("copied string anchors validate and replace an inclusive range", async () =>
|
|
@@ -390,7 +365,7 @@ test("copied string anchors validate and replace an inclusive range", async () =
|
|
|
390
365
|
path: "range.txt",
|
|
391
366
|
edits: [
|
|
392
367
|
{
|
|
393
|
-
|
|
368
|
+
action: "replace",
|
|
394
369
|
anchor: anchorLine(read.content[0].text, 2),
|
|
395
370
|
end: anchorLine(read.content[0].text, 3),
|
|
396
371
|
body: ["merged"],
|
|
@@ -409,13 +384,13 @@ test("invalid anchors and conflicting fields fail before changing the file", asy
|
|
|
409
384
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
410
385
|
const anchor = h(original, 1);
|
|
411
386
|
const invalid = [
|
|
412
|
-
{
|
|
387
|
+
{ action: "replace", anchor: { line: 1, hash: anchor.split("#")[1] }, body: ["changed"] },
|
|
413
388
|
...["0#ABCD", "-1#ABCD", "1.5#ABCD", "1#", "1#abcd", "1#ABCD│a", "9007199254740993#ABCD"].map(
|
|
414
|
-
(anchor) => ({
|
|
389
|
+
(anchor) => ({ action: "replace", anchor, body: ["changed"] }),
|
|
415
390
|
),
|
|
416
|
-
{
|
|
417
|
-
{
|
|
418
|
-
{
|
|
391
|
+
{ action: "insert_after", anchor, end: anchor, body: ["changed"] },
|
|
392
|
+
{ action: "append", anchor, body: ["changed"] },
|
|
393
|
+
{ action: "delete", anchor, body: ["changed"] },
|
|
419
394
|
];
|
|
420
395
|
for (const operation of invalid) {
|
|
421
396
|
await assert.rejects(
|
|
@@ -434,11 +409,11 @@ test("edit rejects empty bodies before file access for arrays and Pi-converted o
|
|
|
434
409
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
435
410
|
const anchor = h(original, 1);
|
|
436
411
|
for (const operation of [
|
|
437
|
-
{
|
|
438
|
-
{
|
|
439
|
-
{
|
|
440
|
-
{
|
|
441
|
-
{
|
|
412
|
+
{ action: "insert_after", anchor, body: [] },
|
|
413
|
+
{ action: "insert_before", anchor, body: [] },
|
|
414
|
+
{ action: "append", body: [] },
|
|
415
|
+
{ action: "prepend", body: [] },
|
|
416
|
+
{ action: "replace", anchor, end: h(original, 2), body: [] },
|
|
442
417
|
]) {
|
|
443
418
|
for (const path of [file, join(dir, "missing.txt")]) {
|
|
444
419
|
for (const edits of [[operation], operation]) {
|
|
@@ -460,7 +435,7 @@ test("mixed empty-body batches name every rejected edit without publishing or ru
|
|
|
460
435
|
let commandRuns = 0;
|
|
461
436
|
const fusion = createActionFusionExecutor(async () => {
|
|
462
437
|
commandRuns++;
|
|
463
|
-
return { status: "succeeded",
|
|
438
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "ran" }] } };
|
|
464
439
|
});
|
|
465
440
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
466
441
|
await assert.rejects(
|
|
@@ -469,10 +444,10 @@ test("mixed empty-body batches name every rejected edit without publishing or ru
|
|
|
469
444
|
{
|
|
470
445
|
path: file,
|
|
471
446
|
edits: [
|
|
472
|
-
{
|
|
473
|
-
{
|
|
474
|
-
{
|
|
475
|
-
{
|
|
447
|
+
{ action: "replace", anchor: h(original, 1), body: ["must not be written"] },
|
|
448
|
+
{ action: "insert_before", anchor: h(original, 3), body: [] },
|
|
449
|
+
{ action: "append", body: ["must not be written"] },
|
|
450
|
+
{ action: "replace", anchor: h(original, 4), body: [] },
|
|
476
451
|
],
|
|
477
452
|
then_run: { command: "must-not-run" },
|
|
478
453
|
},
|
|
@@ -496,11 +471,11 @@ test("blank edit bodies preserve a real blank line for every body-bearing operat
|
|
|
496
471
|
const anchor = h(original, 1);
|
|
497
472
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
498
473
|
for (const [operation, expected] of [
|
|
499
|
-
[{
|
|
500
|
-
[{
|
|
501
|
-
[{
|
|
502
|
-
[{
|
|
503
|
-
[{
|
|
474
|
+
[{ action: "replace", anchor, body: [""] }, "\nb\nc\n"],
|
|
475
|
+
[{ action: "insert_before", anchor, body: [""] }, "\na\nb\nc\n"],
|
|
476
|
+
[{ action: "insert_after", anchor, body: [""] }, "a\n\nb\nc\n"],
|
|
477
|
+
[{ action: "append", body: [""] }, "a\nb\nc\n\n"],
|
|
478
|
+
[{ action: "prepend", body: [""] }, "\na\nb\nc\n"],
|
|
504
479
|
] as const) {
|
|
505
480
|
await writeFile(file, original);
|
|
506
481
|
await call(edit, { path: file, edits: [operation] });
|
|
@@ -515,7 +490,7 @@ test("explicit delete → removes an inclusive range", async () =>
|
|
|
515
490
|
await writeFile(file, original);
|
|
516
491
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
517
492
|
path: file,
|
|
518
|
-
edits: [{
|
|
493
|
+
edits: [{ action: "delete", anchor: h(original, 1), end: h(original, 2) }],
|
|
519
494
|
});
|
|
520
495
|
assert.equal(await readFile(file, "utf8"), "c\n");
|
|
521
496
|
}));
|
|
@@ -531,7 +506,7 @@ test("local and full-file recovery return copyable anchors without changing the
|
|
|
531
506
|
const report = failureReport(
|
|
532
507
|
await call(edit, {
|
|
533
508
|
path: "shift.txt",
|
|
534
|
-
edits: [{
|
|
509
|
+
edits: [{ action: "replace", anchor: h(original, 2), body: ["B"] }],
|
|
535
510
|
}),
|
|
536
511
|
);
|
|
537
512
|
const failure = report.failures?.[0];
|
|
@@ -545,7 +520,7 @@ test("local and full-file recovery return copyable anchors without changing the
|
|
|
545
520
|
assert.equal(await readFile(join(dir, "shift.txt"), "utf8"), prefix + original);
|
|
546
521
|
await call(edit, {
|
|
547
522
|
path: "shift.txt",
|
|
548
|
-
edits: [{
|
|
523
|
+
edits: [{ action: "replace", anchor: replacement, body: ["B"] }],
|
|
549
524
|
});
|
|
550
525
|
assert.equal(await readFile(join(dir, "shift.txt"), "utf8"), prefix + "a\nB\n");
|
|
551
526
|
}
|
|
@@ -560,12 +535,12 @@ test("shifted-anchor recovery keeps the read fallback for oversized candidates",
|
|
|
560
535
|
const report = failureReport(
|
|
561
536
|
await call(edit, {
|
|
562
537
|
path: "shift-large.txt",
|
|
563
|
-
edits: [{
|
|
538
|
+
edits: [{ action: "replace", anchor: h(original, 2), body: ["B"] }],
|
|
564
539
|
}),
|
|
565
540
|
);
|
|
566
541
|
assert.match(
|
|
567
|
-
report.failures?.[0].
|
|
568
|
-
new RegExp(`exceeds ${
|
|
542
|
+
report.failures?.[0].omitted ?? "",
|
|
543
|
+
new RegExp(`exceeds ${formatByteSize(DEFAULT_OUTPUT_BUDGETS.fieldBytes)}`),
|
|
569
544
|
);
|
|
570
545
|
assert.match(report.next ?? "", /use read or grep/);
|
|
571
546
|
assert.equal(report.failures?.[0].content, undefined);
|
|
@@ -585,7 +560,10 @@ test("failed commands preserve mutation results and stay out of all main card re
|
|
|
585
560
|
path: "edit.txt",
|
|
586
561
|
run: async () => {
|
|
587
562
|
const tool = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
588
|
-
const args = {
|
|
563
|
+
const args = {
|
|
564
|
+
path: "edit.txt",
|
|
565
|
+
edits: [{ action: "append" as const, body: ["after"] }],
|
|
566
|
+
};
|
|
589
567
|
const result = await callTool(
|
|
590
568
|
tool,
|
|
591
569
|
{ ...args, then_run: { command: "check" } },
|
|
@@ -617,7 +595,7 @@ test("failed commands preserve mutation results and stay out of all main card re
|
|
|
617
595
|
const tool = makeReplaceTool(dir, DEFAULT_CONFIG, fusion);
|
|
618
596
|
const args = {
|
|
619
597
|
path: "replace.txt",
|
|
620
|
-
replacements: [{ find: "before", replace: "after" }],
|
|
598
|
+
replacements: [{ literal: true, find: "before", replace: "after" }],
|
|
621
599
|
};
|
|
622
600
|
const result = await callTool(
|
|
623
601
|
tool,
|
|
@@ -685,12 +663,12 @@ test("failed commands preserve mutation results and stay out of all main card re
|
|
|
685
663
|
await writeFile(join(dir, path), "before\n");
|
|
686
664
|
const { result, rendered } = await run();
|
|
687
665
|
assert.equal("isError" in result, false);
|
|
688
|
-
|
|
689
|
-
assert.equal(
|
|
666
|
+
const report = detailsReport(result.details);
|
|
667
|
+
assert.equal(report?.publication, "PUBLISHED");
|
|
690
668
|
const last = result.content.at(-1);
|
|
691
669
|
assert.ok(last?.type === "text");
|
|
692
|
-
assert.equal(
|
|
693
|
-
assert.match(
|
|
670
|
+
assert.equal(report?.then_run?.status, "failed");
|
|
671
|
+
assert.match(report?.then_run?.output ?? "", /command-only diagnostic/);
|
|
694
672
|
if (path !== "write.txt")
|
|
695
673
|
assert.equal(typeof ("diff" in result.details ? result.details.diff : undefined), "string");
|
|
696
674
|
assert.doesNotMatch(rendered, /command-only diagnostic|then_run:failed/);
|
|
@@ -711,11 +689,11 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
|
|
|
711
689
|
[makeReadOverride(dir, DEFAULT_CONFIG), { path: "invalid-utf8.txt" }],
|
|
712
690
|
[
|
|
713
691
|
makeEditOverride(dir, DEFAULT_CONFIG),
|
|
714
|
-
{ path: "invalid-utf8.txt", edits: [{
|
|
692
|
+
{ path: "invalid-utf8.txt", edits: [{ action: "append", body: ["x"] }] },
|
|
715
693
|
],
|
|
716
694
|
[
|
|
717
695
|
makeReplaceTool(dir, DEFAULT_CONFIG),
|
|
718
|
-
{ path: "invalid-utf8.txt", replacements: [{ find: "a", replace: "b" }] },
|
|
696
|
+
{ path: "invalid-utf8.txt", replacements: [{ literal: true, find: "a", replace: "b" }] },
|
|
719
697
|
],
|
|
720
698
|
] as const) {
|
|
721
699
|
assert.equal(failureReport(await call(tool, args)).error, "UNSUPPORTED_ENCODING");
|
|
@@ -728,11 +706,11 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
|
|
|
728
706
|
for (const [tool, args] of [
|
|
729
707
|
[
|
|
730
708
|
makeEditOverride(dir, DEFAULT_CONFIG),
|
|
731
|
-
{ path: "nul.txt", edits: [{
|
|
709
|
+
{ path: "nul.txt", edits: [{ action: "append", body: ["x"] }] },
|
|
732
710
|
],
|
|
733
711
|
[
|
|
734
712
|
makeReplaceTool(dir, DEFAULT_CONFIG),
|
|
735
|
-
{ path: "nul.txt", replacements: [{ find: "a", replace: "b" }] },
|
|
713
|
+
{ path: "nul.txt", replacements: [{ literal: true, find: "a", replace: "b" }] },
|
|
736
714
|
],
|
|
737
715
|
] as const) {
|
|
738
716
|
assert.equal(failureReport(await call(tool, args)).error, "UNSUPPORTED_TEXT");
|
|
@@ -758,9 +736,9 @@ test("edit rejects embedded line terminators at its schema boundary", async () =
|
|
|
758
736
|
await assert.rejects(
|
|
759
737
|
call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
760
738
|
path: "body.txt",
|
|
761
|
-
edits: [{
|
|
739
|
+
edits: [{ action: "append", body: [line] }],
|
|
762
740
|
}),
|
|
763
|
-
rejectsArguments(
|
|
741
|
+
rejectsArguments(),
|
|
764
742
|
);
|
|
765
743
|
assert.equal(await readFile(target, "utf8"), "a\n");
|
|
766
744
|
}
|
|
@@ -770,21 +748,21 @@ test("edit rejects unwritable body lines before reading a missing target", async
|
|
|
770
748
|
withDir(async (dir) => {
|
|
771
749
|
const target = join(dir, "missing.txt");
|
|
772
750
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
773
|
-
const valid = { path: target, edits: [{
|
|
751
|
+
const valid = { path: target, edits: [{ action: "append" as const, body: ["ok"] }] };
|
|
774
752
|
assert.equal(edit.prepareArguments(valid), valid);
|
|
775
753
|
for (const [line, expected] of [
|
|
776
754
|
["bad\0", rejectsArgument("edits[0].body[1]", /NUL/)],
|
|
777
755
|
["\ud800", rejectsArgument("edits[0].body[1]", /losslessly.*UTF-8/)],
|
|
778
756
|
] as const) {
|
|
779
757
|
await assert.rejects(
|
|
780
|
-
call(edit, { path: target, edits: [{
|
|
758
|
+
call(edit, { path: target, edits: [{ action: "append", body: ["ok", line] }] }),
|
|
781
759
|
expected,
|
|
782
760
|
);
|
|
783
761
|
await assert.rejects(readFile(target, "utf8"), { code: "ENOENT" });
|
|
784
762
|
}
|
|
785
763
|
}));
|
|
786
764
|
|
|
787
|
-
test("
|
|
765
|
+
test("editing a BOM-prefixed file → publishes the changed bytes with the BOM intact", async () =>
|
|
788
766
|
withDir(async (dir) => {
|
|
789
767
|
const target = join(dir, "bom.txt");
|
|
790
768
|
const source = "\ufeffguard\nold\n";
|
|
@@ -793,14 +771,12 @@ test("edit preserves a UTF-8 BOM and reports bound mutation revisions", async ()
|
|
|
793
771
|
await writeFile(target, original);
|
|
794
772
|
const result = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
795
773
|
path: "bom.txt",
|
|
796
|
-
edits: [{
|
|
774
|
+
edits: [{ action: "replace", anchor: h(source, line), body: ["new"] }],
|
|
797
775
|
});
|
|
798
776
|
const expected = Buffer.from(line === 1 ? "\ufeffnew\nold\n" : "\ufeffguard\nnew\n", "utf8");
|
|
799
777
|
assert.deepEqual(await readFile(target), expected);
|
|
800
|
-
assert.equal(result
|
|
801
|
-
assert.equal(result
|
|
802
|
-
assert.equal(result.details.observedRevision, result.details.publishedRevision);
|
|
803
|
-
assert.equal("revision" in result.details, false);
|
|
778
|
+
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
779
|
+
assert.equal(reportOf(result, "edit")?.freshness, undefined);
|
|
804
780
|
}
|
|
805
781
|
}));
|
|
806
782
|
|
|
@@ -812,7 +788,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
|
|
|
812
788
|
await assert.rejects(
|
|
813
789
|
call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
814
790
|
path: "output.txt",
|
|
815
|
-
edits: [{
|
|
791
|
+
edits: [{ action: "append", body: ["bad\0text"] }],
|
|
816
792
|
}),
|
|
817
793
|
rejectsArgument("edits[0].body[0]", /NUL/),
|
|
818
794
|
);
|
|
@@ -820,7 +796,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
|
|
|
820
796
|
await assert.rejects(
|
|
821
797
|
call(makeReplaceTool(dir, DEFAULT_CONFIG), {
|
|
822
798
|
path: "output.txt",
|
|
823
|
-
replacements: [{ find: "before", replace: "bad\0text" }],
|
|
799
|
+
replacements: [{ literal: true, find: "before", replace: "bad\0text" }],
|
|
824
800
|
}),
|
|
825
801
|
rejectsArgument("replacements[0].replace", /NUL/),
|
|
826
802
|
);
|
|
@@ -838,7 +814,7 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
838
814
|
let commands = 0;
|
|
839
815
|
const fusion = createActionFusionExecutor(async () => {
|
|
840
816
|
commands++;
|
|
841
|
-
return { status: "succeeded",
|
|
817
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "checked" }] } };
|
|
842
818
|
});
|
|
843
819
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
844
820
|
const stale = h(original.join("\n"), 5);
|
|
@@ -850,8 +826,8 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
850
826
|
{
|
|
851
827
|
path: file,
|
|
852
828
|
edits: [
|
|
853
|
-
{
|
|
854
|
-
{
|
|
829
|
+
{ action: "insert_after", anchor: stale, body: ["const hashLen = 4;"] },
|
|
830
|
+
{ action: "replace", anchor: stable, body: ["changed"] },
|
|
855
831
|
],
|
|
856
832
|
then_run: { command: "check" },
|
|
857
833
|
},
|
|
@@ -874,11 +850,11 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
874
850
|
path: file,
|
|
875
851
|
edits: [
|
|
876
852
|
{
|
|
877
|
-
|
|
853
|
+
action: "insert_after",
|
|
878
854
|
anchor: report.failures![0].candidate!,
|
|
879
855
|
body: ["const hashLen = 4;"],
|
|
880
856
|
},
|
|
881
|
-
{
|
|
857
|
+
{ action: "replace", anchor: stable, body: ["changed"] },
|
|
882
858
|
],
|
|
883
859
|
then_run: { command: "check" },
|
|
884
860
|
},
|
|
@@ -906,7 +882,11 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
|
|
|
906
882
|
await call(edit, {
|
|
907
883
|
path: file,
|
|
908
884
|
edits: [
|
|
909
|
-
{
|
|
885
|
+
{
|
|
886
|
+
action: "replace",
|
|
887
|
+
anchor: h("header\n return value;\n", 2),
|
|
888
|
+
body: [" return updated;"],
|
|
889
|
+
},
|
|
910
890
|
],
|
|
911
891
|
}),
|
|
912
892
|
);
|
|
@@ -924,7 +904,7 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
|
|
|
924
904
|
assert.equal(await readFile(file, "utf8"), before);
|
|
925
905
|
await call(edit, {
|
|
926
906
|
path: file,
|
|
927
|
-
edits: [{
|
|
907
|
+
edits: [{ action: "replace", anchor: anchorLine(context, 15), body: [" return updated;"] }],
|
|
928
908
|
});
|
|
929
909
|
lines[14] = " return updated;";
|
|
930
910
|
assert.equal(await readFile(file, "utf8"), lines.join("\n") + "\n");
|
|
@@ -938,17 +918,17 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
938
918
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
939
919
|
const stable = h(before, 1);
|
|
940
920
|
for (const operation of [
|
|
941
|
-
{
|
|
942
|
-
{
|
|
921
|
+
{ action: "replace", anchor: stable, body: ["bad\nline"] },
|
|
922
|
+
{ action: "append", body: ["bad\nline"] },
|
|
943
923
|
]) {
|
|
944
924
|
for (const laterAnchor of [h(before, 2), "2#XXXX"]) {
|
|
945
925
|
await assert.rejects(
|
|
946
926
|
call(edit, {
|
|
947
927
|
path: file,
|
|
948
|
-
edits: [operation, {
|
|
928
|
+
edits: [operation, { action: "replace", anchor: laterAnchor, body: ["B"] }],
|
|
949
929
|
}),
|
|
950
930
|
(error: Error) => {
|
|
951
|
-
rejectsArguments(
|
|
931
|
+
rejectsArguments()(error);
|
|
952
932
|
const report = argumentError(error);
|
|
953
933
|
assert.equal(report.matched, undefined);
|
|
954
934
|
assert.equal(report.failures, undefined);
|
|
@@ -962,8 +942,8 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
962
942
|
await call(edit, {
|
|
963
943
|
path: file,
|
|
964
944
|
edits: [
|
|
965
|
-
{
|
|
966
|
-
{
|
|
945
|
+
{ action: "replace", anchor: stable, body: ["A"] },
|
|
946
|
+
{ action: "delete", anchor: h(before, 2), end: "3#ZZZZ" },
|
|
967
947
|
],
|
|
968
948
|
}),
|
|
969
949
|
);
|
|
@@ -977,8 +957,8 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
977
957
|
await call(edit, {
|
|
978
958
|
path: file,
|
|
979
959
|
edits: [
|
|
980
|
-
{
|
|
981
|
-
{
|
|
960
|
+
{ action: "replace", anchor: stable, body: ["A"] },
|
|
961
|
+
{ action: "replace", anchor: "3#ZZZZ", body: ["B"] },
|
|
982
962
|
],
|
|
983
963
|
}),
|
|
984
964
|
);
|
|
@@ -994,15 +974,18 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
994
974
|
test("single-operation anchor failures omit redundant matched-anchor facts", async () =>
|
|
995
975
|
withDir(async (dir) => {
|
|
996
976
|
const file = join(dir, "single.txt");
|
|
997
|
-
|
|
977
|
+
const source = "line1\nline2\nline3\n";
|
|
978
|
+
await writeFile(file, source);
|
|
998
979
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
999
980
|
for (const operation of [
|
|
1000
|
-
{
|
|
1001
|
-
{
|
|
981
|
+
{ action: "replace", anchor: "1#XXXX", body: ["new"] },
|
|
982
|
+
{ action: "replace", anchor: h(source, 1), end: "2#YYYY", body: ["new"] },
|
|
1002
983
|
]) {
|
|
1003
984
|
const report = failureReport(await call(edit, { path: file, edits: [operation] }));
|
|
1004
985
|
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
1005
986
|
assert.equal(report.matched, undefined);
|
|
987
|
+
assert.equal(report.omittedMatched, undefined);
|
|
988
|
+
assert.equal(await readFile(file, "utf8"), source);
|
|
1006
989
|
}
|
|
1007
990
|
}));
|
|
1008
991
|
|
|
@@ -1013,7 +996,7 @@ test("failed batches return more than forty checks and mappings when byte budget
|
|
|
1013
996
|
const file = join(dir, "many-checks.txt");
|
|
1014
997
|
await writeFile(file, before);
|
|
1015
998
|
const edits = Array.from({ length: 45 }, () => ({
|
|
1016
|
-
|
|
999
|
+
action: "replace",
|
|
1017
1000
|
anchor: h(original, 2),
|
|
1018
1001
|
body: ["changed"],
|
|
1019
1002
|
}));
|
|
@@ -1038,7 +1021,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
|
|
|
1038
1021
|
const report = failureReport(
|
|
1039
1022
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1040
1023
|
path: file,
|
|
1041
|
-
edits: [{
|
|
1024
|
+
edits: [{ action: "replace", anchor: h(original, 2), body: ["updated"] }],
|
|
1042
1025
|
}),
|
|
1043
1026
|
);
|
|
1044
1027
|
const candidate = report.failures?.[0].candidate;
|
|
@@ -1050,12 +1033,12 @@ test("unique candidate content is independent of oversized neighboring rows", as
|
|
|
1050
1033
|
assert.equal(await readFile(file, "utf8"), before);
|
|
1051
1034
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1052
1035
|
path: file,
|
|
1053
|
-
edits: [{
|
|
1036
|
+
edits: [{ action: "replace", anchor: candidate, body: ["updated"] }],
|
|
1054
1037
|
});
|
|
1055
1038
|
assert.equal(await readFile(file, "utf8"), before.replace("target", "updated"));
|
|
1056
1039
|
}));
|
|
1057
1040
|
|
|
1058
|
-
test("standalone CR replacements remain visible in diffs and exact in
|
|
1041
|
+
test("standalone CR replacements remain visible in diffs and exact in file bytes", async () =>
|
|
1059
1042
|
withDir(async (dir) => {
|
|
1060
1043
|
const file = join(dir, "cr.txt");
|
|
1061
1044
|
for (const [before, find, replacement] of [
|
|
@@ -1065,15 +1048,12 @@ test("standalone CR replacements remain visible in diffs and exact in patches",
|
|
|
1065
1048
|
await writeFile(file, before);
|
|
1066
1049
|
const result = await call(makeReplaceTool(dir, DEFAULT_CONFIG), {
|
|
1067
1050
|
path: file,
|
|
1068
|
-
replacements: [{ find, replace: replacement,
|
|
1051
|
+
replacements: [{ find, replace: replacement, literal: false }],
|
|
1069
1052
|
});
|
|
1070
1053
|
assert.equal(await readFile(file, "utf8"), before.replaceAll(find, replacement));
|
|
1071
|
-
assert.equal(result.details.firstChangedLine, 1);
|
|
1072
1054
|
assert.match(result.details.diff, /^-1 a␍/m);
|
|
1073
1055
|
assert.match(result.details.diff, /^\+1 a/m);
|
|
1074
1056
|
assert.ok(!result.details.diff.includes("\r"));
|
|
1075
|
-
assert.ok(result.details.patch.includes(`-a${before.includes("\r\n") ? "\r\n" : "\rb\n"}`));
|
|
1076
|
-
assert.match(result.details.patch, /@@/);
|
|
1077
1057
|
}
|
|
1078
1058
|
}));
|
|
1079
1059
|
|
|
@@ -1084,38 +1064,19 @@ test("shifted unique candidate → displays standalone CR without altering its a
|
|
|
1084
1064
|
await writeFile(file, before);
|
|
1085
1065
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1086
1066
|
path: file,
|
|
1087
|
-
edits: [{
|
|
1067
|
+
edits: [{ action: "delete", anchor: h(before, 1) }],
|
|
1088
1068
|
});
|
|
1089
1069
|
assert.equal(await readFile(file, "utf8"), "a\rb\n");
|
|
1090
1070
|
const report = failureReport(
|
|
1091
1071
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1092
1072
|
path: file,
|
|
1093
|
-
edits: [{
|
|
1073
|
+
edits: [{ action: "delete", anchor: h(before, 2) }],
|
|
1094
1074
|
}),
|
|
1095
1075
|
);
|
|
1096
1076
|
assert.equal(report.failures?.[0].candidate, h("a\rb\n", 1));
|
|
1097
1077
|
assert.equal(report.failures?.[0].content, "a␍b");
|
|
1098
1078
|
}));
|
|
1099
1079
|
|
|
1100
|
-
test("edit tool rejects non-array formats Pi cannot convert", async () =>
|
|
1101
|
-
withDir(async (dir) => {
|
|
1102
|
-
const file = join(dir, "f.txt");
|
|
1103
|
-
await writeFile(file, "first\nsecond\n");
|
|
1104
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
1105
|
-
const anchor = h("first\nsecond\n", 2);
|
|
1106
|
-
for (const alternate of [
|
|
1107
|
-
{ path: "f.txt", edits: JSON.stringify([{ op: "replace", anchor, body: ["SECOND"] }]) },
|
|
1108
|
-
{ path: "f.txt", op: "replace", anchor, body: ["SECOND"] },
|
|
1109
|
-
]) {
|
|
1110
|
-
const original = structuredClone(alternate);
|
|
1111
|
-
await assert.rejects(call(edit, alternate), rejectsArguments("edit"));
|
|
1112
|
-
assert.deepEqual(alternate, original);
|
|
1113
|
-
assert.equal(await readFile(file, "utf8"), "first\nsecond\n");
|
|
1114
|
-
}
|
|
1115
|
-
await call(edit, { path: "f.txt", edits: [{ op: "replace", anchor, body: ["SECOND"] }] });
|
|
1116
|
-
assert.equal(await readFile(file, "utf8"), "first\nSECOND\n");
|
|
1117
|
-
}));
|
|
1118
|
-
|
|
1119
1080
|
test("edit receives multiple wrong-length anchors → reports each location with one recovery hint", async () =>
|
|
1120
1081
|
withDir(async (dir) => {
|
|
1121
1082
|
const text = "first\nsecond\n";
|
|
@@ -1128,8 +1089,8 @@ test("edit receives multiple wrong-length anchors → reports each location with
|
|
|
1128
1089
|
const args = {
|
|
1129
1090
|
path: "f.txt",
|
|
1130
1091
|
edits: [
|
|
1131
|
-
{
|
|
1132
|
-
{
|
|
1092
|
+
{ action: "replace", anchor, end: short, body: ["x"] },
|
|
1093
|
+
{ action: "delete", anchor: short },
|
|
1133
1094
|
],
|
|
1134
1095
|
};
|
|
1135
1096
|
|
|
@@ -1155,7 +1116,7 @@ test("Pi-converted single-object edits execute as a canonical array", async () =
|
|
|
1155
1116
|
const original = "first\nsecond\n";
|
|
1156
1117
|
await writeFile(file, original);
|
|
1157
1118
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
1158
|
-
const operation = {
|
|
1119
|
+
const operation = { action: "replace", anchor: h(original, 2), body: ["SECOND"] };
|
|
1159
1120
|
const args = validateToolArguments(edit as any, {
|
|
1160
1121
|
type: "toolCall",
|
|
1161
1122
|
id: "converted",
|
|
@@ -1167,29 +1128,6 @@ test("Pi-converted single-object edits execute as a canonical array", async () =
|
|
|
1167
1128
|
assert.equal(await readFile(file, "utf8"), "first\nSECOND\n");
|
|
1168
1129
|
}));
|
|
1169
1130
|
|
|
1170
|
-
test("edit execute rejects legacy oldText/newText without op", async () =>
|
|
1171
|
-
withDir(async (dir) => {
|
|
1172
|
-
const file = join(dir, "f.txt");
|
|
1173
|
-
await writeFile(file, "first\nsecond\n");
|
|
1174
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
1175
|
-
await assert.rejects(
|
|
1176
|
-
call(edit, {
|
|
1177
|
-
path: "f.txt",
|
|
1178
|
-
oldText: "first",
|
|
1179
|
-
newText: "FIRST",
|
|
1180
|
-
}),
|
|
1181
|
-
rejectsArguments("edit"),
|
|
1182
|
-
);
|
|
1183
|
-
await assert.rejects(
|
|
1184
|
-
call(edit, {
|
|
1185
|
-
path: "f.txt",
|
|
1186
|
-
edits: [{ oldText: "first", newText: "FIRST" } as any],
|
|
1187
|
-
}),
|
|
1188
|
-
rejectsArguments("edit"),
|
|
1189
|
-
);
|
|
1190
|
-
assert.equal(await readFile(file, "utf8"), "first\nsecond\n");
|
|
1191
|
-
}));
|
|
1192
|
-
|
|
1193
1131
|
test("unresolved snapshot rows support direct retry and revalidate after further changes", async () => {
|
|
1194
1132
|
await withDir(async (dir) => {
|
|
1195
1133
|
const file = join(dir, "recover.txt");
|
|
@@ -1200,7 +1138,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
|
|
|
1200
1138
|
const report = failureReport(
|
|
1201
1139
|
await call(edit, {
|
|
1202
1140
|
path: "recover.txt",
|
|
1203
|
-
edits: [{
|
|
1141
|
+
edits: [{ action: "replace", anchor: h(observed, 2), body: ["target = new"] }],
|
|
1204
1142
|
}),
|
|
1205
1143
|
);
|
|
1206
1144
|
const diagnostic = report.failures?.[0].observed ?? "";
|
|
@@ -1212,7 +1150,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
|
|
|
1212
1150
|
const retry = failureReport(
|
|
1213
1151
|
await call(edit, {
|
|
1214
1152
|
path: "recover.txt",
|
|
1215
|
-
edits: [{
|
|
1153
|
+
edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
|
|
1216
1154
|
}),
|
|
1217
1155
|
);
|
|
1218
1156
|
assert.equal(retry.error, "ANCHOR_MISMATCH");
|
|
@@ -1220,7 +1158,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
|
|
|
1220
1158
|
await writeFile(file, current);
|
|
1221
1159
|
await call(edit, {
|
|
1222
1160
|
path: "recover.txt",
|
|
1223
|
-
edits: [{
|
|
1161
|
+
edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
|
|
1224
1162
|
});
|
|
1225
1163
|
assert.deepEqual(await readFile(file), Buffer.from(observed.replace("old", "new")));
|
|
1226
1164
|
});
|
|
@@ -1236,16 +1174,16 @@ test("unresolved oversized and out-of-range rows require more context without pa
|
|
|
1236
1174
|
const report = failureReport(
|
|
1237
1175
|
await call(edit, {
|
|
1238
1176
|
path: "recover.txt",
|
|
1239
|
-
edits: [{
|
|
1177
|
+
edits: [{ action: "replace", anchor, body: ["new"] }],
|
|
1240
1178
|
}),
|
|
1241
1179
|
);
|
|
1242
1180
|
assert.match(report.next ?? "", /read or grep/);
|
|
1243
1181
|
assert.equal(report.failures?.[0].observed, undefined);
|
|
1244
1182
|
assert.equal(
|
|
1245
|
-
report.failures?.[0].
|
|
1183
|
+
report.failures?.[0].omitted,
|
|
1246
1184
|
anchor.startsWith("99#")
|
|
1247
1185
|
? "cited line is out of range"
|
|
1248
|
-
: `row exceeds ${
|
|
1186
|
+
: `row exceeds ${formatByteSize(DEFAULT_OUTPUT_BUDGETS.fieldBytes)}`,
|
|
1249
1187
|
);
|
|
1250
1188
|
assert.deepEqual(await readFile(file), Buffer.from(current));
|
|
1251
1189
|
}
|
|
@@ -1259,9 +1197,9 @@ test("edit rejects impossible checksum characters before accessing the file", as
|
|
|
1259
1197
|
await assert.rejects(
|
|
1260
1198
|
call(tool, {
|
|
1261
1199
|
path: "missing.txt",
|
|
1262
|
-
edits: [{
|
|
1200
|
+
edits: [{ action: "delete", anchor: `1#${char.repeat(DEFAULT_CONFIG.hashLen)}` }],
|
|
1263
1201
|
}),
|
|
1264
|
-
rejectsArguments(
|
|
1202
|
+
rejectsArguments(),
|
|
1265
1203
|
);
|
|
1266
1204
|
}
|
|
1267
1205
|
}));
|
|
@@ -1277,7 +1215,7 @@ test("ambiguous failure lists and neighborhoods select the same first eight cand
|
|
|
1277
1215
|
const report = failureReport(
|
|
1278
1216
|
await call(tool, {
|
|
1279
1217
|
path: "candidates.txt",
|
|
1280
|
-
edits: [{
|
|
1218
|
+
edits: [{ action: "delete", anchor: `200#${computeLineHash(200, "target", 4)}` }],
|
|
1281
1219
|
}),
|
|
1282
1220
|
);
|
|
1283
1221
|
assert.equal(report.failures?.[0].omittedCandidates, 1);
|
|
@@ -1300,7 +1238,7 @@ test("edit verification → uses the supplied hash length", async () =>
|
|
|
1300
1238
|
path: "registered.txt",
|
|
1301
1239
|
edits: [
|
|
1302
1240
|
{
|
|
1303
|
-
|
|
1241
|
+
action: "replace",
|
|
1304
1242
|
anchor: `1#${computeLineHash(1, "before", 6)}`,
|
|
1305
1243
|
body: ["after"],
|
|
1306
1244
|
},
|
|
@@ -1310,7 +1248,7 @@ test("edit verification → uses the supplied hash length", async () =>
|
|
|
1310
1248
|
assert.equal(await readFile(join(dir, "registered.txt"), "utf8"), "after\n");
|
|
1311
1249
|
}));
|
|
1312
1250
|
|
|
1313
|
-
test("copy/move through read anchors →
|
|
1251
|
+
test("copy/move through read anchors → publishes captured bytes with BOM and mixed endings intact", async () =>
|
|
1314
1252
|
withDir(async (dir) => {
|
|
1315
1253
|
const path = "transfer.txt";
|
|
1316
1254
|
const file = join(dir, path);
|
|
@@ -1327,17 +1265,19 @@ test("copy/move through read anchors → publish bytes bound to the read revisio
|
|
|
1327
1265
|
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(edit, {
|
|
1328
1266
|
path,
|
|
1329
1267
|
edits: [
|
|
1330
|
-
{
|
|
1268
|
+
{
|
|
1269
|
+
action: op,
|
|
1270
|
+
anchor: anchorLine(rows, 1),
|
|
1271
|
+
end: anchorLine(rows, 2),
|
|
1272
|
+
after: anchorLine(rows, 4),
|
|
1273
|
+
},
|
|
1331
1274
|
],
|
|
1332
1275
|
});
|
|
1333
1276
|
const expected = op === "copy" ? source + "A\r\nB\n" : "\uFEFFC\r\nD\nA\r\nB\n";
|
|
1334
1277
|
const bytes = Buffer.from(expected, "utf8");
|
|
1335
1278
|
assert.deepEqual(await readFile(file), bytes);
|
|
1336
|
-
assert.
|
|
1337
|
-
assert.equal(result
|
|
1338
|
-
assert.equal(result.details.publication, "PUBLISHED");
|
|
1339
|
-
assert.equal(result.details.publishedRevision, byteRevision(bytes));
|
|
1340
|
-
assert.equal(result.details.observedRevision, result.details.publishedRevision);
|
|
1279
|
+
assert.equal(result.isError, undefined);
|
|
1280
|
+
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
1341
1281
|
}
|
|
1342
1282
|
}));
|
|
1343
1283
|
|
|
@@ -1350,7 +1290,7 @@ test("copy/move stale destination → report its field and skip publication and
|
|
|
1350
1290
|
let commands = 0;
|
|
1351
1291
|
const fusion = createActionFusionExecutor(async () => {
|
|
1352
1292
|
commands++;
|
|
1353
|
-
return { status: "succeeded",
|
|
1293
|
+
return { status: "succeeded", result: { content: [{ type: "text", text: "ran" }] } };
|
|
1354
1294
|
});
|
|
1355
1295
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
1356
1296
|
for (const op of ["copy", "move"] as const) {
|
|
@@ -1358,8 +1298,8 @@ test("copy/move stale destination → report its field and skip publication and
|
|
|
1358
1298
|
await callTool(edit, {
|
|
1359
1299
|
path: file,
|
|
1360
1300
|
edits: [
|
|
1361
|
-
{ op, anchor: h(current, 1), after: h(original, 3) },
|
|
1362
|
-
{
|
|
1301
|
+
{ action: op, anchor: h(current, 1), after: h(original, 3) },
|
|
1302
|
+
{ action: "replace", anchor: h(current, 2), body: ["changed"] },
|
|
1363
1303
|
],
|
|
1364
1304
|
then_run: { command: "check" },
|
|
1365
1305
|
}),
|
|
@@ -1381,25 +1321,28 @@ test("copy/move with fused command → execute after the complete transfer and p
|
|
|
1381
1321
|
await writeFile(file, source);
|
|
1382
1322
|
const expected = op === "copy" ? "A\nB\nC\nA\n" : "B\nC\nA\n";
|
|
1383
1323
|
let commands = 0;
|
|
1324
|
+
let commandBytes: string | undefined;
|
|
1325
|
+
const commandFailure = new Error("Command exited with code 7");
|
|
1384
1326
|
const fusion = createActionFusionExecutor(async () => {
|
|
1385
1327
|
commands++;
|
|
1386
|
-
|
|
1387
|
-
throw
|
|
1328
|
+
commandBytes = await readFile(file, "utf8");
|
|
1329
|
+
throw commandFailure;
|
|
1388
1330
|
});
|
|
1389
1331
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
1390
1332
|
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(
|
|
1391
1333
|
edit,
|
|
1392
1334
|
{
|
|
1393
1335
|
path: file,
|
|
1394
|
-
edits: [{ op, anchor: h(source, 1), after: h(source, 3) }],
|
|
1336
|
+
edits: [{ action: op, anchor: h(source, 1), after: h(source, 3) }],
|
|
1395
1337
|
then_run: { command: "check" },
|
|
1396
1338
|
},
|
|
1397
1339
|
{ ctx: { cwd: dir } },
|
|
1398
1340
|
);
|
|
1399
|
-
assert.
|
|
1400
|
-
assert.equal(result
|
|
1401
|
-
assert.equal(
|
|
1402
|
-
assert.equal(result
|
|
1341
|
+
assert.equal(reportOf(result, "edit")?.then_run?.status, "failed");
|
|
1342
|
+
assert.equal(reportOf(result, "edit")?.then_run?.output, commandFailure.message);
|
|
1343
|
+
assert.equal(commandBytes, expected);
|
|
1344
|
+
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
1345
|
+
assert.equal(reportOf(result, "edit")?.freshness, undefined);
|
|
1403
1346
|
assert.equal(await readFile(file, "utf8"), expected);
|
|
1404
1347
|
assert.equal(commands, 1);
|
|
1405
1348
|
}
|