@criogaid/pi-hashline-edit 0.1.2 → 0.2.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 +67 -21
- package/package.json +1 -1
- package/src/core/apply.test.ts +85 -8
- package/src/core/apply.ts +99 -79
- package/src/core/ranges.test.ts +28 -0
- package/src/core/ranges.ts +25 -0
- package/src/core/text.ts +5 -0
- package/src/core/types.ts +37 -20
- package/src/integration/grep-rg.test.ts +76 -1
- package/src/pi/action-fusion.test.ts +1 -1
- package/src/pi/action-fusion.ts +9 -21
- package/src/pi/anchor-format.test.ts +30 -0
- package/src/pi/anchor-format.ts +28 -0
- package/src/pi/config.test.ts +6 -9
- package/src/pi/config.ts +4 -4
- package/src/pi/edit-tool.ts +90 -99
- package/src/pi/execute.test.ts +240 -14
- package/src/pi/failure-context.test.ts +99 -62
- package/src/pi/failure-context.ts +67 -64
- package/src/pi/failure-path.test.ts +3 -2
- package/src/pi/file-commit.test.ts +21 -0
- package/src/pi/file-commit.ts +35 -3
- package/src/pi/grep-tool.ts +75 -48
- package/src/pi/grep.test.ts +67 -3
- package/src/pi/mutation-result.ts +46 -9
- package/src/pi/read-tool.ts +7 -10
- package/src/pi/registration.test.ts +15 -2
- package/src/pi/render.test.ts +24 -0
- package/src/pi/render.ts +18 -4
- package/src/pi/replace-tool.ts +134 -130
- package/src/pi/replace.test.ts +118 -1
- package/src/pi/result-safety.test.ts +241 -8
- package/src/pi/rg-line-filter.test.ts +7 -1
- package/src/pi/rg-line-filter.ts +9 -11
- package/src/pi/rg-line-ranges.test.ts +10 -0
- package/src/pi/rg-line-ranges.ts +21 -15
- package/src/pi/state.ts +2 -3
- package/src/pi/write-tool.ts +10 -44
- package/src/pi/write.test.ts +25 -36
package/src/pi/write.test.ts
CHANGED
|
@@ -6,8 +6,6 @@ import { test } from "node:test";
|
|
|
6
6
|
import { makeWriteOverride } from "./write-tool.ts";
|
|
7
7
|
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
8
8
|
import { fileRevision } from "./file-commit.ts";
|
|
9
|
-
import { makeEditOverride } from "./edit-tool.ts";
|
|
10
|
-
import { getState } from "./state.ts";
|
|
11
9
|
|
|
12
10
|
const context = (cwd: string) => ({ cwd }) as any;
|
|
13
11
|
|
|
@@ -25,7 +23,10 @@ test("write schema follows the shared actionFusion switch", () => {
|
|
|
25
23
|
test("write preserves native default create/overwrite behavior", async () => withTemp(async (dir) => {
|
|
26
24
|
const write = makeWriteOverride(dir) as any;
|
|
27
25
|
const target = join(dir, "file.txt");
|
|
28
|
-
await write.execute("create", { path: "file.txt", content: "one\n" }, undefined, undefined, context(dir));
|
|
26
|
+
const created = await write.execute("create", { path: "file.txt", content: "one\n" }, undefined, undefined, context(dir));
|
|
27
|
+
assert.doesNotMatch(created.content[0].text, /Revision:|[0-9a-f]{64}/);
|
|
28
|
+
assert.equal(created.details.publishedRevision, await fileRevision(target));
|
|
29
|
+
assert.equal(created.details.revision, created.details.publishedRevision);
|
|
29
30
|
assert.equal(await readFile(target, "utf8"), "one\n");
|
|
30
31
|
await write.execute("overwrite", { path: "file.txt", content: "two\n" }, undefined, undefined, context(dir));
|
|
31
32
|
assert.equal(await readFile(target, "utf8"), "two\n");
|
|
@@ -56,72 +57,60 @@ test("concurrent writes cannot both consume the same expectedRevision", async ()
|
|
|
56
57
|
assert.match(rejected.reason.message, /expectedRevision/);
|
|
57
58
|
}));
|
|
58
59
|
|
|
59
|
-
test("write
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
assert.ok(anchor);
|
|
67
|
-
assert.equal(anchor[1].length, 6);
|
|
68
|
-
assert.doesNotMatch(result.content[0].text, /before|│/);
|
|
69
|
-
await makeEditOverride(dir).execute("edit", { path: "anchors.txt", edits: [{ op: "replace", anchor: anchor[0], body: ["after"] }] }, undefined, undefined, context(dir));
|
|
70
|
-
assert.equal(await readFile(join(dir, "anchors.txt"), "utf8"), "after\n");
|
|
71
|
-
} finally {
|
|
72
|
-
state.config = previousConfig;
|
|
60
|
+
test("write returns only a summary for empty, short, and long content", async () => withTemp(async (dir) => {
|
|
61
|
+
const contents = ["", "before\n", Array.from({ length: 500 }, (_, index) => `line ${index + 1}`).join("\n")];
|
|
62
|
+
for (const [index, content] of contents.entries()) {
|
|
63
|
+
const path = `file-${index}.txt`;
|
|
64
|
+
const result = await makeWriteOverride(dir).execute("write", { path, content }, undefined, undefined, context(dir));
|
|
65
|
+
assert.deepEqual(result.content, [{ type: "text", text: `Created ${path}.` }]);
|
|
66
|
+
assert.equal(await readFile(join(dir, path), "utf8"), content);
|
|
73
67
|
}
|
|
74
68
|
}));
|
|
75
69
|
|
|
76
|
-
test("write returns
|
|
77
|
-
const content = Array.from({ length: 500 }, (_, index) => `line ${index + 1}`).join("\n");
|
|
78
|
-
const result = await makeWriteOverride(dir).execute("write", { path: "large.txt", content }, undefined, undefined, context(dir));
|
|
79
|
-
assert.equal(result.content[0].text.match(/\b\d+#[0-9A-Z]+\b/g)?.length, 40);
|
|
80
|
-
assert.match(result.content[0].text, /… \(460 more/);
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
test("write publishes anchors after an unchanged then_run", async () => withTemp(async (dir) => {
|
|
70
|
+
test("write returns its summary and command output after an unchanged then_run", async () => withTemp(async (dir) => {
|
|
84
71
|
const fusion = createActionFusionExecutor(async () => "checked");
|
|
85
72
|
const write = makeWriteOverride(dir, fusion) as any;
|
|
86
73
|
const result = await write.execute("unchanged", { path: "unchanged.txt", content: "mutation\n", then_run: { command: "check" } }, undefined, undefined, context(dir));
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
assert.deepEqual(result.content, [
|
|
75
|
+
{ type: "text", text: "Created unchanged.txt." },
|
|
76
|
+
{ type: "text", text: "[then_run:succeeded]\nchecked" },
|
|
77
|
+
]);
|
|
90
78
|
assert.equal(result.details.actionFusion.freshness, "unchanged");
|
|
91
79
|
}));
|
|
92
80
|
|
|
93
|
-
test("write
|
|
81
|
+
test("write reports changed freshness when then_run changes the target", async () => withTemp(async (dir) => {
|
|
94
82
|
const target = join(dir, "changed.txt");
|
|
95
83
|
const fusion = createActionFusionExecutor(async () => { await writeFile(target, "command changed\n"); return "checked"; });
|
|
96
84
|
const write = makeWriteOverride(dir, fusion) as any;
|
|
97
85
|
const result = await write.execute("changed", { path: "changed.txt", content: "mutation\n", then_run: { command: "check" } }, undefined, undefined, context(dir));
|
|
98
86
|
const text = result.content.map((block: any) => block.text).join("\n");
|
|
99
|
-
assert.
|
|
100
|
-
assert.
|
|
101
|
-
assert.match(
|
|
87
|
+
assert.doesNotMatch(text, /revision:|[0-9a-f]{64}/i);
|
|
88
|
+
assert.doesNotMatch(text, /anchors are omitted/);
|
|
89
|
+
assert.equal((text.match(/Re-read/g) ?? []).length, 1);
|
|
90
|
+
assert.equal((text.match(/\[then_run:stale\]/g) ?? []).length, 1);
|
|
102
91
|
assert.doesNotMatch(text, /Fresh anchors:|\b1#[0-9A-Z]+\b/);
|
|
103
92
|
assert.equal(result.details.actionFusion.freshness, "changed");
|
|
104
93
|
assert.deepEqual(write.renderResult(result, { isPartial: false }, {}, { isError: false }).render(100), []);
|
|
105
94
|
}));
|
|
106
95
|
|
|
107
|
-
test("write
|
|
96
|
+
test("write reports missing freshness when then_run removes the target", async () => withTemp(async (dir) => {
|
|
108
97
|
const target = join(dir, "missing.txt");
|
|
109
98
|
const fusion = createActionFusionExecutor(async () => { await rm(target); return "removed"; });
|
|
110
99
|
const result = await makeWriteOverride(dir, fusion).execute("missing", { path: "missing.txt", content: "mutation\n", then_run: { command: "remove" } }, undefined, undefined, context(dir));
|
|
111
100
|
const text = result.content.map((block: any) => block.text).join("\n");
|
|
112
101
|
assert.equal(result.details.actionFusion.freshness, "missing");
|
|
113
|
-
assert.match(text, /
|
|
102
|
+
assert.match(text, /Re-read/);
|
|
114
103
|
assert.doesNotMatch(text, /Fresh anchors:/);
|
|
115
104
|
}));
|
|
116
105
|
|
|
117
|
-
test("write
|
|
106
|
+
test("write preserves command failure and changed freshness", async () => withTemp(async (dir) => {
|
|
118
107
|
const target = join(dir, "failed.txt");
|
|
119
108
|
const fusion = createActionFusionExecutor(async () => { await writeFile(target, "changed before failure\n"); throw new Error("command failed"); });
|
|
120
109
|
const result = await makeWriteOverride(dir, fusion).execute("failed", { path: "failed.txt", content: "mutation\n", then_run: { command: "fail" } }, undefined, undefined, context(dir));
|
|
121
110
|
const text = result.content.map((block: any) => block.text).join("\n");
|
|
122
111
|
assert.equal(result.details.actionFusion.freshness, "changed");
|
|
123
112
|
assert.equal(result.details.actionFusion.command, "failed");
|
|
124
|
-
assert.match(text, /
|
|
113
|
+
assert.match(text, /Re-read/);
|
|
125
114
|
assert.doesNotMatch(text, /Fresh anchors:/);
|
|
126
115
|
}));
|
|
127
116
|
|