@criogaid/pi-hashline-edit 0.10.0 → 0.11.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 (94) hide show
  1. package/README.md +4 -3
  2. package/README.zh-CN.md +4 -3
  3. package/package.json +1 -1
  4. package/src/core/apply.test.ts +2 -2
  5. package/src/core/apply.ts +2 -2
  6. package/src/core/character-set.test.ts +2 -3
  7. package/src/core/character-set.ts +1 -1
  8. package/src/core/ranges.test.ts +2 -1
  9. package/src/core/ranges.ts +1 -1
  10. package/src/core/types.ts +1 -1
  11. package/src/index.ts +8 -8
  12. package/src/integration/config-registration.test.ts +8 -10
  13. package/src/integration/fusion-dispatch.test.ts +2 -2
  14. package/src/integration/grep-errors.test.ts +3 -3
  15. package/src/integration/grep-flags.test.ts +5 -5
  16. package/src/integration/grep-js-completeness.test.ts +12 -11
  17. package/src/integration/grep-line-candidates.test.ts +3 -2
  18. package/src/integration/grep-matrix.test.ts +5 -4
  19. package/src/integration/grep-order.test.ts +4 -4
  20. package/src/integration/grep-path-matrix.test.ts +5 -4
  21. package/src/integration/grep-prefilter-coverage.test.ts +4 -3
  22. package/src/integration/grep-process-limits.test.ts +2 -4
  23. package/src/integration/grep-regex.test.ts +10 -10
  24. package/src/integration/grep-rg.test.ts +50 -48
  25. package/src/integration/grep-scan-budget.test.ts +8 -8
  26. package/src/integration/grep-translation.test.ts +8 -7
  27. package/src/integration/large-text.test.ts +5 -5
  28. package/src/integration/model-budget-lifecycle.test.ts +9 -9
  29. package/src/integration/mutation-file-types.testing.ts +4 -4
  30. package/src/integration/npm-package.testing.ts +3 -3
  31. package/src/integration/publication-read-changes.test.ts +54 -54
  32. package/src/integration/read-changes.test.ts +4 -4
  33. package/src/integration/replace-worker-boundary.test.ts +1 -1
  34. package/src/integration/report-replay.test.ts +5 -6
  35. package/src/integration/utf8-errors.test.ts +4 -4
  36. package/src/pi/AGENTS.md +6 -5
  37. package/src/pi/action-fusion.test.ts +125 -105
  38. package/src/pi/action-fusion.testing.ts +38 -0
  39. package/src/pi/action-fusion.ts +9 -21
  40. package/src/pi/argument-diagnostics.ts +4 -3
  41. package/src/pi/argument-format.test.ts +19 -18
  42. package/src/pi/argument-validation.test.ts +218 -139
  43. package/src/pi/budgets.ts +1 -4
  44. package/src/pi/codemode.test.ts +7 -2
  45. package/src/pi/config.test.ts +2 -1
  46. package/src/pi/config.ts +8 -3
  47. package/src/pi/diagnostic-buffer.test.ts +23 -13
  48. package/src/pi/edit-tool.ts +47 -62
  49. package/src/pi/error-text.ts +7 -2
  50. package/src/pi/execute.test.ts +174 -157
  51. package/src/pi/failure-context.test.ts +4 -3
  52. package/src/pi/failure-context.ts +1 -1
  53. package/src/pi/failure-path.test.ts +37 -37
  54. package/src/pi/file-commit.test.ts +47 -19
  55. package/src/pi/file-commit.ts +36 -9
  56. package/src/pi/fusion-card.test.ts +22 -21
  57. package/src/pi/grep-candidates.test.ts +18 -20
  58. package/src/pi/grep-candidates.ts +8 -13
  59. package/src/pi/grep-matrix.test.ts +3 -3
  60. package/src/pi/grep-order.test.ts +12 -11
  61. package/src/pi/grep-output.ts +36 -15
  62. package/src/pi/grep-reread.ts +7 -2
  63. package/src/pi/grep-rg.testing.ts +70 -0
  64. package/src/pi/grep-scope.ts +4 -4
  65. package/src/pi/grep-search.ts +8 -11
  66. package/src/pi/grep-tool.ts +23 -39
  67. package/src/pi/grep.test.ts +102 -116
  68. package/src/pi/model-budgets.test.ts +2 -1
  69. package/src/pi/mutation-outcome.testing.ts +0 -1
  70. package/src/pi/mutation-result.test.ts +8 -8
  71. package/src/pi/mutation-result.ts +1 -1
  72. package/src/pi/mutation-runner.ts +9 -5
  73. package/src/pi/output-budgets.test.ts +53 -31
  74. package/src/pi/pi.test.ts +18 -13
  75. package/src/pi/read-tool.ts +13 -18
  76. package/src/pi/read.test.ts +22 -41
  77. package/src/pi/registration.test.ts +25 -19
  78. package/src/pi/render.test.ts +51 -32
  79. package/src/pi/render.ts +7 -4
  80. package/src/pi/replace-regex.ts +1 -1
  81. package/src/pi/replace-tool.ts +6 -16
  82. package/src/pi/replace.test.ts +45 -34
  83. package/src/pi/report-failure.testing.ts +9 -1
  84. package/src/pi/report-schema.ts +205 -83
  85. package/src/pi/report.test.ts +66 -64
  86. package/src/pi/report.ts +23 -17
  87. package/src/pi/result-safety.test.ts +121 -100
  88. package/src/pi/rg-process.test.ts +2 -2
  89. package/src/pi/rg-process.ts +9 -15
  90. package/src/pi/schema.ts +23 -0
  91. package/src/pi/tool-factories.testing.ts +59 -0
  92. package/src/pi/write-tool.ts +9 -15
  93. package/src/pi/write.test.ts +30 -31
  94. package/src/testing/run-tests.ts +1 -1
@@ -1,6 +1,7 @@
1
+ import type { MockRg } from "./grep-rg.testing.ts";
1
2
  import { rejectsArgument, rejectsArguments } from "./argument-error.testing.ts";
2
3
  /**
3
- * Deterministic grep override tests. Ripgrep and built-in grep are injected;
4
+ * Deterministic grep override tests. The ripgrep process module is mocked;
4
5
  * fixture files live only in a per-test system temporary directory.
5
6
  */
6
7
  import { test } from "node:test";
@@ -14,21 +15,22 @@ import { join } from "node:path";
14
15
  import { initTheme } from "@earendil-works/pi-coding-agent";
15
16
  import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
16
17
  import { computeLineHash } from "../core/hash.ts";
17
- import { makeGrepOverrideWithBackend } from "./grep-tool.ts";
18
+ import { makeMockGrep } from "./grep-rg.testing.ts";
18
19
  import { Worker } from "node:worker_threads";
19
- import { makeEditOverride } from "./edit-tool.ts";
20
+ const { makeEditOverride } = await import("./tool-factories.testing.ts");
20
21
  import { callTool } from "./tool-call.testing.ts";
21
- import { DEFAULT_CONFIG } from "./config.ts";
22
- import { DEFAULT_OUTPUT_BUDGETS, formatByteSize, outputBudgetsFor } from "./budgets.ts";
22
+ const { DEFAULT_CONFIG } = await import("./tool-factories.testing.ts");
23
+ import { formatByteSize, outputBudgetsFor } from "./budgets.ts";
23
24
  import { reportOf } from "./report.ts";
24
- import { grepCounts } from "./grep-output.testing.ts";
25
- import { parseFileHeader } from "./grep-output.ts";
25
+ const { grepCounts } = await import("./grep-output.testing.ts");
26
+ const { parseFileHeader } = await import("./grep-output.ts");
26
27
  import { parseHashline } from "./anchor-format.ts";
27
28
  import { expectToolFailure } from "./report-failure.testing.ts";
28
29
  import { RegExpParser } from "@eslint-community/regexpp";
29
- import { COMMON_RG_ARGS, LINE_LISTING_ARGS, type GrepBackend } from "./rg-process.ts";
30
- import { candidateArgs } from "./grep-candidates.ts";
31
- import { extractPrefilter } from "../core/search-analysis.ts";
30
+ import { COMMON_RG_ARGS, LINE_LISTING_ARGS } from "./rg-process.ts";
31
+ import { fileCandidateArgs } from "./grep-rg.testing.ts";
32
+ const { DEFAULT_OUTPUT_BUDGETS } = await import("./tool-factories.testing.ts");
33
+
32
34
  import { lineCandidatePatterns } from "./rg-regex.ts";
33
35
 
34
36
  type FakeOptions = {
@@ -68,7 +70,7 @@ function fakeBackend(options: FakeOptions = {}) {
68
70
  stopped: false,
69
71
  };
70
72
  };
71
- const backend: GrepBackend = {
73
+ const backend: MockRg = {
72
74
  runRgPaths: (args, _signal, onPath) => run("paths", args, onPath),
73
75
  runRgLines: (args, _signal, _maxLines, onFile) =>
74
76
  run("lines", args, (file) => onFile(file, options.lines)),
@@ -83,7 +85,7 @@ const call = (tool: any, params: any, signal?: AbortSignal) =>
83
85
  test("explicit JavaScript flags → call rendering shows them", () => {
84
86
  initTheme("dark");
85
87
  const { backend } = fakeBackend();
86
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, backend);
88
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, backend);
87
89
  const rendered = tool.renderCall!(
88
90
  { pattern: ["\\p{Letter}+"], literal: false, flags: "u" },
89
91
  theme,
@@ -96,7 +98,7 @@ test("explicit JavaScript flags → call rendering shows them", () => {
96
98
  test("streamed grep strings and null fields → render the pattern and default path without a limit", () => {
97
99
  initTheme("dark");
98
100
  const { backend } = fakeBackend();
99
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, backend);
101
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, backend);
100
102
  for (const pattern of ["needle", null]) {
101
103
  const args: unknown = { pattern, literal: true, path: null, limit: null };
102
104
  const rendered = tool
@@ -128,7 +130,7 @@ test("configured defaults → descriptions, limits, and context use registered v
128
130
  ...DEFAULT_CONFIG,
129
131
  grep: { ...DEFAULT_CONFIG.grep, defaultLimit: 1, defaultContext: 2 },
130
132
  };
131
- const tool = makeGrepOverrideWithBackend(dir, config, fake.backend);
133
+ const tool = makeMockGrep(dir, config, fake.backend);
132
134
  for (const [field, expected] of [
133
135
  ["limit", 1],
134
136
  ["context", 2],
@@ -163,7 +165,7 @@ test("configured defaults → descriptions, limits, and context use registered v
163
165
  test("grep limit accepts only positive integers", async () => {
164
166
  await withDir(async (dir) => {
165
167
  const fake = fakeBackend();
166
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
168
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
167
169
  const limitSchema = tool.parameters.properties.limit;
168
170
  assert.equal(limitSchema.type, "number");
169
171
  assert.equal("minimum" in limitSchema ? limitSchema.minimum : undefined, 1);
@@ -182,7 +184,7 @@ test("grep limit accepts only positive integers", async () => {
182
184
  test("grep schema rejects empty search inputs and fractional context", async () =>
183
185
  withDir(async (dir) => {
184
186
  const fake = fakeBackend();
185
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
187
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
186
188
  const invalidArgs = [
187
189
  { literal: true, pattern: "" },
188
190
  { literal: true, pattern: [] },
@@ -205,7 +207,7 @@ test("grep schema rejects empty search inputs and fractional context", async ()
205
207
 
206
208
  test("grep points wildcard paths to glob without changing ordinary missing-path errors", async () => {
207
209
  await withDir(async (dir) => {
208
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fakeBackend().backend);
210
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fakeBackend().backend);
209
211
  await expectToolFailure(
210
212
  call(tool, { literal: true, pattern: "value", path: "src/fusion-card*" }),
211
213
  "PATH_NOT_FOUND",
@@ -234,7 +236,7 @@ test("multiple grep paths are missing → reports all resolved paths and selects
234
236
  [["missing?.txt", "present.txt", "other.txt"], ["missing?.txt", "other.txt"], true],
235
237
  ] as const) {
236
238
  const fake = fakeBackend();
237
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
239
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
238
240
  const result = await call(tool, { literal: true, pattern: "value", path });
239
241
  assert.equal(result.isError, true);
240
242
  const block = result.content[0];
@@ -265,7 +267,7 @@ test("matched files → full-line hash anchors", async () => {
265
267
  await writeFile(b, "alpha here\n");
266
268
  const fake = fakeBackend({ paths: [a, b] });
267
269
 
268
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
270
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
269
271
  assert.deepEqual(tool.parameters.required, ["pattern", "literal"]);
270
272
  const result = await call(tool, { literal: true, pattern: "alpha" });
271
273
  const output = text(result);
@@ -298,7 +300,7 @@ test("grep payload blocks → only a single complete content or count block omit
298
300
  grepBytes: truncated ? truncatedBytes : DEFAULT_OUTPUT_BUDGETS.grepBytes,
299
301
  };
300
302
  const result = await callTool(
301
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend, () => budget),
303
+ makeMockGrep(dir, DEFAULT_CONFIG, backend, () => budget),
302
304
  {
303
305
  path: dir,
304
306
  pattern: "needle",
@@ -341,7 +343,7 @@ test("grep output truncates preview rows → reports only displayed preview fact
341
343
  const { backend } = fakeBackend({ paths });
342
344
  const args = { path: dir, pattern: "needle", literal: true };
343
345
  const full = await callTool(
344
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend, () => budget),
346
+ makeMockGrep(dir, DEFAULT_CONFIG, backend, () => budget),
345
347
  args,
346
348
  );
347
349
  const rows = text(full).split("\n");
@@ -350,7 +352,7 @@ test("grep output truncates preview rows → reports only displayed preview fact
350
352
  for (const keptLines of [headerIndex - 1, headerIndex + 1, headerIndex + 2, rows.length]) {
351
353
  const expected = rows.slice(0, keptLines).join("\n");
352
354
  const result = await callTool(
353
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend, () => ({
355
+ makeMockGrep(dir, DEFAULT_CONFIG, backend, () => ({
354
356
  ...budget,
355
357
  grepBytes: Buffer.byteLength(expected),
356
358
  })),
@@ -380,7 +382,7 @@ test(
380
382
  const path = join(dir, "outside.txt");
381
383
  await writeFile(path, "needle\n");
382
384
  const { backend } = fakeBackend({ paths: [path] });
383
- const result = await callTool(makeGrepOverrideWithBackend(cwd, DEFAULT_CONFIG, backend), {
385
+ const result = await callTool(makeMockGrep(cwd, DEFAULT_CONFIG, backend), {
384
386
  path,
385
387
  pattern: "needle",
386
388
  literal: true,
@@ -430,16 +432,13 @@ test("file changes after matching → summary modes retain the snapshot and cont
430
432
  },
431
433
  );
432
434
  const fake = fakeBackend({ paths });
433
- const result = await call(
434
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
435
- {
436
- pattern: "needle",
437
- literal: true,
438
- multiline,
439
- outputMode,
440
- context: 1,
441
- },
442
- );
435
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
436
+ pattern: "needle",
437
+ literal: true,
438
+ multiline,
439
+ outputMode,
440
+ context: 1,
441
+ });
443
442
  assert.equal(changed, true);
444
443
  if (outputMode !== "content") {
445
444
  assert.equal(result.isError, undefined);
@@ -494,7 +493,7 @@ test("excluded changed file → contributes no preview limit or recovery to comp
494
493
  },
495
494
  );
496
495
  const { backend } = fakeBackend({ paths });
497
- const result = await callTool(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend), {
496
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
498
497
  pattern: "needle",
499
498
  literal: true,
500
499
  outputMode: "content",
@@ -517,28 +516,24 @@ test("excluded changed file → contributes no preview limit or recovery to comp
517
516
  });
518
517
  });
519
518
 
520
- test("candidate selection → reports only whole-file candidate facts", async () =>
519
+ test("candidate selection → reports matches without internal strategy facts", async () =>
521
520
  withDir(async (dir) => {
522
521
  const file = join(dir, "input.txt");
523
522
  await writeFile(file, "abc \nneedle");
524
- for (const [pattern, multiline, scanned] of [
525
- ["needle", false, undefined],
526
- ["needle", true, "files"],
527
- ["[^x\\s]{3}\\s", true, "all"],
523
+ for (const [pattern, multiline] of [
524
+ ["needle", false],
525
+ ["needle", true],
526
+ ["[^x\\s]{3}\\s", true],
528
527
  ] as const) {
529
528
  const fake = fakeBackend({ paths: [file] });
530
- const result = await callTool(
531
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
532
- {
533
- path: file,
534
- pattern,
535
- literal: false,
536
- multiline,
537
- },
538
- );
529
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
530
+ path: file,
531
+ pattern,
532
+ literal: false,
533
+ multiline,
534
+ });
539
535
  assert.equal(result.isError, undefined);
540
536
  assert.equal(grepCounts(result).matches, 1);
541
- assert.equal(reportOf(result, "grep")?.scanned, scanned);
542
537
  assert.equal(reportOf(result, "grep")?.scanLimit, undefined);
543
538
  assert.equal(fake.calls[0].kind, multiline ? "paths" : "lines");
544
539
  }
@@ -553,7 +548,7 @@ test("grep in a subdirectory returns a path that edits the matching file", async
553
548
  await writeFile(rootFile, original);
554
549
  await writeFile(matchedFile, original);
555
550
  const fake = fakeBackend({ paths: [matchedFile] });
556
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
551
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
557
552
  literal: true,
558
553
  pattern: "status",
559
554
  path: "src",
@@ -566,11 +561,11 @@ test("grep in a subdirectory returns a path that edits the matching file", async
566
561
  const edit: any = makeEditOverride(dir, DEFAULT_CONFIG);
567
562
  await call(edit, {
568
563
  path: displayPath,
569
- edits: [
564
+ steps: [
570
565
  {
571
566
  action: "replace",
572
567
  anchor: contextAnchor,
573
- body: ["export const context = 2;"],
568
+ lines: ["export const context = 2;"],
574
569
  },
575
570
  ],
576
571
  });
@@ -591,7 +586,7 @@ test("context preserves logical CRLF anchors around a matched line", async () =>
591
586
  );
592
587
  const fake = fakeBackend({ paths: [file] });
593
588
 
594
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
589
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
595
590
  const contextSchema: any = tool.parameters.properties.context;
596
591
  assert.equal(contextSchema.type, "number");
597
592
  assert.equal(contextSchema.minimum, 0);
@@ -618,7 +613,7 @@ test("scope filters and output modes → confirmed files and counts are preserve
618
613
  await writeFile(b, "foo a.b\n");
619
614
  const fake = fakeBackend({ paths: [a, b] });
620
615
 
621
- const files = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
616
+ const files = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
622
617
  pattern: ["Foo", "a.b"],
623
618
  path: ["a.ts", "b.ts"],
624
619
  glob: ["*.ts", "!**/*.test.ts"],
@@ -631,7 +626,7 @@ test("scope filters and output modes → confirmed files and counts are preserve
631
626
  );
632
627
  assert.deepEqual(fake.calls.at(-1)?.args.slice(-2), [a, b]);
633
628
 
634
- const count = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
629
+ const count = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
635
630
  literal: true,
636
631
  pattern: "foo",
637
632
  outputMode: "count",
@@ -651,7 +646,7 @@ for (const diagnosticLineCount of [0, 80]) {
651
646
  "error: missing runtime library",
652
647
  ].join("\n");
653
648
  const fake = fakeBackend({ code: 2, stderr: diagnostic });
654
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, fake.backend);
649
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, fake.backend);
655
650
  const args = { pattern: ["(?<=a+)b"], literal: false };
656
651
  const failure: Awaited<ReturnType<typeof tool.execute>> = await callTool(tool, args);
657
652
  assert.equal(failure.isError, true);
@@ -701,7 +696,7 @@ for (const diagnosticLineCount of [0, 80]) {
701
696
  }
702
697
 
703
698
  test("aligns TUI line numbers across files to the widest result", () => {
704
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, fakeBackend().backend);
699
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, fakeBackend().backend);
705
700
  const raw = [
706
701
  "a.ts · 2 matches",
707
702
  "99#ABCD│ alpha",
@@ -732,7 +727,7 @@ test("matching rows exceed limit → bounded results offer optional continuation
732
727
  const fake = fakeBackend({ paths: [file] });
733
728
 
734
729
  const limit = 1;
735
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
730
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
736
731
  literal: true,
737
732
  pattern: "alpha",
738
733
  limit,
@@ -751,7 +746,7 @@ test("literal punctuation → exact text is matched", async () =>
751
746
  const file = join(dir, "literal.txt");
752
747
  await writeFile(file, "foo(0)\n");
753
748
  const fake = fakeBackend({ paths: [file] });
754
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
749
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
755
750
  const result = await call(tool, { pattern: "foo(0)", literal: true });
756
751
  assert.match(text(result), /1#[0-9A-Z]+│foo\(0\)/);
757
752
  assert.equal(fake.calls.length, 1);
@@ -761,7 +756,7 @@ test("literal pipe patterns find no match → alternatives recovery preserves li
761
756
  withDir(async (dir) => {
762
757
  const path = join(dir, "pipe.txt");
763
758
  const { backend } = fakeBackend({ paths: [path] });
764
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend);
759
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, backend);
765
760
  for (const { pattern, literal, source, matches, literalPipe } of [
766
761
  { pattern: "foo|bar", literal: true, source: "foo\nbar\n", matches: 0, literalPipe: true },
767
762
  {
@@ -817,7 +812,7 @@ test("invalid JavaScript → its field rejects before file discovery", async ()
817
812
  ["*", undefined, "pattern[0]"],
818
813
  ] as const) {
819
814
  const fake = fakeBackend();
820
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
815
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
821
816
  await assert.rejects(
822
817
  call(tool, { path: "missing.txt", pattern, literal: false, flags }),
823
818
  rejectsArgument(field, /Invalid regular expression/),
@@ -829,7 +824,7 @@ test("invalid JavaScript → its field rejects before file discovery", async ()
829
824
  test("grep OR arrays accept more than sixteen patterns in one line scan", async () => {
830
825
  await withDir(async (dir) => {
831
826
  const fake = fakeBackend();
832
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
827
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
833
828
  const patterns = Array.from({ length: 17 }, (_, index) => `pattern${index}`);
834
829
  assert.equal(
835
830
  reportOf(await call(tool, { literal: true, pattern: patterns }), "grep")?.matches,
@@ -842,7 +837,7 @@ test("grep OR arrays accept more than sixteen patterns in one line scan", async
842
837
  test("character classes, literals, and empty-line searches → valid nonempty patterns", async () => {
843
838
  await withDir(async (dir) => {
844
839
  const fake = fakeBackend();
845
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
840
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
846
841
  for (const pattern of ["[\\w.*]*", "^[\\w.*]+$", "[\\w.*]?"]) {
847
842
  assert.equal(reportOf(await call(tool, { pattern, literal: false }), "grep")?.matches, 0);
848
843
  }
@@ -856,7 +851,7 @@ test("character classes, literals, and empty-line searches → valid nonempty pa
856
851
  test("grep accepts nonempty whitespace literals", async () => {
857
852
  await withDir(async (dir) => {
858
853
  const fake = fakeBackend();
859
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
854
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
860
855
  for (const pattern of [" ", "\t", ["word", " "]]) {
861
856
  assert.equal(reportOf(await call(tool, { pattern, literal: true }), "grep")?.matches, 0);
862
857
  }
@@ -867,7 +862,7 @@ test("grep accepts nonempty whitespace literals", async () => {
867
862
  test("reports empty output and ripgrep execution failures", async () => {
868
863
  await withDir(async (dir) => {
869
864
  const empty = fakeBackend({ code: 1 });
870
- const noMatches = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, empty.backend), {
865
+ const noMatches = await call(makeMockGrep(dir, DEFAULT_CONFIG, empty.backend), {
871
866
  literal: true,
872
867
  pattern: "missing",
873
868
  });
@@ -877,7 +872,7 @@ test("reports empty output and ripgrep execution failures", async () => {
877
872
 
878
873
  const failed = fakeBackend({ code: 2, stderr: "bad regex" });
879
874
  await expectToolFailure(
880
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, failed.backend), {
875
+ call(makeMockGrep(dir, DEFAULT_CONFIG, failed.backend), {
881
876
  pattern: "x",
882
877
  literal: false,
883
878
  }),
@@ -889,7 +884,7 @@ test("reports empty output and ripgrep execution failures", async () => {
889
884
 
890
885
  const rejected = fakeBackend({ error: new Error("spawn failed") });
891
886
  await expectToolFailure(
892
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, rejected.backend), {
887
+ call(makeMockGrep(dir, DEFAULT_CONFIG, rejected.backend), {
893
888
  literal: true,
894
889
  pattern: "x",
895
890
  }),
@@ -908,7 +903,7 @@ test("rejects calls aborted before or during rg execution", async () => {
908
903
  first.abort();
909
904
  await expectToolFailure(
910
905
  call(
911
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, alreadyAborted.backend),
906
+ makeMockGrep(dir, DEFAULT_CONFIG, alreadyAborted.backend),
912
907
  { literal: true, pattern: ["x", "y"] },
913
908
  first.signal,
914
909
  ),
@@ -919,7 +914,7 @@ test("rejects calls aborted before or during rg execution", async () => {
919
914
  const interrupted = fakeBackend({ onRun: () => controller.abort() });
920
915
  await expectToolFailure(
921
916
  call(
922
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, interrupted.backend),
917
+ makeMockGrep(dir, DEFAULT_CONFIG, interrupted.backend),
923
918
  { literal: true, pattern: ["x", "y"] },
924
919
  controller.signal,
925
920
  ),
@@ -933,7 +928,7 @@ test("overlapping OR patterns → each matched line counts once", async () => {
933
928
  const file = join(dir, "fixture.ts");
934
929
  await writeFile(file, "foo bar\n".repeat(4097));
935
930
  const fake = fakeBackend({ paths: [file] });
936
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
931
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
937
932
  pattern: ["foo", "bar"],
938
933
  literal: true,
939
934
  outputMode: "count",
@@ -950,7 +945,7 @@ test("long matching lines → counts do not depend on content previews", async (
950
945
  const line = `foo${"x".repeat(600_000)}\n`;
951
946
  await writeFile(file, line.repeat(3));
952
947
  const fake = fakeBackend({ paths: [file] });
953
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
948
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
954
949
  pattern: "foo",
955
950
  literal: true,
956
951
  outputMode: "count",
@@ -968,7 +963,7 @@ test("grep previews invalid UTF-8 without anchors and skips NUL hits in every mo
968
963
  const fake = fakeBackend({
969
964
  paths: [invalid],
970
965
  });
971
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
966
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
972
967
  literal: true,
973
968
  pattern: "a",
974
969
  path: invalid,
@@ -992,10 +987,13 @@ test("grep previews invalid UTF-8 without anchors and skips NUL hits in every mo
992
987
  { outputMode: "files", multiline: true },
993
988
  { outputMode: "count", multiline: true },
994
989
  ] as const) {
995
- const skipped = await call(
996
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, binaryBackend.backend),
997
- { literal: true, pattern: "a", path: binary, outputMode, multiline },
998
- );
990
+ const skipped = await call(makeMockGrep(dir, DEFAULT_CONFIG, binaryBackend.backend), {
991
+ literal: true,
992
+ pattern: "a",
993
+ path: binary,
994
+ outputMode,
995
+ multiline,
996
+ });
999
997
  assert.equal(reportOf(skipped, "grep")?.matches, 0);
1000
998
  assert.equal(skipped.isError, undefined);
1001
999
  }
@@ -1011,7 +1009,7 @@ test("candidate file disappears before reading → summary modes report incomple
1011
1009
  const fake = fakeBackend({ paths: [file], onRun: () => rm(file) });
1012
1010
  const backend = fake.backend;
1013
1011
  await expectToolFailure(
1014
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend), {
1012
+ call(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
1015
1013
  literal: true,
1016
1014
  pattern: "needle",
1017
1015
  path: file,
@@ -1019,7 +1017,7 @@ test("candidate file disappears before reading → summary modes report incomple
1019
1017
  }),
1020
1018
  "SEARCH_INCOMPLETE",
1021
1019
  (report) => {
1022
- assert.match(report.diagnostics ?? "", /Could not read .*listed\.txt: ENOENT/);
1020
+ assert.match(report.diagnostics ?? "", /listed\.txt: ENOENT/);
1023
1021
  },
1024
1022
  );
1025
1023
  assert.equal(fake.calls.length, 1);
@@ -1040,7 +1038,7 @@ test("candidate listing reports errors → all output modes retain confirmed mat
1040
1038
  code: 2,
1041
1039
  stderr: "unreadable.txt: Permission denied",
1042
1040
  });
1043
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1041
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1044
1042
  literal: true,
1045
1043
  pattern: "needle",
1046
1044
  outputMode,
@@ -1056,7 +1054,7 @@ test("candidate listing reports errors → all output modes retain confirmed mat
1056
1054
  }
1057
1055
  const fake = fakeBackend({ code: 2, stderr: "Permission denied" });
1058
1056
  await expectToolFailure(
1059
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1057
+ call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1060
1058
  literal: true,
1061
1059
  pattern: "needle",
1062
1060
  }),
@@ -1076,7 +1074,7 @@ test("one candidate cannot be read → matches from other files remain available
1076
1074
  await writeFile(gone, "needle\n");
1077
1075
  const fake = fakeBackend({ paths: [good, gone], onRun: () => rm(gone) });
1078
1076
  const backend = fake.backend;
1079
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend), {
1077
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
1080
1078
  literal: true,
1081
1079
  pattern: "needle",
1082
1080
  });
@@ -1092,7 +1090,7 @@ for (const admitted of [2, 1, 0]) {
1092
1090
  await Promise.all(files.map((file) => writeFile(file, "needle\n")));
1093
1091
  const fake = fakeBackend({ paths: files.slice(0, admitted) });
1094
1092
  const result = await call(
1095
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {
1093
+ makeMockGrep(dir, DEFAULT_CONFIG, {
1096
1094
  ...fake.backend,
1097
1095
  runRgPaths: async (...args) => {
1098
1096
  const listing = await fake.backend.runRgPaths(...args);
@@ -1127,7 +1125,7 @@ test("concurrent file searches → all discovered matches remain present", async
1127
1125
  files.push(file);
1128
1126
  }
1129
1127
  const fake = fakeBackend({ paths: files });
1130
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1128
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1131
1129
  literal: true,
1132
1130
  pattern: "match",
1133
1131
  });
@@ -1172,7 +1170,7 @@ test("scope inspection fails for access or traversal reasons → grep preserves
1172
1170
  syncBuiltinESMExports();
1173
1171
  try {
1174
1172
  const fake = fakeBackend();
1175
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
1173
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
1176
1174
  await expectToolFailure(
1177
1175
  callTool(tool, { path, pattern: "needle", literal: true }),
1178
1176
  "FILESYSTEM_ERROR",
@@ -1216,11 +1214,7 @@ test("invalid worker replies → the entire grep call fails", async (t) => {
1216
1214
  return emit.call(this, event, ...(event === "message" ? [{ result }] : args));
1217
1215
  },
1218
1216
  );
1219
- const tool = makeGrepOverrideWithBackend(
1220
- dir,
1221
- DEFAULT_CONFIG,
1222
- fakeBackend({ paths: [path] }).backend,
1223
- );
1217
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fakeBackend({ paths: [path] }).backend);
1224
1218
  await expectToolFailure(
1225
1219
  callTool(tool, { pattern: "^..$", literal: false, path }),
1226
1220
  "REGEX_WORKER_FAILED",
@@ -1237,7 +1231,7 @@ test("catastrophic worker evaluation → timeout and cancellation fail the searc
1237
1231
  const path = join(dir, "input.txt");
1238
1232
  await writeFile(path, `${"a".repeat(100)}!`);
1239
1233
  const config = { ...DEFAULT_CONFIG, grep: { ...DEFAULT_CONFIG.grep, regexTimeoutMs: 3_000 } };
1240
- const tool = makeGrepOverrideWithBackend(dir, config, fakeBackend({ paths: [path] }).backend);
1234
+ const tool = makeMockGrep(dir, config, fakeBackend({ paths: [path] }).backend);
1241
1235
  const params = { path, pattern: "(?=.)^(a+)+$", literal: false };
1242
1236
  await expectToolFailure(callTool(tool, params), "REGEX_TIMEOUT", (report) =>
1243
1237
  assert.equal(report.timeoutMs, config.grep.regexTimeoutMs),
@@ -1273,10 +1267,7 @@ test("non-multiline or multiline query → use line candidates or the file prefi
1273
1267
  multiline,
1274
1268
  ignoreCase: false,
1275
1269
  };
1276
- const result = await callTool(
1277
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
1278
- params,
1279
- );
1270
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), params);
1280
1271
  assert.equal(grepCounts(result).matches, 2);
1281
1272
  assert.equal(fake.calls.length, 1);
1282
1273
  assert.equal(fake.calls[0].kind, multiline ? "paths" : "lines");
@@ -1284,7 +1275,7 @@ test("non-multiline or multiline query → use line candidates or the file prefi
1284
1275
  const candidates = lineCandidatePatterns(query);
1285
1276
  assert.ok(candidates);
1286
1277
  const prefix = multiline
1287
- ? [...candidateArgs(extractPrefilter(query)), "--null"]
1278
+ ? [...(await fileCandidateArgs(query)), "--null"]
1288
1279
  : [
1289
1280
  ...COMMON_RG_ARGS,
1290
1281
  "--engine=default",
@@ -1319,14 +1310,11 @@ test("line discovery status and emitted files → fallback only for code 2 befor
1319
1310
  [2, [file], ["lines"]],
1320
1311
  ] as const) {
1321
1312
  const fake = fakeBackend({ code, paths: [...paths], lines: [1] });
1322
- const result = await callTool(
1323
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
1324
- {
1325
- path: dir,
1326
- pattern: "needle",
1327
- literal: true,
1328
- },
1329
- );
1313
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1314
+ path: dir,
1315
+ pattern: "needle",
1316
+ literal: true,
1317
+ });
1330
1318
  assert.deepEqual(
1331
1319
  fake.calls.map(({ kind }) => kind),
1332
1320
  kinds,
@@ -1342,21 +1330,18 @@ test("sparse, dense, or overflowed candidate lines → matching preserves origin
1342
1330
  await writeFile(file, "miss\r\nneedle\r\nmiss\nmiss\nneedle\r");
1343
1331
  for (const lines of [[2, 5], [1, 2, 4, 5], undefined]) {
1344
1332
  const fake = fakeBackend({ paths: [file], lines });
1345
- const result = await callTool(
1346
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
1347
- {
1348
- path: file,
1349
- pattern: "needle",
1350
- literal: true,
1351
- context: 0,
1352
- },
1353
- );
1333
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1334
+ path: file,
1335
+ pattern: "needle",
1336
+ literal: true,
1337
+ context: 0,
1338
+ });
1354
1339
  assert.equal(grepCounts(result).matches, 2);
1355
1340
  assert.match(text(result), /2#[0-9A-Z]+│needle/);
1356
1341
  assert.match(text(result), /5#[0-9A-Z]+│needle␍/);
1357
1342
  }
1358
1343
  const fake = fakeBackend({ paths: [file], lines: [2, 5] });
1359
- const result = await callTool(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1344
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1360
1345
  path: file,
1361
1346
  pattern: "\\r$",
1362
1347
  literal: false,
@@ -1374,7 +1359,7 @@ test("native-valid pattern exceeds parser limits → use the all-file prefilter"
1374
1359
  throw new RangeError("parser stack limit");
1375
1360
  });
1376
1361
  const fake = fakeBackend({ paths: [file] });
1377
- const result = await callTool(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1362
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1378
1363
  path: file,
1379
1364
  pattern: "a",
1380
1365
  literal: false,
@@ -1386,7 +1371,8 @@ test("native-valid pattern exceeds parser limits → use the all-file prefilter"
1386
1371
  ["paths"],
1387
1372
  );
1388
1373
  assert.deepEqual(fake.calls[0].args, [
1389
- ...candidateArgs({ kind: "all" }),
1374
+ ...COMMON_RG_ARGS,
1375
+ "--files",
1390
1376
  "--null",
1391
1377
  "--hidden",
1392
1378
  "--glob",
@@ -1403,7 +1389,7 @@ test("rg rejects line patterns before listing files → successful file fallback
1403
1389
  const lines = fakeBackend({ code: 2, stderr: "regex too large" });
1404
1390
  const paths = fakeBackend({ paths: [file] });
1405
1391
  const result = await callTool(
1406
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {
1392
+ makeMockGrep(dir, DEFAULT_CONFIG, {
1407
1393
  runRgLines: lines.backend.runRgLines,
1408
1394
  runRgPaths: paths.backend.runRgPaths,
1409
1395
  }),
@@ -1,6 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { test } from "node:test";
3
- import { DEFAULT_OUTPUT_BUDGETS, MAX_CONTENT_KIB, outputBudgetsFor } from "./budgets.ts";
3
+ import { MAX_CONTENT_KIB, outputBudgetsFor } from "./budgets.ts";
4
+ import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
4
5
  import { openTestSession } from "../testing/session.testing.ts";
5
6
  import { registerModelBudgets } from "./model-budgets.ts";
6
7
 
@@ -15,7 +15,6 @@ export function publishedMutation<T extends object | undefined>(
15
15
  publication: "PUBLISHED",
16
16
  publishedRevision: revision,
17
17
  observedRevision: revision,
18
- created: false,
19
18
  },
20
19
  };
21
20
  }