@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.
- package/README.md +12 -12
- package/README.zh-CN.md +12 -12
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +96 -271
- package/src/core/apply.ts +62 -169
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +5 -5
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +8 -44
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +4 -7
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -19
- package/src/integration/grep-js-completeness.test.ts +45 -18
- package/src/integration/grep-line-candidates.test.ts +7 -10
- package/src/integration/grep-matrix.test.ts +6 -9
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +10 -9
- package/src/integration/grep-prefilter-coverage.test.ts +5 -8
- package/src/integration/grep-process-limits.test.ts +76 -0
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +166 -66
- package/src/integration/grep-scan-budget.test.ts +9 -9
- package/src/integration/grep-translation.test.ts +18 -32
- package/src/integration/large-text.test.ts +6 -52
- package/src/integration/model-budget-lifecycle.test.ts +10 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +161 -83
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +22 -12
- package/src/integration/report-replay.test.ts +23 -26
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +18 -17
- package/src/pi/action-fusion.test.ts +241 -353
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +150 -125
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +25 -28
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +334 -283
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +6 -8
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +7 -3
- package/src/pi/config.ts +12 -9
- package/src/pi/diagnostic-buffer.test.ts +34 -13
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +86 -211
- package/src/pi/error-text.ts +10 -9
- package/src/pi/execute.test.ts +249 -345
- package/src/pi/failure-context.test.ts +146 -127
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +182 -155
- package/src/pi/file-commit.test.ts +156 -71
- package/src/pi/file-commit.ts +126 -146
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +26 -22
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +19 -120
- package/src/pi/grep-candidates.ts +25 -76
- package/src/pi/grep-matrix.test.ts +5 -5
- package/src/pi/grep-order.test.ts +16 -15
- package/src/pi/grep-output.ts +94 -107
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +97 -0
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +41 -43
- package/src/pi/grep-search.ts +27 -39
- package/src/pi/grep-tool.ts +63 -106
- package/src/pi/grep.test.ts +177 -156
- package/src/pi/model-budgets.test.ts +27 -24
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +52 -21
- package/src/pi/mutation-runner.ts +134 -74
- package/src/pi/output-budgets.test.ts +86 -42
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +18 -23
- package/src/pi/read.test.ts +22 -41
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +85 -51
- package/src/pi/render.test.ts +88 -59
- package/src/pi/render.ts +64 -65
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -94
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +53 -38
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +10 -3
- package/src/pi/report-schema.ts +251 -148
- package/src/pi/report.test.ts +215 -67
- package/src/pi/report.ts +50 -98
- package/src/pi/result-safety.test.ts +241 -247
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +53 -75
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +35 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +36 -71
- package/src/pi/write.test.ts +31 -34
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/testing/run-tests.ts +1 -1
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { makeMockGrep } from "../pi/grep-rg.testing.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Explicit integration coverage for the platform rg bundled by @vscode/ripgrep.
|
|
4
4
|
* This suite is excluded from the default test script.
|
|
@@ -21,21 +21,21 @@ import {
|
|
|
21
21
|
import { tmpdir } from "node:os";
|
|
22
22
|
import { dirname, join } from "node:path";
|
|
23
23
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
24
|
-
import { rgPath } from "@vscode/ripgrep";
|
|
25
24
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import { COMMON_RG_ARGS,
|
|
32
|
-
|
|
25
|
+
|
|
26
|
+
const { makeEditOverride } = await import("../pi/tool-factories.testing.ts");
|
|
27
|
+
const { makeReadOverride } = await import("../pi/tool-factories.testing.ts");
|
|
28
|
+
const { makeWriteOverride } = await import("../pi/tool-factories.testing.ts");
|
|
29
|
+
const { makeReplaceTool } = await import("../pi/tool-factories.testing.ts");
|
|
30
|
+
import { COMMON_RG_ARGS, runRgPaths } from "../pi/rg-process.ts";
|
|
31
|
+
const { DEFAULT_OUTPUT_BUDGETS } = await import("../pi/tool-factories.testing.ts");
|
|
32
|
+
const MAX_RG_RECORD_BYTES = 16 * 1024 * 1024;
|
|
33
33
|
import { computeLineHash } from "../core/hash.ts";
|
|
34
34
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
35
|
-
|
|
35
|
+
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
36
36
|
import { canonicalPath } from "../pi/path.ts";
|
|
37
37
|
import { reportOf } from "../pi/report.ts";
|
|
38
|
-
|
|
38
|
+
const { grepCounts } = await import("../pi/grep-output.testing.ts");
|
|
39
39
|
import { hostCompiles, unsupportedByHost } from "../testing/regex-host.testing.ts";
|
|
40
40
|
|
|
41
41
|
const invoke = (
|
|
@@ -52,7 +52,7 @@ test("real rg emits anchored matches from a temporary directory", async () => {
|
|
|
52
52
|
try {
|
|
53
53
|
const file = join(directory, "fixture.ts");
|
|
54
54
|
await writeFile(file, "needle\nother\n");
|
|
55
|
-
const tool =
|
|
55
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
56
56
|
|
|
57
57
|
for (const pattern of ["needle", ["needle"]]) {
|
|
58
58
|
const result: any = await invoke(tool, "0", { pattern, literal: true }, undefined, undefined);
|
|
@@ -69,7 +69,7 @@ test("real rg finds whitespace-only literal queries and OR alternatives", async
|
|
|
69
69
|
try {
|
|
70
70
|
const file = join(directory, "fixture.txt");
|
|
71
71
|
await writeFile(file, "plain word\nfirst\tsecond\nboth \tforms\n");
|
|
72
|
-
const tool =
|
|
72
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
73
73
|
for (const { pattern, expected } of [
|
|
74
74
|
{ pattern: " ", expected: 2 },
|
|
75
75
|
{ pattern: "\t", expected: 2 },
|
|
@@ -103,7 +103,7 @@ test("real rg uses smart-case across OR patterns and Unicode matches", async ()
|
|
|
103
103
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-case-"));
|
|
104
104
|
try {
|
|
105
105
|
await writeFile(join(directory, "fixture.ts"), "FOO abc\nfoo BAR\nfoo bar\nK zip\nk zip\n");
|
|
106
|
-
const tool =
|
|
106
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
107
107
|
const lower = await invoke(
|
|
108
108
|
tool,
|
|
109
109
|
"0",
|
|
@@ -136,7 +136,7 @@ test("explicit ignoreCase overrides smart-case for regex and literal queries", a
|
|
|
136
136
|
try {
|
|
137
137
|
const file = join(directory, "fixture.txt");
|
|
138
138
|
await writeFile(file, "FOO\nfoo\n");
|
|
139
|
-
const tool =
|
|
139
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
140
140
|
const sensitive = await invoke(
|
|
141
141
|
tool,
|
|
142
142
|
"0",
|
|
@@ -195,7 +195,7 @@ test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
|
|
|
195
195
|
);
|
|
196
196
|
await writeFile(join(directory, "fixture.ts"), "FOO\nfoo\nbar\n");
|
|
197
197
|
process.env.RIPGREP_CONFIG_PATH = config;
|
|
198
|
-
const tool =
|
|
198
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
199
199
|
const result: any = await invoke(
|
|
200
200
|
tool,
|
|
201
201
|
"0",
|
|
@@ -232,7 +232,7 @@ test("real rg separates exact text from regex", async () => {
|
|
|
232
232
|
join(directory, "fixture.ts"),
|
|
233
233
|
"FOO\nfoo\nfoo0\nfoo(0)\nqueueTool(\nfoo(?=bar)\n",
|
|
234
234
|
);
|
|
235
|
-
const tool =
|
|
235
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
236
236
|
for (const pattern of ["(?i:^foo$)", "(?<name>foo)$"].filter((source) =>
|
|
237
237
|
hostCompiles(source),
|
|
238
238
|
)) {
|
|
@@ -249,14 +249,6 @@ test("real rg separates exact text from regex", async () => {
|
|
|
249
249
|
const missing = await invoke(tool, "no-match", { pattern: "missing(", literal: true });
|
|
250
250
|
assert.equal(grepCounts(missing).matches, 0);
|
|
251
251
|
assert.equal(missing.isError, undefined);
|
|
252
|
-
await assert.rejects(
|
|
253
|
-
invoke(tool, "invalid-regex", { pattern: "queueTool(", literal: false }),
|
|
254
|
-
rejectsArgument("pattern", /Invalid regular expression/),
|
|
255
|
-
);
|
|
256
|
-
await assert.rejects(
|
|
257
|
-
invoke(tool, "invalid-array", { pattern: ["queueTool(", "\\bfoo\\b"], literal: false }),
|
|
258
|
-
rejectsArgument("pattern[0]", /Invalid regular expression/),
|
|
259
|
-
);
|
|
260
252
|
} finally {
|
|
261
253
|
await rm(directory, { recursive: true, force: true });
|
|
262
254
|
}
|
|
@@ -266,7 +258,7 @@ test("real rg keeps CRLF line-end anchors with regex OR matching", async () => {
|
|
|
266
258
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-crlf-"));
|
|
267
259
|
try {
|
|
268
260
|
await writeFile(join(directory, "fixture.ts"), "alpha beta drop\r\nalpha beta\r\nalpha only");
|
|
269
|
-
const tool =
|
|
261
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
270
262
|
const ending = await invoke(
|
|
271
263
|
tool,
|
|
272
264
|
"0",
|
|
@@ -297,7 +289,7 @@ test("real rg finds a late OR match and respects the line limit", async () => {
|
|
|
297
289
|
join(directory, "fixture.ts"),
|
|
298
290
|
"foo skip\n".repeat(4096) + "foo keep\nfoo keep later\n",
|
|
299
291
|
);
|
|
300
|
-
const tool =
|
|
292
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
301
293
|
const result = await invoke(
|
|
302
294
|
tool,
|
|
303
295
|
"0",
|
|
@@ -319,9 +311,14 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
319
311
|
const spawn = childProcess.spawn;
|
|
320
312
|
const children: ReturnType<typeof spawn>[] = [];
|
|
321
313
|
const closed = new Set<ReturnType<typeof spawn>>();
|
|
314
|
+
let missingExecutable = false;
|
|
322
315
|
try {
|
|
323
316
|
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) => {
|
|
324
|
-
const child = spawn(
|
|
317
|
+
const child = spawn(
|
|
318
|
+
missingExecutable ? join(directory, "missing-rg") : process.execPath,
|
|
319
|
+
args[1],
|
|
320
|
+
args[2],
|
|
321
|
+
);
|
|
325
322
|
children.push(child);
|
|
326
323
|
child.once("close", () => closed.add(child));
|
|
327
324
|
return child;
|
|
@@ -341,7 +338,6 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
341
338
|
const consumed: string[] = [];
|
|
342
339
|
let aliveAtCallback = false;
|
|
343
340
|
const run = runRgPaths(
|
|
344
|
-
process.execPath,
|
|
345
341
|
args,
|
|
346
342
|
AbortSignal.any([controller.signal, AbortSignal.timeout(processTimeoutMs)]),
|
|
347
343
|
(path) => {
|
|
@@ -362,8 +358,9 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
362
358
|
assert.ok(child && closed.has(child), "runner must await child close");
|
|
363
359
|
assert.ok(child.exitCode !== null || child.signalCode !== null);
|
|
364
360
|
}
|
|
361
|
+
missingExecutable = true;
|
|
365
362
|
await assert.rejects(
|
|
366
|
-
runRgPaths(
|
|
363
|
+
runRgPaths([], undefined, () => true),
|
|
367
364
|
/Failed to run ripgrep/,
|
|
368
365
|
);
|
|
369
366
|
} finally {
|
|
@@ -380,7 +377,7 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
380
377
|
await writeFile(join(directory, ".ignore"), "ignored.txt\n");
|
|
381
378
|
const ignored = join(directory, "ignored.txt");
|
|
382
379
|
await writeFile(ignored, "needle\n");
|
|
383
|
-
const tool =
|
|
380
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
384
381
|
const normal = await invoke(
|
|
385
382
|
tool,
|
|
386
383
|
"0",
|
|
@@ -420,6 +417,91 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
420
417
|
}
|
|
421
418
|
});
|
|
422
419
|
|
|
420
|
+
test("gitignored directory → root traversal skips it and an explicit directory path searches it", async (t) => {
|
|
421
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-ignore-scope-"));
|
|
422
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
423
|
+
const ignored = join(directory, "ignored");
|
|
424
|
+
await mkdir(join(directory, ".git"));
|
|
425
|
+
await mkdir(ignored);
|
|
426
|
+
await writeFile(join(directory, ".gitignore"), "ignored/\n");
|
|
427
|
+
await writeFile(join(ignored, "x.txt"), "needle\n");
|
|
428
|
+
await writeFile(join(directory, "a.txt"), "needle\n");
|
|
429
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
430
|
+
for (const [path, expected] of [
|
|
431
|
+
[directory, "a.txt"],
|
|
432
|
+
[ignored, "ignored/x.txt"],
|
|
433
|
+
]) {
|
|
434
|
+
const result = await callTool(tool, {
|
|
435
|
+
path,
|
|
436
|
+
literal: true,
|
|
437
|
+
pattern: "needle",
|
|
438
|
+
outputMode: "files",
|
|
439
|
+
});
|
|
440
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
441
|
+
assert.equal(grepCounts(result).matches, 1);
|
|
442
|
+
assert.equal(result.content[0].type, "text");
|
|
443
|
+
assert.equal(result.content[0].text.replace(/\\/g, "/"), expected);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test("named directory → nested ignores, .git and links still limit traversal", async (t) => {
|
|
448
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-nested-scope-"));
|
|
449
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
450
|
+
await mkdir(join(directory, ".git"));
|
|
451
|
+
await writeFile(join(directory, ".gitignore"), "node_modules/\ndist/\n*.map\n");
|
|
452
|
+
for (const file of [
|
|
453
|
+
"node_modules/foo/index.js",
|
|
454
|
+
"node_modules/foo/dist/bundle.js",
|
|
455
|
+
"node_modules/foo/index.js.map",
|
|
456
|
+
"named/index.js",
|
|
457
|
+
"named/nested/.git/config",
|
|
458
|
+
"target/linked.js",
|
|
459
|
+
]) {
|
|
460
|
+
await mkdir(dirname(join(directory, file)), { recursive: true });
|
|
461
|
+
await writeFile(join(directory, file), "needle\n");
|
|
462
|
+
}
|
|
463
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
464
|
+
for (const { path, expected, linked } of [
|
|
465
|
+
{ path: "node_modules/foo", expected: "node_modules/foo/index.js" },
|
|
466
|
+
{ path: "node_modules/foo/dist", expected: "node_modules/foo/dist/bundle.js" },
|
|
467
|
+
{ path: "node_modules/foo/index.js.map", expected: "node_modules/foo/index.js.map" },
|
|
468
|
+
{ path: "named", expected: "named/index.js" },
|
|
469
|
+
{ path: "named", expected: "named/index.js", linked: true },
|
|
470
|
+
]) {
|
|
471
|
+
await t.test(`${path}${linked ? " with nested link" : ""}`, async (t) => {
|
|
472
|
+
if (linked) {
|
|
473
|
+
try {
|
|
474
|
+
await symlink(
|
|
475
|
+
join(directory, "target"),
|
|
476
|
+
join(directory, "named/nested/link"),
|
|
477
|
+
process.platform === "win32" ? "junction" : "dir",
|
|
478
|
+
);
|
|
479
|
+
} catch (error) {
|
|
480
|
+
if (
|
|
481
|
+
error instanceof Error &&
|
|
482
|
+
"code" in error &&
|
|
483
|
+
["EPERM", "EACCES", "ENOTSUP"].includes(String(error.code))
|
|
484
|
+
) {
|
|
485
|
+
t.skip("symbolic link creation unavailable");
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const result = await callTool(tool, {
|
|
492
|
+
path: [path],
|
|
493
|
+
literal: true,
|
|
494
|
+
pattern: ["needle"],
|
|
495
|
+
outputMode: "files",
|
|
496
|
+
});
|
|
497
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
498
|
+
assert.equal(grepCounts(result).matches, 1);
|
|
499
|
+
assert.equal(result.content[0].type, "text");
|
|
500
|
+
assert.equal(result.content[0].text.replace(/\\/g, "/"), expected);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
423
505
|
test("directory traversal with caller globs → excludes .git while an explicit .git path remains searchable", async (t) => {
|
|
424
506
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-git-scope-"));
|
|
425
507
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
@@ -427,7 +509,7 @@ test("directory traversal with caller globs → excludes .git while an explicit
|
|
|
427
509
|
await mkdir(git);
|
|
428
510
|
await writeFile(join(git, "x.txt"), "needle\n");
|
|
429
511
|
await writeFile(join(directory, "a.txt"), "needle\n");
|
|
430
|
-
const tool =
|
|
512
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
431
513
|
for (const multiline of [false, true]) {
|
|
432
514
|
for (const glob of [undefined, "*"]) {
|
|
433
515
|
for (const [path, expected] of [
|
|
@@ -468,7 +550,7 @@ test("explicit file with different case and a glob → admits the same file on a
|
|
|
468
550
|
const original = await stat(file, { bigint: true });
|
|
469
551
|
assert.equal(alias.dev, original.dev);
|
|
470
552
|
assert.equal(alias.ino, original.ino);
|
|
471
|
-
const tool =
|
|
553
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
472
554
|
const result = await callTool(tool, {
|
|
473
555
|
path: requested,
|
|
474
556
|
glob: "*.txt",
|
|
@@ -507,7 +589,7 @@ test("explicit file with a dangling sibling link and a glob → returns complete
|
|
|
507
589
|
}
|
|
508
590
|
await assert.rejects(stat(link), { code: "ENOENT" });
|
|
509
591
|
let listingDiagnostics = "";
|
|
510
|
-
const tool =
|
|
592
|
+
const tool = makeMockGrep(directory, DEFAULT_CONFIG, {
|
|
511
593
|
runRgPaths: async (...args) => {
|
|
512
594
|
const listed = await runRgPaths(...args);
|
|
513
595
|
listingDiagnostics = listed.stderr;
|
|
@@ -534,7 +616,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
|
|
|
534
616
|
const ignored = join(directory, "ignored.ts");
|
|
535
617
|
await writeFile(join(directory, ".ignore"), "ignored.ts\n");
|
|
536
618
|
await Promise.all([kept, excluded, ignored].map((path) => writeFile(path, "needle\n")));
|
|
537
|
-
const tool =
|
|
619
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
538
620
|
const result: any = await invoke(
|
|
539
621
|
tool,
|
|
540
622
|
"0",
|
|
@@ -564,7 +646,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
|
|
|
564
646
|
}
|
|
565
647
|
});
|
|
566
648
|
|
|
567
|
-
test("directory traversal skips symlinks but
|
|
649
|
+
test("directory traversal skips symlinks but explicit linked directories and files remain searchable", async (t) => {
|
|
568
650
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-follow-"));
|
|
569
651
|
try {
|
|
570
652
|
const root = join(directory, "root");
|
|
@@ -583,7 +665,7 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
583
665
|
return t.skip("symbolic link creation unavailable");
|
|
584
666
|
throw error;
|
|
585
667
|
}
|
|
586
|
-
const grep =
|
|
668
|
+
const grep = makeGrepOverride(root, DEFAULT_CONFIG);
|
|
587
669
|
const hidden: any = await invoke(
|
|
588
670
|
grep,
|
|
589
671
|
"0",
|
|
@@ -592,6 +674,20 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
592
674
|
undefined,
|
|
593
675
|
);
|
|
594
676
|
assert.equal(grepCounts(hidden).matches, 0);
|
|
677
|
+
const linkedDirectory = await callTool(grep, {
|
|
678
|
+
path: link,
|
|
679
|
+
literal: true,
|
|
680
|
+
pattern: "needle",
|
|
681
|
+
outputMode: "files",
|
|
682
|
+
});
|
|
683
|
+
assert.equal(
|
|
684
|
+
linkedDirectory.isError,
|
|
685
|
+
undefined,
|
|
686
|
+
JSON.stringify(reportOf(linkedDirectory, "grep")),
|
|
687
|
+
);
|
|
688
|
+
assert.equal(grepCounts(linkedDirectory).matches, 1);
|
|
689
|
+
assert.equal(linkedDirectory.content[0].type, "text");
|
|
690
|
+
assert.equal(linkedDirectory.content[0].text.replace(/\\/g, "/"), "link/linked.txt");
|
|
595
691
|
const found: any = await invoke(
|
|
596
692
|
grep,
|
|
597
693
|
"0",
|
|
@@ -608,7 +704,7 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
608
704
|
await invoke(
|
|
609
705
|
edit,
|
|
610
706
|
"0",
|
|
611
|
-
{ path: resultPath,
|
|
707
|
+
{ path: resultPath, steps: [{ action: "replace", anchor, lines: ["updated"] }] },
|
|
612
708
|
undefined,
|
|
613
709
|
undefined,
|
|
614
710
|
);
|
|
@@ -625,7 +721,7 @@ test("unbounded lookbehind → native JS matches after rg discovery", async (t)
|
|
|
625
721
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-lookbehind-"));
|
|
626
722
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
627
723
|
await writeFile(join(directory, "fixture.txt"), "aaab\n");
|
|
628
|
-
const tool =
|
|
724
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
629
725
|
const result = await invoke(tool, "0", { pattern: "(?<=a+)b", literal: false });
|
|
630
726
|
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
631
727
|
assert.equal(grepCounts(result).matches, 1);
|
|
@@ -635,7 +731,7 @@ test("line-based grep uses context for display but never matches across CRLF", a
|
|
|
635
731
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-lines-"));
|
|
636
732
|
try {
|
|
637
733
|
await writeFile(join(directory, "fixture.txt"), "alpha\r\nbeta\r\ngamma\r\n");
|
|
638
|
-
const tool =
|
|
734
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
639
735
|
const context = await invoke(
|
|
640
736
|
tool,
|
|
641
737
|
"0",
|
|
@@ -674,7 +770,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
674
770
|
try {
|
|
675
771
|
const file = join(directory, "fixture.txt");
|
|
676
772
|
await writeFile(file, "alpha\r\nbeta\r\ngamma\r\n");
|
|
677
|
-
const tool =
|
|
773
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
678
774
|
const regex = await invoke(
|
|
679
775
|
tool,
|
|
680
776
|
"0",
|
|
@@ -749,7 +845,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
749
845
|
await invoke(
|
|
750
846
|
edit,
|
|
751
847
|
"0",
|
|
752
|
-
{ path: file,
|
|
848
|
+
{ path: file, steps: [{ action: "replace", anchor, lines: ["updated"] }] },
|
|
753
849
|
undefined,
|
|
754
850
|
undefined,
|
|
755
851
|
);
|
|
@@ -764,7 +860,7 @@ test("multiline grep preserves BOM and standalone CR while normalizing CRLF", as
|
|
|
764
860
|
try {
|
|
765
861
|
const file = join(directory, "fixture.txt");
|
|
766
862
|
await writeFile(file, "\uFEFFalpha\rsolo\r\nbeta\r\n");
|
|
767
|
-
const tool =
|
|
863
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
768
864
|
const result = await invoke(
|
|
769
865
|
tool,
|
|
770
866
|
"0",
|
|
@@ -793,7 +889,7 @@ test("multiline grep anchors empty lines and line-start zero-width matches", asy
|
|
|
793
889
|
try {
|
|
794
890
|
const file = join(directory, "fixture.txt");
|
|
795
891
|
await writeFile(file, "alpha\r\n\r\nbeta\r\n");
|
|
796
|
-
const tool =
|
|
892
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
797
893
|
const span = await invoke(
|
|
798
894
|
tool,
|
|
799
895
|
"0",
|
|
@@ -824,7 +920,7 @@ test("multiline zero-width EOF stays on the last existing physical line", {
|
|
|
824
920
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-multiline-eof-"));
|
|
825
921
|
try {
|
|
826
922
|
const file = join(directory, "fixture.txt");
|
|
827
|
-
const tool =
|
|
923
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
828
924
|
for (const content of ["last line", "last line\n"]) {
|
|
829
925
|
await writeFile(file, content);
|
|
830
926
|
const result = await invoke(
|
|
@@ -853,7 +949,7 @@ test("files and count modes aggregate only matching lines inside the limit", asy
|
|
|
853
949
|
const second = join(directory, "b.txt");
|
|
854
950
|
await writeFile(first, "needle needle\nneedle\n");
|
|
855
951
|
await writeFile(second, "needle\n");
|
|
856
|
-
const tool =
|
|
952
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
857
953
|
const query = { literal: true, pattern: "needle", path: [first, second], limit: 1 };
|
|
858
954
|
const files = await invoke(
|
|
859
955
|
tool,
|
|
@@ -900,7 +996,7 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
900
996
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-wildcard-"));
|
|
901
997
|
try {
|
|
902
998
|
await writeFile(join(directory, "fixture.txt"), "first\n\n.*\n");
|
|
903
|
-
const tool =
|
|
999
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
904
1000
|
for (const [pattern, expected] of [
|
|
905
1001
|
["[\\w.*]*", 3],
|
|
906
1002
|
["^[\\w.*]+$", 2],
|
|
@@ -933,10 +1029,6 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
933
1029
|
undefined,
|
|
934
1030
|
);
|
|
935
1031
|
assert.match(literal.content[0].text, /3#[0-9A-Z]+│\.\*/);
|
|
936
|
-
await assert.rejects(
|
|
937
|
-
invoke(tool, "invalid", { pattern: "*", literal: false }),
|
|
938
|
-
rejectsArgument("pattern", /Invalid regular expression/),
|
|
939
|
-
);
|
|
940
1032
|
} finally {
|
|
941
1033
|
await rm(directory, { recursive: true, force: true });
|
|
942
1034
|
}
|
|
@@ -963,7 +1055,7 @@ test("tools share physical lines and anchors across text representations", async
|
|
|
963
1055
|
});
|
|
964
1056
|
assert.equal(await readFile(file, "utf8"), before);
|
|
965
1057
|
const read = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
|
|
966
|
-
const grep = await call(
|
|
1058
|
+
const grep = await call(makeGrepOverride(directory, DEFAULT_CONFIG), {
|
|
967
1059
|
literal: true,
|
|
968
1060
|
path: file,
|
|
969
1061
|
pattern: "old",
|
|
@@ -974,7 +1066,7 @@ test("tools share physical lines and anchors across text representations", async
|
|
|
974
1066
|
const anchor = rows(grep)[1].split("│")[0];
|
|
975
1067
|
const edit = await call(makeEditOverride(directory, DEFAULT_CONFIG), {
|
|
976
1068
|
path: file,
|
|
977
|
-
|
|
1069
|
+
steps: [{ action: "replace", anchor, lines: ["new"] }],
|
|
978
1070
|
});
|
|
979
1071
|
assert.equal(await readFile(file, "utf8"), before.replace("old", "new"));
|
|
980
1072
|
assert.match(edit.details.diff, /^-2 old/m);
|
|
@@ -997,7 +1089,7 @@ test("long-line previews preserve full-line anchors across literal and JavaScrip
|
|
|
997
1089
|
const long = "😀界".repeat(220) + "NEEDLE" + "tail".repeat(200);
|
|
998
1090
|
const context = "x" + "😀".repeat(400);
|
|
999
1091
|
await writeFile(join(directory, "long.txt"), `${long}\r\nfollow\r\n${context}\r\n`);
|
|
1000
|
-
const tool =
|
|
1092
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1001
1093
|
for (const params of [
|
|
1002
1094
|
{ literal: true, pattern: "NEEDLE" },
|
|
1003
1095
|
{ pattern: ["NEEDLE", "tail"], literal: true },
|
|
@@ -1037,7 +1129,7 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
|
|
|
1037
1129
|
const before = "\uFEFFhead\r\nalpha\r\nbeta\nstand\rCR\r\r\nlast";
|
|
1038
1130
|
const write = makeWriteOverride(directory);
|
|
1039
1131
|
const read = makeReadOverride(directory, DEFAULT_CONFIG);
|
|
1040
|
-
const grep =
|
|
1132
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1041
1133
|
await invoke(write, "write", { path, content: before, mode: "create" }, undefined, undefined, {
|
|
1042
1134
|
cwd: directory,
|
|
1043
1135
|
} as ExtensionContext);
|
|
@@ -1103,12 +1195,12 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
|
|
|
1103
1195
|
"edit",
|
|
1104
1196
|
{
|
|
1105
1197
|
path,
|
|
1106
|
-
|
|
1198
|
+
steps: [
|
|
1107
1199
|
{
|
|
1108
1200
|
action: "replace",
|
|
1109
1201
|
anchor: rows[1].split("│")[0],
|
|
1110
1202
|
end: rows[2].split("│")[0],
|
|
1111
|
-
|
|
1203
|
+
lines: ["A", "B", "C"],
|
|
1112
1204
|
},
|
|
1113
1205
|
],
|
|
1114
1206
|
},
|
|
@@ -1179,7 +1271,7 @@ test("visible source escapes remain readable and searchable while real CRLF stay
|
|
|
1179
1271
|
);
|
|
1180
1272
|
assert.ok(read.content[0].type === "text");
|
|
1181
1273
|
assert.ok(read.content[0].text.includes(String.raw`const eol = "\r\n";`));
|
|
1182
|
-
const grep =
|
|
1274
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1183
1275
|
for (const query of [
|
|
1184
1276
|
{ pattern: String.raw`\r\n`, literal: true },
|
|
1185
1277
|
{ pattern: String.raw`\\r\\n`, literal: false },
|
|
@@ -1221,7 +1313,7 @@ test("grep retains original paths and ignores unmatched invalid UTF-8 across man
|
|
|
1221
1313
|
Array.from({ length: 70 }, (_, i) => writeFile(join(directory, `file ${i}.txt`), "--\r\n")),
|
|
1222
1314
|
);
|
|
1223
1315
|
await writeFile(join(directory, "invalid.txt"), Buffer.from([0xc3, 0x28]));
|
|
1224
|
-
const grep =
|
|
1316
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1225
1317
|
const result = await invoke(
|
|
1226
1318
|
grep,
|
|
1227
1319
|
"grep",
|
|
@@ -1250,7 +1342,7 @@ test("NUL files are silently skipped across search scopes and output modes", asy
|
|
|
1250
1342
|
]);
|
|
1251
1343
|
await writeFile(binary, source);
|
|
1252
1344
|
await writeFile(join(directory, "valid.txt"), "needle\n");
|
|
1253
|
-
const grep =
|
|
1345
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1254
1346
|
for (const outputMode of ["content", "files", "count"] as const) {
|
|
1255
1347
|
for (const multiline of [false, true]) {
|
|
1256
1348
|
const skipped = await invoke(
|
|
@@ -1284,7 +1376,7 @@ test("NUL files are silently skipped across search scopes and output modes", asy
|
|
|
1284
1376
|
test("invalid UTF-8 matches use plain previews while valid files retain edit anchors", async () => {
|
|
1285
1377
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-preview-"));
|
|
1286
1378
|
try {
|
|
1287
|
-
const grep =
|
|
1379
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1288
1380
|
const invalid = join(directory, "invalid.txt");
|
|
1289
1381
|
for (const separator of ["\n", "\r\n"]) {
|
|
1290
1382
|
const source = Buffer.concat([
|
|
@@ -1361,7 +1453,7 @@ test("grep paths with input shorthand or literal separators still edit the searc
|
|
|
1361
1453
|
await mkdir(dirname(otherFile), { recursive: true });
|
|
1362
1454
|
await writeFile(file, "needle\n");
|
|
1363
1455
|
await writeFile(otherFile, "needle\n");
|
|
1364
|
-
const grep =
|
|
1456
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1365
1457
|
let content = "";
|
|
1366
1458
|
let returnedPath = "";
|
|
1367
1459
|
for (const outputMode of ["content", "files", "count"] as const) {
|
|
@@ -1386,7 +1478,7 @@ test("grep paths with input shorthand or literal separators still edit the searc
|
|
|
1386
1478
|
assert.ok(anchor);
|
|
1387
1479
|
await invoke(makeEditOverride(directory, DEFAULT_CONFIG), "edit", {
|
|
1388
1480
|
path: returnedPath,
|
|
1389
|
-
|
|
1481
|
+
steps: [{ action: "replace", anchor, lines: ["updated"] }],
|
|
1390
1482
|
});
|
|
1391
1483
|
assert.equal(await readFile(file, "utf8"), "updated\n");
|
|
1392
1484
|
assert.equal(await readFile(otherFile, "utf8"), "needle\n");
|
|
@@ -1405,7 +1497,7 @@ test("literal LF and CRLF queries match original valid and invalid UTF-8 files a
|
|
|
1405
1497
|
join(directory, "invalid.txt"),
|
|
1406
1498
|
Buffer.concat([Buffer.from("alpha\r\nbeta\r\n"), Buffer.from([0xff])]),
|
|
1407
1499
|
);
|
|
1408
|
-
const grep =
|
|
1500
|
+
const grep = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
1409
1501
|
for (const outputMode of ["content", "files", "count"] as const) {
|
|
1410
1502
|
await t.test(outputMode, async () => {
|
|
1411
1503
|
const result = await invoke(grep, "crlf", {
|
|
@@ -1442,11 +1534,19 @@ test("literal LF and CRLF queries match original valid and invalid UTF-8 files a
|
|
|
1442
1534
|
}
|
|
1443
1535
|
});
|
|
1444
1536
|
|
|
1445
|
-
test("oversized candidate path record → bounded runner rejects before invoking its consumer", async () => {
|
|
1537
|
+
test("oversized candidate path record → bounded runner rejects before invoking its consumer", async (t) => {
|
|
1538
|
+
const spawn = childProcess.spawn;
|
|
1539
|
+
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) =>
|
|
1540
|
+
spawn(process.execPath, args[1], args[2]),
|
|
1541
|
+
);
|
|
1542
|
+
syncBuiltinESMExports();
|
|
1543
|
+
t.after(() => {
|
|
1544
|
+
t.mock.restoreAll();
|
|
1545
|
+
syncBuiltinESMExports();
|
|
1546
|
+
});
|
|
1446
1547
|
let called = false;
|
|
1447
1548
|
await assert.rejects(
|
|
1448
1549
|
runRgPaths(
|
|
1449
|
-
process.execPath,
|
|
1450
1550
|
[
|
|
1451
1551
|
"--input-type=module",
|
|
1452
1552
|
"--eval",
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { makeMockGrep } from "../pi/grep-rg.testing.ts";
|
|
1
2
|
import assert from "node:assert/strict";
|
|
2
3
|
import { mkdtemp, rm, truncate, writeFile } from "node:fs/promises";
|
|
3
4
|
import { tmpdir } from "node:os";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { test } from "node:test";
|
|
6
7
|
import { formatByteSize } from "../pi/budgets.ts";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
9
|
+
const MAX_MULTILINE_SEARCH_BYTES = 64 * 1024 * 1024;
|
|
10
|
+
const { MAX_UNNARROWED_SCAN_BYTES } = await import("../pi/grep-candidates.ts");
|
|
11
|
+
|
|
11
12
|
import { OUTCOME_NEXT } from "../pi/report-schema.ts";
|
|
12
13
|
import { reportOf } from "../pi/report.ts";
|
|
13
|
-
|
|
14
|
+
const { grepCounts } = await import("../pi/grep-output.testing.ts");
|
|
14
15
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
15
16
|
|
|
16
17
|
test("repeated all-file candidates → count each file once toward the scan budget", async (t) => {
|
|
@@ -22,7 +23,7 @@ test("repeated all-file candidates → count each file once toward the scan budg
|
|
|
22
23
|
await truncate(padding, MAX_MULTILINE_SEARCH_BYTES);
|
|
23
24
|
await writeFile(fixture, "ab\n");
|
|
24
25
|
const repeats = Math.ceil(MAX_UNNARROWED_SCAN_BYTES / MAX_MULTILINE_SEARCH_BYTES);
|
|
25
|
-
const result = await callTool(
|
|
26
|
+
const result = await callTool(makeGrepOverride(directory, DEFAULT_CONFIG), {
|
|
26
27
|
path: [...Array<string>(repeats).fill(padding), fixture],
|
|
27
28
|
pattern: ".",
|
|
28
29
|
literal: false,
|
|
@@ -69,9 +70,9 @@ test("all-file candidates exceed the scan budget → stop listing and retain sca
|
|
|
69
70
|
await writeFile(fixture, scenario.source);
|
|
70
71
|
const offered: string[] = [];
|
|
71
72
|
let stopped = false;
|
|
72
|
-
const tool =
|
|
73
|
+
const tool = makeMockGrep(directory, DEFAULT_CONFIG, {
|
|
73
74
|
runRgLines: async () => assert.fail("multiline candidates must use file listing"),
|
|
74
|
-
runRgPaths: async (
|
|
75
|
+
runRgPaths: async (_args, _signal, onFile) => {
|
|
75
76
|
for (const path of paths) {
|
|
76
77
|
offered.push(path);
|
|
77
78
|
if (!(await onFile(path))) {
|
|
@@ -92,7 +93,6 @@ test("all-file candidates exceed the scan budget → stop listing and retain sca
|
|
|
92
93
|
assert.deepEqual(offered, [fixture, ...padding, blocked]);
|
|
93
94
|
const report = reportOf(result, "grep");
|
|
94
95
|
assert.ok(report);
|
|
95
|
-
assert.equal(report.candidates, "all");
|
|
96
96
|
assert.equal(report.scanLimit, formatByteSize(MAX_UNNARROWED_SCAN_BYTES));
|
|
97
97
|
if (scenario.stderr) {
|
|
98
98
|
assert.equal(result.isError, true);
|