@criogaid/pi-hashline-edit 0.13.0 → 0.15.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 +18 -12
- package/README.zh-CN.md +18 -12
- package/package.json +8 -1
- package/src/core/AGENTS.md +3 -1
- package/src/core/apply.ts +110 -117
- package/src/core/character-set.ts +2 -3
- package/src/core/copy-span.ts +15 -0
- package/src/core/errors.ts +24 -9
- package/src/core/lines.ts +71 -17
- package/src/core/ranges.ts +5 -4
- package/src/core/replace-schema.ts +3 -1
- package/src/core/replace.ts +50 -29
- package/src/core/search-analysis.ts +21 -22
- package/src/core/search.ts +15 -32
- package/src/core/types.ts +3 -0
- package/src/index.ts +47 -39
- package/src/pi/AGENTS.md +30 -19
- package/src/pi/action-fusion.ts +284 -211
- package/src/pi/argument-diagnostics.ts +50 -37
- package/src/pi/argument-error.ts +2 -2
- package/src/pi/argument-validation.ts +163 -66
- package/src/pi/budgets.ts +12 -0
- package/src/pi/diagnostic-buffer.ts +12 -11
- package/src/pi/edit-tool.ts +138 -115
- package/src/pi/error-text.ts +10 -2
- package/src/pi/failure-context.ts +24 -37
- package/src/pi/file-commit.ts +131 -164
- package/src/pi/file-read.ts +122 -31
- package/src/pi/fusion-arguments.ts +214 -0
- package/src/pi/fusion-card.ts +102 -60
- package/src/pi/grep-candidates.ts +35 -22
- package/src/pi/grep-output.ts +197 -190
- package/src/pi/grep-render.ts +22 -13
- package/src/pi/grep-reread.ts +7 -6
- package/src/pi/grep-scope.ts +31 -16
- package/src/pi/grep-search.ts +56 -47
- package/src/pi/grep-tool.ts +35 -33
- package/src/pi/grep-worker.ts +3 -4
- package/src/pi/mutation-diff.ts +238 -0
- package/src/pi/mutation-result.ts +102 -79
- package/src/pi/mutation-runner.ts +107 -84
- package/src/pi/native-bash.ts +41 -0
- package/src/pi/path.ts +59 -6
- package/src/pi/read-tool.ts +173 -138
- package/src/pi/regex-worker.ts +14 -8
- package/src/pi/render.ts +101 -54
- package/src/pi/replace-regex.ts +1 -1
- package/src/pi/replace-tool.ts +14 -7
- package/src/pi/report-cause.ts +34 -17
- package/src/pi/report-schema.ts +184 -85
- package/src/pi/report.ts +133 -64
- package/src/pi/rg-process.ts +68 -48
- package/src/pi/schema.ts +4 -0
- package/src/pi/text-stream.ts +81 -87
- package/src/pi/workspace-cwd.js +2 -0
- package/src/pi/workspace.ts +46 -0
- package/src/pi/write-tool.ts +19 -13
- package/src/core/apply.test.ts +0 -644
- package/src/core/case-fold.test.ts +0 -35
- package/src/core/character-set.test.ts +0 -97
- package/src/core/errors.test.ts +0 -39
- package/src/core/hash.test.ts +0 -64
- package/src/core/lines.test.ts +0 -63
- package/src/core/ranges.test.ts +0 -123
- package/src/core/replace.test.ts +0 -187
- package/src/core/search-analysis.test.ts +0 -210
- package/src/core/search-matrix.test.ts +0 -64
- package/src/core/search-matrix.testing.ts +0 -171
- package/src/core/search.test.ts +0 -132
- package/src/core/text.test.ts +0 -52
- package/src/integration/config-registration.test.ts +0 -291
- package/src/integration/fusion-dispatch.test.ts +0 -320
- package/src/integration/grep-errors.test.ts +0 -81
- package/src/integration/grep-flags.test.ts +0 -76
- package/src/integration/grep-js-completeness.test.ts +0 -278
- package/src/integration/grep-line-candidates.test.ts +0 -201
- package/src/integration/grep-matrix.test.ts +0 -118
- package/src/integration/grep-order.test.ts +0 -78
- package/src/integration/grep-path-matrix.test.ts +0 -128
- package/src/integration/grep-prefilter-coverage.test.ts +0 -204
- package/src/integration/grep-process-limits.test.ts +0 -122
- package/src/integration/grep-regex.test.ts +0 -412
- package/src/integration/grep-rg.test.ts +0 -1659
- package/src/integration/grep-scan-budget.test.ts +0 -111
- package/src/integration/grep-translation.test.ts +0 -199
- package/src/integration/large-text.test.ts +0 -70
- package/src/integration/model-budget-lifecycle.test.ts +0 -186
- package/src/integration/mutation-file-types.test.ts +0 -30
- package/src/integration/mutation-file-types.testing.ts +0 -33
- package/src/integration/npm-package.test.ts +0 -19
- package/src/integration/npm-package.testing.ts +0 -243
- package/src/integration/publication-read-changes.test.ts +0 -454
- package/src/integration/read-changes.test.ts +0 -98
- package/src/integration/replace-package.test.ts +0 -22
- package/src/integration/replace-package.testing.ts +0 -36
- package/src/integration/replace-worker-boundary.test.ts +0 -127
- package/src/integration/report-replay.test.ts +0 -91
- package/src/integration/utf8-errors.test.ts +0 -46
- package/src/pi/action-fusion.test.ts +0 -659
- package/src/pi/action-fusion.testing.ts +0 -38
- package/src/pi/anchor-format.test.ts +0 -124
- package/src/pi/argument-error.testing.ts +0 -46
- package/src/pi/argument-format.test.ts +0 -196
- package/src/pi/argument-validation.test.ts +0 -1007
- package/src/pi/codemode.test.ts +0 -101
- package/src/pi/config.test.ts +0 -204
- package/src/pi/diagnostic-buffer.test.ts +0 -115
- package/src/pi/directory-sync.test.ts +0 -57
- package/src/pi/execute.test.ts +0 -1257
- package/src/pi/extension-loading.test.ts +0 -14
- package/src/pi/extension-loading.testing.ts +0 -3
- package/src/pi/failure-context.test.ts +0 -370
- package/src/pi/failure-path.test.ts +0 -289
- package/src/pi/file-commit.test.ts +0 -628
- package/src/pi/file-read.test.ts +0 -29
- package/src/pi/file-snapshot.test.ts +0 -22
- package/src/pi/fusion-card-interaction.test.ts +0 -143
- package/src/pi/fusion-card.test.ts +0 -353
- package/src/pi/grep-candidates.test.ts +0 -26
- package/src/pi/grep-matrix.test.ts +0 -68
- package/src/pi/grep-order.test.ts +0 -447
- package/src/pi/grep-output.testing.ts +0 -24
- package/src/pi/grep-rg.testing.ts +0 -73
- package/src/pi/grep.test.ts +0 -1670
- package/src/pi/model-budgets.test.ts +0 -96
- package/src/pi/mutation-outcome.testing.ts +0 -20
- package/src/pi/mutation-result.test.ts +0 -96
- package/src/pi/output-budgets.test.ts +0 -221
- package/src/pi/pi.test.ts +0 -158
- package/src/pi/read-delegation.test.ts +0 -119
- package/src/pi/read.test.ts +0 -735
- package/src/pi/regex-worker.test.ts +0 -42
- package/src/pi/registration.test.ts +0 -549
- package/src/pi/render.test.ts +0 -841
- package/src/pi/replace.test.ts +0 -634
- package/src/pi/report-failure.testing.ts +0 -27
- package/src/pi/report.test.ts +0 -533
- package/src/pi/result-safety.test.ts +0 -597
- package/src/pi/rg-process.test.ts +0 -133
- package/src/pi/rg-regex.test.ts +0 -40
- package/src/pi/text-stream.test.ts +0 -281
- package/src/pi/tool-call.testing.ts +0 -61
- package/src/pi/tool-factories.testing.ts +0 -59
- package/src/pi/write.test.ts +0 -256
- package/src/testing/extension-loader.testing.ts +0 -24
- package/src/testing/installation.testing.ts +0 -77
- package/src/testing/process.testing.ts +0 -33
- package/src/testing/regex-host.testing.ts +0 -20
- package/src/testing/regex-translation-corpus.ts +0 -267
- package/src/testing/rg-line-listing.fixture.mjs +0 -7
- package/src/testing/run-tests.ts +0 -47
- package/src/testing/session.testing.ts +0 -127
package/src/pi/codemode.test.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { test } from "node:test";
|
|
5
|
-
import { Type } from "typebox";
|
|
6
|
-
import { createCodemodeToolDefinition } from "../../node_modules/@earendil-works/pi-coding-agent/dist/extensions/codemode/tool.js";
|
|
7
|
-
import { openTestSession, responseStream, SESSION_TIMEOUT_MS } from "../testing/session.testing.ts";
|
|
8
|
-
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
9
|
-
import { makeWriteOverride } from "./tool-factories.testing.ts";
|
|
10
|
-
|
|
11
|
-
for (const entry of ["direct", "codemode"] as const) {
|
|
12
|
-
test(`${entry} mutation waits on then_run → the call and model continuation stay pending`, {
|
|
13
|
-
timeout: SESSION_TIMEOUT_MS,
|
|
14
|
-
}, async (t) => {
|
|
15
|
-
const started = Promise.withResolvers<void>();
|
|
16
|
-
const finished = Promise.withResolvers<void>();
|
|
17
|
-
const { cwd, session, model } = await openTestSession(t, {
|
|
18
|
-
tools: ["write", "bash", "codemode"],
|
|
19
|
-
configure(pi, cwd) {
|
|
20
|
-
pi.registerTool(
|
|
21
|
-
makeWriteOverride(
|
|
22
|
-
cwd,
|
|
23
|
-
createActionFusionExecutor(() => {}),
|
|
24
|
-
),
|
|
25
|
-
);
|
|
26
|
-
pi.registerTool(createCodemodeToolDefinition());
|
|
27
|
-
pi.registerTool({
|
|
28
|
-
name: "bash",
|
|
29
|
-
label: "bash",
|
|
30
|
-
description: "Hold the requested command until the test releases it",
|
|
31
|
-
parameters: Type.Object({ command: Type.String() }),
|
|
32
|
-
async execute() {
|
|
33
|
-
started.resolve();
|
|
34
|
-
await finished.promise;
|
|
35
|
-
return { content: [{ type: "text", text: "checked" }], details: undefined };
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
const ended: string[] = [];
|
|
41
|
-
session.subscribe((event) => {
|
|
42
|
-
if (event.type === "tool_execution_end") ended.push(event.toolName);
|
|
43
|
-
});
|
|
44
|
-
const args = {
|
|
45
|
-
path: "saved.txt",
|
|
46
|
-
mode: "create",
|
|
47
|
-
content: "saved\n",
|
|
48
|
-
then_run: { command: "held command" },
|
|
49
|
-
};
|
|
50
|
-
let requests = 0;
|
|
51
|
-
session.agent.streamFunction = () => {
|
|
52
|
-
const first = requests++ === 0;
|
|
53
|
-
assert.ok(requests <= 2, "Unexpected model continuation");
|
|
54
|
-
return responseStream(model, {
|
|
55
|
-
content: first
|
|
56
|
-
? [
|
|
57
|
-
{
|
|
58
|
-
type: "toolCall",
|
|
59
|
-
id: "mutation",
|
|
60
|
-
name: entry === "direct" ? "write" : "codemode",
|
|
61
|
-
arguments:
|
|
62
|
-
entry === "direct"
|
|
63
|
-
? args
|
|
64
|
-
: {
|
|
65
|
-
code: `text(await tools.write(${JSON.stringify(args)})); text("AFTER_WRITE");`,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
]
|
|
69
|
-
: [{ type: "text", text: "Done." }],
|
|
70
|
-
stopReason: first ? "toolUse" : "stop",
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
const pending = session.prompt("Run the mutation and its command.");
|
|
74
|
-
try {
|
|
75
|
-
await started.promise;
|
|
76
|
-
assert.equal(await readFile(join(cwd, "saved.txt"), "utf8"), "saved\n");
|
|
77
|
-
assert.equal(requests, 1, "The model must not continue before then_run ends");
|
|
78
|
-
assert.ok(!ended.includes("write"));
|
|
79
|
-
assert.ok(!ended.includes("codemode"));
|
|
80
|
-
} finally {
|
|
81
|
-
finished.resolve();
|
|
82
|
-
await pending;
|
|
83
|
-
}
|
|
84
|
-
assert.equal(session.agent.state.errorMessage, undefined);
|
|
85
|
-
assert.equal(requests, 2);
|
|
86
|
-
assert.ok(ended.includes("write"));
|
|
87
|
-
const result = session.agent.state.messages.find(
|
|
88
|
-
(message) => message.role === "toolResult" && message.toolCallId === "mutation",
|
|
89
|
-
);
|
|
90
|
-
assert.ok(result?.role === "toolResult");
|
|
91
|
-
assert.equal(result.isError, false);
|
|
92
|
-
if (entry === "codemode") {
|
|
93
|
-
assert.ok(ended.includes("codemode"));
|
|
94
|
-
const output = result.content
|
|
95
|
-
.filter((block) => block.type === "text")
|
|
96
|
-
.map((block) => block.text)
|
|
97
|
-
.join("\n");
|
|
98
|
-
assert.match(output, /"then_run":\s*\{\s*"status":\s*"succeeded"[\s\S]*AFTER_WRITE/);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
package/src/pi/config.test.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_MAX_LINES } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import assert from "node:assert/strict";
|
|
6
|
-
import { test } from "node:test";
|
|
7
|
-
import { loadConfig } from "./config.ts";
|
|
8
|
-
import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
|
|
9
|
-
|
|
10
|
-
async function withSettings(
|
|
11
|
-
fn: (
|
|
12
|
-
write: (settings: unknown) => Promise<void>,
|
|
13
|
-
root: string,
|
|
14
|
-
agentDir: string,
|
|
15
|
-
) => Promise<void>,
|
|
16
|
-
) {
|
|
17
|
-
const root = await mkdtemp(join(tmpdir(), "hashline-config-"));
|
|
18
|
-
const agentDir = join(root, "agent");
|
|
19
|
-
const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
20
|
-
try {
|
|
21
|
-
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
22
|
-
await mkdir(agentDir);
|
|
23
|
-
await mkdir(join(root, ".pi"));
|
|
24
|
-
const path = join(root, ".pi", "settings.json");
|
|
25
|
-
await fn((settings) => writeFile(path, JSON.stringify(settings)), root, agentDir);
|
|
26
|
-
} finally {
|
|
27
|
-
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
28
|
-
else process.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
29
|
-
await rm(root, { recursive: true, force: true });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test("defaults come from the settings schema", () => {
|
|
34
|
-
assert.deepEqual(DEFAULT_CONFIG, {
|
|
35
|
-
enabled: true,
|
|
36
|
-
actionFusion: true,
|
|
37
|
-
hashLen: 4,
|
|
38
|
-
shiftRadius: 15,
|
|
39
|
-
read: { defaultLimit: DEFAULT_MAX_LINES, maxKiB: undefined },
|
|
40
|
-
grep: { defaultLimit: 100, defaultContext: 0, regexTimeoutMs: 5_000 },
|
|
41
|
-
replace: { regexTimeoutMs: 5_000 },
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("actionFusion defaults on and honors explicit disabling", () =>
|
|
46
|
-
withSettings(async (write, root) => {
|
|
47
|
-
for (const [actionFusion, expected] of [
|
|
48
|
-
[undefined, true],
|
|
49
|
-
[false, false],
|
|
50
|
-
[true, true],
|
|
51
|
-
[null, true],
|
|
52
|
-
["false", true],
|
|
53
|
-
[0, true],
|
|
54
|
-
]) {
|
|
55
|
-
await write({ hashlineEdit: { actionFusion } });
|
|
56
|
-
assert.deepEqual(loadConfig(root), { ...DEFAULT_CONFIG, actionFusion: expected });
|
|
57
|
-
}
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
test("invalid or unknown settings → preserve valid leaves and default malformed values", () =>
|
|
61
|
-
withSettings(async (write, root) => {
|
|
62
|
-
for (const value of [3.5, -1, "4", null]) {
|
|
63
|
-
await write({ hashlineEdit: { hashLen: value, shiftRadius: value } });
|
|
64
|
-
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
65
|
-
}
|
|
66
|
-
for (const rootValue of [
|
|
67
|
-
null,
|
|
68
|
-
[],
|
|
69
|
-
42,
|
|
70
|
-
"settings",
|
|
71
|
-
{ hashlineEdit: [] },
|
|
72
|
-
{ hashlineEdit: "invalid" },
|
|
73
|
-
]) {
|
|
74
|
-
await write(rootValue);
|
|
75
|
-
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
76
|
-
}
|
|
77
|
-
await write({ hashlineEdit: { hashLen: 8, shiftRadius: 0, unexpected: true } });
|
|
78
|
-
assert.deepEqual(loadConfig(root), { ...DEFAULT_CONFIG, hashLen: 8, shiftRadius: 0 });
|
|
79
|
-
}));
|
|
80
|
-
|
|
81
|
-
test("tool groups resolve each setting independently", () =>
|
|
82
|
-
withSettings(async (write, root) => {
|
|
83
|
-
await write({
|
|
84
|
-
hashlineEdit: {
|
|
85
|
-
read: { defaultLimit: 50, maxKiB: 0 },
|
|
86
|
-
grep: { ...DEFAULT_CONFIG.grep, defaultContext: 21, defaultLimit: 7 },
|
|
87
|
-
replace: "fast",
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
assert.deepEqual(loadConfig(root), {
|
|
91
|
-
...DEFAULT_CONFIG,
|
|
92
|
-
read: { defaultLimit: 50, maxKiB: DEFAULT_CONFIG.read.maxKiB },
|
|
93
|
-
grep: {
|
|
94
|
-
...DEFAULT_CONFIG.grep,
|
|
95
|
-
defaultLimit: 7,
|
|
96
|
-
defaultContext: DEFAULT_CONFIG.grep.defaultContext,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
await write({ hashlineEdit: { replace: { regexTimeoutMs: 20_000 } } });
|
|
100
|
-
assert.equal(loadConfig(root).replace.regexTimeoutMs, 20_000);
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
test("project settings replace global groups while absent project settings use global values", () =>
|
|
104
|
-
withSettings(async (write, root, agentDir) => {
|
|
105
|
-
const globalConfig = {
|
|
106
|
-
...DEFAULT_CONFIG,
|
|
107
|
-
enabled: false,
|
|
108
|
-
actionFusion: false,
|
|
109
|
-
hashLen: 8,
|
|
110
|
-
shiftRadius: 0,
|
|
111
|
-
read: { defaultLimit: 7, maxKiB: 2 },
|
|
112
|
-
grep: { ...DEFAULT_CONFIG.grep, defaultLimit: 3, defaultContext: 2 },
|
|
113
|
-
replace: { regexTimeoutMs: 3_000 },
|
|
114
|
-
};
|
|
115
|
-
await writeFile(
|
|
116
|
-
join(agentDir, "settings.json"),
|
|
117
|
-
JSON.stringify({ hashlineEdit: globalConfig }),
|
|
118
|
-
);
|
|
119
|
-
const withoutSettings = join(root, "without-settings");
|
|
120
|
-
await mkdir(withoutSettings);
|
|
121
|
-
assert.deepEqual(loadConfig(withoutSettings), globalConfig);
|
|
122
|
-
assert.deepEqual(loadConfig(root), globalConfig);
|
|
123
|
-
for (const settings of [{}, null, [], 42, "settings"]) {
|
|
124
|
-
await write(settings);
|
|
125
|
-
assert.deepEqual(loadConfig(root), globalConfig);
|
|
126
|
-
}
|
|
127
|
-
await write({ hashlineEdit: { read: { defaultLimit: 2 } } });
|
|
128
|
-
assert.deepEqual(loadConfig(root), {
|
|
129
|
-
...DEFAULT_CONFIG,
|
|
130
|
-
read: { defaultLimit: 2, maxKiB: DEFAULT_CONFIG.read.maxKiB },
|
|
131
|
-
});
|
|
132
|
-
await write({ hashlineEdit: {} });
|
|
133
|
-
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
134
|
-
}));
|
|
135
|
-
|
|
136
|
-
test("project hashlineEdit is null → replaces global settings with defaults", () =>
|
|
137
|
-
withSettings(async (write, root, agentDir) => {
|
|
138
|
-
const globalConfig = { ...DEFAULT_CONFIG, enabled: false, hashLen: 8 };
|
|
139
|
-
await writeFile(
|
|
140
|
-
join(agentDir, "settings.json"),
|
|
141
|
-
JSON.stringify({ hashlineEdit: globalConfig }),
|
|
142
|
-
);
|
|
143
|
-
assert.deepEqual(loadConfig(root), globalConfig);
|
|
144
|
-
await write({ hashlineEdit: null });
|
|
145
|
-
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
146
|
-
}));
|
|
147
|
-
|
|
148
|
-
test("invalid tool groups default independently without discarding valid sibling groups", () =>
|
|
149
|
-
withSettings(async (write, root) => {
|
|
150
|
-
const configured = {
|
|
151
|
-
...DEFAULT_CONFIG,
|
|
152
|
-
enabled: false,
|
|
153
|
-
hashLen: 6,
|
|
154
|
-
shiftRadius: 0,
|
|
155
|
-
read: { defaultLimit: 2, maxKiB: 1 },
|
|
156
|
-
grep: { ...DEFAULT_CONFIG.grep, defaultLimit: 3, defaultContext: 2 },
|
|
157
|
-
replace: { regexTimeoutMs: 3_000 },
|
|
158
|
-
};
|
|
159
|
-
for (const group of ["read", "grep", "replace"] as const) {
|
|
160
|
-
for (const value of [null, [], 42, "invalid", true]) {
|
|
161
|
-
await write({ hashlineEdit: { ...configured, [group]: value } });
|
|
162
|
-
assert.deepEqual(loadConfig(root), { ...configured, [group]: DEFAULT_CONFIG[group] });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}));
|
|
166
|
-
|
|
167
|
-
test("tool settings accept their boundary values and default invalid leaves", () =>
|
|
168
|
-
withSettings(async (write, root) => {
|
|
169
|
-
const cases = [
|
|
170
|
-
{
|
|
171
|
-
group: "read",
|
|
172
|
-
key: "defaultLimit",
|
|
173
|
-
valid: [1, Number.MAX_SAFE_INTEGER],
|
|
174
|
-
invalid: [0, -1, 1.5, Number.MAX_SAFE_INTEGER + 1, "2", null],
|
|
175
|
-
},
|
|
176
|
-
{ group: "read", key: "maxKiB", valid: [1, 4096], invalid: [0, 4097, 1.5, "2", null] },
|
|
177
|
-
{
|
|
178
|
-
group: "grep",
|
|
179
|
-
key: "defaultLimit",
|
|
180
|
-
valid: [1, Number.MAX_SAFE_INTEGER],
|
|
181
|
-
invalid: [0, -1, 1.5, Number.MAX_SAFE_INTEGER + 1, "2", null],
|
|
182
|
-
},
|
|
183
|
-
{ group: "grep", key: "defaultContext", valid: [0, 20], invalid: [-1, 21, 1.5, "2", null] },
|
|
184
|
-
{
|
|
185
|
-
group: "replace",
|
|
186
|
-
key: "regexTimeoutMs",
|
|
187
|
-
valid: [3_000, 300_000],
|
|
188
|
-
invalid: [2_999, 300_001, 3000.5, "3000", null],
|
|
189
|
-
},
|
|
190
|
-
] as const;
|
|
191
|
-
for (const { group, key, valid, invalid } of cases) {
|
|
192
|
-
for (const value of valid) {
|
|
193
|
-
await write({ hashlineEdit: { [group]: { [key]: value } } });
|
|
194
|
-
assert.deepEqual(loadConfig(root), {
|
|
195
|
-
...DEFAULT_CONFIG,
|
|
196
|
-
[group]: { ...DEFAULT_CONFIG[group], [key]: value },
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
for (const value of invalid) {
|
|
200
|
-
await write({ hashlineEdit: { [group]: { [key]: value } } });
|
|
201
|
-
assert.deepEqual(loadConfig(root), DEFAULT_CONFIG);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}));
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { test } from "node:test";
|
|
3
|
-
import childProcess from "node:child_process";
|
|
4
|
-
import { syncBuiltinESMExports } from "node:module";
|
|
5
|
-
import { DiagnosticBuffer } from "./diagnostic-buffer.ts";
|
|
6
|
-
import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
|
|
7
|
-
import { grepOutput } from "./grep-output.ts";
|
|
8
|
-
import { createAnchorFormatter } from "./anchor-format.ts";
|
|
9
|
-
import { runRgPaths } from "./rg-process.ts";
|
|
10
|
-
const MAX_RG_STDERR_BYTES = 64 * 1024;
|
|
11
|
-
import { mkdtemp, writeFile, rm } from "node:fs/promises";
|
|
12
|
-
import { tmpdir } from "node:os";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
|
|
15
|
-
const diagnostic = (size: number) =>
|
|
16
|
-
`regex parse error:\n${"intermediate context 中🙂\n".repeat(size)}error: unclosed group\n`;
|
|
17
|
-
|
|
18
|
-
test("bounded diagnostics retain opening context and the final cause across streamed chunks", () => {
|
|
19
|
-
const source = diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes);
|
|
20
|
-
const buffer = new DiagnosticBuffer(DEFAULT_OUTPUT_BUDGETS.fieldBytes);
|
|
21
|
-
const chunkChars = 113;
|
|
22
|
-
for (let offset = 0; offset < source.length; offset += chunkChars) {
|
|
23
|
-
buffer.append(source.slice(offset, offset + chunkChars));
|
|
24
|
-
}
|
|
25
|
-
const result = buffer.toString();
|
|
26
|
-
assert.match(result, /^regex parse error:/);
|
|
27
|
-
assert.match(result, /error: unclosed group\n$/);
|
|
28
|
-
assert.match(result, /omitted/i);
|
|
29
|
-
assert.ok(Buffer.byteLength(result) <= DEFAULT_OUTPUT_BUDGETS.fieldBytes);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("a diagnostic is one oversized line → retain its opening and final cause without splitting UTF-8", () => {
|
|
33
|
-
const source = `opening cause: ${"中🙂".repeat(DEFAULT_OUTPUT_BUDGETS.fieldBytes)}; final recovery`;
|
|
34
|
-
const buffer = new DiagnosticBuffer(DEFAULT_OUTPUT_BUDGETS.fieldBytes);
|
|
35
|
-
buffer.append(source);
|
|
36
|
-
const result = buffer.toString();
|
|
37
|
-
assert.match(result, /^opening cause:/);
|
|
38
|
-
assert.match(result, /final recovery$/);
|
|
39
|
-
assert.match(result, /omitted/);
|
|
40
|
-
assert.doesNotMatch(result, /�/);
|
|
41
|
-
assert.ok(Buffer.byteLength(result) <= DEFAULT_OUTPUT_BUDGETS.fieldBytes);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("diagnostics within the budget are unchanged", () => {
|
|
45
|
-
const buffer = new DiagnosticBuffer(DEFAULT_OUTPUT_BUDGETS.fieldBytes);
|
|
46
|
-
const source = "path: 权限不足🙂\nretry with another path\n";
|
|
47
|
-
for (const point of source) buffer.append(point);
|
|
48
|
-
assert.equal(buffer.toString(), source);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("search warning aggregation retains the final cause and labels truncation", async () => {
|
|
52
|
-
const { facts, payload } = await grepOutput({
|
|
53
|
-
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
54
|
-
cwd: process.cwd(),
|
|
55
|
-
missing: [],
|
|
56
|
-
anchors: createAnchorFormatter(4),
|
|
57
|
-
context: 0,
|
|
58
|
-
search: {
|
|
59
|
-
files: [
|
|
60
|
-
{
|
|
61
|
-
filePath: join(process.cwd(), "confirmed match"),
|
|
62
|
-
rows: [],
|
|
63
|
-
snapshot: { revision: "", validUtf8: true },
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
matchLimitReached: false,
|
|
67
|
-
scanLimitReached: false,
|
|
68
|
-
},
|
|
69
|
-
warnings: [{ reason: diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes) }],
|
|
70
|
-
outputMode: "files",
|
|
71
|
-
effectiveLimit: 100,
|
|
72
|
-
literalPipe: false,
|
|
73
|
-
});
|
|
74
|
-
assert.equal(payload, "confirmed match");
|
|
75
|
-
assert.match(facts.diagnostics ?? "", /regex parse error:/);
|
|
76
|
-
assert.match(facts.diagnostics ?? "", /error: unclosed group/);
|
|
77
|
-
assert.match(facts.diagnostics ?? "", /omitted/i);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("stderr overflow → UTF-8 opening and final cause survive", async (t) => {
|
|
81
|
-
const spawn = childProcess.spawn;
|
|
82
|
-
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) =>
|
|
83
|
-
spawn(process.execPath, args[1] ?? [], args[2]),
|
|
84
|
-
);
|
|
85
|
-
syncBuiltinESMExports();
|
|
86
|
-
t.after(() => {
|
|
87
|
-
t.mock.restoreAll();
|
|
88
|
-
syncBuiltinESMExports();
|
|
89
|
-
});
|
|
90
|
-
const directory = await mkdtemp(join(tmpdir(), "hl-rg-stderr-"));
|
|
91
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
92
|
-
const path = join(directory, "stderr.txt");
|
|
93
|
-
for (const source of ["权限不足🙂\n", diagnostic(MAX_RG_STDERR_BYTES)]) {
|
|
94
|
-
await writeFile(path, source);
|
|
95
|
-
const result = await runRgPaths(
|
|
96
|
-
[
|
|
97
|
-
"--input-type=module",
|
|
98
|
-
"--eval",
|
|
99
|
-
"import { createReadStream } from 'node:fs'; createReadStream(process.argv[1]).pipe(process.stderr)",
|
|
100
|
-
path,
|
|
101
|
-
],
|
|
102
|
-
AbortSignal.timeout(10000),
|
|
103
|
-
() => true,
|
|
104
|
-
);
|
|
105
|
-
if (Buffer.byteLength(source) <= MAX_RG_STDERR_BYTES) {
|
|
106
|
-
assert.equal(result.stderr, source);
|
|
107
|
-
} else {
|
|
108
|
-
assert.match(result.stderr, /^regex parse error:/);
|
|
109
|
-
assert.match(result.stderr, /error: unclosed group\n$/);
|
|
110
|
-
assert.match(result.stderr, /omitted/i);
|
|
111
|
-
assert.doesNotMatch(result.stderr, /�/);
|
|
112
|
-
assert.ok(Buffer.byteLength(result.stderr) <= MAX_RG_STDERR_BYTES);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import { syncBuiltinESMExports } from "node:module";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { commitFile, FileMutationError } from "./file-commit.ts";
|
|
8
|
-
|
|
9
|
-
test("macOS attempts directory sync, tolerates unsupported operations, and preserves published I/O failures", async (t) => {
|
|
10
|
-
const directory = await fs.mkdtemp(join(tmpdir(), "hashline-directory-sync-"));
|
|
11
|
-
const nativeOpen = fs.open;
|
|
12
|
-
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
|
|
13
|
-
let syncs = 0;
|
|
14
|
-
let closes = 0;
|
|
15
|
-
let failure: string | undefined;
|
|
16
|
-
try {
|
|
17
|
-
Object.defineProperty(process, "platform", { value: "darwin" });
|
|
18
|
-
t.mock.method(fs, "open", async (...args: Parameters<typeof fs.open>) => {
|
|
19
|
-
if (args[0] !== directory) return nativeOpen(...args);
|
|
20
|
-
return {
|
|
21
|
-
async sync() {
|
|
22
|
-
syncs++;
|
|
23
|
-
if (failure) throw Object.assign(new Error(failure), { code: failure });
|
|
24
|
-
},
|
|
25
|
-
async close() {
|
|
26
|
-
closes++;
|
|
27
|
-
},
|
|
28
|
-
} as Awaited<ReturnType<typeof fs.open>>;
|
|
29
|
-
});
|
|
30
|
-
syncBuiltinESMExports();
|
|
31
|
-
for (failure of [undefined, "EINVAL", "ENOTSUP", "EIO"]) {
|
|
32
|
-
const path = join(directory, failure ?? "success");
|
|
33
|
-
const commit = commitFile(path, "published\n", { mode: "create" });
|
|
34
|
-
if (failure === "EIO") {
|
|
35
|
-
await assert.rejects(
|
|
36
|
-
commit,
|
|
37
|
-
(error: unknown) =>
|
|
38
|
-
error instanceof FileMutationError &&
|
|
39
|
-
error.publication === "PUBLISHED" &&
|
|
40
|
-
error.cause instanceof Error &&
|
|
41
|
-
"code" in error.cause &&
|
|
42
|
-
error.cause.code === "EIO",
|
|
43
|
-
);
|
|
44
|
-
} else {
|
|
45
|
-
assert.equal((await commit).publication, "PUBLISHED");
|
|
46
|
-
}
|
|
47
|
-
assert.equal(await fs.readFile(path, "utf8"), "published\n");
|
|
48
|
-
}
|
|
49
|
-
assert.equal(syncs, 4);
|
|
50
|
-
assert.equal(closes, 4);
|
|
51
|
-
} finally {
|
|
52
|
-
Object.defineProperty(process, "platform", platform);
|
|
53
|
-
t.mock.restoreAll();
|
|
54
|
-
syncBuiltinESMExports();
|
|
55
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
56
|
-
}
|
|
57
|
-
});
|