@firstpick/pi-package-webui 0.8.1 → 0.8.3
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 +21 -3
- package/bin/pi-webui.mjs +287 -32
- package/lib/component-update-state.mjs +126 -0
- package/lib/git-workflow-preferences.mjs +246 -19
- package/lib/thinking-stream-recovery.mjs +156 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/lib/ui-layout-settings.mjs +254 -0
- package/package.json +5 -3
- package/public/app.js +3072 -142
- package/public/index.html +188 -39
- package/public/service-worker.js +1 -1
- package/public/styles.css +1091 -39
- package/tests/boot-failure-diagnostics.test.mjs +63 -5
- package/tests/browser/composer-action-grid-reorder.spec.mjs +303 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
- package/tests/browser/feature-decision-output-popup.spec.mjs +156 -0
- package/tests/browser/interaction-continuity.spec.mjs +187 -0
- package/tests/browser/mobile-foundation.spec.mjs +11 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +744 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
- package/tests/browser/stats-overlay.spec.mjs +265 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/component-update-api-static.test.mjs +67 -0
- package/tests/component-update-state.test.mjs +80 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +63 -0
- package/tests/control-deck-component-updates-static.test.mjs +251 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +172 -0
- package/tests/fixtures/fake-pi.mjs +180 -6
- package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
- package/tests/git-workflow-preferences.test.mjs +4 -2
- package/tests/http-endpoints-harness.test.mjs +88 -1
- package/tests/interaction-state-stability-static.test.mjs +24 -4
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +6 -4
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +34 -16
- package/tests/native-parity-harness.test.mjs +2 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +267 -0
- package/tests/questionnaire-dialog.test.mjs +511 -0
- package/tests/queue-edit-reorder-static.test.mjs +1 -0
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +1 -0
- package/tests/side-panel-section-reorder-static.test.mjs +68 -0
- package/tests/sse-backpressure-harness.test.mjs +51 -12
- package/tests/stats-dashboard-static.test.mjs +266 -0
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/thinking-stream-recovery.test.mjs +88 -0
- package/tests/ui-layout-settings.test.mjs +92 -0
- package/tests/webui-settings-locking.test.mjs +159 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import vm from "node:vm";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const [html, css, app, server, readme] = await Promise.all([
|
|
9
|
+
readFile(join(root, "public", "index.html"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
11
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
12
|
+
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
13
|
+
readFile(join(root, "README.md"), "utf8"),
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
function functionSource(name, nextName) {
|
|
17
|
+
const start = app.indexOf(`function ${name}(`);
|
|
18
|
+
const end = app.indexOf(`\nfunction ${nextName}(`, start);
|
|
19
|
+
assert.ok(start >= 0 && end > start, `${name} should remain a standalone frontend helper`);
|
|
20
|
+
return app.slice(start, end);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const piDialog = html.match(/<dialog id="piReleaseNotesDialog"[\s\S]*?<\/dialog>/)?.[0] || "";
|
|
24
|
+
assert.match(piDialog, /aria-labelledby="piReleaseNotesTitle"/, "the Pi version tag should keep its accessible release-notes dialog");
|
|
25
|
+
assert.match(piDialog, /id="piComponentUpdateStatus"[^>]*role="status"[^>]*aria-live="polite"/, "the Pi dialog should announce component update state");
|
|
26
|
+
assert.match(piDialog, /id="piComponentUpdateButton"[^>]*>Update Pi<\/button>/, "the Pi dialog should expose a targeted update action");
|
|
27
|
+
|
|
28
|
+
const webuiDialog = html.match(/<dialog id="webuiPackageDialog"[\s\S]*?<\/dialog>/)?.[0] || "";
|
|
29
|
+
assert.match(html, /id="webuiVersionButton"[^>]*aria-haspopup="dialog"[^>]*aria-controls="webuiPackageDialog"/, "the Web UI version tag should control its dedicated package dialog");
|
|
30
|
+
assert.match(webuiDialog, /aria-labelledby="webuiPackageTitle"/, "the Web UI package dialog should have an accessible title");
|
|
31
|
+
assert.match(webuiDialog, /<dt>Installed<\/dt>[\s\S]*id="webuiPackageCurrentVersion"[\s\S]*<dt>Latest on npm<\/dt>[\s\S]*id="webuiPackageLatestVersion"/, "the Web UI dialog should show installed and latest versions");
|
|
32
|
+
assert.match(webuiDialog, /id="webuiPackageNpmButton"[^>]*>View on npm<\/button>/, "the Web UI dialog should retain the npm package action");
|
|
33
|
+
assert.match(webuiDialog, /id="webuiComponentUpdateStatus"[^>]*role="status"[^>]*aria-live="polite"/, "the Web UI dialog should announce component update state");
|
|
34
|
+
assert.match(webuiDialog, /id="webuiComponentUpdateButton"[^>]*>Update Web UI<\/button>/, "the Web UI dialog should expose a targeted update action");
|
|
35
|
+
assert.match(app, /webuiPackageNpmButton\?\.addEventListener\("click", \(\) => \{[\s\S]*confirmOpenWebuiNpmPage\(\)/, "the package dialog npm action should reuse the guarded external-link flow");
|
|
36
|
+
|
|
37
|
+
for (const state of ["available", "running", "succeeded", "failed"]) {
|
|
38
|
+
assert.match(css, new RegExp(`\\.pi-version-button\\[data-update-state="${state}"\\]::after[\\s\\S]*\\.webui-version-button\\[data-update-state="${state}"\\]::after`), `both component tags should render the ${state} indicator`);
|
|
39
|
+
}
|
|
40
|
+
assert.match(css, /prefers-reduced-motion: reduce[\s\S]*data-update-state="running"/, "the running indicator should respect reduced-motion preferences");
|
|
41
|
+
|
|
42
|
+
const renderPiVersionButtonSource = functionSource("renderPiVersionButton", "renderWebuiVersionButton");
|
|
43
|
+
const renderWebuiVersionButtonSource = functionSource("renderWebuiVersionButton", "renderWebuiDevBadge");
|
|
44
|
+
assert.match(renderPiVersionButtonSource, /componentUpdateTagState\("pi"\)[\s\S]*setAttribute\("aria-label", stateText/, "the Pi tag should use Pi-only state in its accessible name");
|
|
45
|
+
assert.match(renderWebuiVersionButtonSource, /componentUpdateTagState\("webui"\)[\s\S]*setAttribute\("aria-label", stateText/, "the Web UI tag should use Web-UI-only state in its accessible name");
|
|
46
|
+
|
|
47
|
+
const componentBlockStart = app.indexOf('const COMPONENT_UPDATE_TARGETS = ["pi", "webui"];');
|
|
48
|
+
const componentBlockEnd = app.indexOf("\nfunction initializeUpdateNotifications()", componentBlockStart);
|
|
49
|
+
assert.ok(componentBlockStart >= 0 && componentBlockEnd > componentBlockStart, "component update helpers should remain a focused frontend block");
|
|
50
|
+
const componentBlock = app.slice(componentBlockStart, componentBlockEnd);
|
|
51
|
+
|
|
52
|
+
const calls = [];
|
|
53
|
+
const events = [];
|
|
54
|
+
const scheduled = [];
|
|
55
|
+
const cleared = [];
|
|
56
|
+
const makeButton = () => ({
|
|
57
|
+
hidden: false,
|
|
58
|
+
textContent: "",
|
|
59
|
+
title: "",
|
|
60
|
+
disabled: false,
|
|
61
|
+
dataset: {},
|
|
62
|
+
attributes: {},
|
|
63
|
+
setAttribute(name, value) { this.attributes[name] = value; },
|
|
64
|
+
});
|
|
65
|
+
const makeStatus = () => ({ textContent: "", hidden: false, dataset: {} });
|
|
66
|
+
const elements = {
|
|
67
|
+
piVersionButton: makeButton(),
|
|
68
|
+
webuiVersionButton: makeButton(),
|
|
69
|
+
piComponentUpdateStatus: makeStatus(),
|
|
70
|
+
piComponentUpdateButton: makeButton(),
|
|
71
|
+
webuiComponentUpdateStatus: makeStatus(),
|
|
72
|
+
webuiComponentUpdateButton: makeButton(),
|
|
73
|
+
webuiPackageCurrentVersion: makeStatus(),
|
|
74
|
+
webuiPackageLatestVersion: makeStatus(),
|
|
75
|
+
webuiPackageDialog: { open: false, showModal() { this.open = true; } },
|
|
76
|
+
};
|
|
77
|
+
let nextTimer = 1;
|
|
78
|
+
let refreshShouldFail = false;
|
|
79
|
+
const context = {
|
|
80
|
+
elements,
|
|
81
|
+
console,
|
|
82
|
+
setTimeout(callback, delay) {
|
|
83
|
+
const id = nextTimer++;
|
|
84
|
+
scheduled.push({ id, callback, delay });
|
|
85
|
+
return id;
|
|
86
|
+
},
|
|
87
|
+
clearTimeout(id) { cleared.push(id); },
|
|
88
|
+
formatWebuiVersion(value) {
|
|
89
|
+
const text = String(value || "").trim();
|
|
90
|
+
return text ? (text.startsWith("v") ? text : `v${text}`) : "";
|
|
91
|
+
},
|
|
92
|
+
packageUpdateText(label, status = {}) {
|
|
93
|
+
return `${label} ${status.currentVersion || ""} → ${status.latestVersion || ""}`.trim();
|
|
94
|
+
},
|
|
95
|
+
appConfirmText: async (_message, options) => {
|
|
96
|
+
calls.push({ kind: "confirm", options });
|
|
97
|
+
return true;
|
|
98
|
+
},
|
|
99
|
+
api: async (path, options) => {
|
|
100
|
+
calls.push({ kind: "api", path, options });
|
|
101
|
+
return { data: { target: options.body.target, state: "running", canStart: false, message: "Update is running." } };
|
|
102
|
+
},
|
|
103
|
+
addEvent(message, level) { events.push({ message, level }); },
|
|
104
|
+
refreshUpdateStatus: async () => {
|
|
105
|
+
if (refreshShouldFail) throw new Error("temporary status failure");
|
|
106
|
+
return null;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
vm.runInNewContext(`
|
|
110
|
+
let latestUpdateStatus = null;
|
|
111
|
+
let piVersion = "0.83.0";
|
|
112
|
+
let webuiVersion = "0.8.1";
|
|
113
|
+
let componentUpdatePollTimer = null;
|
|
114
|
+
let componentUpdateStartInProgress = false;
|
|
115
|
+
let updateRequestInProgress = false;
|
|
116
|
+
const COMPONENT_UPDATE_POLL_MS = 1000;
|
|
117
|
+
${renderPiVersionButtonSource}
|
|
118
|
+
${renderWebuiVersionButtonSource}
|
|
119
|
+
${componentBlock}
|
|
120
|
+
globalThis.componentHarness = {
|
|
121
|
+
setStatus(value) { latestUpdateStatus = value; },
|
|
122
|
+
getStatus() { return latestUpdateStatus; },
|
|
123
|
+
tagState: componentUpdateTagState,
|
|
124
|
+
statusText: componentUpdateStatusText,
|
|
125
|
+
buttonState: componentUpdateButtonState,
|
|
126
|
+
renderIndicators: renderComponentUpdateIndicators,
|
|
127
|
+
renderDialogs: renderComponentUpdateDialogs,
|
|
128
|
+
syncPolling: syncComponentUpdatePolling,
|
|
129
|
+
pollTimer() { return componentUpdatePollTimer; },
|
|
130
|
+
start: startComponentUpdate,
|
|
131
|
+
};
|
|
132
|
+
`, context);
|
|
133
|
+
const harness = context.componentHarness;
|
|
134
|
+
|
|
135
|
+
harness.setStatus({
|
|
136
|
+
updateInProgress: false,
|
|
137
|
+
pi: { currentVersion: "0.83.0", latestVersion: "0.84.0", updateAvailable: true },
|
|
138
|
+
webui: { currentVersion: "0.8.1", latestVersion: "0.8.1", updateAvailable: false, checked: true },
|
|
139
|
+
componentUpdates: {
|
|
140
|
+
pi: { target: "pi", state: "idle", canStart: true },
|
|
141
|
+
webui: { target: "webui", state: "idle", canStart: true },
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
harness.renderIndicators();
|
|
145
|
+
assert.equal(elements.piVersionButton.dataset.updateState, "available", "Pi availability should mark only the Pi tag");
|
|
146
|
+
assert.equal(elements.piVersionButton.attributes["aria-label"], "View Pi v0.83.0 release notes, update available", "Pi availability should be present in the accessible name");
|
|
147
|
+
assert.equal(elements.webuiVersionButton.dataset.updateState, undefined, "Pi availability should not mark the Web UI tag");
|
|
148
|
+
assert.doesNotMatch(elements.webuiVersionButton.attributes["aria-label"], /update available/, "Pi availability should not leak into the Web UI accessible name");
|
|
149
|
+
|
|
150
|
+
harness.setStatus({
|
|
151
|
+
updateInProgress: false,
|
|
152
|
+
pi: { updateAvailable: true },
|
|
153
|
+
webui: { updateAvailable: true },
|
|
154
|
+
componentUpdates: {
|
|
155
|
+
pi: { state: "succeeded", canStart: true, message: "Pi update completed." },
|
|
156
|
+
webui: { state: "failed", canStart: true, message: "Web UI update failed.", error: "bounded failure" },
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
assert.equal(harness.tagState("pi"), "succeeded", "terminal Pi success should outrank stale availability");
|
|
160
|
+
assert.equal(harness.tagState("webui"), "failed", "terminal Web UI failure should outrank stale availability");
|
|
161
|
+
assert.match(harness.statusText("pi").text, /New or reloaded Pi sessions use the update; already-running tabs keep their current runtime/, "Pi success should explain activation without interrupting active tabs");
|
|
162
|
+
assert.match(harness.statusText("webui").text, /bounded failure[\s\S]*retry the update/, "Web UI failure should remain visible and permit retry");
|
|
163
|
+
assert.equal(harness.buttonState("webui").label, "Retry Web UI update", "a failed Web UI update should expose retry");
|
|
164
|
+
assert.equal(harness.buttonState("webui").disabled, false, "retry should be enabled when no update is running");
|
|
165
|
+
|
|
166
|
+
harness.setStatus({
|
|
167
|
+
updateInProgress: false,
|
|
168
|
+
webui: { currentVersion: "0.8.1", latestVersion: "0.8.2", updateAvailable: true },
|
|
169
|
+
componentUpdates: {
|
|
170
|
+
pi: { state: "idle", canStart: true },
|
|
171
|
+
webui: { state: "idle", canStart: false, unavailableReason: "Automatic Web UI update is unavailable from a source or development checkout." },
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
assert.equal(harness.buttonState("webui").disabled, true, "source/development Web UI self-update should be disabled");
|
|
175
|
+
assert.match(harness.statusText("webui").text, /source or development checkout/, "source/development refusal should be explained in the live status");
|
|
176
|
+
|
|
177
|
+
harness.setStatus({
|
|
178
|
+
updateInProgress: true,
|
|
179
|
+
pi: { updateAvailable: true },
|
|
180
|
+
webui: { updateAvailable: true },
|
|
181
|
+
componentUpdates: {
|
|
182
|
+
pi: { state: "running", canStart: false, message: "Updating Pi…" },
|
|
183
|
+
webui: { state: "idle", canStart: false },
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
assert.equal(harness.buttonState("pi").disabled, true, "the running target should reject duplicate starts");
|
|
187
|
+
assert.equal(harness.buttonState("webui").disabled, true, "a running Pi update should disable the conflicting Web UI start");
|
|
188
|
+
harness.syncPolling();
|
|
189
|
+
assert.equal(scheduled.length, 1, "a running update should create one short polling timer");
|
|
190
|
+
assert.equal(scheduled[0].delay, 1000, "running status should poll at the bounded one-second interval");
|
|
191
|
+
harness.syncPolling();
|
|
192
|
+
assert.equal(scheduled.length, 1, "re-rendering while running should not create duplicate poll timers");
|
|
193
|
+
refreshShouldFail = true;
|
|
194
|
+
scheduled[0].callback();
|
|
195
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
196
|
+
assert.equal(scheduled.length, 2, "a transient status failure should re-arm polling while the last known job remains running");
|
|
197
|
+
assert.match(events.at(-1)?.message || "", /status check failed/i, "a transient polling failure should remain visible in the event log");
|
|
198
|
+
refreshShouldFail = false;
|
|
199
|
+
const rearmedTimer = harness.pollTimer();
|
|
200
|
+
harness.setStatus({
|
|
201
|
+
updateInProgress: false,
|
|
202
|
+
componentUpdates: {
|
|
203
|
+
pi: { state: "succeeded", canStart: true },
|
|
204
|
+
webui: { state: "idle", canStart: true },
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
harness.syncPolling();
|
|
208
|
+
assert.deepEqual(cleared, [rearmedTimer], "terminal state should clear the re-armed running poll");
|
|
209
|
+
assert.equal(harness.pollTimer(), null, "terminal state should release the polling timer reference");
|
|
210
|
+
|
|
211
|
+
calls.length = 0;
|
|
212
|
+
harness.setStatus({
|
|
213
|
+
updateInProgress: false,
|
|
214
|
+
pi: { currentVersion: "0.83.0", latestVersion: "0.84.0", updateAvailable: true },
|
|
215
|
+
webui: { updateAvailable: false },
|
|
216
|
+
componentUpdates: {
|
|
217
|
+
pi: { state: "idle", canStart: true },
|
|
218
|
+
webui: { state: "idle", canStart: true },
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
await harness.start("pi");
|
|
222
|
+
const piStartCall = calls.find((call) => call.kind === "api");
|
|
223
|
+
assert.equal(piStartCall?.path, "/api/component-update", "the Pi dialog should use the component-update endpoint");
|
|
224
|
+
assert.equal(piStartCall?.options.method, "POST", "component update starts should use POST");
|
|
225
|
+
assert.equal(piStartCall?.options.scoped, false, "component update starts should not inherit a Pi tab scope");
|
|
226
|
+
assert.equal(JSON.stringify(piStartCall?.options.body), '{"target":"pi"}', "the Pi dialog should send only the exact Pi target");
|
|
227
|
+
assert.equal(harness.getStatus().componentUpdates.pi.state, "running", "the accepted 202-shaped state should render immediately as running");
|
|
228
|
+
assert.equal(harness.buttonState("pi").disabled, true, "the accepted job should immediately disable duplicate starts");
|
|
229
|
+
assert.match(componentBlock, /statusElement\.hidden = false;[\s\S]*statusElement\.textContent = text;/, "component live regions should remain rendered before their status text changes");
|
|
230
|
+
assert.match(app, /openPiReleaseNotes\(\)[\s\S]*refreshUpdateStatus\(\{ notify: false \}\)/, "opening Pi details should refresh component status even when cached state exists");
|
|
231
|
+
|
|
232
|
+
assert.match(
|
|
233
|
+
server,
|
|
234
|
+
/url\.pathname === "\/api\/component-update" && req\.method === "POST"[\s\S]*requireLocalhostRoute\(req, url\.pathname\)[\s\S]*validateComponentUpdateRequest\(body\)[\s\S]*sendJson\(res, 202/,
|
|
235
|
+
"the server should keep exact validation, localhost restriction, and 202 acceptance for component starts",
|
|
236
|
+
);
|
|
237
|
+
assert.match(
|
|
238
|
+
app,
|
|
239
|
+
/async function runPiUpdateAndRestart\([\s\S]*api\(all \? "\/api\/update\?all=1" : "\/api\/update", \{ method: "POST", scoped: false \}\)[\s\S]*waitForServerRestart\(\)/,
|
|
240
|
+
"the legacy browser update-and-restart flow should remain compatible",
|
|
241
|
+
);
|
|
242
|
+
assert.match(
|
|
243
|
+
server,
|
|
244
|
+
/url\.pathname === "\/api\/update" && req\.method === "POST"[\s\S]*runPiUpdateAndPrepareRestart\(\{ all: queryAll \|\| bodyAll \}\)[\s\S]*sendJson\(res, 200[\s\S]*shutdown\("api update", \{ preserveSessions: true \}\)/,
|
|
245
|
+
"the legacy server route should retain update-all selection, completion response, restart, and managed-session preservation",
|
|
246
|
+
);
|
|
247
|
+
assert.match(readme, /Control Deck component updates[\s\S]*component-specific `available`, `running`, `succeeded`, or `failed` status/, "README should explain the component-specific tag indicators");
|
|
248
|
+
assert.match(readme, /Update Pi[\s\S]*does not restart the Web UI or interrupt managed Pi tabs[\s\S]*Update Web UI[\s\S]*restart the Web UI after success/, "README should explain Pi and Web UI activation behavior");
|
|
249
|
+
assert.match(readme, /only from localhost[\s\S]*disabled for source\/development checkouts[\s\S]*verify the installed version before retrying[\s\S]*broader legacy behavior/, "README should document security, source refusal, recovery, and legacy compatibility");
|
|
250
|
+
|
|
251
|
+
console.log("control deck component update static tests passed");
|
|
@@ -123,7 +123,7 @@ assert.match(styles, /\.compact-tool-shell \.compact-tool-status\s*\{[\s\S]*?dis
|
|
|
123
123
|
assert.match(styles, /\.compact-tool-shell\.tool-running \.compact-tool-status[\s\S]*?\.compact-tool-shell\.tool-success \.compact-tool-status[\s\S]*?\.compact-tool-shell\.tool-error \.compact-tool-status/, "running, success, and failure tool states should have distinct visual tones");
|
|
124
124
|
assert.match(compactUpdate, /compactLiveState = reduced\.state;\s+clearCompactToolShells\(\)/, "new assistant or tool-call deltas should clear the preceding transient tool shell");
|
|
125
125
|
assert.match(compactLiveStreamActive, /messageOutputActive = streamMessageActive && Boolean\([\s\S]*?compactLiveState\.text[\s\S]*?compactLiveState\.thinking[\s\S]*?compactOutputActive\(\) && currentState\?\.isStreaming === true && Boolean\(compactToolShells\.size \|\| messageOutputActive\)/, "mid-stream reconciliation should preserve active compact message output or a current tool shell, but not completed final text");
|
|
126
|
-
assert.match(restoreCompactStream, /compactTextBubble = null[\s\S]*?compactThinkingBubble = null[\s\S]*?if \(streamMessageActive\) flushCompactLiveOutput\(\)[\s\S]*?compactToolShells\.values\(\)[\s\S]*?appendChatMessageBubble\(shell\.bubble\)/, "compact message state should be restored only while its message is active, while the current shell
|
|
126
|
+
assert.match(restoreCompactStream, /compactTextBubble = null[\s\S]*?compactThinkingBubble = null[\s\S]*?if \(streamMessageActive\) flushCompactLiveOutput\(\)[\s\S]*?compactToolShells\.values\(\)[\s\S]*?appendChatMessageBubble\(shell\.bubble, \{ liveTail: true \}\)/, "compact message state should be restored only while its message is active, while the current shell survives in chronological live-tail order between messages");
|
|
127
127
|
assert.match(refreshMessages, /preserveCompactStream = compactLiveStreamRenderActive\(\)[\s\S]*?!preserveCompactStream && !preserveNormalStream[\s\S]*?renderMessages\(latestMessages\)[\s\S]*?preserveCompactStream\) restoreCompactLiveOutputAfterChatRebuild\(\)/, "message refreshes must not reset active compact output before rebuilding the transcript");
|
|
128
128
|
|
|
129
129
|
assert.match(app, /const SETTINGS_OUTPUT_MODE_OPTIONS = \[[\s\S]*?value: "normal"[\s\S]*?value: "compact-v1"/, "settings should offer normal and compact-v1 server defaults");
|
|
@@ -155,7 +155,7 @@ assert.match(worker, /pi-webui-pwa-v\d+[\s\S]*?"\/fast-output-live\.mjs"/, "PWA
|
|
|
155
155
|
assert.match(html, /<label for="fastOutputModeSelect">Compact mode \(Experimental\)<\/label>/, "the sidebar should mark compact mode as experimental");
|
|
156
156
|
assert.match(html, /Lightweight browser rendering; Markdown final output; live thinking expanded; stored thinking grouped and collapsed/, "the sidebar should distinguish compact rendering from model inference");
|
|
157
157
|
// Intent preserved: the guarded PWA entry point must advance whenever app wiring changes.
|
|
158
|
-
assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=
|
|
158
|
+
assert.match(html, /id="webuiBootLoader"[^>]*data-app-src="\/app\.js\?v=112"/, "the guarded PWA entry point should cache-bust browser wiring");
|
|
159
159
|
assert.match(JSON.parse(packageRaw).scripts.check, /node --check public\/fast-output-live\.mjs/, "package checks should parse the compact helper");
|
|
160
160
|
|
|
161
161
|
const events = createFastModeOutputEvents();
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import vm from "node:vm";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const [html, app, css] = await Promise.all([
|
|
9
|
+
readFile(join(root, "public", "index.html"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
11
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function functionSource(name) {
|
|
15
|
+
const start = app.indexOf(`function ${name}(`);
|
|
16
|
+
assert.ok(start >= 0, `${name} should exist`);
|
|
17
|
+
const next = app.slice(start + 1).match(/\nfunction [A-Za-z0-9_$]+\(/);
|
|
18
|
+
const end = next ? start + 1 + next.index : app.length;
|
|
19
|
+
return app.slice(start, end);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
assert.match(
|
|
23
|
+
html,
|
|
24
|
+
/<button id="featureCategoryTag"[^>]*type="button"[^>]*aria-haspopup="dialog"[^>]*aria-controls="featureDecisionDialog"[^>]*disabled hidden><\/button>/,
|
|
25
|
+
"the category tag should be a native dialog-triggering button and remain unavailable until exact output arrives",
|
|
26
|
+
);
|
|
27
|
+
assert.match(
|
|
28
|
+
html,
|
|
29
|
+
/<dialog id="featureDecisionDialog" class="extension-dialog feature-decision-dialog" aria-labelledby="featureDecisionDialogTitle">[\s\S]*<h2 id="featureDecisionDialogTitle">Classifier output<\/h2>[\s\S]*<pre id="featureDecisionDialogOutput"[\s\S]*<button id="featureDecisionDialogCloseButton" type="submit" value="close">Close<\/button>/,
|
|
30
|
+
"the popup should use a labelled native dialog, plain-text output container, and explicit close control",
|
|
31
|
+
);
|
|
32
|
+
assert.match(html, /<form method="dialog">[\s\S]*id="featureDecisionDialogCloseButton"/, "the popup close button should use native dialog close semantics");
|
|
33
|
+
assert.doesNotMatch(app, /featureDecisionDialog\?\.addEventListener\("cancel"/, "Escape should retain native dialog cancellation behavior");
|
|
34
|
+
assert.match(css, /\.composer-feature-category-tag:hover:not\(:disabled\),\s*\.composer-feature-category-tag:focus-visible/, "the category button should expose hover and keyboard focus styling");
|
|
35
|
+
assert.match(css, /\.feature-decision-dialog-output \{[\s\S]*white-space:\s*pre-wrap;/, "exact output should render as wrapping preformatted plain text");
|
|
36
|
+
|
|
37
|
+
assert.match(app, /const FEATURE_DECISION_OUTPUT_STATUS_KEY = "feature-decision-output";/, "the consumer should use the approved dedicated status key");
|
|
38
|
+
assert.match(app, /const featureCategoryByTab = new Map\(\);\s*const featureDecisionOutputByTab = new Map\(\);/, "category and decision output should remain isolated in separate per-tab maps");
|
|
39
|
+
assert.match(app, /const FEATURE_DECISION_PAYLOAD_MAX_CHARS = \d+;/, "the consumer should bound the accepted status payload size");
|
|
40
|
+
assert.match(app, /const FEATURE_DECISION_REASON_MAX_CHARS = \d+;/, "the consumer should bound the rendered classifier reason");
|
|
41
|
+
|
|
42
|
+
const context = vm.createContext({ Map, JSON });
|
|
43
|
+
vm.runInContext(`
|
|
44
|
+
const FEATURE_DECISION_PAYLOAD_MAX_CHARS = ${/const FEATURE_DECISION_PAYLOAD_MAX_CHARS = (\d+);/.exec(app)[1]};
|
|
45
|
+
const FEATURE_DECISION_REASON_MAX_CHARS = ${/const FEATURE_DECISION_REASON_MAX_CHARS = (\d+);/.exec(app)[1]};
|
|
46
|
+
${functionSource("normalizeFeatureCategory")}
|
|
47
|
+
${functionSource("normalizeFeatureDecisionKind")}
|
|
48
|
+
${functionSource("normalizeFeatureDecisionReason")}
|
|
49
|
+
${functionSource("parseFeatureDecisionPayload")}
|
|
50
|
+
${functionSource("featureDecisionKindLabel")}
|
|
51
|
+
${functionSource("formatFeatureDecisionText")}
|
|
52
|
+
const featureCategoryByTab = new Map();
|
|
53
|
+
const featureDecisionOutputByTab = new Map();
|
|
54
|
+
${functionSource("featureDecisionForTab")}
|
|
55
|
+
${functionSource("featureDecisionOutputForTab")}
|
|
56
|
+
`, context);
|
|
57
|
+
assert.equal(context.normalizeFeatureCategory("lightweight-feature"), "lightweight-feature");
|
|
58
|
+
assert.equal(context.normalizeFeatureCategory("complex-feature"), "complex-feature");
|
|
59
|
+
assert.equal(context.normalizeFeatureCategory(" lightweight-feature"), "", "category validation must not trim payloads");
|
|
60
|
+
assert.equal(context.normalizeFeatureDecisionKind("feature_lightweight"), "feature_lightweight");
|
|
61
|
+
assert.equal(context.normalizeFeatureDecisionKind("feature_complex"), "feature_complex");
|
|
62
|
+
for (const invalid of ["feature_lightweight\n", "feature-lightweight", "lightweight-feature", "", null, undefined]) {
|
|
63
|
+
assert.equal(context.normalizeFeatureDecisionKind(invalid), "", `decision kind should reject ${String(invalid)}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The parser runs inside the sandbox realm, so compare plain field copies rather than prototypes.
|
|
67
|
+
function parsePayload(payload) {
|
|
68
|
+
const decision = context.parseFeatureDecisionPayload(payload);
|
|
69
|
+
return decision ? { kind: decision.kind, reason: decision.reason } : decision;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
assert.deepEqual(
|
|
73
|
+
parsePayload(JSON.stringify({ kind: "feature_complex", reason: "Crosses two packages." })),
|
|
74
|
+
{ kind: "feature_complex", reason: "Crosses two packages." },
|
|
75
|
+
"the structured classifier payload should be accepted",
|
|
76
|
+
);
|
|
77
|
+
assert.deepEqual(
|
|
78
|
+
parsePayload(JSON.stringify({ reason: " Collapses\n\tuntrusted\u0007 whitespace and \u202espoofed direction. ", kind: "feature_lightweight" })),
|
|
79
|
+
{ kind: "feature_lightweight", reason: "Collapses untrusted whitespace and spoofed direction." },
|
|
80
|
+
"reason text should strip control and bidi formatting characters and collapse whitespace regardless of key order",
|
|
81
|
+
);
|
|
82
|
+
assert.deepEqual(
|
|
83
|
+
parsePayload("feature_complex"),
|
|
84
|
+
{ kind: "feature_complex", reason: "" },
|
|
85
|
+
"the legacy exact label should stay accepted for rolling compatibility",
|
|
86
|
+
);
|
|
87
|
+
assert.equal(
|
|
88
|
+
parsePayload(JSON.stringify({ kind: "feature_complex", reason: "x".repeat(900) }))?.reason.length,
|
|
89
|
+
500,
|
|
90
|
+
"an oversized reason should be bounded rather than rendered in full",
|
|
91
|
+
);
|
|
92
|
+
for (const invalid of [
|
|
93
|
+
undefined,
|
|
94
|
+
null,
|
|
95
|
+
42,
|
|
96
|
+
"",
|
|
97
|
+
"feature-lightweight",
|
|
98
|
+
"lightweight-feature",
|
|
99
|
+
'["feature_complex","reason"]',
|
|
100
|
+
"{not json",
|
|
101
|
+
JSON.stringify({ kind: "feature_complex" }),
|
|
102
|
+
JSON.stringify({ kind: "feature_complex", reason: "" }),
|
|
103
|
+
JSON.stringify({ kind: "feature_complex", reason: " " }),
|
|
104
|
+
JSON.stringify({ kind: "feature_complex", reason: 7 }),
|
|
105
|
+
JSON.stringify({ kind: "bug", reason: "Restores documented behavior." }),
|
|
106
|
+
JSON.stringify({ kind: "feature_complex", reason: "Extra fields are rejected.", extra: true }),
|
|
107
|
+
JSON.stringify({ kind: "feature_complex", reason: "y".repeat(6000) }),
|
|
108
|
+
]) {
|
|
109
|
+
assert.equal(parsePayload(invalid), null, `payload should fail closed: ${String(invalid).slice(0, 60)}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
assert.equal(
|
|
113
|
+
context.formatFeatureDecisionText({ kind: "feature_complex", reason: "Crosses two packages." }),
|
|
114
|
+
"Decision: Complex feature (feature_complex)\nReason: Crosses two packages.",
|
|
115
|
+
"the dialog text should read as a decision plus reason, not only the machine label",
|
|
116
|
+
);
|
|
117
|
+
assert.equal(
|
|
118
|
+
context.formatFeatureDecisionText({ kind: "feature_lightweight", reason: "" }),
|
|
119
|
+
"Decision: Lightweight feature (feature_lightweight)\nReason: The classifier reported feature_lightweight without a reason.",
|
|
120
|
+
"a legacy label should render a deterministic readable fallback reason",
|
|
121
|
+
);
|
|
122
|
+
assert.equal(context.formatFeatureDecisionText(null), "", "absent decisions should render no dialog text");
|
|
123
|
+
|
|
124
|
+
vm.runInContext(`
|
|
125
|
+
featureCategoryByTab.set("light", "lightweight-feature");
|
|
126
|
+
featureDecisionOutputByTab.set("light", { kind: "feature_lightweight", reason: "One localized slice." });
|
|
127
|
+
featureCategoryByTab.set("complex", "complex-feature");
|
|
128
|
+
featureDecisionOutputByTab.set("complex", { kind: "feature_complex", reason: "Crosses two packages." });
|
|
129
|
+
featureCategoryByTab.set("legacy", "complex-feature");
|
|
130
|
+
featureDecisionOutputByTab.set("legacy", { kind: "feature_complex", reason: "" });
|
|
131
|
+
featureCategoryByTab.set("mismatch", "complex-feature");
|
|
132
|
+
featureDecisionOutputByTab.set("mismatch", { kind: "feature_lightweight", reason: "One localized slice." });
|
|
133
|
+
`, context);
|
|
134
|
+
assert.equal(
|
|
135
|
+
context.featureDecisionOutputForTab("light"),
|
|
136
|
+
"Decision: Lightweight feature (feature_lightweight)\nReason: One localized slice.",
|
|
137
|
+
"lightweight output should stay readable and tab-scoped",
|
|
138
|
+
);
|
|
139
|
+
assert.equal(
|
|
140
|
+
context.featureDecisionOutputForTab("complex"),
|
|
141
|
+
"Decision: Complex feature (feature_complex)\nReason: Crosses two packages.",
|
|
142
|
+
"complex output should stay readable and tab-scoped",
|
|
143
|
+
);
|
|
144
|
+
assert.equal(
|
|
145
|
+
context.featureDecisionOutputForTab("legacy"),
|
|
146
|
+
"Decision: Complex feature (feature_complex)\nReason: The classifier reported feature_complex without a reason.",
|
|
147
|
+
"legacy exact-label state should render the deterministic fallback reason",
|
|
148
|
+
);
|
|
149
|
+
assert.equal(context.featureDecisionOutputForTab("mismatch"), "", "a category/decision mismatch must not open a popup");
|
|
150
|
+
assert.equal(context.featureDecisionOutputForTab("missing"), "", "a tab must not inherit another tab's decision");
|
|
151
|
+
|
|
152
|
+
const openSource = functionSource("openFeatureDecisionDialog");
|
|
153
|
+
assert.match(openSource, /const tabId = activeTabId;[\s\S]*featureDecisionOutputForTab\(tabId\)[\s\S]*textContent = output;[\s\S]*dialog\.showModal\(\)/, "popup opening should resolve and render only the active tab's exact output");
|
|
154
|
+
assert.doesNotMatch(app, /featureDecisionDialogOutput\.innerHTML/, "classifier reason text must never reach innerHTML");
|
|
155
|
+
assert.match(functionSource("handleFeatureDecisionOutputStatus"), /parseFeatureDecisionPayload\(statusText\)[\s\S]*featureDecisionOutputByTab\.set\(tabId, decision\);\s*else featureDecisionOutputByTab\.delete\(tabId\)/, "status handling should store only parsed decisions and drop rejected payloads");
|
|
156
|
+
assert.match(openSource, /featureDecisionDialogCloseButton\?\.focus/, "popup opening should place focus on its explicit close control");
|
|
157
|
+
assert.match(app, /elements\.featureCategoryTag\?\.addEventListener\("click", openFeatureDecisionDialog\)/, "native click and keyboard button activation should open the popup");
|
|
158
|
+
assert.match(app, /function installDialogModalPrimitive\(dialog\)[\s\S]*trigger\.focus\(\{ preventScroll: true \}\)/, "native dialog close should return focus to the triggering category button");
|
|
159
|
+
|
|
160
|
+
const clearSource = functionSource("clearFeatureDecisionStateForTab");
|
|
161
|
+
assert.match(clearSource, /featureCategoryByTab\.delete\(tabId\);\s*featureDecisionOutputByTab\.delete\(tabId\);[\s\S]*closeFeatureDecisionDialog\(\{ restoreFocus: false \}\)/, "lifecycle cleanup should clear both maps and close the affected popup");
|
|
162
|
+
assert.match(functionSource("handleFeatureCategoryStatus"), /else clearFeatureDecisionStateForTab\(tabId\)/, "clearing or rejecting a category should defensively clear exact output");
|
|
163
|
+
assert.match(functionSource("setActiveTabId"), /nextTabId !== activeTabId[\s\S]*closeFeatureDecisionDialog\(\{ restoreFocus: false \}\)/, "switching tabs should close the prior tab popup");
|
|
164
|
+
assert.match(functionSource("syncTabMetadata"), /clearFeatureDecisionStateForTab\(tabId\)/, "closed-tab metadata cleanup should remove decision state");
|
|
165
|
+
assert.match(functionSource("closeTerminalTabs"), /clearFeatureDecisionStateForTab\(id\)/, "explicit tab closure should remove decision state");
|
|
166
|
+
assert.match(app, /case "webui_connected":[\s\S]*clearFeatureDecisionStateForTab\(connectedTabId, \{ render: true \}\)[\s\S]*scheduleForegroundReconcile\("event stream reconnect", 0\)/, "reconnect should clear local state before authoritative replay");
|
|
167
|
+
assert.match(app, /statusKey === FEATURE_DECISION_OUTPUT_STATUS_KEY[\s\S]*handleFeatureDecisionOutputStatus[\s\S]*return;[\s\S]*statusKey === FEATURE_CATEGORY_STATUS_KEY[\s\S]*return;[\s\S]*statusEntries\.set/, "both feature statuses should be intercepted before generic footer storage while preserving category handling");
|
|
168
|
+
|
|
169
|
+
assert.match(html, /\/styles\.css\?v=98/, "integrated stylesheet changes should advance the cache query");
|
|
170
|
+
assert.match(html, /\/app\.js\?v=112/, "integrated app changes should advance the cache query");
|
|
171
|
+
|
|
172
|
+
console.log("feature decision-output popup static checks passed");
|