@criogaid/pi-hashline-edit 0.5.1 → 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.
Files changed (51) hide show
  1. package/README.md +51 -15
  2. package/package.json +6 -6
  3. package/src/core/apply.test.ts +66 -16
  4. package/src/core/apply.ts +36 -19
  5. package/src/core/lines.ts +3 -3
  6. package/src/index.ts +2 -0
  7. package/src/integration/forget-grep.test.ts +98 -0
  8. package/src/integration/fusion-dispatch.test.ts +343 -0
  9. package/src/integration/grep-rg.test.ts +269 -33
  10. package/src/integration/mutation-file-types.test.ts +44 -0
  11. package/src/pi/action-fusion.test.ts +71 -128
  12. package/src/pi/action-fusion.ts +83 -45
  13. package/src/pi/argument-validation.test.ts +136 -0
  14. package/src/pi/argument-validation.ts +103 -0
  15. package/src/pi/budgets.ts +4 -1
  16. package/src/pi/config.test.ts +1 -0
  17. package/src/pi/config.ts +4 -0
  18. package/src/pi/directory-sync.test.ts +1 -1
  19. package/src/pi/edit-tool.ts +55 -36
  20. package/src/pi/execute.test.ts +185 -645
  21. package/src/pi/failure-context.test.ts +4 -3
  22. package/src/pi/failure-path.test.ts +3 -3
  23. package/src/pi/file-commit.test.ts +24 -17
  24. package/src/pi/file-commit.ts +36 -9
  25. package/src/pi/file-snapshot.test.ts +24 -0
  26. package/src/pi/forget-tool.ts +268 -0
  27. package/src/pi/forget.test.ts +343 -0
  28. package/src/pi/forget.testing.ts +273 -0
  29. package/src/pi/grep-output.ts +57 -28
  30. package/src/pi/grep-search.ts +35 -12
  31. package/src/pi/grep-tool.ts +28 -9
  32. package/src/pi/grep.test.ts +173 -152
  33. package/src/pi/mutation-result.test.ts +23 -0
  34. package/src/pi/mutation-runner.ts +8 -4
  35. package/src/pi/path.ts +16 -2
  36. package/src/pi/pi.test.ts +3 -2
  37. package/src/pi/read-tool.ts +58 -26
  38. package/src/pi/read.test.ts +361 -0
  39. package/src/pi/registration.test.ts +115 -2
  40. package/src/pi/render.test.ts +45 -14
  41. package/src/pi/replace-tool.ts +18 -27
  42. package/src/pi/replace.test.ts +8 -107
  43. package/src/pi/result-safety.test.ts +123 -149
  44. package/src/pi/rg-match-bytes.ts +95 -0
  45. package/src/pi/rg-process.test.ts +40 -59
  46. package/src/pi/rg-text-view.ts +52 -5
  47. package/src/pi/tool-call.testing.ts +50 -0
  48. package/src/pi/tool-prompts.ts +15 -0
  49. package/src/pi/write-tool.ts +17 -26
  50. package/src/pi/write.test.ts +70 -61
  51. package/src/pi/e2e-scenarios.test.ts +0 -361
@@ -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 type { ExtensionContext } from "@earendil-works/pi-coding-agent";
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,13 +27,6 @@ async function tempDir(): Promise<string> {
28
27
  return mkdtemp(join(tmpdir(), "hashline-action-fusion-"));
29
28
  }
30
29
 
31
- // Only the context fields consumed by Fusion and Pi Bash are needed by these tests.
32
- const ctx = (cwd: string) =>
33
- ({
34
- cwd,
35
- sessionManager: { getSessionId: () => "test", getSessionFile: () => undefined },
36
- }) as ExtensionContext;
37
-
38
30
  type Fusion = Parameters<typeof makeWriteOverride>[1];
39
31
  const mutationFactories = [
40
32
  (cwd: string, fusion?: Fusion) => makeEditOverride(cwd, DEFAULT_CONFIG, fusion),
@@ -63,7 +55,7 @@ test("mutation tools expose Fusion schemas and guidance when supplied an executo
63
55
  }
64
56
  });
65
57
 
66
- 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) => {
67
59
  const dir = await tempDir();
68
60
  try {
69
61
  for (const makeTool of mutationFactories) {
@@ -75,7 +67,7 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
75
67
  ? { edits: [{ op: "append", body: ["new"] }] }
76
68
  : tool.name === "replace"
77
69
  ? { replacements: [{ find: "old", replace: "new" }] }
78
- : { content: "new\n" };
70
+ : { content: "new\n", mode: "overwrite" };
79
71
  for (const then_run of [
80
72
  {},
81
73
  { command: " " },
@@ -83,7 +75,7 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
83
75
  { command: "echo ok", timeout: 2_147_483.648 },
84
76
  ]) {
85
77
  await assert.rejects(
86
- callTool(tool, { path, ...mutation, then_run }, { ctx: ctx(dir) }),
78
+ callTool(tool, { path, ...mutation, then_run }, { ctx: await ctx(dir, t) }),
87
79
  new RegExp(`Validation failed for tool "${tool.name}":[\\s\\S]*- then_run`),
88
80
  );
89
81
  assert.equal(await readFile(join(dir, path), "utf8"), "old\n");
@@ -94,13 +86,13 @@ test("then_run schemas reject invalid commands, unknown keys, and excessive time
94
86
  }
95
87
  });
96
88
 
97
- 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) => {
98
90
  const dir = await tempDir();
99
91
  try {
100
92
  const calls: string[] = [];
101
93
  const fusion = createActionFusionExecutor(async (_id, input) => {
102
94
  calls.push(input.command);
103
- return "checked";
95
+ return { status: "succeeded", output: "checked" };
104
96
  });
105
97
  const edit = makeEditOverride(dir, DEFAULT_CONFIG, fusion);
106
98
  const replace = makeReplaceTool(dir, DEFAULT_CONFIG, fusion);
@@ -115,7 +107,7 @@ test("edit and replace share one embedded executor and preserve mutation results
115
107
  },
116
108
  undefined,
117
109
  undefined,
118
- ctx(dir),
110
+ await ctx(dir, t),
119
111
  );
120
112
  const replaceResult = await replace.execute(
121
113
  "replace-1",
@@ -126,7 +118,7 @@ test("edit and replace share one embedded executor and preserve mutation results
126
118
  },
127
119
  undefined,
128
120
  undefined,
129
- ctx(dir),
121
+ await ctx(dir, t),
130
122
  );
131
123
  const editOutput = editResult.content.at(-1);
132
124
  assert.ok(editOutput?.type === "text");
@@ -146,7 +138,7 @@ test("edit and replace share one embedded executor and preserve mutation results
146
138
  }
147
139
  });
148
140
 
149
- 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) => {
150
142
  const dir = await tempDir();
151
143
  try {
152
144
  let calls = 0;
@@ -164,7 +156,7 @@ test("mutation failure skips the command and command failure does not roll back"
164
156
  throw new Error("anchor mismatch: current 1#ABCD");
165
157
  },
166
158
  signal: undefined,
167
- ctx: ctx(dir),
159
+ ctx: await ctx(dir, t),
168
160
  }),
169
161
  (error: Error) =>
170
162
  error.message.includes(THEN_RUN_SKIPPED) &&
@@ -183,7 +175,7 @@ test("mutation failure skips the command and command failure does not roll back"
183
175
  details: { ok: true },
184
176
  }),
185
177
  signal: undefined,
186
- ctx: ctx(dir),
178
+ ctx: await ctx(dir, t),
187
179
  });
188
180
  assert.equal(result.content[0].type === "text" && result.content[0].text, "mutation");
189
181
  const diagnostic = result.content[1].type === "text" ? result.content[1].text : "";
@@ -195,7 +187,7 @@ test("mutation failure skips the command and command failure does not roll back"
195
187
  }
196
188
  });
197
189
 
198
- test("cancelled calls do not mutate or run the command", async () => {
190
+ test("cancelled calls do not mutate or run the command", async (t) => {
199
191
  const dir = await tempDir();
200
192
  try {
201
193
  const controller = new AbortController();
@@ -204,7 +196,7 @@ test("cancelled calls do not mutate or run the command", async () => {
204
196
  let commanded = false;
205
197
  const fusion = createActionFusionExecutor(async () => {
206
198
  commanded = true;
207
- return "";
199
+ return { status: "succeeded", output: "" };
208
200
  });
209
201
  await assert.rejects(
210
202
  fusion({
@@ -216,7 +208,7 @@ test("cancelled calls do not mutate or run the command", async () => {
216
208
  throw new Error("Cancelled mutation must not run");
217
209
  },
218
210
  signal: controller.signal,
219
- ctx: ctx(dir),
211
+ ctx: await ctx(dir, t),
220
212
  }),
221
213
  );
222
214
  assert.equal(mutated, false);
@@ -226,44 +218,14 @@ test("cancelled calls do not mutate or run the command", async () => {
226
218
  }
227
219
  });
228
220
 
229
- test("default runner executes a real local command", async () => {
230
- const dir = await tempDir();
231
- try {
232
- const target = join(dir, "real.txt");
233
- await writeFile(target, "before\n");
234
- const fusion = createActionFusionExecutor();
235
- const result = await fusion({
236
- toolCallId: "real",
237
- absolutePath: target,
238
- thenRun: { command: "node -e \"process.stdout.write('real runner')\"" },
239
- mutate: async () => {
240
- await writeFile(target, "after\n");
241
- return publishedMutation("after\n", {
242
- content: [{ type: "text", text: "mutated" }],
243
- details: { ok: true },
244
- });
245
- },
246
- signal: undefined,
247
- ctx: ctx(dir),
248
- });
249
- const output = result.content
250
- .filter((block) => block.type === "text")
251
- .map((block) => (block.type === "text" ? block.text : ""))
252
- .join("\n");
253
- assert.match(output, /real runner/);
254
- } finally {
255
- await rm(dir, { recursive: true, force: true });
256
- }
257
- });
258
-
259
- test("marks anchors stale when then_run changes the target", async () => {
221
+ test("marks anchors stale when then_run changes the target", async (t) => {
260
222
  const dir = await tempDir();
261
223
  try {
262
224
  const target = join(dir, "stale.txt");
263
225
  await writeFile(target, "before\n");
264
226
  const fusion = createActionFusionExecutor(async () => {
265
227
  await writeFile(target, "changed by command\n");
266
- return "changed";
228
+ return { status: "succeeded", output: "changed" };
267
229
  });
268
230
  const result = await fusion({
269
231
  toolCallId: "stale",
@@ -281,7 +243,7 @@ test("marks anchors stale when then_run changes the target", async () => {
281
243
  );
282
244
  },
283
245
  signal: undefined,
284
- ctx: ctx(dir),
246
+ ctx: await ctx(dir, t),
285
247
  });
286
248
  const output = result.content
287
249
  .filter((block) => block.type === "text")
@@ -295,14 +257,14 @@ test("marks anchors stale when then_run changes the target", async () => {
295
257
  }
296
258
  });
297
259
 
298
- 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) => {
299
261
  const dir = await tempDir();
300
262
  try {
301
263
  const missing = join(dir, "unreadable.txt");
302
264
  let commands = 0;
303
265
  const fusion = createActionFusionExecutor(async () => {
304
266
  commands++;
305
- return "unexpected";
267
+ return { status: "succeeded", output: "unexpected" };
306
268
  });
307
269
  const result = await fusion({
308
270
  toolCallId: "unknown",
@@ -322,7 +284,7 @@ test("Action Fusion omits structured anchors when target freshness is unknown",
322
284
  );
323
285
  },
324
286
  signal: undefined,
325
- ctx: ctx(dir),
287
+ ctx: await ctx(dir, t),
326
288
  });
327
289
  const output = result.content
328
290
  .map((block) => (block.type === "text" ? block.text : ""))
@@ -336,14 +298,14 @@ test("Action Fusion omits structured anchors when target freshness is unknown",
336
298
  }
337
299
  });
338
300
 
339
- 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) => {
340
302
  const dir = await tempDir();
341
303
  try {
342
304
  const target = join(dir, "edit-stale.txt");
343
305
  await writeFile(target, "before\n");
344
306
  const fusion = createActionFusionExecutor(async () => {
345
307
  await writeFile(target, "command changed\n");
346
- return "changed";
308
+ return { status: "succeeded", output: "changed" };
347
309
  });
348
310
  const result = await makeEditOverride(dir, DEFAULT_CONFIG, fusion).execute(
349
311
  "edit-stale",
@@ -354,7 +316,7 @@ test("edit omits Updated anchors when then_run changes the target", async () =>
354
316
  },
355
317
  undefined,
356
318
  undefined,
357
- ctx(dir),
319
+ await ctx(dir, t),
358
320
  );
359
321
  const output = result.content.map((block: any) => block.text ?? "").join("\n");
360
322
  assert.ok(result.details.actionFusion);
@@ -367,7 +329,7 @@ test("edit omits Updated anchors when then_run changes the target", async () =>
367
329
  }
368
330
  });
369
331
 
370
- 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) => {
371
333
  const dir = await tempDir();
372
334
  try {
373
335
  const events: ActionFusionProgress[] = [];
@@ -378,10 +340,11 @@ test("all mutation tools forward command progress before completion in RPC mode"
378
340
  onUpdate?.({ content: [{ type: "text", text: "live output" }], details: undefined });
379
341
  assert.match(updates.at(-1).content.at(-1).text, /live output/);
380
342
  assert.equal(events.at(-1)?.output, "live output");
381
- return "final output";
343
+ return { status: "succeeded", output: "final output" };
382
344
  },
383
345
  (event) => events.push(event),
384
346
  );
347
+ const rpcContext = await ctx(dir, t, "rpc");
385
348
  const cases = [
386
349
  () =>
387
350
  makeEditOverride(dir, DEFAULT_CONFIG, fusion).execute(
@@ -393,7 +356,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
393
356
  },
394
357
  undefined,
395
358
  (update) => updates.push(update),
396
- { ...ctx(dir), mode: "rpc" },
359
+ rpcContext,
397
360
  ),
398
361
  () =>
399
362
  makeReplaceTool(dir, DEFAULT_CONFIG, fusion).execute(
@@ -405,15 +368,20 @@ test("all mutation tools forward command progress before completion in RPC mode"
405
368
  },
406
369
  undefined,
407
370
  (update) => updates.push(update),
408
- { ...ctx(dir), mode: "rpc" },
371
+ rpcContext,
409
372
  ),
410
373
  () =>
411
374
  makeWriteOverride(dir, fusion).execute(
412
375
  "write",
413
- { path: "progress.txt", content: "after\n", then_run: { command: "check" } },
376
+ {
377
+ path: "progress.txt",
378
+ content: "after\n",
379
+ mode: "overwrite",
380
+ then_run: { command: "check" },
381
+ },
414
382
  undefined,
415
383
  (update) => updates.push(update),
416
- { ...ctx(dir), mode: "rpc" },
384
+ rpcContext,
417
385
  ),
418
386
  ];
419
387
  for (const run of cases) {
@@ -438,7 +406,7 @@ test("all mutation tools forward command progress before completion in RPC mode"
438
406
  }
439
407
  });
440
408
 
441
- 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) => {
442
410
  const dir = await tempDir();
443
411
  try {
444
412
  const events: ActionFusionProgress[] = [];
@@ -460,7 +428,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
460
428
  },
461
429
  undefined,
462
430
  undefined,
463
- ctx(dir),
431
+ await ctx(dir, t),
464
432
  ),
465
433
  );
466
434
  assert.equal(commands, 0);
@@ -482,7 +450,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
482
450
  },
483
451
  undefined,
484
452
  undefined,
485
- ctx(dir),
453
+ await ctx(dir, t),
486
454
  ),
487
455
  /no matches/,
488
456
  );
@@ -495,10 +463,15 @@ test("progress reports skipped mutations and failed commands without rolling bac
495
463
  events.length = 0;
496
464
  const failed = await makeWriteOverride(dir, fusion).execute(
497
465
  "fail",
498
- { path: "failed.txt", content: "published\n", then_run: { command: "check" } },
466
+ {
467
+ path: "failed.txt",
468
+ content: "published\n",
469
+ mode: "create",
470
+ then_run: { command: "check" },
471
+ },
499
472
  undefined,
500
473
  undefined,
501
- ctx(dir),
474
+ await ctx(dir, t),
502
475
  );
503
476
  assert.ok(failed.details.actionFusion);
504
477
  assert.equal(failed.details.actionFusion.command, "failed");
@@ -515,7 +488,7 @@ test("progress reports skipped mutations and failed commands without rolling bac
515
488
 
516
489
  test("concurrent mutations on case-differing paths serialize on Windows", {
517
490
  skip: process.platform !== "win32",
518
- }, async () => {
491
+ }, async (t) => {
519
492
  const dir = await tempDir();
520
493
  try {
521
494
  const fusion = createActionFusionExecutor();
@@ -535,7 +508,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
535
508
  return publishedMutation("first\n", { content: [], details: undefined });
536
509
  },
537
510
  signal: undefined,
538
- ctx: ctx(dir),
511
+ ctx: await ctx(dir, t),
539
512
  });
540
513
  await new Promise((r) => setTimeout(r, 20));
541
514
  const p2 = fusion({
@@ -548,7 +521,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
548
521
  return publishedMutation("second\n", { content: [], details: undefined });
549
522
  },
550
523
  signal: undefined,
551
- ctx: ctx(dir),
524
+ ctx: await ctx(dir, t),
552
525
  });
553
526
  await new Promise((r) => setTimeout(r, 20));
554
527
  assert.deepEqual(order, ["start-1"]);
@@ -560,7 +533,7 @@ test("concurrent mutations on case-differing paths serialize on Windows", {
560
533
  }
561
534
  });
562
535
 
563
- 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) => {
564
537
  const dir = await tempDir();
565
538
  try {
566
539
  const fusion = createActionFusionExecutor();
@@ -575,7 +548,7 @@ test("ActionFusionError re-wrapping appends recovery guidance without duplicatin
575
548
  throw mutationError;
576
549
  },
577
550
  signal: undefined,
578
- ctx: ctx(dir),
551
+ ctx: await ctx(dir, t),
579
552
  });
580
553
  } catch (error) {
581
554
  caught = error;
@@ -603,7 +576,7 @@ test("ActionFusionError re-wrapping appends recovery guidance without duplicatin
603
576
  }
604
577
  });
605
578
 
606
- 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) => {
607
580
  const dir = await tempDir();
608
581
  try {
609
582
  const target = join(dir, "unchanged.txt");
@@ -622,14 +595,14 @@ test("Fusion uses commit facts when details omit or contradict publication and r
622
595
  let commands = 0;
623
596
  const fusion = createActionFusionExecutor(async () => {
624
597
  commands++;
625
- return "checked";
598
+ return { status: "succeeded", output: "checked" };
626
599
  });
627
600
  const result = await fusion({
628
601
  toolCallId: "commit-facts",
629
602
  absolutePath: target,
630
603
  thenRun,
631
604
  signal: undefined,
632
- ctx: ctx(dir),
605
+ ctx: await ctx(dir, t),
633
606
  mutate: async () => ({
634
607
  result: { content: [{ type: "text", text: "mutation" }], details },
635
608
  commit,
@@ -660,7 +633,7 @@ test("timed command progress ticks during silence, preserves output, and stops a
660
633
  const dir = await tempDir();
661
634
  t.mock.timers.enable({ apis: ["Date", "setInterval"], now: 0 });
662
635
  const started = Promise.withResolvers<void>();
663
- const finished = Promise.withResolvers<string>();
636
+ const finished = Promise.withResolvers<CommandOutcome>();
664
637
  const controller = new AbortController();
665
638
  const events: ActionFusionProgress[] = [];
666
639
  const updates: unknown[] = [];
@@ -685,7 +658,7 @@ test("timed command progress ticks during silence, preserves output, and stops a
685
658
  return publishedMutation("saved\n", { content: [], details: undefined });
686
659
  },
687
660
  signal: controller.signal,
688
- ctx: ctx(dir),
661
+ ctx: await ctx(dir, t),
689
662
  onUpdate: (update) => updates.push(update),
690
663
  });
691
664
  await started.promise;
@@ -696,22 +669,23 @@ test("timed command progress ticks during silence, preserves output, and stops a
696
669
  assert.equal(updates.length, updateCount + 2);
697
670
  assert.equal(events.at(-1)?.timing?.remainingSeconds, 8);
698
671
  assert.equal(events.at(-1)?.output, "latest output");
699
- if (outcome === "succeeded") finished.resolve("complete");
700
- else {
701
- if (outcome === "cancelled") controller.abort();
702
- finished.reject(
703
- new Error(
704
- outcome === "timeout" ? "Command timed out" : "command stopped\nunderlying cause",
705
- ),
706
- );
707
- }
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
+ });
708
682
  await execution;
709
683
  assert.equal(events.at(-1)?.command, outcome);
710
684
  const terminalCount = updates.length;
711
685
  t.mock.timers.tick(20_000);
712
686
  assert.equal(updates.length, terminalCount);
713
687
  } finally {
714
- finished.resolve("");
688
+ finished.resolve({ status: "succeeded", output: "" });
715
689
  await rm(dir, { recursive: true, force: true });
716
690
  }
717
691
  });
@@ -722,7 +696,7 @@ test("commands without an explicit timeout do not start countdown updates", asyn
722
696
  const dir = await tempDir();
723
697
  t.mock.timers.enable({ apis: ["Date", "setInterval"], now: 0 });
724
698
  const started = Promise.withResolvers<void>();
725
- const finished = Promise.withResolvers<string>();
699
+ const finished = Promise.withResolvers<CommandOutcome>();
726
700
  const events: ActionFusionProgress[] = [];
727
701
  try {
728
702
  const fusion = createActionFusionExecutor(
@@ -742,48 +716,17 @@ test("commands without an explicit timeout do not start countdown updates", asyn
742
716
  return publishedMutation("saved\n", { content: [], details: undefined });
743
717
  },
744
718
  signal: undefined,
745
- ctx: ctx(dir),
719
+ ctx: await ctx(dir, t),
746
720
  });
747
721
  await started.promise;
748
722
  const count = events.length;
749
723
  t.mock.timers.tick(20_000);
750
724
  assert.equal(events.length, count);
751
725
  assert.equal(events.at(-1)?.timing, undefined);
752
- finished.resolve("complete");
726
+ finished.resolve({ status: "succeeded", output: "complete" });
753
727
  await execution;
754
728
  } finally {
755
- finished.resolve("");
756
- await rm(dir, { recursive: true, force: true });
757
- }
758
- });
759
-
760
- test("Pi Bash timeout returns the cause to the model while keeping the published file", async () => {
761
- const dir = await tempDir();
762
- try {
763
- await writeFile(join(dir, "slow.mjs"), "setTimeout(() => {}, 10_000);\n");
764
- const events: ActionFusionProgress[] = [];
765
- const fusion = createActionFusionExecutor(undefined, (event) => events.push(event));
766
- const tool = makeWriteOverride(dir, fusion);
767
- const result = await callTool(
768
- tool,
769
- {
770
- path: "saved.txt",
771
- content: "published\n",
772
- then_run: { command: "node slow.mjs", timeout: 0.2 },
773
- },
774
- { ctx: ctx(dir) },
775
- );
776
- assert.equal(await readFile(join(dir, "saved.txt"), "utf8"), "published\n");
777
- assert.equal(result.details.actionFusion.command, "timeout");
778
- assert.equal(result.details.actionFusion.publication, "PUBLISHED");
779
- const text = result.content
780
- .filter((block: { type: string }) => block.type === "text")
781
- .map((block: { text: string }) => block.text)
782
- .join("\n");
783
- assert.match(text, /timed out after 0\.2 seconds/);
784
- assert.match(text, /File changes.*saved/);
785
- assert.equal(events.at(-1)?.command, "timeout");
786
- } finally {
729
+ finished.resolve({ status: "succeeded", output: "" });
787
730
  await rm(dir, { recursive: true, force: true });
788
731
  }
789
732
  });