@criogaid/pi-hashline-edit 0.3.1 → 0.5.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 +166 -61
- package/package.json +8 -3
- package/src/core/apply.test.ts +459 -313
- package/src/core/apply.ts +251 -215
- package/src/core/errors.ts +9 -0
- package/src/core/hash.test.ts +61 -23
- package/src/core/hash.ts +49 -20
- package/src/core/lines.test.ts +46 -27
- package/src/core/lines.ts +36 -28
- package/src/core/ranges.test.ts +73 -19
- package/src/core/ranges.ts +15 -15
- package/src/core/replace.ts +109 -0
- package/src/core/text.test.ts +3 -3
- package/src/core/text.ts +26 -9
- package/src/core/types.ts +56 -41
- package/src/index.ts +23 -19
- package/src/integration/config-registration.test.ts +206 -0
- package/src/integration/grep-rg.test.ts +879 -251
- package/src/integration/large-text.test.ts +63 -0
- package/src/integration/replace-package.test.ts +41 -0
- package/src/pi/action-fusion.test.ts +612 -207
- package/src/pi/action-fusion.ts +442 -254
- package/src/pi/anchor-format.test.ts +53 -21
- package/src/pi/anchor-format.ts +48 -20
- package/src/pi/budgets.ts +25 -0
- package/src/pi/config.test.ts +178 -35
- package/src/pi/config.ts +96 -37
- package/src/pi/directory-sync.test.ts +55 -0
- package/src/pi/e2e-scenarios.test.ts +360 -0
- package/src/pi/edit-tool.ts +307 -279
- package/src/pi/error-text.ts +26 -0
- package/src/pi/execute.test.ts +1718 -713
- package/src/pi/failure-context.test.ts +110 -83
- package/src/pi/failure-context.ts +232 -73
- package/src/pi/failure-path.test.ts +180 -66
- package/src/pi/file-commit.test.ts +446 -233
- package/src/pi/file-commit.ts +348 -203
- package/src/pi/fusion-card.test.ts +118 -83
- package/src/pi/fusion-card.ts +203 -87
- package/src/pi/grep-output.ts +225 -0
- package/src/pi/grep-render.ts +59 -0
- package/src/pi/grep-scope.ts +139 -0
- package/src/pi/grep-search.ts +231 -0
- package/src/pi/grep-tool.ts +215 -774
- package/src/pi/grep.test.ts +825 -376
- package/src/pi/mutation-outcome.testing.ts +22 -0
- package/src/pi/mutation-result.test.ts +86 -0
- package/src/pi/mutation-result.ts +118 -63
- package/src/pi/mutation-runner.ts +151 -0
- package/src/pi/path.ts +20 -12
- package/src/pi/pi.test.ts +100 -52
- package/src/pi/read-tool.ts +245 -134
- package/src/pi/registration.test.ts +271 -114
- package/src/pi/render.test.ts +227 -84
- package/src/pi/render.ts +86 -116
- package/src/pi/replace-regex.ts +54 -0
- package/src/pi/replace-tool.ts +247 -241
- package/src/pi/replace-worker.mjs +4 -0
- package/src/pi/replace-worker.ts +10 -0
- package/src/pi/replace.test.ts +778 -390
- package/src/pi/result-safety.test.ts +821 -344
- package/src/pi/rg-line-ranges.test.ts +57 -31
- package/src/pi/rg-line-ranges.ts +45 -82
- package/src/pi/rg-process.test.ts +113 -0
- package/src/pi/{rg-line-filter.ts → rg-process.ts} +72 -125
- package/src/pi/rg-text-view.ts +102 -48
- package/src/pi/schema.ts +19 -0
- package/src/pi/text-stream.test.ts +118 -0
- package/src/pi/text-stream.ts +136 -0
- package/src/pi/tool-call.testing.ts +37 -0
- package/src/pi/write-tool.ts +114 -52
- package/src/pi/write.test.ts +250 -97
- package/src/core/index.ts +0 -14
- package/src/pi/rg-line-filter.test.ts +0 -85
- package/src/pi/state.ts +0 -26
package/src/core/types.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
/** Line anchor: dual reference of line number (1-based) + content hash. */
|
|
8
8
|
export interface Anchor {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
readonly line: number;
|
|
10
|
+
readonly hash: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -16,12 +16,17 @@ export interface Anchor {
|
|
|
16
16
|
* address is still what was read; both must match at apply time.
|
|
17
17
|
*/
|
|
18
18
|
export type Edit =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
| {
|
|
20
|
+
readonly op: "replace";
|
|
21
|
+
readonly start: Anchor;
|
|
22
|
+
readonly end?: Anchor;
|
|
23
|
+
readonly body: string[];
|
|
24
|
+
}
|
|
25
|
+
| { readonly op: "delete"; readonly start: Anchor; readonly end?: Anchor }
|
|
26
|
+
| { readonly op: "insert_after"; readonly anchor: Anchor; readonly body: string[] }
|
|
27
|
+
| { readonly op: "insert_before"; readonly anchor: Anchor; readonly body: string[] }
|
|
28
|
+
| { readonly op: "append"; readonly body: string[] }
|
|
29
|
+
| { readonly op: "prepend"; readonly body: string[] };
|
|
25
30
|
|
|
26
31
|
export type LineEnding = "lf" | "crlf";
|
|
27
32
|
|
|
@@ -41,13 +46,18 @@ export type LineEnding = "lf" | "crlf";
|
|
|
41
46
|
* - `none` — no candidate found, or recovery disabled; re-read.
|
|
42
47
|
*/
|
|
43
48
|
export type AnchorRecovery =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
| {
|
|
50
|
+
readonly kind: "found";
|
|
51
|
+
readonly scope: "local" | "full-file";
|
|
52
|
+
readonly newLine: number;
|
|
53
|
+
readonly newHash: string;
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
readonly kind: "ambiguous";
|
|
57
|
+
readonly scope: "local" | "full-file";
|
|
58
|
+
readonly candidates: ReadonlyArray<{ readonly line: number; readonly hash: string }>;
|
|
59
|
+
}
|
|
60
|
+
| { readonly kind: "none" };
|
|
51
61
|
|
|
52
62
|
/**
|
|
53
63
|
* A single anchor that failed verification, with its recovery attempt.
|
|
@@ -58,30 +68,35 @@ export type AnchorRecovery =
|
|
|
58
68
|
* out of range) — surfaced when recovery is `none` so the model can self-diagnose.
|
|
59
69
|
*/
|
|
60
70
|
export interface AnchorFailure {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
readonly opIndex: number;
|
|
72
|
+
readonly which: "anchor" | "end";
|
|
73
|
+
readonly op: Edit["op"];
|
|
74
|
+
readonly cited: Anchor;
|
|
75
|
+
readonly recovery: AnchorRecovery;
|
|
76
|
+
readonly current: { readonly hash: string; readonly content: string } | null;
|
|
67
77
|
}
|
|
68
78
|
|
|
69
|
-
/**
|
|
70
|
-
* Record for one supplied anchor in the immutable apply snapshot.
|
|
71
|
-
* not_checked means input validation rejected the batch before hashing.
|
|
72
|
-
*/
|
|
79
|
+
/** Record for one supplied anchor in the immutable apply snapshot. */
|
|
73
80
|
export interface AnchorCheck {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
readonly opIndex: number;
|
|
82
|
+
readonly which: "anchor" | "end";
|
|
83
|
+
readonly op: Edit["op"];
|
|
84
|
+
readonly cited: Anchor;
|
|
85
|
+
readonly status: "matched" | "mismatched";
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
/** Batch-level failure. Anchor checks describe only checksum validation in this snapshot. */
|
|
82
89
|
export type ApplyFailure =
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
| {
|
|
91
|
+
readonly kind: "anchor";
|
|
92
|
+
readonly failures: readonly AnchorFailure[];
|
|
93
|
+
readonly checks: readonly AnchorCheck[];
|
|
94
|
+
}
|
|
95
|
+
| {
|
|
96
|
+
readonly kind: "range";
|
|
97
|
+
readonly message: string;
|
|
98
|
+
readonly checks: readonly AnchorCheck[];
|
|
99
|
+
};
|
|
85
100
|
|
|
86
101
|
/**
|
|
87
102
|
* Apply result. On success, `touchedLines` lists 0-based NEW-file indices to
|
|
@@ -89,15 +104,15 @@ export type ApplyFailure =
|
|
|
89
104
|
* callers retain their content while compacting anchors for caller-supplied rows.
|
|
90
105
|
* Byte-identical output succeeds with changed=false and empty anchor lists.
|
|
91
106
|
* On failure, `failure` is either the collected set of anchor failures
|
|
92
|
-
* (each with recovery) or
|
|
107
|
+
* (each with recovery) or a range error, plus per-input anchor checks.
|
|
93
108
|
* Nothing is written on failure.
|
|
94
109
|
*/
|
|
95
110
|
export type ApplyResult =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
111
|
+
| {
|
|
112
|
+
readonly ok: true;
|
|
113
|
+
readonly text: string;
|
|
114
|
+
readonly changed: boolean;
|
|
115
|
+
readonly touchedLines: readonly number[];
|
|
116
|
+
readonly contextLines: readonly number[];
|
|
117
|
+
}
|
|
118
|
+
| { readonly ok: false; readonly failure: ApplyFailure };
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Overrides the built-in read/edit: read outputs "lineNo#hash│content";
|
|
5
5
|
* edit accepts structured hashline ops (edits[] with LINE#HASH anchors), and
|
|
6
|
-
* legacy oldText/newText is rejected
|
|
6
|
+
* legacy oldText/newText is rejected by the schema. grep
|
|
7
7
|
* is overridden the same way so results carry usable anchors. A separate
|
|
8
8
|
* `replace` tool adds location-blind bulk + regex replacement (replaceAll and
|
|
9
9
|
* full JS regex with capture groups) for renames/pattern transforms that
|
|
@@ -12,34 +12,38 @@
|
|
|
12
12
|
* @module pi-hashline-edit
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import type { TSchema } from "typebox";
|
|
16
17
|
import { loadConfig } from "./pi/config.ts";
|
|
17
|
-
import { getState } from "./pi/state.ts";
|
|
18
18
|
import { makeEditOverride } from "./pi/edit-tool.ts";
|
|
19
19
|
import { makeReadOverride } from "./pi/read-tool.ts";
|
|
20
20
|
import { makeGrepOverride } from "./pi/grep-tool.ts";
|
|
21
21
|
import { makeReplaceTool } from "./pi/replace-tool.ts";
|
|
22
22
|
import { makeWriteOverride } from "./pi/write-tool.ts";
|
|
23
23
|
import { createActionFusionExecutor } from "./pi/action-fusion.ts";
|
|
24
|
-
import { registerFusionCards } from "./pi/fusion-card.ts";
|
|
25
|
-
import { withMutationStatus } from "./pi/render.ts";
|
|
24
|
+
import { registerFusionCards, withMutationStatus } from "./pi/fusion-card.ts";
|
|
26
25
|
|
|
27
26
|
export default function (pi: ExtensionAPI) {
|
|
28
|
-
|
|
27
|
+
const cwd = process.cwd();
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// Tools capture this snapshot at registration; a reload registers them again.
|
|
30
|
+
const config = loadConfig(cwd);
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
// `enabled: false` leaves the extension fully inert — pi's built-in
|
|
33
|
+
// read/edit/grep/replace/write stay in place, as if this package were not installed.
|
|
34
|
+
if (config.enabled) {
|
|
35
|
+
const reportProgress = registerFusionCards(pi);
|
|
36
|
+
const fusion = config.actionFusion
|
|
37
|
+
? createActionFusionExecutor(undefined, reportProgress)
|
|
38
|
+
: undefined;
|
|
39
|
+
const registerMutation = <TParams extends TSchema, TDetails>(
|
|
40
|
+
tool: ToolDefinition<TParams, TDetails>,
|
|
41
|
+
) => pi.registerTool(fusion ? withMutationStatus(tool) : tool);
|
|
42
|
+
registerMutation(makeWriteOverride(cwd, fusion));
|
|
43
|
+
registerMutation(makeEditOverride(cwd, config, fusion));
|
|
44
|
+
registerMutation(makeReplaceTool(cwd, config, fusion));
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
pi.registerTool(makeReadOverride(cwd, config));
|
|
47
|
+
pi.registerTool(makeGrepOverride(cwd, config));
|
|
48
|
+
}
|
|
45
49
|
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import registerHashline from "../index.ts";
|
|
8
|
+
import { computeLineHash } from "../core/hash.ts";
|
|
9
|
+
import { callTool } from "../pi/tool-call.testing.ts";
|
|
10
|
+
import { DEFAULT_CONFIG, type HashlineEditConfig } from "../pi/config.ts";
|
|
11
|
+
|
|
12
|
+
test("registered tools retain their configuration when another tool set is registered", async (t) => {
|
|
13
|
+
const directory = await mkdtemp(join(tmpdir(), "hashline-config-registration-"));
|
|
14
|
+
const previousCwd = process.cwd();
|
|
15
|
+
try {
|
|
16
|
+
await mkdir(join(directory, ".pi"));
|
|
17
|
+
process.chdir(directory);
|
|
18
|
+
const register = async (config: HashlineEditConfig) => {
|
|
19
|
+
await writeFile(
|
|
20
|
+
join(directory, ".pi", "settings.json"),
|
|
21
|
+
JSON.stringify({ hashlineEdit: config }),
|
|
22
|
+
);
|
|
23
|
+
const tools = new Map<string, ToolDefinition>();
|
|
24
|
+
registerHashline({
|
|
25
|
+
on() {},
|
|
26
|
+
registerEntryRenderer() {},
|
|
27
|
+
registerTool(tool: ToolDefinition) {
|
|
28
|
+
tools.set(tool.name, tool);
|
|
29
|
+
},
|
|
30
|
+
} as unknown as ExtensionAPI);
|
|
31
|
+
return { tools, config };
|
|
32
|
+
};
|
|
33
|
+
const registrations = [
|
|
34
|
+
{
|
|
35
|
+
...(await register({
|
|
36
|
+
...DEFAULT_CONFIG,
|
|
37
|
+
actionFusion: false,
|
|
38
|
+
hashLen: 6,
|
|
39
|
+
shiftRadius: 1,
|
|
40
|
+
read: { defaultLimit: 1, maxKiB: 1 },
|
|
41
|
+
grep: { defaultLimit: 1, defaultContext: 1 },
|
|
42
|
+
replace: { regexTimeoutMs: 1_000 },
|
|
43
|
+
})),
|
|
44
|
+
expectedGrepLines: [1, 2, 3],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
...(await register({
|
|
48
|
+
...DEFAULT_CONFIG,
|
|
49
|
+
actionFusion: false,
|
|
50
|
+
hashLen: 8,
|
|
51
|
+
shiftRadius: 0,
|
|
52
|
+
read: { defaultLimit: 2, maxKiB: 2 },
|
|
53
|
+
grep: { defaultLimit: 2, defaultContext: 0 },
|
|
54
|
+
replace: { regexTimeoutMs: 1_500 },
|
|
55
|
+
})),
|
|
56
|
+
expectedGrepLines: [2, 6],
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
for (const { tools, config, expectedGrepLines } of registrations) {
|
|
61
|
+
const { hashLen, shiftRadius, read, grep, replace } = config;
|
|
62
|
+
for (const name of ["read", "grep", "replace", "edit"] as const) {
|
|
63
|
+
await t.test(`${name} retains the registered hash length ${hashLen}`, async () => {
|
|
64
|
+
const tool = tools.get(name);
|
|
65
|
+
assert.ok(tool);
|
|
66
|
+
const path = `${hashLen}-${name}.txt`;
|
|
67
|
+
await writeFile(join(directory, path), "before\n");
|
|
68
|
+
const params = {
|
|
69
|
+
read: { path },
|
|
70
|
+
grep: { path, pattern: "before", literal: true },
|
|
71
|
+
replace: { path, replacements: [{ find: "before", replace: "after" }] },
|
|
72
|
+
edit: {
|
|
73
|
+
path,
|
|
74
|
+
edits: [
|
|
75
|
+
{
|
|
76
|
+
op: "replace",
|
|
77
|
+
anchor: `1#${computeLineHash(1, "before", hashLen)}`,
|
|
78
|
+
body: ["after"],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
}[name];
|
|
83
|
+
const result = await callTool(tool, params);
|
|
84
|
+
const expected = name === "read" || name === "grep" ? "before" : "after";
|
|
85
|
+
const anchor = `1#${computeLineHash(1, expected, hashLen)}`;
|
|
86
|
+
assert.match(result.content[0].text, new RegExp(`^${anchor}(?:│|$)`, "m"));
|
|
87
|
+
assert.equal(await readFile(join(directory, path), "utf8"), `${expected}\n`);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await t.test(`edit retains the registered recovery radius ${shiftRadius}`, async () => {
|
|
92
|
+
const tool = tools.get("edit");
|
|
93
|
+
assert.ok(tool);
|
|
94
|
+
const path = `${hashLen}-recovery.txt`;
|
|
95
|
+
const text = "changed\ntarget\n";
|
|
96
|
+
await writeFile(join(directory, path), text);
|
|
97
|
+
await assert.rejects(
|
|
98
|
+
callTool(tool, {
|
|
99
|
+
path,
|
|
100
|
+
edits: [{ op: "delete", anchor: `1#${computeLineHash(1, "target", hashLen)}` }],
|
|
101
|
+
}),
|
|
102
|
+
shiftRadius === 0
|
|
103
|
+
? /no checksum-matching candidate found/
|
|
104
|
+
: /checksum-matching candidate 2#/,
|
|
105
|
+
);
|
|
106
|
+
assert.equal(await readFile(join(directory, path), "utf8"), text);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await t.test(
|
|
110
|
+
`read retains registered limit ${read.defaultLimit} and budget ${read.maxKiB} KiB`,
|
|
111
|
+
async () => {
|
|
112
|
+
const tool = tools.get("read");
|
|
113
|
+
assert.ok(tool);
|
|
114
|
+
const path = `${hashLen}-read-settings.txt`;
|
|
115
|
+
const lines = ["first", "second", "third"];
|
|
116
|
+
await writeFile(join(directory, path), `${lines.join("\n")}\n`);
|
|
117
|
+
const result = await callTool(tool, { path });
|
|
118
|
+
assert.deepEqual(
|
|
119
|
+
result.content[0].text.split("\n").filter((line: string) => /^\d+#/.test(line)),
|
|
120
|
+
lines
|
|
121
|
+
.slice(0, read.defaultLimit)
|
|
122
|
+
.map(
|
|
123
|
+
(content, index) =>
|
|
124
|
+
`${index + 1}#${computeLineHash(index + 1, content, hashLen)}│${content}`,
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
assert.equal(result.details.pagination.nextOffset, read.defaultLimit + 1);
|
|
128
|
+
|
|
129
|
+
const wide = "界".repeat(500);
|
|
130
|
+
await writeFile(join(directory, path), `${wide}\n`);
|
|
131
|
+
const bounded = await callTool(tool, { path });
|
|
132
|
+
if (read.maxKiB === 1) {
|
|
133
|
+
assert.match(bounded.content[0].text, /line 1 exceeds 1 KiB/);
|
|
134
|
+
assert.equal(bounded.details.truncation.maxBytes, 1024);
|
|
135
|
+
assert.equal(bounded.details.truncation.outputBytes, 0);
|
|
136
|
+
} else {
|
|
137
|
+
assert.ok(
|
|
138
|
+
bounded.content[0].text.includes(`1#${computeLineHash(1, wide, hashLen)}│${wide}`),
|
|
139
|
+
);
|
|
140
|
+
assert.equal(bounded.details, undefined);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
await t.test(
|
|
146
|
+
`grep retains registered limit ${grep.defaultLimit} and context ${grep.defaultContext}`,
|
|
147
|
+
async () => {
|
|
148
|
+
const tool = tools.get("grep");
|
|
149
|
+
assert.ok(tool);
|
|
150
|
+
const path = `${hashLen}-grep-settings.txt`;
|
|
151
|
+
const lines = [
|
|
152
|
+
"before one",
|
|
153
|
+
"needle one",
|
|
154
|
+
"after one",
|
|
155
|
+
"gap",
|
|
156
|
+
"before two",
|
|
157
|
+
"needle two",
|
|
158
|
+
"after two",
|
|
159
|
+
"gap",
|
|
160
|
+
"before three",
|
|
161
|
+
"needle three",
|
|
162
|
+
"after three",
|
|
163
|
+
];
|
|
164
|
+
await writeFile(join(directory, path), `${lines.join("\n")}\n`);
|
|
165
|
+
const result = await callTool(tool, { path, pattern: "needle", literal: true });
|
|
166
|
+
assert.deepEqual(
|
|
167
|
+
result.content[0].text.split("\n").filter((line: string) => /^\d+#/.test(line)),
|
|
168
|
+
expectedGrepLines.map(
|
|
169
|
+
(line) =>
|
|
170
|
+
`${line}#${computeLineHash(line, lines[line - 1], hashLen)}│${lines[line - 1]}`,
|
|
171
|
+
),
|
|
172
|
+
);
|
|
173
|
+
assert.match(
|
|
174
|
+
result.content[0].text,
|
|
175
|
+
new RegExp(`${grep.defaultLimit} matches limit reached`),
|
|
176
|
+
);
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
await t.test(
|
|
181
|
+
`replace retains registered regex timeout ${replace.regexTimeoutMs}ms`,
|
|
182
|
+
async () => {
|
|
183
|
+
const tool = tools.get("replace");
|
|
184
|
+
assert.ok(tool);
|
|
185
|
+
const path = `${hashLen}-replace-settings.txt`;
|
|
186
|
+
const original = `${"a".repeat(35)}!`;
|
|
187
|
+
await writeFile(join(directory, path), original);
|
|
188
|
+
await assert.rejects(
|
|
189
|
+
callTool(tool, {
|
|
190
|
+
path,
|
|
191
|
+
replacements: [{ find: "^(a+)+$", replace: "changed", regex: true }],
|
|
192
|
+
}),
|
|
193
|
+
(error: unknown) =>
|
|
194
|
+
error instanceof Error &&
|
|
195
|
+
error.message ===
|
|
196
|
+
`Replace ${path}: regex evaluation timed out after ${replace.regexTimeoutMs}ms`,
|
|
197
|
+
);
|
|
198
|
+
assert.equal(await readFile(join(directory, path), "utf8"), original);
|
|
199
|
+
},
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
} finally {
|
|
203
|
+
process.chdir(previousCwd);
|
|
204
|
+
await rm(directory, { recursive: true, force: true });
|
|
205
|
+
}
|
|
206
|
+
});
|