@criogaid/pi-hashline-edit 0.9.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 +9 -10
- package/README.zh-CN.md +8 -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 +96 -271
- package/src/core/apply.ts +62 -169
- 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/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/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 +118 -20
- 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 +2 -1
- package/src/integration/publication-read-changes.test.ts +123 -45
- package/src/integration/replace-worker-boundary.test.ts +21 -11
- package/src/integration/report-replay.test.ts +20 -22
- package/src/pi/AGENTS.md +15 -15
- package/src/pi/action-fusion.test.ts +164 -296
- 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 +21 -25
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-validation.test.ts +129 -157
- 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 +46 -156
- package/src/pi/error-text.ts +4 -8
- package/src/pi/execute.test.ts +83 -196
- package/src/pi/failure-context.test.ts +144 -126
- package/src/pi/failure-context.ts +44 -93
- 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 +80 -45
- 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 +36 -14
- package/src/pi/path.ts +1 -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 +64 -36
- package/src/pi/render.test.ts +38 -28
- package/src/pi/render.ts +59 -63
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +20 -82
- 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 +62 -81
- package/src/pi/report.test.ts +171 -25
- package/src/pi/report.ts +33 -87
- package/src/pi/result-safety.test.ts +149 -176
- 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
|
|
|
@@ -99,24 +99,6 @@ test("edit execute: hashline round-trip (read → edit → file changed)", async
|
|
|
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
|
-
{ action: "insert_after", anchor: h(text, 3), body: ["z"] },
|
|
112
|
-
{ action: "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]) {
|
|
@@ -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: [{ action: "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");
|
|
@@ -230,7 +196,7 @@ test("unresolved observations require target confirmation before retrying a move
|
|
|
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);
|
|
@@ -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: [{ action: "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");
|
|
@@ -514,8 +466,7 @@ 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, {
|
|
@@ -539,7 +490,7 @@ test("shifted-anchor recovery keeps the read fallback for oversized candidates",
|
|
|
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/);
|
|
@@ -680,6 +631,58 @@ test("failed commands preserve mutation results and stay out of all main card re
|
|
|
680
631
|
);
|
|
681
632
|
}));
|
|
682
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
|
+
|
|
683
686
|
test("text tools reject malformed UTF-8 and NUL bytes without rewriting source bytes", async () =>
|
|
684
687
|
withDir(async (dir) => {
|
|
685
688
|
const target = join(dir, "invalid-utf8.txt");
|
|
@@ -803,7 +806,7 @@ test("edit and replace reject NUL arguments without rewriting source bytes", asy
|
|
|
803
806
|
assert.deepEqual(await readFile(target), original);
|
|
804
807
|
}));
|
|
805
808
|
|
|
806
|
-
test("failed edits
|
|
809
|
+
test("failed edits return candidate code for a verified fused retry", async () =>
|
|
807
810
|
withDir(async (dir) => {
|
|
808
811
|
const original = Array.from({ length: 14 }, (_, index) => `line-${index + 1}`);
|
|
809
812
|
original[4] = "if (!fusion) throw new Error();";
|
|
@@ -835,7 +838,7 @@ test("failed edits expose input status and candidate code for a verified fused r
|
|
|
835
838
|
),
|
|
836
839
|
);
|
|
837
840
|
assert.equal(report.then_run?.status, "skipped");
|
|
838
|
-
assert.
|
|
841
|
+
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
839
842
|
assert.equal(report.failures?.[0].field, "edits[0].anchor");
|
|
840
843
|
assert.equal(report.failures?.[0].cited, stale);
|
|
841
844
|
assert.equal(report.failures?.[0].candidate, candidate);
|
|
@@ -891,7 +894,6 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
|
|
|
891
894
|
}),
|
|
892
895
|
);
|
|
893
896
|
assert.equal(report.failures?.[0].result, "ambiguous");
|
|
894
|
-
assert.equal(report.failures?.[0].search, "local window");
|
|
895
897
|
assert.deepEqual(report.failures?.[0].candidates, [h(before, 5), h(before, 15)]);
|
|
896
898
|
assert.deepEqual(
|
|
897
899
|
report.candidateNeighborhoods?.map((group) => group.lines),
|
|
@@ -910,7 +912,7 @@ test("ambiguous candidates include distinguishing neighborhoods for a verified r
|
|
|
910
912
|
assert.equal(await readFile(file, "utf8"), lines.join("\n") + "\n");
|
|
911
913
|
}));
|
|
912
914
|
|
|
913
|
-
test("schema-invalid bodies
|
|
915
|
+
test("schema-invalid bodies reject before anchor verification; retries revalidate", async () =>
|
|
914
916
|
withDir(async (dir) => {
|
|
915
917
|
const before = "a\nb\nc\n";
|
|
916
918
|
const file = join(dir, "checks.txt");
|
|
@@ -930,7 +932,6 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
930
932
|
(error: Error) => {
|
|
931
933
|
rejectsArguments()(error);
|
|
932
934
|
const report = argumentError(error);
|
|
933
|
-
assert.equal(report.matched, undefined);
|
|
934
935
|
assert.equal(report.failures, undefined);
|
|
935
936
|
return true;
|
|
936
937
|
},
|
|
@@ -947,10 +948,8 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
947
948
|
],
|
|
948
949
|
}),
|
|
949
950
|
);
|
|
950
|
-
assert.deepEqual(rejected.matched, ["edits[0].anchor", "edits[1].anchor"]);
|
|
951
951
|
assert.equal(rejected.failures?.[0].field, "edits[1].end");
|
|
952
952
|
assert.equal(rejected.failures?.[0].cited, "3#ZZZZ");
|
|
953
|
-
assert.match(rejected.next ?? "", /Retries verify every anchor again/);
|
|
954
953
|
assert.equal(await readFile(file, "utf8"), before);
|
|
955
954
|
await writeFile(file, "changed\nb\nc\n");
|
|
956
955
|
const retry = failureReport(
|
|
@@ -962,34 +961,17 @@ test("schema-invalid bodies omit anchor checks; subsequent retries revalidate",
|
|
|
962
961
|
],
|
|
963
962
|
}),
|
|
964
963
|
);
|
|
965
|
-
assert.
|
|
966
|
-
retry.failures?.
|
|
967
|
-
|
|
968
|
-
|
|
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
|
+
],
|
|
969
970
|
);
|
|
970
|
-
assert.equal(retry.matched, undefined);
|
|
971
971
|
assert.equal(await readFile(file, "utf8"), "changed\nb\nc\n");
|
|
972
972
|
}));
|
|
973
973
|
|
|
974
|
-
test("
|
|
975
|
-
withDir(async (dir) => {
|
|
976
|
-
const file = join(dir, "single.txt");
|
|
977
|
-
const source = "line1\nline2\nline3\n";
|
|
978
|
-
await writeFile(file, source);
|
|
979
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
980
|
-
for (const operation of [
|
|
981
|
-
{ action: "replace", anchor: "1#XXXX", body: ["new"] },
|
|
982
|
-
{ action: "replace", anchor: h(source, 1), end: "2#YYYY", body: ["new"] },
|
|
983
|
-
]) {
|
|
984
|
-
const report = failureReport(await call(edit, { path: file, edits: [operation] }));
|
|
985
|
-
assert.equal(report.error, "ANCHOR_MISMATCH");
|
|
986
|
-
assert.equal(report.matched, undefined);
|
|
987
|
-
assert.equal(report.omittedMatched, undefined);
|
|
988
|
-
assert.equal(await readFile(file, "utf8"), source);
|
|
989
|
-
}
|
|
990
|
-
}));
|
|
991
|
-
|
|
992
|
-
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 () =>
|
|
993
975
|
withDir(async (dir) => {
|
|
994
976
|
const original = "a\ntarget\nz\n";
|
|
995
977
|
const before = `prefix\n${original}`;
|
|
@@ -1005,10 +987,15 @@ test("failed batches return more than forty checks and mappings when byte budget
|
|
|
1005
987
|
);
|
|
1006
988
|
assert.equal(report.failures?.length, 45);
|
|
1007
989
|
assert.equal(report.omittedFailures, undefined);
|
|
1008
|
-
assert.
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
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
|
+
);
|
|
1012
999
|
assert.equal(await readFile(file, "utf8"), before);
|
|
1013
1000
|
}));
|
|
1014
1001
|
|
|
@@ -1180,7 +1167,7 @@ test("unresolved oversized and out-of-range rows require more context without pa
|
|
|
1180
1167
|
assert.match(report.next ?? "", /read or grep/);
|
|
1181
1168
|
assert.equal(report.failures?.[0].observed, undefined);
|
|
1182
1169
|
assert.equal(
|
|
1183
|
-
report.failures?.[0].
|
|
1170
|
+
report.failures?.[0].notShown,
|
|
1184
1171
|
anchor.startsWith("99#")
|
|
1185
1172
|
? "cited line is out of range"
|
|
1186
1173
|
: `row exceeds ${formatByteSize(DEFAULT_OUTPUT_BUDGETS.fieldBytes)}`,
|
|
@@ -1247,103 +1234,3 @@ test("edit verification → uses the supplied hash length", async () =>
|
|
|
1247
1234
|
assert.equal(result.isError, undefined);
|
|
1248
1235
|
assert.equal(await readFile(join(dir, "registered.txt"), "utf8"), "after\n");
|
|
1249
1236
|
}));
|
|
1250
|
-
|
|
1251
|
-
test("copy/move through read anchors → publishes captured bytes with BOM and mixed endings intact", async () =>
|
|
1252
|
-
withDir(async (dir) => {
|
|
1253
|
-
const path = "transfer.txt";
|
|
1254
|
-
const file = join(dir, path);
|
|
1255
|
-
const source = "\uFEFFA\r\nB\nC\r\nD\n";
|
|
1256
|
-
const read = makeReadOverride(dir, DEFAULT_CONFIG);
|
|
1257
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG);
|
|
1258
|
-
for (const op of ["copy", "move"] as const) {
|
|
1259
|
-
await writeFile(file, source);
|
|
1260
|
-
const observed: Awaited<ReturnType<typeof read.execute>> = await callTool(read, { path });
|
|
1261
|
-
const rows = observed.content
|
|
1262
|
-
.filter((block) => block.type === "text")
|
|
1263
|
-
.map((block) => block.text)
|
|
1264
|
-
.join("\n");
|
|
1265
|
-
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(edit, {
|
|
1266
|
-
path,
|
|
1267
|
-
edits: [
|
|
1268
|
-
{
|
|
1269
|
-
action: op,
|
|
1270
|
-
anchor: anchorLine(rows, 1),
|
|
1271
|
-
end: anchorLine(rows, 2),
|
|
1272
|
-
after: anchorLine(rows, 4),
|
|
1273
|
-
},
|
|
1274
|
-
],
|
|
1275
|
-
});
|
|
1276
|
-
const expected = op === "copy" ? source + "A\r\nB\n" : "\uFEFFC\r\nD\nA\r\nB\n";
|
|
1277
|
-
const bytes = Buffer.from(expected, "utf8");
|
|
1278
|
-
assert.deepEqual(await readFile(file), bytes);
|
|
1279
|
-
assert.equal(result.isError, undefined);
|
|
1280
|
-
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
1281
|
-
}
|
|
1282
|
-
}));
|
|
1283
|
-
|
|
1284
|
-
test("copy/move stale destination → report its field and skip publication and fused commands", async () =>
|
|
1285
|
-
withDir(async (dir) => {
|
|
1286
|
-
const original = "A\nB\nC\n";
|
|
1287
|
-
const current = "A\nB\nNEW\n";
|
|
1288
|
-
const file = join(dir, "stale-transfer.txt");
|
|
1289
|
-
await writeFile(file, current);
|
|
1290
|
-
let commands = 0;
|
|
1291
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
1292
|
-
commands++;
|
|
1293
|
-
return { status: "succeeded", result: { content: [{ type: "text", text: "ran" }] } };
|
|
1294
|
-
});
|
|
1295
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
1296
|
-
for (const op of ["copy", "move"] as const) {
|
|
1297
|
-
const report = failureReport(
|
|
1298
|
-
await callTool(edit, {
|
|
1299
|
-
path: file,
|
|
1300
|
-
edits: [
|
|
1301
|
-
{ action: op, anchor: h(current, 1), after: h(original, 3) },
|
|
1302
|
-
{ action: "replace", anchor: h(current, 2), body: ["changed"] },
|
|
1303
|
-
],
|
|
1304
|
-
then_run: { command: "check" },
|
|
1305
|
-
}),
|
|
1306
|
-
);
|
|
1307
|
-
assert.equal(report.failures?.[0].field, "edits[0].after");
|
|
1308
|
-
assert.equal(report.failures?.[0].cited, h(original, 3));
|
|
1309
|
-
assert.equal(report.then_run?.status, "skipped");
|
|
1310
|
-
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
1311
|
-
assert.equal(await readFile(file, "utf8"), current);
|
|
1312
|
-
assert.equal(commands, 0);
|
|
1313
|
-
}
|
|
1314
|
-
}));
|
|
1315
|
-
|
|
1316
|
-
test("copy/move with fused command → execute after the complete transfer and preserve it on failure", async () =>
|
|
1317
|
-
withDir(async (dir) => {
|
|
1318
|
-
const source = "A\nB\nC\n";
|
|
1319
|
-
const file = join(dir, "fused-transfer.txt");
|
|
1320
|
-
for (const op of ["copy", "move"] as const) {
|
|
1321
|
-
await writeFile(file, source);
|
|
1322
|
-
const expected = op === "copy" ? "A\nB\nC\nA\n" : "B\nC\nA\n";
|
|
1323
|
-
let commands = 0;
|
|
1324
|
-
let commandBytes: string | undefined;
|
|
1325
|
-
const commandFailure = new Error("Command exited with code 7");
|
|
1326
|
-
const fusion = createActionFusionExecutor(async () => {
|
|
1327
|
-
commands++;
|
|
1328
|
-
commandBytes = await readFile(file, "utf8");
|
|
1329
|
-
throw commandFailure;
|
|
1330
|
-
});
|
|
1331
|
-
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
1332
|
-
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(
|
|
1333
|
-
edit,
|
|
1334
|
-
{
|
|
1335
|
-
path: file,
|
|
1336
|
-
edits: [{ action: op, anchor: h(source, 1), after: h(source, 3) }],
|
|
1337
|
-
then_run: { command: "check" },
|
|
1338
|
-
},
|
|
1339
|
-
{ ctx: { cwd: dir } },
|
|
1340
|
-
);
|
|
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);
|
|
1346
|
-
assert.equal(await readFile(file, "utf8"), expected);
|
|
1347
|
-
assert.equal(commands, 1);
|
|
1348
|
-
}
|
|
1349
|
-
}));
|