@firstpick/pi-package-webui 0.7.6 → 0.7.8
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 +60 -4
- package/bin/pi-webui-rpc-supervisor.mjs +612 -0
- package/bin/pi-webui.mjs +1051 -95
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/rpc-supervisor-client.mjs +317 -0
- package/lib/rpc-supervisor-protocol.mjs +245 -0
- package/lib/rpc-supervisor-state.mjs +165 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +4 -4
- package/public/app.js +1986 -170
- package/public/index.html +388 -25
- package/public/issue-bot-client.mjs +344 -0
- package/public/issue-wizard-state.mjs +443 -0
- package/public/service-worker.js +8 -1
- package/public/styles.css +578 -52
- package/public/subagent-gate-visibility.mjs +36 -0
- package/public/workflow-status-stack.mjs +69 -0
- package/tests/app-runner-process-tree-harness.test.mjs +37 -3
- package/tests/boot-failure-diagnostics.test.mjs +180 -0
- package/tests/completion-signal-contract.test.mjs +156 -0
- package/tests/cwd-footer-reliability-static.test.mjs +107 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +275 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/fixtures/fake-pi.mjs +90 -6
- package/tests/footer-context-contrast-static.test.mjs +10 -0
- package/tests/git-panel-file-preview-static.test.mjs +221 -0
- package/tests/git-panel-render-stability-static.test.mjs +11 -1
- package/tests/http-endpoints-harness.test.mjs +458 -33
- package/tests/issue-bot-client.test.mjs +135 -0
- package/tests/issue-wizard-state.test.mjs +126 -0
- package/tests/mobile-static.test.mjs +79 -16
- package/tests/native-parity-harness.test.mjs +2 -1
- package/tests/native-parity.test.mjs +13 -2
- package/tests/numpad-decimal-input-static.test.mjs +128 -0
- package/tests/open-issue-wizard-static.test.mjs +75 -0
- package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
- package/tests/prompt-routing-tab-status.test.mjs +108 -0
- package/tests/rpc-supervisor-host.test.mjs +408 -0
- package/tests/rpc-supervisor-protocol.test.mjs +93 -0
- package/tests/rpc-supervisor-state.test.mjs +62 -0
- package/tests/run-all.mjs +4 -1
- package/tests/streaming-ui-coupling.test.mjs +18 -2
- package/tests/subagent-gate-visibility.test.mjs +66 -0
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagents-helper.test.mjs +136 -0
- package/tests/terminal-tab-workspace-static.test.mjs +99 -0
- package/tests/workflow-status-stack.test.mjs +87 -0
- package/webui-rpc-helper.mjs +160 -2
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { connectRpcSupervisor } from "../lib/rpc-supervisor-client.mjs";
|
|
9
|
+
import { readSupervisorState, supervisorPaths } from "../lib/rpc-supervisor-state.mjs";
|
|
10
|
+
|
|
11
|
+
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
12
|
+
const serverScript = path.join(root, "bin", "pi-webui.mjs");
|
|
13
|
+
const fakePi = path.join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
14
|
+
const port = 39000 + Math.floor(Math.random() * 15000);
|
|
15
|
+
const streamPrompt = "fixture continuity delayed stream";
|
|
16
|
+
|
|
17
|
+
async function request(pathname, { method = "GET", body, timeoutMs = 3_000 } = {}) {
|
|
18
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
19
|
+
method,
|
|
20
|
+
headers: body === undefined ? undefined : { "content-type": "application/json" },
|
|
21
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
22
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
23
|
+
});
|
|
24
|
+
let payload;
|
|
25
|
+
try { payload = await response.json(); } catch { payload = undefined; }
|
|
26
|
+
return { status: response.status, body: payload };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function waitFor(label, predicate, { timeoutMs = 12_000, intervalMs = 80 } = {}) {
|
|
30
|
+
const deadline = Date.now() + timeoutMs;
|
|
31
|
+
let lastError;
|
|
32
|
+
while (Date.now() < deadline) {
|
|
33
|
+
try {
|
|
34
|
+
const value = await predicate();
|
|
35
|
+
if (value) return value;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
lastError = error;
|
|
38
|
+
}
|
|
39
|
+
await delay(intervalMs);
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`${label} did not happen in time${lastError ? `: ${lastError.message}` : ""}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function initialSseEvents(tabId, expectedCount = 3) {
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const timeout = setTimeout(() => controller.abort(new Error("timed out reading continuity SSE state")), 5_000);
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/events?tab=${encodeURIComponent(tabId)}`, { signal: controller.signal });
|
|
49
|
+
assert.equal(response.status, 200, "replacement server SSE endpoint must open");
|
|
50
|
+
const reader = response.body.getReader();
|
|
51
|
+
const decoder = new TextDecoder();
|
|
52
|
+
const events = [];
|
|
53
|
+
let buffer = "";
|
|
54
|
+
while (events.length < expectedCount) {
|
|
55
|
+
const { done, value } = await reader.read();
|
|
56
|
+
if (done) break;
|
|
57
|
+
buffer += decoder.decode(value, { stream: true });
|
|
58
|
+
let boundary;
|
|
59
|
+
while ((boundary = buffer.indexOf("\n\n")) >= 0) {
|
|
60
|
+
const block = buffer.slice(0, boundary);
|
|
61
|
+
buffer = buffer.slice(boundary + 2);
|
|
62
|
+
const data = block.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).join("\n");
|
|
63
|
+
if (data) events.push(JSON.parse(data));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return events;
|
|
67
|
+
} finally {
|
|
68
|
+
clearTimeout(timeout);
|
|
69
|
+
controller.abort();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function pidIsAlive(pid) {
|
|
74
|
+
if (!Number.isInteger(pid) || pid < 1) return false;
|
|
75
|
+
try {
|
|
76
|
+
process.kill(pid, 0);
|
|
77
|
+
return true;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return error?.code === "EPERM";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function spawnServer({ cwd, env, output }) {
|
|
84
|
+
const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
85
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
86
|
+
env,
|
|
87
|
+
});
|
|
88
|
+
child.stdout.on("data", (chunk) => output.push(String(chunk)));
|
|
89
|
+
child.stderr.on("data", (chunk) => output.push(String(chunk)));
|
|
90
|
+
return child;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function health() {
|
|
94
|
+
const response = await request("/api/health", { timeoutMs: 1_000 });
|
|
95
|
+
if (response.status !== 200 || response.body?.ok !== true) return null;
|
|
96
|
+
return response.body;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function tabs() {
|
|
100
|
+
const response = await request("/api/tabs");
|
|
101
|
+
assert.equal(response.status, 200, "tabs endpoint should be available");
|
|
102
|
+
return response.body?.data?.tabs || [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function readLog(logFile) {
|
|
106
|
+
const text = await readFile(logFile, "utf8").catch(() => "");
|
|
107
|
+
return text.split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const work = await mkdtemp(path.join(tmpdir(), "pi-webui-continuity-harness-"));
|
|
111
|
+
const agentDir = path.join(work, "agent");
|
|
112
|
+
const cwd = path.join(work, "cwd");
|
|
113
|
+
const changedCwd = path.join(work, "changed-cwd");
|
|
114
|
+
const settingsFile = path.join(work, "settings.json");
|
|
115
|
+
const sessionFile = path.join(work, "fixture-session.jsonl");
|
|
116
|
+
const logFile = path.join(work, "fake-pi.jsonl");
|
|
117
|
+
const output = [];
|
|
118
|
+
const environment = {
|
|
119
|
+
...process.env,
|
|
120
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
121
|
+
PI_WEBUI_SETTINGS_FILE: settingsFile,
|
|
122
|
+
PI_WEBUI_RPC_SUPERVISOR: "1",
|
|
123
|
+
FAKE_PI_CONTINUITY_MODE: "1",
|
|
124
|
+
FAKE_PI_CONTINUITY_SESSION_FILE: sessionFile,
|
|
125
|
+
FAKE_PI_LOG_FILE: logFile,
|
|
126
|
+
};
|
|
127
|
+
const paths = await supervisorPaths({ agentDir, port });
|
|
128
|
+
let initialServer;
|
|
129
|
+
let manualServer;
|
|
130
|
+
let observedPiPid;
|
|
131
|
+
let observedTabId;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
await writeFile(settingsFile, "{}\n");
|
|
135
|
+
await mkdir(cwd, { recursive: true });
|
|
136
|
+
await mkdir(changedCwd, { recursive: true });
|
|
137
|
+
initialServer = spawnServer({ cwd, env: environment, output });
|
|
138
|
+
|
|
139
|
+
const initialHealth = await waitFor("initial supervised server health", health);
|
|
140
|
+
assert.equal(initialHealth.rpcSupervisor?.enabled, true, "harness must opt into the supervisor");
|
|
141
|
+
assert.equal(initialHealth.rpcSupervisor?.attached, true, "server must attach to the supervisor");
|
|
142
|
+
const initialWebuiPid = initialHealth.webuiPid;
|
|
143
|
+
const initialTabs = await tabs();
|
|
144
|
+
assert.equal(initialTabs.length, 1, "isolated server startup should create one tab");
|
|
145
|
+
const initialTab = initialTabs[0];
|
|
146
|
+
observedTabId = initialTab.id;
|
|
147
|
+
observedPiPid = initialTab.pid;
|
|
148
|
+
assert.ok(Number.isInteger(observedPiPid) && observedPiPid > 0, "initial tab must expose its fake Pi PID");
|
|
149
|
+
assert.equal(initialTab.cwd, cwd, "tab metadata must retain the isolated cwd");
|
|
150
|
+
assert.equal(initialTab.sessionFile, sessionFile, "fixture session metadata must be captured before restart");
|
|
151
|
+
|
|
152
|
+
const concurrentCwdChanges = await Promise.all([
|
|
153
|
+
request(`/api/tabs/${encodeURIComponent(observedTabId)}`, { method: "PATCH", body: { cwd: changedCwd }, timeoutMs: 12_000 }),
|
|
154
|
+
request(`/api/tabs/${encodeURIComponent(observedTabId)}`, { method: "PATCH", body: { cwd: changedCwd }, timeoutMs: 12_000 }),
|
|
155
|
+
]);
|
|
156
|
+
assert.deepEqual(concurrentCwdChanges.map((response) => response.status).sort(), [200, 409], "overlapping existing-tab cwd changes should allow one restart and reject the duplicate deterministically");
|
|
157
|
+
const cwdChange = concurrentCwdChanges.find((response) => response.status === 200);
|
|
158
|
+
const rejectedCwdChange = concurrentCwdChanges.find((response) => response.status === 409);
|
|
159
|
+
assert.match(String(rejectedCwdChange.body?.error || ""), /already changing its working folder/i, "rejected overlapping cwd change should explain the active restart");
|
|
160
|
+
assert.equal(cwdChange.body?.data?.changed, true, "existing-tab cwd change should report a real restart");
|
|
161
|
+
assert.equal(cwdChange.body?.data?.tab?.cwd, changedCwd, "cwd change response should expose the replacement cwd");
|
|
162
|
+
assert.notEqual(cwdChange.body?.data?.tab?.pid, observedPiPid, "cwd change should replace the managed Pi child");
|
|
163
|
+
observedPiPid = cwdChange.body.data.tab.pid;
|
|
164
|
+
const cwdChangeState = await request(`/api/state?tab=${encodeURIComponent(observedTabId)}`);
|
|
165
|
+
assert.equal(cwdChangeState.status, 200, "replacement child should answer state requests before cwd PATCH resolves");
|
|
166
|
+
const cwdChangeCommands = await request(`/api/commands?tab=${encodeURIComponent(observedTabId)}`);
|
|
167
|
+
assert.equal(cwdChangeCommands.status, 200, "replacement child should answer command discovery after cwd change");
|
|
168
|
+
const replacementStartup = await waitFor("replacement cwd startup", async () => (
|
|
169
|
+
(await readLog(logFile)).find((entry) => entry.direction === "startup" && entry.pid === observedPiPid && entry.cwd === changedCwd)
|
|
170
|
+
));
|
|
171
|
+
assert.equal(replacementStartup.cwd, changedCwd, "replacement child process should actually run in the requested cwd");
|
|
172
|
+
|
|
173
|
+
const controlledPrompt = await request("/api/prompt", { method: "POST", body: { tab: observedTabId, message: streamPrompt } });
|
|
174
|
+
assert.equal(controlledPrompt.status, 200, "controlled-restart prompt must be accepted once");
|
|
175
|
+
const preRestartTab = (await tabs())[0];
|
|
176
|
+
const restart = await request("/api/restart", { method: "POST" });
|
|
177
|
+
assert.equal(restart.status, 200, "controlled restart must be accepted");
|
|
178
|
+
assert.equal(restart.body?.webuiPid, initialWebuiPid, "restart response must identify the retiring HTTP server");
|
|
179
|
+
|
|
180
|
+
const restartedHealth = await waitFor("controlled-restart replacement health", async () => {
|
|
181
|
+
const value = await health();
|
|
182
|
+
return value && value.webuiPid !== initialWebuiPid ? value : null;
|
|
183
|
+
}, { timeoutMs: 15_000 });
|
|
184
|
+
const controlledTabs = await tabs();
|
|
185
|
+
assert.equal(controlledTabs.length, 1, "controlled restart must hydrate instead of spawning duplicate tabs");
|
|
186
|
+
assert.deepEqual(
|
|
187
|
+
controlledTabs.map((tab) => ({ id: tab.id, pid: tab.pid, cwd: tab.cwd, sessionFile: tab.sessionFile, title: tab.title, index: tab.index })),
|
|
188
|
+
[{ id: preRestartTab.id, pid: observedPiPid, cwd: changedCwd, sessionFile, title: preRestartTab.title, index: preRestartTab.index }],
|
|
189
|
+
"controlled restart must retain the same managed tab metadata and Pi PID",
|
|
190
|
+
);
|
|
191
|
+
assert.equal(restartedHealth.piPid, observedPiPid, "controlled restart must retain the active Pi process");
|
|
192
|
+
await waitFor("controlled stream completion", async () => {
|
|
193
|
+
const state = await request(`/api/state?tab=${encodeURIComponent(observedTabId)}`);
|
|
194
|
+
return state.body?.data?.isStreaming === false;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const abruptPrompt = await request("/api/prompt", { method: "POST", body: { tab: observedTabId, message: streamPrompt } });
|
|
198
|
+
assert.equal(abruptPrompt.status, 200, "abrupt-loss prompt must be accepted once");
|
|
199
|
+
const abruptWebuiPid = restartedHealth.webuiPid;
|
|
200
|
+
process.kill(abruptWebuiPid, "SIGKILL");
|
|
201
|
+
await waitFor("abrupt HTTP server exit", () => !pidIsAlive(abruptWebuiPid));
|
|
202
|
+
await delay(1_500);
|
|
203
|
+
|
|
204
|
+
const state = await readSupervisorState(paths);
|
|
205
|
+
assert.ok(state, "supervisor state must remain available after HTTP SIGKILL");
|
|
206
|
+
|
|
207
|
+
manualServer = spawnServer({ cwd, env: environment, output });
|
|
208
|
+
const manualHealth = await waitFor("manual same-port replacement health", health, { timeoutMs: 15_000 });
|
|
209
|
+
assert.notEqual(manualHealth.webuiPid, abruptWebuiPid, "manual relaunch must use a new HTTP server process");
|
|
210
|
+
assert.equal(manualHealth.piPid, observedPiPid, "manual same-port relaunch must attach to the original Pi process");
|
|
211
|
+
const manualTabs = await tabs();
|
|
212
|
+
assert.equal(manualTabs.length, 1, "manual relaunch must not duplicate the supervised tab");
|
|
213
|
+
assert.deepEqual(
|
|
214
|
+
manualTabs.map((tab) => ({ id: tab.id, pid: tab.pid, cwd: tab.cwd, sessionFile: tab.sessionFile, title: tab.title, index: tab.index })),
|
|
215
|
+
[{ id: preRestartTab.id, pid: observedPiPid, cwd: changedCwd, sessionFile, title: preRestartTab.title, index: preRestartTab.index }],
|
|
216
|
+
"manual relaunch must retain tab ID, PID, and persisted metadata",
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const reconnectEvents = await initialSseEvents(observedTabId);
|
|
220
|
+
const connectedEvent = reconnectEvents.find((event) => event.type === "webui_connected");
|
|
221
|
+
const replayGapEvent = reconnectEvents.find((event) => event.type === "webui_supervisor_replay_gap");
|
|
222
|
+
assert.equal(connectedEvent?.supervisorReplayGap, true, "actual replacement server must report a truthful cursor-less replay gap");
|
|
223
|
+
assert.equal(Object.hasOwn(connectedEvent || {}, "supervisorGap"), false, "replacement server must use the browser's canonical replay-gap field");
|
|
224
|
+
assert.equal(replayGapEvent?.supervisorReplayGap, true, "replacement SSE must explicitly warn that authoritative replay recovery ran");
|
|
225
|
+
|
|
226
|
+
const recoveredState = await request(`/api/state?tab=${encodeURIComponent(observedTabId)}`);
|
|
227
|
+
assert.equal(recoveredState.status, 200, "replacement server must query authoritative Pi state");
|
|
228
|
+
assert.equal(recoveredState.body?.data?.isStreaming, false, "replacement server must observe the completed downtime turn");
|
|
229
|
+
const recoveredMessages = await request(`/api/messages?tab=${encodeURIComponent(observedTabId)}`);
|
|
230
|
+
assert.equal(recoveredMessages.status, 200, "replacement server must expose the authoritative transcript");
|
|
231
|
+
const recoveredTranscript = recoveredMessages.body?.data?.messages || [];
|
|
232
|
+
assert.equal(recoveredTranscript.filter((message) => message?.role === "user" && message.content === streamPrompt).length, 2, "both accepted continuity prompts must appear once in the transcript");
|
|
233
|
+
assert.equal(recoveredTranscript.filter((message) => message?.role === "assistant" && message.content?.[0]?.text === "continuity stream complete").length, 2, "the completed controlled and downtime outputs must each appear once authoritatively");
|
|
234
|
+
const replacementStatus = await request("/api/webui-status?detailed=true&events=200");
|
|
235
|
+
const replayedEventTypes = (replacementStatus.body?.data?.events || []).map((event) => event.type);
|
|
236
|
+
const lastAgentStart = replayedEventTypes.lastIndexOf("agent_start");
|
|
237
|
+
const followingAgentEnd = replayedEventTypes.indexOf("agent_end", lastAgentStart);
|
|
238
|
+
assert.deepEqual(replayedEventTypes.slice(lastAgentStart, followingAgentEnd + 1), ["agent_start", "message_start", "message_update", "message_end", "agent_end"], "replacement server must apply the ordered downtime event stream before authoritative refresh events");
|
|
239
|
+
|
|
240
|
+
const commandEntries = (await readLog(logFile)).filter((entry) => entry.direction === "command" && entry.message === streamPrompt);
|
|
241
|
+
assert.equal(commandEntries.length, 2, "each accepted continuity prompt must reach fake Pi exactly once despite server loss");
|
|
242
|
+
assert.equal(new Set(commandEntries.map((entry) => entry.type)).size, 1, "continuity prompt command records must remain identifiable");
|
|
243
|
+
assert.equal(commandEntries[0].type, "prompt");
|
|
244
|
+
|
|
245
|
+
const stopped = await request("/api/shutdown", { method: "POST" });
|
|
246
|
+
assert.equal(stopped.status, 200, "explicit shutdown must be accepted");
|
|
247
|
+
await waitFor("explicit HTTP shutdown", () => !pidIsAlive(manualHealth.webuiPid));
|
|
248
|
+
await waitFor("explicit Pi cleanup", () => !pidIsAlive(observedPiPid), { timeoutMs: 8_000 });
|
|
249
|
+
await waitFor("supervisor state cleanup", async () => {
|
|
250
|
+
const remainingState = await readSupervisorState(paths);
|
|
251
|
+
if (!remainingState) return true;
|
|
252
|
+
if (!pidIsAlive(remainingState.pid)) throw new Error(`dead supervisor ${remainingState.pid} left stale state`);
|
|
253
|
+
return false;
|
|
254
|
+
}, { timeoutMs: 12_000 });
|
|
255
|
+
const exitEntries = (await readLog(logFile)).filter((entry) => entry.direction === "exit" && entry.pid === observedPiPid);
|
|
256
|
+
assert.ok(exitEntries.some((entry) => entry.signal === "SIGTERM"), "explicit shutdown must produce the fake-Pi termination marker");
|
|
257
|
+
console.log(`durable-rpc-supervisor-harness.test.mjs passed (Pi PID ${observedPiPid}; tab ${observedTabId})`);
|
|
258
|
+
} finally {
|
|
259
|
+
const liveServer = manualServer?.exitCode === null ? manualServer : initialServer?.exitCode === null ? initialServer : null;
|
|
260
|
+
if (liveServer) {
|
|
261
|
+
try { await request("/api/shutdown", { method: "POST", timeoutMs: 1_000 }); } catch {
|
|
262
|
+
try { liveServer.kill("SIGKILL"); } catch {}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const remaining = await readSupervisorState(paths).catch(() => null);
|
|
266
|
+
if (remaining) {
|
|
267
|
+
const cleanupClient = await connectRpcSupervisor({ agentDir, port, controllerId: "durable-harness-cleanup", connectTimeoutMs: 1_000 }).catch(() => null);
|
|
268
|
+
if (cleanupClient) {
|
|
269
|
+
try { await cleanupClient.shutdown(); } catch {}
|
|
270
|
+
cleanupClient.close();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
await delay(150);
|
|
274
|
+
await rm(work, { recursive: true, force: true });
|
|
275
|
+
}
|
|
@@ -149,10 +149,10 @@ assert.match(app, /fastOutputModeSelect\?\.addEventListener\("change", \(\) => \
|
|
|
149
149
|
assert.match(app, /refreshSidebarOutputMode\(\)\.catch[\s\S]*?initializeTabs\(\)/, "sidebar output mode should initialize with the WebUI");
|
|
150
150
|
|
|
151
151
|
assert.match(helper, /FAST_OUTPUT_FLUSH_INTERVAL_MS = 100/, "the live scheduler should retain the exact 100 ms sustained-output bound");
|
|
152
|
-
assert.match(worker, /pi-webui-pwa-
|
|
152
|
+
assert.match(worker, /pi-webui-pwa-v\d+[\s\S]*?"\/fast-output-live\.mjs"/, "PWA cache identity and app shell should include the compact helper");
|
|
153
153
|
assert.match(html, /<label for="fastOutputModeSelect">Fast mode \(Experimental\)<\/label>/, "the sidebar should mark fast mode as experimental");
|
|
154
154
|
assert.match(html, /Markdown final output; live thinking expanded; stored thinking grouped and collapsed/, "the sidebar should distinguish live and stored thinking defaults");
|
|
155
|
-
assert.match(html,
|
|
155
|
+
assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=92"/, "the guarded PWA entry point should cache-bust browser wiring");
|
|
156
156
|
assert.match(JSON.parse(packageRaw).scripts.check, /node --check public\/fast-output-live\.mjs/, "package checks should parse the compact helper");
|
|
157
157
|
|
|
158
158
|
const events = createFastModeOutputEvents();
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// ({direction:"event", type}), so browser-driver tests can assert ordering.
|
|
12
12
|
// - FAKE_PI_VOICE_SCRIPTS=1: prompts containing "voice test say|question|tool|slow"
|
|
13
13
|
// respond success and then asynchronously emit a scripted agent event flow
|
|
14
|
-
// (agent_start/message_*/tool_execution_*/agent_end) over stdout; the scripted
|
|
14
|
+
// (agent_start/message_*/tool_execution_*/agent_end/agent_settled) over stdout; the scripted
|
|
15
15
|
// assistant turns are appended to a dynamic transcript returned by
|
|
16
16
|
// get_messages AFTER the three baseline messages, and get_state reports
|
|
17
17
|
// isStreaming=true while a scripted flow runs.
|
|
@@ -20,7 +20,9 @@ import { randomUUID } from "node:crypto";
|
|
|
20
20
|
import { appendFileSync } from "node:fs";
|
|
21
21
|
|
|
22
22
|
const sessionIndex = process.argv.indexOf("--session");
|
|
23
|
-
const sessionFile = sessionIndex !== -1
|
|
23
|
+
const sessionFile = sessionIndex !== -1
|
|
24
|
+
? process.argv[sessionIndex + 1]
|
|
25
|
+
: process.env.FAKE_PI_CONTINUITY_MODE === "1" ? process.env.FAKE_PI_CONTINUITY_SESSION_FILE || undefined : undefined;
|
|
24
26
|
|
|
25
27
|
let activeBash = 0;
|
|
26
28
|
let peakBash = 0;
|
|
@@ -38,7 +40,13 @@ let enabledToolNames = new Set(fakeTools.map((tool) => tool.name));
|
|
|
38
40
|
let enabledSkillNames = new Set(fakeSkills.map((skill) => skill.name));
|
|
39
41
|
|
|
40
42
|
const voiceScriptsEnabled = process.env.FAKE_PI_VOICE_SCRIPTS === "1";
|
|
43
|
+
// The continuity harness opts into this behavior explicitly so existing fixture
|
|
44
|
+
// consumers retain their current timing and log shapes.
|
|
45
|
+
const continuityModeEnabled = process.env.FAKE_PI_CONTINUITY_MODE === "1";
|
|
46
|
+
const largePayloadsEnabled = process.env.FAKE_PI_LARGE_PAYLOADS === "1";
|
|
41
47
|
const commandLogFile = process.env.FAKE_PI_LOG_FILE || "";
|
|
48
|
+
const largeRpcText = "large-rpc-payload:" + "λ".repeat(70_000);
|
|
49
|
+
const largeTokenSamples = Array.from({ length: 300 }, (_, index) => ({ index, input: index + 1, output: index + 2 }));
|
|
42
50
|
const staticEntries = [
|
|
43
51
|
{ type: "message", id: "u0000001", parentId: null, timestamp: new Date(1000).toISOString(), message: { role: "user", content: "fake prompt", timestamp: 1000 } },
|
|
44
52
|
{ type: "message", id: "a0000001", parentId: "u0000001", timestamp: new Date(2000).toISOString(), message: { role: "assistant", content: [{ type: "text", text: "fake answer" }], timestamp: 2000 } },
|
|
@@ -48,6 +56,8 @@ const dynamicEntries = [];
|
|
|
48
56
|
const dynamicMessages = [];
|
|
49
57
|
let dynamicLeafId = "u0000002";
|
|
50
58
|
let scriptedStreaming = false;
|
|
59
|
+
let continuityRun = 0;
|
|
60
|
+
let largeTranscriptEnabled = false;
|
|
51
61
|
|
|
52
62
|
function allSessionEntries() {
|
|
53
63
|
return [...staticEntries, ...dynamicEntries];
|
|
@@ -91,10 +101,28 @@ function logJsonLine(entry) {
|
|
|
91
101
|
|
|
92
102
|
logJsonLine({
|
|
93
103
|
direction: "startup",
|
|
104
|
+
cwd: process.cwd(),
|
|
94
105
|
recoveryUrl: String(process.env.PI_WEBUI_RECOVERY_URL || ""),
|
|
95
106
|
recoveryTokenConfigured: Boolean(process.env.PI_WEBUI_RECOVERY_TOKEN),
|
|
107
|
+
...(continuityModeEnabled ? { pid: process.pid, continuityMode: true } : {}),
|
|
96
108
|
});
|
|
97
109
|
|
|
110
|
+
function continuityExitMarker(signal) {
|
|
111
|
+
if (continuityModeEnabled) logJsonLine({ direction: "exit", signal, pid: process.pid });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (continuityModeEnabled) {
|
|
115
|
+
process.on("SIGTERM", () => {
|
|
116
|
+
continuityExitMarker("SIGTERM");
|
|
117
|
+
process.exit(143);
|
|
118
|
+
});
|
|
119
|
+
process.on("SIGINT", () => {
|
|
120
|
+
continuityExitMarker("SIGINT");
|
|
121
|
+
process.exit(130);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
98
126
|
function respond(payload) {
|
|
99
127
|
process.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
100
128
|
}
|
|
@@ -128,7 +156,7 @@ function cancelScriptedSteps() {
|
|
|
128
156
|
}
|
|
129
157
|
|
|
130
158
|
// Emits a full scripted assistant turn: agent_start, optional tool phase,
|
|
131
|
-
// streamed assistant text, message_end, agent_end. The final assistant text is
|
|
159
|
+
// streamed assistant text, message_end, agent_end, agent_settled. The final assistant text is
|
|
132
160
|
// appended to the dynamic transcript so get_messages returns it afterwards.
|
|
133
161
|
function runVoiceScriptFlow({ text, chunks, chunkSpacingMs = 60, toolPhase = false, toolDurationMs = 1500 }) {
|
|
134
162
|
scriptedStreaming = true;
|
|
@@ -150,16 +178,57 @@ function runVoiceScriptFlow({ text, chunks, chunkSpacingMs = 60, toolPhase = fal
|
|
|
150
178
|
emitScriptedEvent({ type: "message_end", message });
|
|
151
179
|
},
|
|
152
180
|
});
|
|
181
|
+
steps.push({ afterMs: 60, run: () => emitScriptedEvent({ type: "agent_end" }) });
|
|
153
182
|
steps.push({
|
|
154
|
-
afterMs:
|
|
183
|
+
afterMs: 10,
|
|
155
184
|
run: () => {
|
|
156
185
|
scriptedStreaming = false;
|
|
157
|
-
emitScriptedEvent({ type: "
|
|
186
|
+
emitScriptedEvent({ type: "agent_settled" });
|
|
158
187
|
},
|
|
159
188
|
});
|
|
160
189
|
runScriptedSteps(steps);
|
|
161
190
|
}
|
|
162
191
|
|
|
192
|
+
function runContinuityDelayedStream() {
|
|
193
|
+
scriptedStreaming = true;
|
|
194
|
+
const text = "continuity stream complete";
|
|
195
|
+
const run = ++continuityRun;
|
|
196
|
+
const tagged = (payload) => ({ ...payload, continuityRun: run });
|
|
197
|
+
const steps = [
|
|
198
|
+
{ afterMs: 80, run: () => emitScriptedEvent(tagged({ type: "agent_start", continuityStep: "start" })) },
|
|
199
|
+
{ afterMs: 80, run: () => emitScriptedEvent(tagged({ type: "message_start", continuityStep: "message-start", message: { role: "assistant" } })) },
|
|
200
|
+
{ afterMs: 300, run: () => emitScriptedEvent(tagged({ type: "message_update", continuityStep: "delta-1", assistantMessageEvent: { type: "text_delta", delta: "continuity " } })) },
|
|
201
|
+
{ afterMs: 300, run: () => emitScriptedEvent(tagged({ type: "message_update", continuityStep: "delta-2", assistantMessageEvent: { type: "text_delta", delta: "stream " } })) },
|
|
202
|
+
{ afterMs: 300, run: () => emitScriptedEvent(tagged({ type: "message_update", continuityStep: "delta-3", assistantMessageEvent: { type: "text_delta", delta: "complete" } })) },
|
|
203
|
+
{ afterMs: 100, run: () => {
|
|
204
|
+
const message = { role: "assistant", content: [{ type: "text", text }], timestamp: Date.now() };
|
|
205
|
+
appendDynamicMessage(message);
|
|
206
|
+
emitScriptedEvent(tagged({ type: "message_end", continuityStep: "message-end", message }));
|
|
207
|
+
} },
|
|
208
|
+
{ afterMs: 80, run: () => emitScriptedEvent(tagged({ type: "agent_end", continuityStep: "end" })) },
|
|
209
|
+
{ afterMs: 10, run: () => {
|
|
210
|
+
scriptedStreaming = false;
|
|
211
|
+
emitScriptedEvent(tagged({ type: "agent_settled", continuityStep: "settled" }));
|
|
212
|
+
} },
|
|
213
|
+
];
|
|
214
|
+
runScriptedSteps(steps);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function handleContinuityPrompt(command, base) {
|
|
218
|
+
if (!continuityModeEnabled || String(command.message || "").trim() !== "fixture continuity delayed stream") return false;
|
|
219
|
+
appendDynamicMessage({ role: "user", content: String(command.message), timestamp: Date.now() });
|
|
220
|
+
respond({ ...base, data: { output: "fake continuity stream accepted", pid: process.pid } });
|
|
221
|
+
runContinuityDelayedStream();
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function handleLargePayloadPrompt(command, base) {
|
|
226
|
+
if (!largePayloadsEnabled || String(command.message || "").trim() !== "fixture large rpc payload") return false;
|
|
227
|
+
largeTranscriptEnabled = true;
|
|
228
|
+
respond({ ...base, data: { output: largeRpcText, tokens: { input: 123456, output: 654321 }, samples: largeTokenSamples } });
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
|
|
163
232
|
function handleVoiceScriptPrompt(command, base) {
|
|
164
233
|
if (!voiceScriptsEnabled) return false;
|
|
165
234
|
const message = String(command.message || "");
|
|
@@ -323,6 +392,7 @@ function runFastModeFixtureFlow({ barrierOnly = false } = {}) {
|
|
|
323
392
|
const finish = () => {
|
|
324
393
|
emitEvent({ type: "message_end", message: { role: "assistant", content: [{ type: "text", text: finalText }] } });
|
|
325
394
|
emitEvent({ type: "agent_end" });
|
|
395
|
+
emitEvent({ type: "agent_settled" });
|
|
326
396
|
};
|
|
327
397
|
emitEvent({ type: "agent_start" });
|
|
328
398
|
emitEvent({ type: "message_start", message: { role: "assistant" } });
|
|
@@ -353,6 +423,7 @@ function runFastModeHistoryFlow() {
|
|
|
353
423
|
}
|
|
354
424
|
emitEvent({ type: "message_end", message: { role: "assistant", content: [{ type: "text", text: accumulated }] } });
|
|
355
425
|
emitEvent({ type: "agent_end" });
|
|
426
|
+
emitEvent({ type: "agent_settled" });
|
|
356
427
|
}
|
|
357
428
|
|
|
358
429
|
function handleFastModeFixturePrompt(command, base) {
|
|
@@ -499,6 +570,7 @@ rl.on("line", (line) => {
|
|
|
499
570
|
...(Array.isArray(command.images) ? { images: command.images } : {}),
|
|
500
571
|
...(command.provider !== undefined ? { provider: String(command.provider) } : {}),
|
|
501
572
|
...(command.modelId !== undefined ? { modelId: String(command.modelId) } : {}),
|
|
573
|
+
...(type === "extension_ui_response" ? { id: String(command.id), value: command.value, cancelled: command.cancelled === true } : {}),
|
|
502
574
|
});
|
|
503
575
|
const base = { type: "response", id, command: type, success: true };
|
|
504
576
|
|
|
@@ -531,6 +603,7 @@ rl.on("line", (line) => {
|
|
|
531
603
|
{ role: "assistant", content: [{ type: "text", text: "fake answer" }], timestamp: 2000 },
|
|
532
604
|
{ role: "user", content: "fake follow-up", timestamp: 3000 },
|
|
533
605
|
...dynamicMessages,
|
|
606
|
+
...(largeTranscriptEnabled ? [{ role: "assistant", content: [{ type: "text", text: largeRpcText }], timestamp: 4000 }] : []),
|
|
534
607
|
],
|
|
535
608
|
},
|
|
536
609
|
});
|
|
@@ -573,6 +646,8 @@ rl.on("line", (line) => {
|
|
|
573
646
|
if (handleDocumentArtifactFixturePrompt(command, base)) return;
|
|
574
647
|
if (handleWorkflowFixturePrompt(command, base)) return;
|
|
575
648
|
if (handleTalkPrompt(command, base)) return;
|
|
649
|
+
if (handleContinuityPrompt(command, base)) return;
|
|
650
|
+
if (handleLargePayloadPrompt(command, base)) return;
|
|
576
651
|
if (handleVoiceScriptPrompt(command, base)) return;
|
|
577
652
|
respond({ ...base, data: { output: "fake prompt accepted" } });
|
|
578
653
|
return;
|
|
@@ -591,11 +666,20 @@ rl.on("line", (line) => {
|
|
|
591
666
|
respond({ ...base, data: { models: [{ provider: "fake", id: "fake-model", name: "Fake Model" }] } });
|
|
592
667
|
return;
|
|
593
668
|
case "get_session_stats":
|
|
594
|
-
respond({
|
|
669
|
+
respond({
|
|
670
|
+
...base,
|
|
671
|
+
data: largePayloadsEnabled
|
|
672
|
+
? { tokens: { input: 123456, output: 654321, total: 777777 }, samples: largeTokenSamples }
|
|
673
|
+
: { tokens: 0 },
|
|
674
|
+
});
|
|
595
675
|
return;
|
|
596
676
|
case "get_last_assistant_text":
|
|
597
677
|
respond({ ...base, data: { text: "fake last text" } });
|
|
598
678
|
return;
|
|
679
|
+
case "extension_ui_response":
|
|
680
|
+
// Pi's extension UI response is a one-way RPC write. Deliberately emit
|
|
681
|
+
// no response so supervised HTTP coverage catches accidental waits.
|
|
682
|
+
return;
|
|
599
683
|
case "bash": {
|
|
600
684
|
activeBash += 1;
|
|
601
685
|
peakBash = Math.max(peakBash, activeBash);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
const css = await readFile(new URL("../public/styles.css", import.meta.url), "utf8");
|
|
5
|
+
const progressOverlay = css.match(/\.footer-context-card\.has-context-usage::before\s*\{([^}]+)\}/)?.[1] ?? "";
|
|
6
|
+
|
|
7
|
+
assert.match(progressOverlay, /background:\s*var\(--context-card-gradient\)/, "context usage should retain its themed progress gradient");
|
|
8
|
+
assert.match(progressOverlay, /opacity:\s*0\.34/, "context progress should stay translucent enough for readable text");
|
|
9
|
+
|
|
10
|
+
console.log("footer context contrast static tests passed");
|