@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
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { isUtf8 } from "node:buffer";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import { mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
5
|
-
import { syncBuiltinESMExports } from "node:module";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { test } from "node:test";
|
|
9
|
-
import { DEFAULT_CONFIG } from "../pi/tool-factories.testing.ts";
|
|
10
|
-
import { makeGrepOverride } from "../pi/tool-factories.testing.ts";
|
|
11
|
-
import { makeReadOverride } from "../pi/tool-factories.testing.ts";
|
|
12
|
-
import { callTool } from "../pi/tool-call.testing.ts";
|
|
13
|
-
import { withFileRead } from "../pi/file-read.ts";
|
|
14
|
-
import { expectToolFailure } from "../pi/report-failure.testing.ts";
|
|
15
|
-
|
|
16
|
-
const CHUNK_BYTES = 64 * 1024;
|
|
17
|
-
|
|
18
|
-
test("read or grep scan truncated across a UTF-8 sequence → reports file change without encoding blame", async (t) => {
|
|
19
|
-
const directory = await mkdtemp(join(tmpdir(), "hashline-read-change-"));
|
|
20
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
21
|
-
const path = join(directory, "race.txt");
|
|
22
|
-
const source = Buffer.from(
|
|
23
|
-
"head\r\n" +
|
|
24
|
-
"x".repeat(CHUNK_BYTES - 7) +
|
|
25
|
-
"中" +
|
|
26
|
-
"x".repeat(CHUNK_BYTES - 3) +
|
|
27
|
-
"中" +
|
|
28
|
-
"tail".repeat(CHUNK_BYTES),
|
|
29
|
-
);
|
|
30
|
-
assert.equal(isUtf8(source), true);
|
|
31
|
-
const tools = [
|
|
32
|
-
makeReadOverride(directory, DEFAULT_CONFIG),
|
|
33
|
-
makeGrepOverride(directory, DEFAULT_CONFIG),
|
|
34
|
-
];
|
|
35
|
-
for (const tool of tools) {
|
|
36
|
-
await t.test(tool.name, async () => {
|
|
37
|
-
await writeFile(path, source);
|
|
38
|
-
const original = fs.createReadStream;
|
|
39
|
-
let scans = 0;
|
|
40
|
-
fs.createReadStream = (...args: Parameters<typeof original>) => {
|
|
41
|
-
const stream = original(...args);
|
|
42
|
-
if (args[0] === path && ++scans === (tool.name === "read" ? 1 : 2)) {
|
|
43
|
-
stream.once("data", () => fs.truncateSync(path, CHUNK_BYTES - 1));
|
|
44
|
-
}
|
|
45
|
-
return stream;
|
|
46
|
-
};
|
|
47
|
-
syncBuiltinESMExports();
|
|
48
|
-
try {
|
|
49
|
-
const args =
|
|
50
|
-
tool.name === "read" ? { path, limit: 1 } : { path, pattern: "head", literal: true };
|
|
51
|
-
await expectToolFailure(
|
|
52
|
-
callTool(tool, args),
|
|
53
|
-
tool.name === "read" ? "FILE_CHANGED" : "SEARCH_INCOMPLETE",
|
|
54
|
-
(report) => {
|
|
55
|
-
if (tool.name === "grep") {
|
|
56
|
-
assert.match(report.diagnostics ?? "", /race\.txt/);
|
|
57
|
-
assert.match(report.diagnostics ?? "", /File changed during read\./);
|
|
58
|
-
} else assert.match(JSON.stringify(report), /File changed/);
|
|
59
|
-
assert.doesNotMatch(JSON.stringify(report), /UNSUPPORTED_ENCODING|Invalid UTF-8/);
|
|
60
|
-
},
|
|
61
|
-
);
|
|
62
|
-
const current = await readFile(path);
|
|
63
|
-
assert.equal(isUtf8(current), true);
|
|
64
|
-
assert.deepEqual(current, source.subarray(0, CHUNK_BYTES - 1));
|
|
65
|
-
} finally {
|
|
66
|
-
fs.createReadStream = original;
|
|
67
|
-
syncBuiltinESMExports();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
for (const operation of ["delete", "replace", "atomic replace"] as const) {
|
|
74
|
-
test(`path ${operation} during a read → rejects the opened file's obsolete observation`, {
|
|
75
|
-
skip:
|
|
76
|
-
operation === "atomic replace" && process.platform === "win32"
|
|
77
|
-
? "Windows rename rejects a concurrently open target"
|
|
78
|
-
: false,
|
|
79
|
-
}, async (t) => {
|
|
80
|
-
const directory = await mkdtemp(join(tmpdir(), "hashline-read-path-"));
|
|
81
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
82
|
-
const path = join(directory, "source.txt");
|
|
83
|
-
const replacement = join(directory, "replacement.txt");
|
|
84
|
-
await writeFile(path, "中文\n");
|
|
85
|
-
await writeFile(replacement, "汉字\n");
|
|
86
|
-
await assert.rejects(
|
|
87
|
-
withFileRead(path, undefined, async (handle) => {
|
|
88
|
-
const bytes = await handle.readFile();
|
|
89
|
-
if (operation !== "atomic replace") await rm(path);
|
|
90
|
-
if (operation !== "delete") await rename(replacement, path);
|
|
91
|
-
return bytes;
|
|
92
|
-
}),
|
|
93
|
-
/File changed/,
|
|
94
|
-
);
|
|
95
|
-
if (operation === "delete") await assert.rejects(readFile(path), { code: "ENOENT" });
|
|
96
|
-
else assert.equal(await readFile(path, "utf8"), "汉字\n");
|
|
97
|
-
});
|
|
98
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
-
import { test } from "node:test";
|
|
3
|
-
import { installedExtension } from "../testing/installation.testing.ts";
|
|
4
|
-
import { runTestProcess } from "../testing/process.testing.ts";
|
|
5
|
-
|
|
6
|
-
// Workers have their own loader; an installed worker must resolve only production dependencies.
|
|
7
|
-
test("regex workers start from installed source and npm archive paths", async (t) => {
|
|
8
|
-
for (const source of ["source", "packed"] as const) {
|
|
9
|
-
await t.test(source, async (t) => {
|
|
10
|
-
const installation = await installedExtension(t, source);
|
|
11
|
-
await runTestProcess(
|
|
12
|
-
process.execPath,
|
|
13
|
-
[
|
|
14
|
-
fileURLToPath(new URL("./replace-package.testing.ts", import.meta.url)),
|
|
15
|
-
installation.packageDir,
|
|
16
|
-
],
|
|
17
|
-
installation.root,
|
|
18
|
-
installation.agentDir,
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { Worker } from "node:worker_threads";
|
|
4
|
-
|
|
5
|
-
for (const { entry, input, expected } of [
|
|
6
|
-
{
|
|
7
|
-
entry: "replace-worker.mjs",
|
|
8
|
-
input: {
|
|
9
|
-
source: "before\n",
|
|
10
|
-
rules: [{ find: "(before)", replace: "$1 after", literal: false }],
|
|
11
|
-
},
|
|
12
|
-
expected: { text: "before after\n", count: 1 },
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
entry: "grep-worker.mjs",
|
|
16
|
-
input: {
|
|
17
|
-
source: "😀\r\na\n",
|
|
18
|
-
query: { patterns: ["^..$"], literal: false, multiline: false, ignoreCase: false },
|
|
19
|
-
limit: 10,
|
|
20
|
-
},
|
|
21
|
-
expected: { lines: [{ lineNumber: 1, column: 0 }] },
|
|
22
|
-
},
|
|
23
|
-
]) {
|
|
24
|
-
const worker = new Worker(join(process.argv[2], "src", "pi", entry));
|
|
25
|
-
try {
|
|
26
|
-
const result = await new Promise<unknown>((resolve, reject) => {
|
|
27
|
-
worker.once("message", resolve);
|
|
28
|
-
worker.once("error", reject);
|
|
29
|
-
worker.once("exit", (code) => reject(new Error(`Worker exited before responding: ${code}`)));
|
|
30
|
-
worker.postMessage(input);
|
|
31
|
-
});
|
|
32
|
-
assert.deepEqual(result, { result: expected });
|
|
33
|
-
} finally {
|
|
34
|
-
await worker.terminate();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { Worker } from "node:worker_threads";
|
|
3
|
-
import { test } from "node:test";
|
|
4
|
-
import { HashlineError } from "../core/errors.ts";
|
|
5
|
-
import { runRegexReplacements } from "../pi/replace-regex.ts";
|
|
6
|
-
import { DEFAULT_OUTPUT_BUDGETS } from "../pi/tool-factories.testing.ts";
|
|
7
|
-
import { causeOf } from "../pi/report-cause.ts";
|
|
8
|
-
import type { Cause } from "../pi/report-schema.ts";
|
|
9
|
-
|
|
10
|
-
const timeoutMs = 10_000;
|
|
11
|
-
const validRules = [{ find: "safe", replace: "changed", literal: false }];
|
|
12
|
-
|
|
13
|
-
test("worker boundary: malformed external reply → rejects its result and facts", async (t) => {
|
|
14
|
-
for (const reply of [
|
|
15
|
-
{ result: { text: 123, count: 1 } },
|
|
16
|
-
{ result: { text: "changed", count: 0 } },
|
|
17
|
-
{
|
|
18
|
-
result: { text: "changed", count: 1 },
|
|
19
|
-
error: { code: "NO_MATCH", message: "failure", facts: { unmatched: ["replacements[0]"] } },
|
|
20
|
-
},
|
|
21
|
-
{ error: { code: "NO_MATCH", message: "failure" } },
|
|
22
|
-
{ error: { code: "foreign", message: "failure" } },
|
|
23
|
-
{
|
|
24
|
-
error: {
|
|
25
|
-
code: "NO_MATCH",
|
|
26
|
-
message: "failure",
|
|
27
|
-
facts: { unmatched: ["replacements[0]"], foreign: true },
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
]) {
|
|
31
|
-
await t.test(JSON.stringify(reply), { timeout: timeoutMs }, async (t) => {
|
|
32
|
-
const emit = Worker.prototype.emit;
|
|
33
|
-
t.mock.method(
|
|
34
|
-
Worker.prototype,
|
|
35
|
-
"emit",
|
|
36
|
-
function (this: Worker, event: string | symbol, ...args: unknown[]) {
|
|
37
|
-
return emit.call(this, event, ...(event === "message" ? [reply] : args));
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
await assert.rejects(
|
|
41
|
-
runRegexReplacements("safe", validRules, timeoutMs, undefined),
|
|
42
|
-
(error: unknown) =>
|
|
43
|
-
error instanceof HashlineError &&
|
|
44
|
-
error.errorCode === "REGEX_WORKER_FAILED" &&
|
|
45
|
-
/invalid result/i.test(error.message),
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("worker boundary: deep structured cause reply → preserves the complete cause chain", {
|
|
52
|
-
timeout: timeoutMs,
|
|
53
|
-
}, async (t) => {
|
|
54
|
-
let nested: Cause = { code: "EACCES", message: "permission denied" };
|
|
55
|
-
for (let index = 0; index < 12; index++)
|
|
56
|
-
nested = { code: "EIO", message: `layer ${index}`, cause: nested };
|
|
57
|
-
const cause: Cause = {
|
|
58
|
-
message: "worker failure",
|
|
59
|
-
cause: nested,
|
|
60
|
-
};
|
|
61
|
-
const emit = Worker.prototype.emit;
|
|
62
|
-
t.mock.method(
|
|
63
|
-
Worker.prototype,
|
|
64
|
-
"emit",
|
|
65
|
-
function (this: Worker, event: string | symbol, ...args: unknown[]) {
|
|
66
|
-
return emit.call(
|
|
67
|
-
this,
|
|
68
|
-
event,
|
|
69
|
-
...(event === "message"
|
|
70
|
-
? [{ error: { code: "REGEX_WORKER_FAILED", message: "Regex evaluation failed.", cause } }]
|
|
71
|
-
: args),
|
|
72
|
-
);
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
await assert.rejects(
|
|
76
|
-
runRegexReplacements("safe", validRules, timeoutMs, undefined),
|
|
77
|
-
(error: unknown) => {
|
|
78
|
-
assert.ok(error instanceof HashlineError);
|
|
79
|
-
assert.equal(error.errorCode, "REGEX_WORKER_FAILED");
|
|
80
|
-
assert.deepEqual(causeOf(error.cause, DEFAULT_OUTPUT_BUDGETS.fieldBytes), cause);
|
|
81
|
-
return true;
|
|
82
|
-
},
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("worker boundary: cyclic structured cause → rejects a reply accepted with an acyclic cause", {
|
|
87
|
-
timeout: timeoutMs,
|
|
88
|
-
}, async (t) => {
|
|
89
|
-
for (const cyclic of [false, true]) {
|
|
90
|
-
await t.test(`cyclic=${cyclic}`, async (t) => {
|
|
91
|
-
const cause: Cause = { code: "EIO", message: "worker failure" };
|
|
92
|
-
if (cyclic) cause.cause = cause;
|
|
93
|
-
const reply = {
|
|
94
|
-
error: {
|
|
95
|
-
code: "NO_MATCH",
|
|
96
|
-
message: "no match",
|
|
97
|
-
facts: { unmatched: ["replacements[0]"] },
|
|
98
|
-
cause,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
const emit = Worker.prototype.emit;
|
|
102
|
-
t.mock.method(
|
|
103
|
-
Worker.prototype,
|
|
104
|
-
"emit",
|
|
105
|
-
function (this: Worker, event: string | symbol, ...args: unknown[]) {
|
|
106
|
-
return emit.call(this, event, ...(event === "message" ? [reply] : args));
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
await assert.rejects(
|
|
110
|
-
runRegexReplacements("safe", validRules, timeoutMs, undefined),
|
|
111
|
-
(error: unknown) => {
|
|
112
|
-
assert.ok(error instanceof HashlineError);
|
|
113
|
-
if (cyclic) {
|
|
114
|
-
assert.equal(error.errorCode, "REGEX_WORKER_FAILED");
|
|
115
|
-
assert.ok(error.cause instanceof RangeError);
|
|
116
|
-
} else {
|
|
117
|
-
assert.equal(error.errorCode, "NO_MATCH");
|
|
118
|
-
assert.equal(error.message, reply.error.message);
|
|
119
|
-
assert.deepEqual(error.facts, reply.error.facts);
|
|
120
|
-
assert.deepEqual(causeOf(error.cause, DEFAULT_OUTPUT_BUDGETS.fieldBytes), cause);
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
123
|
-
},
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/** Preparation errors transported by Pi and replayed with a fresh tool registration. */
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { test } from "node:test";
|
|
6
|
-
import { stripVTControlCharacters } from "node:util";
|
|
7
|
-
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
9
|
-
import { DEFAULT_CONFIG, makeEditOverride } from "../pi/tool-factories.testing.ts";
|
|
10
|
-
import { reportOf } from "../pi/report.ts";
|
|
11
|
-
import { openTestSession, responseStream } from "../testing/session.testing.ts";
|
|
12
|
-
|
|
13
|
-
const args = { path: "target.txt", steps: [{ action: "append", lines: [] }] };
|
|
14
|
-
|
|
15
|
-
test("live preparation failure → replays diagnostic after fresh registration", async (t) => {
|
|
16
|
-
initTheme("dark");
|
|
17
|
-
const first = await openTestSession(t, {
|
|
18
|
-
tools: ["edit"],
|
|
19
|
-
configure(pi, cwd) {
|
|
20
|
-
pi.registerTool(makeEditOverride(cwd, DEFAULT_CONFIG));
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
await writeFile(join(first.cwd, args.path), "unchanged\n");
|
|
24
|
-
let requests = 0;
|
|
25
|
-
first.session.agent.streamFunction = (_model, context) => {
|
|
26
|
-
if (requests++ === 0) {
|
|
27
|
-
return responseStream(first.model, {
|
|
28
|
-
content: [{ type: "toolCall", id: "invalid-edit", name: "edit", arguments: args }],
|
|
29
|
-
stopReason: "toolUse",
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const result = context.messages.find(
|
|
33
|
-
(message) => message.role === "toolResult" && message.toolCallId === "invalid-edit",
|
|
34
|
-
);
|
|
35
|
-
assert.ok(result?.role === "toolResult");
|
|
36
|
-
assert.equal(result.isError, true);
|
|
37
|
-
assert.equal(reportOf(result, "edit")?.error, "INVALID_ARGUMENTS");
|
|
38
|
-
return responseStream(first.model, {
|
|
39
|
-
content: [{ type: "text", text: "Done." }],
|
|
40
|
-
stopReason: "stop",
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
await first.session.prompt("Exercise a rejected edit in an isolated fixture.");
|
|
44
|
-
assert.equal(first.session.agent.state.errorMessage, undefined);
|
|
45
|
-
assert.equal(requests, 2);
|
|
46
|
-
assert.equal(await readFile(join(first.cwd, args.path), "utf8"), "unchanged\n");
|
|
47
|
-
const live = first.session.agent.state.messages.find(
|
|
48
|
-
(message) => message.role === "toolResult" && message.toolCallId === "invalid-edit",
|
|
49
|
-
);
|
|
50
|
-
assert.ok(live?.role === "toolResult");
|
|
51
|
-
const replay = { content: structuredClone(live.content), details: undefined };
|
|
52
|
-
const serialized = JSON.stringify(replay);
|
|
53
|
-
const report = reportOf(replay, "edit");
|
|
54
|
-
assert.equal(report?.issues?.[0].field, "steps[0].lines");
|
|
55
|
-
assert.equal(report?.issues?.[0].reason, "is empty");
|
|
56
|
-
|
|
57
|
-
const second = await openTestSession(t, {
|
|
58
|
-
tools: ["edit"],
|
|
59
|
-
configure(pi, cwd) {
|
|
60
|
-
pi.registerTool(makeEditOverride(cwd, DEFAULT_CONFIG));
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
const tool = second.session.getToolDefinition("edit");
|
|
64
|
-
assert.ok(tool?.renderResult);
|
|
65
|
-
for (const expanded of [false, true]) {
|
|
66
|
-
const decoded = JSON.parse(serialized);
|
|
67
|
-
const component = tool.renderResult(decoded, { expanded, isPartial: false }, theme, {
|
|
68
|
-
args,
|
|
69
|
-
toolCallId: "invalid-edit",
|
|
70
|
-
cwd: second.cwd,
|
|
71
|
-
state: {},
|
|
72
|
-
invalidate() {},
|
|
73
|
-
lastComponent: undefined,
|
|
74
|
-
executionStarted: true,
|
|
75
|
-
durationMs: undefined,
|
|
76
|
-
outputPad: 1,
|
|
77
|
-
keyText: () => "",
|
|
78
|
-
keyHint: (_key, description) => description,
|
|
79
|
-
argsComplete: true,
|
|
80
|
-
expanded,
|
|
81
|
-
isPartial: false,
|
|
82
|
-
showImages: false,
|
|
83
|
-
isError: true,
|
|
84
|
-
});
|
|
85
|
-
const shown = stripVTControlCharacters(component.render(240).join("\n"));
|
|
86
|
-
assert.match(shown, /steps\[0\]\.lines: is empty/);
|
|
87
|
-
assert.equal(shown.split("steps[0].lines: is empty").length - 1, 1);
|
|
88
|
-
assert.doesNotMatch(shown, /"issues":/);
|
|
89
|
-
assert.equal(JSON.stringify(decoded), serialized);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { constants, isUtf8 } from "node:buffer";
|
|
3
|
-
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { test } from "node:test";
|
|
7
|
-
import { DEFAULT_CONFIG } from "../pi/tool-factories.testing.ts";
|
|
8
|
-
import { makeEditOverride } from "../pi/tool-factories.testing.ts";
|
|
9
|
-
import { makeReplaceTool } from "../pi/tool-factories.testing.ts";
|
|
10
|
-
import { byteRevision } from "../pi/file-revision.ts";
|
|
11
|
-
import { callTool } from "../pi/tool-call.testing.ts";
|
|
12
|
-
import { expectToolFailure } from "../pi/report-failure.testing.ts";
|
|
13
|
-
|
|
14
|
-
const SIZE_TEST_TIMEOUT_MS = 60_000;
|
|
15
|
-
|
|
16
|
-
test("valid UTF-8 exceeding the runtime string limit → mutations retain the size failure without publishing", {
|
|
17
|
-
timeout: SIZE_TEST_TIMEOUT_MS,
|
|
18
|
-
}, async (t) => {
|
|
19
|
-
const directory = await mkdtemp(join(tmpdir(), "hashline-utf8-size-"));
|
|
20
|
-
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
21
|
-
const path = join(directory, "large.txt");
|
|
22
|
-
const source = Buffer.alloc(constants.MAX_STRING_LENGTH + Buffer.byteLength("中文"), 97);
|
|
23
|
-
source.write("中文", 0, "utf8");
|
|
24
|
-
assert.equal(isUtf8(source), true);
|
|
25
|
-
const originalRevision = byteRevision(source);
|
|
26
|
-
await writeFile(path, source);
|
|
27
|
-
const tools = [
|
|
28
|
-
makeEditOverride(directory, DEFAULT_CONFIG),
|
|
29
|
-
makeReplaceTool(directory, DEFAULT_CONFIG),
|
|
30
|
-
];
|
|
31
|
-
for (const tool of tools) {
|
|
32
|
-
await t.test(tool.name, async () => {
|
|
33
|
-
const args =
|
|
34
|
-
tool.name === "edit"
|
|
35
|
-
? { path, steps: [{ action: "append", lines: ["tail"] }] }
|
|
36
|
-
: { path, replacements: [{ literal: true, find: "中文", replace: "汉字" }] };
|
|
37
|
-
await expectToolFailure(callTool(tool, args), "FILESYSTEM_ERROR", (report) => {
|
|
38
|
-
assert.doesNotMatch(JSON.stringify(report), /UNSUPPORTED_ENCODING/);
|
|
39
|
-
assert.match(report.message ?? "", /ERR_STRING_TOO_LONG/);
|
|
40
|
-
assert.equal(report.cause, undefined);
|
|
41
|
-
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
42
|
-
});
|
|
43
|
-
assert.equal(byteRevision(await readFile(path)), originalRevision);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
});
|