@firstpick/pi-package-webui 0.8.0 → 0.8.1
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 +22 -5
- package/bin/pi-webui.mjs +434 -100
- package/lib/npm-command.mjs +81 -0
- package/lib/queue-mutation.mjs +6 -0
- package/lib/workspace-files-live-watcher.mjs +138 -0
- package/package.json +8 -3
- package/public/app.js +2816 -314
- package/public/index.html +112 -27
- package/public/mobile-shell-state.mjs +166 -0
- package/public/service-worker.js +60 -13
- package/public/styles.css +1049 -371
- package/public/subagent-gate-visibility.mjs +16 -0
- package/public/subagent-launch-slot-state.mjs +16 -0
- package/public/transcript-renderer.mjs +433 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +739 -0
- package/tests/browser/mobile-foundation.spec.mjs +352 -0
- package/tests/browser/optimistic-prompt.spec.mjs +130 -0
- package/tests/chat-scroll-intent-static.test.mjs +6 -1
- package/tests/codex-fast-mode-static.test.mjs +8 -5
- package/tests/compact-sections-static.test.mjs +20 -2
- package/tests/compaction-mutation-contract.test.mjs +18 -4
- package/tests/compaction-static.test.mjs +1 -0
- package/tests/completion-signal-contract.test.mjs +13 -2
- package/tests/fast-mode-client-static.test.mjs +7 -4
- package/tests/fixtures/fake-pi.mjs +181 -2
- package/tests/git-panel-gitignore-static.test.mjs +104 -0
- package/tests/http-endpoints-harness.test.mjs +228 -2
- package/tests/interaction-state-stability-static.test.mjs +254 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
- package/tests/mobile-foundation-static.test.mjs +69 -0
- package/tests/mobile-phone-experience-static.test.mjs +65 -0
- package/tests/mobile-shell-state.test.mjs +69 -0
- package/tests/mobile-static.test.mjs +244 -38
- package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
- package/tests/npm-command.test.mjs +64 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -1
- package/tests/queue-edit-reorder-static.test.mjs +9 -1
- package/tests/queue-mutation-contract.test.mjs +22 -0
- package/tests/service-worker-lifecycle.test.mjs +120 -0
- package/tests/sse-backpressure-harness.test.mjs +98 -0
- package/tests/streaming-ui-coupling.test.mjs +7 -1
- package/tests/subagent-gate-visibility.test.mjs +18 -2
- package/tests/subagent-launch-slot-state.test.mjs +32 -0
- package/tests/subagent-launch-slots-static.test.mjs +8 -2
- package/tests/subagents-helper.test.mjs +90 -0
- package/tests/terminal-tab-workspace-static.test.mjs +1 -1
- package/tests/update-commands.test.mjs +4 -0
- package/tests/workspace-files-live-updates-static.test.mjs +76 -0
- package/tests/workspace-files-live-watcher.test.mjs +95 -0
- package/webui-rpc-helper.mjs +175 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
8
|
+
const TAB_COUNT = 10;
|
|
9
|
+
const MESSAGES_PER_TAB = 30;
|
|
10
|
+
const TOOL_OUTPUT_BYTES = 128 * 1024;
|
|
11
|
+
const DEFER_NO_GO_BYTES = 32 * 1024 * 1024;
|
|
12
|
+
|
|
13
|
+
// This matches the current cache's retained shape: a complete messages array
|
|
14
|
+
// per open tab. Use unique tool output per message so JavaScript cannot hide
|
|
15
|
+
// the multi-tab payload behind one shared string reference.
|
|
16
|
+
const cache = new Map();
|
|
17
|
+
const heapBefore = process.memoryUsage().heapUsed;
|
|
18
|
+
for (let tabIndex = 0; tabIndex < TAB_COUNT; tabIndex += 1) {
|
|
19
|
+
const messages = Array.from({ length: MESSAGES_PER_TAB }, (_, messageIndex) => ({
|
|
20
|
+
role: "toolExecution",
|
|
21
|
+
toolName: "fixture-tool",
|
|
22
|
+
result: `${tabIndex}:${messageIndex}:${"x".repeat(TOOL_OUTPUT_BYTES - 32)}`,
|
|
23
|
+
}));
|
|
24
|
+
cache.set(`tab-${tabIndex}`, { messages, sessionKey: `tab-${tabIndex}|fixture-session` });
|
|
25
|
+
}
|
|
26
|
+
const retainedBytes = Buffer.byteLength(JSON.stringify([...cache.values()].flatMap((entry) => entry.messages)));
|
|
27
|
+
const heapDelta = Math.max(0, process.memoryUsage().heapUsed - heapBefore);
|
|
28
|
+
|
|
29
|
+
assert.match(app, /const tabMessagesCache = new Map\(\)/, "the characterization must cover the real per-tab cache");
|
|
30
|
+
assert.match(app, /function cacheMessagesForTab[\s\S]*?tabMessagesCache\.set\(tabId, \{ messages, sessionKey: resolvedSessionKey \}\)/, "the current cache retains complete message arrays by tab");
|
|
31
|
+
assert.ok(retainedBytes >= DEFER_NO_GO_BYTES, "the 10-tab long-tool fixture must cross the documented defer/no-go threshold");
|
|
32
|
+
assert.equal(cache.size, TAB_COUNT);
|
|
33
|
+
|
|
34
|
+
console.log(`mobile transcript characterization: ${TAB_COUNT} tabs × ${MESSAGES_PER_TAB} long tool messages retained ${Math.round(retainedBytes / (1024 * 1024))} MiB serialized; heap delta ${Math.round(heapDelta / (1024 * 1024))} MiB. Defer in-memory bounding until it preserves every authoritative final answer and transcript; ${DEFER_NO_GO_BYTES / (1024 * 1024)} MiB retained serialized payload is the follow-up threshold.`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { resolveNpmCommandInvocation } from "../lib/npm-command.mjs";
|
|
3
|
+
import { prependPathDirectory, prependedPathEnvironment, resolveCommandDirectory, resolveNpmCommandInvocation, resolvePiCommandInvocation } from "../lib/npm-command.mjs";
|
|
4
4
|
|
|
5
5
|
const windowsExecPath = "C:\\PortableNode\\node.exe";
|
|
6
6
|
const bundledCli = "C:\\PortableNode\\node_modules\\npm\\bin\\npm-cli.js";
|
|
@@ -26,12 +26,75 @@ const fromPath = resolveNpmCommandInvocation(["root", "-g"], {
|
|
|
26
26
|
});
|
|
27
27
|
assert.deepEqual(fromPath.args, [pathCli, "root", "-g"], "Windows resolution should find npm-cli.js beside an npm directory on PATH");
|
|
28
28
|
|
|
29
|
+
const selectedPiDirectory = "C:\\PortablePi";
|
|
30
|
+
const selectedPi = `${selectedPiDirectory}\\pi`;
|
|
31
|
+
const selectedPiNpmCli = `${selectedPiDirectory}\\node_modules\\npm\\bin\\npm-cli.js`;
|
|
32
|
+
const staleNpmDirectory = "C:\\Users\\Example\\AppData\\Roaming\\npm";
|
|
33
|
+
const selectedDirectory = resolveCommandDirectory("pi", {
|
|
34
|
+
platform: "win32",
|
|
35
|
+
env: { PATH: `${staleNpmDirectory};${selectedPiDirectory}` },
|
|
36
|
+
existsSync: (candidate) => path.win32.normalize(candidate) === path.win32.normalize(selectedPi),
|
|
37
|
+
});
|
|
38
|
+
assert.equal(selectedDirectory, selectedPiDirectory, "Pi should be resolved from its actual PATH entry, not an unrelated earlier npm directory");
|
|
39
|
+
assert.equal(
|
|
40
|
+
prependPathDirectory(selectedDirectory, { platform: "win32", env: { PATH: `${staleNpmDirectory};${selectedPiDirectory}` } }),
|
|
41
|
+
`${selectedPiDirectory};${staleNpmDirectory}`,
|
|
42
|
+
"the selected Pi installation should lead PATH while its update runs",
|
|
43
|
+
);
|
|
44
|
+
assert.deepEqual(
|
|
45
|
+
prependedPathEnvironment(selectedDirectory, { platform: "win32", env: { Path: `${staleNpmDirectory};${selectedPiDirectory}` } }),
|
|
46
|
+
{ Path: `${selectedPiDirectory};${staleNpmDirectory}` },
|
|
47
|
+
"Windows updates should preserve the existing Path key casing",
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const fromSelectedPi = resolveNpmCommandInvocation(["install"], {
|
|
51
|
+
platform: "win32",
|
|
52
|
+
execPath: windowsExecPath,
|
|
53
|
+
env: { PATH: `${staleNpmDirectory};${selectedPiDirectory}` },
|
|
54
|
+
preferredDirectories: [selectedDirectory],
|
|
55
|
+
existsSync: (candidate) => path.win32.normalize(candidate) === path.win32.normalize(selectedPiNpmCli),
|
|
56
|
+
});
|
|
57
|
+
assert.deepEqual(fromSelectedPi.args, [selectedPiNpmCli, "install"], "package updates should use npm bundled beside the selected Pi installation");
|
|
58
|
+
|
|
59
|
+
const selectedPiNode = `${selectedPiDirectory}\\node.exe`;
|
|
60
|
+
const selectedPiCli = `${selectedPiDirectory}\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js`;
|
|
61
|
+
const explicitPi = resolvePiCommandInvocation(selectedPi, ["update", "--help"], {
|
|
62
|
+
platform: "win32",
|
|
63
|
+
execPath: windowsExecPath,
|
|
64
|
+
env: { PATH: staleNpmDirectory },
|
|
65
|
+
existsSync: (candidate) => [selectedPi, selectedPiNode, selectedPiCli].some((expected) => path.win32.normalize(candidate) === path.win32.normalize(expected)),
|
|
66
|
+
});
|
|
67
|
+
assert.equal(explicitPi.command, selectedPiNode, "an explicit Windows Pi shim should run through Node from the same installation");
|
|
68
|
+
assert.deepEqual(explicitPi.args, [selectedPiCli, "update", "--help"], "an explicit Windows Pi shim should resolve to that installation's CLI script");
|
|
69
|
+
|
|
70
|
+
const selectedPiCmd = `${selectedPiDirectory}\\pi.cmd`;
|
|
71
|
+
const extensionResolvedPi = resolvePiCommandInvocation(selectedPi, ["--version"], {
|
|
72
|
+
platform: "win32",
|
|
73
|
+
execPath: windowsExecPath,
|
|
74
|
+
env: { PATH: staleNpmDirectory, PATHEXT: ".exe;.cmd" },
|
|
75
|
+
existsSync: (candidate) => [selectedPiCmd, selectedPiNode, selectedPiCli].some((expected) => path.win32.normalize(candidate) === path.win32.normalize(expected)),
|
|
76
|
+
});
|
|
77
|
+
assert.equal(extensionResolvedPi.command, selectedPiNode, "an extensionless explicit path should resolve a matching pi.cmd through PATHEXT");
|
|
78
|
+
assert.deepEqual(extensionResolvedPi.args, [selectedPiCli, "--version"]);
|
|
79
|
+
|
|
80
|
+
const customPiExecutable = `${selectedPiDirectory}\\custom-pi.exe`;
|
|
81
|
+
assert.deepEqual(
|
|
82
|
+
resolvePiCommandInvocation(customPiExecutable, ["--version"], {
|
|
83
|
+
platform: "win32",
|
|
84
|
+
execPath: windowsExecPath,
|
|
85
|
+
existsSync: (candidate) => [customPiExecutable, selectedPiCli].some((expected) => path.win32.normalize(candidate) === path.win32.normalize(expected)),
|
|
86
|
+
}),
|
|
87
|
+
{ command: customPiExecutable, args: ["--version"], source: "command" },
|
|
88
|
+
"explicit custom Pi executables should not be replaced by npm-shim normalization",
|
|
89
|
+
);
|
|
90
|
+
|
|
29
91
|
const configuredShim = "E:\\CustomNode\\npm.cmd";
|
|
30
92
|
const configuredCli = "E:\\CustomNode\\node_modules\\npm\\bin\\npm-cli.js";
|
|
31
93
|
const configured = resolveNpmCommandInvocation(["--version"], {
|
|
32
94
|
platform: "win32",
|
|
33
95
|
execPath: windowsExecPath,
|
|
34
96
|
env: { PI_WEBUI_NPM_BIN: configuredShim, PATH: "" },
|
|
97
|
+
preferredDirectories: [selectedPiDirectory],
|
|
35
98
|
existsSync: (candidate) => path.win32.normalize(candidate) === path.win32.normalize(configuredCli),
|
|
36
99
|
});
|
|
37
100
|
assert.equal(configured.command, windowsExecPath, "a configured npm.cmd shim should be normalized to its npm CLI");
|
|
@@ -68,7 +68,8 @@ assert.match(server, /"issue-wizard-state\.mjs"/, "the static allowlist must con
|
|
|
68
68
|
assert.match(server, /"issue-bot-client\.mjs"/, "the static allowlist must serve the browser client module");
|
|
69
69
|
assert.match(serviceWorker, /"\/issue-wizard-state\.mjs"/, "the PWA shell must keep caching the pure wizard module");
|
|
70
70
|
assert.match(serviceWorker, /"\/issue-bot-client\.mjs"/, "the PWA shell must cache the browser client module");
|
|
71
|
-
|
|
71
|
+
// Intent preserved: changing the public startup graph advances the PWA cache identity.
|
|
72
|
+
assert.match(serviceWorker, /pi-webui-pwa-v61/, "the PWA cache name must change with browser wiring updates");
|
|
72
73
|
assert.match(packageJson, /node --check public\/issue-wizard-state\.mjs/, "the package check must keep syntax-checking the pure wizard module");
|
|
73
74
|
assert.match(packageJson, /node --check public\/issue-bot-client\.mjs/, "the package check must syntax-check the browser client module");
|
|
74
75
|
|
|
@@ -17,6 +17,10 @@ assert.match(
|
|
|
17
17
|
"the composer should expose a count trigger and accessible non-modal follow-up queue overlay",
|
|
18
18
|
);
|
|
19
19
|
assert.match(css, /\.follow-up-queue-overlay \{[\s\S]*position:\s*absolute;[\s\S]*bottom:\s*calc\(100% \+ 0\.42rem\);[\s\S]*max-height:\s*min\(32rem, calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\)\)/, "the queue overlay should float upward without changing composer layout and be bounded by the visual viewport");
|
|
20
|
+
assert.match(css, /\.follow-up-queue-trigger \{[\s\S]*justify-content:\s*center;[\s\S]*min-width:\s*5\.25rem;/, "the queue trigger should reserve a predictable width for its label and three-digit count");
|
|
21
|
+
assert.match(css, /body:not\(\.mobile-keyboard-open\) \.composer-input-row:has\(\.composer-workflow-mode-dock:not\(\[hidden\]\)\) \.follow-up-queue-trigger \{\s*right:\s*calc\(3\.55rem \+ 2\.25rem \+ 0\.4rem\);\s*\}/, "the queue trigger should move left of the visible Workflow control instead of overlapping it");
|
|
22
|
+
assert.match(css, /\.composer-input-row:has\(\.follow-up-queue-trigger:not\(\[hidden\]\)\) \.composer-context-tags \{\s*max-width:\s*max\(0px, calc\(100% - 9\.7rem\)\);\s*\}/, "visible queues should reserve prompt-frame space so feature and context tags cannot overlap the queue trigger");
|
|
23
|
+
assert.match(css, /body:not\(\.mobile-keyboard-open\) \.composer-input-row:has\(\.composer-workflow-mode-dock:not\(\[hidden\]\)\):has\(\.follow-up-queue-trigger:not\(\[hidden\]\)\) \.composer-context-tags \{\s*max-width:\s*max\(0px, calc\(100% - 12\.6rem\)\);\s*\}/, "context tags should reserve the combined Workflow and queue dock width");
|
|
20
24
|
assert.match(css, /body\.mobile-keyboard-open \.follow-up-queue-trigger:not\(\[hidden\]\) \{ display: inline-flex; \}/, "the queue trigger should remain usable while the mobile keyboard is open");
|
|
21
25
|
assert.match(css, /@media \(prefers-reduced-motion: reduce\) \{[\s\S]*\.follow-up-queue-overlay,[\s\S]*\.follow-up-queue-row \{ transition: none; \}/, "the queue overlay should suppress motion for reduced-motion users");
|
|
22
26
|
|
|
@@ -48,6 +52,8 @@ assert.deepEqual(compactionMutation, {
|
|
|
48
52
|
const runtimeMutation = JSON.parse(vm.runInNewContext(`${mutationBodySource}\nJSON.stringify(queueMutationBody({ source: "pi-runtime", steering: [], followUp: ["old"] }, { type: "edit", index: 0, expectedText: "old", text: "new" }))`));
|
|
49
53
|
assert.equal(Object.hasOwn(runtimeMutation, "revision"), false, "Pi-runtime mutations must omit the compaction-only revision field");
|
|
50
54
|
assert.deepEqual(runtimeMutation.expected, { steering: [], followUp: ["old"] }, "Pi-runtime mutations should send the complete B1 expected snapshot");
|
|
55
|
+
const deleteMutation = JSON.parse(vm.runInNewContext(`${mutationBodySource}\nJSON.stringify(queueMutationBody({ source: "webui-compaction", revision: 4, steering: ["steer"], followUp: ["remove me"] }, { type: "delete", index: 0, expectedText: "remove me" }))`));
|
|
56
|
+
assert.deepEqual(deleteMutation.operation, { type: "delete", index: 0, expectedText: "remove me" }, "queue deletion should use the same source-aware full-snapshot mutation contract");
|
|
51
57
|
|
|
52
58
|
const draftHelperStart = app.indexOf("function preservedFocusedFollowUpQueueDraft(draft, followUps) {");
|
|
53
59
|
const draftHelperEnd = app.indexOf("\nfunction focusedFollowUpQueueDraft", draftHelperStart);
|
|
@@ -90,12 +96,14 @@ assert.match(app, /const textarea = make\("textarea", "follow-up-queue-textarea"
|
|
|
90
96
|
assert.match(app, /row\.draggable = false;[\s\S]*dragHandle\.draggable = !unavailable;[\s\S]*row\.addEventListener\("dragstart", \(event\) => \{[\s\S]*event\.target\?\.closest\?\.\("\.follow-up-queue-drag-handle"\) !== dragHandle[\s\S]*application\/x-pi-webui-follow-up[\s\S]*row\.addEventListener\("dragover"[\s\S]*event\.stopPropagation\(\)[\s\S]*row\.addEventListener\("drop"[\s\S]*type: "move", from: drag\.index, to: index/, "native drag/drop should begin only from its visible handle, persist the final-index permutation, and isolate row drag events");
|
|
91
97
|
assert.match(app, /function handleComposerDragOver\(event\) \{\n\s*if \(event\.target\?\.closest\?\.\("#followUpQueueOverlay"\) \|\| !isFileDrag\(event\)\) return;[\s\S]*function handleComposerDrop\(event\) \{\n\s*if \(event\.target\?\.closest\?\.\("#followUpQueueOverlay"\) \|\| !isFileDrag\(event\)\) return;/, "composer attachment drops should ignore queue-row drag events");
|
|
92
98
|
assert.match(app, /Moved queued follow-up \$\{operation\.from \+ 1\} to position \$\{operation\.to \+ 1\}[\s\S]*Move queued follow-up \$\{index \+ 1\} up[\s\S]*Move queued follow-up \$\{index \+ 1\} down/, "move controls should provide labelled keyboard/touch parity and live reorder announcements");
|
|
99
|
+
assert.match(app, /const remove = make\("button", "follow-up-queue-remove-button", "Remove"\)[\s\S]*type: "delete", index, expectedText: message/, "every composer queue row should expose an accessible remove control backed by the unified mutation contract");
|
|
100
|
+
assert.match(css, /\.follow-up-queue-remove-button \{[\s\S]*color:\s*var\(--ctp-red\)/, "queue removal should have a distinct destructive visual treatment");
|
|
93
101
|
assert.match(app, /setFollowUpQueueOpen\(false, \{ restoreFocus: true \}\)/, "outside close and Escape should request queue-focus restoration");
|
|
94
102
|
assert.match(app, /function setFollowUpQueueOpen\([\s\S]*followUpQueueRestoreFocus[\s\S]*requestAnimationFrame\(\(\) => focusTarget\?\.focus\(\{ preventScroll: true \}\)\)/, "queue close should restore focus to the saved trigger context");
|
|
95
103
|
assert.match(app, /function setFollowUpQueueOpen[\s\S]*setComposerActionsOpen\(false\)[\s\S]*setPublishMenuOpen\(false\)[\s\S]*setNativeCommandMenuOpen\(false\)[\s\S]*setAppRunnerMenuOpen\(false\)[\s\S]*setOptionsMenuOpen\(false\)[\s\S]*setConversationVoiceMenuOpen\(false\)[\s\S]*setBusyPromptBehaviorMenuOpen\(false\)[\s\S]*setNewTabMenuOpen\(false\)/, "opening the queue should close competing dropdown surfaces");
|
|
96
104
|
assert.match(app, /function renderFollowUpQueueOverlay\(\) \{\n\s*if \(deferUiRenderDuringPointerActivation\("follow-up-queue", renderFollowUpQueueOverlay\)\) return;/, "queue rendering should defer during pointer activation");
|
|
97
105
|
assert.match(app, /function switchTab\(tabId\)[\s\S]*setFollowUpQueueOpen\(false\)[\s\S]*setFollowUpQueueStatus\(""\)/, "switching tabs should close queue UI and clear its tab-local status before the new context renders");
|
|
98
|
-
assert.match(app, /renderQueueGroup\("Follow-up", followUp, "follow-up", \{ removable: snapshot\.
|
|
106
|
+
assert.match(app, /renderQueueGroup\("Follow-up", followUp, "follow-up", \{ removable: !snapshot\.draining, tabId \}\)/, "Control Deck removal should support every mutable queue source");
|
|
99
107
|
assert.doesNotMatch(app, /nextQueuedFollowUpPrompt|sticky-user-follow-up-prompt|Next follow-up prompt:/, "the sticky last/current prompt control must no longer expose queued follow-up preview content");
|
|
100
108
|
|
|
101
109
|
console.log("queue edit/reorder static tests passed");
|
|
@@ -47,6 +47,15 @@ function moveRequest(session, from, to, expectedText = session._followUpMessages
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
function deleteRequest(session, index, expectedText = session._followUpMessages[index]) {
|
|
51
|
+
return {
|
|
52
|
+
source: "pi-runtime",
|
|
53
|
+
kind: "followUp",
|
|
54
|
+
expected: expected(session),
|
|
55
|
+
operation: { type: "delete", index, expectedText },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
{
|
|
51
60
|
const { session, eventCount } = fixture();
|
|
52
61
|
const beforeMessage = session.agent.followUpQueue.messages[1];
|
|
@@ -76,6 +85,17 @@ function moveRequest(session, from, to, expectedText = session._followUpMessages
|
|
|
76
85
|
assert.equal(eventCount(), 1, "successful move emits exactly one queue update");
|
|
77
86
|
}
|
|
78
87
|
|
|
88
|
+
{
|
|
89
|
+
const { session, eventCount } = fixture();
|
|
90
|
+
const removedMessage = session.agent.followUpQueue.messages[1];
|
|
91
|
+
const result = mutatePiRuntimeFollowUpQueue(session, deleteRequest(session, 1));
|
|
92
|
+
assert.equal(result.mutated, true);
|
|
93
|
+
assert.deepEqual(session._followUpMessages, ["first", "third"], "delete removes the selected tracked follow-up");
|
|
94
|
+
assert.deepEqual(session.agent.followUpQueue.messages.map((message) => message.content[0].text), ["first", "third"], "delete keeps the remaining message objects paired with their tracking strings");
|
|
95
|
+
assert.equal(session.agent.followUpQueue.messages.includes(removedMessage), false, "delete removes the matching queued message object");
|
|
96
|
+
assert.equal(eventCount(), 1, "successful delete emits exactly one queue update");
|
|
97
|
+
}
|
|
98
|
+
|
|
79
99
|
{
|
|
80
100
|
const { session, eventCount } = fixture({ followUp: ["same", "same"] });
|
|
81
101
|
const result = mutatePiRuntimeFollowUpQueue(session, editRequest(session, 1, "changed"));
|
|
@@ -115,6 +135,8 @@ for (const requestFor of [
|
|
|
115
135
|
(session) => editRequest(session, 99, "edited"),
|
|
116
136
|
(session) => moveRequest(session, 0, 0),
|
|
117
137
|
(session) => moveRequest(session, 0, 99),
|
|
138
|
+
(session) => deleteRequest(session, 99),
|
|
139
|
+
(session) => deleteRequest(session, 1, "different"),
|
|
118
140
|
(session) => ({ ...editRequest(session, 1, "edited"), source: "webui-compaction" }),
|
|
119
141
|
(session) => ({ ...editRequest(session, 1, "edited"), kind: "steering" }),
|
|
120
142
|
]) {
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import vm from "node:vm";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const rawSource = await readFile(join(root, "public", "service-worker.js"), "utf8");
|
|
9
|
+
assert.match(rawSource, /const APP_SHELL_NETWORK_TIMEOUT_MS = 8_000;/, "app-shell requests need a bounded network timeout");
|
|
10
|
+
const source = rawSource.replace(
|
|
11
|
+
"const APP_SHELL_NETWORK_TIMEOUT_MS = 8_000;",
|
|
12
|
+
"const APP_SHELL_NETWORK_TIMEOUT_MS = 20;",
|
|
13
|
+
);
|
|
14
|
+
const handlers = new Map();
|
|
15
|
+
let releaseCacheWrite;
|
|
16
|
+
const cacheWrite = new Promise((resolve) => { releaseCacheWrite = resolve; });
|
|
17
|
+
let cachePutCount = 0;
|
|
18
|
+
let cacheMatchResult;
|
|
19
|
+
const cache = {
|
|
20
|
+
async addAll() {},
|
|
21
|
+
put: async () => {
|
|
22
|
+
cachePutCount += 1;
|
|
23
|
+
await cacheWrite;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const networkResponse = { ok: true, source: "network", clone() { return this; } };
|
|
27
|
+
let fetchImpl = async () => networkResponse;
|
|
28
|
+
const focusedMessages = [];
|
|
29
|
+
const client = {
|
|
30
|
+
url: "https://webui.test/",
|
|
31
|
+
async focus() { return this; },
|
|
32
|
+
postMessage(message) { focusedMessages.push(message); },
|
|
33
|
+
};
|
|
34
|
+
const context = {
|
|
35
|
+
self: {
|
|
36
|
+
location: { origin: "https://webui.test" },
|
|
37
|
+
addEventListener(name, handler) { handlers.set(name, handler); },
|
|
38
|
+
skipWaiting: async () => {},
|
|
39
|
+
clients: {
|
|
40
|
+
async claim() {},
|
|
41
|
+
async matchAll() { return [client]; },
|
|
42
|
+
async openWindow(url) { return { url }; },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
caches: {
|
|
46
|
+
async open() { return cache; },
|
|
47
|
+
async keys() { return []; },
|
|
48
|
+
async delete() { return true; },
|
|
49
|
+
async match() { return cacheMatchResult; },
|
|
50
|
+
},
|
|
51
|
+
fetch: (...args) => fetchImpl(...args),
|
|
52
|
+
AbortController,
|
|
53
|
+
setTimeout,
|
|
54
|
+
clearTimeout,
|
|
55
|
+
URL,
|
|
56
|
+
Promise,
|
|
57
|
+
RegExp,
|
|
58
|
+
Object,
|
|
59
|
+
String,
|
|
60
|
+
console,
|
|
61
|
+
};
|
|
62
|
+
vm.runInNewContext(source, context, { filename: "service-worker.js" });
|
|
63
|
+
|
|
64
|
+
let fetchResponse;
|
|
65
|
+
let fetchLifetime;
|
|
66
|
+
const fetchEvent = {
|
|
67
|
+
request: { method: "GET", url: "https://webui.test/app.js", mode: "cors" },
|
|
68
|
+
respondWith(promise) { fetchResponse = promise; },
|
|
69
|
+
waitUntil(promise) { fetchLifetime = promise; },
|
|
70
|
+
};
|
|
71
|
+
handlers.get("fetch")(fetchEvent);
|
|
72
|
+
assert.ok(fetchResponse, "app-shell fetch should be intercepted");
|
|
73
|
+
assert.ok(fetchLifetime, "runtime cache writes should extend the fetch-event lifetime");
|
|
74
|
+
assert.equal(await fetchResponse, networkResponse, "a usable network response must not wait for CacheStorage");
|
|
75
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
76
|
+
assert.equal(cachePutCount, 1, "network responses should begin a cache write");
|
|
77
|
+
let lifetimeSettled = false;
|
|
78
|
+
fetchLifetime.then(() => { lifetimeSettled = true; });
|
|
79
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
80
|
+
assert.equal(lifetimeSettled, false, "the event lifetime should still track an unfinished cache write");
|
|
81
|
+
releaseCacheWrite();
|
|
82
|
+
await fetchLifetime;
|
|
83
|
+
assert.equal(lifetimeSettled, true, "the event lifetime should settle after the cache write");
|
|
84
|
+
|
|
85
|
+
const cachedResponse = { ok: true, source: "cache" };
|
|
86
|
+
cacheMatchResult = cachedResponse;
|
|
87
|
+
fetchImpl = (_request, { signal }) => new Promise((_resolve, reject) => {
|
|
88
|
+
signal.addEventListener("abort", () => {
|
|
89
|
+
const error = new Error("network request timed out");
|
|
90
|
+
error.name = "AbortError";
|
|
91
|
+
reject(error);
|
|
92
|
+
}, { once: true });
|
|
93
|
+
});
|
|
94
|
+
let timeoutResponse;
|
|
95
|
+
let timeoutLifetime;
|
|
96
|
+
const timeoutEvent = {
|
|
97
|
+
request: { method: "GET", url: "https://webui.test/styles.css", mode: "cors" },
|
|
98
|
+
respondWith(promise) { timeoutResponse = promise; },
|
|
99
|
+
waitUntil(promise) { timeoutLifetime = promise; },
|
|
100
|
+
};
|
|
101
|
+
handlers.get("fetch")(timeoutEvent);
|
|
102
|
+
assert.equal(await timeoutResponse, cachedResponse, "a timed-out app-shell request should use the offline cache");
|
|
103
|
+
await timeoutLifetime;
|
|
104
|
+
|
|
105
|
+
let notificationWork;
|
|
106
|
+
const notificationEvent = {
|
|
107
|
+
notification: {
|
|
108
|
+
data: { target: { v: 1, route: "activity", tabId: "tab_12345678", runId: "run_12345678" } },
|
|
109
|
+
close() {},
|
|
110
|
+
},
|
|
111
|
+
waitUntil(promise) { notificationWork = promise; },
|
|
112
|
+
};
|
|
113
|
+
handlers.get("notificationclick")(notificationEvent);
|
|
114
|
+
await notificationWork;
|
|
115
|
+
assert.deepEqual(JSON.parse(JSON.stringify(focusedMessages)), [{
|
|
116
|
+
type: "pi-webui:navigate:v1",
|
|
117
|
+
target: { v: 1, route: "activity", tabId: "tab_12345678", runId: "run_12345678" },
|
|
118
|
+
}], "an existing active client should receive only the validated opaque navigation target");
|
|
119
|
+
|
|
120
|
+
console.log("service-worker-lifecycle.test.mjs passed");
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createServer } from "node:net";
|
|
4
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
12
|
+
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
13
|
+
const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
14
|
+
|
|
15
|
+
async function freePort() {
|
|
16
|
+
const server = createServer();
|
|
17
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
18
|
+
const { port } = server.address();
|
|
19
|
+
await new Promise((resolve) => server.close(resolve));
|
|
20
|
+
return port;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const port = await freePort();
|
|
24
|
+
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-sse-backpressure-"));
|
|
25
|
+
const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
26
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
27
|
+
env: {
|
|
28
|
+
...process.env,
|
|
29
|
+
PI_WEBUI_RPC_SUPERVISOR: "0",
|
|
30
|
+
PI_CODING_AGENT_DIR: join(cwd, "agent"),
|
|
31
|
+
PI_WEBUI_SETTINGS_FILE: join(cwd, "settings.json"),
|
|
32
|
+
FAKE_PI_SSE_FLOOD: "1",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
let output = "";
|
|
36
|
+
child.stdout.on("data", (chunk) => { output += String(chunk); });
|
|
37
|
+
child.stderr.on("data", (chunk) => { output += String(chunk); });
|
|
38
|
+
|
|
39
|
+
async function json(pathname, options = {}) {
|
|
40
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
41
|
+
...options,
|
|
42
|
+
headers: options.body ? { "content-type": "application/json", ...(options.headers || {}) } : options.headers,
|
|
43
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
44
|
+
signal: AbortSignal.timeout(5_000),
|
|
45
|
+
});
|
|
46
|
+
return { status: response.status, body: await response.json() };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
let health;
|
|
51
|
+
for (let attempt = 0; attempt < 80; attempt += 1) {
|
|
52
|
+
if (child.exitCode !== null) break;
|
|
53
|
+
try {
|
|
54
|
+
health = await json("/api/health");
|
|
55
|
+
if (health.status === 200) break;
|
|
56
|
+
} catch {
|
|
57
|
+
// Wait for the real server and fake Pi child.
|
|
58
|
+
}
|
|
59
|
+
await delay(100);
|
|
60
|
+
}
|
|
61
|
+
assert.equal(health?.status, 200, `server should start for backpressure test:\n${output}`);
|
|
62
|
+
const tabs = await json("/api/tabs");
|
|
63
|
+
const tabId = tabs.body?.data?.tabs?.[0]?.id;
|
|
64
|
+
assert.ok(tabId, "fixture server should expose an initial tab");
|
|
65
|
+
|
|
66
|
+
// Deliberately never consume this body. The fixture emits >2MiB of semantic
|
|
67
|
+
// events, exercising Node's write-backpressure path rather than a synthetic
|
|
68
|
+
// mocked response object.
|
|
69
|
+
const stalled = await fetch(`http://127.0.0.1:${port}/api/events?tab=${encodeURIComponent(tabId)}`, { signal: AbortSignal.timeout(15_000) });
|
|
70
|
+
assert.equal(stalled.status, 200);
|
|
71
|
+
const flood = await json("/api/prompt", { method: "POST", body: { tab: tabId, message: "fixture sse flood" } });
|
|
72
|
+
assert.equal(flood.status, 200, "flood fixture should dispatch through the real server");
|
|
73
|
+
|
|
74
|
+
let evicted = false;
|
|
75
|
+
for (let attempt = 0; attempt < 50; attempt += 1) {
|
|
76
|
+
const refreshed = await json("/api/tabs");
|
|
77
|
+
const clientCount = refreshed.body?.data?.tabs?.find((tab) => tab.id === tabId)?.clientCount;
|
|
78
|
+
if (clientCount === 0) {
|
|
79
|
+
evicted = true;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
await delay(100);
|
|
83
|
+
}
|
|
84
|
+
assert.equal(evicted, true, "the stalled SSE client must be evicted instead of accumulating an unbounded semantic-event queue");
|
|
85
|
+
|
|
86
|
+
const reconnected = await fetch(`http://127.0.0.1:${port}/api/events?tab=${encodeURIComponent(tabId)}`, { signal: AbortSignal.timeout(5_000) });
|
|
87
|
+
const firstFrame = await reconnected.body.getReader().read();
|
|
88
|
+
assert.equal(firstFrame.done, false, "a client can reconnect after slow-client eviction");
|
|
89
|
+
assert.match(new TextDecoder().decode(firstFrame.value), /webui_connected/, "reconnection should receive an authoritative connection snapshot");
|
|
90
|
+
await stalled.body?.cancel().catch(() => {});
|
|
91
|
+
await reconnected.body?.cancel().catch(() => {});
|
|
92
|
+
} finally {
|
|
93
|
+
child.kill("SIGTERM");
|
|
94
|
+
await new Promise((resolve) => child.once("exit", resolve));
|
|
95
|
+
await rm(cwd, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log("sse-backpressure-harness.test.mjs passed");
|
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
|
|
6
6
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
7
|
const app = await readFile(join(root, "public", "app.js"), "utf8");
|
|
8
|
+
const transcriptRenderer = await readFile(join(root, "public", "transcript-renderer.mjs"), "utf8");
|
|
8
9
|
|
|
9
10
|
const SELF_CONTAINED_THEORY_TITLES = new Map([
|
|
10
11
|
[0, "Live todo-progress widget rebuild"],
|
|
@@ -155,7 +156,12 @@ futureInvariant("theory #2: streaming assistant render must not derive all views
|
|
|
155
156
|
});
|
|
156
157
|
|
|
157
158
|
futureInvariant("theory #3: streaming markdown must not full-rebuild when earlier derived text changes", () => {
|
|
158
|
-
|
|
159
|
+
const reconcileMarkdownSurface = findFunctionBody(transcriptRenderer, "reconcileMarkdownSurface");
|
|
160
|
+
assert.match(renderStreamingMarkdown, /transcriptRenderer\.reconcileMarkdownSurface\(\{[\s\S]*?stableBoundary: streamingMarkdownStableBoundary[\s\S]*?renderInto: renderMarkdownInto/, "streaming markdown must route through the coordinator's committed-block/mutable-tail reconciler");
|
|
161
|
+
assert.doesNotMatch(renderStreamingMarkdown, /block\.replaceChildren\(\)/, "streaming markdown must not replace the whole block directly");
|
|
162
|
+
assert.match(reconcileMarkdownSurface, /!value\.startsWith\(state\.stableText\)[\s\S]*?invalidateSelection: diverged/, "retroactive todo/thinking rewrites must be explicit invalidations, not silent full rebuilds");
|
|
163
|
+
assert.match(reconcileMarkdownSurface, /if \(boundary > state\.stableText\.length\)/, "committed blocks must stay mounted for append-only updates");
|
|
164
|
+
assert.match(reconcileMarkdownSurface, /for \(const node of state\.tailNodes\) node\.remove\(\)/, "only the mutable tail may be re-parsed per delta batch");
|
|
159
165
|
});
|
|
160
166
|
|
|
161
167
|
futureInvariant("theory #4: run-indicator activity changes must not render/scroll synchronously from token paths", () => {
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
pruneDismissedSubagentGateKeys,
|
|
8
8
|
subagentGateIsTerminal,
|
|
9
9
|
subagentGateKey,
|
|
10
|
+
subagentGateRunIds,
|
|
11
|
+
ungatedSubagentRuns,
|
|
10
12
|
visibleSubagentGates,
|
|
11
13
|
} from "../public/subagent-gate-visibility.mjs";
|
|
12
14
|
|
|
@@ -28,6 +30,20 @@ assert.equal(subagentGateKey("", "gate-a"), "");
|
|
|
28
30
|
assert.equal(subagentGateIsTerminal({ status: "running" }), false);
|
|
29
31
|
assert.equal(subagentGateIsTerminal({ status: "failed" }), true);
|
|
30
32
|
|
|
33
|
+
const mixedRunsTab = {
|
|
34
|
+
runs: [
|
|
35
|
+
{ id: "direct-run", agents: [{ name: "scout" }] },
|
|
36
|
+
{ id: "gate-run-1", agents: [{ name: "reviewer" }] },
|
|
37
|
+
{ id: "gate-run-2", agents: [{ name: "planner" }] },
|
|
38
|
+
],
|
|
39
|
+
gates: [
|
|
40
|
+
{ attempts: [{ runId: "gate-run-1" }, { runId: " gate-run-2 " }, { runId: "" }] },
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
assert.deepEqual([...subagentGateRunIds(mixedRunsTab)], ["gate-run-1", "gate-run-2"], "retry gates should identify every spawned run they own");
|
|
44
|
+
assert.deepEqual(ungatedSubagentRuns(mixedRunsTab).map((run) => run.id), ["direct-run"], "retry-gated runs should be omitted while direct subagent spawns remain visible");
|
|
45
|
+
assert.deepEqual(ungatedSubagentRuns({ runs: mixedRunsTab.runs, gates: [] }).map((run) => run.id), ["direct-run", "gate-run-1", "gate-run-2"], "ordinary spawns should remain visible when no retry gate owns them");
|
|
46
|
+
|
|
31
47
|
assert.deepEqual(
|
|
32
48
|
visibleSubagentGates(tab, new Set(), now).map((gate) => gate.id),
|
|
33
49
|
["running", "fresh", "updated", "untimed"],
|
|
@@ -55,10 +71,10 @@ const [app, css, serviceWorker, server, pkgRaw] = await Promise.all([
|
|
|
55
71
|
const pkg = JSON.parse(pkgRaw);
|
|
56
72
|
|
|
57
73
|
assert.match(app, /from "\.\/subagent-gate-visibility\.mjs"/, "the browser should load the retry-gate visibility policy");
|
|
58
|
-
assert.match(app, /function subagentTabsWithRunningAgents\(\)[\s\S]*latestSubagents\?\.updatedAt[\s\S]*visibleSubagentGates\(tab, dismissedSubagentGateKeys, now\)/, "the side panel should
|
|
74
|
+
assert.match(app, /function subagentTabsWithRunningAgents\(\)[\s\S]*latestSubagents\?\.updatedAt[\s\S]*visibleSubagentGates\(tab, dismissedSubagentGateKeys, now\)[\s\S]*ungatedSubagentRuns\(tab\)[\s\S]*displayRuns/, "the side panel should filter retry-gated runs while retaining the gate attempts as their only rows");
|
|
59
75
|
assert.match(app, /function renderSubagentGate\(tab, gate\)[\s\S]*subagentGateIsTerminal\(gate\)[\s\S]*Hide finished retry gate[\s\S]*dismissedSubagentGateKeys\.add\(key\)[\s\S]*renderSubagents\(\)[\s\S]*event\.detail === 0[\s\S]*focusTarget\?\.focus/, "terminal gate cards should expose an accessible hide button and preserve keyboard focus after rerendering");
|
|
60
76
|
assert.match(app, /pruneDismissedSubagentGateKeys\(latestSubagents\?\.tabs, dismissedSubagentGateKeys\)/, "polling should prune stale dismissal keys");
|
|
61
|
-
assert.match(css, /\.subagent-gate-actions[\s\S]*\.subagent-gate-close[\s\S]*min-width:\s*1\.
|
|
77
|
+
assert.match(css, /\.subagent-gate-actions[\s\S]*\.subagent-gate-close[\s\S]*min-width:\s*1\.45rem[\s\S]*background:\s*transparent[\s\S]*\.subagent-gate-close:hover,[\s\S]*\.subagent-gate-close:focus-visible/, "the close control should remain minimal, compact, and keyboard-visible");
|
|
62
78
|
assert.match(serviceWorker, /"\/subagent-gate-visibility\.mjs"/, "the PWA app shell should cache the visibility module");
|
|
63
79
|
assert.match(server, /"subagent-gate-visibility\.mjs"/, "the server static allowlist should serve the visibility module");
|
|
64
80
|
assert.match(pkg.scripts.check, /node --check public\/subagent-gate-visibility\.mjs/, "the package check should syntax-check the visibility module");
|
|
@@ -4,9 +4,41 @@ import {
|
|
|
4
4
|
cloneLaunchSlotRoles,
|
|
5
5
|
launchSlotRolesEqual,
|
|
6
6
|
removeLaunchSlot,
|
|
7
|
+
subagentLaunchSlotSaveState,
|
|
7
8
|
updateLaunchSlot,
|
|
8
9
|
} from "../public/subagent-launch-slot-state.mjs";
|
|
9
10
|
|
|
11
|
+
assert.deepEqual(
|
|
12
|
+
subagentLaunchSlotSaveState({ hasConfig: true, hasDraft: true, dirty: true, activeConfigTab: true }),
|
|
13
|
+
{ disabled: false, reason: "Ready to save." },
|
|
14
|
+
"a dirty draft owned by the active tab should be saveable",
|
|
15
|
+
);
|
|
16
|
+
assert.deepEqual(
|
|
17
|
+
subagentLaunchSlotSaveState({ hasConfig: true, hasDraft: true, dirty: true, activeConfigTab: false }),
|
|
18
|
+
{ disabled: true, reason: "Switch back to the tab where these changes were made to save them." },
|
|
19
|
+
"a dirty draft should explain that its owning tab must be active",
|
|
20
|
+
);
|
|
21
|
+
assert.deepEqual(
|
|
22
|
+
subagentLaunchSlotSaveState({ hasConfig: true, hasDraft: true, dirty: true, loading: true, activeConfigTab: true }),
|
|
23
|
+
{ disabled: true, reason: "Wait for agent models to finish loading." },
|
|
24
|
+
"loading should temporarily block saving with an explanation",
|
|
25
|
+
);
|
|
26
|
+
assert.deepEqual(
|
|
27
|
+
subagentLaunchSlotSaveState({ hasConfig: true, hasDraft: true, dirty: true, saving: true, activeConfigTab: true }),
|
|
28
|
+
{ disabled: true, reason: "Saving agent models…" },
|
|
29
|
+
"saving should remain disabled while the request is in progress",
|
|
30
|
+
);
|
|
31
|
+
assert.deepEqual(
|
|
32
|
+
subagentLaunchSlotSaveState({ hasConfig: true, hasDraft: true, activeConfigTab: true }),
|
|
33
|
+
{ disabled: true, reason: "Change a model or thinking preset to enable saving." },
|
|
34
|
+
"a clean draft should explain how saving becomes available",
|
|
35
|
+
);
|
|
36
|
+
assert.deepEqual(
|
|
37
|
+
subagentLaunchSlotSaveState(),
|
|
38
|
+
{ disabled: true, reason: "Agent model configuration is not available for this tab." },
|
|
39
|
+
"missing configuration should explain why saving is unavailable",
|
|
40
|
+
);
|
|
41
|
+
|
|
10
42
|
const initial = {
|
|
11
43
|
reviewer: [{ id: "reviewer:base", model: "anthropic/reviewer", thinking: "high" }],
|
|
12
44
|
worker: [{ id: "worker:base", model: null, thinking: null }],
|
|
@@ -16,15 +16,21 @@ const [html, app, css, server, serviceWorker, pkg] = await Promise.all([
|
|
|
16
16
|
assert.match(html, /<details id="subagentLaunchSlots" class="subagent-launch-slots">[\s\S]*<summary class="subagent-launch-slots-summary">[\s\S]*id="subagentLaunchSlotsTitle">Agent models<[\s\S]*id="subagentLaunchSlotRoles"[\s\S]*id="subagentsStatus"[\s\S]*id="subagentsBox"/, "launch-slot configuration should be a native collapsible surface separate from the live monitor");
|
|
17
17
|
assert.doesNotMatch(html, /<details id="subagentLaunchSlots"[^>]*\sopen(?:\s|>)/, "Agent models should start collapsed to keep the Subagents panel compact");
|
|
18
18
|
assert.match(html, /id="subagentLaunchSlotScope"[^>]*aria-describedby="subagentLaunchSlotScopeStatus"/, "scope selection should use stable accessible help");
|
|
19
|
+
assert.match(html, /id="subagentLaunchSlotsSave"[^>]*aria-describedby="subagentLaunchSlotsDirty"[^>]*disabled[\s\S]*id="subagentLaunchSlotsDirty"[^>]*role="status"[^>]*aria-live="polite"/, "save availability explanations should be visible and associated with the disabled control");
|
|
19
20
|
assert.match(html, /id="subagentLaunchSlotsAnnouncer"[^>]*aria-live="polite"[^>]*aria-atomic="true"/, "slot changes should be announced accessibly");
|
|
20
21
|
assert.match(app, /from "\.\/subagent-launch-slot-state\.mjs"/, "the browser should use the pure launch-slot state helper");
|
|
21
22
|
assert.match(app, /const subagentLaunchSlotReloadTabs = new Set\(\)[\s\S]*subagentLaunchSlotReloadTabs\.add\(activeTabId\)[\s\S]*subagentLaunchSlotReloadTabs\.delete\(activeTabId\)/, "reload reminders should be tracked per tab until reload");
|
|
22
23
|
assert.match(app, /subagentLaunchSlotsSummaryStatus\.textContent[\s\S]*"Unsaved changes"[\s\S]*"Saved · reload this tab"[\s\S]*subagentLaunchSlots\.open = true/, "the collapsed summary should surface state and reopen for errors or required reloads");
|
|
24
|
+
assert.match(app, /const saveState = subagentLaunchSlotSaveState\([\s\S]*subagentLaunchSlotsSave\.disabled = saveState\.disabled[\s\S]*`Unsaved changes · \$\{saveState\.reason\}`/, "save eligibility and its adjacent explanation should come from one canonical state");
|
|
23
25
|
assert.doesNotMatch(app, /`(?:Model|Thinking) · \$\{slotLabel\}`/, "visible field labels should stay compact while aria-labels retain slot context");
|
|
26
|
+
assert.doesNotMatch(app, /make\("(?:p|span)", "subagent-launch-slot-(?:meta|id)"/, "redundant assignment summaries and internal slot IDs should stay out of the compact editor");
|
|
27
|
+
assert.match(app, /if \(slots\.length > 1\)[\s\S]*`Slot \$\{ordinal\}`/, "slot headings should appear only when a role has multiple slots");
|
|
24
28
|
assert.match(app, /api\(`\/api\/subagents\/config\?\$\{query\}`/, "the editor should load configuration through the tab-scoped API");
|
|
25
29
|
assert.match(app, /api\("\/api\/subagents\/config", \{ method: "POST", body, scoped: false \}\)/, "the editor should save through the localhost-scoped configuration API");
|
|
26
|
-
assert.match(css, /\.subagent-launch-slots \{[\s\S]*container: subagent-launch-slots \/ inline-size[\s\S]*@container subagent-launch-slots \(max-width:
|
|
27
|
-
assert.match(css, /\.subagent-launch-
|
|
30
|
+
assert.match(css, /\.subagent-launch-slots \{[\s\S]*container: subagent-launch-slots \/ inline-size[\s\S]*@container subagent-launch-slots \(max-width: 22rem\)[\s\S]*\.subagent-launch-slot-controls \{ grid-template-columns: minmax\(0, 1fr\); \}/, "launch-slot controls should stack only in genuinely narrow side-panel containers");
|
|
31
|
+
assert.match(css, /\.subagent-launch-slots-summary \{[^}]*min-height: 2\.35rem/, "the summary should retain the compact density contract");
|
|
32
|
+
assert.match(css, /\.subagent-launch-slot-role \{[^}]*padding: 0\.34rem/, "role surfaces should retain the compact density contract");
|
|
33
|
+
assert.match(css, /\.subagent-launch-slot-controls \{[\s\S]*grid-column: 1 \/ -1[\s\S]*grid-template-columns: repeat\(2, minmax\(0, 1fr\)\)/, "model and thinking controls should remain paired where side-panel space permits");
|
|
28
34
|
assert.match(css, /\.sr-only \{[\s\S]*clip-path: inset\(50%\)[\s\S]*white-space: nowrap/, "screen-reader announcements should stay visually hidden without leaving the accessibility tree");
|
|
29
35
|
assert.match(css, /\.subagent-launch-slot-remove \{[^}]*color: var\(--ctp-red\)/, "destructive slot removal should have a textual control and warning color");
|
|
30
36
|
assert.match(server, /"subagent-launch-slot-state\.mjs"/, "the pure browser module should be on the static allowlist");
|