@criogaid/pi-hashline-edit 0.5.0 → 0.6.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 +66 -22
- package/package.json +6 -6
- package/src/core/apply.test.ts +66 -16
- package/src/core/apply.ts +36 -19
- package/src/core/lines.ts +3 -3
- package/src/core/text.test.ts +30 -1
- package/src/core/text.ts +8 -3
- package/src/index.ts +2 -0
- package/src/integration/forget-grep.test.ts +98 -0
- package/src/integration/fusion-dispatch.test.ts +343 -0
- package/src/integration/grep-rg.test.ts +466 -111
- package/src/integration/large-text.test.ts +3 -5
- package/src/integration/mutation-file-types.test.ts +44 -0
- package/src/pi/action-fusion.test.ts +158 -79
- package/src/pi/action-fusion.ts +105 -34
- package/src/pi/anchor-format.test.ts +46 -0
- package/src/pi/anchor-format.ts +21 -2
- package/src/pi/argument-validation.test.ts +136 -0
- package/src/pi/argument-validation.ts +103 -0
- package/src/pi/budgets.ts +4 -1
- package/src/pi/config.test.ts +1 -0
- package/src/pi/config.ts +4 -0
- package/src/pi/diagnostic-buffer.test.ts +58 -0
- package/src/pi/diagnostic-buffer.ts +59 -0
- package/src/pi/directory-sync.test.ts +1 -1
- package/src/pi/edit-tool.ts +56 -37
- package/src/pi/execute.test.ts +185 -645
- package/src/pi/failure-context.test.ts +4 -3
- package/src/pi/failure-path.test.ts +3 -3
- package/src/pi/file-commit.test.ts +24 -17
- package/src/pi/file-commit.ts +36 -9
- package/src/pi/file-snapshot.test.ts +24 -0
- package/src/pi/forget-tool.ts +268 -0
- package/src/pi/forget.test.ts +343 -0
- package/src/pi/forget.testing.ts +273 -0
- package/src/pi/fusion-card.test.ts +26 -0
- package/src/pi/fusion-card.ts +21 -6
- package/src/pi/grep-output.ts +82 -55
- package/src/pi/grep-render.ts +8 -11
- package/src/pi/grep-scope.ts +6 -31
- package/src/pi/grep-search.ts +94 -58
- package/src/pi/grep-tool.ts +50 -59
- package/src/pi/grep.test.ts +412 -208
- package/src/pi/mutation-result.test.ts +23 -0
- package/src/pi/mutation-runner.ts +8 -4
- package/src/pi/path.ts +16 -2
- package/src/pi/pi.test.ts +4 -3
- package/src/pi/read-tool.ts +59 -27
- package/src/pi/read.test.ts +361 -0
- package/src/pi/registration.test.ts +121 -4
- package/src/pi/render.test.ts +172 -15
- package/src/pi/render.ts +28 -5
- package/src/pi/replace-tool.ts +18 -27
- package/src/pi/replace.test.ts +8 -107
- package/src/pi/result-safety.test.ts +123 -149
- package/src/pi/rg-match-bytes.ts +95 -0
- package/src/pi/rg-process.test.ts +40 -59
- package/src/pi/rg-process.ts +8 -5
- package/src/pi/rg-text-view.ts +59 -9
- package/src/pi/text-stream.test.ts +153 -0
- package/src/pi/text-stream.ts +33 -13
- package/src/pi/tool-call.testing.ts +50 -0
- package/src/pi/tool-prompts.ts +15 -0
- package/src/pi/write-tool.ts +19 -26
- package/src/pi/write.test.ts +70 -61
- package/src/pi/e2e-scenarios.test.ts +0 -360
|
@@ -33,11 +33,9 @@ test("read and line-based grep retain anchors on LF and CRLF files over 100 MiB"
|
|
|
33
33
|
assert.ok(first.content[0].text.includes(`1#${computeLineHash(1, "needle", 4)}│needle`));
|
|
34
34
|
const last: any = await call(read, { path, offset: 103426, limit: 1 });
|
|
35
35
|
assert.ok(last.content[0].text.includes(`103426#${computeLineHash(103426, "tail", 4)}│tail`));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
assert.doesNotMatch(result.content[0].text, /Search incomplete/);
|
|
40
|
-
}
|
|
36
|
+
const result: any = await call(grep, { path, pattern: "needle", literal: true });
|
|
37
|
+
assert.ok(result.content[0].text.includes(`1#${computeLineHash(1, "needle", 4)}│needle`));
|
|
38
|
+
assert.doesNotMatch(result.content[0].text, /Search incomplete/);
|
|
41
39
|
}
|
|
42
40
|
} finally {
|
|
43
41
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
3
|
+
import { mkdtemp, rm, symlink } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
|
|
9
|
+
const execFile = promisify(execFileCallback);
|
|
10
|
+
|
|
11
|
+
test("FIFO mutation targets → reject without waiting for a writer, including through a symlink", {
|
|
12
|
+
skip: process.platform === "win32" ? "POSIX FIFO behavior" : false,
|
|
13
|
+
}, async (t) => {
|
|
14
|
+
const directory = await mkdtemp(join(tmpdir(), "hashline-fifo-"));
|
|
15
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
16
|
+
const fifo = join(directory, "pipe");
|
|
17
|
+
await execFile("mkfifo", [fifo]);
|
|
18
|
+
await symlink("pipe", join(directory, "alias"));
|
|
19
|
+
const moduleUrl = (path: string) => JSON.stringify(new URL(path, import.meta.url).href);
|
|
20
|
+
// Isolate a blocking open so a regression cannot leave the test runner's I/O threads stuck.
|
|
21
|
+
const script = `
|
|
22
|
+
import assert from "node:assert/strict";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
import { makeEditOverride } from ${moduleUrl("../pi/edit-tool.ts")};
|
|
25
|
+
import { makeReplaceTool } from ${moduleUrl("../pi/replace-tool.ts")};
|
|
26
|
+
import { DEFAULT_CONFIG } from ${moduleUrl("../pi/config.ts")};
|
|
27
|
+
import { callTool } from ${moduleUrl("../pi/tool-call.testing.ts")};
|
|
28
|
+
const directory = process.argv[1];
|
|
29
|
+
const cases = [
|
|
30
|
+
[makeEditOverride(directory, DEFAULT_CONFIG), { edits: [{ op: "append", body: ["after"] }] }],
|
|
31
|
+
[makeReplaceTool(directory, DEFAULT_CONFIG), { replacements: [{ find: "before", replace: "after" }] }],
|
|
32
|
+
];
|
|
33
|
+
for (const path of ["pipe", "alias"]) {
|
|
34
|
+
for (const [tool, args] of cases) {
|
|
35
|
+
await assert.rejects(callTool(tool, { path: join(directory, path), ...args }),
|
|
36
|
+
error => /not a regular file/.test(error.message) && error.publication === "NOT_PUBLISHED");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
await execFile(process.execPath, ["--input-type=module", "--eval", script, directory], {
|
|
41
|
+
timeout: 10_000,
|
|
42
|
+
killSignal: "SIGKILL",
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -3,13 +3,12 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
import
|
|
7
|
-
import { callTool } from "./tool-call.testing.ts";
|
|
6
|
+
import { callTool, createToolContext as ctx } from "./tool-call.testing.ts";
|
|
8
7
|
import { makeEditOverride } from "./edit-tool.ts";
|
|
9
8
|
import { makeReplaceTool } from "./replace-tool.ts";
|
|
10
9
|
import { makeWriteOverride } from "./write-tool.ts";
|
|
11
10
|
import { computeLineHash } from "../core/hash.ts";
|
|
12
|
-
import type { ActionFusionProgress } from "./action-fusion.ts";
|
|
11
|
+
import type { ActionFusionProgress, CommandOutcome } from "./action-fusion.ts";
|
|
13
12
|
import {
|
|
14
13
|
ACTION_FUSION_GUIDELINES,
|
|
15
14
|
ActionFusionError,
|
|
@@ -28,8 +27,6 @@ async function tempDir(): Promise<string> {
|
|
|
28
27
|
return mkdtemp(join(tmpdir(), "hashline-action-fusion-"));
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
const ctx = (cwd: string) => ({ cwd }) as ExtensionContext;
|
|
32
|
-
|
|
33
30
|
type Fusion = Parameters<typeof makeWriteOverride>[1];
|
|
34
31
|
const mutationFactories = [
|
|
35
32
|
(cwd: string, fusion?: Fusion) => makeEditOverride(cwd, DEFAULT_CONFIG, fusion),
|
|
@@ -58,7 +55,7 @@ test("mutation tools expose Fusion schemas and guidance when supplied an executo
|
|
|
58
55
|
}
|
|
59
56
|
});
|
|
60
57
|
|
|
61
|
-
test("then_run schemas reject invalid commands, unknown keys, and excessive timeouts", async () => {
|
|
58
|
+
test("then_run schemas reject invalid commands, unknown keys, and excessive timeouts", async (t) => {
|
|
62
59
|
const dir = await tempDir();
|
|
63
60
|
try {
|
|
64
61
|
for (const makeTool of mutationFactories) {
|
|
@@ -70,7 +67,7 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
|
|
|
70
67
|
? { edits: [{ op: "append", body: ["new"] }] }
|
|
71
68
|
: tool.name === "replace"
|
|
72
69
|
? { replacements: [{ find: "old", replace: "new" }] }
|
|
73
|
-
: { content: "new\n" };
|
|
70
|
+
: { content: "new\n", mode: "overwrite" };
|
|
74
71
|
for (const then_run of [
|
|
75
72
|
{},
|
|
76
73
|
{ command: " " },
|
|
@@ -78,7 +75,7 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
|
|
|
78
75
|
{ command: "echo ok", timeout: 2_147_483.648 },
|
|
79
76
|
]) {
|
|
80
77
|
await assert.rejects(
|
|
81
|
-
callTool(tool, { path, ...mutation, then_run }, { ctx: ctx(dir) }),
|
|
78
|
+
callTool(tool, { path, ...mutation, then_run }, { ctx: await ctx(dir, t) }),
|
|
82
79
|
new RegExp(`Validation failed for tool "${tool.name}":[\\s\\S]*- then_run`),
|
|
83
80
|
);
|
|
84
81
|
assert.equal(await readFile(join(dir, path), "utf8"), "old\n");
|
|
@@ -89,13 +86,13 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
|
|
|
89
86
|
}
|
|
90
87
|
});
|
|
91
88
|
|
|
92
|
-
test("edit and replace share one embedded executor and preserve mutation results", async () => {
|
|
89
|
+
test("edit and replace share one embedded executor and preserve mutation results", async (t) => {
|
|
93
90
|
const dir = await tempDir();
|
|
94
91
|
try {
|
|
95
92
|
const calls: string[] = [];
|
|
96
93
|
const fusion = createActionFusionExecutor(async (_id, input) => {
|
|
97
94
|
calls.push(input.command);
|
|
98
|
-
return "checked";
|
|
95
|
+
return { status: "succeeded", output: "checked" };
|
|
99
96
|
});
|
|
100
97
|
const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
|
|
101
98
|
const replace = makeReplaceTool(dir, DEFAULT_CONFIG, fusion);
|
|
@@ -110,7 +107,7 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
110
107
|
},
|
|
111
108
|
undefined,
|
|
112
109
|
undefined,
|
|
113
|
-
ctx(dir),
|
|
110
|
+
await ctx(dir, t),
|
|
114
111
|
);
|
|
115
112
|
const replaceResult = await replace.execute(
|
|
116
113
|
"replace-1",
|
|
@@ -121,7 +118,7 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
121
118
|
},
|
|
122
119
|
undefined,
|
|
123
120
|
undefined,
|
|
124
|
-
ctx(dir),
|
|
121
|
+
await ctx(dir, t),
|
|
125
122
|
);
|
|
126
123
|
const editOutput = editResult.content.at(-1);
|
|
127
124
|
assert.ok(editOutput?.type === "text");
|
|
@@ -141,7 +138,7 @@ test("edit and replace share one embedded executor and preserve mutation results
|
|
|
141
138
|
}
|
|
142
139
|
});
|
|
143
140
|
|
|
144
|
-
test("mutation failure skips the command and command failure does not roll back", async () => {
|
|
141
|
+
test("mutation failure skips the command and command failure does not roll back", async (t) => {
|
|
145
142
|
const dir = await tempDir();
|
|
146
143
|
try {
|
|
147
144
|
let calls = 0;
|
|
@@ -159,7 +156,7 @@ test("mutation failure skips the command and command failure does not roll back"
|
|
|
159
156
|
throw new Error("anchor mismatch: current 1#ABCD");
|
|
160
157
|
},
|
|
161
158
|
signal: undefined,
|
|
162
|
-
ctx: ctx(dir),
|
|
159
|
+
ctx: await ctx(dir, t),
|
|
163
160
|
}),
|
|
164
161
|
(error: Error) =>
|
|
165
162
|
error.message.includes(THEN_RUN_SKIPPED) &&
|
|
@@ -178,7 +175,7 @@ test("mutation failure skips the command and command failure does not roll back"
|
|
|
178
175
|
details: { ok: true },
|
|
179
176
|
}),
|
|
180
177
|
signal: undefined,
|
|
181
|
-
ctx: ctx(dir),
|
|
178
|
+
ctx: await ctx(dir, t),
|
|
182
179
|
});
|
|
183
180
|
assert.equal(result.content[0].type === "text" && result.content[0].text, "mutation");
|
|
184
181
|
const diagnostic = result.content[1].type === "text" ? result.content[1].text : "";
|
|
@@ -190,7 +187,7 @@ test("mutation failure skips the command and command failure does not roll back"
|
|
|
190
187
|
}
|
|
191
188
|
});
|
|
192
189
|
|
|
193
|
-
test("cancelled calls do not mutate or run the command", async () => {
|
|
190
|
+
test("cancelled calls do not mutate or run the command", async (t) => {
|
|
194
191
|
const dir = await tempDir();
|
|
195
192
|
try {
|
|
196
193
|
const controller = new AbortController();
|
|
@@ -199,7 +196,7 @@ test("cancelled calls do not mutate or run the command", async () => {
|
|
|
199
196
|
let commanded = false;
|
|
200
197
|
const fusion = createActionFusionExecutor(async () => {
|
|
201
198
|
commanded = true;
|
|
202
|
-
return "";
|
|
199
|
+
return { status: "succeeded", output: "" };
|
|
203
200
|
});
|
|
204
201
|
await assert.rejects(
|
|
205
202
|
fusion({
|
|
@@ -211,7 +208,7 @@ test("cancelled calls do not mutate or run the command", async () => {
|
|
|
211
208
|
throw new Error("Cancelled mutation must not run");
|
|
212
209
|
},
|
|
213
210
|
signal: controller.signal,
|
|
214
|
-
ctx: ctx(dir),
|
|
211
|
+
ctx: await ctx(dir, t),
|
|
215
212
|
}),
|
|
216
213
|
);
|
|
217
214
|
assert.equal(mutated, false);
|
|
@@ -221,47 +218,14 @@ test("cancelled calls do not mutate or run the command", async () => {
|
|
|
221
218
|
}
|
|
222
219
|
});
|
|
223
220
|
|
|
224
|
-
test("
|
|
225
|
-
const dir = await tempDir();
|
|
226
|
-
try {
|
|
227
|
-
const target = join(dir, "real.txt");
|
|
228
|
-
await writeFile(target, "before\n");
|
|
229
|
-
const fusion = createActionFusionExecutor();
|
|
230
|
-
const result = await fusion({
|
|
231
|
-
toolCallId: "real",
|
|
232
|
-
absolutePath: target,
|
|
233
|
-
thenRun: { command: "node -e \"process.stdout.write('real runner')\"" },
|
|
234
|
-
mutate: async () => {
|
|
235
|
-
await writeFile(target, "after\n");
|
|
236
|
-
return publishedMutation("after\n", {
|
|
237
|
-
content: [{ type: "text", text: "mutated" }],
|
|
238
|
-
details: { ok: true },
|
|
239
|
-
});
|
|
240
|
-
},
|
|
241
|
-
signal: undefined,
|
|
242
|
-
ctx: {
|
|
243
|
-
...ctx(dir),
|
|
244
|
-
sessionManager: { getSessionId: () => "test", getSessionFile: () => undefined },
|
|
245
|
-
} as any,
|
|
246
|
-
});
|
|
247
|
-
const output = result.content
|
|
248
|
-
.filter((block) => block.type === "text")
|
|
249
|
-
.map((block) => (block.type === "text" ? block.text : ""))
|
|
250
|
-
.join("\n");
|
|
251
|
-
assert.match(output, /real runner/);
|
|
252
|
-
} finally {
|
|
253
|
-
await rm(dir, { recursive: true, force: true });
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test("marks anchors stale when then_run changes the target", async () => {
|
|
221
|
+
test("marks anchors stale when then_run changes the target", async (t) => {
|
|
258
222
|
const dir = await tempDir();
|
|
259
223
|
try {
|
|
260
224
|
const target = join(dir, "stale.txt");
|
|
261
225
|
await writeFile(target, "before\n");
|
|
262
226
|
const fusion = createActionFusionExecutor(async () => {
|
|
263
227
|
await writeFile(target, "changed by command\n");
|
|
264
|
-
return "changed";
|
|
228
|
+
return { status: "succeeded", output: "changed" };
|
|
265
229
|
});
|
|
266
230
|
const result = await fusion({
|
|
267
231
|
toolCallId: "stale",
|
|
@@ -279,7 +243,7 @@ test("marks anchors stale when then_run changes the target", async () => {
|
|
|
279
243
|
);
|
|
280
244
|
},
|
|
281
245
|
signal: undefined,
|
|
282
|
-
ctx: ctx(dir),
|
|
246
|
+
ctx: await ctx(dir, t),
|
|
283
247
|
});
|
|
284
248
|
const output = result.content
|
|
285
249
|
.filter((block) => block.type === "text")
|
|
@@ -293,14 +257,14 @@ test("marks anchors stale when then_run changes the target", async () => {
|
|
|
293
257
|
}
|
|
294
258
|
});
|
|
295
259
|
|
|
296
|
-
test("Action Fusion omits structured anchors when target freshness is unknown", async () => {
|
|
260
|
+
test("Action Fusion omits structured anchors when target freshness is unknown", async (t) => {
|
|
297
261
|
const dir = await tempDir();
|
|
298
262
|
try {
|
|
299
263
|
const missing = join(dir, "unreadable.txt");
|
|
300
264
|
let commands = 0;
|
|
301
265
|
const fusion = createActionFusionExecutor(async () => {
|
|
302
266
|
commands++;
|
|
303
|
-
return "unexpected";
|
|
267
|
+
return { status: "succeeded", output: "unexpected" };
|
|
304
268
|
});
|
|
305
269
|
const result = await fusion({
|
|
306
270
|
toolCallId: "unknown",
|
|
@@ -320,7 +284,7 @@ test("Action Fusion omits structured anchors when target freshness is unknown",
|
|
|
320
284
|
);
|
|
321
285
|
},
|
|
322
286
|
signal: undefined,
|
|
323
|
-
ctx: ctx(dir),
|
|
287
|
+
ctx: await ctx(dir, t),
|
|
324
288
|
});
|
|
325
289
|
const output = result.content
|
|
326
290
|
.map((block) => (block.type === "text" ? block.text : ""))
|
|
@@ -334,14 +298,14 @@ test("Action Fusion omits structured anchors when target freshness is unknown",
|
|
|
334
298
|
}
|
|
335
299
|
});
|
|
336
300
|
|
|
337
|
-
test("edit omits Updated anchors when then_run changes the target", async () => {
|
|
301
|
+
test("edit omits Updated anchors when then_run changes the target", async (t) => {
|
|
338
302
|
const dir = await tempDir();
|
|
339
303
|
try {
|
|
340
304
|
const target = join(dir, "edit-stale.txt");
|
|
341
305
|
await writeFile(target, "before\n");
|
|
342
306
|
const fusion = createActionFusionExecutor(async () => {
|
|
343
307
|
await writeFile(target, "command changed\n");
|
|
344
|
-
return "changed";
|
|
308
|
+
return { status: "succeeded", output: "changed" };
|
|
345
309
|
});
|
|
346
310
|
const result = await makeEditOverride(dir, DEFAULT_CONFIG, fusion).execute(
|
|
347
311
|
"edit-stale",
|
|
@@ -352,7 +316,7 @@ test("edit omits Updated anchors when then_run changes the target", async () =>
|
|
|
352
316
|
},
|
|
353
317
|
undefined,
|
|
354
318
|
undefined,
|
|
355
|
-
ctx(dir),
|
|
319
|
+
await ctx(dir, t),
|
|
356
320
|
);
|
|
357
321
|
const output = result.content.map((block: any) => block.text ?? "").join("\n");
|
|
358
322
|
assert.ok(result.details.actionFusion);
|
|
@@ -365,7 +329,7 @@ test("edit omits Updated anchors when then_run changes the target", async () =>
|
|
|
365
329
|
}
|
|
366
330
|
});
|
|
367
331
|
|
|
368
|
-
test("all mutation tools forward command progress before completion in RPC mode", async () => {
|
|
332
|
+
test("all mutation tools forward command progress before completion in RPC mode", async (t) => {
|
|
369
333
|
const dir = await tempDir();
|
|
370
334
|
try {
|
|
371
335
|
const events: ActionFusionProgress[] = [];
|
|
@@ -376,10 +340,11 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
376
340
|
onUpdate?.({ content: [{ type: "text", text: "live output" }], details: undefined });
|
|
377
341
|
assert.match(updates.at(-1).content.at(-1).text, /live output/);
|
|
378
342
|
assert.equal(events.at(-1)?.output, "live output");
|
|
379
|
-
return "final output";
|
|
343
|
+
return { status: "succeeded", output: "final output" };
|
|
380
344
|
},
|
|
381
345
|
(event) => events.push(event),
|
|
382
346
|
);
|
|
347
|
+
const rpcContext = await ctx(dir, t, "rpc");
|
|
383
348
|
const cases = [
|
|
384
349
|
() =>
|
|
385
350
|
makeEditOverride(dir, DEFAULT_CONFIG, fusion).execute(
|
|
@@ -391,7 +356,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
391
356
|
},
|
|
392
357
|
undefined,
|
|
393
358
|
(update) => updates.push(update),
|
|
394
|
-
|
|
359
|
+
rpcContext,
|
|
395
360
|
),
|
|
396
361
|
() =>
|
|
397
362
|
makeReplaceTool(dir, DEFAULT_CONFIG, fusion).execute(
|
|
@@ -403,15 +368,20 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
403
368
|
},
|
|
404
369
|
undefined,
|
|
405
370
|
(update) => updates.push(update),
|
|
406
|
-
|
|
371
|
+
rpcContext,
|
|
407
372
|
),
|
|
408
373
|
() =>
|
|
409
374
|
makeWriteOverride(dir, fusion).execute(
|
|
410
375
|
"write",
|
|
411
|
-
{
|
|
376
|
+
{
|
|
377
|
+
path: "progress.txt",
|
|
378
|
+
content: "after\n",
|
|
379
|
+
mode: "overwrite",
|
|
380
|
+
then_run: { command: "check" },
|
|
381
|
+
},
|
|
412
382
|
undefined,
|
|
413
383
|
(update) => updates.push(update),
|
|
414
|
-
|
|
384
|
+
rpcContext,
|
|
415
385
|
),
|
|
416
386
|
];
|
|
417
387
|
for (const run of cases) {
|
|
@@ -436,7 +406,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
|
|
|
436
406
|
}
|
|
437
407
|
});
|
|
438
408
|
|
|
439
|
-
test("progress reports skipped mutations and failed commands without rolling back", async () => {
|
|
409
|
+
test("progress reports skipped mutations and failed commands without rolling back", async (t) => {
|
|
440
410
|
const dir = await tempDir();
|
|
441
411
|
try {
|
|
442
412
|
const events: ActionFusionProgress[] = [];
|
|
@@ -458,7 +428,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
458
428
|
},
|
|
459
429
|
undefined,
|
|
460
430
|
undefined,
|
|
461
|
-
ctx(dir),
|
|
431
|
+
await ctx(dir, t),
|
|
462
432
|
),
|
|
463
433
|
);
|
|
464
434
|
assert.equal(commands, 0);
|
|
@@ -480,7 +450,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
480
450
|
},
|
|
481
451
|
undefined,
|
|
482
452
|
undefined,
|
|
483
|
-
ctx(dir),
|
|
453
|
+
await ctx(dir, t),
|
|
484
454
|
),
|
|
485
455
|
/no matches/,
|
|
486
456
|
);
|
|
@@ -493,10 +463,15 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
493
463
|
events.length = 0;
|
|
494
464
|
const failed = await makeWriteOverride(dir, fusion).execute(
|
|
495
465
|
"fail",
|
|
496
|
-
{
|
|
466
|
+
{
|
|
467
|
+
path: "failed.txt",
|
|
468
|
+
content: "published\n",
|
|
469
|
+
mode: "create",
|
|
470
|
+
then_run: { command: "check" },
|
|
471
|
+
},
|
|
497
472
|
undefined,
|
|
498
473
|
undefined,
|
|
499
|
-
ctx(dir),
|
|
474
|
+
await ctx(dir, t),
|
|
500
475
|
);
|
|
501
476
|
assert.ok(failed.details.actionFusion);
|
|
502
477
|
assert.equal(failed.details.actionFusion.command, "failed");
|
|
@@ -513,7 +488,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
|
|
|
513
488
|
|
|
514
489
|
test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
515
490
|
skip: process.platform !== "win32",
|
|
516
|
-
}, async () => {
|
|
491
|
+
}, async (t) => {
|
|
517
492
|
const dir = await tempDir();
|
|
518
493
|
try {
|
|
519
494
|
const fusion = createActionFusionExecutor();
|
|
@@ -533,7 +508,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
|
533
508
|
return publishedMutation("first\n", { content: [], details: undefined });
|
|
534
509
|
},
|
|
535
510
|
signal: undefined,
|
|
536
|
-
ctx: ctx(dir),
|
|
511
|
+
ctx: await ctx(dir, t),
|
|
537
512
|
});
|
|
538
513
|
await new Promise((r) => setTimeout(r, 20));
|
|
539
514
|
const p2 = fusion({
|
|
@@ -546,7 +521,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
|
546
521
|
return publishedMutation("second\n", { content: [], details: undefined });
|
|
547
522
|
},
|
|
548
523
|
signal: undefined,
|
|
549
|
-
ctx: ctx(dir),
|
|
524
|
+
ctx: await ctx(dir, t),
|
|
550
525
|
});
|
|
551
526
|
await new Promise((r) => setTimeout(r, 20));
|
|
552
527
|
assert.deepEqual(order, ["start-1"]);
|
|
@@ -558,7 +533,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
|
|
|
558
533
|
}
|
|
559
534
|
});
|
|
560
535
|
|
|
561
|
-
test("ActionFusionError re-wrapping appends recovery guidance without duplicating outcome banners", async () => {
|
|
536
|
+
test("ActionFusionError re-wrapping appends recovery guidance without duplicating outcome banners", async (t) => {
|
|
562
537
|
const dir = await tempDir();
|
|
563
538
|
try {
|
|
564
539
|
const fusion = createActionFusionExecutor();
|
|
@@ -573,7 +548,7 @@ test("ActionFusionError re-wrapping appends recovery guidance without duplicatin
|
|
|
573
548
|
throw mutationError;
|
|
574
549
|
},
|
|
575
550
|
signal: undefined,
|
|
576
|
-
ctx: ctx(dir),
|
|
551
|
+
ctx: await ctx(dir, t),
|
|
577
552
|
});
|
|
578
553
|
} catch (error) {
|
|
579
554
|
caught = error;
|
|
@@ -601,7 +576,7 @@ test("ActionFusionError re-wrapping appends recovery guidance without duplicatin
|
|
|
601
576
|
}
|
|
602
577
|
});
|
|
603
578
|
|
|
604
|
-
test("Fusion uses commit facts when details omit or contradict publication and revision", async () => {
|
|
579
|
+
test("Fusion uses commit facts when details omit or contradict publication and revision", async (t) => {
|
|
605
580
|
const dir = await tempDir();
|
|
606
581
|
try {
|
|
607
582
|
const target = join(dir, "unchanged.txt");
|
|
@@ -620,14 +595,14 @@ test("Fusion uses commit facts when details omit or contradict publication and r
|
|
|
620
595
|
let commands = 0;
|
|
621
596
|
const fusion = createActionFusionExecutor(async () => {
|
|
622
597
|
commands++;
|
|
623
|
-
return "checked";
|
|
598
|
+
return { status: "succeeded", output: "checked" };
|
|
624
599
|
});
|
|
625
600
|
const result = await fusion({
|
|
626
601
|
toolCallId: "commit-facts",
|
|
627
602
|
absolutePath: target,
|
|
628
603
|
thenRun,
|
|
629
604
|
signal: undefined,
|
|
630
|
-
ctx: ctx(dir),
|
|
605
|
+
ctx: await ctx(dir, t),
|
|
631
606
|
mutate: async () => ({
|
|
632
607
|
result: { content: [{ type: "text", text: "mutation" }], details },
|
|
633
608
|
commit,
|
|
@@ -651,3 +626,107 @@ test("Fusion uses commit facts when details omit or contradict publication and r
|
|
|
651
626
|
await rm(dir, { recursive: true, force: true });
|
|
652
627
|
}
|
|
653
628
|
});
|
|
629
|
+
|
|
630
|
+
test("timed command progress ticks during silence, preserves output, and stops at every outcome", async (t) => {
|
|
631
|
+
for (const outcome of ["succeeded", "failed", "timeout", "cancelled"] as const) {
|
|
632
|
+
await t.test(outcome, async (t) => {
|
|
633
|
+
const dir = await tempDir();
|
|
634
|
+
t.mock.timers.enable({ apis: ["Date", "setInterval"], now: 0 });
|
|
635
|
+
const started = Promise.withResolvers<void>();
|
|
636
|
+
const finished = Promise.withResolvers<CommandOutcome>();
|
|
637
|
+
const controller = new AbortController();
|
|
638
|
+
const events: ActionFusionProgress[] = [];
|
|
639
|
+
const updates: unknown[] = [];
|
|
640
|
+
try {
|
|
641
|
+
const fusion = createActionFusionExecutor(
|
|
642
|
+
async (_id, input, _signal, _ctx, onUpdate) => {
|
|
643
|
+
assert.equal(input.timeout, 10);
|
|
644
|
+
started.resolve();
|
|
645
|
+
onUpdate?.({ content: [{ type: "text", text: "latest output" }], details: undefined });
|
|
646
|
+
return finished.promise;
|
|
647
|
+
},
|
|
648
|
+
(event) => events.push(event),
|
|
649
|
+
);
|
|
650
|
+
const execution = fusion({
|
|
651
|
+
toolCallId: outcome,
|
|
652
|
+
absolutePath: join(dir, "target.txt"),
|
|
653
|
+
thenRun: { command: "check", timeout: 10 },
|
|
654
|
+
mutate: async () => {
|
|
655
|
+
// Mutation time must not consume the command's timeout.
|
|
656
|
+
t.mock.timers.tick(5_000);
|
|
657
|
+
await writeFile(join(dir, "target.txt"), "saved\n");
|
|
658
|
+
return publishedMutation("saved\n", { content: [], details: undefined });
|
|
659
|
+
},
|
|
660
|
+
signal: controller.signal,
|
|
661
|
+
ctx: await ctx(dir, t),
|
|
662
|
+
onUpdate: (update) => updates.push(update),
|
|
663
|
+
});
|
|
664
|
+
await started.promise;
|
|
665
|
+
assert.equal(events[0].timing, undefined);
|
|
666
|
+
assert.deepEqual(events.at(-1)?.timing, { timeoutSeconds: 10, remainingSeconds: 10 });
|
|
667
|
+
const updateCount = updates.length;
|
|
668
|
+
t.mock.timers.tick(2_000);
|
|
669
|
+
assert.equal(updates.length, updateCount + 2);
|
|
670
|
+
assert.equal(events.at(-1)?.timing?.remainingSeconds, 8);
|
|
671
|
+
assert.equal(events.at(-1)?.output, "latest output");
|
|
672
|
+
if (outcome === "cancelled") controller.abort();
|
|
673
|
+
finished.resolve({
|
|
674
|
+
status: outcome,
|
|
675
|
+
output:
|
|
676
|
+
outcome === "succeeded"
|
|
677
|
+
? "complete"
|
|
678
|
+
: outcome === "timeout"
|
|
679
|
+
? "Command timed out"
|
|
680
|
+
: "command stopped\nunderlying cause",
|
|
681
|
+
});
|
|
682
|
+
await execution;
|
|
683
|
+
assert.equal(events.at(-1)?.command, outcome);
|
|
684
|
+
const terminalCount = updates.length;
|
|
685
|
+
t.mock.timers.tick(20_000);
|
|
686
|
+
assert.equal(updates.length, terminalCount);
|
|
687
|
+
} finally {
|
|
688
|
+
finished.resolve({ status: "succeeded", output: "" });
|
|
689
|
+
await rm(dir, { recursive: true, force: true });
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
test("commands without an explicit timeout do not start countdown updates", async (t) => {
|
|
696
|
+
const dir = await tempDir();
|
|
697
|
+
t.mock.timers.enable({ apis: ["Date", "setInterval"], now: 0 });
|
|
698
|
+
const started = Promise.withResolvers<void>();
|
|
699
|
+
const finished = Promise.withResolvers<CommandOutcome>();
|
|
700
|
+
const events: ActionFusionProgress[] = [];
|
|
701
|
+
try {
|
|
702
|
+
const fusion = createActionFusionExecutor(
|
|
703
|
+
async (_id, input) => {
|
|
704
|
+
assert.equal(input.timeout, undefined);
|
|
705
|
+
started.resolve();
|
|
706
|
+
return finished.promise;
|
|
707
|
+
},
|
|
708
|
+
(event) => events.push(event),
|
|
709
|
+
);
|
|
710
|
+
const execution = fusion({
|
|
711
|
+
toolCallId: "untimed",
|
|
712
|
+
absolutePath: join(dir, "target.txt"),
|
|
713
|
+
thenRun: { command: "check" },
|
|
714
|
+
mutate: async () => {
|
|
715
|
+
await writeFile(join(dir, "target.txt"), "saved\n");
|
|
716
|
+
return publishedMutation("saved\n", { content: [], details: undefined });
|
|
717
|
+
},
|
|
718
|
+
signal: undefined,
|
|
719
|
+
ctx: await ctx(dir, t),
|
|
720
|
+
});
|
|
721
|
+
await started.promise;
|
|
722
|
+
const count = events.length;
|
|
723
|
+
t.mock.timers.tick(20_000);
|
|
724
|
+
assert.equal(events.length, count);
|
|
725
|
+
assert.equal(events.at(-1)?.timing, undefined);
|
|
726
|
+
finished.resolve({ status: "succeeded", output: "complete" });
|
|
727
|
+
await execution;
|
|
728
|
+
} finally {
|
|
729
|
+
finished.resolve({ status: "succeeded", output: "" });
|
|
730
|
+
await rm(dir, { recursive: true, force: true });
|
|
731
|
+
}
|
|
732
|
+
});
|