@firstpick/pi-package-webui 0.7.7 → 0.7.9
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 +23 -0
- package/bin/pi-webui-rpc-supervisor.mjs +115 -21
- package/bin/pi-webui.mjs +447 -88
- package/lib/queue-mutation.mjs +109 -0
- package/lib/rpc-supervisor-client.mjs +18 -2
- package/lib/rpc-supervisor-protocol.mjs +11 -2
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +4 -4
- package/public/app.js +2227 -195
- package/public/index.html +143 -2
- package/public/issue-bot-client.mjs +344 -0
- package/public/issue-wizard-state.mjs +443 -0
- package/public/service-worker.js +3 -1
- package/public/styles.css +787 -56
- package/public/voice-conversation.mjs +1 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/compaction-mutation-contract.test.mjs +166 -0
- package/tests/compaction-resume-harness.test.mjs +113 -2
- package/tests/compaction-static.test.mjs +5 -0
- package/tests/completion-signal-contract.test.mjs +156 -0
- package/tests/cwd-footer-reliability-static.test.mjs +112 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +25 -2
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/file-selection-overlay-static.test.mjs +21 -0
- package/tests/file-viewer-search-static.test.mjs +65 -0
- package/tests/fixtures/compacting-pi.mjs +0 -0
- package/tests/fixtures/fake-pi.mjs +186 -49
- package/tests/footer-context-contrast-static.test.mjs +10 -0
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/git-panel-render-stability-static.test.mjs +11 -1
- package/tests/http-endpoints-harness.test.mjs +160 -1
- package/tests/issue-bot-client.test.mjs +135 -0
- package/tests/issue-wizard-state.test.mjs +126 -0
- package/tests/mobile-static.test.mjs +61 -42
- package/tests/native-parity.test.mjs +3 -3
- package/tests/open-issue-wizard-static.test.mjs +75 -0
- package/tests/prompt-routing-tab-status.test.mjs +5 -0
- package/tests/queue-edit-reorder-static.test.mjs +101 -0
- package/tests/queue-mutation-contract.test.mjs +143 -0
- package/tests/rpc-supervisor-host.test.mjs +135 -2
- package/tests/rpc-supervisor-protocol.test.mjs +26 -0
- package/tests/scoped-models.test.mjs +42 -0
- package/tests/streaming-ui-coupling.test.mjs +3 -2
- package/tests/subagents-helper.test.mjs +216 -3
- package/tests/terminal-tab-workspace-static.test.mjs +101 -0
- package/tests/webui-workspaces-harness.test.mjs +223 -0
- package/tests/webui-workspaces.test.mjs +106 -0
- package/tests/workspace-save-load-static.test.mjs +69 -0
- package/webui-rpc-helper.mjs +300 -41
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mutatePiRuntimeFollowUpQueue } from "../lib/queue-mutation.mjs";
|
|
3
|
+
|
|
4
|
+
function queuedMessage(text, extra = {}) {
|
|
5
|
+
return {
|
|
6
|
+
role: "user",
|
|
7
|
+
timestamp: 1234,
|
|
8
|
+
metadata: { origin: "fixture" },
|
|
9
|
+
content: [{ type: "text", text }, { type: "image", mimeType: "image/png", data: "iVBORw0KGgo=" }],
|
|
10
|
+
...extra,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function fixture({ steering = ["steer"], followUp = ["first", "second", "third"], steeringMessages, followUpMessages } = {}) {
|
|
15
|
+
let events = 0;
|
|
16
|
+
const session = {
|
|
17
|
+
_steeringMessages: [...steering],
|
|
18
|
+
_followUpMessages: [...followUp],
|
|
19
|
+
agent: {
|
|
20
|
+
steeringQueue: { messages: steeringMessages || steering.map((text) => queuedMessage(text)) },
|
|
21
|
+
followUpQueue: { messages: followUpMessages || followUp.map((text) => queuedMessage(text)) },
|
|
22
|
+
},
|
|
23
|
+
_emitQueueUpdate() { events += 1; },
|
|
24
|
+
};
|
|
25
|
+
return { session, eventCount: () => events };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function expected(session) {
|
|
29
|
+
return { steering: [...session._steeringMessages], followUp: [...session._followUpMessages] };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function editRequest(session, index, text, expectedText = session._followUpMessages[index]) {
|
|
33
|
+
return {
|
|
34
|
+
source: "pi-runtime",
|
|
35
|
+
kind: "followUp",
|
|
36
|
+
expected: expected(session),
|
|
37
|
+
operation: { type: "edit", index, expectedText, text },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function moveRequest(session, from, to, expectedText = session._followUpMessages[from]) {
|
|
42
|
+
return {
|
|
43
|
+
source: "pi-runtime",
|
|
44
|
+
kind: "followUp",
|
|
45
|
+
expected: expected(session),
|
|
46
|
+
operation: { type: "move", from, to, expectedText },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
{
|
|
51
|
+
const { session, eventCount } = fixture();
|
|
52
|
+
const beforeMessage = session.agent.followUpQueue.messages[1];
|
|
53
|
+
const beforeImage = beforeMessage.content[1];
|
|
54
|
+
const result = mutatePiRuntimeFollowUpQueue(session, editRequest(session, 1, "edited"));
|
|
55
|
+
assert.deepEqual(result, {
|
|
56
|
+
mutated: true,
|
|
57
|
+
source: "pi-runtime",
|
|
58
|
+
queue: { source: "pi-runtime", steering: ["steer"], followUp: ["first", "edited", "third"] },
|
|
59
|
+
});
|
|
60
|
+
assert.deepEqual(session._followUpMessages, ["first", "edited", "third"]);
|
|
61
|
+
assert.equal(session.agent.followUpQueue.messages[1].role, "user", "edit preserves message role");
|
|
62
|
+
assert.equal(session.agent.followUpQueue.messages[1].timestamp, 1234, "edit preserves message timestamp");
|
|
63
|
+
assert.deepEqual(session.agent.followUpQueue.messages[1].metadata, { origin: "fixture" }, "edit preserves metadata");
|
|
64
|
+
assert.strictEqual(session.agent.followUpQueue.messages[1].content[1], beforeImage, "edit preserves image content exactly");
|
|
65
|
+
assert.equal(beforeMessage.content[0].text, "second", "edit does not mutate the original message object");
|
|
66
|
+
assert.equal(eventCount(), 1, "successful edit emits exactly one queue update");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
const { session, eventCount } = fixture();
|
|
71
|
+
const firstMessage = session.agent.followUpQueue.messages[0];
|
|
72
|
+
const result = mutatePiRuntimeFollowUpQueue(session, moveRequest(session, 0, 2));
|
|
73
|
+
assert.equal(result.mutated, true);
|
|
74
|
+
assert.deepEqual(session._followUpMessages, ["second", "third", "first"], "move uses the final post-removal index");
|
|
75
|
+
assert.strictEqual(session.agent.followUpQueue.messages[2], firstMessage, "move keeps the message object paired with its tracking string");
|
|
76
|
+
assert.equal(eventCount(), 1, "successful move emits exactly one queue update");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
{
|
|
80
|
+
const { session, eventCount } = fixture({ followUp: ["same", "same"] });
|
|
81
|
+
const result = mutatePiRuntimeFollowUpQueue(session, editRequest(session, 1, "changed"));
|
|
82
|
+
assert.equal(result.mutated, true, "duplicate text is safe when the requested index and complete snapshot match");
|
|
83
|
+
assert.deepEqual(session._followUpMessages, ["same", "changed"]);
|
|
84
|
+
assert.equal(eventCount(), 1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (const staleMutation of [
|
|
88
|
+
(session) => { session._followUpMessages.push("new"); session.agent.followUpQueue.messages.push(queuedMessage("new")); },
|
|
89
|
+
(session) => { session._followUpMessages.shift(); session.agent.followUpQueue.messages.shift(); },
|
|
90
|
+
(session) => { session._followUpMessages.reverse(); session.agent.followUpQueue.messages.reverse(); },
|
|
91
|
+
]) {
|
|
92
|
+
const { session, eventCount } = fixture();
|
|
93
|
+
const request = editRequest(session, 1, "edited");
|
|
94
|
+
staleMutation(session);
|
|
95
|
+
const before = structuredClone({ tracking: session._followUpMessages, messages: session.agent.followUpQueue.messages });
|
|
96
|
+
const result = mutatePiRuntimeFollowUpQueue(session, request);
|
|
97
|
+
assert.equal(result.mutated, false);
|
|
98
|
+
assert.equal(result.reason, "queue-changed", "a stale full snapshot is rejected");
|
|
99
|
+
assert.deepEqual({ tracking: session._followUpMessages, messages: session.agent.followUpQueue.messages }, before, "stale mutations leave paired arrays untouched");
|
|
100
|
+
assert.equal(eventCount(), 0, "stale mutations emit no queue update");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
{
|
|
104
|
+
const { session, eventCount } = fixture();
|
|
105
|
+
session.agent.followUpQueue.messages[1] = queuedMessage("different");
|
|
106
|
+
const before = structuredClone({ tracking: session._followUpMessages, messages: session.agent.followUpQueue.messages });
|
|
107
|
+
const result = mutatePiRuntimeFollowUpQueue(session, editRequest(session, 1, "edited"));
|
|
108
|
+
assert.equal(result.reason, "queue-desynchronized");
|
|
109
|
+
assert.deepEqual({ tracking: session._followUpMessages, messages: session.agent.followUpQueue.messages }, before);
|
|
110
|
+
assert.equal(eventCount(), 0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const requestFor of [
|
|
114
|
+
(session) => ({ ...editRequest(session, 1, ""), operation: { ...editRequest(session, 1, "").operation, text: " " } }),
|
|
115
|
+
(session) => editRequest(session, 99, "edited"),
|
|
116
|
+
(session) => moveRequest(session, 0, 0),
|
|
117
|
+
(session) => moveRequest(session, 0, 99),
|
|
118
|
+
(session) => ({ ...editRequest(session, 1, "edited"), source: "webui-compaction" }),
|
|
119
|
+
(session) => ({ ...editRequest(session, 1, "edited"), kind: "steering" }),
|
|
120
|
+
]) {
|
|
121
|
+
const { session, eventCount } = fixture();
|
|
122
|
+
const before = structuredClone({ tracking: session._followUpMessages, messages: session.agent.followUpQueue.messages });
|
|
123
|
+
const result = mutatePiRuntimeFollowUpQueue(session, requestFor(session));
|
|
124
|
+
assert.equal(result.mutated, false);
|
|
125
|
+
assert.equal(result.reason, "invalid-request");
|
|
126
|
+
assert.deepEqual({ tracking: session._followUpMessages, messages: session.agent.followUpQueue.messages }, before);
|
|
127
|
+
assert.equal(eventCount(), 0, "invalid mutations emit no queue update");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
{
|
|
131
|
+
const { session, eventCount } = fixture();
|
|
132
|
+
session.agent.followUpQueue.messages[0].content.push({ type: "text", text: "unexpected" });
|
|
133
|
+
const result = mutatePiRuntimeFollowUpQueue(session, editRequest(session, 0, "edited"));
|
|
134
|
+
assert.equal(result.reason, "queue-desynchronized", "unknown message text layouts fail closed");
|
|
135
|
+
assert.equal(eventCount(), 0);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
const result = mutatePiRuntimeFollowUpQueue({}, { source: "pi-runtime", kind: "followUp", expected: { steering: [], followUp: [] }, operation: { type: "edit", index: 0, expectedText: "x", text: "y" } });
|
|
140
|
+
assert.deepEqual(result, { mutated: false, reason: "queue-unsupported", queue: { source: "pi-runtime", steering: [], followUp: [] } }, "missing private Pi structures fail closed");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log("queue-mutation-contract.test.mjs passed");
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { createConnection, createServer } from "node:net";
|
|
3
|
-
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { setTimeout as delay } from "node:timers/promises";
|
|
8
8
|
import {
|
|
9
|
+
RPC_SUPERVISOR_CHILD_ARG_LIMIT,
|
|
9
10
|
RPC_SUPERVISOR_EVENT_RING_MAX_BYTES,
|
|
10
11
|
RPC_SUPERVISOR_REQUEST_DEDUPE_LIMIT,
|
|
11
12
|
} from "../lib/rpc-supervisor-protocol.mjs";
|
|
@@ -39,7 +40,13 @@ const rawPiScript = String.raw`
|
|
|
39
40
|
setTimeout(() => process.exit(0), 2500).unref();
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
if (command.type === "
|
|
43
|
+
if (command.type === "pause_stdin") {
|
|
44
|
+
send({ type: "response", id: command.id, data: { paused: true } });
|
|
45
|
+
setInterval(() => {}, 1000);
|
|
46
|
+
process.stdin.pause();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (command.type === "no_response" || command.type === "extension_ui_response") return;
|
|
43
50
|
if (command.type === "flood") {
|
|
44
51
|
send({ type: "response", id: command.id, data: { accepted: true } });
|
|
45
52
|
for (let index = 0; index < 80; index += 1) send({ type: "large_event", index, tokens: { keep: index }, body: "r".repeat(72 * 1024) });
|
|
@@ -90,6 +97,16 @@ async function waitFor(label, predicate, timeoutMs = 5_000) {
|
|
|
90
97
|
throw new Error(`${label} did not happen within ${timeoutMs}ms`);
|
|
91
98
|
}
|
|
92
99
|
|
|
100
|
+
function pidIsAlive(pid) {
|
|
101
|
+
if (!Number.isInteger(pid) || pid < 1) return false;
|
|
102
|
+
try {
|
|
103
|
+
process.kill(pid, 0);
|
|
104
|
+
return true;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
return error?.code === "EPERM";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
93
110
|
let client;
|
|
94
111
|
let replacement;
|
|
95
112
|
let replayClient;
|
|
@@ -112,6 +129,18 @@ try {
|
|
|
112
129
|
metadata: { title: "Raw", index: 1, cwd: work, sessionFile: path.join(work, "raw.jsonl") },
|
|
113
130
|
child: { command: process.execPath, args: ["-e", rawPiScript], cwd: work },
|
|
114
131
|
});
|
|
132
|
+
await assert.rejects(
|
|
133
|
+
Promise.race([
|
|
134
|
+
client.createTab({
|
|
135
|
+
tabId: "invalid-arg-tab",
|
|
136
|
+
metadata: { title: "Invalid", index: 2, cwd: work },
|
|
137
|
+
child: { command: process.execPath, args: Array.from({ length: RPC_SUPERVISOR_CHILD_ARG_LIMIT + 1 }, () => "x"), cwd: work },
|
|
138
|
+
}),
|
|
139
|
+
delay(1_000).then(() => { throw new Error("validation failure was not correlated to the create request"); }),
|
|
140
|
+
]),
|
|
141
|
+
/at most 1024 entries/,
|
|
142
|
+
"invalid create frames must reject their matching client request instead of hanging",
|
|
143
|
+
);
|
|
115
144
|
|
|
116
145
|
const response = await Promise.all([
|
|
117
146
|
client.command("tab-1", { type: "prompt", message: "dedupe me" }, { requestId: "prompt-once" }),
|
|
@@ -142,6 +171,95 @@ try {
|
|
|
142
171
|
const written = await waitFor("raw write log", async () => (await rawLines()).find((line) => line.type === "extension_ui_response"));
|
|
143
172
|
assert.deepEqual(written, rawWrite, "fire-and-forget writes must reach Pi unchanged and without an injected request ID");
|
|
144
173
|
|
|
174
|
+
const pendingCommand = client.command("raw-tab", { type: "no_response" }, { requestId: "pending-before-ui-write", timeoutMs: 700 });
|
|
175
|
+
await waitFor("pending command admission", async () => (await rawLines()).some((line) => line.type === "no_response"));
|
|
176
|
+
const queuedProbe = await Promise.race([
|
|
177
|
+
client.command("raw-tab", { type: "queued_behind_pending_response" }, { requestId: "queued-behind-pending-response", timeoutMs: 500 }),
|
|
178
|
+
delay(300).then(() => { throw new Error("a pending Pi response held the supervisor admission queue"); }),
|
|
179
|
+
]);
|
|
180
|
+
assert.equal(queuedProbe.data.type, "queued_behind_pending_response", "later commands should be admitted without waiting for an earlier Pi response");
|
|
181
|
+
await Promise.race([
|
|
182
|
+
client.write("raw-tab", { type: "extension_ui_response", id: "ui-behind-pending-command" }, { requestId: "ui-behind-pending-command" }),
|
|
183
|
+
delay(300).then(() => { throw new Error("extension UI response deadlocked behind a pending Pi command"); }),
|
|
184
|
+
]);
|
|
185
|
+
await waitFor("extension UI response behind pending command", async () => (await rawLines()).some((line) => line.id === "ui-behind-pending-command"));
|
|
186
|
+
await assert.rejects(pendingCommand, /Timed out waiting for RPC response/, "the deliberately unanswered command should retain its own response timeout");
|
|
187
|
+
|
|
188
|
+
const metadataUpdates = [];
|
|
189
|
+
let metadataSerial = 0;
|
|
190
|
+
const metadataFlood = setInterval(() => {
|
|
191
|
+
metadataSerial += 1;
|
|
192
|
+
metadataUpdates.push(client.updateTab("raw-tab", {
|
|
193
|
+
title: `Raw ${metadataSerial}`,
|
|
194
|
+
index: 1,
|
|
195
|
+
cwd: work,
|
|
196
|
+
sessionFile: path.join(work, "raw.jsonl"),
|
|
197
|
+
}));
|
|
198
|
+
}, 1);
|
|
199
|
+
try {
|
|
200
|
+
await delay(40);
|
|
201
|
+
const starvationProbe = await Promise.race([
|
|
202
|
+
client.command("raw-tab", { type: "metadata_starvation_probe" }, { requestId: "metadata-starvation-probe" }),
|
|
203
|
+
delay(3_000).then(() => { throw new Error("RPC command starved behind continuous metadata updates"); }),
|
|
204
|
+
]);
|
|
205
|
+
assert.equal(starvationProbe.data.type, "metadata_starvation_probe", "commands should take a FIFO admission position instead of chasing a continuously moving metadata tail");
|
|
206
|
+
} finally {
|
|
207
|
+
clearInterval(metadataFlood);
|
|
208
|
+
const updateResults = await Promise.allSettled(metadataUpdates);
|
|
209
|
+
assert.ok(updateResults.length > 0 && updateResults.every((result) => result.status === "fulfilled"), "metadata flood must consist of successful updates");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const replacementCwd = path.join(work, "replacement-cwd");
|
|
213
|
+
await mkdir(replacementCwd);
|
|
214
|
+
const originalRawPid = client.snapshot.tabs.find((tab) => tab.id === "raw-tab")?.pid;
|
|
215
|
+
const paused = await client.command("raw-tab", { type: "pause_stdin" }, { requestId: "pause-stdin-before-replace" });
|
|
216
|
+
assert.equal(paused.data.paused, true);
|
|
217
|
+
const blockedWriteResult = client.write("raw-tab", {
|
|
218
|
+
type: "extension_ui_response",
|
|
219
|
+
id: "backpressured-before-replace",
|
|
220
|
+
body: "x".repeat(2 * 1024 * 1024),
|
|
221
|
+
}, { requestId: "backpressured-before-replace" }).then(
|
|
222
|
+
() => ({ status: "fulfilled" }),
|
|
223
|
+
(error) => ({ status: "rejected", error }),
|
|
224
|
+
);
|
|
225
|
+
const replacedRawTab = await Promise.race([
|
|
226
|
+
client.replaceTab({
|
|
227
|
+
tabId: "raw-tab",
|
|
228
|
+
metadata: { title: "Raw", index: 1, cwd: replacementCwd, sessionFile: path.join(work, "raw.jsonl") },
|
|
229
|
+
child: { command: process.execPath, args: ["-e", rawPiScript], cwd: replacementCwd },
|
|
230
|
+
}),
|
|
231
|
+
delay(5_000).then(() => { throw new Error("replacement remained blocked behind a backpressured one-way write"); }),
|
|
232
|
+
]);
|
|
233
|
+
const blockedWrite = await blockedWriteResult;
|
|
234
|
+
assert.equal(blockedWrite.status, "rejected", "a backpressured one-way write must fail within a bounded interval");
|
|
235
|
+
assert.match(blockedWrite.error?.message || "", /Timed out flushing a one-way Pi RPC write/, "the bounded write failure should explain the queue blockage");
|
|
236
|
+
assert.equal(replacedRawTab.metadata.cwd, replacementCwd, "successful replacement should publish the child cwd atomically");
|
|
237
|
+
assert.notEqual(replacedRawTab.pid, originalRawPid, "successful replacement should expose the replacement child PID");
|
|
238
|
+
const replacedRawResponse = await client.command("raw-tab", { type: "replacement_probe" }, { requestId: "replacement-probe" });
|
|
239
|
+
assert.equal(replacedRawResponse.data.type, "replacement_probe", "replacement child should accept RPC commands after replace resolves");
|
|
240
|
+
|
|
241
|
+
const concurrentCwdA = path.join(work, "concurrent-cwd-a");
|
|
242
|
+
const concurrentCwdB = path.join(work, "concurrent-cwd-b");
|
|
243
|
+
await Promise.all([mkdir(concurrentCwdA), mkdir(concurrentCwdB)]);
|
|
244
|
+
const [concurrentA, concurrentB] = await Promise.all([
|
|
245
|
+
client.replaceTab({
|
|
246
|
+
tabId: "raw-tab",
|
|
247
|
+
metadata: { title: "Raw A", index: 1, cwd: concurrentCwdA, sessionFile: path.join(work, "raw.jsonl") },
|
|
248
|
+
child: { command: process.execPath, args: ["-e", rawPiScript], cwd: concurrentCwdA },
|
|
249
|
+
}),
|
|
250
|
+
client.replaceTab({
|
|
251
|
+
tabId: "raw-tab",
|
|
252
|
+
metadata: { title: "Raw B", index: 1, cwd: concurrentCwdB, sessionFile: path.join(work, "raw.jsonl") },
|
|
253
|
+
child: { command: process.execPath, args: ["-e", rawPiScript], cwd: concurrentCwdB },
|
|
254
|
+
}),
|
|
255
|
+
]);
|
|
256
|
+
assert.equal(concurrentA.metadata.cwd, concurrentCwdA, "first queued replacement should resolve with its own committed cwd");
|
|
257
|
+
assert.equal(concurrentB.metadata.cwd, concurrentCwdB, "second queued replacement should resolve with its own committed cwd");
|
|
258
|
+
assert.notEqual(concurrentA.pid, concurrentB.pid, "serialized replacements should use distinct child processes");
|
|
259
|
+
await waitFor("superseded replacement child exit", () => !pidIsAlive(concurrentA.pid));
|
|
260
|
+
const concurrentProbe = await client.command("raw-tab", { type: "concurrent_replacement_probe" }, { requestId: "concurrent-replacement-probe" });
|
|
261
|
+
assert.equal(concurrentProbe.data.type, "concurrent_replacement_probe", "commands arriving after queued replacements should reach the final child");
|
|
262
|
+
|
|
145
263
|
const deliveredStartupEvents = [];
|
|
146
264
|
const unsubscribe = client.onEvent((event) => deliveredStartupEvents.push(event));
|
|
147
265
|
await client.command("raw-tab", { type: "emit_one" }, { requestId: "startup-buffer-event" });
|
|
@@ -157,6 +275,21 @@ try {
|
|
|
157
275
|
assert.equal(state.tabs.length, 2);
|
|
158
276
|
assert.equal(state.tabs.find((tab) => tab.id === "tab-1").metadata.apiToken, undefined, "private metadata fields must not reach the state snapshot");
|
|
159
277
|
|
|
278
|
+
const failedReplacementCwd = path.join(work, "failed-replacement-cwd");
|
|
279
|
+
await mkdir(failedReplacementCwd);
|
|
280
|
+
await assert.rejects(
|
|
281
|
+
client.replaceTab({
|
|
282
|
+
tabId: "tab-1",
|
|
283
|
+
metadata: { title: "One", index: 0, cwd: failedReplacementCwd, sessionFile: path.join(work, "one.jsonl") },
|
|
284
|
+
child: { command: path.join(work, "missing-pi-executable"), args: [], cwd: failedReplacementCwd },
|
|
285
|
+
}),
|
|
286
|
+
/ENOENT|spawn/i,
|
|
287
|
+
"replace should reject when the replacement child cannot spawn",
|
|
288
|
+
);
|
|
289
|
+
await delay(50);
|
|
290
|
+
const stateAfterFailedReplacement = await readSupervisorState(paths);
|
|
291
|
+
assert.equal(stateAfterFailedReplacement.tabs.find((tab) => tab.id === "tab-1").metadata.cwd, work, "failed replacement must not persist the requested cwd");
|
|
292
|
+
|
|
160
293
|
replacement = await discoverStartAttachRpcSupervisor({ agentDir, port, controllerId: "replacement-controller", startupTimeoutMs: 5_000 });
|
|
161
294
|
await assert.rejects(client.command("tab-1", { type: "get_state" }), /fenced|closed|not attached/i, "newer attachment must fence prior controller writes");
|
|
162
295
|
assert.equal(replacement.snapshot.tabs.find((tab) => tab.id === "tab-1").id, "tab-1");
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import {
|
|
3
3
|
PI_RPC_JSONL_LINE_MAX_BYTES,
|
|
4
|
+
RPC_SUPERVISOR_CHILD_ARG_LIMIT,
|
|
4
5
|
RPC_SUPERVISOR_MAX_FRAME_BYTES,
|
|
5
6
|
RPC_SUPERVISOR_PROTOCOL,
|
|
6
7
|
RpcSupervisorProtocolError,
|
|
7
8
|
constantTimeTokenEqual,
|
|
8
9
|
encodeFrame,
|
|
9
10
|
frameReader,
|
|
11
|
+
protocolCompatible,
|
|
12
|
+
protocolCurrent,
|
|
10
13
|
sanitizeSupervisorData,
|
|
11
14
|
validateClientFrame,
|
|
12
15
|
} from "../lib/rpc-supervisor-protocol.mjs";
|
|
@@ -17,6 +20,29 @@ const attach = validateClientFrame({
|
|
|
17
20
|
assert.equal(attach.token, "private-token", "attach validation must retain the private token for authentication");
|
|
18
21
|
assert.equal(constantTimeTokenEqual("same", "same"), true);
|
|
19
22
|
assert.equal(constantTimeTokenEqual("same", "different"), false);
|
|
23
|
+
assert.equal(protocolCompatible({ major: RPC_SUPERVISOR_PROTOCOL.major, minor: 0 }), true, "older minor versions remain attach-compatible for actionable recovery");
|
|
24
|
+
assert.equal(protocolCurrent({ major: RPC_SUPERVISOR_PROTOCOL.major, minor: 0 }), false, "older detached supervisors must be detectable after a server-only restart");
|
|
25
|
+
assert.equal(protocolCurrent(RPC_SUPERVISOR_PROTOCOL), true);
|
|
26
|
+
|
|
27
|
+
const resumedChildArgs = Array.from({ length: 257 }, (_, index) => index % 2 === 0 ? "--extension" : `/tmp/resource-${index}`);
|
|
28
|
+
const resumedChild = validateClientFrame({
|
|
29
|
+
type: "create",
|
|
30
|
+
requestId: "create-resumed-tab",
|
|
31
|
+
tabId: "resumed-tab",
|
|
32
|
+
metadata: {},
|
|
33
|
+
child: { command: "pi", args: resumedChildArgs, cwd: "/tmp" },
|
|
34
|
+
});
|
|
35
|
+
assert.equal(resumedChild.child.args.length, 257, "resource-heavy resumed tabs must fit the supervisor launch contract");
|
|
36
|
+
assert.throws(
|
|
37
|
+
() => validateClientFrame({
|
|
38
|
+
type: "create",
|
|
39
|
+
requestId: "create-too-many-args",
|
|
40
|
+
tabId: "oversized-tab",
|
|
41
|
+
metadata: {},
|
|
42
|
+
child: { command: "pi", args: Array.from({ length: RPC_SUPERVISOR_CHILD_ARG_LIMIT + 1 }, () => "x"), cwd: "/tmp" },
|
|
43
|
+
}),
|
|
44
|
+
/at most 1024 entries/,
|
|
45
|
+
);
|
|
20
46
|
|
|
21
47
|
const rawPiCommand = {
|
|
22
48
|
type: "prompt",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { resolveScopedModelsFromPatterns } from "../lib/scoped-models.mjs";
|
|
3
|
+
|
|
4
|
+
const models = [
|
|
5
|
+
{ provider: "anthropic", id: "claude-fable-5", name: "Claude Fable 5" },
|
|
6
|
+
{ provider: "openrouter", id: "anthropic/claude-fable-5", name: "Claude Fable 5" },
|
|
7
|
+
{ provider: "openrouter", id: "anthropic/claude-fable-5:batch", name: "Claude Fable 5 Batch" },
|
|
8
|
+
{ provider: "openrouter", id: "google/gemini-3.6-flash", name: "Gemini 3.6 Flash" },
|
|
9
|
+
{ provider: "openrouter", id: "google/gemini-3.6-flash:batch", name: "Gemini 3.6 Flash Batch" },
|
|
10
|
+
{ provider: "openrouter", id: "openrouter/auto", name: "Auto" },
|
|
11
|
+
{ provider: "openrouter", id: "openrouter/auto-beta", name: "Auto Beta" },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const exactPatterns = [
|
|
15
|
+
"anthropic/claude-fable-5",
|
|
16
|
+
"openrouter/google/gemini-3.6-flash",
|
|
17
|
+
"openrouter/openrouter/auto",
|
|
18
|
+
];
|
|
19
|
+
const exact = await resolveScopedModelsFromPatterns(exactPatterns, models);
|
|
20
|
+
assert.deepEqual(
|
|
21
|
+
exact.map((model) => `${model.provider}/${model.id}`),
|
|
22
|
+
exactPatterns,
|
|
23
|
+
"exact Pi scope entries must not expand to cross-provider, batch, or similarly named models",
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const withThinking = await resolveScopedModelsFromPatterns(["anthropic/claude-fable-5:high"], models);
|
|
27
|
+
assert.deepEqual(withThinking.map((model) => `${model.provider}/${model.id}`), ["anthropic/claude-fable-5"]);
|
|
28
|
+
|
|
29
|
+
const exactColonId = await resolveScopedModelsFromPatterns(["openrouter/anthropic/claude-fable-5:batch"], models);
|
|
30
|
+
assert.deepEqual(exactColonId.map((model) => `${model.provider}/${model.id}`), ["openrouter/anthropic/claude-fable-5:batch"]);
|
|
31
|
+
|
|
32
|
+
const glob = await resolveScopedModelsFromPatterns(["openrouter/google/gemini-3.6-flash*"], models);
|
|
33
|
+
assert.deepEqual(
|
|
34
|
+
glob.map((model) => `${model.provider}/${model.id}`),
|
|
35
|
+
["openrouter/google/gemini-3.6-flash", "openrouter/google/gemini-3.6-flash:batch"],
|
|
36
|
+
"explicit Pi glob patterns must retain their intentional expansion behavior",
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
assert.deepEqual(await resolveScopedModelsFromPatterns([null, ""], models), []);
|
|
40
|
+
assert.deepEqual(await resolveScopedModelsFromPatterns(exactPatterns, null), []);
|
|
41
|
+
|
|
42
|
+
console.log("scoped-models.test.mjs passed");
|
|
@@ -178,7 +178,7 @@ futureInvariant("theory #6: output-seen tab refresh should remain out of the mes
|
|
|
178
178
|
futureInvariant("theory #6: event-end output-seen refresh should not synchronously rebuild all tabs", () => {
|
|
179
179
|
assert.doesNotMatch(markTabOutputSeen, /renderTabs\(\)/, "output-seen serial changes should schedule/coalesce tab chrome updates");
|
|
180
180
|
});
|
|
181
|
-
assert.match(findCaseBody(handleEvent, "
|
|
181
|
+
assert.match(findCaseBody(handleEvent, "agent_settled"), /markTabOutputSeen\(\)/, "theory #6: output-seen marking should happen only when a logical run settles");
|
|
182
182
|
assert.match(findCaseBody(handleEvent, "compaction_end"), /markTabOutputSeen\(\)/, "theory #6: output-seen marking should still happen when compaction ends");
|
|
183
183
|
|
|
184
184
|
futureInvariant("theory #7: skill tracking must not inspect every message_update event", () => {
|
|
@@ -192,7 +192,8 @@ assert.match(trackAutoRetryStateFromEvent, /event\.type === "auto_retry_start"/,
|
|
|
192
192
|
// Theory #8 is a correctness guard: the current design still uses a steer prompt,
|
|
193
193
|
// but it must never run while the agent is active.
|
|
194
194
|
assert.match(requestGitFooterWebuiPayload, /currentState\?\.isStreaming \|\| currentState\?\.isCompacting/, "theory #8: git-footer steer refresh must remain guarded during active streaming/compaction");
|
|
195
|
-
assert.match(findCaseBody(handleEvent, "
|
|
195
|
+
assert.match(findCaseBody(handleEvent, "agent_settled"), /currentState\) currentState = \{ \.\.\.currentState, isStreaming: false \};[\s\S]*?requestGitFooterWebuiPayload\(tabContext, \{ force: true \}\)/, "theory #8: forced git-footer refresh should only happen after agent settlement clears streaming state");
|
|
196
|
+
assert.doesNotMatch(findCaseBody(handleEvent, "agent_end"), /isStreaming: false|requestGitFooterWebuiPayload/, "theory #8: low-level agent_end must not expose an idle window before retry or continuation");
|
|
196
197
|
|
|
197
198
|
if (futureFailures.length) {
|
|
198
199
|
assert.fail(`streaming/UI coupling invariants still failing (${futureFailures.length}):\n\n${futureFailures.map((failure, index) => `${index + 1}. ${failure}`).join("\n\n")}`);
|