@criogaid/pi-hashline-edit 0.6.1 → 0.7.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 +161 -304
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/package.json +10 -6
- package/src/core/AGENTS.md +20 -0
- package/src/core/apply.test.ts +189 -60
- package/src/core/apply.ts +110 -74
- package/src/core/case-fold.test.ts +40 -0
- package/src/core/case-fold.ts +81 -0
- package/src/core/character-set.test.ts +103 -0
- package/src/core/character-set.ts +170 -0
- package/src/core/errors.test.ts +23 -0
- package/src/core/errors.ts +70 -4
- package/src/core/lines.ts +7 -0
- package/src/core/regex.ts +21 -0
- package/src/core/replace-schema.ts +34 -0
- package/src/core/replace.ts +37 -54
- package/src/core/search-analysis.test.ts +199 -0
- package/src/core/search-analysis.ts +375 -0
- package/src/core/search-matrix.test.ts +64 -0
- package/src/core/search-matrix.testing.ts +183 -0
- package/src/core/search-schema.ts +18 -0
- package/src/core/search.test.ts +145 -0
- package/src/core/search.ts +119 -0
- package/src/core/text.test.ts +16 -8
- package/src/core/text.ts +26 -6
- package/src/core/types.ts +16 -11
- package/src/index.ts +25 -15
- package/src/integration/config-registration.test.ts +30 -24
- package/src/integration/forget-grep.test.ts +52 -2
- package/src/integration/fusion-dispatch.test.ts +21 -105
- package/src/integration/grep-errors.test.ts +50 -0
- package/src/integration/grep-flags.test.ts +280 -0
- package/src/integration/grep-js-completeness.test.ts +208 -0
- package/src/integration/grep-line-candidates.test.ts +233 -0
- package/src/integration/grep-matrix.test.ts +121 -0
- package/src/integration/grep-path-matrix.test.ts +132 -0
- package/src/integration/grep-prefilter-coverage.test.ts +189 -0
- package/src/integration/grep-regex.test.ts +410 -0
- package/src/integration/grep-rg.test.ts +220 -402
- package/src/integration/grep-scan-budget.test.ts +89 -0
- package/src/integration/grep-translation.test.ts +206 -0
- package/src/integration/large-text.test.ts +57 -1
- package/src/integration/model-budget-lifecycle.test.ts +128 -0
- package/src/integration/mutation-file-types.test.ts +12 -25
- package/src/integration/mutation-file-types.testing.ts +33 -0
- package/src/integration/npm-package.test.ts +17 -0
- package/src/integration/npm-package.testing.ts +123 -0
- package/src/integration/publication-read-changes.test.ts +344 -0
- package/src/integration/read-changes.test.ts +98 -0
- package/src/integration/replace-package.test.ts +17 -36
- package/src/integration/replace-package.testing.ts +33 -0
- package/src/integration/replace-worker-boundary.test.ts +107 -0
- package/src/integration/report-replay.test.ts +90 -0
- package/src/integration/utf8-errors.test.ts +46 -0
- package/src/pi/AGENTS.md +55 -0
- package/src/pi/action-fusion.test.ts +253 -103
- package/src/pi/action-fusion.ts +116 -290
- package/src/pi/anchor-format.ts +9 -0
- package/src/pi/argument-diagnostics.ts +478 -0
- package/src/pi/argument-error.testing.ts +43 -0
- package/src/pi/argument-error.ts +78 -0
- package/src/pi/argument-format.test.ts +208 -0
- package/src/pi/argument-validation.test.ts +742 -45
- package/src/pi/argument-validation.ts +55 -57
- package/src/pi/budgets.ts +45 -16
- package/src/pi/codemode.test.ts +96 -0
- package/src/pi/config.test.ts +14 -10
- package/src/pi/config.ts +21 -7
- package/src/pi/diagnostic-buffer.test.ts +52 -16
- package/src/pi/diagnostic-buffer.ts +11 -14
- package/src/pi/directory-sync.test.ts +4 -1
- package/src/pi/edit-tool.ts +100 -93
- package/src/pi/error-text.ts +39 -16
- package/src/pi/execute.test.ts +362 -315
- package/src/pi/extension-loading.test.ts +7 -27
- package/src/pi/extension-loading.testing.ts +2 -14
- package/src/pi/failure-context.test.ts +220 -88
- package/src/pi/failure-context.ts +161 -180
- package/src/pi/failure-path.test.ts +85 -88
- package/src/pi/file-commit.test.ts +78 -45
- package/src/pi/file-commit.ts +218 -151
- package/src/pi/file-read.test.ts +29 -0
- package/src/pi/file-read.ts +60 -0
- package/src/pi/file-snapshot.test.ts +1 -1
- package/src/pi/forget-tool.ts +189 -90
- package/src/pi/forget.test.ts +309 -22
- package/src/pi/forget.testing.ts +41 -113
- package/src/pi/fusion-card.test.ts +40 -14
- package/src/pi/fusion-card.ts +84 -50
- package/src/pi/grep-candidates.test.ts +127 -0
- package/src/pi/grep-candidates.ts +193 -0
- package/src/pi/grep-matrix.test.ts +83 -0
- package/src/pi/grep-output.ts +181 -138
- package/src/pi/grep-render.ts +28 -25
- package/src/pi/grep-scope.ts +61 -53
- package/src/pi/grep-search.ts +299 -242
- package/src/pi/grep-tool.ts +150 -140
- package/src/pi/grep-worker.mjs +4 -0
- package/src/pi/grep-worker.ts +14 -0
- package/src/pi/grep.test.ts +631 -632
- package/src/pi/model-budgets.test.ts +43 -0
- package/src/pi/model-budgets.ts +44 -0
- package/src/pi/mutation-outcome.testing.ts +5 -5
- package/src/pi/mutation-result.test.ts +21 -74
- package/src/pi/mutation-result.ts +74 -87
- package/src/pi/mutation-runner.ts +83 -75
- package/src/pi/output-budgets.test.ts +166 -0
- package/src/pi/path.ts +7 -0
- package/src/pi/read-tool.ts +151 -137
- package/src/pi/read.test.ts +39 -33
- package/src/pi/regex-worker-contract.ts +73 -0
- package/src/pi/regex-worker.ts +101 -0
- package/src/pi/registration.test.ts +111 -92
- package/src/pi/render.test.ts +193 -19
- package/src/pi/render.ts +137 -29
- package/src/pi/replace-regex.ts +11 -44
- package/src/pi/replace-tool.ts +38 -145
- package/src/pi/replace-worker-contract.ts +19 -0
- package/src/pi/replace-worker.ts +12 -8
- package/src/pi/replace.test.ts +93 -160
- package/src/pi/report-cause.ts +99 -0
- package/src/pi/report-failure.testing.ts +20 -0
- package/src/pi/report-schema.ts +512 -0
- package/src/pi/report.test.ts +276 -0
- package/src/pi/report.ts +288 -0
- package/src/pi/result-safety.test.ts +122 -427
- package/src/pi/rg-process.test.ts +78 -79
- package/src/pi/rg-process.ts +124 -177
- package/src/pi/rg-regex.test.ts +50 -0
- package/src/pi/rg-regex.ts +709 -0
- package/src/pi/text-stream.test.ts +67 -38
- package/src/pi/text-stream.ts +96 -75
- package/src/pi/tool-call.testing.ts +3 -39
- package/src/pi/write-tool.ts +45 -34
- package/src/pi/write.test.ts +45 -37
- package/src/testing/extension-loader.testing.ts +24 -0
- package/src/testing/installation.testing.ts +77 -0
- package/src/testing/process.testing.ts +33 -0
- package/src/testing/regex-host.testing.ts +20 -0
- package/src/testing/regex-translation-corpus.ts +308 -0
- package/src/testing/rg-line-listing.fixture.mjs +7 -0
- package/src/testing/run-tests.ts +47 -0
- package/src/testing/session.testing.ts +127 -0
- package/src/pi/rg-line-ranges.test.ts +0 -66
- package/src/pi/rg-line-ranges.ts +0 -75
- package/src/pi/rg-match-bytes.ts +0 -95
- package/src/pi/rg-text-view.ts +0 -192
- package/src/pi/tool-prompts.ts +0 -15
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectsArgument } from "../pi/argument-error.testing.ts";
|
|
1
2
|
/**
|
|
2
3
|
* Explicit integration coverage for the platform rg bundled by @vscode/ripgrep.
|
|
3
4
|
* This suite is excluded from the default test script.
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
readFile,
|
|
12
13
|
readlink,
|
|
13
14
|
rm,
|
|
15
|
+
stat,
|
|
14
16
|
symlink,
|
|
15
17
|
writeFile,
|
|
16
18
|
} from "node:fs/promises";
|
|
@@ -24,19 +26,15 @@ import { makeEditOverride } from "../pi/edit-tool.ts";
|
|
|
24
26
|
import { makeReadOverride } from "../pi/read-tool.ts";
|
|
25
27
|
import { makeWriteOverride } from "../pi/write-tool.ts";
|
|
26
28
|
import { makeReplaceTool } from "../pi/replace-tool.ts";
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
MAX_RG_RECORD_BYTES,
|
|
30
|
-
probeRegex,
|
|
31
|
-
resolveIgnoreCase,
|
|
32
|
-
runRg,
|
|
33
|
-
} from "../pi/rg-process.ts";
|
|
34
|
-
import { GREP_MAX_LINE_LENGTH } from "../pi/budgets.ts";
|
|
35
|
-
import { runRgTextView } from "../pi/rg-text-view.ts";
|
|
29
|
+
import { COMMON_RG_ARGS, MAX_RG_RECORD_BYTES, runRgPaths } from "../pi/rg-process.ts";
|
|
30
|
+
import { DEFAULT_OUTPUT_BUDGETS } from "../pi/budgets.ts";
|
|
36
31
|
import { computeLineHash } from "../core/hash.ts";
|
|
37
32
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
38
33
|
import { DEFAULT_CONFIG } from "../pi/config.ts";
|
|
39
34
|
import { canonicalPath } from "../pi/path.ts";
|
|
35
|
+
import { reportOf } from "../pi/report.ts";
|
|
36
|
+
import { expectToolFailure } from "../pi/report-failure.testing.ts";
|
|
37
|
+
import { hostCompiles, unsupportedByHost } from "../testing/regex-host.testing.ts";
|
|
40
38
|
|
|
41
39
|
const invoke = (
|
|
42
40
|
tool: any,
|
|
@@ -82,7 +80,8 @@ test("real rg finds whitespace-only literal queries and OR alternatives", async
|
|
|
82
80
|
undefined,
|
|
83
81
|
undefined,
|
|
84
82
|
);
|
|
85
|
-
assert.
|
|
83
|
+
assert.equal(reportOf(result)?.matches, expected);
|
|
84
|
+
assert.equal(reportOf(result)?.files, 1);
|
|
86
85
|
}
|
|
87
86
|
const lineBreaks = await invoke(
|
|
88
87
|
tool,
|
|
@@ -91,7 +90,8 @@ test("real rg finds whitespace-only literal queries and OR alternatives", async
|
|
|
91
90
|
undefined,
|
|
92
91
|
undefined,
|
|
93
92
|
);
|
|
94
|
-
assert.
|
|
93
|
+
assert.equal(reportOf(lineBreaks)?.matches, 3);
|
|
94
|
+
assert.equal(reportOf(lineBreaks)?.files, 1);
|
|
95
95
|
} finally {
|
|
96
96
|
await rm(directory, { recursive: true, force: true });
|
|
97
97
|
}
|
|
@@ -121,8 +121,9 @@ test("real rg uses smart-case across OR patterns and Unicode matches", async ()
|
|
|
121
121
|
assert.match(mixed.content[0].text, /fixture\.ts · 2 matches/);
|
|
122
122
|
assert.doesNotMatch(mixed.content[0].text, /│FOO abc/);
|
|
123
123
|
const unicode = await invoke(tool, "0", { literal: true, pattern: "k" }, undefined, undefined);
|
|
124
|
-
assert.match(unicode.content[0].text, /fixture\.ts ·
|
|
125
|
-
assert.match(unicode.content[0].text,
|
|
124
|
+
assert.match(unicode.content[0].text, /fixture\.ts · 1 match/);
|
|
125
|
+
assert.match(unicode.content[0].text, /│k zip/);
|
|
126
|
+
assert.doesNotMatch(unicode.content[0].text, /│K zip/);
|
|
126
127
|
} finally {
|
|
127
128
|
await rm(directory, { recursive: true, force: true });
|
|
128
129
|
}
|
|
@@ -159,6 +160,7 @@ test("explicit ignoreCase overrides smart-case for regex and literal queries", a
|
|
|
159
160
|
undefined,
|
|
160
161
|
);
|
|
161
162
|
assert.match(regex.content[0].text, /fixture\.txt · 2 matches/);
|
|
163
|
+
if (!hostCompiles("(?i:a)")) return;
|
|
162
164
|
const inlineSensitive = await invoke(
|
|
163
165
|
tool,
|
|
164
166
|
"0",
|
|
@@ -180,69 +182,6 @@ test("explicit ignoreCase overrides smart-case for regex and literal queries", a
|
|
|
180
182
|
}
|
|
181
183
|
});
|
|
182
184
|
|
|
183
|
-
test("real rg resolves regex-aware smart-case decisions", async () => {
|
|
184
|
-
const cases = new Map<string, boolean>([
|
|
185
|
-
["foo", true],
|
|
186
|
-
["Foo", false],
|
|
187
|
-
["foo\\S*", true],
|
|
188
|
-
["foo\\D+", true],
|
|
189
|
-
["foo\\W+", true],
|
|
190
|
-
["foo\\p{Lu}*", true],
|
|
191
|
-
["(?P<UPPER>foo)$", true],
|
|
192
|
-
["foo[A-Z]", false],
|
|
193
|
-
["\\x66oo", true],
|
|
194
|
-
["\\x46oo", false],
|
|
195
|
-
["\\w", false],
|
|
196
|
-
["\\p{Lu}", false],
|
|
197
|
-
]);
|
|
198
|
-
for (const [pattern, expected] of cases) {
|
|
199
|
-
assert.equal(
|
|
200
|
-
await resolveIgnoreCase(rgPath!, [pattern], { literal: false, multiline: false }, undefined),
|
|
201
|
-
expected,
|
|
202
|
-
pattern,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
assert.equal(
|
|
206
|
-
await resolveIgnoreCase(rgPath!, ["foo\\S*"], { literal: true, multiline: false }, undefined),
|
|
207
|
-
false,
|
|
208
|
-
);
|
|
209
|
-
assert.equal(
|
|
210
|
-
await resolveIgnoreCase(
|
|
211
|
-
rgPath!,
|
|
212
|
-
["(a)", "Foo"],
|
|
213
|
-
{ literal: false, multiline: false },
|
|
214
|
-
undefined,
|
|
215
|
-
),
|
|
216
|
-
false,
|
|
217
|
-
);
|
|
218
|
-
assert.equal(
|
|
219
|
-
await resolveIgnoreCase(rgPath!, ["foo\\nbar"], { literal: false, multiline: true }, undefined),
|
|
220
|
-
true,
|
|
221
|
-
);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("real rg accepts Rust regex syntax and rejects unsupported lookarounds", async () => {
|
|
225
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-regex-engine-"));
|
|
226
|
-
try {
|
|
227
|
-
await writeFile(join(directory, "fixture.ts"), "FOO abc\nfoo BAR\nfoo bar\n");
|
|
228
|
-
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
229
|
-
const result = await invoke(
|
|
230
|
-
tool,
|
|
231
|
-
"0",
|
|
232
|
-
{ pattern: "(?P<name>foo)\\S*", literal: false },
|
|
233
|
-
undefined,
|
|
234
|
-
undefined,
|
|
235
|
-
);
|
|
236
|
-
assert.match(result.content[0].text, /│foo BAR/);
|
|
237
|
-
await assert.rejects(
|
|
238
|
-
invoke(tool, "0", { pattern: "foo(?= BAR)", literal: false }, undefined, undefined),
|
|
239
|
-
/regex parse error/,
|
|
240
|
-
);
|
|
241
|
-
} finally {
|
|
242
|
-
await rm(directory, { recursive: true, force: true });
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
|
|
246
185
|
test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
|
|
247
186
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-config-"));
|
|
248
187
|
const previous = process.env.RIPGREP_CONFIG_PATH;
|
|
@@ -266,10 +205,9 @@ test("owned rg processes ignore RIPGREP_CONFIG_PATH", async () => {
|
|
|
266
205
|
assert.match(result.content[0].text, /│foo/);
|
|
267
206
|
assert.match(result.content[0].text, /│FOO/);
|
|
268
207
|
assert.doesNotMatch(result.content[0].text, /│bar/);
|
|
269
|
-
await
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
);
|
|
208
|
+
const lineOnly = await invoke(tool, "0", { pattern: "foo\\nbar", literal: false });
|
|
209
|
+
assert.equal(lineOnly.isError, undefined);
|
|
210
|
+
assert.equal(reportOf(lineOnly)?.matches, 0);
|
|
273
211
|
const multiline = await invoke(
|
|
274
212
|
tool,
|
|
275
213
|
"0",
|
|
@@ -295,9 +233,11 @@ test("real rg requires an explicit mode and separates exact text from regex", as
|
|
|
295
233
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
296
234
|
await assert.rejects(
|
|
297
235
|
invoke(tool, "missing-mode", { pattern: "foo" }),
|
|
298
|
-
/
|
|
236
|
+
rejectsArgument("literal", /required/),
|
|
299
237
|
);
|
|
300
|
-
for (const pattern of ["(?i
|
|
238
|
+
for (const pattern of ["(?i:^foo$)", "(?<name>foo)$"].filter((source) =>
|
|
239
|
+
hostCompiles(source),
|
|
240
|
+
)) {
|
|
301
241
|
const result = await invoke(tool, "regex", { pattern, literal: false });
|
|
302
242
|
assert.match(result.content[0].text, /│foo/);
|
|
303
243
|
}
|
|
@@ -309,14 +249,15 @@ test("real rg requires an explicit mode and separates exact text from regex", as
|
|
|
309
249
|
assert.ok(result.content[0].text.includes(`│${pattern}`));
|
|
310
250
|
}
|
|
311
251
|
const missing = await invoke(tool, "no-match", { pattern: "missing(", literal: true });
|
|
312
|
-
assert.equal(missing
|
|
252
|
+
assert.equal(reportOf(missing)?.matches, 0);
|
|
253
|
+
assert.equal(missing.isError, undefined);
|
|
313
254
|
await assert.rejects(
|
|
314
255
|
invoke(tool, "invalid-regex", { pattern: "queueTool(", literal: false }),
|
|
315
|
-
/
|
|
256
|
+
rejectsArgument("pattern", /Invalid regular expression/),
|
|
316
257
|
);
|
|
317
258
|
await assert.rejects(
|
|
318
259
|
invoke(tool, "invalid-array", { pattern: ["queueTool(", "\\bfoo\\b"], literal: false }),
|
|
319
|
-
/
|
|
260
|
+
rejectsArgument("pattern[0]", /Invalid regular expression/),
|
|
320
261
|
);
|
|
321
262
|
} finally {
|
|
322
263
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -364,7 +305,7 @@ test("real rg finds a late OR match and respects the line limit", async () => {
|
|
|
364
305
|
undefined,
|
|
365
306
|
);
|
|
366
307
|
assert.match(result.content[0].text, /4097#[0-9A-Z]+│foo keep/);
|
|
367
|
-
assert.
|
|
308
|
+
assert.equal(reportOf(result)?.matchLimit, 1);
|
|
368
309
|
} finally {
|
|
369
310
|
await rm(directory, { recursive: true, force: true });
|
|
370
311
|
}
|
|
@@ -375,38 +316,25 @@ test("shared rg runner stops and cleans up after limits, callback failures, and
|
|
|
375
316
|
try {
|
|
376
317
|
const file = join(directory, "fixture.txt");
|
|
377
318
|
await writeFile(file, "needle\n".repeat(10_000));
|
|
378
|
-
const args = [
|
|
379
|
-
|
|
380
|
-
"--engine=default",
|
|
381
|
-
"--no-multiline",
|
|
382
|
-
"--json",
|
|
383
|
-
"-e",
|
|
384
|
-
"needle",
|
|
385
|
-
"--",
|
|
386
|
-
file,
|
|
387
|
-
];
|
|
388
|
-
const stopped = await runRg(rgPath, args, undefined, () => false);
|
|
319
|
+
const args = [...COMMON_RG_ARGS, "--files", "--null", "--", file];
|
|
320
|
+
const stopped = await runRgPaths(rgPath, args, undefined, () => false);
|
|
389
321
|
assert.equal(stopped.stopped, true);
|
|
390
322
|
await assert.rejects(
|
|
391
|
-
|
|
323
|
+
runRgPaths(rgPath, args, undefined, () => {
|
|
392
324
|
throw new Error("callback failed");
|
|
393
325
|
}),
|
|
394
326
|
/callback failed/,
|
|
395
327
|
);
|
|
396
328
|
const controller = new AbortController();
|
|
397
329
|
await assert.rejects(
|
|
398
|
-
|
|
330
|
+
runRgPaths(rgPath, args, controller.signal, () => {
|
|
399
331
|
controller.abort();
|
|
400
332
|
return true;
|
|
401
333
|
}),
|
|
402
334
|
/Operation aborted/,
|
|
403
335
|
);
|
|
404
336
|
await assert.rejects(
|
|
405
|
-
|
|
406
|
-
/Failed to run ripgrep/,
|
|
407
|
-
);
|
|
408
|
-
await assert.rejects(
|
|
409
|
-
probeRegex(join(directory, "missing-rg"), ["needle"], false),
|
|
337
|
+
runRgPaths(join(directory, "missing-rg"), [], undefined, () => true),
|
|
410
338
|
/Failed to run ripgrep/,
|
|
411
339
|
);
|
|
412
340
|
} finally {
|
|
@@ -428,7 +356,7 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
428
356
|
undefined,
|
|
429
357
|
undefined,
|
|
430
358
|
);
|
|
431
|
-
assert.equal(normal
|
|
359
|
+
assert.equal(reportOf(normal)?.matches, 0);
|
|
432
360
|
const explicit = await invoke(
|
|
433
361
|
tool,
|
|
434
362
|
"0",
|
|
@@ -444,7 +372,7 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
444
372
|
undefined,
|
|
445
373
|
undefined,
|
|
446
374
|
);
|
|
447
|
-
assert.equal(excluded
|
|
375
|
+
assert.equal(reportOf(excluded)?.matches, 0);
|
|
448
376
|
await writeFile(join(directory, ".hidden.txt"), "needle\n");
|
|
449
377
|
const hidden = await invoke(
|
|
450
378
|
tool,
|
|
@@ -460,6 +388,112 @@ test("directory searches respect ignores but explicit files and hidden files rem
|
|
|
460
388
|
}
|
|
461
389
|
});
|
|
462
390
|
|
|
391
|
+
test("directory traversal with caller globs → excludes .git while an explicit .git path remains searchable", async (t) => {
|
|
392
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-git-scope-"));
|
|
393
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
394
|
+
const git = join(directory, ".git");
|
|
395
|
+
await mkdir(git);
|
|
396
|
+
await writeFile(join(git, "x.txt"), "needle\n");
|
|
397
|
+
await writeFile(join(directory, "a.txt"), "needle\n");
|
|
398
|
+
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
399
|
+
for (const multiline of [false, true]) {
|
|
400
|
+
for (const glob of [undefined, "*"]) {
|
|
401
|
+
for (const [path, expected] of [
|
|
402
|
+
[directory, "a.txt"],
|
|
403
|
+
[git, ".git/x.txt"],
|
|
404
|
+
]) {
|
|
405
|
+
const result = await callTool(tool, {
|
|
406
|
+
path,
|
|
407
|
+
glob,
|
|
408
|
+
multiline,
|
|
409
|
+
literal: true,
|
|
410
|
+
pattern: "needle",
|
|
411
|
+
outputMode: "files",
|
|
412
|
+
});
|
|
413
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result)));
|
|
414
|
+
assert.equal(reportOf(result)?.matches, 1);
|
|
415
|
+
assert.equal(result.content[0].text.replace(/\\/g, "/"), expected);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test("explicit file with different case and a glob → admits the same file on a case-insensitive filesystem", async (t) => {
|
|
422
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-case-admission-"));
|
|
423
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
424
|
+
const file = join(directory, "MiXeD.txt");
|
|
425
|
+
const requested = join(directory, "mixed.txt");
|
|
426
|
+
await writeFile(file, "needle\n");
|
|
427
|
+
let alias;
|
|
428
|
+
try {
|
|
429
|
+
alias = await stat(requested, { bigint: true });
|
|
430
|
+
} catch (error) {
|
|
431
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
432
|
+
return t.skip("Temporary filesystem is case-sensitive");
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
const original = await stat(file, { bigint: true });
|
|
436
|
+
assert.equal(alias.dev, original.dev);
|
|
437
|
+
assert.equal(alias.ino, original.ino);
|
|
438
|
+
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
439
|
+
const result = await callTool(tool, {
|
|
440
|
+
path: requested,
|
|
441
|
+
glob: "*.txt",
|
|
442
|
+
literal: true,
|
|
443
|
+
pattern: "needle",
|
|
444
|
+
});
|
|
445
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result)));
|
|
446
|
+
assert.equal(reportOf(result)?.matches, 1);
|
|
447
|
+
assert.equal(reportOf(result)?.files, 1);
|
|
448
|
+
assert.match(result.content[0].text, /1#[0-9A-Z]+│needle/);
|
|
449
|
+
assert.equal(reportOf(result)?.diagnostics, undefined);
|
|
450
|
+
assert.equal(result.details.incomplete, undefined);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
test("explicit file with a dangling sibling link and a glob → returns complete matches without listing diagnostics", async (t) => {
|
|
454
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-dangling-sibling-"));
|
|
455
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
456
|
+
const file = join(directory, "fixture.txt");
|
|
457
|
+
const link = join(directory, "broken.txt");
|
|
458
|
+
await writeFile(file, "needle\n");
|
|
459
|
+
try {
|
|
460
|
+
await symlink(
|
|
461
|
+
join(directory, "missing"),
|
|
462
|
+
link,
|
|
463
|
+
process.platform === "win32" ? "junction" : "dir",
|
|
464
|
+
);
|
|
465
|
+
} catch (error) {
|
|
466
|
+
if (
|
|
467
|
+
error instanceof Error &&
|
|
468
|
+
"code" in error &&
|
|
469
|
+
typeof error.code === "string" &&
|
|
470
|
+
["EPERM", "EACCES", "ENOTSUP"].includes(error.code)
|
|
471
|
+
)
|
|
472
|
+
return t.skip("Symbolic link creation unavailable");
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
await assert.rejects(stat(link), { code: "ENOENT" });
|
|
476
|
+
let listingDiagnostics = "";
|
|
477
|
+
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
478
|
+
runRgPaths: async (...args) => {
|
|
479
|
+
const listed = await runRgPaths(...args);
|
|
480
|
+
listingDiagnostics = listed.stderr;
|
|
481
|
+
return listed;
|
|
482
|
+
},
|
|
483
|
+
});
|
|
484
|
+
const result = await callTool(tool, {
|
|
485
|
+
path: file,
|
|
486
|
+
glob: "*.txt",
|
|
487
|
+
literal: true,
|
|
488
|
+
pattern: "needle",
|
|
489
|
+
});
|
|
490
|
+
assert.match(listingDiagnostics, /broken\.txt/);
|
|
491
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result)));
|
|
492
|
+
assert.equal(reportOf(result)?.matches, 1);
|
|
493
|
+
assert.equal(reportOf(result)?.diagnostics, undefined);
|
|
494
|
+
assert.equal(result.details.incomplete, undefined);
|
|
495
|
+
});
|
|
496
|
+
|
|
463
497
|
test("explicit file paths obey ordered glob filters without inheriting ignore rules", async () => {
|
|
464
498
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-file-glob-"));
|
|
465
499
|
try {
|
|
@@ -492,7 +526,7 @@ test("explicit file paths obey ordered glob filters without inheriting ignore ru
|
|
|
492
526
|
undefined,
|
|
493
527
|
undefined,
|
|
494
528
|
);
|
|
495
|
-
assert.equal(none
|
|
529
|
+
assert.equal(reportOf(none)?.matches, 0);
|
|
496
530
|
} finally {
|
|
497
531
|
await rm(directory, { recursive: true, force: true });
|
|
498
532
|
}
|
|
@@ -525,7 +559,7 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
525
559
|
undefined,
|
|
526
560
|
undefined,
|
|
527
561
|
);
|
|
528
|
-
assert.equal(hidden
|
|
562
|
+
assert.equal(reportOf(hidden)?.matches, 0);
|
|
529
563
|
const found: any = await invoke(
|
|
530
564
|
grep,
|
|
531
565
|
"0",
|
|
@@ -555,44 +589,14 @@ test("directory traversal skips symlinks but explicitly named linked files remai
|
|
|
555
589
|
}
|
|
556
590
|
});
|
|
557
591
|
|
|
558
|
-
test("
|
|
559
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
{ pattern: "foo(?:bar|foo)", literal: false },
|
|
567
|
-
undefined,
|
|
568
|
-
undefined,
|
|
569
|
-
);
|
|
570
|
-
assert.match(valid.content[0].text, /fixture\.txt · 2 matches/);
|
|
571
|
-
for (const pattern of ["foo(?=bar)", "(foo)\\1", ["plain", "foo(?=bar)"]]) {
|
|
572
|
-
await assert.rejects(
|
|
573
|
-
invoke(tool, "0", { pattern, literal: false }, undefined, undefined),
|
|
574
|
-
(error: Error) => {
|
|
575
|
-
assert.match(error.message, /regex parse error/);
|
|
576
|
-
assert.match(error.message, /no lookaround or backreferences/);
|
|
577
|
-
assert.match(error.message, /rewrite.*pattern/);
|
|
578
|
-
assert.match(error.message, /use replace/);
|
|
579
|
-
return true;
|
|
580
|
-
},
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
const literal = await invoke(tool, "0", { pattern: "foo(?=bar)", literal: true });
|
|
584
|
-
assert.equal(literal.content[0].text, "No matches found");
|
|
585
|
-
// A parse error without other-dialect syntax requests an exact-text search.
|
|
586
|
-
await assert.rejects(
|
|
587
|
-
invoke(tool, "0", { pattern: "foo(", literal: false }, undefined, undefined),
|
|
588
|
-
(error: Error) =>
|
|
589
|
-
/regex parse error/.test(error.message) &&
|
|
590
|
-
/literal:true/.test(error.message) &&
|
|
591
|
-
!/lookaround/.test(error.message),
|
|
592
|
-
);
|
|
593
|
-
} finally {
|
|
594
|
-
await rm(directory, { recursive: true, force: true });
|
|
595
|
-
}
|
|
592
|
+
test("unbounded lookbehind → native JS matches after rg discovery", async (t) => {
|
|
593
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-lookbehind-"));
|
|
594
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
595
|
+
await writeFile(join(directory, "fixture.txt"), "aaab\n");
|
|
596
|
+
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
597
|
+
const result = await invoke(tool, "0", { pattern: "(?<=a+)b", literal: false });
|
|
598
|
+
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result)));
|
|
599
|
+
assert.equal(reportOf(result)?.matches, 1);
|
|
596
600
|
});
|
|
597
601
|
|
|
598
602
|
test("line-based grep uses context for display but never matches across CRLF", async () => {
|
|
@@ -611,14 +615,14 @@ test("line-based grep uses context for display but never matches across CRLF", a
|
|
|
611
615
|
assert.match(context.content[0].text, /1#[0-9A-Z]+│alpha/);
|
|
612
616
|
assert.match(context.content[0].text, /2#[0-9A-Z]+│beta/);
|
|
613
617
|
assert.doesNotMatch(context.content[0].text, /3#[0-9A-Z]+│gamma/);
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
)
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
618
|
+
for (const [pattern, literal] of [
|
|
619
|
+
["alpha\\nbeta", false],
|
|
620
|
+
["alpha\nbeta", true],
|
|
621
|
+
] as const) {
|
|
622
|
+
const result = await invoke(tool, "0", { pattern, literal });
|
|
623
|
+
assert.equal(result.isError, undefined);
|
|
624
|
+
assert.equal(reportOf(result)?.matches, 0);
|
|
625
|
+
}
|
|
622
626
|
const limited = await invoke(
|
|
623
627
|
tool,
|
|
624
628
|
"0",
|
|
@@ -627,7 +631,7 @@ test("line-based grep uses context for display but never matches across CRLF", a
|
|
|
627
631
|
undefined,
|
|
628
632
|
);
|
|
629
633
|
assert.match(limited.content[0].text, /fixture\.txt: 1/);
|
|
630
|
-
assert.
|
|
634
|
+
assert.equal(reportOf(limited)?.matchLimit, 1);
|
|
631
635
|
} finally {
|
|
632
636
|
await rm(directory, { recursive: true, force: true });
|
|
633
637
|
}
|
|
@@ -669,7 +673,7 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
669
673
|
tool,
|
|
670
674
|
"0",
|
|
671
675
|
{
|
|
672
|
-
pattern: "
|
|
676
|
+
pattern: "alpha[\\w\\s]*gamma",
|
|
673
677
|
literal: false,
|
|
674
678
|
path: file,
|
|
675
679
|
multiline: true,
|
|
@@ -680,8 +684,9 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
680
684
|
undefined,
|
|
681
685
|
);
|
|
682
686
|
assert.match(bounded.content[0].text, /fixture\.txt: 2/);
|
|
683
|
-
assert.
|
|
684
|
-
assert.
|
|
687
|
+
assert.equal(reportOf(bounded)?.matches, 2);
|
|
688
|
+
assert.equal(reportOf(bounded)?.files, 1);
|
|
689
|
+
assert.equal(reportOf(bounded)?.matchLimit, 2);
|
|
685
690
|
const files = await invoke(
|
|
686
691
|
tool,
|
|
687
692
|
"0",
|
|
@@ -696,7 +701,8 @@ test("multiline grep anchors CRLF spans and counts overlapping physical lines on
|
|
|
696
701
|
undefined,
|
|
697
702
|
undefined,
|
|
698
703
|
);
|
|
699
|
-
assert.
|
|
704
|
+
assert.equal(files.content[0].text, "fixture.txt");
|
|
705
|
+
assert.equal(reportOf(files)?.matchLimit, 1);
|
|
700
706
|
const boundary = await invoke(
|
|
701
707
|
tool,
|
|
702
708
|
"0",
|
|
@@ -768,7 +774,7 @@ test("multiline grep anchors empty lines and line-start zero-width matches", asy
|
|
|
768
774
|
const starts = await invoke(
|
|
769
775
|
tool,
|
|
770
776
|
"0",
|
|
771
|
-
{ pattern: "
|
|
777
|
+
{ pattern: "^", path: file, multiline: true, literal: false },
|
|
772
778
|
undefined,
|
|
773
779
|
undefined,
|
|
774
780
|
);
|
|
@@ -780,7 +786,9 @@ test("multiline grep anchors empty lines and line-start zero-width matches", asy
|
|
|
780
786
|
}
|
|
781
787
|
});
|
|
782
788
|
|
|
783
|
-
test("multiline zero-width EOF stays on the last existing physical line",
|
|
789
|
+
test("multiline zero-width EOF stays on the last existing physical line", {
|
|
790
|
+
skip: unsupportedByHost(["(?-m:$)"]),
|
|
791
|
+
}, async () => {
|
|
784
792
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-multiline-eof-"));
|
|
785
793
|
try {
|
|
786
794
|
const file = join(directory, "fixture.txt");
|
|
@@ -790,12 +798,12 @@ test("multiline zero-width EOF stays on the last existing physical line", async
|
|
|
790
798
|
const result = await invoke(
|
|
791
799
|
tool,
|
|
792
800
|
"0",
|
|
793
|
-
{ pattern: "
|
|
801
|
+
{ pattern: "(?-m:$)", path: file, multiline: true, literal: false },
|
|
794
802
|
undefined,
|
|
795
803
|
undefined,
|
|
796
804
|
);
|
|
797
805
|
if (content.endsWith("\n")) {
|
|
798
|
-
assert.equal(result
|
|
806
|
+
assert.equal(reportOf(result)?.matches, 0);
|
|
799
807
|
} else {
|
|
800
808
|
assert.match(result.content[0].text, /fixture\.txt · 1 match/);
|
|
801
809
|
assert.match(result.content[0].text, /1#[0-9A-Z]+│last line/);
|
|
@@ -806,51 +814,6 @@ test("multiline zero-width EOF stays on the last existing physical line", async
|
|
|
806
814
|
}
|
|
807
815
|
});
|
|
808
816
|
|
|
809
|
-
test("multiline grep detects changed files and propagates cancellation", async () => {
|
|
810
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-multiline-state-"));
|
|
811
|
-
try {
|
|
812
|
-
const file = join(directory, "fixture.txt");
|
|
813
|
-
await writeFile(file, "alpha\nbeta\n");
|
|
814
|
-
const changing = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
815
|
-
async search(path, request, signal, onLine) {
|
|
816
|
-
const result = await runRgTextView(path, request, signal, onLine);
|
|
817
|
-
await writeFile(file, "alpha\nchanged\n");
|
|
818
|
-
return result;
|
|
819
|
-
},
|
|
820
|
-
});
|
|
821
|
-
await assert.rejects(
|
|
822
|
-
invoke(
|
|
823
|
-
changing,
|
|
824
|
-
"0",
|
|
825
|
-
{ pattern: "alpha\\nbeta", path: file, multiline: true, literal: false },
|
|
826
|
-
undefined,
|
|
827
|
-
undefined,
|
|
828
|
-
),
|
|
829
|
-
/File changed during search/,
|
|
830
|
-
);
|
|
831
|
-
await writeFile(file, "alpha\nbeta\n");
|
|
832
|
-
const controller = new AbortController();
|
|
833
|
-
const cancelling = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
834
|
-
search(path, request, signal, onLine) {
|
|
835
|
-
controller.abort();
|
|
836
|
-
return runRgTextView(path, request, signal, onLine);
|
|
837
|
-
},
|
|
838
|
-
});
|
|
839
|
-
await assert.rejects(
|
|
840
|
-
invoke(
|
|
841
|
-
cancelling,
|
|
842
|
-
"0",
|
|
843
|
-
{ pattern: "alpha\\nbeta", path: file, multiline: true, literal: false },
|
|
844
|
-
controller.signal,
|
|
845
|
-
undefined,
|
|
846
|
-
),
|
|
847
|
-
/Operation aborted/,
|
|
848
|
-
);
|
|
849
|
-
} finally {
|
|
850
|
-
await rm(directory, { recursive: true, force: true });
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
|
|
854
817
|
test("files and count modes aggregate only matching lines inside the limit", async () => {
|
|
855
818
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-output-modes-"));
|
|
856
819
|
try {
|
|
@@ -867,7 +830,8 @@ test("files and count modes aggregate only matching lines inside the limit", asy
|
|
|
867
830
|
undefined,
|
|
868
831
|
undefined,
|
|
869
832
|
);
|
|
870
|
-
assert.match(files.content[0].text, /^(?:a|b)\.txt
|
|
833
|
+
assert.match(files.content[0].text, /^(?:a|b)\.txt$/);
|
|
834
|
+
assert.equal(reportOf(files)?.matchLimit, 1);
|
|
871
835
|
const limited = await invoke(
|
|
872
836
|
tool,
|
|
873
837
|
"count",
|
|
@@ -875,7 +839,8 @@ test("files and count modes aggregate only matching lines inside the limit", asy
|
|
|
875
839
|
undefined,
|
|
876
840
|
undefined,
|
|
877
841
|
);
|
|
878
|
-
assert.
|
|
842
|
+
assert.equal(reportOf(limited)?.matches, 1);
|
|
843
|
+
assert.equal(reportOf(limited)?.files, 1);
|
|
879
844
|
const complete = await invoke(
|
|
880
845
|
tool,
|
|
881
846
|
"count-all",
|
|
@@ -883,7 +848,8 @@ test("files and count modes aggregate only matching lines inside the limit", asy
|
|
|
883
848
|
undefined,
|
|
884
849
|
undefined,
|
|
885
850
|
);
|
|
886
|
-
assert.
|
|
851
|
+
assert.equal(reportOf(complete)?.matches, 3);
|
|
852
|
+
assert.equal(reportOf(complete)?.files, 2);
|
|
887
853
|
const contextual = await invoke(
|
|
888
854
|
tool,
|
|
889
855
|
"content",
|
|
@@ -898,69 +864,15 @@ test("files and count modes aggregate only matching lines inside the limit", asy
|
|
|
898
864
|
}
|
|
899
865
|
});
|
|
900
866
|
|
|
901
|
-
test("default grep rejects file changes and propagates cancellation", async () => {
|
|
902
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-default-state-"));
|
|
903
|
-
try {
|
|
904
|
-
const file = join(directory, "fixture.txt");
|
|
905
|
-
await writeFile(file, "foo bar\n");
|
|
906
|
-
const changing = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
907
|
-
async search(path, request, signal, onLine) {
|
|
908
|
-
const result = await runRgTextView(path, request, signal, onLine);
|
|
909
|
-
await writeFile(file, "changed content\n");
|
|
910
|
-
return result;
|
|
911
|
-
},
|
|
912
|
-
});
|
|
913
|
-
await assert.rejects(
|
|
914
|
-
invoke(changing, "0", { literal: true, pattern: "foo", path: file }, undefined, undefined),
|
|
915
|
-
/File changed during search/,
|
|
916
|
-
);
|
|
917
|
-
|
|
918
|
-
await writeFile(file, "foo bar\n");
|
|
919
|
-
const controller = new AbortController();
|
|
920
|
-
const cancelling = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
921
|
-
search(path, request, signal, onLine) {
|
|
922
|
-
controller.abort();
|
|
923
|
-
return runRgTextView(path, request, signal, onLine);
|
|
924
|
-
},
|
|
925
|
-
});
|
|
926
|
-
await assert.rejects(
|
|
927
|
-
invoke(
|
|
928
|
-
cancelling,
|
|
929
|
-
"0",
|
|
930
|
-
{ literal: true, pattern: "foo", path: file },
|
|
931
|
-
controller.signal,
|
|
932
|
-
undefined,
|
|
933
|
-
),
|
|
934
|
-
/Operation aborted/,
|
|
935
|
-
);
|
|
936
|
-
} finally {
|
|
937
|
-
await rm(directory, { recursive: true, force: true });
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
test("owned rg rejects an oversized JSONL record", async () => {
|
|
942
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-record-limit-"));
|
|
943
|
-
try {
|
|
944
|
-
await writeFile(join(directory, "large.txt"), `needle${"x".repeat(MAX_RG_RECORD_BYTES + 1)}\n`);
|
|
945
|
-
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
946
|
-
await assert.rejects(
|
|
947
|
-
invoke(tool, "0", { pattern: "needle", literal: true }, undefined, undefined),
|
|
948
|
-
new RegExp(`record exceeds ${MAX_RG_RECORD_BYTES / 1024 ** 2} MiB`),
|
|
949
|
-
);
|
|
950
|
-
} finally {
|
|
951
|
-
await rm(directory, { recursive: true, force: true });
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
|
|
955
867
|
test("real rg accepts wildcard-only regexes and preserves limits and literal mode", async () => {
|
|
956
868
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-wildcard-"));
|
|
957
869
|
try {
|
|
958
870
|
await writeFile(join(directory, "fixture.txt"), "first\n\n.*\n");
|
|
959
871
|
const tool = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {});
|
|
960
872
|
for (const [pattern, expected] of [
|
|
961
|
-
[".*", 3],
|
|
962
|
-
["
|
|
963
|
-
["
|
|
873
|
+
["[\\w.*]*", 3],
|
|
874
|
+
["^[\\w.*]+$", 2],
|
|
875
|
+
["[\\w.*]?", 3],
|
|
964
876
|
] as const) {
|
|
965
877
|
const result: any = await invoke(
|
|
966
878
|
tool,
|
|
@@ -969,12 +881,13 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
969
881
|
undefined,
|
|
970
882
|
undefined,
|
|
971
883
|
);
|
|
972
|
-
assert.
|
|
884
|
+
assert.equal(reportOf(result)?.matches, expected);
|
|
885
|
+
assert.equal(reportOf(result)?.files, 1);
|
|
973
886
|
}
|
|
974
887
|
const limited: any = await invoke(
|
|
975
888
|
tool,
|
|
976
889
|
"limited",
|
|
977
|
-
{ pattern: ".*", literal: false, limit: 1 },
|
|
890
|
+
{ pattern: "[\\w.*]*", literal: false, limit: 1 },
|
|
978
891
|
undefined,
|
|
979
892
|
undefined,
|
|
980
893
|
);
|
|
@@ -989,8 +902,8 @@ test("real rg accepts wildcard-only regexes and preserves limits and literal mod
|
|
|
989
902
|
);
|
|
990
903
|
assert.match(literal.content[0].text, /3#[0-9A-Z]+│\.\*/);
|
|
991
904
|
await assert.rejects(
|
|
992
|
-
invoke(tool, "invalid", { pattern: "*", literal: false }
|
|
993
|
-
/
|
|
905
|
+
invoke(tool, "invalid", { pattern: "*", literal: false }),
|
|
906
|
+
rejectsArgument("pattern", /Invalid regular expression/),
|
|
994
907
|
);
|
|
995
908
|
} finally {
|
|
996
909
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -1037,23 +950,19 @@ test("tools share physical lines and anchors across text representations", async
|
|
|
1037
950
|
assert.match(edit.details.diff, /^\+2 new/m);
|
|
1038
951
|
assert.ok(!edit.details.diff.includes("\r"));
|
|
1039
952
|
if (before.includes("a\rb")) assert.ok(edit.details.patch.includes(" a\rb\n"));
|
|
1040
|
-
const editedRead = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
|
|
1041
|
-
assert.equal(rows(edit)[0], rows(editedRead)[1].split("│")[0]);
|
|
1042
953
|
const replaced = await call(makeReplaceTool(directory, DEFAULT_CONFIG), {
|
|
1043
954
|
path: file,
|
|
1044
955
|
replacements: [{ find: "new", replace: "next" }],
|
|
1045
956
|
});
|
|
1046
957
|
assert.equal(await readFile(file, "utf8"), before.replace("old", "next"));
|
|
1047
958
|
assert.equal(replaced.details.firstChangedLine, 2);
|
|
1048
|
-
const replacedRead = await call(makeReadOverride(directory, DEFAULT_CONFIG), { path: file });
|
|
1049
|
-
assert.equal(rows(replaced)[0], rows(replacedRead)[1].split("│")[0]);
|
|
1050
959
|
}
|
|
1051
960
|
} finally {
|
|
1052
961
|
await rm(directory, { recursive: true, force: true });
|
|
1053
962
|
}
|
|
1054
963
|
});
|
|
1055
964
|
|
|
1056
|
-
test("long-line previews preserve full-line anchors across literal and
|
|
965
|
+
test("long-line previews preserve full-line anchors across literal and JavaScript regex queries", async () => {
|
|
1057
966
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-preview-"));
|
|
1058
967
|
try {
|
|
1059
968
|
const long = "😀界".repeat(220) + "NEEDLE" + "tail".repeat(200);
|
|
@@ -1079,10 +988,10 @@ test("long-line previews preserve full-line anchors across literal and Rust rege
|
|
|
1079
988
|
assert.equal(Buffer.from(row).toString("utf8"), row);
|
|
1080
989
|
assert.ok(
|
|
1081
990
|
output.includes(
|
|
1082
|
-
`3#${computeLineHash(3, context, 4)}│[partial, columns 1-${
|
|
991
|
+
`3#${computeLineHash(3, context, 4)}│[partial, columns 1-${DEFAULT_OUTPUT_BUDGETS.grepPreviewUnits - 1}]`,
|
|
1083
992
|
),
|
|
1084
993
|
);
|
|
1085
|
-
assert.
|
|
994
|
+
assert.equal(reportOf(result)?.linePreviewLimit, DEFAULT_OUTPUT_BUDGETS.grepPreviewUnits);
|
|
1086
995
|
}
|
|
1087
996
|
} finally {
|
|
1088
997
|
await rm(directory, { recursive: true, force: true });
|
|
@@ -1270,8 +1179,8 @@ test("visible source escapes remain readable and searchable while real CRLF stay
|
|
|
1270
1179
|
}
|
|
1271
1180
|
});
|
|
1272
1181
|
|
|
1273
|
-
test("
|
|
1274
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-
|
|
1182
|
+
test("grep retains original paths and ignores unmatched invalid UTF-8 across many files", async () => {
|
|
1183
|
+
const directory = await mkdtemp(join(tmpdir(), "hl-grep-many-files-"));
|
|
1275
1184
|
try {
|
|
1276
1185
|
await Promise.all(
|
|
1277
1186
|
Array.from({ length: 70 }, (_, i) => writeFile(join(directory, `file ${i}.txt`), "--\r\n")),
|
|
@@ -1315,7 +1224,8 @@ test("NUL files are silently skipped across search scopes and output modes", asy
|
|
|
1315
1224
|
undefined,
|
|
1316
1225
|
undefined,
|
|
1317
1226
|
);
|
|
1318
|
-
assert.equal(skipped
|
|
1227
|
+
assert.equal(reportOf(skipped)?.matches, 0);
|
|
1228
|
+
assert.equal(reportOf(skipped)?.diagnostics, undefined);
|
|
1319
1229
|
const result = await invoke(
|
|
1320
1230
|
grep,
|
|
1321
1231
|
"directory",
|
|
@@ -1354,7 +1264,7 @@ test("invalid UTF-8 matches use plain previews while valid files retain edit anc
|
|
|
1354
1264
|
undefined,
|
|
1355
1265
|
);
|
|
1356
1266
|
assert.match(result.content[0].text, /1│before\n2│needle �\n3│after/);
|
|
1357
|
-
assert.
|
|
1267
|
+
assert.deepEqual(reportOf(result)?.invalidUtf8, ["invalid.txt"]);
|
|
1358
1268
|
assert.doesNotMatch(result.content[0].text, /\d+#/);
|
|
1359
1269
|
assert.equal(result.details?.incomplete, undefined);
|
|
1360
1270
|
assert.deepEqual(await readFile(invalid), source);
|
|
@@ -1384,21 +1294,12 @@ test("invalid UTF-8 matches use plain previews while valid files retain edit anc
|
|
|
1384
1294
|
const multiline = await invoke(
|
|
1385
1295
|
grep,
|
|
1386
1296
|
"multiline",
|
|
1387
|
-
{ path: invalid, pattern: "needle
|
|
1388
|
-
undefined,
|
|
1389
|
-
undefined,
|
|
1390
|
-
);
|
|
1391
|
-
// Raw-byte regex matching follows rg semantics: dot does not match malformed UTF-8.
|
|
1392
|
-
assert.equal(multiline.content[0].text, "No matches found");
|
|
1393
|
-
const rawBoundary = await invoke(
|
|
1394
|
-
grep,
|
|
1395
|
-
"raw-boundary",
|
|
1396
|
-
{ path: invalid, pattern: "(?-u:needle[^\\r]*\\r\\nafter)", literal: false, multiline: true },
|
|
1297
|
+
{ path: invalid, pattern: "needle[\\w ]*\\nafter", literal: false, multiline: true },
|
|
1397
1298
|
undefined,
|
|
1398
1299
|
undefined,
|
|
1399
1300
|
);
|
|
1400
|
-
|
|
1401
|
-
assert.
|
|
1301
|
+
// The explicit class excludes the replacement character in the lossy view.
|
|
1302
|
+
assert.equal(reportOf(multiline)?.matches, 0);
|
|
1402
1303
|
} finally {
|
|
1403
1304
|
await rm(directory, { recursive: true, force: true });
|
|
1404
1305
|
}
|
|
@@ -1457,7 +1358,7 @@ test("grep paths with input shorthand or literal separators still edit the searc
|
|
|
1457
1358
|
}
|
|
1458
1359
|
});
|
|
1459
1360
|
|
|
1460
|
-
test("literal CRLF queries
|
|
1361
|
+
test("literal LF and CRLF queries match original valid and invalid UTF-8 files alike", async (t) => {
|
|
1461
1362
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-raw-crlf-"));
|
|
1462
1363
|
try {
|
|
1463
1364
|
await writeFile(join(directory, "valid.txt"), "alpha\r\nbeta\r\n");
|
|
@@ -1481,7 +1382,8 @@ test("literal CRLF queries use the corresponding UTF-8 and raw-byte search views
|
|
|
1481
1382
|
assert.match(result.content[0].text, /1│alpha\n2│beta/);
|
|
1482
1383
|
assert.match(result.content[0].text, /1#[0-9A-Z]+│alpha\n2#[0-9A-Z]+│beta/);
|
|
1483
1384
|
} else if (outputMode === "count") {
|
|
1484
|
-
assert.
|
|
1385
|
+
assert.equal(reportOf(result)?.matches, 4);
|
|
1386
|
+
assert.equal(reportOf(result)?.files, 2);
|
|
1485
1387
|
}
|
|
1486
1388
|
assert.equal(result.details?.incomplete, undefined);
|
|
1487
1389
|
const lf = await invoke(grep, "lf", {
|
|
@@ -1492,7 +1394,7 @@ test("literal CRLF queries use the corresponding UTF-8 and raw-byte search views
|
|
|
1492
1394
|
outputMode,
|
|
1493
1395
|
});
|
|
1494
1396
|
assert.match(lf.content[0].text, /valid\.txt/);
|
|
1495
|
-
assert.
|
|
1397
|
+
assert.match(lf.content[0].text, /invalid\.txt/);
|
|
1496
1398
|
});
|
|
1497
1399
|
}
|
|
1498
1400
|
} finally {
|
|
@@ -1500,108 +1402,24 @@ test("literal CRLF queries use the corresponding UTF-8 and raw-byte search views
|
|
|
1500
1402
|
}
|
|
1501
1403
|
});
|
|
1502
1404
|
|
|
1503
|
-
test("
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
let changed = false;
|
|
1524
|
-
const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
1525
|
-
search(path, request, signal, onLine) {
|
|
1526
|
-
return runRgTextView(path, request, signal, async (...event) => {
|
|
1527
|
-
if (!changed && JSON.parse(event[0]).type === "match") {
|
|
1528
|
-
changed = true;
|
|
1529
|
-
await writeFile(file, changedSource);
|
|
1530
|
-
}
|
|
1531
|
-
return onLine(...event);
|
|
1532
|
-
});
|
|
1533
|
-
},
|
|
1534
|
-
});
|
|
1535
|
-
const boundary = separator === "\r\n" ? "\\r\\n" : "\\n";
|
|
1536
|
-
await assert.rejects(
|
|
1537
|
-
invoke(grep, "changed", {
|
|
1538
|
-
path: file,
|
|
1539
|
-
pattern:
|
|
1540
|
-
mode === "limited"
|
|
1541
|
-
? `before${boundary}(?-u:[^\\r\\n]*\\xFF)`
|
|
1542
|
-
: mode === "eof"
|
|
1543
|
-
? `(?-u:\\xFF${boundary}after${boundary})\\z`
|
|
1544
|
-
: `(?-u:\\xFF${multiline ? `${boundary}after` : ""})`,
|
|
1545
|
-
literal: false,
|
|
1546
|
-
ignoreCase: false,
|
|
1547
|
-
multiline,
|
|
1548
|
-
...(mode === "limited" || mode === "eof" ? { limit: 1 } : {}),
|
|
1549
|
-
outputMode,
|
|
1550
|
-
}),
|
|
1551
|
-
/File changed during search/,
|
|
1552
|
-
);
|
|
1553
|
-
assert.equal(changed, true);
|
|
1554
|
-
assert.deepEqual(await readFile(file), changedSource);
|
|
1555
|
-
});
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
} finally {
|
|
1560
|
-
await rm(directory, { recursive: true, force: true });
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
|
|
1564
|
-
test("raw files lost before summary verification leave only confirmed counts and an incomplete notice", async (t) => {
|
|
1565
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-grep-raw-summary-"));
|
|
1566
|
-
try {
|
|
1567
|
-
const invalid = join(directory, "invalid.txt");
|
|
1568
|
-
const valid = join(directory, "valid.txt");
|
|
1569
|
-
for (const outputMode of ["files", "count"] as const) {
|
|
1570
|
-
for (const keepValid of [true, false]) {
|
|
1571
|
-
await t.test(`${outputMode} ${keepValid}`, async () => {
|
|
1572
|
-
await writeFile(invalid, Buffer.concat([Buffer.from("needle "), Buffer.from([0xff])]));
|
|
1573
|
-
await writeFile(valid, "needle\n");
|
|
1574
|
-
const grep = makeGrepOverrideWithBackend(directory, DEFAULT_CONFIG, {
|
|
1575
|
-
async search(...args) {
|
|
1576
|
-
const result = await runRgTextView(...args);
|
|
1577
|
-
await rm(invalid);
|
|
1578
|
-
return result;
|
|
1579
|
-
},
|
|
1580
|
-
});
|
|
1581
|
-
const result = invoke(grep, "summary", {
|
|
1582
|
-
path: keepValid ? [invalid, valid] : invalid,
|
|
1583
|
-
pattern: "needle",
|
|
1584
|
-
literal: true,
|
|
1585
|
-
limit: keepValid ? 2 : 1,
|
|
1586
|
-
outputMode,
|
|
1587
|
-
});
|
|
1588
|
-
if (!keepValid) {
|
|
1589
|
-
await assert.rejects(result, /No matches could be displayed\.[\s\S]*Search incomplete/);
|
|
1590
|
-
return;
|
|
1591
|
-
}
|
|
1592
|
-
const summary = await result;
|
|
1593
|
-
assert.equal(summary.details?.incomplete, true);
|
|
1594
|
-
const shown = summary.content[0].text.split("\n\n[")[0];
|
|
1595
|
-
assert.equal(
|
|
1596
|
-
shown,
|
|
1597
|
-
outputMode === "files" ? "valid.txt" : "valid.txt: 1\nTotal: 1 match in 1 file",
|
|
1598
|
-
);
|
|
1599
|
-
assert.match(summary.content[0].text, /2 matches limit reached/);
|
|
1600
|
-
assert.match(summary.content[0].text, /Could not read .*invalid\.txt/);
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
} finally {
|
|
1605
|
-
await rm(directory, { recursive: true, force: true });
|
|
1606
|
-
}
|
|
1405
|
+
test("oversized candidate path record → bounded runner rejects before invoking its consumer", async () => {
|
|
1406
|
+
let called = false;
|
|
1407
|
+
await assert.rejects(
|
|
1408
|
+
runRgPaths(
|
|
1409
|
+
process.execPath,
|
|
1410
|
+
[
|
|
1411
|
+
"--input-type=module",
|
|
1412
|
+
"--eval",
|
|
1413
|
+
"process.stdout.write(Buffer.alloc(Number(process.argv[1]), 97))",
|
|
1414
|
+
String(MAX_RG_RECORD_BYTES + 1),
|
|
1415
|
+
],
|
|
1416
|
+
AbortSignal.timeout(10_000),
|
|
1417
|
+
() => {
|
|
1418
|
+
called = true;
|
|
1419
|
+
return true;
|
|
1420
|
+
},
|
|
1421
|
+
),
|
|
1422
|
+
(error: unknown) => error instanceof Error && error.message.includes("record exceeds"),
|
|
1423
|
+
);
|
|
1424
|
+
assert.equal(called, false);
|
|
1607
1425
|
});
|