@criogaid/pi-hashline-edit 0.5.0 → 0.5.1
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 +18 -10
- package/package.json +1 -1
- package/src/core/text.test.ts +30 -1
- package/src/core/text.ts +8 -3
- package/src/integration/grep-rg.test.ts +212 -93
- package/src/integration/large-text.test.ts +3 -5
- package/src/pi/action-fusion.test.ts +141 -5
- package/src/pi/action-fusion.ts +36 -3
- package/src/pi/anchor-format.test.ts +46 -0
- package/src/pi/anchor-format.ts +21 -2
- package/src/pi/diagnostic-buffer.test.ts +58 -0
- package/src/pi/diagnostic-buffer.ts +59 -0
- package/src/pi/e2e-scenarios.test.ts +1 -0
- package/src/pi/edit-tool.ts +1 -1
- package/src/pi/fusion-card.test.ts +26 -0
- package/src/pi/fusion-card.ts +21 -6
- package/src/pi/grep-output.ts +26 -28
- package/src/pi/grep-render.ts +8 -11
- package/src/pi/grep-scope.ts +6 -31
- package/src/pi/grep-search.ts +62 -49
- package/src/pi/grep-tool.ts +25 -53
- package/src/pi/grep.test.ts +292 -109
- package/src/pi/pi.test.ts +1 -1
- package/src/pi/read-tool.ts +1 -1
- package/src/pi/registration.test.ts +6 -2
- package/src/pi/render.test.ts +127 -1
- package/src/pi/render.ts +28 -5
- package/src/pi/replace-tool.ts +1 -1
- package/src/pi/rg-process.ts +8 -5
- package/src/pi/rg-text-view.ts +8 -5
- package/src/pi/text-stream.test.ts +153 -0
- package/src/pi/text-stream.ts +33 -13
- package/src/pi/write-tool.ts +2 -0
|
@@ -46,7 +46,7 @@ test("real rg emits anchored matches from a temporary directory", async () => {
|
|
|
46
46
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
47
47
|
|
|
48
48
|
for (const pattern of ["needle", ["needle"]]) {
|
|
49
|
-
const result: any = await invoke(tool, "0", { pattern }, undefined, undefined);
|
|
49
|
+
const result: any = await invoke(tool, "0", { pattern, literal: true }, undefined, undefined);
|
|
50
50
|
assert.match(result.content[0].text, /fixture\.ts · 1 match/);
|
|
51
51
|
assert.match(result.content[0].text, /1#[0-9A-Z]+│needle/);
|
|
52
52
|
}
|
|
@@ -93,13 +93,25 @@ test("real rg uses smart-case across OR patterns and Unicode matches", async ()
|
|
|
93
93
|
try {
|
|
94
94
|
await writeFile(join(directory, "fixture.ts"), "FOO abc\nfoo BAR\nfoo bar\nK zip\nk zip\n");
|
|
95
95
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
96
|
-
const lower = await invoke(
|
|
96
|
+
const lower = await invoke(
|
|
97
|
+
tool,
|
|
98
|
+
"0",
|
|
99
|
+
{ literal: true, pattern: ["foo", "bar"] },
|
|
100
|
+
undefined,
|
|
101
|
+
undefined,
|
|
102
|
+
);
|
|
97
103
|
assert.match(lower.content[0].text, /fixture\.ts · 3 matches/);
|
|
98
104
|
assert.match(lower.content[0].text, /│FOO abc/);
|
|
99
|
-
const mixed = await invoke(
|
|
105
|
+
const mixed = await invoke(
|
|
106
|
+
tool,
|
|
107
|
+
"0",
|
|
108
|
+
{ literal: true, pattern: ["foo", "BAR"] },
|
|
109
|
+
undefined,
|
|
110
|
+
undefined,
|
|
111
|
+
);
|
|
100
112
|
assert.match(mixed.content[0].text, /fixture\.ts · 2 matches/);
|
|
101
113
|
assert.doesNotMatch(mixed.content[0].text, /│FOO abc/);
|
|
102
|
-
const unicode = await invoke(tool, "0", { pattern: "k" }, undefined, undefined);
|
|
114
|
+
const unicode = await invoke(tool, "0", { literal: true, pattern: "k" }, undefined, undefined);
|
|
103
115
|
assert.match(unicode.content[0].text, /fixture\.ts · 2 matches/);
|
|
104
116
|
assert.match(unicode.content[0].text, /│K zip/);
|
|
105
117
|
} finally {
|
|
@@ -116,7 +128,7 @@ test("explicit ignoreCase overrides smart-case for regex and literal queries", a
|
|
|
116
128
|
const sensitive = await invoke(
|
|
117
129
|
tool,
|
|
118
130
|
"0",
|
|
119
|
-
{ pattern: "foo", path: file, ignoreCase: false },
|
|
131
|
+
{ literal: true, pattern: "foo", path: file, ignoreCase: false },
|
|
120
132
|
undefined,
|
|
121
133
|
undefined,
|
|
122
134
|
);
|
|
@@ -237,9 +249,7 @@ test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
|
|
|
237
249
|
const result: any = await invoke(
|
|
238
250
|
tool,
|
|
239
251
|
"0",
|
|
240
|
-
{
|
|
241
|
-
pattern: ["^foo$", "foo"],
|
|
242
|
-
},
|
|
252
|
+
{ literal: false, pattern: ["^foo$", "foo"] },
|
|
243
253
|
undefined,
|
|
244
254
|
undefined,
|
|
245
255
|
);
|
|
@@ -266,57 +276,62 @@ test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
|
|
|
266
276
|
}
|
|
267
277
|
});
|
|
268
278
|
|
|
269
|
-
test("real rg
|
|
279
|
+
test("real rg requires an explicit mode and separates exact text from regex", async () => {
|
|
270
280
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-regex-"));
|
|
271
281
|
try {
|
|
272
|
-
await writeFile(
|
|
282
|
+
await writeFile(
|
|
283
|
+
join(directory, "fixture.ts"),
|
|
284
|
+
"FOO\nfoo\nfoo0\nfoo(0)\nqueueTool(\nfoo(?=bar)\n",
|
|
285
|
+
);
|
|
273
286
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
287
|
+
await assert.rejects(
|
|
288
|
+
invoke(tool, "missing-mode", { pattern: "foo" }),
|
|
289
|
+
/Validation failed for tool "grep":\n {2}- literal: /,
|
|
290
|
+
);
|
|
274
291
|
for (const pattern of ["(?i)^foo$", "(?P<name>foo)$"]) {
|
|
275
|
-
const result
|
|
292
|
+
const result = await invoke(tool, "regex", { pattern, literal: false });
|
|
276
293
|
assert.match(result.content[0].text, /│foo/);
|
|
277
|
-
assert.doesNotMatch(result.content[0].text, /Invalid regex/);
|
|
278
294
|
}
|
|
279
|
-
|
|
280
|
-
|
|
295
|
+
const regex = await invoke(tool, "regex-punctuation", { pattern: "foo(0)", literal: false });
|
|
296
|
+
assert.match(regex.content[0].text, /│foo0/);
|
|
297
|
+
assert.doesNotMatch(regex.content[0].text, /│foo\(0\)/);
|
|
298
|
+
for (const pattern of ["foo(0)", "queueTool(", "foo(?=bar)"]) {
|
|
299
|
+
const result = await invoke(tool, "literal", { pattern, literal: true });
|
|
281
300
|
assert.ok(result.content[0].text.includes(`│${pattern}`));
|
|
282
|
-
assert.match(result.content[0].text, /Invalid regex; searched the pattern as literal text/);
|
|
283
|
-
await assert.rejects(
|
|
284
|
-
invoke(tool, "0", { pattern, literal: false }, undefined, undefined),
|
|
285
|
-
/regex parse error/,
|
|
286
|
-
);
|
|
287
301
|
}
|
|
288
|
-
const missing
|
|
289
|
-
assert.
|
|
290
|
-
|
|
291
|
-
tool,
|
|
292
|
-
|
|
293
|
-
{ pattern: "queueTool(", literal: true },
|
|
294
|
-
undefined,
|
|
295
|
-
undefined,
|
|
302
|
+
const missing = await invoke(tool, "no-match", { pattern: "missing(", literal: true });
|
|
303
|
+
assert.equal(missing.content[0].text, "No matches found");
|
|
304
|
+
await assert.rejects(
|
|
305
|
+
invoke(tool, "invalid-regex", { pattern: "queueTool(", literal: false }),
|
|
306
|
+
/regex parse error[\s\S]*set literal:true to search the text exactly/,
|
|
296
307
|
);
|
|
297
|
-
assert.match(explicit.content[0].text, /│queueTool\(/);
|
|
298
|
-
assert.doesNotMatch(explicit.content[0].text, /Invalid regex/);
|
|
299
308
|
await assert.rejects(
|
|
300
|
-
invoke(tool, "
|
|
301
|
-
/
|
|
309
|
+
invoke(tool, "invalid-array", { pattern: ["queueTool(", "\\bfoo\\b"], literal: false }),
|
|
310
|
+
/regex parse error[\s\S]*set literal:true to search the text exactly/,
|
|
302
311
|
);
|
|
303
312
|
} finally {
|
|
304
313
|
await rm(directory, { recursive: true, force: true });
|
|
305
314
|
}
|
|
306
315
|
});
|
|
307
316
|
|
|
308
|
-
test("real rg keeps CRLF line-end anchors with
|
|
317
|
+
test("real rg keeps CRLF line-end anchors with regex OR matching", async () => {
|
|
309
318
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-crlf-"));
|
|
310
319
|
try {
|
|
311
320
|
await writeFile(join(directory, "fixture.ts"), "alpha beta drop\r\nalpha beta\r\nalpha only");
|
|
312
321
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
313
|
-
const ending = await invoke(
|
|
322
|
+
const ending = await invoke(
|
|
323
|
+
tool,
|
|
324
|
+
"0",
|
|
325
|
+
{ pattern: "beta$", literal: false },
|
|
326
|
+
undefined,
|
|
327
|
+
undefined,
|
|
328
|
+
);
|
|
314
329
|
assert.match(ending.content[0].text, /fixture\.ts · 1 match/);
|
|
315
330
|
assert.match(ending.content[0].text, /2#[0-9A-Z]+│alpha beta$/);
|
|
316
331
|
const alternatives = await invoke(
|
|
317
332
|
tool,
|
|
318
333
|
"0",
|
|
319
|
-
{ pattern: ["beta$", "alpha only"] },
|
|
334
|
+
{ pattern: ["beta$", "alpha only"], literal: false },
|
|
320
335
|
undefined,
|
|
321
336
|
undefined,
|
|
322
337
|
);
|
|
@@ -397,12 +412,18 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
397
412
|
const ignored = join(directory, "ignored.txt");
|
|
398
413
|
await writeFile(ignored, "needle\n");
|
|
399
414
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
400
|
-
const normal = await invoke(
|
|
415
|
+
const normal = await invoke(
|
|
416
|
+
tool,
|
|
417
|
+
"0",
|
|
418
|
+
{ literal: true, pattern: "needle" },
|
|
419
|
+
undefined,
|
|
420
|
+
undefined,
|
|
421
|
+
);
|
|
401
422
|
assert.equal(normal.content[0].text, "No matches found");
|
|
402
423
|
const explicit = await invoke(
|
|
403
424
|
tool,
|
|
404
425
|
"0",
|
|
405
|
-
{ pattern: "needle", path: ignored },
|
|
426
|
+
{ literal: true, pattern: "needle", path: ignored },
|
|
406
427
|
undefined,
|
|
407
428
|
undefined,
|
|
408
429
|
);
|
|
@@ -410,13 +431,19 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
410
431
|
const excluded = await invoke(
|
|
411
432
|
tool,
|
|
412
433
|
"0",
|
|
413
|
-
{ pattern: "needle", path: ignored, glob: "!ignored.txt" },
|
|
434
|
+
{ literal: true, pattern: "needle", path: ignored, glob: "!ignored.txt" },
|
|
414
435
|
undefined,
|
|
415
436
|
undefined,
|
|
416
437
|
);
|
|
417
438
|
assert.equal(excluded.content[0].text, "No matches found");
|
|
418
439
|
await writeFile(join(directory, ".hidden.txt"), "needle\n");
|
|
419
|
-
const hidden = await invoke(
|
|
440
|
+
const hidden = await invoke(
|
|
441
|
+
tool,
|
|
442
|
+
"0",
|
|
443
|
+
{ literal: true, pattern: "needle" },
|
|
444
|
+
undefined,
|
|
445
|
+
undefined,
|
|
446
|
+
);
|
|
420
447
|
assert.match(hidden.content[0].text, /\.hidden\.txt · 1 match/);
|
|
421
448
|
assert.doesNotMatch(hidden.content[0].text, /ignored\.txt · 1 match/);
|
|
422
449
|
} finally {
|
|
@@ -437,6 +464,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
|
|
|
437
464
|
tool,
|
|
438
465
|
"0",
|
|
439
466
|
{
|
|
467
|
+
literal: true,
|
|
440
468
|
pattern: "needle",
|
|
441
469
|
path: [kept, excluded, ignored],
|
|
442
470
|
glob: ["*.ts", "!**/*.test.ts"],
|
|
@@ -451,11 +479,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
|
|
|
451
479
|
const none: any = await invoke(
|
|
452
480
|
tool,
|
|
453
481
|
"0",
|
|
454
|
-
{
|
|
455
|
-
pattern: "needle",
|
|
456
|
-
path: excluded,
|
|
457
|
-
glob: "!**/*.test.ts",
|
|
458
|
-
},
|
|
482
|
+
{ literal: true, pattern: "needle", path: excluded, glob: "!**/*.test.ts" },
|
|
459
483
|
undefined,
|
|
460
484
|
undefined,
|
|
461
485
|
);
|
|
@@ -485,12 +509,18 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
485
509
|
throw error;
|
|
486
510
|
}
|
|
487
511
|
const grep = makeGrepOverrideWithBackend(root, DEFAULT_CONFIG, {});
|
|
488
|
-
const hidden: any = await invoke(
|
|
512
|
+
const hidden: any = await invoke(
|
|
513
|
+
grep,
|
|
514
|
+
"0",
|
|
515
|
+
{ literal: true, pattern: "needle" },
|
|
516
|
+
undefined,
|
|
517
|
+
undefined,
|
|
518
|
+
);
|
|
489
519
|
assert.equal(hidden.content[0].text, "No matches found");
|
|
490
520
|
const found: any = await invoke(
|
|
491
521
|
grep,
|
|
492
522
|
"0",
|
|
493
|
-
{ pattern: "needle", path: join(link, "linked.txt") },
|
|
523
|
+
{ literal: true, pattern: "needle", path: join(link, "linked.txt") },
|
|
494
524
|
undefined,
|
|
495
525
|
undefined,
|
|
496
526
|
);
|
|
@@ -529,22 +559,21 @@ test("real rg reports unsupported lookarounds and backreferences under Rust rege
|
|
|
529
559
|
undefined,
|
|
530
560
|
);
|
|
531
561
|
assert.match(valid.content[0].text, /fixture\.txt · 2 matches/);
|
|
532
|
-
for (const pattern of ["foo(?=bar)", "(foo)\\1"]) {
|
|
562
|
+
for (const pattern of ["foo(?=bar)", "(foo)\\1", ["plain", "foo(?=bar)"]]) {
|
|
533
563
|
await assert.rejects(
|
|
534
564
|
invoke(tool, "0", { pattern, literal: false }, undefined, undefined),
|
|
535
565
|
/regex parse error[\s\S]*no lookaround or backreferences; rewrite the pattern, or use replace/,
|
|
536
566
|
);
|
|
537
567
|
}
|
|
538
|
-
const
|
|
539
|
-
assert.
|
|
540
|
-
|
|
541
|
-
/No matches found.*Invalid regex; searched the pattern as literal text; ripgrep's Rust regex has no lookaround or backreferences/s,
|
|
542
|
-
);
|
|
543
|
-
// A parse error without other-dialect syntax gets no dialect hint.
|
|
568
|
+
const literal = await invoke(tool, "0", { pattern: "foo(?=bar)", literal: true });
|
|
569
|
+
assert.equal(literal.content[0].text, "No matches found");
|
|
570
|
+
// A parse error without other-dialect syntax requests an exact-text search.
|
|
544
571
|
await assert.rejects(
|
|
545
572
|
invoke(tool, "0", { pattern: "foo(", literal: false }, undefined, undefined),
|
|
546
573
|
(error: Error) =>
|
|
547
|
-
/regex parse error/.test(error.message) &&
|
|
574
|
+
/regex parse error/.test(error.message) &&
|
|
575
|
+
/set literal:true to search the text exactly/.test(error.message) &&
|
|
576
|
+
!/lookaround/.test(error.message),
|
|
548
577
|
);
|
|
549
578
|
} finally {
|
|
550
579
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -556,7 +585,13 @@ test("line-based grep uses context for display but never matches across CRLF", a
|
|
|
556
585
|
try {
|
|
557
586
|
await writeFile(join(directory, "fixture.txt"), "alpha\r\nbeta\r\ngamma\r\n");
|
|
558
587
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
559
|
-
const context = await invoke(
|
|
588
|
+
const context = await invoke(
|
|
589
|
+
tool,
|
|
590
|
+
"0",
|
|
591
|
+
{ literal: true, pattern: "alpha", context: 1 },
|
|
592
|
+
undefined,
|
|
593
|
+
undefined,
|
|
594
|
+
);
|
|
560
595
|
assert.match(context.content[0].text, /fixture\.txt · 1 match/);
|
|
561
596
|
assert.match(context.content[0].text, /1#[0-9A-Z]+│alpha/);
|
|
562
597
|
assert.match(context.content[0].text, /2#[0-9A-Z]+│beta/);
|
|
@@ -572,7 +607,7 @@ test("line-based grep uses context for display but never matches across CRLF", a
|
|
|
572
607
|
const limited = await invoke(
|
|
573
608
|
tool,
|
|
574
609
|
"0",
|
|
575
|
-
{ pattern: ["alpha", "beta"], outputMode: "count", limit: 1 },
|
|
610
|
+
{ literal: true, pattern: ["alpha", "beta"], outputMode: "count", limit: 1 },
|
|
576
611
|
undefined,
|
|
577
612
|
undefined,
|
|
578
613
|
);
|
|
@@ -618,7 +653,14 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
618
653
|
const bounded = await invoke(
|
|
619
654
|
tool,
|
|
620
655
|
"0",
|
|
621
|
-
{
|
|
656
|
+
{
|
|
657
|
+
pattern: "(?s)alpha.*gamma",
|
|
658
|
+
literal: false,
|
|
659
|
+
path: file,
|
|
660
|
+
multiline: true,
|
|
661
|
+
outputMode: "count",
|
|
662
|
+
limit: 2,
|
|
663
|
+
},
|
|
622
664
|
undefined,
|
|
623
665
|
undefined,
|
|
624
666
|
);
|
|
@@ -628,7 +670,14 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
628
670
|
const files = await invoke(
|
|
629
671
|
tool,
|
|
630
672
|
"0",
|
|
631
|
-
{
|
|
673
|
+
{
|
|
674
|
+
pattern: "alpha\\nbeta",
|
|
675
|
+
literal: false,
|
|
676
|
+
path: file,
|
|
677
|
+
multiline: true,
|
|
678
|
+
outputMode: "files",
|
|
679
|
+
limit: 1,
|
|
680
|
+
},
|
|
632
681
|
undefined,
|
|
633
682
|
undefined,
|
|
634
683
|
);
|
|
@@ -795,7 +844,7 @@ test("files and count modes aggregate only matching lines inside the limit", asy
|
|
|
795
844
|
await writeFile(first, "needle needle\nneedle\n");
|
|
796
845
|
await writeFile(second, "needle\n");
|
|
797
846
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
798
|
-
const query = { pattern: "needle", path: [first, second], limit: 1 };
|
|
847
|
+
const query = { literal: true, pattern: "needle", path: [first, second], limit: 1 };
|
|
799
848
|
const files = await invoke(
|
|
800
849
|
tool,
|
|
801
850
|
"files",
|
|
@@ -847,7 +896,7 @@ test("default grep rejects file changes and propagates cancellation", async () =
|
|
|
847
896
|
},
|
|
848
897
|
});
|
|
849
898
|
await assert.rejects(
|
|
850
|
-
invoke(changing, "0", { pattern: "foo", path: file }, undefined, undefined),
|
|
899
|
+
invoke(changing, "0", { literal: true, pattern: "foo", path: file }, undefined, undefined),
|
|
851
900
|
/File changed during search/,
|
|
852
901
|
);
|
|
853
902
|
|
|
@@ -860,7 +909,13 @@ test("default grep rejects file changes and propagates cancellation", async () =
|
|
|
860
909
|
},
|
|
861
910
|
});
|
|
862
911
|
await assert.rejects(
|
|
863
|
-
invoke(
|
|
912
|
+
invoke(
|
|
913
|
+
cancelling,
|
|
914
|
+
"0",
|
|
915
|
+
{ literal: true, pattern: "foo", path: file },
|
|
916
|
+
controller.signal,
|
|
917
|
+
undefined,
|
|
918
|
+
),
|
|
864
919
|
/Operation aborted/,
|
|
865
920
|
);
|
|
866
921
|
} finally {
|
|
@@ -895,7 +950,7 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
895
950
|
const result: any = await invoke(
|
|
896
951
|
tool,
|
|
897
952
|
"count",
|
|
898
|
-
{ pattern, outputMode: "count" },
|
|
953
|
+
{ pattern, literal: false, outputMode: "count" },
|
|
899
954
|
undefined,
|
|
900
955
|
undefined,
|
|
901
956
|
);
|
|
@@ -904,7 +959,7 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
904
959
|
const limited: any = await invoke(
|
|
905
960
|
tool,
|
|
906
961
|
"limited",
|
|
907
|
-
{ pattern: ".*", limit: 1 },
|
|
962
|
+
{ pattern: ".*", literal: false, limit: 1 },
|
|
908
963
|
undefined,
|
|
909
964
|
undefined,
|
|
910
965
|
);
|
|
@@ -945,6 +1000,7 @@ test("tools share physical lines and anchors across text representations", async
|
|
|
945
1000
|
assert.equal(await readFile(file, "utf8"), before);
|
|
946
1001
|
const read = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
|
|
947
1002
|
const grep = await call(makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {}), {
|
|
1003
|
+
literal: true,
|
|
948
1004
|
path: file,
|
|
949
1005
|
pattern: "old",
|
|
950
1006
|
context: 2,
|
|
@@ -986,7 +1042,7 @@ test("long-line previews preserve full-line anchors across literal and Rust rege
|
|
|
986
1042
|
await writeFile(join(directory, "long.txt"), `${long}\r\nfollow\r\n${context}\r\n`);
|
|
987
1043
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
988
1044
|
for (const params of [
|
|
989
|
-
{ pattern: "NEEDLE" },
|
|
1045
|
+
{ literal: true, pattern: "NEEDLE" },
|
|
990
1046
|
{ pattern: ["NEEDLE", "tail"], literal: true },
|
|
991
1047
|
{ pattern: "NEEDLE(?:tail)+", literal: false },
|
|
992
1048
|
]) {
|
|
@@ -1040,7 +1096,7 @@ test("all text tools share logical CRLF matching, anchors, and mutation separato
|
|
|
1040
1096
|
const contextual = await invoke(
|
|
1041
1097
|
grep,
|
|
1042
1098
|
"grep",
|
|
1043
|
-
{ path, pattern: "alpha", context: 1 },
|
|
1099
|
+
{ literal: true, path, pattern: "alpha", context: 1 },
|
|
1044
1100
|
undefined,
|
|
1045
1101
|
undefined,
|
|
1046
1102
|
);
|
|
@@ -1177,7 +1233,7 @@ test("visible source escapes remain readable and searchable while real CRLF stay
|
|
|
1177
1233
|
}
|
|
1178
1234
|
});
|
|
1179
1235
|
|
|
1180
|
-
test("normalized grep batches retain original paths
|
|
1236
|
+
test("normalized grep batches retain original paths and ignore unmatched invalid UTF-8", async () => {
|
|
1181
1237
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-snapshots-"));
|
|
1182
1238
|
try {
|
|
1183
1239
|
await Promise.all(
|
|
@@ -1193,59 +1249,122 @@ test("normalized grep batches retain original paths, literal option markers, and
|
|
|
1193
1249
|
undefined,
|
|
1194
1250
|
);
|
|
1195
1251
|
assert.equal((result.content[0].text.match(/file \d+\.txt: 1/g) ?? []).length, 70);
|
|
1196
|
-
assert.
|
|
1197
|
-
|
|
1198
|
-
|
|
1252
|
+
assert.doesNotMatch(
|
|
1253
|
+
result.content[0].text,
|
|
1254
|
+
/Search incomplete|invalid\.txt|UNSUPPORTED_ENCODING/,
|
|
1255
|
+
);
|
|
1199
1256
|
assert.doesNotMatch(result.content[0].text, /hashline-grep-/);
|
|
1200
1257
|
} finally {
|
|
1201
1258
|
await rm(directory, { recursive: true, force: true });
|
|
1202
1259
|
}
|
|
1203
1260
|
});
|
|
1204
1261
|
|
|
1205
|
-
test("NUL files are
|
|
1262
|
+
test("NUL files are silently skipped across search scopes and output modes", async () => {
|
|
1206
1263
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-nul-"));
|
|
1207
1264
|
try {
|
|
1208
1265
|
const binary = join(directory, "binary.txt");
|
|
1209
|
-
|
|
1266
|
+
const source = Buffer.concat([
|
|
1267
|
+
Buffer.from("needle\r\n"),
|
|
1268
|
+
Buffer.alloc(65536, 97),
|
|
1269
|
+
Buffer.from("\0needle\n"),
|
|
1270
|
+
]);
|
|
1271
|
+
await writeFile(binary, source);
|
|
1272
|
+
await writeFile(join(directory, "valid.txt"), "needle\n");
|
|
1210
1273
|
const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
1211
|
-
|
|
1212
|
-
|
|
1274
|
+
for (const outputMode of ["content", "files", "count"] as const) {
|
|
1275
|
+
for (const multiline of [false, true]) {
|
|
1276
|
+
const skipped = await invoke(
|
|
1277
|
+
grep,
|
|
1278
|
+
"binary",
|
|
1279
|
+
{ path: binary, pattern: "needle", literal: true, outputMode, multiline },
|
|
1280
|
+
undefined,
|
|
1281
|
+
undefined,
|
|
1282
|
+
);
|
|
1283
|
+
assert.equal(skipped.content[0].text, "No matches found");
|
|
1284
|
+
const result = await invoke(
|
|
1285
|
+
grep,
|
|
1286
|
+
"directory",
|
|
1287
|
+
{ path: directory, pattern: "needle", literal: true, outputMode, multiline, limit: 1 },
|
|
1288
|
+
undefined,
|
|
1289
|
+
undefined,
|
|
1290
|
+
);
|
|
1291
|
+
assert.match(result.content[0].text, /valid\.txt/);
|
|
1292
|
+
assert.doesNotMatch(
|
|
1293
|
+
result.content[0].text,
|
|
1294
|
+
/binary\.txt|UNSUPPORTED_TEXT|Search incomplete/,
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
assert.deepEqual(await readFile(binary), source);
|
|
1299
|
+
} finally {
|
|
1300
|
+
await rm(directory, { recursive: true, force: true });
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1304
|
+
test("invalid UTF-8 matches use plain previews while valid files retain edit anchors", async () => {
|
|
1305
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-preview-"));
|
|
1306
|
+
try {
|
|
1307
|
+
const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
1308
|
+
const invalid = join(directory, "invalid.txt");
|
|
1309
|
+
for (const separator of ["\n", "\r\n"]) {
|
|
1310
|
+
const source = Buffer.concat([
|
|
1311
|
+
Buffer.from(`before${separator}needle `),
|
|
1312
|
+
Buffer.from([0xff]),
|
|
1313
|
+
Buffer.from(`${separator}after${separator}`),
|
|
1314
|
+
]);
|
|
1315
|
+
await writeFile(invalid, source);
|
|
1316
|
+
const result = await invoke(
|
|
1213
1317
|
grep,
|
|
1214
|
-
"
|
|
1215
|
-
{ path:
|
|
1318
|
+
"preview",
|
|
1319
|
+
{ path: invalid, pattern: "needle", literal: true, context: 1 },
|
|
1216
1320
|
undefined,
|
|
1217
1321
|
undefined,
|
|
1218
|
-
)
|
|
1219
|
-
/
|
|
1220
|
-
|
|
1221
|
-
|
|
1322
|
+
);
|
|
1323
|
+
assert.match(result.content[0].text, /1│before\n2│needle �\n3│after/);
|
|
1324
|
+
assert.match(result.content[0].text, /Invalid UTF-8.*cannot be used as edit anchors/);
|
|
1325
|
+
assert.doesNotMatch(result.content[0].text, /\d+#|Search incomplete/);
|
|
1326
|
+
assert.deepEqual(await readFile(invalid), source);
|
|
1327
|
+
}
|
|
1328
|
+
await writeFile(join(directory, "valid.txt"), "needle\n");
|
|
1329
|
+
const mixed = await invoke(
|
|
1222
1330
|
grep,
|
|
1223
|
-
"
|
|
1224
|
-
{ path:
|
|
1331
|
+
"mixed",
|
|
1332
|
+
{ path: directory, pattern: "needle", literal: true },
|
|
1225
1333
|
undefined,
|
|
1226
1334
|
undefined,
|
|
1227
1335
|
);
|
|
1228
|
-
assert.
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
invoke(
|
|
1336
|
+
assert.match(mixed.content[0].text, /valid\.txt · 1 match\n1#[A-Z0-9]+│needle/);
|
|
1337
|
+
assert.match(mixed.content[0].text, /invalid\.txt · 1 match\n2│needle �/);
|
|
1338
|
+
for (const outputMode of ["files", "count"] as const) {
|
|
1339
|
+
const result = await invoke(
|
|
1233
1340
|
grep,
|
|
1234
|
-
"
|
|
1235
|
-
{ path: directory, pattern: "needle", literal: true },
|
|
1341
|
+
"summary",
|
|
1342
|
+
{ path: directory, pattern: "needle", literal: true, outputMode },
|
|
1236
1343
|
undefined,
|
|
1237
1344
|
undefined,
|
|
1238
|
-
)
|
|
1239
|
-
/
|
|
1345
|
+
);
|
|
1346
|
+
assert.match(result.content[0].text, /invalid\.txt/);
|
|
1347
|
+
assert.match(result.content[0].text, /valid\.txt/);
|
|
1348
|
+
assert.doesNotMatch(result.content[0].text, /Search incomplete/);
|
|
1349
|
+
}
|
|
1350
|
+
const multiline = await invoke(
|
|
1351
|
+
grep,
|
|
1352
|
+
"multiline",
|
|
1353
|
+
{ path: invalid, pattern: "needle.*\\r\\nafter", literal: false, multiline: true },
|
|
1354
|
+
undefined,
|
|
1355
|
+
undefined,
|
|
1240
1356
|
);
|
|
1241
|
-
|
|
1357
|
+
// Raw-byte regex matching follows rg semantics: dot does not match malformed UTF-8.
|
|
1358
|
+
assert.equal(multiline.content[0].text, "No matches found");
|
|
1359
|
+
const rawBoundary = await invoke(
|
|
1242
1360
|
grep,
|
|
1243
|
-
"
|
|
1244
|
-
{ path:
|
|
1361
|
+
"raw-boundary",
|
|
1362
|
+
{ path: invalid, pattern: "(?-u:needle[^\\r]*\\r\\nafter)", literal: false, multiline: true },
|
|
1245
1363
|
undefined,
|
|
1246
1364
|
undefined,
|
|
1247
1365
|
);
|
|
1248
|
-
assert.match(
|
|
1366
|
+
assert.match(rawBoundary.content[0].text, /2│needle �\n3│after/);
|
|
1367
|
+
assert.doesNotMatch(rawBoundary.content[0].text, /\d+#/);
|
|
1249
1368
|
} finally {
|
|
1250
1369
|
await rm(directory, { recursive: true, force: true });
|
|
1251
1370
|
}
|
|
@@ -33,11 +33,9 @@ test("read and line-based grep retain anchors on LF and CRLF files over 100 MiB"
|
|
|
33
33
|
assert.ok(first.content[0].text.includes(`1#${computeLineHash(1, "needle", 4)}│needle`));
|
|
34
34
|
const last: any = await call(read, { path, offset: 103426, limit: 1 });
|
|
35
35
|
assert.ok(last.content[0].text.includes(`103426#${computeLineHash(103426, "tail", 4)}│tail`));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
assert.doesNotMatch(result.content[0].text, /Search incomplete/);
|
|
40
|
-
}
|
|
36
|
+
const result: any = await call(grep, { path, pattern: "needle", literal: true });
|
|
37
|
+
assert.ok(result.content[0].text.includes(`1#${computeLineHash(1, "needle", 4)}│needle`));
|
|
38
|
+
assert.doesNotMatch(result.content[0].text, /Search incomplete/);
|
|
41
39
|
}
|
|
42
40
|
} finally {
|
|
43
41
|
await rm(directory, { recursive: true, force: true });
|