@criogaid/pi-hashline-edit 0.8.0 → 0.10.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 +13 -10
- package/README.zh-CN.md +12 -9
- 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 +118 -293
- package/src/core/apply.ts +63 -165
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.ts +4 -4
- 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 +16 -8
- package/src/core/ranges.ts +10 -6
- 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 +7 -43
- package/src/integration/config-registration.test.ts +2 -2
- package/src/integration/fusion-dispatch.test.ts +2 -5
- package/src/integration/grep-flags.test.ts +0 -14
- package/src/integration/grep-js-completeness.test.ts +34 -8
- package/src/integration/grep-line-candidates.test.ts +4 -8
- package/src/integration/grep-matrix.test.ts +3 -7
- package/src/integration/grep-path-matrix.test.ts +5 -5
- package/src/integration/grep-prefilter-coverage.test.ts +3 -7
- package/src/integration/grep-process-limits.test.ts +78 -0
- package/src/integration/grep-rg.test.ts +123 -25
- package/src/integration/grep-scan-budget.test.ts +2 -2
- package/src/integration/grep-translation.test.ts +12 -27
- package/src/integration/large-text.test.ts +1 -47
- package/src/integration/model-budget-lifecycle.test.ts +13 -3
- package/src/integration/mutation-file-types.testing.ts +1 -1
- package/src/integration/npm-package.testing.ts +1 -1
- package/src/integration/publication-read-changes.test.ts +125 -47
- package/src/integration/replace-worker-boundary.test.ts +21 -11
- package/src/integration/report-replay.test.ts +21 -23
- package/src/integration/utf8-errors.test.ts +1 -1
- package/src/pi/AGENTS.md +16 -16
- package/src/pi/action-fusion.test.ts +168 -300
- package/src/pi/action-fusion.ts +148 -111
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +52 -207
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +20 -22
- package/src/pi/argument-validation.test.ts +382 -418
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +5 -4
- package/src/pi/config.test.ts +5 -2
- package/src/pi/config.ts +4 -6
- package/src/pi/diagnostic-buffer.test.ts +12 -1
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +173 -226
- package/src/pi/error-text.ts +4 -8
- package/src/pi/execute.test.ts +165 -266
- package/src/pi/failure-context.test.ts +144 -126
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +168 -141
- package/src/pi/file-commit.test.ts +110 -53
- package/src/pi/file-commit.ts +90 -137
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +4 -1
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +2 -101
- package/src/pi/grep-candidates.ts +23 -69
- package/src/pi/grep-matrix.test.ts +2 -2
- package/src/pi/grep-order.test.ts +4 -4
- package/src/pi/grep-output.ts +62 -96
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +92 -0
- package/src/pi/grep-scope.ts +40 -42
- package/src/pi/grep-search.ts +22 -31
- package/src/pi/grep-tool.ts +55 -82
- package/src/pi/grep.test.ts +81 -46
- package/src/pi/model-budgets.test.ts +25 -23
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +51 -20
- package/src/pi/mutation-runner.ts +126 -70
- package/src/pi/output-budgets.test.ts +38 -16
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +3 -1
- package/src/pi/read-tool.ts +5 -5
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +82 -20
- package/src/pi/render.test.ts +79 -42
- package/src/pi/render.ts +69 -63
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -83
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +9 -5
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +1 -2
- package/src/pi/report-schema.ts +65 -81
- package/src/pi/report.test.ts +171 -25
- package/src/pi/report.ts +33 -87
- package/src/pi/result-safety.test.ts +177 -189
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +48 -64
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +12 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/write-tool.ts +33 -62
- package/src/pi/write.test.ts +1 -3
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { rejectsArgument } from "../pi/argument-error.testing.ts";
|
|
2
1
|
/**
|
|
3
2
|
* Explicit integration coverage for the platform rg bundled by @vscode/ripgrep.
|
|
4
3
|
* This suite is excluded from the default test script.
|
|
@@ -21,7 +20,6 @@ import {
|
|
|
21
20
|
import { tmpdir } from "node:os";
|
|
22
21
|
import { dirname, join } from "node:path";
|
|
23
22
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
24
|
-
import { rgPath } from "@vscode/ripgrep";
|
|
25
23
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
26
24
|
import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
|
|
27
25
|
import { makeEditOverride } from "../pi/edit-tool.ts";
|
|
@@ -249,14 +247,6 @@ test("real rg separates exact text from regex", async () => {
|
|
|
249
247
|
const missing = await invoke(tool, "no-match", { pattern: "missing(", literal: true });
|
|
250
248
|
assert.equal(grepCounts(missing).matches, 0);
|
|
251
249
|
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
250
|
} finally {
|
|
261
251
|
await rm(directory, { recursive: true, force: true });
|
|
262
252
|
}
|
|
@@ -319,9 +309,14 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
319
309
|
const spawn = childProcess.spawn;
|
|
320
310
|
const children: ReturnType<typeof spawn>[] = [];
|
|
321
311
|
const closed = new Set<ReturnType<typeof spawn>>();
|
|
312
|
+
let missingExecutable = false;
|
|
322
313
|
try {
|
|
323
314
|
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) => {
|
|
324
|
-
const child = spawn(
|
|
315
|
+
const child = spawn(
|
|
316
|
+
missingExecutable ? join(directory, "missing-rg") : process.execPath,
|
|
317
|
+
args[1],
|
|
318
|
+
args[2],
|
|
319
|
+
);
|
|
325
320
|
children.push(child);
|
|
326
321
|
child.once("close", () => closed.add(child));
|
|
327
322
|
return child;
|
|
@@ -341,7 +336,6 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
341
336
|
const consumed: string[] = [];
|
|
342
337
|
let aliveAtCallback = false;
|
|
343
338
|
const run = runRgPaths(
|
|
344
|
-
process.execPath,
|
|
345
339
|
args,
|
|
346
340
|
AbortSignal.any([controller.signal, AbortSignal.timeout(processTimeoutMs)]),
|
|
347
341
|
(path) => {
|
|
@@ -362,8 +356,9 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
362
356
|
assert.ok(child && closed.has(child), "runner must await child close");
|
|
363
357
|
assert.ok(child.exitCode !== null || child.signalCode !== null);
|
|
364
358
|
}
|
|
359
|
+
missingExecutable = true;
|
|
365
360
|
await assert.rejects(
|
|
366
|
-
runRgPaths(
|
|
361
|
+
runRgPaths([], undefined, () => true),
|
|
367
362
|
/Failed to run ripgrep/,
|
|
368
363
|
);
|
|
369
364
|
} finally {
|
|
@@ -420,6 +415,91 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
420
415
|
}
|
|
421
416
|
});
|
|
422
417
|
|
|
418
|
+
test("gitignored directory → root traversal skips it and an explicit directory path searches it", async (t) => {
|
|
419
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-ignore-scope-"));
|
|
420
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
421
|
+
const ignored = join(directory, "ignored");
|
|
422
|
+
await mkdir(join(directory, ".git"));
|
|
423
|
+
await mkdir(ignored);
|
|
424
|
+
await writeFile(join(directory, ".gitignore"), "ignored/\n");
|
|
425
|
+
await writeFile(join(ignored, "x.txt"), "needle\n");
|
|
426
|
+
await writeFile(join(directory, "a.txt"), "needle\n");
|
|
427
|
+
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
428
|
+
for (const [path, expected] of [
|
|
429
|
+
[directory, "a.txt"],
|
|
430
|
+
[ignored, "ignored/x.txt"],
|
|
431
|
+
]) {
|
|
432
|
+
const result = await callTool(tool, {
|
|
433
|
+
path,
|
|
434
|
+
literal: true,
|
|
435
|
+
pattern: "needle",
|
|
436
|
+
outputMode: "files",
|
|
437
|
+
});
|
|
438
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
439
|
+
assert.equal(grepCounts(result).matches, 1);
|
|
440
|
+
assert.equal(result.content[0].type, "text");
|
|
441
|
+
assert.equal(result.content[0].text.replace(/\\/g, "/"), expected);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test("named directory → nested ignores, .git and links still limit traversal", async (t) => {
|
|
446
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-nested-scope-"));
|
|
447
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
448
|
+
await mkdir(join(directory, ".git"));
|
|
449
|
+
await writeFile(join(directory, ".gitignore"), "node_modules/\ndist/\n*.map\n");
|
|
450
|
+
for (const file of [
|
|
451
|
+
"node_modules/foo/index.js",
|
|
452
|
+
"node_modules/foo/dist/bundle.js",
|
|
453
|
+
"node_modules/foo/index.js.map",
|
|
454
|
+
"named/index.js",
|
|
455
|
+
"named/nested/.git/config",
|
|
456
|
+
"target/linked.js",
|
|
457
|
+
]) {
|
|
458
|
+
await mkdir(dirname(join(directory, file)), { recursive: true });
|
|
459
|
+
await writeFile(join(directory, file), "needle\n");
|
|
460
|
+
}
|
|
461
|
+
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
462
|
+
for (const { path, expected, linked } of [
|
|
463
|
+
{ path: "node_modules/foo", expected: "node_modules/foo/index.js" },
|
|
464
|
+
{ path: "node_modules/foo/dist", expected: "node_modules/foo/dist/bundle.js" },
|
|
465
|
+
{ path: "node_modules/foo/index.js.map", expected: "node_modules/foo/index.js.map" },
|
|
466
|
+
{ path: "named", expected: "named/index.js" },
|
|
467
|
+
{ path: "named", expected: "named/index.js", linked: true },
|
|
468
|
+
]) {
|
|
469
|
+
await t.test(`${path}${linked ? " with nested link" : ""}`, async (t) => {
|
|
470
|
+
if (linked) {
|
|
471
|
+
try {
|
|
472
|
+
await symlink(
|
|
473
|
+
join(directory, "target"),
|
|
474
|
+
join(directory, "named/nested/link"),
|
|
475
|
+
process.platform === "win32" ? "junction" : "dir",
|
|
476
|
+
);
|
|
477
|
+
} catch (error) {
|
|
478
|
+
if (
|
|
479
|
+
error instanceof Error &&
|
|
480
|
+
"code" in error &&
|
|
481
|
+
["EPERM", "EACCES", "ENOTSUP"].includes(String(error.code))
|
|
482
|
+
) {
|
|
483
|
+
t.skip("symbolic link creation unavailable");
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
const result = await callTool(tool, {
|
|
490
|
+
path: [path],
|
|
491
|
+
literal: true,
|
|
492
|
+
pattern: ["needle"],
|
|
493
|
+
outputMode: "files",
|
|
494
|
+
});
|
|
495
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
496
|
+
assert.equal(grepCounts(result).matches, 1);
|
|
497
|
+
assert.equal(result.content[0].type, "text");
|
|
498
|
+
assert.equal(result.content[0].text.replace(/\\/g, "/"), expected);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
|
|
423
503
|
test("directory traversal with caller globs → excludes .git while an explicit .git path remains searchable", async (t) => {
|
|
424
504
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-git-scope-"));
|
|
425
505
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
@@ -564,7 +644,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
|
|
|
564
644
|
}
|
|
565
645
|
});
|
|
566
646
|
|
|
567
|
-
test("directory traversal skips symlinks but
|
|
647
|
+
test("directory traversal skips symlinks but explicit linked directories and files remain searchable", async (t) => {
|
|
568
648
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-follow-"));
|
|
569
649
|
try {
|
|
570
650
|
const root = join(directory, "root");
|
|
@@ -592,6 +672,20 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
592
672
|
undefined,
|
|
593
673
|
);
|
|
594
674
|
assert.equal(grepCounts(hidden).matches, 0);
|
|
675
|
+
const linkedDirectory = await callTool(grep, {
|
|
676
|
+
path: link,
|
|
677
|
+
literal: true,
|
|
678
|
+
pattern: "needle",
|
|
679
|
+
outputMode: "files",
|
|
680
|
+
});
|
|
681
|
+
assert.equal(
|
|
682
|
+
linkedDirectory.isError,
|
|
683
|
+
undefined,
|
|
684
|
+
JSON.stringify(reportOf(linkedDirectory, "grep")),
|
|
685
|
+
);
|
|
686
|
+
assert.equal(grepCounts(linkedDirectory).matches, 1);
|
|
687
|
+
assert.equal(linkedDirectory.content[0].type, "text");
|
|
688
|
+
assert.equal(linkedDirectory.content[0].text.replace(/\\/g, "/"), "link/linked.txt");
|
|
595
689
|
const found: any = await invoke(
|
|
596
690
|
grep,
|
|
597
691
|
"0",
|
|
@@ -608,7 +702,7 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
608
702
|
await invoke(
|
|
609
703
|
edit,
|
|
610
704
|
"0",
|
|
611
|
-
{ path: resultPath, edits: [{
|
|
705
|
+
{ path: resultPath, edits: [{ action: "replace", anchor, body: ["updated"] }] },
|
|
612
706
|
undefined,
|
|
613
707
|
undefined,
|
|
614
708
|
);
|
|
@@ -749,7 +843,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
749
843
|
await invoke(
|
|
750
844
|
edit,
|
|
751
845
|
"0",
|
|
752
|
-
{ path: file, edits: [{
|
|
846
|
+
{ path: file, edits: [{ action: "replace", anchor, body: ["updated"] }] },
|
|
753
847
|
undefined,
|
|
754
848
|
undefined,
|
|
755
849
|
);
|
|
@@ -933,10 +1027,6 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
933
1027
|
undefined,
|
|
934
1028
|
);
|
|
935
1029
|
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
1030
|
} finally {
|
|
941
1031
|
await rm(directory, { recursive: true, force: true });
|
|
942
1032
|
}
|
|
@@ -974,7 +1064,7 @@ test("tools share physical lines and anchors across text representations", async
|
|
|
974
1064
|
const anchor = rows(grep)[1].split("│")[0];
|
|
975
1065
|
const edit = await call(makeEditOverride(directory, DEFAULT_CONFIG), {
|
|
976
1066
|
path: file,
|
|
977
|
-
edits: [{
|
|
1067
|
+
edits: [{ action: "replace", anchor, body: ["new"] }],
|
|
978
1068
|
});
|
|
979
1069
|
assert.equal(await readFile(file, "utf8"), before.replace("old", "new"));
|
|
980
1070
|
assert.match(edit.details.diff, /^-2 old/m);
|
|
@@ -1105,7 +1195,7 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
|
|
|
1105
1195
|
path,
|
|
1106
1196
|
edits: [
|
|
1107
1197
|
{
|
|
1108
|
-
|
|
1198
|
+
action: "replace",
|
|
1109
1199
|
anchor: rows[1].split("│")[0],
|
|
1110
1200
|
end: rows[2].split("│")[0],
|
|
1111
1201
|
body: ["A", "B", "C"],
|
|
@@ -1386,7 +1476,7 @@ test("grep paths with input shorthand or literal separators still edit the searc
|
|
|
1386
1476
|
assert.ok(anchor);
|
|
1387
1477
|
await invoke(makeEditOverride(directory, DEFAULT_CONFIG), "edit", {
|
|
1388
1478
|
path: returnedPath,
|
|
1389
|
-
edits: [{
|
|
1479
|
+
edits: [{ action: "replace", anchor, body: ["updated"] }],
|
|
1390
1480
|
});
|
|
1391
1481
|
assert.equal(await readFile(file, "utf8"), "updated\n");
|
|
1392
1482
|
assert.equal(await readFile(otherFile, "utf8"), "needle\n");
|
|
@@ -1442,11 +1532,19 @@ test("literal LF and CRLF queries match original valid and invalid UTF-8 files a
|
|
|
1442
1532
|
}
|
|
1443
1533
|
});
|
|
1444
1534
|
|
|
1445
|
-
test("oversized candidate path record → bounded runner rejects before invoking its consumer", async () => {
|
|
1535
|
+
test("oversized candidate path record → bounded runner rejects before invoking its consumer", async (t) => {
|
|
1536
|
+
const spawn = childProcess.spawn;
|
|
1537
|
+
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) =>
|
|
1538
|
+
spawn(process.execPath, args[1], args[2]),
|
|
1539
|
+
);
|
|
1540
|
+
syncBuiltinESMExports();
|
|
1541
|
+
t.after(() => {
|
|
1542
|
+
t.mock.restoreAll();
|
|
1543
|
+
syncBuiltinESMExports();
|
|
1544
|
+
});
|
|
1446
1545
|
let called = false;
|
|
1447
1546
|
await assert.rejects(
|
|
1448
1547
|
runRgPaths(
|
|
1449
|
-
process.execPath,
|
|
1450
1548
|
[
|
|
1451
1549
|
"--input-type=module",
|
|
1452
1550
|
"--eval",
|
|
@@ -71,7 +71,7 @@ test("all-file candidates exceed the scan budget → stop listing and retain sca
|
|
|
71
71
|
let stopped = false;
|
|
72
72
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
73
73
|
runRgLines: async () => assert.fail("multiline candidates must use file listing"),
|
|
74
|
-
runRgPaths: async (
|
|
74
|
+
runRgPaths: async (_args, _signal, onFile) => {
|
|
75
75
|
for (const path of paths) {
|
|
76
76
|
offered.push(path);
|
|
77
77
|
if (!(await onFile(path))) {
|
|
@@ -92,7 +92,7 @@ test("all-file candidates exceed the scan budget → stop listing and retain sca
|
|
|
92
92
|
assert.deepEqual(offered, [fixture, ...padding, blocked]);
|
|
93
93
|
const report = reportOf(result, "grep");
|
|
94
94
|
assert.ok(report);
|
|
95
|
-
assert.equal(report.
|
|
95
|
+
assert.equal(report.scanned, "all");
|
|
96
96
|
assert.equal(report.scanLimit, formatByteSize(MAX_UNNARROWED_SCAN_BYTES));
|
|
97
97
|
if (scenario.stderr) {
|
|
98
98
|
assert.equal(result.isError, true);
|
|
@@ -3,11 +3,10 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
import { rgPath } from "@vscode/ripgrep";
|
|
7
6
|
import { searchText, type GrepQuery } from "../core/search.ts";
|
|
8
7
|
import { searchFiles, type GrepFileMatch } from "../pi/grep-search.ts";
|
|
9
8
|
import { runRgLines, runRgPaths } from "../pi/rg-process.ts";
|
|
10
|
-
import {
|
|
9
|
+
import { candidateArgs } from "../pi/grep-candidates.ts";
|
|
11
10
|
import { lineCandidatePatterns } from "../pi/rg-regex.ts";
|
|
12
11
|
import { extractPrefilter } from "../core/search-analysis.ts";
|
|
13
12
|
import { REGEX_TRANSLATION_CORPUS } from "../testing/regex-translation-corpus.ts";
|
|
@@ -71,28 +70,23 @@ test("upstream regex witnesses × LF/CRLF/malformed bytes → sound candidates,
|
|
|
71
70
|
inputs.push({ bytes, filePath });
|
|
72
71
|
}
|
|
73
72
|
const candidates = new Map<string, readonly number[] | undefined>();
|
|
74
|
-
const warnings: string[] = [];
|
|
75
73
|
const result = await searchFiles({
|
|
76
74
|
backend: {
|
|
77
75
|
runRgPaths: async () => assert.fail("unexpected file fallback"),
|
|
78
|
-
runRgLines: (
|
|
79
|
-
runRgLines(
|
|
76
|
+
runRgLines: (args, signal, maxLines, onFile) =>
|
|
77
|
+
runRgLines(args, signal, maxLines, (path, lines) => {
|
|
80
78
|
candidates.set(resolve(path), lines);
|
|
81
79
|
return onFile(path, lines);
|
|
82
80
|
}),
|
|
83
81
|
},
|
|
84
|
-
rgPath,
|
|
85
82
|
scope: {
|
|
86
83
|
globs: [],
|
|
87
|
-
noIgnore: false,
|
|
88
|
-
follow: false,
|
|
89
84
|
searchPaths: inputs.map((input) => input.filePath),
|
|
90
85
|
},
|
|
91
86
|
query,
|
|
92
87
|
limit: 1000,
|
|
93
88
|
timeoutMs,
|
|
94
89
|
signal: AbortSignal.timeout(timeoutMs),
|
|
95
|
-
warnings,
|
|
96
90
|
});
|
|
97
91
|
const expected = inputs.map(({ bytes, filePath }) => {
|
|
98
92
|
const native = searchText({ source: bytes.toString("utf8"), query, limit: 1000 });
|
|
@@ -112,14 +106,14 @@ test("upstream regex witnesses × LF/CRLF/malformed bytes → sound candidates,
|
|
|
112
106
|
}
|
|
113
107
|
return { filePath, rows: native.lines };
|
|
114
108
|
});
|
|
115
|
-
assert.deepEqual(warnings, []);
|
|
109
|
+
assert.deepEqual(result.warnings, []);
|
|
116
110
|
assert.deepEqual(sorted(result.files), sorted(expected));
|
|
117
111
|
},
|
|
118
112
|
);
|
|
119
113
|
}
|
|
120
114
|
});
|
|
121
115
|
|
|
122
|
-
test("real rg AND/OR file prefilter →
|
|
116
|
+
test("real rg AND/OR file prefilter → broad candidates retain exact JS results", async (t) => {
|
|
123
117
|
const directory = await mkdtemp(join(tmpdir(), "hl-regex-conjunction-"));
|
|
124
118
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
125
119
|
const fixtures = ["foo\nbar", "baz\nqux", "foo\nqux", "baz\nbar", "foo", "bar", "unrelated"];
|
|
@@ -136,11 +130,8 @@ test("real rg AND/OR file prefilter → excludes incomplete branches before JS v
|
|
|
136
130
|
multiline: true,
|
|
137
131
|
};
|
|
138
132
|
const candidates: string[] = [];
|
|
139
|
-
const listing = await
|
|
140
|
-
|
|
141
|
-
rgPath,
|
|
142
|
-
extractPrefilter(query),
|
|
143
|
-
["--", directory],
|
|
133
|
+
const listing = await runRgPaths(
|
|
134
|
+
[...candidateArgs(extractPrefilter(query)), "--null", "--", directory],
|
|
144
135
|
AbortSignal.timeout(timeoutMs),
|
|
145
136
|
(path) => {
|
|
146
137
|
candidates.push(resolve(path));
|
|
@@ -149,18 +140,15 @@ test("real rg AND/OR file prefilter → excludes incomplete branches before JS v
|
|
|
149
140
|
);
|
|
150
141
|
assert.equal(listing.code, 0);
|
|
151
142
|
assert.equal(listing.stderr, "");
|
|
152
|
-
assert.deepEqual(candidates.sort(), paths
|
|
153
|
-
const warnings: string[] = [];
|
|
143
|
+
assert.deepEqual(candidates.sort(), [paths[0], paths[1], paths[2], paths[3], paths[4]].sort());
|
|
154
144
|
const result = await searchFiles({
|
|
155
145
|
backend: { runRgPaths, runRgLines },
|
|
156
|
-
|
|
157
|
-
scope: { globs: [], noIgnore: false, follow: false, searchPaths: [directory] },
|
|
146
|
+
scope: { globs: [], searchPaths: [directory] },
|
|
158
147
|
query,
|
|
159
148
|
limit: 100,
|
|
160
149
|
timeoutMs,
|
|
161
|
-
warnings,
|
|
162
150
|
});
|
|
163
|
-
assert.deepEqual(warnings, []);
|
|
151
|
+
assert.deepEqual(result.warnings, []);
|
|
164
152
|
assert.deepEqual(
|
|
165
153
|
sorted(result.files),
|
|
166
154
|
sorted(
|
|
@@ -181,7 +169,6 @@ test("oversized line translation → file prefilter fallback preserves JS result
|
|
|
181
169
|
const path = join(directory, "long.txt");
|
|
182
170
|
await writeFile(path, pattern);
|
|
183
171
|
let filePasses = 0;
|
|
184
|
-
const warnings: string[] = [];
|
|
185
172
|
const result = await searchFiles({
|
|
186
173
|
backend: {
|
|
187
174
|
runRgPaths: (...args) => {
|
|
@@ -190,15 +177,13 @@ test("oversized line translation → file prefilter fallback preserves JS result
|
|
|
190
177
|
},
|
|
191
178
|
runRgLines: async () => assert.fail("translation budget must select file prefilter"),
|
|
192
179
|
},
|
|
193
|
-
|
|
194
|
-
scope: { globs: [], noIgnore: false, follow: false, searchPaths: [path] },
|
|
180
|
+
scope: { globs: [], searchPaths: [path] },
|
|
195
181
|
query,
|
|
196
182
|
limit: 10,
|
|
197
183
|
timeoutMs,
|
|
198
|
-
warnings,
|
|
199
184
|
});
|
|
200
185
|
assert.ok(filePasses > 0);
|
|
201
|
-
assert.deepEqual(warnings, []);
|
|
186
|
+
assert.deepEqual(result.warnings, []);
|
|
202
187
|
assert.deepEqual(
|
|
203
188
|
sorted(result.files),
|
|
204
189
|
sorted([{ filePath: path, rows: searchText({ source: pattern, query, limit: 10 }).lines }]),
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtemp, open,
|
|
3
|
+
import { mkdtemp, open, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { makeReadOverride } from "../pi/read-tool.ts";
|
|
7
|
-
import { makeEditOverride } from "../pi/edit-tool.ts";
|
|
8
|
-
import { reportOf } from "../pi/report.ts";
|
|
9
7
|
import { makeGrepOverrideWithBackend } from "../pi/grep-tool.ts";
|
|
10
8
|
import { computeLineHash } from "../core/hash.ts";
|
|
11
9
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
@@ -70,47 +68,3 @@ test("CRLF snapshots normalize terminators split across read chunks and preserve
|
|
|
70
68
|
await rm(directory, { recursive: true, force: true });
|
|
71
69
|
}
|
|
72
70
|
});
|
|
73
|
-
|
|
74
|
-
test("copy/move a 150,000-line block → publish every captured line", async (t) => {
|
|
75
|
-
const directory = await mkdtemp(join(tmpdir(), "hashline-large-transfer-"));
|
|
76
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
77
|
-
const path = join(directory, "transfer.txt");
|
|
78
|
-
const lineCount = 150_000;
|
|
79
|
-
const block = " value🙂\r\n".repeat(lineCount);
|
|
80
|
-
const source = `\uFEFFSTART\n${block}END`;
|
|
81
|
-
const read = makeReadOverride(directory, DEFAULT_CONFIG);
|
|
82
|
-
const edit = makeEditOverride(directory, DEFAULT_CONFIG);
|
|
83
|
-
const observedAnchor = async (line: number) => {
|
|
84
|
-
const result: Awaited<ReturnType<typeof read.execute>> = await callTool(read, {
|
|
85
|
-
path,
|
|
86
|
-
offset: line,
|
|
87
|
-
limit: 1,
|
|
88
|
-
});
|
|
89
|
-
const rows = result.content
|
|
90
|
-
.filter((part) => part.type === "text")
|
|
91
|
-
.map((part) => part.text)
|
|
92
|
-
.join("\n");
|
|
93
|
-
const match = new RegExp(`^(${line}#[0-9A-Z]+)│`, "m").exec(rows);
|
|
94
|
-
assert(match);
|
|
95
|
-
return match[1];
|
|
96
|
-
};
|
|
97
|
-
for (const op of ["copy", "move"] as const) {
|
|
98
|
-
await writeFile(path, source);
|
|
99
|
-
const [anchor, end, after] = await Promise.all([
|
|
100
|
-
observedAnchor(2),
|
|
101
|
-
observedAnchor(lineCount + 1),
|
|
102
|
-
observedAnchor(lineCount + 2),
|
|
103
|
-
]);
|
|
104
|
-
const result: Awaited<ReturnType<typeof edit.execute>> = await callTool(edit, {
|
|
105
|
-
path,
|
|
106
|
-
edits: [{ op, anchor, end, after }],
|
|
107
|
-
});
|
|
108
|
-
const expected = Buffer.from(
|
|
109
|
-
(op === "copy" ? source : "\uFEFFSTART\nEND") + "\r\n" + block.slice(0, -2),
|
|
110
|
-
"utf8",
|
|
111
|
-
);
|
|
112
|
-
assert.deepEqual(await readFile(path), expected);
|
|
113
|
-
assert.equal(result.isError, undefined);
|
|
114
|
-
assert.equal(reportOf(result, "edit")?.publication, "PUBLISHED");
|
|
115
|
-
}
|
|
116
|
-
});
|
|
@@ -5,7 +5,8 @@ import { join } from "node:path";
|
|
|
5
5
|
import hashlineEdit from "../index.ts";
|
|
6
6
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
7
7
|
import { outputBudgetsFor } from "../pi/budgets.ts";
|
|
8
|
-
import { decodeReport, reportOf
|
|
8
|
+
import { decodeReport, reportOf } from "../pi/report.ts";
|
|
9
|
+
import type { Report } from "../pi/report-schema.ts";
|
|
9
10
|
import { openTestSession } from "../testing/session.testing.ts";
|
|
10
11
|
|
|
11
12
|
// Budget invalidation relies on Pi publishing the new model before tool preparation.
|
|
@@ -108,9 +109,18 @@ test("model switches before argument preparation → rejection uses the new budg
|
|
|
108
109
|
const tool = session.getToolDefinition("edit");
|
|
109
110
|
const prepare = tool?.prepareArguments;
|
|
110
111
|
assert.ok(prepare);
|
|
112
|
+
const properties: unknown = Reflect.get(tool.parameters, "properties");
|
|
113
|
+
assert.ok(properties && typeof properties === "object");
|
|
114
|
+
const edits: unknown = Reflect.get(properties, "edits");
|
|
115
|
+
assert.ok(edits && typeof edits === "object");
|
|
116
|
+
const maxEdits: unknown = Reflect.get(edits, "maxItems");
|
|
117
|
+
assert.ok(typeof maxEdits === "number");
|
|
111
118
|
const args = {
|
|
112
119
|
path: "never-opened.txt",
|
|
113
|
-
edits: Array.from({ length:
|
|
120
|
+
edits: Array.from({ length: maxEdits }, () => ({
|
|
121
|
+
action: "append",
|
|
122
|
+
body: Array(4).fill("\ud800"),
|
|
123
|
+
})),
|
|
114
124
|
};
|
|
115
125
|
const reports: Report[] = [];
|
|
116
126
|
for (const [id, contextWindow] of [
|
|
@@ -126,7 +136,7 @@ test("model switches before argument preparation → rejection uses the new budg
|
|
|
126
136
|
assert.ok(Buffer.byteLength(error.message) <= budget.blockBytes);
|
|
127
137
|
const report = decodeReport(error.message, "edit");
|
|
128
138
|
assert.ok(report?.issues);
|
|
129
|
-
assert.equal(report.issues.length + (report.omittedIssues ?? 0), args.edits.length);
|
|
139
|
+
assert.equal(report.issues.length + (report.omittedIssues ?? 0), args.edits.length * 4);
|
|
130
140
|
reports.push(report);
|
|
131
141
|
return true;
|
|
132
142
|
},
|
|
@@ -12,7 +12,7 @@ assert.ok(directory);
|
|
|
12
12
|
const cases = [
|
|
13
13
|
{
|
|
14
14
|
tool: makeEditOverride(directory, DEFAULT_CONFIG),
|
|
15
|
-
args: { edits: [{
|
|
15
|
+
args: { edits: [{ action: "append", body: ["after"] }] },
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
tool: makeReplaceTool(directory, DEFAULT_CONFIG),
|
|
@@ -64,7 +64,7 @@ test("packed extension completes file, worker, and command operations", {
|
|
|
64
64
|
assert.equal(anchor("grep"), anchor("read"));
|
|
65
65
|
return call("edit", "edit", {
|
|
66
66
|
path: "fixture.txt",
|
|
67
|
-
edits: [{
|
|
67
|
+
edits: [{ action: "replace", anchor: anchor("grep"), body: ["edited"] }],
|
|
68
68
|
});
|
|
69
69
|
},
|
|
70
70
|
() =>
|