@criogaid/pi-hashline-edit 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/README.zh-CN.md +12 -12
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +96 -271
- package/src/core/apply.ts +62 -169
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +5 -5
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +8 -44
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +4 -7
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -19
- package/src/integration/grep-js-completeness.test.ts +45 -18
- package/src/integration/grep-line-candidates.test.ts +7 -10
- package/src/integration/grep-matrix.test.ts +6 -9
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +10 -9
- package/src/integration/grep-prefilter-coverage.test.ts +5 -8
- package/src/integration/grep-process-limits.test.ts +76 -0
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +166 -66
- package/src/integration/grep-scan-budget.test.ts +9 -9
- package/src/integration/grep-translation.test.ts +18 -32
- package/src/integration/large-text.test.ts +6 -52
- package/src/integration/model-budget-lifecycle.test.ts +10 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +161 -83
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +22 -12
- package/src/integration/report-replay.test.ts +23 -26
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +18 -17
- package/src/pi/action-fusion.test.ts +241 -353
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +150 -125
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +25 -28
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +334 -283
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +6 -8
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +7 -3
- package/src/pi/config.ts +12 -9
- package/src/pi/diagnostic-buffer.test.ts +34 -13
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +86 -211
- package/src/pi/error-text.ts +10 -9
- package/src/pi/execute.test.ts +249 -345
- package/src/pi/failure-context.test.ts +146 -127
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +182 -155
- package/src/pi/file-commit.test.ts +156 -71
- package/src/pi/file-commit.ts +126 -146
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +26 -22
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +19 -120
- package/src/pi/grep-candidates.ts +25 -76
- package/src/pi/grep-matrix.test.ts +5 -5
- package/src/pi/grep-order.test.ts +16 -15
- package/src/pi/grep-output.ts +94 -107
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +97 -0
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +41 -43
- package/src/pi/grep-search.ts +27 -39
- package/src/pi/grep-tool.ts +63 -106
- package/src/pi/grep.test.ts +177 -156
- package/src/pi/model-budgets.test.ts +27 -24
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +52 -21
- package/src/pi/mutation-runner.ts +134 -74
- package/src/pi/output-budgets.test.ts +86 -42
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +18 -23
- package/src/pi/read.test.ts +22 -41
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +85 -51
- package/src/pi/render.test.ts +88 -59
- package/src/pi/render.ts +64 -65
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -94
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +53 -38
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +10 -3
- package/src/pi/report-schema.ts +251 -148
- package/src/pi/report.test.ts +215 -67
- package/src/pi/report.ts +50 -98
- package/src/pi/result-safety.test.ts +241 -247
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +53 -75
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +35 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +36 -71
- package/src/pi/write.test.ts +31 -34
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/testing/run-tests.ts +1 -1
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -1,127 +1,26 @@
|
|
|
1
|
+
import { fileCandidateArgs } from "./grep-rg.testing.ts";
|
|
1
2
|
import { test } from "node:test";
|
|
2
3
|
import assert from "node:assert/strict";
|
|
3
|
-
import {
|
|
4
|
-
import { COMMON_RG_ARGS, type GrepBackend } from "./rg-process.ts";
|
|
5
|
-
import type { Prefilter } from "../core/search-analysis.ts";
|
|
4
|
+
import { COMMON_RG_ARGS } from "./rg-process.ts";
|
|
6
5
|
|
|
7
|
-
test("candidate literals → rg lists files with escaped byte-preserving alternatives", () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
test("candidate literals → rg lists files with escaped byte-preserving alternatives", async () => {
|
|
7
|
+
const query = { patterns: ["."], literal: false, flags: "", multiline: true };
|
|
8
|
+
assert.deepEqual(await fileCandidateArgs(query), [...COMMON_RG_ARGS, "--files"]);
|
|
9
|
+
for (const [patterns, literal, flags, pattern] of [
|
|
10
|
+
[["a.b", "-é"], true, "", "a\\x{2e}b|\\x{2d}\\x{e9}"],
|
|
11
|
+
[["k_9"], true, "iu", "[Kk\\x{212a}]_9"],
|
|
12
|
+
] as const) {
|
|
13
|
+
assert.deepEqual(
|
|
14
|
+
await fileCandidateArgs({ patterns: [...patterns], literal, flags, multiline: true }),
|
|
11
15
|
[
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
...COMMON_RG_ARGS,
|
|
17
|
+
"--files-with-matches",
|
|
18
|
+
"--engine=default",
|
|
19
|
+
"--case-sensitive",
|
|
20
|
+
"--encoding=none",
|
|
21
|
+
"-e",
|
|
22
|
+
pattern,
|
|
14
23
|
],
|
|
15
|
-
"a\\x{2e}b|\\x{2d}\\x{e9}",
|
|
16
|
-
],
|
|
17
|
-
[[[["K", "k", "K"], ["_"], ["9"]]], "[Kk\\x{212a}]_9"],
|
|
18
|
-
] as const) {
|
|
19
|
-
assert.deepEqual(candidateArgs({ kind: "literals", literals }), [
|
|
20
|
-
...COMMON_RG_ARGS,
|
|
21
|
-
"--files-with-matches",
|
|
22
|
-
"--engine=default",
|
|
23
|
-
"--case-sensitive",
|
|
24
|
-
"--encoding=none",
|
|
25
|
-
"-e",
|
|
26
|
-
pattern,
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const conjunction: Prefilter = {
|
|
32
|
-
kind: "and",
|
|
33
|
-
filters: [
|
|
34
|
-
{ kind: "literals", literals: [[["a"]]] },
|
|
35
|
-
{ kind: "literals", literals: [[["b"]]] },
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
test("AND file passes → intersect paths before emitting and preserve final callback stop", async () => {
|
|
40
|
-
let pass = 0;
|
|
41
|
-
const calls: string[][] = [];
|
|
42
|
-
const run: GrepBackend["runRgPaths"] = async (_rg, args, _signal, onPath) => {
|
|
43
|
-
calls.push([...args]);
|
|
44
|
-
for (const path of [
|
|
45
|
-
["a-only", "both"],
|
|
46
|
-
["b-only", "both", "later"],
|
|
47
|
-
][pass++])
|
|
48
|
-
if (!(await onPath(path))) return { code: null, stderr: "", stopped: true };
|
|
49
|
-
return { code: 0, stderr: "", stopped: false };
|
|
50
|
-
};
|
|
51
|
-
const paths: string[] = [];
|
|
52
|
-
const result = await runCandidatePaths(
|
|
53
|
-
run,
|
|
54
|
-
"rg",
|
|
55
|
-
conjunction,
|
|
56
|
-
["--", "root"],
|
|
57
|
-
undefined,
|
|
58
|
-
(path) => {
|
|
59
|
-
paths.push(path);
|
|
60
|
-
return false;
|
|
61
|
-
},
|
|
62
|
-
);
|
|
63
|
-
assert.deepEqual(paths, ["both"]);
|
|
64
|
-
assert.equal(result.stopped, true);
|
|
65
|
-
assert.equal(calls.length, 2);
|
|
66
|
-
for (const args of calls) assert.deepEqual(args.slice(-2), ["--", "root"]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("AND path retention fills → rerun one necessary clause without excluding its candidates", async () => {
|
|
70
|
-
let pass = 0;
|
|
71
|
-
const run: GrepBackend["runRgPaths"] = async (_rg, _args, _signal, onPath) => {
|
|
72
|
-
const keepGoing = await onPath(
|
|
73
|
-
pass++ === 0 ? "x".repeat(MAX_PREFILTER_PATH_BYTES + 1) : "candidate",
|
|
74
24
|
);
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
const paths: string[] = [];
|
|
78
|
-
const result = await runCandidatePaths(
|
|
79
|
-
run,
|
|
80
|
-
"rg",
|
|
81
|
-
conjunction,
|
|
82
|
-
["--", "root"],
|
|
83
|
-
undefined,
|
|
84
|
-
(path) => {
|
|
85
|
-
paths.push(path);
|
|
86
|
-
return true;
|
|
87
|
-
},
|
|
88
|
-
);
|
|
89
|
-
assert.deepEqual(paths, ["candidate"]);
|
|
90
|
-
assert.equal(pass, 2);
|
|
91
|
-
assert.equal(result.stopped, false);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test("incomplete intermediate pass → retain reported candidates and the failure diagnostics", async () => {
|
|
95
|
-
const run: GrepBackend["runRgPaths"] = async (_rg, _args, _signal, onPath) => {
|
|
96
|
-
await onPath("reported");
|
|
97
|
-
return { code: 2, stderr: "unreadable path", stopped: false };
|
|
98
|
-
};
|
|
99
|
-
const paths: string[] = [];
|
|
100
|
-
const result = await runCandidatePaths(run, "rg", conjunction, [], undefined, (path) => {
|
|
101
|
-
paths.push(path);
|
|
102
|
-
return true;
|
|
103
|
-
});
|
|
104
|
-
assert.deepEqual(paths, ["reported"]);
|
|
105
|
-
assert.equal(result.code, 2);
|
|
106
|
-
assert.match(result.stderr, /unreadable path/);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("cancel between AND passes → propagate cancellation before emitting candidates", async () => {
|
|
110
|
-
const controller = new AbortController();
|
|
111
|
-
let pass = 0;
|
|
112
|
-
const run: GrepBackend["runRgPaths"] = async (_rg, _args, signal, onPath) => {
|
|
113
|
-
assert.equal(signal, controller.signal);
|
|
114
|
-
if (pass++) {
|
|
115
|
-
controller.abort(new Error("cancelled"));
|
|
116
|
-
signal?.throwIfAborted();
|
|
117
|
-
}
|
|
118
|
-
await onPath("candidate");
|
|
119
|
-
return { code: 0, stderr: "", stopped: false };
|
|
120
|
-
};
|
|
121
|
-
await assert.rejects(
|
|
122
|
-
runCandidatePaths(run, "rg", conjunction, [], controller.signal, () =>
|
|
123
|
-
assert.fail("cancelled candidate"),
|
|
124
|
-
),
|
|
125
|
-
/cancelled/,
|
|
126
|
-
);
|
|
25
|
+
}
|
|
127
26
|
});
|
|
@@ -10,16 +10,16 @@ import { stat } from "node:fs/promises";
|
|
|
10
10
|
import { resolve } from "node:path";
|
|
11
11
|
import type { GrepQuery } from "../core/search.ts";
|
|
12
12
|
import { extractPrefilter, type Literal, type Prefilter } from "../core/search-analysis.ts";
|
|
13
|
-
import { DiagnosticBuffer } from "./diagnostic-buffer.ts";
|
|
14
13
|
import { scopeArgs, type SearchScope } from "./grep-scope.ts";
|
|
15
14
|
import {
|
|
16
15
|
COMMON_RG_ARGS,
|
|
17
16
|
LINE_LISTING_ARGS,
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
MAX_RG_PATTERN_UNITS,
|
|
18
|
+
runRgLines,
|
|
19
|
+
runRgPaths,
|
|
20
20
|
type RgRunResult,
|
|
21
21
|
} from "./rg-process.ts";
|
|
22
|
-
import { lineCandidatePatterns } from "./rg-regex.ts";
|
|
22
|
+
import { lineCandidatePatterns, rgCodePoint } from "./rg-regex.ts";
|
|
23
23
|
|
|
24
24
|
/** Beyond this many candidate lines, a file's every line is checked instead. */
|
|
25
25
|
const MAX_CANDIDATE_LINES = 64 * 1024;
|
|
@@ -28,8 +28,6 @@ const MAX_CANDIDATE_LINES = 64 * 1024;
|
|
|
28
28
|
* them were queued; README's search limits link here.
|
|
29
29
|
*/
|
|
30
30
|
export const MAX_UNNARROWED_SCAN_BYTES = 256 * 1024 * 1024;
|
|
31
|
-
/** Maximum retained paths while intersecting necessary file conditions. */
|
|
32
|
-
export const MAX_PREFILTER_PATH_BYTES = 4 * 1024 * 1024;
|
|
33
31
|
/** Candidate patterns match original bytes exactly as written; JavaScript decides case and encoding. */
|
|
34
32
|
const BYTE_PATTERN_ARGS = ["--engine=default", "--case-sensitive", "--encoding=none"];
|
|
35
33
|
|
|
@@ -39,85 +37,40 @@ export interface Candidate {
|
|
|
39
37
|
readonly lines?: readonly number[];
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
/** A literal's characters as one rg pattern
|
|
40
|
+
/** A literal's characters as one rg pattern. */
|
|
43
41
|
function literalPattern(literal: Literal): string {
|
|
44
|
-
const escape = (char: string) =>
|
|
45
|
-
/^[0-9A-Za-z_]$/.test(char) ? char : `\\x{${char.codePointAt(0)!.toString(16)}}`;
|
|
42
|
+
const escape = (char: string) => rgCodePoint(char.codePointAt(0)!);
|
|
46
43
|
return literal
|
|
47
44
|
.map((chars) => (chars.length === 1 ? escape(chars[0]) : `[${chars.map(escape).join("")}]`))
|
|
48
45
|
.join("");
|
|
49
46
|
}
|
|
50
47
|
|
|
48
|
+
const literalAlternation = (literals: readonly Literal[]): string =>
|
|
49
|
+
literals.map(literalPattern).join("|");
|
|
50
|
+
|
|
51
|
+
/** Necessary literals too long for rg's command line widen to every file in scope. */
|
|
52
|
+
function boundedPrefilter(prefilter: Prefilter): Prefilter {
|
|
53
|
+
return prefilter.kind === "literals" &&
|
|
54
|
+
literalAlternation(prefilter.literals).length > MAX_RG_PATTERN_UNITS
|
|
55
|
+
? { kind: "all" }
|
|
56
|
+
: prefilter;
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
/**
|
|
52
60
|
* List candidate files: those whose original bytes contain a prefilter literal, or every
|
|
53
61
|
* file in scope. Literals never contain a line break, so line-oriented matching finds them.
|
|
54
62
|
*/
|
|
55
|
-
|
|
56
|
-
if (prefilter.kind === "and") return candidateArgs(prefilter.filters[0]);
|
|
63
|
+
function candidateArgs(prefilter: Prefilter): string[] {
|
|
57
64
|
if (prefilter.kind === "all") return [...COMMON_RG_ARGS, "--files"];
|
|
58
65
|
return [
|
|
59
66
|
...COMMON_RG_ARGS,
|
|
60
67
|
"--files-with-matches",
|
|
61
68
|
...BYTE_PATTERN_ARGS,
|
|
62
69
|
"-e",
|
|
63
|
-
prefilter.literals
|
|
70
|
+
literalAlternation(prefilter.literals),
|
|
64
71
|
];
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
/** Execute AND-of-OR file conditions, falling back to one necessary clause if retention fills. */
|
|
68
|
-
export async function runCandidatePaths(
|
|
69
|
-
run: GrepBackend["runRgPaths"],
|
|
70
|
-
rgPath: string,
|
|
71
|
-
prefilter: Prefilter,
|
|
72
|
-
scopedArgs: readonly string[],
|
|
73
|
-
signal: AbortSignal | undefined,
|
|
74
|
-
onFile: (path: string) => boolean | Promise<boolean>,
|
|
75
|
-
): Promise<RgRunResult> {
|
|
76
|
-
const filters = prefilter.kind === "and" ? prefilter.filters : [prefilter];
|
|
77
|
-
const diagnostics = new DiagnosticBuffer(MAX_RG_STDERR_BYTES);
|
|
78
|
-
let allowed: ReadonlySet<string> | undefined;
|
|
79
|
-
for (const [index, filter] of filters.entries()) {
|
|
80
|
-
const last = index === filters.length - 1;
|
|
81
|
-
const paths = new Set<string>();
|
|
82
|
-
let bytes = 0;
|
|
83
|
-
let overflow = false;
|
|
84
|
-
const result = await run(
|
|
85
|
-
rgPath,
|
|
86
|
-
[...candidateArgs(filter), "--null", ...scopedArgs],
|
|
87
|
-
signal,
|
|
88
|
-
async (path) => {
|
|
89
|
-
if (allowed && !allowed.has(path)) return true;
|
|
90
|
-
if (last) return onFile(path);
|
|
91
|
-
if (!paths.has(path)) {
|
|
92
|
-
paths.add(path);
|
|
93
|
-
bytes += Buffer.byteLength(path);
|
|
94
|
-
}
|
|
95
|
-
overflow = bytes > MAX_PREFILTER_PATH_BYTES;
|
|
96
|
-
return !overflow;
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
if (result.stderr) diagnostics.append(`${result.stderr}\n`);
|
|
100
|
-
if (overflow) {
|
|
101
|
-
const fallback = await run(
|
|
102
|
-
rgPath,
|
|
103
|
-
[...candidateArgs(filters[0]), "--null", ...scopedArgs],
|
|
104
|
-
signal,
|
|
105
|
-
onFile,
|
|
106
|
-
);
|
|
107
|
-
if (fallback.stderr) diagnostics.append(fallback.stderr);
|
|
108
|
-
return { ...fallback, stderr: diagnostics.toString() };
|
|
109
|
-
}
|
|
110
|
-
if (last || result.stopped || (result.code !== 0 && result.code !== 1)) {
|
|
111
|
-
// An incomplete intermediate listing cannot exclude its already reported candidates.
|
|
112
|
-
if (!last) for (const path of paths) if (!(await onFile(path))) break;
|
|
113
|
-
return { ...result, stderr: diagnostics.toString() };
|
|
114
|
-
}
|
|
115
|
-
if (!paths.size) return { code: 1, stderr: diagnostics.toString(), stopped: false };
|
|
116
|
-
allowed = paths;
|
|
117
|
-
}
|
|
118
|
-
return { code: 1, stderr: diagnostics.toString(), stopped: false };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
74
|
/** How candidates were selected: rg's candidate lines, or whole files (see Prefilter). */
|
|
122
75
|
type CandidateSource = "lines" | "files" | "all";
|
|
123
76
|
|
|
@@ -126,8 +79,6 @@ type CandidateSource = "lines" | "files" | "all";
|
|
|
126
79
|
* An empty scope lists nothing, because rg would search the working directory instead.
|
|
127
80
|
*/
|
|
128
81
|
export async function listCandidates(options: {
|
|
129
|
-
readonly backend: GrepBackend;
|
|
130
|
-
readonly rgPath: string;
|
|
131
82
|
readonly scope: SearchScope;
|
|
132
83
|
readonly query: GrepQuery;
|
|
133
84
|
readonly signal: AbortSignal;
|
|
@@ -135,11 +86,10 @@ export async function listCandidates(options: {
|
|
|
135
86
|
readonly onCandidate: (candidate: Candidate) => Promise<boolean>;
|
|
136
87
|
}): Promise<{
|
|
137
88
|
readonly listing?: RgRunResult;
|
|
138
|
-
readonly candidates: CandidateSource;
|
|
139
89
|
readonly scanLimitReached: boolean;
|
|
140
90
|
}> {
|
|
141
|
-
const {
|
|
142
|
-
if (scope.searchPaths.length === 0) return {
|
|
91
|
+
const { scope, query, signal, stopped, onCandidate } = options;
|
|
92
|
+
if (scope.searchPaths.length === 0) return { scanLimitReached: false };
|
|
143
93
|
let candidates: CandidateSource = "lines";
|
|
144
94
|
let listedAny = false;
|
|
145
95
|
let scanned = 0;
|
|
@@ -167,8 +117,7 @@ export async function listCandidates(options: {
|
|
|
167
117
|
const scoped = [...scopeArgs(scope), "--", ...scope.searchPaths];
|
|
168
118
|
const patterns = query.multiline ? undefined : lineCandidatePatterns(query);
|
|
169
119
|
let listing = patterns
|
|
170
|
-
? await
|
|
171
|
-
rgPath,
|
|
120
|
+
? await runRgLines(
|
|
172
121
|
[
|
|
173
122
|
...COMMON_RG_ARGS,
|
|
174
123
|
...BYTE_PATTERN_ARGS,
|
|
@@ -183,9 +132,9 @@ export async function listCandidates(options: {
|
|
|
183
132
|
: undefined;
|
|
184
133
|
// rg reports a pattern it cannot compile, such as one beyond its size limit, before any file.
|
|
185
134
|
if (!listing || (listing.code === 2 && !listedAny)) {
|
|
186
|
-
const prefilter = extractPrefilter(query);
|
|
135
|
+
const prefilter = boundedPrefilter(extractPrefilter(query));
|
|
187
136
|
candidates = prefilter.kind === "all" ? "all" : "files";
|
|
188
|
-
listing = await
|
|
137
|
+
listing = await runRgPaths([...candidateArgs(prefilter), "--null", ...scoped], signal, offer);
|
|
189
138
|
}
|
|
190
|
-
return { listing,
|
|
139
|
+
return { listing, scanLimitReached };
|
|
191
140
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
3
|
import { MATRIX_FLAGS, MATRIX_SYNTAX } from "../core/search-matrix.testing.ts";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { makeMockGrep } from "./grep-rg.testing.ts";
|
|
5
|
+
const { DEFAULT_CONFIG } = await import("./tool-factories.testing.ts");
|
|
6
6
|
import { reportOf } from "./report.ts";
|
|
7
7
|
import { rejectsArgument } from "./argument-error.testing.ts";
|
|
8
8
|
import { callTool } from "./tool-call.testing.ts";
|
|
@@ -13,7 +13,7 @@ test("Cartesian JS syntax × all flag combinations → tool entry agrees with V8
|
|
|
13
13
|
discoveries++;
|
|
14
14
|
return { code: 1, stderr: "", stopped: false };
|
|
15
15
|
};
|
|
16
|
-
const tool =
|
|
16
|
+
const tool = makeMockGrep(process.cwd(), DEFAULT_CONFIG, {
|
|
17
17
|
runRgPaths: discover,
|
|
18
18
|
runRgLines: discover,
|
|
19
19
|
});
|
|
@@ -40,7 +40,7 @@ test("Cartesian JS syntax × all flag combinations → tool entry agrees with V8
|
|
|
40
40
|
for (const pattern of patterns) {
|
|
41
41
|
for (const flags of flagsCases) {
|
|
42
42
|
const normalizedFlags = [...new Set(flags)].join("");
|
|
43
|
-
let field: "flags" | "pattern" | undefined;
|
|
43
|
+
let field: "flags" | "pattern[0]" | undefined;
|
|
44
44
|
try {
|
|
45
45
|
new RegExp("", normalizedFlags);
|
|
46
46
|
} catch (error) {
|
|
@@ -52,7 +52,7 @@ test("Cartesian JS syntax × all flag combinations → tool entry agrees with V8
|
|
|
52
52
|
new RegExp(pattern, normalizedFlags);
|
|
53
53
|
} catch (error) {
|
|
54
54
|
if (!(error instanceof SyntaxError)) throw error;
|
|
55
|
-
field = "pattern";
|
|
55
|
+
field = "pattern[0]";
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
const before = discoveries;
|
|
@@ -8,9 +8,10 @@ import { setImmediate } from "node:timers/promises";
|
|
|
8
8
|
import { Worker } from "node:worker_threads";
|
|
9
9
|
import { computeLineHash } from "../core/hash.ts";
|
|
10
10
|
import { searchText, type LineSearchInput, type SearchInput } from "../core/search.ts";
|
|
11
|
-
import {
|
|
11
|
+
import { loadConfig } from "./config.ts";
|
|
12
|
+
const DEFAULT_CONFIG = loadConfig(os.tmpdir());
|
|
12
13
|
import { reportOf } from "./report.ts";
|
|
13
|
-
import type {
|
|
14
|
+
import type { MockRg } from "./grep-rg.testing.ts";
|
|
14
15
|
import type { WorkerError } from "./report-cause.ts";
|
|
15
16
|
import { callTool } from "./tool-call.testing.ts";
|
|
16
17
|
|
|
@@ -21,7 +22,7 @@ test("out-of-order file completions → listing order fixes rows, warnings, and
|
|
|
21
22
|
// Fix the pool size before its module loads, including on single-core CI hosts.
|
|
22
23
|
t.mock.method(os, "availableParallelism", () => concurrentFiles + 1);
|
|
23
24
|
syncBuiltinESMExports();
|
|
24
|
-
const {
|
|
25
|
+
const { makeMockGrep } = await import("./grep-rg.testing.ts");
|
|
25
26
|
t.mock.restoreAll();
|
|
26
27
|
syncBuiltinESMExports();
|
|
27
28
|
|
|
@@ -33,7 +34,7 @@ test("out-of-order file completions → listing order fixes rows, warnings, and
|
|
|
33
34
|
await fs.writeFile(join(dir, name), `${sourceLines(name).join("\n")}\n`);
|
|
34
35
|
}
|
|
35
36
|
const listingDiagnostic = "listing: Permission denied";
|
|
36
|
-
const warning = (name: string) =>
|
|
37
|
+
const warning = (name: string) => `${name}: EACCES: ${name}`;
|
|
37
38
|
|
|
38
39
|
for (const limit of [3, 5]) {
|
|
39
40
|
const outputs: unknown[] = [];
|
|
@@ -77,9 +78,9 @@ test("out-of-order file completions → listing order fixes rows, warnings, and
|
|
|
77
78
|
hold(name, () => this.emit("message", { result: searchText(input) }));
|
|
78
79
|
},
|
|
79
80
|
);
|
|
80
|
-
const backend:
|
|
81
|
+
const backend: MockRg = {
|
|
81
82
|
runRgPaths: async () => assert.fail("This query uses line candidates"),
|
|
82
|
-
runRgLines: async (
|
|
83
|
+
runRgLines: async (_args, _signal, _maxLines, onFile) => {
|
|
83
84
|
for (const name of names) {
|
|
84
85
|
if (!(await onFile(join(dir, name), undefined))) {
|
|
85
86
|
return { code: 2, stderr: listingDiagnostic, stopped: true };
|
|
@@ -88,7 +89,7 @@ test("out-of-order file completions → listing order fixes rows, warnings, and
|
|
|
88
89
|
return { code: 2, stderr: listingDiagnostic, stopped: false };
|
|
89
90
|
},
|
|
90
91
|
};
|
|
91
|
-
const running = callTool(
|
|
92
|
+
const running = callTool(makeMockGrep(dir, DEFAULT_CONFIG, backend), {
|
|
92
93
|
path: dir,
|
|
93
94
|
pattern: "needle",
|
|
94
95
|
literal: true,
|
|
@@ -149,7 +150,7 @@ test("out-of-order file completions → listing order fixes rows, warnings, and
|
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
test("match limit reached before a repeated candidate → stop listing before later diagnostics", async (t) => {
|
|
152
|
-
const {
|
|
153
|
+
const { makeMockGrep } = await import("./grep-rg.testing.ts");
|
|
153
154
|
const dir = await fs.mkdtemp(join(os.tmpdir(), "hl-grep-duplicate-stop-"));
|
|
154
155
|
t.after(() => fs.rm(dir, { recursive: true, force: true }));
|
|
155
156
|
const file = join(dir, "fixture.txt");
|
|
@@ -178,10 +179,10 @@ test("match limit reached before a repeated candidate → stop listing before la
|
|
|
178
179
|
return { code: stopped ? 0 : 2, stderr: stopped ? "" : "later diagnostic", stopped };
|
|
179
180
|
};
|
|
180
181
|
const result = await callTool(
|
|
181
|
-
|
|
182
|
-
runRgLines: (
|
|
182
|
+
makeMockGrep(dir, DEFAULT_CONFIG, {
|
|
183
|
+
runRgLines: (_args, _signal, _maxLines, onFile) =>
|
|
183
184
|
list((path) => onFile(path, undefined)),
|
|
184
|
-
runRgPaths: (
|
|
185
|
+
runRgPaths: (_args, _signal, onFile) => list(onFile),
|
|
185
186
|
}),
|
|
186
187
|
{ path: file, ...query, limit: 1, outputMode: "files" },
|
|
187
188
|
);
|
|
@@ -197,7 +198,7 @@ test("file-associated failure → listing position decides failure or cutoff, wh
|
|
|
197
198
|
}, async (t) => {
|
|
198
199
|
t.mock.method(os, "availableParallelism", () => 3);
|
|
199
200
|
syncBuiltinESMExports();
|
|
200
|
-
const {
|
|
201
|
+
const { makeMockGrep } = await import("./grep-rg.testing.ts");
|
|
201
202
|
t.mock.restoreAll();
|
|
202
203
|
syncBuiltinESMExports();
|
|
203
204
|
const dir = await fs.mkdtemp(join(os.tmpdir(), "hl-grep-failure-order-"));
|
|
@@ -229,9 +230,9 @@ test("file-associated failure → listing position decides failure or cutoff, wh
|
|
|
229
230
|
}),
|
|
230
231
|
},
|
|
231
232
|
] as const;
|
|
232
|
-
const backend:
|
|
233
|
+
const backend: MockRg = {
|
|
233
234
|
runRgPaths: async () => assert.fail("This query uses line candidates"),
|
|
234
|
-
runRgLines: async (
|
|
235
|
+
runRgLines: async (_args, _signal, _maxLines, onFile) => {
|
|
235
236
|
for (const name of names) if (!(await onFile(join(dir, name), undefined))) break;
|
|
236
237
|
return { code: 0, stderr: "", stopped: false };
|
|
237
238
|
},
|
|
@@ -269,7 +270,7 @@ test("file-associated failure → listing position decides failure or cutoff, wh
|
|
|
269
270
|
);
|
|
270
271
|
const controller = new AbortController();
|
|
271
272
|
const running = callTool(
|
|
272
|
-
|
|
273
|
+
makeMockGrep(dir, DEFAULT_CONFIG, backend),
|
|
273
274
|
{
|
|
274
275
|
path: dir,
|
|
275
276
|
pattern: "needle",
|