@criogaid/pi-hashline-edit 0.8.0 → 0.10.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 +13 -10
- package/README.zh-CN.md +12 -9
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +118 -293
- package/src/core/apply.ts +63 -165
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.ts +4 -4
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +16 -8
- package/src/core/ranges.ts +10 -6
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +7 -43
- package/src/integration/config-registration.test.ts +2 -2
- package/src/integration/fusion-dispatch.test.ts +2 -5
- package/src/integration/grep-flags.test.ts +0 -14
- package/src/integration/grep-js-completeness.test.ts +34 -8
- package/src/integration/grep-line-candidates.test.ts +4 -8
- package/src/integration/grep-matrix.test.ts +3 -7
- package/src/integration/grep-path-matrix.test.ts +5 -5
- package/src/integration/grep-prefilter-coverage.test.ts +3 -7
- package/src/integration/grep-process-limits.test.ts +78 -0
- package/src/integration/grep-rg.test.ts +123 -25
- package/src/integration/grep-scan-budget.test.ts +2 -2
- package/src/integration/grep-translation.test.ts +12 -27
- package/src/integration/large-text.test.ts +1 -47
- package/src/integration/model-budget-lifecycle.test.ts +13 -3
- package/src/integration/mutation-file-types.testing.ts +1 -1
- package/src/integration/npm-package.testing.ts +1 -1
- package/src/integration/publication-read-changes.test.ts +125 -47
- package/src/integration/replace-worker-boundary.test.ts +21 -11
- package/src/integration/report-replay.test.ts +21 -23
- package/src/integration/utf8-errors.test.ts +1 -1
- package/src/pi/AGENTS.md +16 -16
- package/src/pi/action-fusion.test.ts +168 -300
- package/src/pi/action-fusion.ts +148 -111
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +52 -207
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +20 -22
- package/src/pi/argument-validation.test.ts +382 -418
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +5 -4
- package/src/pi/config.test.ts +5 -2
- package/src/pi/config.ts +4 -6
- package/src/pi/diagnostic-buffer.test.ts +12 -1
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +173 -226
- package/src/pi/error-text.ts +4 -8
- package/src/pi/execute.test.ts +165 -266
- package/src/pi/failure-context.test.ts +144 -126
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +168 -141
- package/src/pi/file-commit.test.ts +110 -53
- package/src/pi/file-commit.ts +90 -137
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +4 -1
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +2 -101
- package/src/pi/grep-candidates.ts +23 -69
- package/src/pi/grep-matrix.test.ts +2 -2
- package/src/pi/grep-order.test.ts +4 -4
- package/src/pi/grep-output.ts +62 -96
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +92 -0
- package/src/pi/grep-scope.ts +40 -42
- package/src/pi/grep-search.ts +22 -31
- package/src/pi/grep-tool.ts +55 -82
- package/src/pi/grep.test.ts +81 -46
- package/src/pi/model-budgets.test.ts +25 -23
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +51 -20
- package/src/pi/mutation-runner.ts +126 -70
- package/src/pi/output-budgets.test.ts +38 -16
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +3 -1
- package/src/pi/read-tool.ts +5 -5
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +82 -20
- package/src/pi/render.test.ts +79 -42
- package/src/pi/render.ts +69 -63
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -83
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +9 -5
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +1 -2
- package/src/pi/report-schema.ts +65 -81
- package/src/pi/report.test.ts +171 -25
- package/src/pi/report.ts +33 -87
- package/src/pi/result-safety.test.ts +177 -189
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +48 -64
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +12 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/write-tool.ts +33 -62
- package/src/pi/write.test.ts +1 -3
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/pi/replace-worker-contract.ts +0 -10
package/src/pi/execute.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { argumentError, rejectsArgument, rejectsArguments } from "./argument-err
|
|
|
2
2
|
/** Tool-level edit and shared mutation workflow tests. */
|
|
3
3
|
import { test } from "node:test";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
|
-
import { mkdtemp, rm, readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import { mkdtemp, readdir, rm, readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
@@ -12,6 +12,7 @@ import { makeEditOverride } from "./edit-tool.ts";
|
|
|
12
12
|
import { makeReadOverride } from "./read-tool.ts";
|
|
13
13
|
import { makeWriteOverride } from "./write-tool.ts";
|
|
14
14
|
import { makeReplaceTool } from "./replace-tool.ts";
|
|
15
|
+
import { makeGrepOverride } from "./grep-tool.ts";
|
|
15
16
|
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
16
17
|
import { computeLineHash } from "../core/hash.ts";
|
|
17
18
|
import { splitLines } from "../core/lines.ts";
|
|
@@ -21,6 +22,8 @@ import { formatByteSize, DEFAULT_OUTPUT_BUDGETS } from "./budgets.ts";
|
|
|
21
22
|
import { detailsReport, reportOf } from "./report.ts";
|
|
22
23
|
import type { Report } from "./report-schema.ts";
|
|
23
24
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
25
|
+
import { PATH_ERROR_MESSAGES } from "../core/errors.ts";
|
|
26
|
+
import { ERROR_DEFINITIONS } from "./report-schema.ts";
|
|
24
27
|
|
|
25
28
|
async function withDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
|
26
29
|
const dir = await mkdtemp(join(tmpdir(), "hl-"));
|
|
@@ -53,16 +56,13 @@ function failureReport(result: AgentToolResult<unknown> & { isError?: boolean })
|
|
|
53
56
|
return report;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
test("edit guidance → refreshes anchors
|
|
59
|
+
test("edit guidance → refreshes mutation anchors with an edit-only exception above changes", () => {
|
|
57
60
|
const guidance = makeEditOverride(process.cwd(), DEFAULT_CONFIG).promptGuidelines.join("\n");
|
|
58
|
-
assert.match(guidance, /
|
|
61
|
+
assert.match(guidance, /before citing a line after write, edit, or replace/i);
|
|
62
|
+
assert.match(guidance, /anchor from a new read or grep/i);
|
|
59
63
|
assert.match(
|
|
60
64
|
guidance,
|
|
61
|
-
/
|
|
62
|
-
);
|
|
63
|
-
assert.match(
|
|
64
|
-
guidance,
|
|
65
|
-
/affected positions are unknown.*read or grep the lines you intend to cite/i,
|
|
65
|
+
/only after edit, lines above the earliest changed line keep their anchors/i,
|
|
66
66
|
);
|
|
67
67
|
});
|
|
68
68
|
|
|
@@ -77,7 +77,7 @@ test("edit execute: a file without a final newline stays byte-exact", async () =
|
|
|
77
77
|
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
78
78
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
79
79
|
path: "f.txt",
|
|
80
|
-
edits: [{
|
|
80
|
+
edits: [{ action: "replace", anchor: h(text, 2), body: ["new value\u2060"] }],
|
|
81
81
|
});
|
|
82
82
|
assert.equal(r.isError, undefined, "should not be an error");
|
|
83
83
|
assert.equal(await readFile(f, "utf-8"), "guard\nnew value\u2060");
|
|
@@ -92,31 +92,13 @@ test("edit execute: hashline round-trip (read → edit → file changed)", async
|
|
|
92
92
|
const read = await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
93
93
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
94
94
|
path: "f.txt",
|
|
95
|
-
edits: [{
|
|
95
|
+
edits: [{ action: "replace", anchor: anchorLine(read.content[0].text, 2), body: ["B"] }],
|
|
96
96
|
});
|
|
97
97
|
assert.equal(r.isError, undefined, "should not be an error");
|
|
98
98
|
assert.equal(await readFile(f, "utf-8"), "a\nB\nc\n");
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
test("edit execute: multiple ops in one call", async () => {
|
|
103
|
-
await withDir(async (dir) => {
|
|
104
|
-
const f = join(dir, "f.txt");
|
|
105
|
-
const text = "a\nb\nc\n";
|
|
106
|
-
await writeFile(f, text);
|
|
107
|
-
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
108
|
-
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
109
|
-
path: "f.txt",
|
|
110
|
-
edits: [
|
|
111
|
-
{ op: "insert_after", anchor: h(text, 3), body: ["z"] },
|
|
112
|
-
{ op: "replace", anchor: h(text, 1), body: ["A"] },
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
assert.equal(r.isError, undefined);
|
|
116
|
-
assert.equal(await readFile(f, "utf-8"), "A\nb\nc\nz\n");
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
102
|
test("successful mutation → returns one report without anchor payload", async (t) => {
|
|
121
103
|
for (const tool of ["edit", "replace", "write"] as const) {
|
|
122
104
|
for (const count of [1, 3000]) {
|
|
@@ -140,7 +122,7 @@ test("successful mutation → returns one report without anchor payload", async
|
|
|
140
122
|
path,
|
|
141
123
|
edits: [
|
|
142
124
|
{
|
|
143
|
-
|
|
125
|
+
action: "replace",
|
|
144
126
|
anchor: anchorLine(rows, 1),
|
|
145
127
|
end: anchorLine(rows, count),
|
|
146
128
|
body: Array.from({ length: count }, () => "new"),
|
|
@@ -179,22 +161,6 @@ test("successful mutation → returns one report without anchor payload", async
|
|
|
179
161
|
}
|
|
180
162
|
});
|
|
181
163
|
|
|
182
|
-
test("unrelated external change does NOT block an edit on a stable line", async () => {
|
|
183
|
-
await withDir(async (dir) => {
|
|
184
|
-
const f = join(dir, "f.txt");
|
|
185
|
-
const text = "a\nb\nc\n";
|
|
186
|
-
await writeFile(f, text);
|
|
187
|
-
// simulate an external change at line 3 between read and edit
|
|
188
|
-
await writeFile(f, "a\nb\nCHANGED\n");
|
|
189
|
-
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
190
|
-
path: "f.txt",
|
|
191
|
-
edits: [{ op: "replace", anchor: h(text, 1), body: ["A"] }],
|
|
192
|
-
});
|
|
193
|
-
assert.equal(r.isError, undefined);
|
|
194
|
-
assert.equal(await readFile(f, "utf-8"), "A\nb\nCHANGED\n");
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
164
|
test("edit on a line that changed externally → anchor mismatch", async () => {
|
|
199
165
|
await withDir(async (dir) => {
|
|
200
166
|
const f = join(dir, "f.txt");
|
|
@@ -204,7 +170,7 @@ test("edit on a line that changed externally → anchor mismatch", async () => {
|
|
|
204
170
|
const report = failureReport(
|
|
205
171
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
206
172
|
path: "f.txt",
|
|
207
|
-
edits: [{
|
|
173
|
+
edits: [{ action: "replace", anchor: h(text, 2), body: ["x"] }],
|
|
208
174
|
}),
|
|
209
175
|
);
|
|
210
176
|
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
@@ -225,18 +191,18 @@ test("unresolved observations require target confirmation before retrying a move
|
|
|
225
191
|
const report = failureReport(
|
|
226
192
|
await call(edit, {
|
|
227
193
|
path: "recover.txt",
|
|
228
|
-
edits: [{
|
|
194
|
+
edits: [{ action: "replace", anchor: h(observed, 5), body: ["updated"] }],
|
|
229
195
|
}),
|
|
230
196
|
);
|
|
231
197
|
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
232
198
|
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
233
|
-
assert.match(report.next ?? "", /
|
|
199
|
+
assert.match(report.next ?? "", /confirm.*intended target.*before reusing/i);
|
|
234
200
|
assert.match(report.failures?.[0].observed ?? "", /^5#[0-9A-Z]+│changed$/);
|
|
235
201
|
const read = await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "recover.txt" });
|
|
236
202
|
const retryAnchor = anchorLine(read.content[0].text, 7);
|
|
237
203
|
await call(edit, {
|
|
238
204
|
path: "recover.txt",
|
|
239
|
-
edits: [{
|
|
205
|
+
edits: [{ action: "replace", anchor: retryAnchor, body: ["updated"] }],
|
|
240
206
|
});
|
|
241
207
|
assert.equal(
|
|
242
208
|
await readFile(file, "utf8"),
|
|
@@ -245,20 +211,6 @@ test("unresolved observations require target confirmation before retrying a move
|
|
|
245
211
|
});
|
|
246
212
|
});
|
|
247
213
|
|
|
248
|
-
test("edit execute: no read before edit → anchor verification fails", async () => {
|
|
249
|
-
await withDir(async (dir) => {
|
|
250
|
-
await writeFile(join(dir, "f.txt"), "a\nb\n");
|
|
251
|
-
const report = failureReport(
|
|
252
|
-
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
253
|
-
path: "f.txt",
|
|
254
|
-
edits: [{ op: "replace", anchor: "1#XXXX", body: ["A"] }],
|
|
255
|
-
}),
|
|
256
|
-
);
|
|
257
|
-
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
258
|
-
assert.equal(await readFile(join(dir, "f.txt"), "utf8"), "a\nb\n");
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
214
|
test("edit execute: delete op", async () => {
|
|
263
215
|
await withDir(async (dir) => {
|
|
264
216
|
const f = join(dir, "f.txt");
|
|
@@ -267,7 +219,7 @@ test("edit execute: delete op", async () => {
|
|
|
267
219
|
await call(makeReadOverride(dir, DEFAULT_CONFIG), { path: "f.txt" });
|
|
268
220
|
const r: any = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
269
221
|
path: "f.txt",
|
|
270
|
-
edits: [{
|
|
222
|
+
edits: [{ action: "delete", anchor: h(text, 2) }],
|
|
271
223
|
});
|
|
272
224
|
assert.equal(r.isError, undefined);
|
|
273
225
|
assert.equal(await readFile(f, "utf-8"), "a\nc\n");
|
|
@@ -323,23 +275,23 @@ test("edit schema rejects misspelled range fields and invalid operation shapes",
|
|
|
323
275
|
const anchor = h(original, 2);
|
|
324
276
|
const callArgs = {
|
|
325
277
|
path: "range.txt",
|
|
326
|
-
edits: [{
|
|
278
|
+
edits: [{ action: "replace", anchor, endd: h(original, 3), body: ["merged"] }],
|
|
327
279
|
};
|
|
328
280
|
await assert.rejects(call(edit, callArgs), rejectsArgument("edits[0].endd", /not allowed/));
|
|
329
281
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
|
|
330
282
|
for (const [edits, expected] of [
|
|
331
283
|
[[], rejectsArgument("edits")],
|
|
332
|
-
[[{
|
|
333
|
-
[[{
|
|
334
|
-
[[{
|
|
335
|
-
[[{
|
|
284
|
+
[[{ action: "replace", anchor }], rejectsArgument("edits[0].body", /required/)],
|
|
285
|
+
[[{ action: "delete", anchor, body: ["bad"] }], rejectsArguments()],
|
|
286
|
+
[[{ action: "insert_after", body: ["bad"] }], rejectsArguments()],
|
|
287
|
+
[[{ action: "append", anchor, body: ["bad"] }], rejectsArguments()],
|
|
336
288
|
] as const) {
|
|
337
289
|
await assert.rejects(call(edit, { path: "range.txt", edits }), expected);
|
|
338
290
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
|
|
339
291
|
}
|
|
340
292
|
const alternates: Parameters<typeof validateToolArguments>[1]["arguments"][] = [
|
|
341
|
-
{ path: "range.txt",
|
|
342
|
-
{ path: "range.txt", edits: JSON.stringify([{
|
|
293
|
+
{ path: "range.txt", action: "replace", anchor, body: ["ok"] },
|
|
294
|
+
{ path: "range.txt", edits: JSON.stringify([{ action: "replace", anchor, body: ["ok"] }]) },
|
|
343
295
|
];
|
|
344
296
|
for (const alternate of alternates) {
|
|
345
297
|
const before = structuredClone(alternate);
|
|
@@ -347,7 +299,7 @@ test("edit schema rejects misspelled range fields and invalid operation shapes",
|
|
|
347
299
|
assert.deepEqual(alternate, before);
|
|
348
300
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), original);
|
|
349
301
|
}
|
|
350
|
-
await call(edit, { path: "range.txt", edits: [{
|
|
302
|
+
await call(edit, { path: "range.txt", edits: [{ action: "replace", anchor, body: ["B"] }] });
|
|
351
303
|
assert.equal(await readFile(join(dir, "range.txt"), "utf8"), "a\nB\nc\n");
|
|
352
304
|
}));
|
|
353
305
|
|
|
@@ -365,7 +317,7 @@ test("copied string anchors validate and replace an inclusive range", async () =
|
|
|
365
317
|
path: "range.txt",
|
|
366
318
|
edits: [
|
|
367
319
|
{
|
|
368
|
-
|
|
320
|
+
action: "replace",
|
|
369
321
|
anchor: anchorLine(read.content[0].text, 2),
|
|
370
322
|
end: anchorLine(read.content[0].text, 3),
|
|
371
323
|
body: ["merged"],
|
|
@@ -384,13 +336,13 @@ test("invalid anchors and conflicting fields fail before changing the file", asy
|
|
|
384
336
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
385
337
|
const anchor = h(original, 1);
|
|
386
338
|
const invalid = [
|
|
387
|
-
{
|
|
339
|
+
{ action: "replace", anchor: { line: 1, hash: anchor.split("#")[1] }, body: ["changed"] },
|
|
388
340
|
...["0#ABCD", "-1#ABCD", "1.5#ABCD", "1#", "1#abcd", "1#ABCD│a", "9007199254740993#ABCD"].map(
|
|
389
|
-
(anchor) => ({
|
|
341
|
+
(anchor) => ({ action: "replace", anchor, body: ["changed"] }),
|
|
390
342
|
),
|
|
391
|
-
{
|
|
392
|
-
{
|
|
393
|
-
{
|
|
343
|
+
{ action: "insert_after", anchor, end: anchor, body: ["changed"] },
|
|
344
|
+
{ action: "append", anchor, body: ["changed"] },
|
|
345
|
+
{ action: "delete", anchor, body: ["changed"] },
|
|
394
346
|
];
|
|
395
347
|
for (const operation of invalid) {
|
|
396
348
|
await assert.rejects(
|
|
@@ -409,11 +361,11 @@ test("edit rejects empty bodies before file access for arrays and Pi-converted o
|
|
|
409
361
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
410
362
|
const anchor = h(original, 1);
|
|
411
363
|
for (const operation of [
|
|
412
|
-
{
|
|
413
|
-
{
|
|
414
|
-
{
|
|
415
|
-
{
|
|
416
|
-
{
|
|
364
|
+
{ action: "insert_after", anchor, body: [] },
|
|
365
|
+
{ action: "insert_before", anchor, body: [] },
|
|
366
|
+
{ action: "append", body: [] },
|
|
367
|
+
{ action: "prepend", body: [] },
|
|
368
|
+
{ action: "replace", anchor, end: h(original, 2), body: [] },
|
|
417
369
|
]) {
|
|
418
370
|
for (const path of [file, join(dir, "missing.txt")]) {
|
|
419
371
|
for (const edits of [[operation], operation]) {
|
|
@@ -444,10 +396,10 @@ test("mixed empty-body batches name every rejected edit without publishing or ru
|
|
|
444
396
|
{
|
|
445
397
|
path: file,
|
|
446
398
|
edits: [
|
|
447
|
-
{
|
|
448
|
-
{
|
|
449
|
-
{
|
|
450
|
-
{
|
|
399
|
+
{ action: "replace", anchor: h(original, 1), body: ["must not be written"] },
|
|
400
|
+
{ action: "insert_before", anchor: h(original, 3), body: [] },
|
|
401
|
+
{ action: "append", body: ["must not be written"] },
|
|
402
|
+
{ action: "replace", anchor: h(original, 4), body: [] },
|
|
451
403
|
],
|
|
452
404
|
then_run: { command: "must-not-run" },
|
|
453
405
|
},
|
|
@@ -471,11 +423,11 @@ test("blank edit bodies preserve a real blank line for every body-bearing operat
|
|
|
471
423
|
const anchor = h(original, 1);
|
|
472
424
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
473
425
|
for (const [operation, expected] of [
|
|
474
|
-
[{
|
|
475
|
-
[{
|
|
476
|
-
[{
|
|
477
|
-
[{
|
|
478
|
-
[{
|
|
426
|
+
[{ action: "replace", anchor, body: [""] }, "\nb\nc\n"],
|
|
427
|
+
[{ action: "insert_before", anchor, body: [""] }, "\na\nb\nc\n"],
|
|
428
|
+
[{ action: "insert_after", anchor, body: [""] }, "a\n\nb\nc\n"],
|
|
429
|
+
[{ action: "append", body: [""] }, "a\nb\nc\n\n"],
|
|
430
|
+
[{ action: "prepend", body: [""] }, "\na\nb\nc\n"],
|
|
479
431
|
] as const) {
|
|
480
432
|
await writeFile(file, original);
|
|
481
433
|
await call(edit, { path: file, edits: [operation] });
|
|
@@ -490,7 +442,7 @@ test("explicit delete → removes an inclusive range", async () =>
|
|
|
490
442
|
await writeFile(file, original);
|
|
491
443
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
492
444
|
path: file,
|
|
493
|
-
edits: [{
|
|
445
|
+
edits: [{ action: "delete", anchor: h(original, 1), end: h(original, 2) }],
|
|
494
446
|
});
|
|
495
447
|
assert.equal(await readFile(file, "utf8"), "c\n");
|
|
496
448
|
}));
|
|
@@ -506,7 +458,7 @@ test("local and full-file recovery return copyable anchors without changing the
|
|
|
506
458
|
const report = failureReport(
|
|
507
459
|
await call(edit, {
|
|
508
460
|
path: "shift.txt",
|
|
509
|
-
edits: [{
|
|
461
|
+
edits: [{ action: "replace", anchor: h(original, 2), body: ["B"] }],
|
|
510
462
|
}),
|
|
511
463
|
);
|
|
512
464
|
const failure = report.failures?.[0];
|
|
@@ -514,13 +466,12 @@ test("local and full-file recovery return copyable anchors without changing the
|
|
|
514
466
|
replacement = failure.candidate ?? "";
|
|
515
467
|
assert.equal(replacement, h(prefix + original, prefixLines + 2));
|
|
516
468
|
assert.equal(failure.content, "b");
|
|
517
|
-
assert.
|
|
518
|
-
assert.match(report.next ?? "", /confirm.*intended target/);
|
|
469
|
+
assert.match(report.next ?? "", /confirm.*intended target/i);
|
|
519
470
|
assert.equal(report.candidateNeighborhoods, undefined);
|
|
520
471
|
assert.equal(await readFile(join(dir, "shift.txt"), "utf8"), prefix + original);
|
|
521
472
|
await call(edit, {
|
|
522
473
|
path: "shift.txt",
|
|
523
|
-
edits: [{
|
|
474
|
+
edits: [{ action: "replace", anchor: replacement, body: ["B"] }],
|
|
524
475
|
});
|
|
525
476
|
assert.equal(await readFile(join(dir, "shift.txt"), "utf8"), prefix + "a\nB\n");
|
|
526
477
|
}
|
|
@@ -535,11 +486,11 @@ test("shifted-anchor recovery keeps the read fallback for oversized candidates",
|
|
|
535
486
|
const report = failureReport(
|
|
536
487
|
await call(edit, {
|
|
537
488
|
path: "shift-large.txt",
|
|
538
|
-
edits: [{
|
|
489
|
+
edits: [{ action: "replace", anchor: h(original, 2), body: ["B"] }],
|
|
539
490
|
}),
|
|
540
491
|
);
|
|
541
492
|
assert.match(
|
|
542
|
-
report.failures?.[0].
|
|
493
|
+
report.failures?.[0].notShown ?? "",
|
|
543
494
|
new RegExp(`exceeds ${formatByteSize(DEFAULT_OUTPUT_BUDGETS.fieldBytes)}`),
|
|
544
495
|
);
|
|
545
496
|
assert.match(report.next ?? "", /use read or grep/);
|
|
@@ -560,7 +511,10 @@ test("failed commands preserve mutation results and stay out of all main card re
|
|
|
560
511
|
path: "edit.txt",
|
|
561
512
|
run: async () => {
|
|
562
513
|
const tool = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
563
|
-
const args = {
|
|
514
|
+
const args = {
|
|
515
|
+
path: "edit.txt",
|
|
516
|
+
edits: [{ action: "append" as const, body: ["after"] }],
|
|
517
|
+
};
|
|
564
518
|
const result = await callTool(
|
|
565
519
|
tool,
|
|
566
520
|
{ ...args, then_run: { command: "check" } },
|
|
@@ -677,6 +631,58 @@ test("failed commands preserve mutation results and stay out of all main card re
|
|
|
677
631
|
);
|
|
678
632
|
}));
|
|
679
633
|
|
|
634
|
+
test("missing or directory targets → tools share path diagnostics without filesystem changes", async (t) => {
|
|
635
|
+
await withDir(async (dir) => {
|
|
636
|
+
const before = await readdir(dir);
|
|
637
|
+
for (const target of [
|
|
638
|
+
{ name: "missing", path: "./missing.txt", code: "PATH_NOT_FOUND" },
|
|
639
|
+
{ name: "directory", path: ".", code: "NOT_REGULAR_FILE" },
|
|
640
|
+
] as const) {
|
|
641
|
+
const path = target.path;
|
|
642
|
+
const cases = [
|
|
643
|
+
{ tool: makeReadOverride(dir, DEFAULT_CONFIG), args: { path } },
|
|
644
|
+
{
|
|
645
|
+
tool: makeEditOverride(dir, DEFAULT_CONFIG),
|
|
646
|
+
args: { path, edits: [{ action: "append", body: ["changed"] }] },
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
tool: makeReplaceTool(dir, DEFAULT_CONFIG),
|
|
650
|
+
args: { path, replacements: [{ literal: true, find: "old", replace: "changed" }] },
|
|
651
|
+
},
|
|
652
|
+
{ tool: makeWriteOverride(dir), args: { path, content: "changed", mode: "overwrite" } },
|
|
653
|
+
...(target.code === "PATH_NOT_FOUND"
|
|
654
|
+
? [
|
|
655
|
+
{
|
|
656
|
+
tool: makeGrepOverride(dir, DEFAULT_CONFIG),
|
|
657
|
+
args: { path: [path], pattern: ["old"], literal: true },
|
|
658
|
+
},
|
|
659
|
+
]
|
|
660
|
+
: []),
|
|
661
|
+
];
|
|
662
|
+
for (const { tool, args } of cases) {
|
|
663
|
+
await t.test(`${tool.name}/${target.name}`, async () => {
|
|
664
|
+
const report = failureReport(await callTool(tool, args));
|
|
665
|
+
assert.equal(report.error, target.code);
|
|
666
|
+
assert.equal(report.message, PATH_ERROR_MESSAGES[target.code]);
|
|
667
|
+
if (target.code === "PATH_NOT_FOUND") {
|
|
668
|
+
assert.deepEqual(report.missing, [join(dir, "missing.txt")]);
|
|
669
|
+
assert.equal(
|
|
670
|
+
report.next,
|
|
671
|
+
ERROR_DEFINITIONS.PATH_NOT_FOUND.next[
|
|
672
|
+
tool.name === "write" ? "useCreate" : "default"
|
|
673
|
+
],
|
|
674
|
+
);
|
|
675
|
+
} else {
|
|
676
|
+
assert.equal(report.missing, undefined);
|
|
677
|
+
assert.equal(report.next, ERROR_DEFINITIONS.NOT_REGULAR_FILE.next.default);
|
|
678
|
+
}
|
|
679
|
+
assert.deepEqual(await readdir(dir), before);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
|
|
680
686
|
test("text tools reject malformed UTF-8 and NUL bytes without rewriting source bytes", async () =>
|
|
681
687
|
withDir(async (dir) => {
|
|
682
688
|
const target = join(dir, "invalid-utf8.txt");
|
|
@@ -686,7 +692,7 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
|
|
|
686
692
|
[makeReadOverride(dir, DEFAULT_CONFIG), { path: "invalid-utf8.txt" }],
|
|
687
693
|
[
|
|
688
694
|
makeEditOverride(dir, DEFAULT_CONFIG),
|
|
689
|
-
{ path: "invalid-utf8.txt", edits: [{
|
|
695
|
+
{ path: "invalid-utf8.txt", edits: [{ action: "append", body: ["x"] }] },
|
|
690
696
|
],
|
|
691
697
|
[
|
|
692
698
|
makeReplaceTool(dir, DEFAULT_CONFIG),
|
|
@@ -703,7 +709,7 @@ test("text tools reject malformed UTF-8 and NUL bytes without rewriting source b
|
|
|
703
709
|
for (const [tool, args] of [
|
|
704
710
|
[
|
|
705
711
|
makeEditOverride(dir, DEFAULT_CONFIG),
|
|
706
|
-
{ path: "nul.txt", edits: [{
|
|
712
|
+
{ path: "nul.txt", edits: [{ action: "append", body: ["x"] }] },
|
|
707
713
|
],
|
|
708
714
|
[
|
|
709
715
|
makeReplaceTool(dir, DEFAULT_CONFIG),
|
|
@@ -733,7 +739,7 @@ test("edit rejects embedded line terminators at its schema boundary", async () =
|
|
|
733
739
|
await assert.rejects(
|
|
734
740
|
call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
735
741
|
path: "body.txt",
|
|
736
|
-
edits: [{
|
|
742
|
+
edits: [{ action: "append", body: [line] }],
|
|
737
743
|
}),
|
|
738
744
|
rejectsArguments(),
|
|
739
745
|
);
|
|
@@ -745,14 +751,14 @@ test("edit rejects unwritable body lines before reading a missing target", async
|
|
|
745
751
|
withDir(async (dir) => {
|
|
746
752
|
const target = join(dir, "missing.txt");
|
|
747
753
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
748
|
-
const valid = { path: target, edits: [{
|
|
754
|
+
const valid = { path: target, edits: [{ action: "append" as const, body: ["ok"] }] };
|
|
749
755
|
assert.equal(edit.prepareArguments(valid), valid);
|
|
750
756
|
for (const [line, expected] of [
|
|
751
757
|
["bad\0", rejectsArgument("edits[0].body[1]", /NUL/)],
|
|
752
758
|
["\ud800", rejectsArgument("edits[0].body[1]", /losslessly.*UTF-8/)],
|
|
753
759
|
] as const) {
|
|
754
760
|
await assert.rejects(
|
|
755
|
-
call(edit, { path: target, edits: [{
|
|
761
|
+
call(edit, { path: target, edits: [{ action: "append", body: ["ok", line] }] }),
|
|
756
762
|
expected,
|
|
757
763
|
);
|
|
758
764
|
await assert.rejects(readFile(target, "utf8"), { code: "ENOENT" });
|
|
@@ -768,7 +774,7 @@ test("editing a BOM-prefixed file → publishes the changed bytes with the BOM i
|
|
|
768
774
|
await writeFile(target, original);
|
|
769
775
|
const result = await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
770
776
|
path: "bom.txt",
|
|
771
|
-
edits: [{
|
|
777
|
+
edits: [{ action: "replace", anchor: h(source, line), body: ["new"] }],
|
|
772
778
|
});
|
|
773
779
|
const expected = Buffer.from(line === 1 ? "\ufeffnew\nold\n" : "\ufeffguard\nnew\n", "utf8");
|
|
774
780
|
assert.deepEqual(await readFile(target), expected);
|
|
@@ -785,7 +791,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
|
|
|
785
791
|
await assert.rejects(
|
|
786
792
|
call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
787
793
|
path: "output.txt",
|
|
788
|
-
edits: [{
|
|
794
|
+
edits: [{ action: "append", body: ["bad\0text"] }],
|
|
789
795
|
}),
|
|
790
796
|
rejectsArgument("edits[0].body[0]", /NUL/),
|
|
791
797
|
);
|
|
@@ -800,7 +806,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
|
|
|
800
806
|
assert.deepEqual(await readFile(target), original);
|
|
801
807
|
}));
|
|
802
808
|
|
|
803
|
-
test("failed edits
|
|
809
|
+
test("failed edits return candidate code for a verified fused retry", async () =>
|
|
804
810
|
withDir(async (dir) => {
|
|
805
811
|
const original = Array.from({ length: 14 }, (_, index) => `line-${index + 1}`);
|
|
806
812
|
original[4] = "if (!fusion) throw new Error();";
|
|
@@ -823,8 +829,8 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
823
829
|
{
|
|
824
830
|
path: file,
|
|
825
831
|
edits: [
|
|
826
|
-
{
|
|
827
|
-
{
|
|
832
|
+
{ action: "insert_after", anchor: stale, body: ["const hashLen = 4;"] },
|
|
833
|
+
{ action: "replace", anchor: stable, body: ["changed"] },
|
|
828
834
|
],
|
|
829
835
|
then_run: { command: "check" },
|
|
830
836
|
},
|
|
@@ -832,7 +838,7 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
832
838
|
),
|
|
833
839
|
);
|
|
834
840
|
assert.equal(report.then_run?.status, "skipped");
|
|
835
|
-
assert.
|
|
841
|
+
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
836
842
|
assert.equal(report.failures?.[0].field, "edits[0].anchor");
|
|
837
843
|
assert.equal(report.failures?.[0].cited, stale);
|
|
838
844
|
assert.equal(report.failures?.[0].candidate, candidate);
|
|
@@ -847,11 +853,11 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
847
853
|
path: file,
|
|
848
854
|
edits: [
|
|
849
855
|
{
|
|
850
|
-
|
|
856
|
+
action: "insert_after",
|
|
851
857
|
anchor: report.failures![0].candidate!,
|
|
852
858
|
body: ["const hashLen = 4;"],
|
|
853
859
|
},
|
|
854
|
-
{
|
|
860
|
+
{ action: "replace", anchor: stable, body: ["changed"] },
|
|
855
861
|
],
|
|
856
862
|
then_run: { command: "check" },
|
|
857
863
|
},
|
|
@@ -879,12 +885,15 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
|
|
|
879
885
|
await call(edit, {
|
|
880
886
|
path: file,
|
|
881
887
|
edits: [
|
|
882
|
-
{
|
|
888
|
+
{
|
|
889
|
+
action: "replace",
|
|
890
|
+
anchor: h("header\n return value;\n", 2),
|
|
891
|
+
body: [" return updated;"],
|
|
892
|
+
},
|
|
883
893
|
],
|
|
884
894
|
}),
|
|
885
895
|
);
|
|
886
896
|
assert.equal(report.failures?.[0].result, "ambiguous");
|
|
887
|
-
assert.equal(report.failures?.[0].search, "local window");
|
|
888
897
|
assert.deepEqual(report.failures?.[0].candidates, [h(before, 5), h(before, 15)]);
|
|
889
898
|
assert.deepEqual(
|
|
890
899
|
report.candidateNeighborhoods?.map((group) => group.lines),
|
|
@@ -897,13 +906,13 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
|
|
|
897
906
|
assert.equal(await readFile(file, "utf8"), before);
|
|
898
907
|
await call(edit, {
|
|
899
908
|
path: file,
|
|
900
|
-
edits: [{
|
|
909
|
+
edits: [{ action: "replace", anchor: anchorLine(context, 15), body: [" return updated;"] }],
|
|
901
910
|
});
|
|
902
911
|
lines[14] = " return updated;";
|
|
903
912
|
assert.equal(await readFile(file, "utf8"), lines.join("\n") + "\n");
|
|
904
913
|
}));
|
|
905
914
|
|
|
906
|
-
test("schema-invalid bodies
|
|
915
|
+
test("schema-invalid bodies reject before anchor verification; retries revalidate", async () =>
|
|
907
916
|
withDir(async (dir) => {
|
|
908
917
|
const before = "a\nb\nc\n";
|
|
909
918
|
const file = join(dir, "checks.txt");
|
|
@@ -911,19 +920,18 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
911
920
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
912
921
|
const stable = h(before, 1);
|
|
913
922
|
for (const operation of [
|
|
914
|
-
{
|
|
915
|
-
{
|
|
923
|
+
{ action: "replace", anchor: stable, body: ["bad\nline"] },
|
|
924
|
+
{ action: "append", body: ["bad\nline"] },
|
|
916
925
|
]) {
|
|
917
926
|
for (const laterAnchor of [h(before, 2), "2#XXXX"]) {
|
|
918
927
|
await assert.rejects(
|
|
919
928
|
call(edit, {
|
|
920
929
|
path: file,
|
|
921
|
-
edits: [operation, {
|
|
930
|
+
edits: [operation, { action: "replace", anchor: laterAnchor, body: ["B"] }],
|
|
922
931
|
}),
|
|
923
932
|
(error: Error) => {
|
|
924
933
|
rejectsArguments()(error);
|
|
925
934
|
const report = argumentError(error);
|
|
926
|
-
assert.equal(report.matched, undefined);
|
|
927
935
|
assert.equal(report.failures, undefined);
|
|
928
936
|
return true;
|
|
929
937
|
},
|
|
@@ -935,61 +943,42 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
935
943
|
await call(edit, {
|
|
936
944
|
path: file,
|
|
937
945
|
edits: [
|
|
938
|
-
{
|
|
939
|
-
{
|
|
946
|
+
{ action: "replace", anchor: stable, body: ["A"] },
|
|
947
|
+
{ action: "delete", anchor: h(before, 2), end: "3#ZZZZ" },
|
|
940
948
|
],
|
|
941
949
|
}),
|
|
942
950
|
);
|
|
943
|
-
assert.deepEqual(rejected.matched, ["edits[0].anchor", "edits[1].anchor"]);
|
|
944
951
|
assert.equal(rejected.failures?.[0].field, "edits[1].end");
|
|
945
952
|
assert.equal(rejected.failures?.[0].cited, "3#ZZZZ");
|
|
946
|
-
assert.match(rejected.next ?? "", /Retries verify every anchor again/);
|
|
947
953
|
assert.equal(await readFile(file, "utf8"), before);
|
|
948
954
|
await writeFile(file, "changed\nb\nc\n");
|
|
949
955
|
const retry = failureReport(
|
|
950
956
|
await call(edit, {
|
|
951
957
|
path: file,
|
|
952
958
|
edits: [
|
|
953
|
-
{
|
|
954
|
-
{
|
|
959
|
+
{ action: "replace", anchor: stable, body: ["A"] },
|
|
960
|
+
{ action: "replace", anchor: "3#ZZZZ", body: ["B"] },
|
|
955
961
|
],
|
|
956
962
|
}),
|
|
957
963
|
);
|
|
958
|
-
assert.
|
|
959
|
-
retry.failures?.
|
|
960
|
-
|
|
961
|
-
|
|
964
|
+
assert.deepEqual(
|
|
965
|
+
retry.failures?.map(({ field, cited }) => ({ field, cited })),
|
|
966
|
+
[
|
|
967
|
+
{ field: "edits[0].anchor", cited: stable },
|
|
968
|
+
{ field: "edits[1].anchor", cited: "3#ZZZZ" },
|
|
969
|
+
],
|
|
962
970
|
);
|
|
963
|
-
assert.equal(retry.matched, undefined);
|
|
964
971
|
assert.equal(await readFile(file, "utf8"), "changed\nb\nc\n");
|
|
965
972
|
}));
|
|
966
973
|
|
|
967
|
-
test("
|
|
968
|
-
withDir(async (dir) => {
|
|
969
|
-
const file = join(dir, "single.txt");
|
|
970
|
-
const source = "line1\nline2\nline3\n";
|
|
971
|
-
await writeFile(file, source);
|
|
972
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
973
|
-
for (const operation of [
|
|
974
|
-
{ op: "replace", anchor: "1#XXXX", body: ["new"] },
|
|
975
|
-
{ op: "replace", anchor: h(source, 1), end: "2#YYYY", body: ["new"] },
|
|
976
|
-
]) {
|
|
977
|
-
const report = failureReport(await call(edit, { path: file, edits: [operation] }));
|
|
978
|
-
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
979
|
-
assert.equal(report.matched, undefined);
|
|
980
|
-
assert.equal(report.omittedMatched, undefined);
|
|
981
|
-
assert.equal(await readFile(file, "utf8"), source);
|
|
982
|
-
}
|
|
983
|
-
}));
|
|
984
|
-
|
|
985
|
-
test("failed batches return more than forty checks and mappings when byte budgets allow", async () =>
|
|
974
|
+
test("failed batches over forty edits → report every failed anchor and its candidate content", async () =>
|
|
986
975
|
withDir(async (dir) => {
|
|
987
976
|
const original = "a\ntarget\nz\n";
|
|
988
977
|
const before = `prefix\n${original}`;
|
|
989
978
|
const file = join(dir, "many-checks.txt");
|
|
990
979
|
await writeFile(file, before);
|
|
991
980
|
const edits = Array.from({ length: 45 }, () => ({
|
|
992
|
-
|
|
981
|
+
action: "replace",
|
|
993
982
|
anchor: h(original, 2),
|
|
994
983
|
body: ["changed"],
|
|
995
984
|
}));
|
|
@@ -998,10 +987,15 @@ test("failed batches return more than forty checks and mappings when byte budget
|
|
|
998
987
|
);
|
|
999
988
|
assert.equal(report.failures?.length, 45);
|
|
1000
989
|
assert.equal(report.omittedFailures, undefined);
|
|
1001
|
-
assert.
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
990
|
+
assert.deepEqual(
|
|
991
|
+
report.failures?.map((failure) => failure.field),
|
|
992
|
+
edits.map((_, index) => `edits[${index}].anchor`),
|
|
993
|
+
);
|
|
994
|
+
assert.ok(
|
|
995
|
+
report.failures?.every(
|
|
996
|
+
(failure) => failure.candidate === h(before, 3) && failure.content === "target",
|
|
997
|
+
),
|
|
998
|
+
);
|
|
1005
999
|
assert.equal(await readFile(file, "utf8"), before);
|
|
1006
1000
|
}));
|
|
1007
1001
|
|
|
@@ -1014,7 +1008,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
|
|
|
1014
1008
|
const report = failureReport(
|
|
1015
1009
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1016
1010
|
path: file,
|
|
1017
|
-
edits: [{
|
|
1011
|
+
edits: [{ action: "replace", anchor: h(original, 2), body: ["updated"] }],
|
|
1018
1012
|
}),
|
|
1019
1013
|
);
|
|
1020
1014
|
const candidate = report.failures?.[0].candidate;
|
|
@@ -1026,7 +1020,7 @@ test("unique candidate content is independent of oversized neighboring rows", as
|
|
|
1026
1020
|
assert.equal(await readFile(file, "utf8"), before);
|
|
1027
1021
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1028
1022
|
path: file,
|
|
1029
|
-
edits: [{
|
|
1023
|
+
edits: [{ action: "replace", anchor: candidate, body: ["updated"] }],
|
|
1030
1024
|
});
|
|
1031
1025
|
assert.equal(await readFile(file, "utf8"), before.replace("target", "updated"));
|
|
1032
1026
|
}));
|
|
@@ -1057,13 +1051,13 @@ test("shifted unique candidate → displays standalone CR without altering its a
|
|
|
1057
1051
|
await writeFile(file, before);
|
|
1058
1052
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1059
1053
|
path: file,
|
|
1060
|
-
edits: [{
|
|
1054
|
+
edits: [{ action: "delete", anchor: h(before, 1) }],
|
|
1061
1055
|
});
|
|
1062
1056
|
assert.equal(await readFile(file, "utf8"), "a\rb\n");
|
|
1063
1057
|
const report = failureReport(
|
|
1064
1058
|
await call(makeEditOverride(dir, DEFAULT_CONFIG), {
|
|
1065
1059
|
path: file,
|
|
1066
|
-
edits: [{
|
|
1060
|
+
edits: [{ action: "delete", anchor: h(before, 2) }],
|
|
1067
1061
|
}),
|
|
1068
1062
|
);
|
|
1069
1063
|
assert.equal(report.failures?.[0].candidate, h("a\rb\n", 1));
|
|
@@ -1082,8 +1076,8 @@ test("edit receives multiple wrong-length anchors → reports each location with
|
|
|
1082
1076
|
const args = {
|
|
1083
1077
|
path: "f.txt",
|
|
1084
1078
|
edits: [
|
|
1085
|
-
{
|
|
1086
|
-
{
|
|
1079
|
+
{ action: "replace", anchor, end: short, body: ["x"] },
|
|
1080
|
+
{ action: "delete", anchor: short },
|
|
1087
1081
|
],
|
|
1088
1082
|
};
|
|
1089
1083
|
|
|
@@ -1109,7 +1103,7 @@ test("Pi-converted single-object edits execute as a canonical array", async () =
|
|
|
1109
1103
|
const original = "first\nsecond\n";
|
|
1110
1104
|
await writeFile(file, original);
|
|
1111
1105
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
1112
|
-
const operation = {
|
|
1106
|
+
const operation = { action: "replace", anchor: h(original, 2), body: ["SECOND"] };
|
|
1113
1107
|
const args = validateToolArguments(edit as any, {
|
|
1114
1108
|
type: "toolCall",
|
|
1115
1109
|
id: "converted",
|
|
@@ -1131,7 +1125,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
|
|
|
1131
1125
|
const report = failureReport(
|
|
1132
1126
|
await call(edit, {
|
|
1133
1127
|
path: "recover.txt",
|
|
1134
|
-
edits: [{
|
|
1128
|
+
edits: [{ action: "replace", anchor: h(observed, 2), body: ["target = new"] }],
|
|
1135
1129
|
}),
|
|
1136
1130
|
);
|
|
1137
1131
|
const diagnostic = report.failures?.[0].observed ?? "";
|
|
@@ -1143,7 +1137,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
|
|
|
1143
1137
|
const retry = failureReport(
|
|
1144
1138
|
await call(edit, {
|
|
1145
1139
|
path: "recover.txt",
|
|
1146
|
-
edits: [{
|
|
1140
|
+
edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
|
|
1147
1141
|
}),
|
|
1148
1142
|
);
|
|
1149
1143
|
assert.equal(retry.error, "ANCHOR_MISMATCH");
|
|
@@ -1151,7 +1145,7 @@ test("unresolved snapshot rows support direct retry and revalidate after further
|
|
|
1151
1145
|
await writeFile(file, current);
|
|
1152
1146
|
await call(edit, {
|
|
1153
1147
|
path: "recover.txt",
|
|
1154
|
-
edits: [{
|
|
1148
|
+
edits: [{ action: "replace", anchor: retryAnchor, body: ["target = new"] }],
|
|
1155
1149
|
});
|
|
1156
1150
|
assert.deepEqual(await readFile(file), Buffer.from(observed.replace("old", "new")));
|
|
1157
1151
|
});
|
|
@@ -1167,13 +1161,13 @@ test("unresolved oversized and out-of-range rows require more context without pa
|
|
|
1167
1161
|
const report = failureReport(
|
|
1168
1162
|
await call(edit, {
|
|
1169
1163
|
path: "recover.txt",
|
|
1170
|
-
edits: [{
|
|
1164
|
+
edits: [{ action: "replace", anchor, body: ["new"] }],
|
|
1171
1165
|
}),
|
|
1172
1166
|
);
|
|
1173
1167
|
assert.match(report.next ?? "", /read or grep/);
|
|
1174
1168
|
assert.equal(report.failures?.[0].observed, undefined);
|
|
1175
1169
|
assert.equal(
|
|
1176
|
-
report.failures?.[0].
|
|
1170
|
+
report.failures?.[0].notShown,
|
|
1177
1171
|
anchor.startsWith("99#")
|
|
1178
1172
|
? "cited line is out of range"
|
|
1179
1173
|
: `row exceeds ${formatByteSize(DEFAULT_OUTPUT_BUDGETS.fieldBytes)}`,
|
|
@@ -1190,7 +1184,7 @@ test("edit rejects impossible checksum characters before accessing the file", as
|
|
|
1190
1184
|
await assert.rejects(
|
|
1191
1185
|
call(tool, {
|
|
1192
1186
|
path: "missing.txt",
|
|
1193
|
-
edits: [{
|
|
1187
|
+
edits: [{ action: "delete", anchor: `1#${char.repeat(DEFAULT_CONFIG.hashLen)}` }],
|
|
1194
1188
|
}),
|
|
1195
1189
|
rejectsArguments(),
|
|
1196
1190
|
);
|
|
@@ -1208,7 +1202,7 @@ test("ambiguous failure lists and neighborhoods select the same first eight cand
|
|
|
1208
1202
|
const report = failureReport(
|
|
1209
1203
|
await call(tool, {
|
|
1210
1204
|
path: "candidates.txt",
|
|
1211
|
-
edits: [{
|
|
1205
|
+
edits: [{ action: "delete", anchor: `200#${computeLineHash(200, "target", 4)}` }],
|
|
1212
1206
|
}),
|
|
1213
1207
|
);
|
|
1214
1208
|
assert.equal(report.failures?.[0].omittedCandidates, 1);
|
|
@@ -1231,7 +1225,7 @@ test("edit verification → uses the supplied hash length", async () =>
|
|
|
1231
1225
|
path: "registered.txt",
|
|
1232
1226
|
edits: [
|
|
1233
1227
|
{
|
|
1234
|
-
|
|
1228
|
+
action: "replace",
|
|
1235
1229
|
anchor: `1#${computeLineHash(1, "before", 6)}`,
|
|
1236
1230
|
body: ["after"],
|
|
1237
1231
|
},
|
|
@@ -1240,98 +1234,3 @@ test("edit verification → uses the supplied hash length", async () =>
|
|
|
1240
1234
|
assert.equal(result.isError, undefined);
|
|
1241
1235
|
assert.equal(await readFile(join(dir, "registered.txt"), "utf8"), "after\n");
|
|
1242
1236
|
}));
|
|
1243
|
-
|
|
1244
|
-
test("copy/move through read anchors → publishes captured bytes with BOM and mixed endings intact", async () =>
|
|
1245
|
-
withDir(async (dir) => {
|
|
1246
|
-
const path = "transfer.txt";
|
|
1247
|
-
const file = join(dir, path);
|
|
1248
|
-
const source = "\uFEFFA\r\nB\nC\r\nD\n";
|
|
1249
|
-
const read = makeReadOverride(dir, DEFAULT_CONFIG);
|
|
1250
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
1251
|
-
for (const op of ["copy", "move"] as const) {
|
|
1252
|
-
await writeFile(file, source);
|
|
1253
|
-
const observed: Awaited<ReturnType<typeof read.execute>> = await callTool(read, { path });
|
|
1254
|
-
const rows = observed.content
|
|
1255
|
-
.filter((block) => block.type === "text")
|
|
1256
|
-
.map((block) => block.text)
|
|
1257
|
-
.join("\n");
|
|
1258
|
-
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(edit, {
|
|
1259
|
-
path,
|
|
1260
|
-
edits: [
|
|
1261
|
-
{ op, anchor: anchorLine(rows, 1), end: anchorLine(rows, 2), after: anchorLine(rows, 4) },
|
|
1262
|
-
],
|
|
1263
|
-
});
|
|
1264
|
-
const expected = op === "copy" ? source + "A\r\nB\n" : "\uFEFFC\r\nD\nA\r\nB\n";
|
|
1265
|
-
const bytes = Buffer.from(expected, "utf8");
|
|
1266
|
-
assert.deepEqual(await readFile(file), bytes);
|
|
1267
|
-
assert.equal(result.isError, undefined);
|
|
1268
|
-
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
1269
|
-
}
|
|
1270
|
-
}));
|
|
1271
|
-
|
|
1272
|
-
test("copy/move stale destination → report its field and skip publication and fused commands", async () =>
|
|
1273
|
-
withDir(async (dir) => {
|
|
1274
|
-
const original = "A\nB\nC\n";
|
|
1275
|
-
const current = "A\nB\nNEW\n";
|
|
1276
|
-
const file = join(dir, "stale-transfer.txt");
|
|
1277
|
-
await writeFile(file, current);
|
|
1278
|
-
let commands = 0;
|
|
1279
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
1280
|
-
commands++;
|
|
1281
|
-
return { status: "succeeded", result: { content: [{ type: "text", text: "ran" }] } };
|
|
1282
|
-
});
|
|
1283
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
1284
|
-
for (const op of ["copy", "move"] as const) {
|
|
1285
|
-
const report = failureReport(
|
|
1286
|
-
await callTool(edit, {
|
|
1287
|
-
path: file,
|
|
1288
|
-
edits: [
|
|
1289
|
-
{ op, anchor: h(current, 1), after: h(original, 3) },
|
|
1290
|
-
{ op: "replace", anchor: h(current, 2), body: ["changed"] },
|
|
1291
|
-
],
|
|
1292
|
-
then_run: { command: "check" },
|
|
1293
|
-
}),
|
|
1294
|
-
);
|
|
1295
|
-
assert.equal(report.failures?.[0].field, "edits[0].after");
|
|
1296
|
-
assert.equal(report.failures?.[0].cited, h(original, 3));
|
|
1297
|
-
assert.equal(report.then_run?.status, "skipped");
|
|
1298
|
-
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
1299
|
-
assert.equal(await readFile(file, "utf8"), current);
|
|
1300
|
-
assert.equal(commands, 0);
|
|
1301
|
-
}
|
|
1302
|
-
}));
|
|
1303
|
-
|
|
1304
|
-
test("copy/move with fused command → execute after the complete transfer and preserve it on failure", async () =>
|
|
1305
|
-
withDir(async (dir) => {
|
|
1306
|
-
const source = "A\nB\nC\n";
|
|
1307
|
-
const file = join(dir, "fused-transfer.txt");
|
|
1308
|
-
for (const op of ["copy", "move"] as const) {
|
|
1309
|
-
await writeFile(file, source);
|
|
1310
|
-
const expected = op === "copy" ? "A\nB\nC\nA\n" : "B\nC\nA\n";
|
|
1311
|
-
let commands = 0;
|
|
1312
|
-
let commandBytes: string | undefined;
|
|
1313
|
-
const commandFailure = new Error("Command exited with code 7");
|
|
1314
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
1315
|
-
commands++;
|
|
1316
|
-
commandBytes = await readFile(file, "utf8");
|
|
1317
|
-
throw commandFailure;
|
|
1318
|
-
});
|
|
1319
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
1320
|
-
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(
|
|
1321
|
-
edit,
|
|
1322
|
-
{
|
|
1323
|
-
path: file,
|
|
1324
|
-
edits: [{ op, anchor: h(source, 1), after: h(source, 3) }],
|
|
1325
|
-
then_run: { command: "check" },
|
|
1326
|
-
},
|
|
1327
|
-
{ ctx: { cwd: dir } },
|
|
1328
|
-
);
|
|
1329
|
-
assert.equal(reportOf(result, "edit")?.then_run?.status, "failed");
|
|
1330
|
-
assert.equal(reportOf(result, "edit")?.then_run?.output, commandFailure.message);
|
|
1331
|
-
assert.equal(commandBytes, expected);
|
|
1332
|
-
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
1333
|
-
assert.equal(reportOf(result, "edit")?.freshness, undefined);
|
|
1334
|
-
assert.equal(await readFile(file, "utf8"), expected);
|
|
1335
|
-
assert.equal(commands, 1);
|
|
1336
|
-
}
|
|
1337
|
-
}));
|