@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/write.test.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { commandCompletion, type SessionCommand } from "./action-fusion.testing.ts";
|
|
2
|
-
import { rejectsArgument } from "./argument-error.testing.ts";
|
|
3
|
-
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { test } from "node:test";
|
|
8
|
-
import { makeWriteOverride } from "./tool-factories.testing.ts";
|
|
9
|
-
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
10
|
-
import { callTool } from "./tool-call.testing.ts";
|
|
11
|
-
import { reportOf } from "./report.ts";
|
|
12
|
-
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
13
|
-
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
14
|
-
initTheme("dark");
|
|
15
|
-
|
|
16
|
-
const context = (cwd: string) => ({ cwd }) as any;
|
|
17
|
-
|
|
18
|
-
async function withTemp<T>(run: (dir: string) => Promise<T>): Promise<T> {
|
|
19
|
-
const dir = await mkdtemp(join(tmpdir(), "hashline-write-"));
|
|
20
|
-
try {
|
|
21
|
-
return await run(dir);
|
|
22
|
-
} finally {
|
|
23
|
-
await rm(dir, { recursive: true, force: true });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
test("write receives an unknown field → rejects without changing the file", async () =>
|
|
28
|
-
withTemp(async (dir) => {
|
|
29
|
-
const file = join(dir, "file.txt");
|
|
30
|
-
await writeFile(file, "original\n");
|
|
31
|
-
for (const fusion of [undefined, createActionFusionExecutor(() => {})]) {
|
|
32
|
-
const tool = makeWriteOverride(dir, fusion);
|
|
33
|
-
const args = { path: "file.txt", content: "new\n", mode: "overwrite", unexpected: true };
|
|
34
|
-
await assert.rejects(
|
|
35
|
-
callTool(tool, args, { ctx: context(dir) }),
|
|
36
|
-
rejectsArgument("unexpected", /not allowed/),
|
|
37
|
-
);
|
|
38
|
-
assert.equal(await readFile(file, "utf8"), "original\n");
|
|
39
|
-
}
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
test("write rejects unwritable content before accessing a missing target", async () =>
|
|
43
|
-
withTemp(async (dir) => {
|
|
44
|
-
const file = join(dir, "missing.txt");
|
|
45
|
-
const tool = makeWriteOverride(dir);
|
|
46
|
-
for (const [content, expected] of [
|
|
47
|
-
["bad\0", rejectsArgument("content", /NUL/)],
|
|
48
|
-
["\ud800", rejectsArgument("content", /encoded losslessly/)],
|
|
49
|
-
] as const) {
|
|
50
|
-
await assert.rejects(
|
|
51
|
-
callTool(tool, { path: file, content, mode: "create" }, { ctx: context(dir) }),
|
|
52
|
-
expected,
|
|
53
|
-
);
|
|
54
|
-
await assert.rejects(readFile(file, "utf8"), { code: "ENOENT" });
|
|
55
|
-
}
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
test("write omits mode → rejects before changing files or running commands", async () =>
|
|
59
|
-
withTemp(async (dir) => {
|
|
60
|
-
const existing = join(dir, "existing.txt");
|
|
61
|
-
const missingParent = join(dir, "missing");
|
|
62
|
-
const missing = join(missingParent, "new.txt");
|
|
63
|
-
await writeFile(existing, "original\n");
|
|
64
|
-
let commandRuns = 0;
|
|
65
|
-
const executeTool: SessionCommand = async () => {
|
|
66
|
-
commandRuns++;
|
|
67
|
-
return commandCompletion({ content: [{ type: "text", text: "checked" }] });
|
|
68
|
-
};
|
|
69
|
-
const fusion = createActionFusionExecutor(() => {});
|
|
70
|
-
for (const executor of [undefined, fusion]) {
|
|
71
|
-
const tool = makeWriteOverride(dir, executor);
|
|
72
|
-
for (const path of [existing, missing]) {
|
|
73
|
-
await assert.rejects(
|
|
74
|
-
callTool(
|
|
75
|
-
tool,
|
|
76
|
-
{ path, content: "changed\n", ...(executor ? { then_run: { command: "check" } } : {}) },
|
|
77
|
-
{ ctx: { ...context(dir), executeTool } },
|
|
78
|
-
),
|
|
79
|
-
rejectsArgument("mode", /required/),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
assert.equal(await readFile(existing, "utf8"), "original\n");
|
|
84
|
-
await assert.rejects(readFile(missingParent), { code: "ENOENT" });
|
|
85
|
-
assert.equal(commandRuns, 0);
|
|
86
|
-
}));
|
|
87
|
-
|
|
88
|
-
test("write supports create-only and overwrite-only modes", async () =>
|
|
89
|
-
withTemp(async (dir) => {
|
|
90
|
-
const write = makeWriteOverride(dir);
|
|
91
|
-
const target = join(dir, "new.txt");
|
|
92
|
-
const options = { ctx: context(dir) };
|
|
93
|
-
const created = await callTool(
|
|
94
|
-
write,
|
|
95
|
-
{ path: "new.txt", content: "new\n", mode: "create" },
|
|
96
|
-
options,
|
|
97
|
-
);
|
|
98
|
-
assert.equal(created.content[0].type, "text");
|
|
99
|
-
assert.doesNotMatch(created.content[0].text, /Revision:|[0-9a-f]{64}/);
|
|
100
|
-
assert.deepEqual(await readFile(target), Buffer.from("new\n"));
|
|
101
|
-
assert.equal(reportOf(created, "write")?.publication, "PUBLISHED");
|
|
102
|
-
const exists = await callTool(
|
|
103
|
-
write,
|
|
104
|
-
{ path: "new.txt", content: "bad\n", mode: "create" },
|
|
105
|
-
options,
|
|
106
|
-
);
|
|
107
|
-
assert.equal(exists.isError, true);
|
|
108
|
-
const conflict = reportOf(exists, "write");
|
|
109
|
-
assert.equal(conflict?.error, "TARGET_EXISTS");
|
|
110
|
-
assert.equal(conflict?.publication, "NOT_PUBLISHED");
|
|
111
|
-
const next = conflict?.next ?? "";
|
|
112
|
-
assert.match(next, /check the path/i);
|
|
113
|
-
assert.match(next, /read the existing file/i);
|
|
114
|
-
assert.match(next, /overwrite.*only if.*intended/i);
|
|
115
|
-
assert.equal(await readFile(target, "utf8"), "new\n");
|
|
116
|
-
const missing = await callTool(
|
|
117
|
-
write,
|
|
118
|
-
{ path: "missing.txt", content: "bad\n", mode: "overwrite" },
|
|
119
|
-
options,
|
|
120
|
-
);
|
|
121
|
-
assert.equal(missing.isError, true);
|
|
122
|
-
assert.equal(reportOf(missing, "write")?.error, "PATH_NOT_FOUND");
|
|
123
|
-
await callTool(write, { path: "new.txt", content: "updated\n", mode: "overwrite" }, options);
|
|
124
|
-
assert.equal(await readFile(target, "utf8"), "updated\n");
|
|
125
|
-
}));
|
|
126
|
-
|
|
127
|
-
test("write returns only a summary for empty, short, and long content", async () =>
|
|
128
|
-
withTemp(async (dir) => {
|
|
129
|
-
const contents = [
|
|
130
|
-
"",
|
|
131
|
-
"before\n",
|
|
132
|
-
Array.from({ length: 500 }, (_, index) => `line ${index + 1}`).join("\n"),
|
|
133
|
-
];
|
|
134
|
-
for (const [index, content] of contents.entries()) {
|
|
135
|
-
const path = `file-${index}.txt`;
|
|
136
|
-
const result = await makeWriteOverride(dir).execute(
|
|
137
|
-
"write",
|
|
138
|
-
{ path, content, mode: "create" },
|
|
139
|
-
undefined,
|
|
140
|
-
undefined,
|
|
141
|
-
context(dir),
|
|
142
|
-
);
|
|
143
|
-
assert.equal(reportOf(result, "write")?.path, path);
|
|
144
|
-
assert.equal(reportOf(result, "write")?.publication, "PUBLISHED");
|
|
145
|
-
assert.equal(result.content.length, 1);
|
|
146
|
-
const block = result.content[0];
|
|
147
|
-
assert.equal(block.type, "text");
|
|
148
|
-
assert.deepEqual(JSON.parse(block.text), { publication: "PUBLISHED" });
|
|
149
|
-
assert.equal(await readFile(join(dir, path), "utf8"), content);
|
|
150
|
-
}
|
|
151
|
-
}));
|
|
152
|
-
|
|
153
|
-
test("write returns its summary and command output after an unchanged then_run", async () =>
|
|
154
|
-
withTemp(async (dir) => {
|
|
155
|
-
const executeTool: SessionCommand = async () =>
|
|
156
|
-
commandCompletion({ content: [{ type: "text", text: "checked" }] });
|
|
157
|
-
const fusion = createActionFusionExecutor(() => {});
|
|
158
|
-
const write = makeWriteOverride(dir, fusion) as any;
|
|
159
|
-
const result = await write.execute(
|
|
160
|
-
"unchanged",
|
|
161
|
-
{
|
|
162
|
-
path: "unchanged.txt",
|
|
163
|
-
content: "mutation\n",
|
|
164
|
-
mode: "create",
|
|
165
|
-
then_run: { command: "check" },
|
|
166
|
-
},
|
|
167
|
-
undefined,
|
|
168
|
-
undefined,
|
|
169
|
-
{ ...context(dir), executeTool },
|
|
170
|
-
);
|
|
171
|
-
assert.deepEqual(reportOf(result, "write")?.then_run, {
|
|
172
|
-
status: "succeeded",
|
|
173
|
-
output: "checked",
|
|
174
|
-
});
|
|
175
|
-
}));
|
|
176
|
-
|
|
177
|
-
test("write reports changed freshness when then_run changes the target", async () =>
|
|
178
|
-
withTemp(async (dir) => {
|
|
179
|
-
const target = join(dir, "changed.txt");
|
|
180
|
-
const executeTool: SessionCommand = async () => {
|
|
181
|
-
await writeFile(target, "command changed\n");
|
|
182
|
-
return commandCompletion({ content: [{ type: "text", text: "checked" }] });
|
|
183
|
-
};
|
|
184
|
-
const fusion = createActionFusionExecutor(() => {});
|
|
185
|
-
const write = makeWriteOverride(dir, fusion) as any;
|
|
186
|
-
const result = await callTool(
|
|
187
|
-
write,
|
|
188
|
-
{
|
|
189
|
-
path: "changed.txt",
|
|
190
|
-
content: "mutation\n",
|
|
191
|
-
mode: "create",
|
|
192
|
-
then_run: { command: "check" },
|
|
193
|
-
},
|
|
194
|
-
{ toolCallId: "changed", ctx: { ...context(dir), executeTool } },
|
|
195
|
-
);
|
|
196
|
-
const text = result.content.map((block: any) => block.text).join("\n");
|
|
197
|
-
assert.doesNotMatch(text, /revision:|[0-9a-f]{64}/i);
|
|
198
|
-
assert.equal(reportOf(result, "write")?.freshness, "changed");
|
|
199
|
-
assert.match(reportOf(result, "write")?.next ?? "", /Read the file before further edits/);
|
|
200
|
-
assert.deepEqual(reportOf(result, "write")?.then_run, {
|
|
201
|
-
status: "succeeded",
|
|
202
|
-
output: "checked",
|
|
203
|
-
});
|
|
204
|
-
assert.doesNotMatch(text, /\b1#[0-9A-Z]+\b/);
|
|
205
|
-
const rendered = write
|
|
206
|
-
.renderResult(result, { isPartial: false }, theme, { isError: false })
|
|
207
|
-
.render(100)
|
|
208
|
-
.join("\n");
|
|
209
|
-
assert.match(rendered, /changed/);
|
|
210
|
-
assert.match(rendered, /Read the file/);
|
|
211
|
-
assert.doesNotMatch(rendered, /Command|checked/);
|
|
212
|
-
}));
|
|
213
|
-
|
|
214
|
-
test("write reports missing freshness when then_run removes the target", async () =>
|
|
215
|
-
withTemp(async (dir) => {
|
|
216
|
-
const target = join(dir, "missing.txt");
|
|
217
|
-
const executeTool: SessionCommand = async () => {
|
|
218
|
-
await rm(target);
|
|
219
|
-
return commandCompletion({ content: [{ type: "text", text: "removed" }] });
|
|
220
|
-
};
|
|
221
|
-
const fusion = createActionFusionExecutor(() => {});
|
|
222
|
-
const result = await makeWriteOverride(dir, fusion).execute(
|
|
223
|
-
"missing",
|
|
224
|
-
{
|
|
225
|
-
path: "missing.txt",
|
|
226
|
-
content: "mutation\n",
|
|
227
|
-
mode: "create",
|
|
228
|
-
then_run: { command: "remove" },
|
|
229
|
-
},
|
|
230
|
-
undefined,
|
|
231
|
-
undefined,
|
|
232
|
-
{ ...context(dir), executeTool },
|
|
233
|
-
);
|
|
234
|
-
assert.equal(reportOf(result, "write")?.freshness, "missing");
|
|
235
|
-
assert.equal(reportOf(result, "write")?.next, undefined);
|
|
236
|
-
}));
|
|
237
|
-
|
|
238
|
-
test("write preserves command failure and changed freshness", async () =>
|
|
239
|
-
withTemp(async (dir) => {
|
|
240
|
-
const target = join(dir, "failed.txt");
|
|
241
|
-
const executeTool: SessionCommand = async () => {
|
|
242
|
-
await writeFile(target, "changed before failure\n");
|
|
243
|
-
return commandCompletion({ content: [{ type: "text", text: "command failed" }] }, true);
|
|
244
|
-
};
|
|
245
|
-
const fusion = createActionFusionExecutor(() => {});
|
|
246
|
-
const result = await makeWriteOverride(dir, fusion).execute(
|
|
247
|
-
"failed",
|
|
248
|
-
{ path: "failed.txt", content: "mutation\n", mode: "create", then_run: { command: "fail" } },
|
|
249
|
-
undefined,
|
|
250
|
-
undefined,
|
|
251
|
-
{ ...context(dir), executeTool },
|
|
252
|
-
);
|
|
253
|
-
assert.equal(reportOf(result, "write")?.freshness, "changed");
|
|
254
|
-
assert.equal(reportOf(result, "write")?.then_run?.status, "failed");
|
|
255
|
-
assert.match(reportOf(result, "write")?.next ?? "", /Read the file before further edits/);
|
|
256
|
-
}));
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** Use Pi's embedded-runtime module mapping against an isolated extension installation. */
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import type { ExtensionFactory } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { createJiti } from "../../node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/jiti-static-loader.js";
|
|
6
|
-
import { VIRTUAL_MODULES } from "../../node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/virtual-modules.js";
|
|
7
|
-
|
|
8
|
-
export async function loadInstalledExtension(entry: string): Promise<ExtensionFactory> {
|
|
9
|
-
const require = createRequire(entry);
|
|
10
|
-
assert.throws(() => require.resolve("@earendil-works/pi-coding-agent"), {
|
|
11
|
-
code: "MODULE_NOT_FOUND",
|
|
12
|
-
});
|
|
13
|
-
// typebox is a host-provided peer: the installed layout must NOT resolve its own
|
|
14
|
-
// copy; jiti's virtualModules supply it instead.
|
|
15
|
-
assert.throws(() => require.resolve("typebox/type"), { code: "MODULE_NOT_FOUND" });
|
|
16
|
-
const jiti = createJiti(import.meta.url, {
|
|
17
|
-
moduleCache: false,
|
|
18
|
-
virtualModules: VIRTUAL_MODULES,
|
|
19
|
-
tryNative: false,
|
|
20
|
-
});
|
|
21
|
-
const factory = await jiti.import<ExtensionFactory>(entry, { default: true });
|
|
22
|
-
assert.equal(typeof factory, "function");
|
|
23
|
-
return factory;
|
|
24
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/** Isolated installed-package layouts with only npm's locked production dependency tree. */
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { cp, mkdir, mkdtemp, readdir, rm, stat } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { dirname, join, relative } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import type { TestContext } from "node:test";
|
|
8
|
-
import manifest from "../../package.json" with { type: "json" };
|
|
9
|
-
import lock from "../../package-lock.json" with { type: "json" };
|
|
10
|
-
import { runTestProcess } from "./process.testing.ts";
|
|
11
|
-
|
|
12
|
-
const repository = fileURLToPath(new URL("../../", import.meta.url));
|
|
13
|
-
|
|
14
|
-
export async function installedExtension(t: TestContext, source: "source" | "packed" = "source") {
|
|
15
|
-
const root = await mkdtemp(join(tmpdir(), "hashline-install-"));
|
|
16
|
-
t.after(() => rm(root, { recursive: true, force: true }));
|
|
17
|
-
const packageDir = join(root, "node_modules", manifest.name);
|
|
18
|
-
const agentDir = join(root, "agent");
|
|
19
|
-
await mkdir(packageDir, { recursive: true });
|
|
20
|
-
await mkdir(agentDir);
|
|
21
|
-
for (const [path, metadata] of Object.entries(lock.packages)) {
|
|
22
|
-
if (
|
|
23
|
-
!path ||
|
|
24
|
-
("dev" in metadata && metadata.dev) ||
|
|
25
|
-
("devOptional" in metadata && metadata.devOptional)
|
|
26
|
-
)
|
|
27
|
-
continue;
|
|
28
|
-
const dependency = join(repository, path);
|
|
29
|
-
try {
|
|
30
|
-
await stat(dependency);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
if (
|
|
33
|
-
error instanceof Error &&
|
|
34
|
-
"code" in error &&
|
|
35
|
-
error.code === "ENOENT" &&
|
|
36
|
-
"optional" in metadata &&
|
|
37
|
-
metadata.optional
|
|
38
|
-
)
|
|
39
|
-
continue;
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
// Copy instead of linking: dependency resolution must not walk back into the checkout.
|
|
43
|
-
await cp(dependency, join(root, path), {
|
|
44
|
-
recursive: true,
|
|
45
|
-
dereference: true,
|
|
46
|
-
filter: (candidate) => candidate !== join(dependency, "node_modules"),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (source === "packed") {
|
|
50
|
-
const npmCli =
|
|
51
|
-
process.env.npm_execpath ??
|
|
52
|
-
join(
|
|
53
|
-
dirname(process.execPath),
|
|
54
|
-
process.platform === "win32"
|
|
55
|
-
? "node_modules/npm/bin/npm-cli.js"
|
|
56
|
-
: "../lib/node_modules/npm/bin/npm-cli.js",
|
|
57
|
-
);
|
|
58
|
-
await runTestProcess(
|
|
59
|
-
process.execPath,
|
|
60
|
-
[npmCli, "pack", "--ignore-scripts", "--pack-destination", root],
|
|
61
|
-
repository,
|
|
62
|
-
agentDir,
|
|
63
|
-
);
|
|
64
|
-
const archives = (await readdir(root)).filter((name) => name.endsWith(".tgz"));
|
|
65
|
-
assert.equal(archives.length, 1, "npm pack must produce one archive");
|
|
66
|
-
await runTestProcess(
|
|
67
|
-
"tar",
|
|
68
|
-
["-xzf", archives[0], "-C", relative(root, packageDir), "--strip-components=1"],
|
|
69
|
-
root,
|
|
70
|
-
agentDir,
|
|
71
|
-
);
|
|
72
|
-
} else {
|
|
73
|
-
await cp(join(repository, "src"), join(packageDir, "src"), { recursive: true });
|
|
74
|
-
await cp(join(repository, "package.json"), join(packageDir, "package.json"));
|
|
75
|
-
}
|
|
76
|
-
return { root, packageDir, agentDir, entry: join(packageDir, manifest.pi.extensions[0]) };
|
|
77
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/** Own the environment used by test runners and isolated package probes. */
|
|
2
|
-
import { execFile as execFileCallback } from "node:child_process";
|
|
3
|
-
import { promisify } from "node:util";
|
|
4
|
-
|
|
5
|
-
const execFile = promisify(execFileCallback);
|
|
6
|
-
const PROCESS_TIMEOUT_MS = 60_000;
|
|
7
|
-
|
|
8
|
-
export function testEnvironment(agentDir: string): NodeJS.ProcessEnv {
|
|
9
|
-
const env = Object.fromEntries(
|
|
10
|
-
Object.entries(process.env).filter(([key]) => {
|
|
11
|
-
const name = key.toUpperCase();
|
|
12
|
-
return (
|
|
13
|
-
!["NODE_OPTIONS", "NODE_PATH", "PI_CODING_AGENT_DIR"].includes(name) &&
|
|
14
|
-
!name.startsWith("JITI_")
|
|
15
|
-
);
|
|
16
|
-
}),
|
|
17
|
-
);
|
|
18
|
-
return { ...env, PI_CODING_AGENT_DIR: agentDir };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Start a bounded child without shell interpretation or inherited Node loaders. */
|
|
22
|
-
export async function runTestProcess(
|
|
23
|
-
command: string,
|
|
24
|
-
args: readonly string[],
|
|
25
|
-
cwd: string,
|
|
26
|
-
agentDir: string,
|
|
27
|
-
) {
|
|
28
|
-
return execFile(command, args, {
|
|
29
|
-
cwd,
|
|
30
|
-
env: testEnvironment(agentDir),
|
|
31
|
-
timeout: PROCESS_TIMEOUT_MS,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host V8 regex support. Pi supports Node 22.19.0, whose V8 rejects modifier groups
|
|
3
|
-
* (`(?i:…)`) and duplicate named groups; grep validates patterns with the host engine, so
|
|
4
|
-
* cases that need this syntax run only where the host compiles them.
|
|
5
|
-
*/
|
|
6
|
-
export function hostCompiles(pattern: string, flags = ""): boolean {
|
|
7
|
-
try {
|
|
8
|
-
new RegExp(pattern, flags);
|
|
9
|
-
return true;
|
|
10
|
-
} catch {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Skip reason for `test`/`t.test` options when the host cannot compile every pattern. */
|
|
16
|
-
export function unsupportedByHost(patterns: readonly string[], flags = ""): string | false {
|
|
17
|
-
return patterns.every((pattern) => hostCompiles(pattern, flags))
|
|
18
|
-
? false
|
|
19
|
-
: `host V8 ${process.version} cannot compile this regex syntax`;
|
|
20
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// Selected Test262 witnesses retain their upstream copyright and BSD license in THIRD_PARTY_NOTICES.md.
|
|
2
|
-
// Copyright 2022 Igalia S.L. All rights reserved.
|
|
3
|
-
// Copyright (C) 2017 the V8 project authors. All rights reserved.
|
|
4
|
-
// Copyright 2025 Mathias Bynens. All rights reserved.
|
|
5
|
-
|
|
6
|
-
export interface RegexWitness {
|
|
7
|
-
readonly pattern: string;
|
|
8
|
-
readonly ignoreCase: boolean;
|
|
9
|
-
readonly hits: readonly string[];
|
|
10
|
-
readonly misses: readonly string[];
|
|
11
|
-
readonly rejectCandidates: boolean;
|
|
12
|
-
readonly source: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const test262 = "https://github.com/tc39/test262/blob/main/test/built-ins/RegExp/";
|
|
16
|
-
const local = "JS-to-rg translation contract";
|
|
17
|
-
|
|
18
|
-
export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
19
|
-
{
|
|
20
|
-
pattern: "(?:([])\\1|b)",
|
|
21
|
-
ignoreCase: false,
|
|
22
|
-
hits: ["b"],
|
|
23
|
-
misses: ["a"],
|
|
24
|
-
rejectCandidates: true,
|
|
25
|
-
source: local,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
pattern: "(?!a)[a-z]",
|
|
29
|
-
ignoreCase: false,
|
|
30
|
-
hits: ["b", "z"],
|
|
31
|
-
misses: ["a", "A"],
|
|
32
|
-
rejectCandidates: false,
|
|
33
|
-
source: local,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
pattern: "(?=ab)a[bcd]",
|
|
37
|
-
ignoreCase: false,
|
|
38
|
-
hits: ["ab"],
|
|
39
|
-
misses: ["ac", "ad"],
|
|
40
|
-
rejectCandidates: false,
|
|
41
|
-
source: local,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
pattern: "[a-z](?<=b)",
|
|
45
|
-
ignoreCase: false,
|
|
46
|
-
hits: ["b"],
|
|
47
|
-
misses: ["a", "c"],
|
|
48
|
-
rejectCandidates: false,
|
|
49
|
-
source: local,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
pattern: "(?!ab)[a-z]{2}",
|
|
53
|
-
ignoreCase: false,
|
|
54
|
-
hits: ["ac", "ba"],
|
|
55
|
-
misses: ["ab"],
|
|
56
|
-
rejectCandidates: false,
|
|
57
|
-
source: local,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
pattern: "[a-z]{2}(?<!ab)",
|
|
61
|
-
ignoreCase: false,
|
|
62
|
-
hits: ["ac", "ba"],
|
|
63
|
-
misses: ["ab"],
|
|
64
|
-
rejectCandidates: false,
|
|
65
|
-
source: local,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
pattern: "(?i:(?!k)[a-z])",
|
|
69
|
-
ignoreCase: false,
|
|
70
|
-
hits: ["a"],
|
|
71
|
-
misses: ["k", "K", "K", "ſ"],
|
|
72
|
-
rejectCandidates: false,
|
|
73
|
-
source: local,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
pattern: "a\\b[ a]",
|
|
77
|
-
ignoreCase: false,
|
|
78
|
-
hits: ["a "],
|
|
79
|
-
misses: ["aa"],
|
|
80
|
-
rejectCandidates: true,
|
|
81
|
-
source: local,
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
pattern: "k\\b[\\w ]",
|
|
85
|
-
ignoreCase: true,
|
|
86
|
-
hits: ["k "],
|
|
87
|
-
misses: ["kk", "Kk", "K "],
|
|
88
|
-
rejectCandidates: false,
|
|
89
|
-
source: local,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
pattern: "(?m:[\\ra]^b)",
|
|
93
|
-
ignoreCase: false,
|
|
94
|
-
hits: ["\rb"],
|
|
95
|
-
misses: ["ab"],
|
|
96
|
-
rejectCandidates: false,
|
|
97
|
-
source: local,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
pattern: "(?-m:a^b)",
|
|
101
|
-
ignoreCase: false,
|
|
102
|
-
hits: [],
|
|
103
|
-
misses: ["ab", "a^b"],
|
|
104
|
-
rejectCandidates: true,
|
|
105
|
-
source: local,
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
pattern: "(?=needle)",
|
|
109
|
-
ignoreCase: false,
|
|
110
|
-
hits: ["needle"],
|
|
111
|
-
misses: ["haystack"],
|
|
112
|
-
rejectCandidates: true,
|
|
113
|
-
source: local,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
pattern: "(?<=needle)",
|
|
117
|
-
ignoreCase: false,
|
|
118
|
-
hits: ["needle"],
|
|
119
|
-
misses: ["haystack"],
|
|
120
|
-
rejectCandidates: true,
|
|
121
|
-
source: local,
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
pattern: "(?<=(a)\\1)",
|
|
125
|
-
ignoreCase: false,
|
|
126
|
-
hits: ["a", "ab"],
|
|
127
|
-
misses: ["b"],
|
|
128
|
-
rejectCandidates: true,
|
|
129
|
-
source: local,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
pattern: "(?<=\\1(a))",
|
|
133
|
-
ignoreCase: false,
|
|
134
|
-
hits: ["aa"],
|
|
135
|
-
misses: ["a", "ab"],
|
|
136
|
-
rejectCandidates: true,
|
|
137
|
-
source: local,
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
pattern: "(cat|dog)\\1",
|
|
141
|
-
ignoreCase: false,
|
|
142
|
-
hits: ["catcat", "dogdog"],
|
|
143
|
-
misses: ["catdog", "dogcat"],
|
|
144
|
-
rejectCandidates: false,
|
|
145
|
-
source: local,
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
pattern: "(a|bc)\\1",
|
|
149
|
-
ignoreCase: false,
|
|
150
|
-
hits: ["aa", "bcbc"],
|
|
151
|
-
misses: ["abc", "bca"],
|
|
152
|
-
rejectCandidates: false,
|
|
153
|
-
source: local,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
pattern: "(a{1,2})b\\1",
|
|
157
|
-
ignoreCase: false,
|
|
158
|
-
hits: ["aba", "aabaa"],
|
|
159
|
-
misses: ["abb"],
|
|
160
|
-
rejectCandidates: true,
|
|
161
|
-
source: local,
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
pattern: "(a(?=b))b\\1",
|
|
165
|
-
ignoreCase: false,
|
|
166
|
-
hits: ["aba"],
|
|
167
|
-
misses: ["abb"],
|
|
168
|
-
rejectCandidates: false,
|
|
169
|
-
source: local,
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
pattern: "^(é|Σ|𐐀)$",
|
|
173
|
-
ignoreCase: true,
|
|
174
|
-
hits: ["É", "é", "ς", "σ", "Σ"],
|
|
175
|
-
misses: ["e", "s", "a", "𐐨"],
|
|
176
|
-
rejectCandidates: true,
|
|
177
|
-
source: local,
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
pattern: "(?:(?<x>a)|(?<x>b))\\k<x>",
|
|
181
|
-
ignoreCase: false,
|
|
182
|
-
hits: ["aa", "bb"],
|
|
183
|
-
misses: ["abab", "cdef"],
|
|
184
|
-
rejectCandidates: false,
|
|
185
|
-
source: `${test262}named-groups/duplicate-names-exec.js`,
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
pattern: "(?:(?:(?<x>a)|(?<x>b))\\k<x>){2}",
|
|
189
|
-
ignoreCase: false,
|
|
190
|
-
hits: ["aabb"],
|
|
191
|
-
misses: ["abab"],
|
|
192
|
-
rejectCandidates: false,
|
|
193
|
-
source: `${test262}named-groups/duplicate-names-exec.js`,
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
pattern: "^(?:(?<a>x)|(?<a>y)|z)\\k<a>$",
|
|
197
|
-
ignoreCase: false,
|
|
198
|
-
hits: ["xx", "z"],
|
|
199
|
-
misses: ["zz"],
|
|
200
|
-
rejectCandidates: false,
|
|
201
|
-
source: `${test262}named-groups/duplicate-names-exec.js`,
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
pattern: "^(?:(?<a>x)|(?<a>y)|z){2}\\k<a>$",
|
|
205
|
-
ignoreCase: false,
|
|
206
|
-
hits: ["xz", "yz"],
|
|
207
|
-
misses: ["xzx", "yzy"],
|
|
208
|
-
rejectCandidates: false,
|
|
209
|
-
source: `${test262}named-groups/duplicate-names-exec.js`,
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
pattern: "(.)(?<=(\\1\\1))",
|
|
213
|
-
ignoreCase: true,
|
|
214
|
-
hits: ["abB"],
|
|
215
|
-
misses: ["ab"],
|
|
216
|
-
rejectCandidates: false,
|
|
217
|
-
source: `${test262}lookBehind/back-references.js`,
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
pattern: "(..)(?<=\\1\\1\\1)",
|
|
221
|
-
ignoreCase: false,
|
|
222
|
-
hits: ["fababab"],
|
|
223
|
-
misses: ["fabxbab", "faxabab"],
|
|
224
|
-
rejectCandidates: false,
|
|
225
|
-
source: `${test262}lookBehind/back-references.js`,
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
pattern: "(?<=(.))(\\w+)(?=\\1)",
|
|
229
|
-
ignoreCase: false,
|
|
230
|
-
hits: [" 'foo' ", ' "foo" '],
|
|
231
|
-
misses: [' .foo" '],
|
|
232
|
-
rejectCandidates: false,
|
|
233
|
-
source: `${test262}lookBehind/back-references.js`,
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
pattern: "(?<=ab(?=c)\\wd)\\w\\w",
|
|
237
|
-
ignoreCase: false,
|
|
238
|
-
hits: ["abcdef"],
|
|
239
|
-
misses: [],
|
|
240
|
-
rejectCandidates: false,
|
|
241
|
-
source: `${test262}lookBehind/nested-lookaround.js`,
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
pattern: "(?<=a(?=([bc]{2}(?<!a{2}))d)\\w{3})\\w\\w",
|
|
245
|
-
ignoreCase: false,
|
|
246
|
-
hits: ["abcdef"],
|
|
247
|
-
misses: [],
|
|
248
|
-
rejectCandidates: false,
|
|
249
|
-
source: `${test262}lookBehind/nested-lookaround.js`,
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
pattern: "(?<=a(?=([bc]{2}(?<!a*))d)\\w{3})\\w\\w",
|
|
253
|
-
ignoreCase: false,
|
|
254
|
-
hits: [],
|
|
255
|
-
misses: ["abcdef"],
|
|
256
|
-
rejectCandidates: false,
|
|
257
|
-
source: `${test262}lookBehind/nested-lookaround.js`,
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
pattern: "(?<!(^|[ab]))\\w{2}",
|
|
261
|
-
ignoreCase: false,
|
|
262
|
-
hits: ["abcdef"],
|
|
263
|
-
misses: [],
|
|
264
|
-
rejectCandidates: false,
|
|
265
|
-
source: `${test262}lookBehind/captures-negative.js`,
|
|
266
|
-
},
|
|
267
|
-
];
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Emit protocol records for real-process smoke and termination checks.
|
|
2
|
-
const chunks = JSON.parse(process.argv[2]);
|
|
3
|
-
for (const chunk of chunks) {
|
|
4
|
-
await new Promise((resolve) => process.stdout.write(Buffer.from(chunk, "base64"), resolve));
|
|
5
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
6
|
-
}
|
|
7
|
-
if (process.argv[3] === "wait") setInterval(() => {}, 1000);
|