@criogaid/pi-hashline-edit 0.1.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/LICENSE +21 -0
- package/README.md +279 -0
- package/package.json +50 -0
- package/src/core/apply.test.ts +327 -0
- package/src/core/apply.ts +264 -0
- package/src/core/hash.test.ts +54 -0
- package/src/core/hash.ts +68 -0
- package/src/core/index.ts +13 -0
- package/src/core/lines.test.ts +33 -0
- package/src/core/lines.ts +52 -0
- package/src/core/types.ts +87 -0
- package/src/index.ts +44 -0
- package/src/integration/grep-rg.test.ts +390 -0
- package/src/pi/action-fusion.test.ts +244 -0
- package/src/pi/action-fusion.ts +284 -0
- package/src/pi/config.test.ts +22 -0
- package/src/pi/config.ts +56 -0
- package/src/pi/edit-tool.ts +367 -0
- package/src/pi/execute.test.ts +521 -0
- package/src/pi/failure-context.test.ts +88 -0
- package/src/pi/failure-context.ts +98 -0
- package/src/pi/failure-path.test.ts +60 -0
- package/src/pi/file-commit.test.ts +200 -0
- package/src/pi/file-commit.ts +185 -0
- package/src/pi/fusion-card.test.ts +69 -0
- package/src/pi/fusion-card.ts +78 -0
- package/src/pi/grep-tool.ts +795 -0
- package/src/pi/grep.test.ts +515 -0
- package/src/pi/pi.test.ts +19 -0
- package/src/pi/read-tool.ts +178 -0
- package/src/pi/registration.test.ts +41 -0
- package/src/pi/render.ts +103 -0
- package/src/pi/replace-tool.ts +303 -0
- package/src/pi/replace.test.ts +287 -0
- package/src/pi/rg-line-filter.test.ts +79 -0
- package/src/pi/rg-line-filter.ts +358 -0
- package/src/pi/rg-line-ranges.test.ts +30 -0
- package/src/pi/rg-line-ranges.ts +106 -0
- package/src/pi/state.ts +27 -0
- package/src/pi/write-tool.ts +83 -0
- package/src/pi/write.test.ts +126 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi integration tests for the `replace` tool: literal replaceAll, regex with
|
|
3
|
+
* capture groups, flags, the maxMatches guard, 0-match / invalid-pattern
|
|
4
|
+
* failures (signaled by throwing — pi's failure contract), diff + fresh-anchor
|
|
5
|
+
* return, and chaining a hashline `edit` on an anchor returned by `replace`.
|
|
6
|
+
*
|
|
7
|
+
* Failures are signaled by throwing (see edit-tool.ts); tests use assert.rejects.
|
|
8
|
+
*/
|
|
9
|
+
import { test } from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { mkdtemp, rm, readFile, writeFile } from "node:fs/promises";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import { makeReplaceTool } from "./replace-tool.ts";
|
|
16
|
+
import { makeEditOverride } from "./edit-tool.ts";
|
|
17
|
+
|
|
18
|
+
async function withDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
|
19
|
+
const dir = await mkdtemp(join(tmpdir(), "hl-replace-"));
|
|
20
|
+
try {
|
|
21
|
+
return await fn(dir);
|
|
22
|
+
} finally {
|
|
23
|
+
await rm(dir, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const call = (tool: any, params: any) => tool.execute("0", params, undefined, undefined);
|
|
28
|
+
|
|
29
|
+
/** Extract a `LINE#HASH` anchor for `line` from a result text block. */
|
|
30
|
+
function anchorLine(block: string, line: number) {
|
|
31
|
+
const m = new RegExp(`^${line}#([0-9A-Z]+)│`, "m").exec(block);
|
|
32
|
+
if (!m) throw new Error(`line ${line} anchor not found in block`);
|
|
33
|
+
return `${line}#${m[1]}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const stubTheme = { fg: (_k: string, s: string) => s, bold: (s: string) => s };
|
|
37
|
+
|
|
38
|
+
// renderResult delegates to pi's renderDiff, which reads the global TUI theme
|
|
39
|
+
// singleton — initialize it once for this test process (watcher off by default).
|
|
40
|
+
initTheme();
|
|
41
|
+
|
|
42
|
+
test("replace literal: replaces all occurrences", async () => {
|
|
43
|
+
await withDir(async (dir) => {
|
|
44
|
+
const f = join(dir, "f.txt");
|
|
45
|
+
await writeFile(f, "foo bar foo baz foo\n");
|
|
46
|
+
const r: any = await call(makeReplaceTool(dir), { path: "f.txt", find: "foo", replace: "qux" });
|
|
47
|
+
assert.equal(r.isError, undefined);
|
|
48
|
+
assert.equal(await readFile(f, "utf-8"), "qux bar qux baz qux\n");
|
|
49
|
+
assert.match(r.content[0].text, /3 matches/);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("replace literal: $ in replacement stays literal (no expansion)", async () => {
|
|
54
|
+
await withDir(async (dir) => {
|
|
55
|
+
const f = join(dir, "f.txt");
|
|
56
|
+
await writeFile(f, "cost: $5 here\n");
|
|
57
|
+
const r: any = await call(makeReplaceTool(dir), { path: "f.txt", find: "$5", replace: "$10" });
|
|
58
|
+
assert.equal(r.isError, undefined);
|
|
59
|
+
// literal mode: "$10" inserted verbatim, NOT interpreted as group-10 + "0"
|
|
60
|
+
assert.equal(await readFile(f, "utf-8"), "cost: $10 here\n");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("replace literal: case-insensitive via flags", async () => {
|
|
65
|
+
await withDir(async (dir) => {
|
|
66
|
+
const f = join(dir, "f.txt");
|
|
67
|
+
await writeFile(f, "Foo fOo FOO\n");
|
|
68
|
+
await call(makeReplaceTool(dir), { path: "f.txt", find: "foo", replace: "x", flags: "i" });
|
|
69
|
+
assert.equal(await readFile(f, "utf-8"), "x x x\n");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("replace regex: capture groups in replacement", async () => {
|
|
74
|
+
await withDir(async (dir) => {
|
|
75
|
+
const f = join(dir, "f.txt");
|
|
76
|
+
await writeFile(f, "name: alice\nname: bob\n");
|
|
77
|
+
await call(makeReplaceTool(dir), {
|
|
78
|
+
path: "f.txt",
|
|
79
|
+
find: "name: (\\w+)",
|
|
80
|
+
replace: "user: $1",
|
|
81
|
+
regex: true,
|
|
82
|
+
});
|
|
83
|
+
assert.equal(await readFile(f, "utf-8"), "user: alice\nuser: bob\n");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("replace regex: multiline flag matches line-anchored pattern", async () => {
|
|
88
|
+
await withDir(async (dir) => {
|
|
89
|
+
const f = join(dir, "f.txt");
|
|
90
|
+
await writeFile(f, "a\nb\nc\n");
|
|
91
|
+
// without `m`, ^a$ wouldn't match (a isn't at end of string); with `m` it does
|
|
92
|
+
await call(makeReplaceTool(dir), { path: "f.txt", find: "^a$", replace: "A", regex: true, flags: "m" });
|
|
93
|
+
assert.equal(await readFile(f, "utf-8"), "A\nb\nc\n");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("replace regex: dotall flag makes . match newlines", async () => {
|
|
98
|
+
await withDir(async (dir) => {
|
|
99
|
+
const f = join(dir, "f.txt");
|
|
100
|
+
await writeFile(f, "a\nb\n");
|
|
101
|
+
// a.b only matches across the newline with the `s` (dotall) flag
|
|
102
|
+
await call(makeReplaceTool(dir), { path: "f.txt", find: "a.b", replace: "X", regex: true, flags: "s" });
|
|
103
|
+
assert.equal(await readFile(f, "utf-8"), "X\n");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("replace: 0 matches throws", async () => {
|
|
108
|
+
await withDir(async (dir) => {
|
|
109
|
+
const f = join(dir, "f.txt");
|
|
110
|
+
await writeFile(f, "a\nb\n");
|
|
111
|
+
await assert.rejects(
|
|
112
|
+
call(makeReplaceTool(dir), { path: "f.txt", find: "zzz", replace: "y" }),
|
|
113
|
+
/no matches/,
|
|
114
|
+
);
|
|
115
|
+
assert.equal(await readFile(f, "utf-8"), "a\nb\n", "file untouched on 0-match failure");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("replace: empty find throws", async () => {
|
|
120
|
+
await withDir(async (dir) => {
|
|
121
|
+
await writeFile(join(dir, "f.txt"), "a\n");
|
|
122
|
+
await assert.rejects(
|
|
123
|
+
call(makeReplaceTool(dir), { path: "f.txt", find: "", replace: "x" }),
|
|
124
|
+
/`find` is empty/,
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("replace: maxMatches guard throws before writing", async () => {
|
|
130
|
+
await withDir(async (dir) => {
|
|
131
|
+
const f = join(dir, "f.txt");
|
|
132
|
+
await writeFile(f, "a".repeat(20) + "\n");
|
|
133
|
+
await assert.rejects(
|
|
134
|
+
call(makeReplaceTool(dir), { path: "f.txt", find: "a", replace: "b", maxMatches: 5 }),
|
|
135
|
+
/exceed `maxMatches`/,
|
|
136
|
+
);
|
|
137
|
+
assert.equal(await readFile(f, "utf-8"), "a".repeat(20) + "\n", "file untouched when guard trips");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("replace: invalid regex throws a friendly message", async () => {
|
|
142
|
+
await withDir(async (dir) => {
|
|
143
|
+
await writeFile(join(dir, "f.txt"), "a\n");
|
|
144
|
+
await assert.rejects(
|
|
145
|
+
call(makeReplaceTool(dir), { path: "f.txt", find: "(unclosed", replace: "x", regex: true }),
|
|
146
|
+
/invalid regex/,
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("replace: invalid flag char throws", async () => {
|
|
152
|
+
await withDir(async (dir) => {
|
|
153
|
+
await writeFile(join(dir, "f.txt"), "a\n");
|
|
154
|
+
await assert.rejects(
|
|
155
|
+
call(makeReplaceTool(dir), { path: "f.txt", find: "a", replace: "x", flags: "z" }),
|
|
156
|
+
/invalid regex flag/,
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("replace: count-but-no-net-change does not rewrite and reports it", async () => {
|
|
162
|
+
await withDir(async (dir) => {
|
|
163
|
+
const f = join(dir, "f.txt");
|
|
164
|
+
await writeFile(f, "xx\n");
|
|
165
|
+
// $& = whole match = "x", so the text is unchanged despite 2 matches
|
|
166
|
+
const r: any = await call(makeReplaceTool(dir), { path: "f.txt", find: "x", replace: "$&", regex: true });
|
|
167
|
+
assert.equal(r.isError, undefined);
|
|
168
|
+
assert.equal(await readFile(f, "utf-8"), "xx\n");
|
|
169
|
+
assert.match(r.content[0].text, /no net change/);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("replace: returns details.diff (string) + patch + firstChangedLine", async () => {
|
|
174
|
+
await withDir(async (dir) => {
|
|
175
|
+
const f = join(dir, "f.txt");
|
|
176
|
+
await writeFile(f, "a\nb\nc\n");
|
|
177
|
+
const r: any = await call(makeReplaceTool(dir), { path: "f.txt", find: "b", replace: "B" });
|
|
178
|
+
assert.equal(typeof r.details.diff, "string");
|
|
179
|
+
assert.equal(typeof r.details.patch, "string");
|
|
180
|
+
assert.equal(typeof r.details.firstChangedLine, "number");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("replace: returns fresh anchors for the changed region", async () => {
|
|
185
|
+
await withDir(async (dir) => {
|
|
186
|
+
const f = join(dir, "f.txt");
|
|
187
|
+
await writeFile(f, "a\nb\nc\n");
|
|
188
|
+
const r: any = await call(makeReplaceTool(dir), { path: "f.txt", find: "b", replace: "B" });
|
|
189
|
+
const out: string = r.content[0].text;
|
|
190
|
+
assert.match(out, /Updated anchors/);
|
|
191
|
+
// line 2 now holds "B"; its anchor must be present and correct
|
|
192
|
+
const a2 = anchorLine(out, 2);
|
|
193
|
+
assert.match(a2, /^2#[0-9A-Z]{2,8}$/);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("replace: changed-region anchor chains a subsequent hashline edit without a re-read", async () => {
|
|
198
|
+
await withDir(async (dir) => {
|
|
199
|
+
const f = join(dir, "f.txt");
|
|
200
|
+
await writeFile(f, "old old old\n");
|
|
201
|
+
const replace = makeReplaceTool(dir);
|
|
202
|
+
const r1: any = await call(replace, { path: "f.txt", find: "old", replace: "new" });
|
|
203
|
+
const out: string = r1.content[0].text;
|
|
204
|
+
// line 1 is the changed line; chain an edit on its returned anchor
|
|
205
|
+
const a1 = anchorLine(out, 1);
|
|
206
|
+
const edit = makeEditOverride(dir);
|
|
207
|
+
const r2: any = await call(edit, {
|
|
208
|
+
path: "f.txt",
|
|
209
|
+
edits: [{ op: "replace", anchor: a1, body: ["NEW NEW NEW"] }],
|
|
210
|
+
});
|
|
211
|
+
assert.equal(r2.isError, undefined);
|
|
212
|
+
assert.equal(await readFile(f, "utf-8"), "NEW NEW NEW\n");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("replace: multiline replacement (changes line count) still reports a correct span", async () => {
|
|
217
|
+
await withDir(async (dir) => {
|
|
218
|
+
const f = join(dir, "f.txt");
|
|
219
|
+
await writeFile(f, "a\nb\nc\n");
|
|
220
|
+
// replace "b" with two lines → line count grows; changed region must cover the insertion
|
|
221
|
+
const r: any = await call(makeReplaceTool(dir), { path: "f.txt", find: "b", replace: "B1\nB2" });
|
|
222
|
+
assert.equal(await readFile(f, "utf-8"), "a\nB1\nB2\nc\n");
|
|
223
|
+
const out: string = r.content[0].text;
|
|
224
|
+
// the two inserted/changed lines (2 and 3) should both be anchored
|
|
225
|
+
assert.doesNotThrow(() => anchorLine(out, 2));
|
|
226
|
+
assert.doesNotThrow(() => anchorLine(out, 3));
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("replace renderResult: renders the diff without throwing", async () => {
|
|
231
|
+
await withDir(async (dir) => {
|
|
232
|
+
const f = join(dir, "f.txt");
|
|
233
|
+
await writeFile(f, "a\nb\nc\n");
|
|
234
|
+
const tool = makeReplaceTool(dir);
|
|
235
|
+
const r: any = await call(tool, { path: "f.txt", find: "b", replace: "B" });
|
|
236
|
+
// @ts-ignore — drive the renderer with a stub theme
|
|
237
|
+
const comp: any = tool.renderResult(
|
|
238
|
+
{ content: r.content, details: r.details },
|
|
239
|
+
{ isPartial: false, expanded: true },
|
|
240
|
+
stubTheme,
|
|
241
|
+
{ isError: r.isError ?? false, state: {}, invalidate: () => {} },
|
|
242
|
+
);
|
|
243
|
+
assert.ok(typeof comp?.text === "string");
|
|
244
|
+
assert.ok(comp.text.includes("B"), "rendered diff should contain the new content");
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("replace renderResult: renders the error line without throwing", async () => {
|
|
249
|
+
await withDir(async (dir) => {
|
|
250
|
+
const f = join(dir, "f.txt");
|
|
251
|
+
await writeFile(f, "a\n");
|
|
252
|
+
const tool = makeReplaceTool(dir);
|
|
253
|
+
let thrown: any;
|
|
254
|
+
const r: any = await call(tool, { path: "f.txt", find: "zzz", replace: "y" }).catch((e: any) => {
|
|
255
|
+
thrown = e;
|
|
256
|
+
return null;
|
|
257
|
+
});
|
|
258
|
+
assert.ok(thrown, "expected the call to throw");
|
|
259
|
+
// @ts-ignore — simulate how the framework hands the thrown message to renderResult
|
|
260
|
+
const comp: any = tool.renderResult(
|
|
261
|
+
{ content: [{ type: "text", text: thrown.message }] },
|
|
262
|
+
{ isPartial: false, expanded: false },
|
|
263
|
+
stubTheme,
|
|
264
|
+
{ isError: true },
|
|
265
|
+
);
|
|
266
|
+
assert.ok(typeof comp?.text === "string");
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("replace header: renderResult refreshes the call header in place — no invalidate", async () => {
|
|
271
|
+
await withDir(async (dir) => {
|
|
272
|
+
const f = join(dir, "f.txt");
|
|
273
|
+
await writeFile(f, "a\nb\nc\n");
|
|
274
|
+
const tool = makeReplaceTool(dir);
|
|
275
|
+
const args = { path: "f.txt", find: "b", replace: "B1\nB2" };
|
|
276
|
+
const r: any = await call(tool, args);
|
|
277
|
+
let invalidated = false;
|
|
278
|
+
const context: any = { args, isError: false, state: {}, invalidate: () => { invalidated = true; } };
|
|
279
|
+
const header: any = tool.renderCall(args, stubTheme, context);
|
|
280
|
+
assert.ok(!header.text.includes("+2"), "pre-execution header must not show counts");
|
|
281
|
+
tool.renderResult({ content: r.content, details: r.details }, { isPartial: false, expanded: true }, stubTheme, context);
|
|
282
|
+
assert.deepEqual(context.state.diffCounts, { added: 2, removed: 1 });
|
|
283
|
+
assert.ok(header.text.includes("+2"), "header should show added count");
|
|
284
|
+
assert.ok(header.text.includes("-1"), "header should show removed count");
|
|
285
|
+
assert.ok(!invalidated, "renderResult must not call invalidate");
|
|
286
|
+
});
|
|
287
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { resolveIgnoreCase, type RunText } from "./rg-line-filter.ts";
|
|
4
|
+
|
|
5
|
+
const regexMode = { engine: "default", multiline: false, literal: false } as const;
|
|
6
|
+
const literalMode = { ...regexMode, literal: true } as const;
|
|
7
|
+
|
|
8
|
+
test("explicit case settings skip the smart-case probe", async () => {
|
|
9
|
+
const run: RunText = async () => { throw new Error("probe must not run"); };
|
|
10
|
+
assert.equal(await resolveIgnoreCase("rg", ["foo"], regexMode, true, undefined, run), true);
|
|
11
|
+
assert.equal(await resolveIgnoreCase("rg", ["foo"], regexMode, false, undefined, run), false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("standard smart-case probe distinguishes its sensor from user matches", async () => {
|
|
15
|
+
const calls: { args: readonly string[]; input: Buffer }[] = [];
|
|
16
|
+
const insensitive: RunText = async (_path, args, input) => {
|
|
17
|
+
calls.push({ args, input });
|
|
18
|
+
return { code: 0, stdout: "a\n\n", stderr: "" };
|
|
19
|
+
};
|
|
20
|
+
assert.equal(await resolveIgnoreCase("rg", ["(a)|Foo"], regexMode, undefined, undefined, insensitive), true);
|
|
21
|
+
assert.deepEqual(calls[0].input, Buffer.from("a\n"));
|
|
22
|
+
assert.ok(calls[0].args.includes("--smart-case"));
|
|
23
|
+
assert.ok(calls[0].args.includes("--no-config"));
|
|
24
|
+
|
|
25
|
+
const sensitive: RunText = async () => ({ code: 0, stdout: "\n", stderr: "" });
|
|
26
|
+
assert.equal(await resolveIgnoreCase("rg", ["(a)|Foo"], regexMode, undefined, undefined, sensitive), false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("literal smart-case escapes user patterns before probing", async () => {
|
|
30
|
+
let args: readonly string[] = [];
|
|
31
|
+
const run: RunText = async (_path, received) => {
|
|
32
|
+
args = received;
|
|
33
|
+
return { code: 1, stdout: "", stderr: "" };
|
|
34
|
+
};
|
|
35
|
+
await resolveIgnoreCase("rg", ["foo\\S*"], literalMode, undefined, undefined, run);
|
|
36
|
+
const patterns = args.flatMap((arg, index) => args[index - 1] === "-e" ? [arg] : []);
|
|
37
|
+
assert.deepEqual(patterns, ["(\\p{Lu})", "foo\\\\S\\*"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("PCRE2 smart-case uses a version-gated comment carrier", async () => {
|
|
41
|
+
const calls: { args: readonly string[]; input: Buffer }[] = [];
|
|
42
|
+
const run: RunText = async (_path, args, input) => {
|
|
43
|
+
calls.push({ args, input });
|
|
44
|
+
if (args.includes("--version")) {
|
|
45
|
+
return { code: 0, stdout: "ripgrep 15.0.0\nfeatures:+pcre2\nPCRE2 10.45 is available (JIT is available)\n", stderr: "" };
|
|
46
|
+
}
|
|
47
|
+
return { code: 0, stdout: "", stderr: "" };
|
|
48
|
+
};
|
|
49
|
+
const mode = { engine: "pcre2", multiline: true, literal: false } as const;
|
|
50
|
+
assert.equal(await resolveIgnoreCase("rg", ["foo(?=bar)", "Foo\nbar"], mode, undefined, undefined, run), true);
|
|
51
|
+
const carrier = calls[1].args[calls[1].args.indexOf("-e") + 1];
|
|
52
|
+
assert.equal(carrier, "(?x)\n#foo(?=bar)\n#Foo\n#bar\n\\x{41}\n");
|
|
53
|
+
assert.ok(calls[1].args.includes("--engine=pcre2"));
|
|
54
|
+
assert.ok(calls[1].args.includes("--multiline"));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("PCRE2 smart-case rejects unvalidated builds unless case is explicit", async () => {
|
|
58
|
+
const run: RunText = async () => ({ code: 0, stdout: "ripgrep 16.0.0\nfeatures:+pcre2\n", stderr: "" });
|
|
59
|
+
const mode = { engine: "pcre2", multiline: false, literal: false } as const;
|
|
60
|
+
await assert.rejects(resolveIgnoreCase("rg", ["foo"], mode, undefined, undefined, run), /not validated/);
|
|
61
|
+
assert.equal(await resolveIgnoreCase("rg", ["foo"], mode, false, undefined, run), false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("smart-case probe propagates parser errors and rejects unknown output", async () => {
|
|
65
|
+
const failed: RunText = async () => ({ code: 2, stdout: "", stderr: "regex parse error" });
|
|
66
|
+
await assert.rejects(resolveIgnoreCase("rg", ["("], regexMode, undefined, undefined, failed), /regex parse error/);
|
|
67
|
+
|
|
68
|
+
const unexpected: RunText = async () => ({ code: 0, stdout: "unexpected\n", stderr: "" });
|
|
69
|
+
await assert.rejects(resolveIgnoreCase("rg", ["foo"], regexMode, undefined, undefined, unexpected), /Unexpected smart-case probe output/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("smart-case probe normalizes cancellation without fallback", async () => {
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const run: RunText = async () => {
|
|
75
|
+
controller.abort();
|
|
76
|
+
return { code: 1, stdout: "", stderr: "" };
|
|
77
|
+
};
|
|
78
|
+
await assert.rejects(resolveIgnoreCase("rg", ["foo"], regexMode, undefined, controller.signal, run), /Operation aborted/);
|
|
79
|
+
});
|