@criogaid/pi-hashline-edit 0.9.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 (131) hide show
  1. package/README.md +12 -12
  2. package/README.zh-CN.md +12 -12
  3. package/THIRD_PARTY_NOTICES.md +0 -6
  4. package/package.json +1 -1
  5. package/src/core/AGENTS.md +4 -5
  6. package/src/core/apply.test.ts +96 -271
  7. package/src/core/apply.ts +62 -169
  8. package/src/core/case-fold.ts +8 -67
  9. package/src/core/character-set.test.ts +2 -3
  10. package/src/core/character-set.ts +5 -5
  11. package/src/core/errors.test.ts +23 -7
  12. package/src/core/errors.ts +32 -5
  13. package/src/core/hash.test.ts +8 -16
  14. package/src/core/hash.ts +3 -23
  15. package/src/core/lines.ts +2 -4
  16. package/src/core/ranges.test.ts +2 -1
  17. package/src/core/ranges.ts +1 -1
  18. package/src/core/regex.ts +3 -4
  19. package/src/core/replace.test.ts +47 -1
  20. package/src/core/replace.ts +19 -13
  21. package/src/core/search-analysis.test.ts +24 -27
  22. package/src/core/search-analysis.ts +34 -65
  23. package/src/core/search-matrix.testing.ts +0 -2
  24. package/src/core/search.ts +1 -1
  25. package/src/core/text.test.ts +5 -5
  26. package/src/core/text.ts +5 -12
  27. package/src/core/types.ts +8 -44
  28. package/src/index.ts +8 -8
  29. package/src/integration/config-registration.test.ts +8 -10
  30. package/src/integration/fusion-dispatch.test.ts +4 -7
  31. package/src/integration/grep-errors.test.ts +3 -3
  32. package/src/integration/grep-flags.test.ts +5 -19
  33. package/src/integration/grep-js-completeness.test.ts +45 -18
  34. package/src/integration/grep-line-candidates.test.ts +7 -10
  35. package/src/integration/grep-matrix.test.ts +6 -9
  36. package/src/integration/grep-order.test.ts +4 -4
  37. package/src/integration/grep-path-matrix.test.ts +10 -9
  38. package/src/integration/grep-prefilter-coverage.test.ts +5 -8
  39. package/src/integration/grep-process-limits.test.ts +76 -0
  40. package/src/integration/grep-regex.test.ts +10 -10
  41. package/src/integration/grep-rg.test.ts +166 -66
  42. package/src/integration/grep-scan-budget.test.ts +9 -9
  43. package/src/integration/grep-translation.test.ts +18 -32
  44. package/src/integration/large-text.test.ts +6 -52
  45. package/src/integration/model-budget-lifecycle.test.ts +10 -9
  46. package/src/integration/mutation-file-types.testing.ts +4 -4
  47. package/src/integration/npm-package.testing.ts +3 -3
  48. package/src/integration/publication-read-changes.test.ts +161 -83
  49. package/src/integration/read-changes.test.ts +4 -4
  50. package/src/integration/replace-worker-boundary.test.ts +22 -12
  51. package/src/integration/report-replay.test.ts +23 -26
  52. package/src/integration/utf8-errors.test.ts +4 -4
  53. package/src/pi/AGENTS.md +18 -17
  54. package/src/pi/action-fusion.test.ts +241 -353
  55. package/src/pi/action-fusion.testing.ts +38 -0
  56. package/src/pi/action-fusion.ts +150 -125
  57. package/src/pi/anchor-format.test.ts +9 -9
  58. package/src/pi/anchor-format.ts +6 -8
  59. package/src/pi/argument-diagnostics.ts +25 -28
  60. package/src/pi/argument-error.ts +2 -1
  61. package/src/pi/argument-format.test.ts +19 -18
  62. package/src/pi/argument-validation.test.ts +334 -283
  63. package/src/pi/argument-validation.ts +5 -8
  64. package/src/pi/budgets.ts +6 -8
  65. package/src/pi/codemode.test.ts +7 -2
  66. package/src/pi/config.test.ts +7 -3
  67. package/src/pi/config.ts +12 -9
  68. package/src/pi/diagnostic-buffer.test.ts +34 -13
  69. package/src/pi/diagnostic-buffer.ts +1 -2
  70. package/src/pi/directory-sync.test.ts +0 -1
  71. package/src/pi/edit-tool.ts +86 -211
  72. package/src/pi/error-text.ts +10 -9
  73. package/src/pi/execute.test.ts +249 -345
  74. package/src/pi/failure-context.test.ts +146 -127
  75. package/src/pi/failure-context.ts +45 -94
  76. package/src/pi/failure-path.test.ts +182 -155
  77. package/src/pi/file-commit.test.ts +156 -71
  78. package/src/pi/file-commit.ts +126 -146
  79. package/src/pi/file-snapshot.test.ts +3 -5
  80. package/src/pi/fusion-card.test.ts +26 -22
  81. package/src/pi/fusion-card.ts +16 -24
  82. package/src/pi/grep-candidates.test.ts +19 -120
  83. package/src/pi/grep-candidates.ts +25 -76
  84. package/src/pi/grep-matrix.test.ts +5 -5
  85. package/src/pi/grep-order.test.ts +16 -15
  86. package/src/pi/grep-output.ts +94 -107
  87. package/src/pi/grep-render.ts +1 -1
  88. package/src/pi/grep-reread.ts +97 -0
  89. package/src/pi/grep-rg.testing.ts +70 -0
  90. package/src/pi/grep-scope.ts +41 -43
  91. package/src/pi/grep-search.ts +27 -39
  92. package/src/pi/grep-tool.ts +63 -106
  93. package/src/pi/grep.test.ts +177 -156
  94. package/src/pi/model-budgets.test.ts +27 -24
  95. package/src/pi/model-budgets.ts +6 -38
  96. package/src/pi/mutation-outcome.testing.ts +0 -1
  97. package/src/pi/mutation-result.test.ts +44 -35
  98. package/src/pi/mutation-result.ts +52 -21
  99. package/src/pi/mutation-runner.ts +134 -74
  100. package/src/pi/output-budgets.test.ts +86 -42
  101. package/src/pi/path.ts +1 -1
  102. package/src/pi/pi.test.ts +18 -13
  103. package/src/pi/read-tool.ts +18 -23
  104. package/src/pi/read.test.ts +22 -41
  105. package/src/pi/regex-worker-contract.ts +3 -13
  106. package/src/pi/regex-worker.ts +1 -10
  107. package/src/pi/registration.test.ts +85 -51
  108. package/src/pi/render.test.ts +88 -59
  109. package/src/pi/render.ts +64 -65
  110. package/src/pi/replace-regex.ts +14 -2
  111. package/src/pi/replace-tool.ts +22 -94
  112. package/src/pi/replace-worker.ts +1 -1
  113. package/src/pi/replace.test.ts +53 -38
  114. package/src/pi/report-cause.ts +3 -8
  115. package/src/pi/report-failure.testing.ts +10 -3
  116. package/src/pi/report-schema.ts +251 -148
  117. package/src/pi/report.test.ts +215 -67
  118. package/src/pi/report.ts +50 -98
  119. package/src/pi/result-safety.test.ts +241 -247
  120. package/src/pi/rg-process.test.ts +77 -63
  121. package/src/pi/rg-process.ts +53 -75
  122. package/src/pi/rg-regex.ts +40 -400
  123. package/src/pi/schema.ts +35 -0
  124. package/src/pi/text-stream.test.ts +0 -21
  125. package/src/pi/text-stream.ts +14 -21
  126. package/src/pi/tool-factories.testing.ts +59 -0
  127. package/src/pi/write-tool.ts +36 -71
  128. package/src/pi/write.test.ts +31 -34
  129. package/src/testing/regex-translation-corpus.ts +12 -12
  130. package/src/testing/run-tests.ts +1 -1
  131. package/src/pi/replace-worker-contract.ts +0 -10
@@ -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";
@@ -11,25 +12,25 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
11
12
  import fsPromises from "node:fs/promises";
12
13
  import { tmpdir } from "node:os";
13
14
  import { join } from "node:path";
14
- import { rgPath } from "@vscode/ripgrep";
15
15
  import { initTheme } from "@earendil-works/pi-coding-agent";
16
16
  import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
17
17
  import { computeLineHash } from "../core/hash.ts";
18
- import { makeGrepOverrideWithBackend } from "./grep-tool.ts";
18
+ import { makeMockGrep } from "./grep-rg.testing.ts";
19
19
  import { Worker } from "node:worker_threads";
20
- import { makeEditOverride } from "./edit-tool.ts";
20
+ const { makeEditOverride } = await import("./tool-factories.testing.ts");
21
21
  import { callTool } from "./tool-call.testing.ts";
22
- import { DEFAULT_CONFIG } from "./config.ts";
23
- 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";
24
24
  import { reportOf } from "./report.ts";
25
- import { grepCounts } from "./grep-output.testing.ts";
26
- import { parseFileHeader } from "./grep-output.ts";
25
+ const { grepCounts } = await import("./grep-output.testing.ts");
26
+ const { parseFileHeader } = await import("./grep-output.ts");
27
27
  import { parseHashline } from "./anchor-format.ts";
28
28
  import { expectToolFailure } from "./report-failure.testing.ts";
29
29
  import { RegExpParser } from "@eslint-community/regexpp";
30
- import { COMMON_RG_ARGS, LINE_LISTING_ARGS, type GrepBackend } from "./rg-process.ts";
31
- import { candidateArgs } from "./grep-candidates.ts";
32
- 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
+
33
34
  import { lineCandidatePatterns } from "./rg-regex.ts";
34
35
 
35
36
  type FakeOptions = {
@@ -51,14 +52,13 @@ async function withDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
51
52
  }
52
53
 
53
54
  function fakeBackend(options: FakeOptions = {}) {
54
- const calls: { kind: "paths" | "lines"; path: string; args: readonly string[] }[] = [];
55
+ const calls: { kind: "paths" | "lines"; args: readonly string[] }[] = [];
55
56
  const run = async (
56
57
  kind: "paths" | "lines",
57
- path: string,
58
58
  args: readonly string[],
59
59
  onPath: (file: string) => boolean | Promise<boolean>,
60
60
  ) => {
61
- calls.push({ kind, path, args });
61
+ calls.push({ kind, args });
62
62
  await options.onRun?.();
63
63
  if (options.error) throw options.error;
64
64
  for (const file of options.paths ?? []) {
@@ -70,10 +70,10 @@ function fakeBackend(options: FakeOptions = {}) {
70
70
  stopped: false,
71
71
  };
72
72
  };
73
- const backend: GrepBackend = {
74
- runRgPaths: (path, args, _signal, onPath) => run("paths", path, args, onPath),
75
- runRgLines: (path, args, _signal, _maxLines, onFile) =>
76
- run("lines", path, args, (file) => onFile(file, options.lines)),
73
+ const backend: MockRg = {
74
+ runRgPaths: (args, _signal, onPath) => run("paths", args, onPath),
75
+ runRgLines: (args, _signal, _maxLines, onFile) =>
76
+ run("lines", args, (file) => onFile(file, options.lines)),
77
77
  };
78
78
  return { backend, calls };
79
79
  }
@@ -85,14 +85,34 @@ const call = (tool: any, params: any, signal?: AbortSignal) =>
85
85
  test("explicit JavaScript flags → call rendering shows them", () => {
86
86
  initTheme("dark");
87
87
  const { backend } = fakeBackend();
88
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, backend);
89
- const rendered = tool.renderCall!({ pattern: "\\p{Letter}+", literal: false, flags: "u" }, theme)
88
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, backend);
89
+ const rendered = tool.renderCall!(
90
+ { pattern: ["\\p{Letter}+"], literal: false, flags: "u" },
91
+ theme,
92
+ )
90
93
  .render(120)
91
94
  .join("\n");
92
95
  assert.ok(rendered.includes("/\\p{Letter}+/u"));
93
96
  });
94
97
 
95
- test("configured defaults → descriptions, limits, and context use the registered values", async () =>
98
+ test("streamed grep strings and null fields → render the pattern and default path without a limit", () => {
99
+ initTheme("dark");
100
+ const { backend } = fakeBackend();
101
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, backend);
102
+ for (const pattern of ["needle", null]) {
103
+ const args: unknown = { pattern, literal: true, path: null, limit: null };
104
+ const rendered = tool
105
+ // Streaming arguments reach the renderer before Pi validates and coerces them.
106
+ .renderCall(args as Parameters<typeof tool.renderCall>[0], theme)
107
+ .render(120)
108
+ .join("\n");
109
+ assert.ok(rendered.includes(`/${pattern ?? ""}/`));
110
+ assert.ok(rendered.includes("in ."));
111
+ assert.doesNotMatch(rendered, /limit/);
112
+ }
113
+ });
114
+
115
+ test("configured defaults → descriptions, limits, and context use registered values", async () =>
96
116
  withDir(async (dir) => {
97
117
  const file = join(dir, "configured.txt");
98
118
  const lines = [
@@ -110,7 +130,7 @@ test("configured defaults → descriptions, limits, and context use the register
110
130
  ...DEFAULT_CONFIG,
111
131
  grep: { ...DEFAULT_CONFIG.grep, defaultLimit: 1, defaultContext: 2 },
112
132
  };
113
- const tool = makeGrepOverrideWithBackend(dir, config, fake.backend);
133
+ const tool = makeMockGrep(dir, config, fake.backend);
114
134
  for (const [field, expected] of [
115
135
  ["limit", 1],
116
136
  ["context", 2],
@@ -145,7 +165,7 @@ test("configured defaults → descriptions, limits, and context use the register
145
165
  test("grep limit accepts only positive integers", async () => {
146
166
  await withDir(async (dir) => {
147
167
  const fake = fakeBackend();
148
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
168
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
149
169
  const limitSchema = tool.parameters.properties.limit;
150
170
  assert.equal(limitSchema.type, "number");
151
171
  assert.equal("minimum" in limitSchema ? limitSchema.minimum : undefined, 1);
@@ -164,7 +184,7 @@ test("grep limit accepts only positive integers", async () => {
164
184
  test("grep schema rejects empty search inputs and fractional context", async () =>
165
185
  withDir(async (dir) => {
166
186
  const fake = fakeBackend();
167
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
187
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
168
188
  const invalidArgs = [
169
189
  { literal: true, pattern: "" },
170
190
  { literal: true, pattern: [] },
@@ -187,12 +207,12 @@ test("grep schema rejects empty search inputs and fractional context", async ()
187
207
 
188
208
  test("grep points wildcard paths to glob without changing ordinary missing-path errors", async () => {
189
209
  await withDir(async (dir) => {
190
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fakeBackend().backend);
210
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fakeBackend().backend);
191
211
  await expectToolFailure(
192
212
  call(tool, { literal: true, pattern: "value", path: "src/fusion-card*" }),
193
213
  "PATH_NOT_FOUND",
194
214
  (report) => {
195
- assert.equal(report.path, "src/fusion-card*");
215
+ assert.deepEqual(report.path, ["src/fusion-card*"]);
196
216
  assert.match(report.next ?? "", /directory.*path.*wildcard.*glob/);
197
217
  },
198
218
  );
@@ -200,33 +220,43 @@ test("grep points wildcard paths to glob without changing ordinary missing-path
200
220
  call(tool, { literal: true, pattern: "value", path: "src/missing" }),
201
221
  "PATH_NOT_FOUND",
202
222
  (report) => {
203
- assert.equal(report.path, "src/missing");
223
+ assert.deepEqual(report.path, ["src/missing"]);
204
224
  assert.equal(report.next, "Check the path.");
205
225
  },
206
226
  );
207
227
  });
208
228
  });
209
229
 
210
- test("one of multiple grep paths is missing → text identifies it without repeating call fields", async () =>
230
+ test("multiple grep paths are missing → reports all resolved paths and selects wildcard recovery", async () =>
211
231
  withDir(async (dir) => {
212
232
  await writeFile(join(dir, "present.txt"), "value\n");
213
- const path = ["present.txt", "missing.txt"];
214
- const fake = fakeBackend();
215
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
216
- const result = await call(tool, { literal: true, pattern: "value", path });
217
- assert.equal(result.isError, true);
218
- const block = result.content[0];
219
- assert.ok(block.type === "text");
220
- const facts = JSON.parse(block.text);
221
- assert.equal(facts.error, "PATH_NOT_FOUND");
222
- assert.equal(facts.missing, join(dir, "missing.txt"));
223
- assert.equal(Object.hasOwn(facts, "tool"), false);
224
- assert.equal(Object.hasOwn(facts, "path"), false);
225
- const report = reportOf(result, "grep");
226
- assert.equal(report?.tool, "grep");
227
- assert.deepEqual(report?.path, path);
228
- assert.equal(report?.missing, facts.missing);
229
- assert.equal(fake.calls.length, 0);
233
+ for (const [path, missing, wildcard] of [
234
+ [["missing.txt", "present.txt", "other.txt"], ["missing.txt", "other.txt"], false],
235
+ [["missing.txt", "present.txt", "other*.txt"], ["missing.txt", "other*.txt"], true],
236
+ [["missing?.txt", "present.txt", "other.txt"], ["missing?.txt", "other.txt"], true],
237
+ ] as const) {
238
+ const fake = fakeBackend();
239
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
240
+ const result = await call(tool, { literal: true, pattern: "value", path });
241
+ assert.equal(result.isError, true);
242
+ const block = result.content[0];
243
+ assert.ok(block.type === "text");
244
+ const facts = JSON.parse(block.text);
245
+ assert.equal(facts.error, "PATH_NOT_FOUND");
246
+ assert.deepEqual(
247
+ facts.missing,
248
+ missing.map((item) => join(dir, item)),
249
+ );
250
+ if (wildcard) assert.match(facts.next, /directory.*path.*wildcard.*glob/);
251
+ else assert.equal(facts.next, "Check the path.");
252
+ assert.equal(Object.hasOwn(facts, "tool"), false);
253
+ assert.equal(Object.hasOwn(facts, "path"), false);
254
+ const report = reportOf(result, "grep");
255
+ assert.equal(report?.tool, "grep");
256
+ assert.deepEqual(report?.path, path);
257
+ assert.deepEqual(report?.missing, facts.missing);
258
+ assert.equal(fake.calls.length, 0);
259
+ }
230
260
  }));
231
261
 
232
262
  test("matched files → full-line hash anchors", async () => {
@@ -237,7 +267,7 @@ test("matched files → full-line hash anchors", async () => {
237
267
  await writeFile(b, "alpha here\n");
238
268
  const fake = fakeBackend({ paths: [a, b] });
239
269
 
240
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
270
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
241
271
  assert.deepEqual(tool.parameters.required, ["pattern", "literal"]);
242
272
  const result = await call(tool, { literal: true, pattern: "alpha" });
243
273
  const output = text(result);
@@ -245,7 +275,6 @@ test("matched files → full-line hash anchors", async () => {
245
275
  assert.match(output, /b\.ts · 1 match/);
246
276
  assert.match(output, new RegExp(`1#${computeLineHash(1, "alpha beta", 4)}│alpha beta`));
247
277
  assert.match(output, /3#[0-9A-Z]+│alpha only/);
248
- assert.equal(fake.calls[0].path, rgPath);
249
278
  });
250
279
  });
251
280
 
@@ -271,7 +300,7 @@ test("grep payload blocks → only a single complete content or count block omit
271
300
  grepBytes: truncated ? truncatedBytes : DEFAULT_OUTPUT_BUDGETS.grepBytes,
272
301
  };
273
302
  const result = await callTool(
274
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend, () => budget),
303
+ makeMockGrep(dir, DEFAULT_CONFIG, backend, () => budget),
275
304
  {
276
305
  path: dir,
277
306
  pattern: "needle",
@@ -314,7 +343,7 @@ test("grep output truncates preview rows → reports only displayed preview fact
314
343
  const { backend } = fakeBackend({ paths });
315
344
  const args = { path: dir, pattern: "needle", literal: true };
316
345
  const full = await callTool(
317
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend, () => budget),
346
+ makeMockGrep(dir, DEFAULT_CONFIG, backend, () => budget),
318
347
  args,
319
348
  );
320
349
  const rows = text(full).split("\n");
@@ -323,7 +352,7 @@ test("grep output truncates preview rows → reports only displayed preview fact
323
352
  for (const keptLines of [headerIndex - 1, headerIndex + 1, headerIndex + 2, rows.length]) {
324
353
  const expected = rows.slice(0, keptLines).join("\n");
325
354
  const result = await callTool(
326
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend, () => ({
355
+ makeMockGrep(dir, DEFAULT_CONFIG, backend, () => ({
327
356
  ...budget,
328
357
  grepBytes: Buffer.byteLength(expected),
329
358
  })),
@@ -353,7 +382,7 @@ test(
353
382
  const path = join(dir, "outside.txt");
354
383
  await writeFile(path, "needle\n");
355
384
  const { backend } = fakeBackend({ paths: [path] });
356
- const result = await callTool(makeGrepOverrideWithBackend(cwd, DEFAULT_CONFIG, backend), {
385
+ const result = await callTool(makeMockGrep(cwd, DEFAULT_CONFIG, backend), {
357
386
  path,
358
387
  pattern: "needle",
359
388
  literal: true,
@@ -403,16 +432,13 @@ test("file changes after matching → summary modes retain the snapshot and cont
403
432
  },
404
433
  );
405
434
  const fake = fakeBackend({ paths });
406
- const result = await call(
407
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
408
- {
409
- pattern: "needle",
410
- literal: true,
411
- multiline,
412
- outputMode,
413
- context: 1,
414
- },
415
- );
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
+ });
416
442
  assert.equal(changed, true);
417
443
  if (outputMode !== "content") {
418
444
  assert.equal(result.isError, undefined);
@@ -467,7 +493,7 @@ test("excluded changed file → contributes no preview limit or recovery to comp
467
493
  },
468
494
  );
469
495
  const { backend } = fakeBackend({ paths });
470
- const result = await callTool(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend), {
496
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
471
497
  pattern: "needle",
472
498
  literal: true,
473
499
  outputMode: "content",
@@ -490,28 +516,24 @@ test("excluded changed file → contributes no preview limit or recovery to comp
490
516
  });
491
517
  });
492
518
 
493
- test("candidate selection → reports only whole-file candidate facts", async () =>
519
+ test("candidate selection → reports matches without internal strategy facts", async () =>
494
520
  withDir(async (dir) => {
495
521
  const file = join(dir, "input.txt");
496
522
  await writeFile(file, "abc \nneedle");
497
- for (const [pattern, multiline, candidates] of [
498
- ["needle", false, undefined],
499
- ["needle", true, "files"],
500
- ["[^x\\s]{3}\\s", true, "all"],
523
+ for (const [pattern, multiline] of [
524
+ ["needle", false],
525
+ ["needle", true],
526
+ ["[^x\\s]{3}\\s", true],
501
527
  ] as const) {
502
528
  const fake = fakeBackend({ paths: [file] });
503
- const result = await callTool(
504
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
505
- {
506
- path: file,
507
- pattern,
508
- literal: false,
509
- multiline,
510
- },
511
- );
529
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
530
+ path: file,
531
+ pattern,
532
+ literal: false,
533
+ multiline,
534
+ });
512
535
  assert.equal(result.isError, undefined);
513
536
  assert.equal(grepCounts(result).matches, 1);
514
- assert.equal(reportOf(result, "grep")?.candidates, candidates);
515
537
  assert.equal(reportOf(result, "grep")?.scanLimit, undefined);
516
538
  assert.equal(fake.calls[0].kind, multiline ? "paths" : "lines");
517
539
  }
@@ -526,7 +548,7 @@ test("grep in a subdirectory returns a path that edits the matching file", async
526
548
  await writeFile(rootFile, original);
527
549
  await writeFile(matchedFile, original);
528
550
  const fake = fakeBackend({ paths: [matchedFile] });
529
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
551
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
530
552
  literal: true,
531
553
  pattern: "status",
532
554
  path: "src",
@@ -539,11 +561,11 @@ test("grep in a subdirectory returns a path that edits the matching file", async
539
561
  const edit: any = makeEditOverride(dir, DEFAULT_CONFIG);
540
562
  await call(edit, {
541
563
  path: displayPath,
542
- edits: [
564
+ steps: [
543
565
  {
544
566
  action: "replace",
545
567
  anchor: contextAnchor,
546
- body: ["export const context = 2;"],
568
+ lines: ["export const context = 2;"],
547
569
  },
548
570
  ],
549
571
  });
@@ -564,7 +586,7 @@ test("context preserves logical CRLF anchors around a matched line", async () =>
564
586
  );
565
587
  const fake = fakeBackend({ paths: [file] });
566
588
 
567
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
589
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
568
590
  const contextSchema: any = tool.parameters.properties.context;
569
591
  assert.equal(contextSchema.type, "number");
570
592
  assert.equal(contextSchema.minimum, 0);
@@ -591,7 +613,7 @@ test("scope filters and output modes → confirmed files and counts are preserve
591
613
  await writeFile(b, "foo a.b\n");
592
614
  const fake = fakeBackend({ paths: [a, b] });
593
615
 
594
- const files = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
616
+ const files = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
595
617
  pattern: ["Foo", "a.b"],
596
618
  path: ["a.ts", "b.ts"],
597
619
  glob: ["*.ts", "!**/*.test.ts"],
@@ -604,7 +626,7 @@ test("scope filters and output modes → confirmed files and counts are preserve
604
626
  );
605
627
  assert.deepEqual(fake.calls.at(-1)?.args.slice(-2), [a, b]);
606
628
 
607
- const count = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
629
+ const count = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
608
630
  literal: true,
609
631
  pattern: "foo",
610
632
  outputMode: "count",
@@ -624,8 +646,8 @@ for (const diagnosticLineCount of [0, 80]) {
624
646
  "error: missing runtime library",
625
647
  ].join("\n");
626
648
  const fake = fakeBackend({ code: 2, stderr: diagnostic });
627
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, fake.backend);
628
- const args = { pattern: "(?<=a+)b", literal: false };
649
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, fake.backend);
650
+ const args = { pattern: ["(?<=a+)b"], literal: false };
629
651
  const failure: Awaited<ReturnType<typeof tool.execute>> = await callTool(tool, args);
630
652
  assert.equal(failure.isError, true);
631
653
  const errorText = failure.content
@@ -674,7 +696,7 @@ for (const diagnosticLineCount of [0, 80]) {
674
696
  }
675
697
 
676
698
  test("aligns TUI line numbers across files to the widest result", () => {
677
- const tool = makeGrepOverrideWithBackend(process.cwd(), DEFAULT_CONFIG, fakeBackend().backend);
699
+ const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, fakeBackend().backend);
678
700
  const raw = [
679
701
  "a.ts · 2 matches",
680
702
  "99#ABCD│ alpha",
@@ -705,7 +727,7 @@ test("matching rows exceed limit → bounded results offer optional continuation
705
727
  const fake = fakeBackend({ paths: [file] });
706
728
 
707
729
  const limit = 1;
708
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
730
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
709
731
  literal: true,
710
732
  pattern: "alpha",
711
733
  limit,
@@ -724,7 +746,7 @@ test("literal punctuation → exact text is matched", async () =>
724
746
  const file = join(dir, "literal.txt");
725
747
  await writeFile(file, "foo(0)\n");
726
748
  const fake = fakeBackend({ paths: [file] });
727
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
749
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
728
750
  const result = await call(tool, { pattern: "foo(0)", literal: true });
729
751
  assert.match(text(result), /1#[0-9A-Z]+│foo\(0\)/);
730
752
  assert.equal(fake.calls.length, 1);
@@ -734,7 +756,7 @@ test("literal pipe patterns find no match → alternatives recovery preserves li
734
756
  withDir(async (dir) => {
735
757
  const path = join(dir, "pipe.txt");
736
758
  const { backend } = fakeBackend({ paths: [path] });
737
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend);
759
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, backend);
738
760
  for (const { pattern, literal, source, matches, literalPipe } of [
739
761
  { pattern: "foo|bar", literal: true, source: "foo\nbar\n", matches: 0, literalPipe: true },
740
762
  {
@@ -766,7 +788,7 @@ test("literal pipe patterns find no match → alternatives recovery preserves li
766
788
  if (literalPipe) {
767
789
  assert.match(
768
790
  report.next ?? "",
769
- /if you meant alternatives.*pattern array.*otherwise.*literal matching/i,
791
+ /if you meant alternatives.*each as its own pattern item.*otherwise.*literal matching/i,
770
792
  context,
771
793
  );
772
794
  } else {
@@ -777,24 +799,32 @@ test("literal pipe patterns find no match → alternatives recovery preserves li
777
799
 
778
800
  test("invalid JavaScript → its field rejects before file discovery", async () =>
779
801
  withDir(async (dir) => {
780
- for (const value of ["(", "(?m)^foo", "(?i)abc"]) {
781
- for (const pattern of [value, ["plain", value]]) {
782
- const fake = fakeBackend();
783
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
784
- const field = typeof pattern === "string" ? "pattern" : "pattern[1]";
785
- await assert.rejects(
786
- call(tool, { pattern, literal: false }),
787
- rejectsArgument(field, /Invalid regular expression/),
788
- );
789
- assert.equal(fake.calls.length, 0);
790
- }
802
+ for (const [pattern, flags, field] of [
803
+ ["(", undefined, "pattern[0]"],
804
+ [["plain", "("], undefined, "pattern[1]"],
805
+ ["(?m)^foo", undefined, "pattern[0]"],
806
+ [["plain", "(?m)^foo"], undefined, "pattern[1]"],
807
+ ["(?i)abc", undefined, "pattern[0]"],
808
+ [["plain", "(?i)abc"], undefined, "pattern[1]"],
809
+ ["\\p{NotAProperty}", "u", "pattern[0]"],
810
+ ["queueTool(", undefined, "pattern[0]"],
811
+ [["queueTool(", "\\bfoo\\b"], undefined, "pattern[0]"],
812
+ ["*", undefined, "pattern[0]"],
813
+ ] as const) {
814
+ const fake = fakeBackend();
815
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
816
+ await assert.rejects(
817
+ call(tool, { path: "missing.txt", pattern, literal: false, flags }),
818
+ rejectsArgument(field, /Invalid regular expression/),
819
+ );
820
+ assert.equal(fake.calls.length, 0);
791
821
  }
792
822
  }));
793
823
 
794
824
  test("grep OR arrays accept more than sixteen patterns in one line scan", async () => {
795
825
  await withDir(async (dir) => {
796
826
  const fake = fakeBackend();
797
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
827
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
798
828
  const patterns = Array.from({ length: 17 }, (_, index) => `pattern${index}`);
799
829
  assert.equal(
800
830
  reportOf(await call(tool, { literal: true, pattern: patterns }), "grep")?.matches,
@@ -807,7 +837,7 @@ test("grep OR arrays accept more than sixteen patterns in one line scan", async
807
837
  test("character classes, literals, and empty-line searches → valid nonempty patterns", async () => {
808
838
  await withDir(async (dir) => {
809
839
  const fake = fakeBackend();
810
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
840
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
811
841
  for (const pattern of ["[\\w.*]*", "^[\\w.*]+$", "[\\w.*]?"]) {
812
842
  assert.equal(reportOf(await call(tool, { pattern, literal: false }), "grep")?.matches, 0);
813
843
  }
@@ -821,7 +851,7 @@ test("character classes, literals, and empty-line searches → valid nonempty pa
821
851
  test("grep accepts nonempty whitespace literals", async () => {
822
852
  await withDir(async (dir) => {
823
853
  const fake = fakeBackend();
824
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
854
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
825
855
  for (const pattern of [" ", "\t", ["word", " "]]) {
826
856
  assert.equal(reportOf(await call(tool, { pattern, literal: true }), "grep")?.matches, 0);
827
857
  }
@@ -832,7 +862,7 @@ test("grep accepts nonempty whitespace literals", async () => {
832
862
  test("reports empty output and ripgrep execution failures", async () => {
833
863
  await withDir(async (dir) => {
834
864
  const empty = fakeBackend({ code: 1 });
835
- const noMatches = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, empty.backend), {
865
+ const noMatches = await call(makeMockGrep(dir, DEFAULT_CONFIG, empty.backend), {
836
866
  literal: true,
837
867
  pattern: "missing",
838
868
  });
@@ -842,7 +872,7 @@ test("reports empty output and ripgrep execution failures", async () => {
842
872
 
843
873
  const failed = fakeBackend({ code: 2, stderr: "bad regex" });
844
874
  await expectToolFailure(
845
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, failed.backend), {
875
+ call(makeMockGrep(dir, DEFAULT_CONFIG, failed.backend), {
846
876
  pattern: "x",
847
877
  literal: false,
848
878
  }),
@@ -854,7 +884,7 @@ test("reports empty output and ripgrep execution failures", async () => {
854
884
 
855
885
  const rejected = fakeBackend({ error: new Error("spawn failed") });
856
886
  await expectToolFailure(
857
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, rejected.backend), {
887
+ call(makeMockGrep(dir, DEFAULT_CONFIG, rejected.backend), {
858
888
  literal: true,
859
889
  pattern: "x",
860
890
  }),
@@ -873,7 +903,7 @@ test("rejects calls aborted before or during rg execution", async () => {
873
903
  first.abort();
874
904
  await expectToolFailure(
875
905
  call(
876
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, alreadyAborted.backend),
906
+ makeMockGrep(dir, DEFAULT_CONFIG, alreadyAborted.backend),
877
907
  { literal: true, pattern: ["x", "y"] },
878
908
  first.signal,
879
909
  ),
@@ -884,7 +914,7 @@ test("rejects calls aborted before or during rg execution", async () => {
884
914
  const interrupted = fakeBackend({ onRun: () => controller.abort() });
885
915
  await expectToolFailure(
886
916
  call(
887
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, interrupted.backend),
917
+ makeMockGrep(dir, DEFAULT_CONFIG, interrupted.backend),
888
918
  { literal: true, pattern: ["x", "y"] },
889
919
  controller.signal,
890
920
  ),
@@ -898,7 +928,7 @@ test("overlapping OR patterns → each matched line counts once", async () => {
898
928
  const file = join(dir, "fixture.ts");
899
929
  await writeFile(file, "foo bar\n".repeat(4097));
900
930
  const fake = fakeBackend({ paths: [file] });
901
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
931
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
902
932
  pattern: ["foo", "bar"],
903
933
  literal: true,
904
934
  outputMode: "count",
@@ -915,7 +945,7 @@ test("long matching lines → counts do not depend on content previews", async (
915
945
  const line = `foo${"x".repeat(600_000)}\n`;
916
946
  await writeFile(file, line.repeat(3));
917
947
  const fake = fakeBackend({ paths: [file] });
918
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
948
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
919
949
  pattern: "foo",
920
950
  literal: true,
921
951
  outputMode: "count",
@@ -933,7 +963,7 @@ test("grep previews invalid UTF-8 without anchors and skips NUL hits in every mo
933
963
  const fake = fakeBackend({
934
964
  paths: [invalid],
935
965
  });
936
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
966
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
937
967
  literal: true,
938
968
  pattern: "a",
939
969
  path: invalid,
@@ -957,10 +987,13 @@ test("grep previews invalid UTF-8 without anchors and skips NUL hits in every mo
957
987
  { outputMode: "files", multiline: true },
958
988
  { outputMode: "count", multiline: true },
959
989
  ] as const) {
960
- const skipped = await call(
961
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, binaryBackend.backend),
962
- { literal: true, pattern: "a", path: binary, outputMode, multiline },
963
- );
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
+ });
964
997
  assert.equal(reportOf(skipped, "grep")?.matches, 0);
965
998
  assert.equal(skipped.isError, undefined);
966
999
  }
@@ -976,7 +1009,7 @@ test("candidate file disappears before reading → summary modes report incomple
976
1009
  const fake = fakeBackend({ paths: [file], onRun: () => rm(file) });
977
1010
  const backend = fake.backend;
978
1011
  await expectToolFailure(
979
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend), {
1012
+ call(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
980
1013
  literal: true,
981
1014
  pattern: "needle",
982
1015
  path: file,
@@ -984,7 +1017,7 @@ test("candidate file disappears before reading → summary modes report incomple
984
1017
  }),
985
1018
  "SEARCH_INCOMPLETE",
986
1019
  (report) => {
987
- assert.match(report.diagnostics ?? "", /Could not read .*listed\.txt: ENOENT/);
1020
+ assert.match(report.diagnostics ?? "", /listed\.txt: ENOENT/);
988
1021
  },
989
1022
  );
990
1023
  assert.equal(fake.calls.length, 1);
@@ -1005,7 +1038,7 @@ test("candidate listing reports errors → all output modes retain confirmed mat
1005
1038
  code: 2,
1006
1039
  stderr: "unreadable.txt: Permission denied",
1007
1040
  });
1008
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1041
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1009
1042
  literal: true,
1010
1043
  pattern: "needle",
1011
1044
  outputMode,
@@ -1021,7 +1054,7 @@ test("candidate listing reports errors → all output modes retain confirmed mat
1021
1054
  }
1022
1055
  const fake = fakeBackend({ code: 2, stderr: "Permission denied" });
1023
1056
  await expectToolFailure(
1024
- call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1057
+ call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1025
1058
  literal: true,
1026
1059
  pattern: "needle",
1027
1060
  }),
@@ -1041,7 +1074,7 @@ test("one candidate cannot be read → matches from other files remain available
1041
1074
  await writeFile(gone, "needle\n");
1042
1075
  const fake = fakeBackend({ paths: [good, gone], onRun: () => rm(gone) });
1043
1076
  const backend = fake.backend;
1044
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, backend), {
1077
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
1045
1078
  literal: true,
1046
1079
  pattern: "needle",
1047
1080
  });
@@ -1057,7 +1090,7 @@ for (const admitted of [2, 1, 0]) {
1057
1090
  await Promise.all(files.map((file) => writeFile(file, "needle\n")));
1058
1091
  const fake = fakeBackend({ paths: files.slice(0, admitted) });
1059
1092
  const result = await call(
1060
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {
1093
+ makeMockGrep(dir, DEFAULT_CONFIG, {
1061
1094
  ...fake.backend,
1062
1095
  runRgPaths: async (...args) => {
1063
1096
  const listing = await fake.backend.runRgPaths(...args);
@@ -1092,7 +1125,7 @@ test("concurrent file searches → all discovered matches remain present", async
1092
1125
  files.push(file);
1093
1126
  }
1094
1127
  const fake = fakeBackend({ paths: files });
1095
- const result = await call(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1128
+ const result = await call(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1096
1129
  literal: true,
1097
1130
  pattern: "match",
1098
1131
  });
@@ -1137,7 +1170,7 @@ test("scope inspection fails for access or traversal reasons → grep preserves
1137
1170
  syncBuiltinESMExports();
1138
1171
  try {
1139
1172
  const fake = fakeBackend();
1140
- const tool = makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend);
1173
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fake.backend);
1141
1174
  await expectToolFailure(
1142
1175
  callTool(tool, { path, pattern: "needle", literal: true }),
1143
1176
  "FILESYSTEM_ERROR",
@@ -1181,11 +1214,7 @@ test("invalid worker replies → the entire grep call fails", async (t) => {
1181
1214
  return emit.call(this, event, ...(event === "message" ? [{ result }] : args));
1182
1215
  },
1183
1216
  );
1184
- const tool = makeGrepOverrideWithBackend(
1185
- dir,
1186
- DEFAULT_CONFIG,
1187
- fakeBackend({ paths: [path] }).backend,
1188
- );
1217
+ const tool = makeMockGrep(dir, DEFAULT_CONFIG, fakeBackend({ paths: [path] }).backend);
1189
1218
  await expectToolFailure(
1190
1219
  callTool(tool, { pattern: "^..$", literal: false, path }),
1191
1220
  "REGEX_WORKER_FAILED",
@@ -1202,7 +1231,7 @@ test("catastrophic worker evaluation → timeout and cancellation fail the searc
1202
1231
  const path = join(dir, "input.txt");
1203
1232
  await writeFile(path, `${"a".repeat(100)}!`);
1204
1233
  const config = { ...DEFAULT_CONFIG, grep: { ...DEFAULT_CONFIG.grep, regexTimeoutMs: 3_000 } };
1205
- const tool = makeGrepOverrideWithBackend(dir, config, fakeBackend({ paths: [path] }).backend);
1234
+ const tool = makeMockGrep(dir, config, fakeBackend({ paths: [path] }).backend);
1206
1235
  const params = { path, pattern: "(?=.)^(a+)+$", literal: false };
1207
1236
  await expectToolFailure(callTool(tool, params), "REGEX_TIMEOUT", (report) =>
1208
1237
  assert.equal(report.timeoutMs, config.grep.regexTimeoutMs),
@@ -1238,10 +1267,7 @@ test("non-multiline or multiline query → use line candidates or the file prefi
1238
1267
  multiline,
1239
1268
  ignoreCase: false,
1240
1269
  };
1241
- const result = await callTool(
1242
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
1243
- params,
1244
- );
1270
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), params);
1245
1271
  assert.equal(grepCounts(result).matches, 2);
1246
1272
  assert.equal(fake.calls.length, 1);
1247
1273
  assert.equal(fake.calls[0].kind, multiline ? "paths" : "lines");
@@ -1249,7 +1275,7 @@ test("non-multiline or multiline query → use line candidates or the file prefi
1249
1275
  const candidates = lineCandidatePatterns(query);
1250
1276
  assert.ok(candidates);
1251
1277
  const prefix = multiline
1252
- ? [...candidateArgs(extractPrefilter(query)), "--null"]
1278
+ ? [...(await fileCandidateArgs(query)), "--null"]
1253
1279
  : [
1254
1280
  ...COMMON_RG_ARGS,
1255
1281
  "--engine=default",
@@ -1284,14 +1310,11 @@ test("line discovery status and emitted files → fallback only for code 2 befor
1284
1310
  [2, [file], ["lines"]],
1285
1311
  ] as const) {
1286
1312
  const fake = fakeBackend({ code, paths: [...paths], lines: [1] });
1287
- const result = await callTool(
1288
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
1289
- {
1290
- path: dir,
1291
- pattern: "needle",
1292
- literal: true,
1293
- },
1294
- );
1313
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1314
+ path: dir,
1315
+ pattern: "needle",
1316
+ literal: true,
1317
+ });
1295
1318
  assert.deepEqual(
1296
1319
  fake.calls.map(({ kind }) => kind),
1297
1320
  kinds,
@@ -1307,21 +1330,18 @@ test("sparse, dense, or overflowed candidate lines → matching preserves origin
1307
1330
  await writeFile(file, "miss\r\nneedle\r\nmiss\nmiss\nneedle\r");
1308
1331
  for (const lines of [[2, 5], [1, 2, 4, 5], undefined]) {
1309
1332
  const fake = fakeBackend({ paths: [file], lines });
1310
- const result = await callTool(
1311
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend),
1312
- {
1313
- path: file,
1314
- pattern: "needle",
1315
- literal: true,
1316
- context: 0,
1317
- },
1318
- );
1333
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1334
+ path: file,
1335
+ pattern: "needle",
1336
+ literal: true,
1337
+ context: 0,
1338
+ });
1319
1339
  assert.equal(grepCounts(result).matches, 2);
1320
1340
  assert.match(text(result), /2#[0-9A-Z]+│needle/);
1321
1341
  assert.match(text(result), /5#[0-9A-Z]+│needle␍/);
1322
1342
  }
1323
1343
  const fake = fakeBackend({ paths: [file], lines: [2, 5] });
1324
- const result = await callTool(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1344
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1325
1345
  path: file,
1326
1346
  pattern: "\\r$",
1327
1347
  literal: false,
@@ -1339,7 +1359,7 @@ test("native-valid pattern exceeds parser limits → use the all-file prefilter"
1339
1359
  throw new RangeError("parser stack limit");
1340
1360
  });
1341
1361
  const fake = fakeBackend({ paths: [file] });
1342
- const result = await callTool(makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, fake.backend), {
1362
+ const result = await callTool(makeMockGrep(dir, DEFAULT_CONFIG, fake.backend), {
1343
1363
  path: file,
1344
1364
  pattern: "a",
1345
1365
  literal: false,
@@ -1351,7 +1371,8 @@ test("native-valid pattern exceeds parser limits → use the all-file prefilter"
1351
1371
  ["paths"],
1352
1372
  );
1353
1373
  assert.deepEqual(fake.calls[0].args, [
1354
- ...candidateArgs({ kind: "all" }),
1374
+ ...COMMON_RG_ARGS,
1375
+ "--files",
1355
1376
  "--null",
1356
1377
  "--hidden",
1357
1378
  "--glob",
@@ -1368,7 +1389,7 @@ test("rg rejects line patterns before listing files → successful file fallback
1368
1389
  const lines = fakeBackend({ code: 2, stderr: "regex too large" });
1369
1390
  const paths = fakeBackend({ paths: [file] });
1370
1391
  const result = await callTool(
1371
- makeGrepOverrideWithBackend(dir, DEFAULT_CONFIG, {
1392
+ makeMockGrep(dir, DEFAULT_CONFIG, {
1372
1393
  runRgLines: lines.backend.runRgLines,
1373
1394
  runRgPaths: paths.backend.runRgPaths,
1374
1395
  }),