@criogaid/pi-hashline-edit 0.9.0 → 0.11.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 +12 -12
- package/README.zh-CN.md +12 -12
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +96 -271
- package/src/core/apply.ts +62 -169
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +5 -5
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +8 -44
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +4 -7
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -19
- package/src/integration/grep-js-completeness.test.ts +45 -18
- package/src/integration/grep-line-candidates.test.ts +7 -10
- package/src/integration/grep-matrix.test.ts +6 -9
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +10 -9
- package/src/integration/grep-prefilter-coverage.test.ts +5 -8
- package/src/integration/grep-process-limits.test.ts +76 -0
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +166 -66
- package/src/integration/grep-scan-budget.test.ts +9 -9
- package/src/integration/grep-translation.test.ts +18 -32
- package/src/integration/large-text.test.ts +6 -52
- package/src/integration/model-budget-lifecycle.test.ts +10 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +161 -83
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +22 -12
- package/src/integration/report-replay.test.ts +23 -26
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +18 -17
- package/src/pi/action-fusion.test.ts +241 -353
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +150 -125
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +25 -28
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +334 -283
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +6 -8
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +7 -3
- package/src/pi/config.ts +12 -9
- package/src/pi/diagnostic-buffer.test.ts +34 -13
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +86 -211
- package/src/pi/error-text.ts +10 -9
- package/src/pi/execute.test.ts +249 -345
- package/src/pi/failure-context.test.ts +146 -127
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +182 -155
- package/src/pi/file-commit.test.ts +156 -71
- package/src/pi/file-commit.ts +126 -146
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +26 -22
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +19 -120
- package/src/pi/grep-candidates.ts +25 -76
- package/src/pi/grep-matrix.test.ts +5 -5
- package/src/pi/grep-order.test.ts +16 -15
- package/src/pi/grep-output.ts +94 -107
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +97 -0
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +41 -43
- package/src/pi/grep-search.ts +27 -39
- package/src/pi/grep-tool.ts +63 -106
- package/src/pi/grep.test.ts +177 -156
- package/src/pi/model-budgets.test.ts +27 -24
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +52 -21
- package/src/pi/mutation-runner.ts +134 -74
- package/src/pi/output-budgets.test.ts +86 -42
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +18 -23
- package/src/pi/read.test.ts +22 -41
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +85 -51
- package/src/pi/render.test.ts +88 -59
- package/src/pi/render.ts +64 -65
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -94
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +53 -38
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +10 -3
- package/src/pi/report-schema.ts +251 -148
- package/src/pi/report.test.ts +215 -67
- package/src/pi/report.ts +50 -98
- package/src/pi/result-safety.test.ts +241 -247
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +53 -75
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +35 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +36 -71
- package/src/pi/write.test.ts +31 -34
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/testing/run-tests.ts +1 -1
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -1,17 +1,16 @@
|
|
|
1
|
+
import { commandCompletion, type SessionCommand } from "./action-fusion.testing.ts";
|
|
1
2
|
import fs, { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
3
|
import { syncBuiltinESMExports } from "node:module";
|
|
3
4
|
import { tmpdir } from "node:os";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import assert from "node:assert/strict";
|
|
6
7
|
import { test } from "node:test";
|
|
7
|
-
import { createActionFusionExecutor
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { CommandNotRun, describeFailure, renderReport, reportOf } from "./report.ts";
|
|
8
|
+
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
9
|
+
import type { ActionFusionProgress } from "./report-schema.ts";
|
|
10
|
+
import { outputBudgetsFor } from "./budgets.ts";
|
|
11
|
+
import { reportOf } from "./report.ts";
|
|
12
12
|
import { callTool, createToolContext } from "./tool-call.testing.ts";
|
|
13
|
-
import { makeWriteOverride } from "./
|
|
14
|
-
import { publishedMutation } from "./mutation-outcome.testing.ts";
|
|
13
|
+
import { makeWriteOverride } from "./tool-factories.testing.ts";
|
|
15
14
|
|
|
16
15
|
async function withTemp<T>(run: (dir: string) => Promise<T>): Promise<T> {
|
|
17
16
|
const dir = await mkdtemp(join(tmpdir(), "hashline-failure-"));
|
|
@@ -21,7 +20,6 @@ async function withTemp<T>(run: (dir: string) => Promise<T>): Promise<T> {
|
|
|
21
20
|
await rm(dir, { recursive: true, force: true });
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
const mutation = (content: string) => publishedMutation(content, { content: [], details: {} });
|
|
25
23
|
|
|
26
24
|
test("temporary preparation and cleanup failures → preserve the commit failure and target bytes", async (t) =>
|
|
27
25
|
withTemp(async (dir) => {
|
|
@@ -51,7 +49,6 @@ test("temporary preparation and cleanup failures → preserve the commit failure
|
|
|
51
49
|
const report = reportOf(result, "write");
|
|
52
50
|
assert.equal(result.isError, true);
|
|
53
51
|
assert.equal(report?.error, "PUBLISH_FAILED");
|
|
54
|
-
assert.equal(report.stage, "commit");
|
|
55
52
|
assert.equal(report.publication, "NOT_PUBLISHED");
|
|
56
53
|
assert.deepEqual(report.cause, { code: original.code, message: original.message });
|
|
57
54
|
assert.equal(await readFile(target, "utf8"), "before\n");
|
|
@@ -62,126 +59,135 @@ test("temporary preparation and cleanup failures → preserve the commit failure
|
|
|
62
59
|
}
|
|
63
60
|
}));
|
|
64
61
|
|
|
65
|
-
test("
|
|
62
|
+
test("publication boundary and observer failures → preserve recovery and emit each diagnostic once", async (t) =>
|
|
66
63
|
withTemp(async (dir) => {
|
|
67
|
-
const
|
|
68
|
-
await
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
64
|
+
const budget = outputBudgetsFor(4096);
|
|
65
|
+
const context = await createToolContext(dir, t);
|
|
66
|
+
for (const publication of ["NOT_PUBLISHED", "PUBLISHED", "UNKNOWN"] as const) {
|
|
67
|
+
for (const progressError of [
|
|
68
|
+
undefined,
|
|
69
|
+
"display unavailable",
|
|
70
|
+
Object.assign(new Error("display unavailable " + "界".repeat(budget.fieldBytes)), {
|
|
71
|
+
code: "EIO",
|
|
72
|
+
cause: new Error("nested " + "界".repeat(budget.fieldBytes)),
|
|
73
|
+
}),
|
|
74
|
+
]) {
|
|
75
|
+
const target = join(dir, "boundary.txt");
|
|
76
|
+
await writeFile(target, "before\n");
|
|
77
|
+
const original = Object.assign(new Error("injected filesystem failure"), { code: "EIO" });
|
|
78
|
+
const nativeOpen = fs.open;
|
|
79
|
+
const nativeRename = fs.rename;
|
|
80
|
+
let published = false;
|
|
81
|
+
let commands = 0;
|
|
82
|
+
const progress: ActionFusionProgress[] = [];
|
|
83
|
+
try {
|
|
84
|
+
t.mock.method(fs, "open", async (...args: Parameters<typeof nativeOpen>) => {
|
|
85
|
+
if (
|
|
86
|
+
publication === "NOT_PUBLISHED" &&
|
|
87
|
+
String(args[0]).includes(".hashline-commit-") &&
|
|
88
|
+
args[1] === "w"
|
|
89
|
+
)
|
|
90
|
+
throw original;
|
|
91
|
+
if (publication === "PUBLISHED" && published && String(args[0]) === target)
|
|
92
|
+
throw original;
|
|
93
|
+
return nativeOpen(...args);
|
|
94
|
+
});
|
|
95
|
+
t.mock.method(fs, "rename", async (...args: Parameters<typeof nativeRename>) => {
|
|
96
|
+
if (String(args[1]) === target && publication === "UNKNOWN") throw original;
|
|
97
|
+
await nativeRename(...args);
|
|
98
|
+
published = true;
|
|
99
|
+
});
|
|
100
|
+
syncBuiltinESMExports();
|
|
101
|
+
const executeTool: SessionCommand = async () => {
|
|
102
|
+
commands++;
|
|
103
|
+
return commandCompletion({ content: [] });
|
|
104
|
+
};
|
|
105
|
+
const fusion = createActionFusionExecutor((update) => {
|
|
106
|
+
progress.push(update);
|
|
107
|
+
if (progressError !== undefined) throw progressError;
|
|
108
|
+
});
|
|
109
|
+
const result = await callTool(
|
|
110
|
+
makeWriteOverride(dir, fusion, () => budget),
|
|
111
|
+
{ path: target, mode: "overwrite", content: "after\n", then_run: { command: "check" } },
|
|
112
|
+
{ ctx: { ...context, executeTool } },
|
|
113
|
+
);
|
|
114
|
+
const report = reportOf(result, "write");
|
|
115
|
+
assert.equal(result.isError, true);
|
|
116
|
+
assert.ok(report);
|
|
117
|
+
assert.equal(
|
|
118
|
+
report.error,
|
|
119
|
+
publication === "PUBLISHED" ? "POST_PROCESS_FAILED" : "PUBLISH_FAILED",
|
|
120
|
+
);
|
|
121
|
+
assert.equal(report.publication, publication);
|
|
122
|
+
assert.deepEqual(report.cause, { code: original.code, message: original.message });
|
|
123
|
+
assert.equal(report.then_run?.status, "skipped");
|
|
124
|
+
if (publication === "PUBLISHED")
|
|
125
|
+
assert.match(report.next ?? "", /change is saved; do not repeat/);
|
|
126
|
+
else if (publication === "UNKNOWN")
|
|
127
|
+
assert.match(report.next ?? "", /may or may not be saved/);
|
|
128
|
+
else assert.equal(report.next, undefined);
|
|
129
|
+
assert.equal(result.content.length, 1);
|
|
130
|
+
const block = result.content[0];
|
|
131
|
+
assert.equal(block.type, "text");
|
|
132
|
+
const diagnostic = block.text;
|
|
133
|
+
for (const once of [
|
|
134
|
+
original.message,
|
|
135
|
+
report.message,
|
|
136
|
+
'"then_run"',
|
|
137
|
+
'"status": "skipped"',
|
|
138
|
+
])
|
|
139
|
+
assert.equal(diagnostic.split(once).length - 1, 1);
|
|
140
|
+
assert.equal(commands, 0);
|
|
141
|
+
assert.deepEqual(
|
|
142
|
+
progress.map((update) => update.command),
|
|
143
|
+
["waiting", "skipped"],
|
|
144
|
+
);
|
|
145
|
+
assert.ok(progress.every((update) => !update.mutationCompleted));
|
|
146
|
+
if (typeof progressError === "string") {
|
|
147
|
+
assert.deepEqual(report.progressError, { message: progressError });
|
|
148
|
+
} else if (progressError) {
|
|
149
|
+
assert.equal(report.progressError?.code, "EIO");
|
|
150
|
+
assert.ok(report.progressError.message.startsWith("display unavailable"));
|
|
151
|
+
assert.ok(Buffer.byteLength(report.progressError.message) <= budget.fieldBytes);
|
|
152
|
+
assert.notEqual(report.progressError.message, progressError.message);
|
|
153
|
+
assert.ok(report.progressError.cause);
|
|
154
|
+
assert.ok(report.progressError.cause.message.startsWith("nested"));
|
|
155
|
+
assert.ok(Buffer.byteLength(report.progressError.cause.message) <= budget.fieldBytes);
|
|
156
|
+
assert.notEqual(report.progressError.cause.message, progressError.cause.message);
|
|
157
|
+
} else assert.equal(report.progressError, undefined);
|
|
158
|
+
} finally {
|
|
159
|
+
t.mock.restoreAll();
|
|
160
|
+
syncBuiltinESMExports();
|
|
161
|
+
}
|
|
162
|
+
assert.equal(
|
|
163
|
+
await readFile(target, "utf8"),
|
|
164
|
+
publication === "PUBLISHED" ? "after\n" : "before\n",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
151
168
|
}));
|
|
152
169
|
|
|
153
170
|
test("cancellation after publication → does not rerun mutation and still inspects freshness", async (t) =>
|
|
154
171
|
withTemp(async (dir) => {
|
|
155
172
|
for (const state of ["changed", "missing"] as const) {
|
|
156
173
|
const target = join(dir, `${state}.txt`);
|
|
157
|
-
let mutations = 0;
|
|
158
174
|
const controller = new AbortController();
|
|
159
|
-
const
|
|
175
|
+
const executeTool: SessionCommand = async () => {
|
|
160
176
|
if (state === "changed") await writeFile(target, "command changed\n");
|
|
161
177
|
else await rm(target);
|
|
162
178
|
controller.abort();
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
mutate: async () => {
|
|
173
|
-
mutations++;
|
|
174
|
-
await writeFile(target, "mutation\n");
|
|
175
|
-
return mutation("mutation\n");
|
|
176
|
-
},
|
|
177
|
-
signal: controller.signal,
|
|
178
|
-
ctx: await createToolContext(dir, t),
|
|
179
|
-
});
|
|
180
|
-
const report = reportOf(outcome, "edit");
|
|
179
|
+
return commandCompletion({ content: [{ type: "text", text: "timed out" }] }, true);
|
|
180
|
+
};
|
|
181
|
+
const fusion = createActionFusionExecutor(() => {});
|
|
182
|
+
const result = await callTool(
|
|
183
|
+
makeWriteOverride(dir, fusion),
|
|
184
|
+
{ path: target, mode: "create", content: "mutation\n", then_run: { command: "check" } },
|
|
185
|
+
{ signal: controller.signal, ctx: { ...(await createToolContext(dir, t)), executeTool } },
|
|
186
|
+
);
|
|
187
|
+
const report = reportOf(result, "write");
|
|
181
188
|
assert.equal(report?.publication, "PUBLISHED");
|
|
182
189
|
assert.equal(report?.then_run?.status, "cancelled");
|
|
183
190
|
assert.equal(report?.freshness, state);
|
|
184
|
-
assert.equal(mutations, 1);
|
|
185
191
|
if (state === "changed") assert.equal(await readFile(target, "utf8"), "command changed\n");
|
|
186
192
|
else await assert.rejects(readFile(target), { code: "ENOENT" });
|
|
187
193
|
}
|
|
@@ -192,28 +198,29 @@ test("first command fails → releases the queue for the next mutation", async (
|
|
|
192
198
|
const target = join(dir, "queue.txt");
|
|
193
199
|
const ctx = await createToolContext(dir, t);
|
|
194
200
|
let calls = 0;
|
|
195
|
-
const
|
|
201
|
+
const executeTool: SessionCommand = async () => {
|
|
196
202
|
calls++;
|
|
197
|
-
if (calls === 1)
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
if (calls === 1)
|
|
204
|
+
return commandCompletion(
|
|
205
|
+
{ content: [{ type: "text", text: "first command failed" }] },
|
|
206
|
+
true,
|
|
207
|
+
);
|
|
208
|
+
return commandCompletion({ content: [{ type: "text", text: "ok" }] });
|
|
209
|
+
};
|
|
210
|
+
const fusion = createActionFusionExecutor(() => {});
|
|
200
211
|
for (const content of ["first\n", "second\n"]) {
|
|
201
|
-
const result = await
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
mutate: async () => {
|
|
209
|
-
await writeFile(target, content);
|
|
210
|
-
return mutation(content);
|
|
212
|
+
const result = await callTool(
|
|
213
|
+
makeWriteOverride(dir, fusion),
|
|
214
|
+
{
|
|
215
|
+
path: target,
|
|
216
|
+
content,
|
|
217
|
+
mode: calls === 0 ? "create" : "overwrite",
|
|
218
|
+
then_run: { command: "check" },
|
|
211
219
|
},
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
});
|
|
220
|
+
{ toolCallId: content, ctx: { ...ctx, executeTool } },
|
|
221
|
+
);
|
|
215
222
|
assert.equal(
|
|
216
|
-
reportOf(result, "
|
|
223
|
+
reportOf(result, "write")?.then_run?.status,
|
|
217
224
|
calls === 1 ? "failed" : "succeeded",
|
|
218
225
|
);
|
|
219
226
|
}
|
|
@@ -225,33 +232,53 @@ test("command succeeds on an unchanged target → retains the result and complet
|
|
|
225
232
|
withTemp(async (dir) => {
|
|
226
233
|
const target = join(dir, "finalize.txt");
|
|
227
234
|
const progress: ActionFusionProgress[] = [];
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
const executeTool: SessionCommand = async () =>
|
|
236
|
+
commandCompletion({ content: [{ type: "text", text: "command finished" }] });
|
|
237
|
+
const fusion = createActionFusionExecutor((event) => progress.push(event));
|
|
238
|
+
const completed = await callTool(
|
|
239
|
+
makeWriteOverride(dir, fusion),
|
|
240
|
+
{ path: target, content: "saved\n", mode: "create", then_run: { command: "check" } },
|
|
241
|
+
{ ctx: { ...(await createToolContext(dir, t)), executeTool } },
|
|
234
242
|
);
|
|
235
|
-
const completed = await fusion({
|
|
236
|
-
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
237
|
-
toolCallId: "finalize",
|
|
238
|
-
tool: "edit",
|
|
239
|
-
displayPath: "finalize.txt",
|
|
240
|
-
absolutePath: target,
|
|
241
|
-
thenRun: { command: "check" },
|
|
242
|
-
signal: undefined,
|
|
243
|
-
ctx: await createToolContext(dir, t),
|
|
244
|
-
mutate: async () => {
|
|
245
|
-
await writeFile(target, "saved\n");
|
|
246
|
-
return mutation("saved\n");
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
243
|
assert.equal(completed.content.length, 1);
|
|
250
|
-
assert.equal(reportOf(completed, "
|
|
251
|
-
assert.equal(reportOf(completed, "
|
|
244
|
+
assert.equal(reportOf(completed, "write")?.then_run?.status, "succeeded");
|
|
245
|
+
assert.equal(reportOf(completed, "write")?.then_run?.output, "command finished");
|
|
252
246
|
assert.equal(progress.filter((event) => event.command === "succeeded").length, 1);
|
|
253
247
|
assert.equal(progress.at(-1)?.freshness, "unchanged");
|
|
254
248
|
assert.deepEqual(progress.at(-1)?.result, {
|
|
255
249
|
content: [{ type: "text", text: "command finished" }],
|
|
250
|
+
details: {},
|
|
256
251
|
});
|
|
257
252
|
}));
|
|
253
|
+
|
|
254
|
+
test("cancellation before mutation → reports a cancelled command without publishing", async (t) =>
|
|
255
|
+
withTemp(async (dir) => {
|
|
256
|
+
const target = join(dir, "cancelled.txt");
|
|
257
|
+
await writeFile(target, "before\n");
|
|
258
|
+
const controller = new AbortController();
|
|
259
|
+
controller.abort();
|
|
260
|
+
let commands = 0;
|
|
261
|
+
const progress: ActionFusionProgress[] = [];
|
|
262
|
+
const executeTool: SessionCommand = async () => {
|
|
263
|
+
commands++;
|
|
264
|
+
return commandCompletion({ content: [] });
|
|
265
|
+
};
|
|
266
|
+
const fusion = createActionFusionExecutor((event) => progress.push(event));
|
|
267
|
+
const result = await callTool(
|
|
268
|
+
makeWriteOverride(dir, fusion),
|
|
269
|
+
{ path: target, mode: "overwrite", content: "after\n", then_run: { command: "check" } },
|
|
270
|
+
{ signal: controller.signal, ctx: { ...(await createToolContext(dir, t)), executeTool } },
|
|
271
|
+
);
|
|
272
|
+
const report = reportOf(result, "write");
|
|
273
|
+
assert.equal(result.isError, true);
|
|
274
|
+
assert.equal(report?.error, "OPERATION_ABORTED");
|
|
275
|
+
assert.equal(report?.publication, "NOT_PUBLISHED");
|
|
276
|
+
assert.equal(report?.then_run?.status, "cancelled");
|
|
277
|
+
assert.deepEqual(
|
|
278
|
+
progress.map((event) => event.command),
|
|
279
|
+
["waiting", "cancelled"],
|
|
280
|
+
);
|
|
281
|
+
assert.ok(progress.every((event) => !event.mutationCompleted));
|
|
282
|
+
assert.equal(commands, 0);
|
|
283
|
+
assert.equal(await readFile(target, "utf8"), "before\n");
|
|
284
|
+
}));
|