@firstpick/pi-package-webui 0.6.9 → 0.7.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 +7 -2
- package/bin/pi-webui.mjs +407 -31
- package/index.ts +7 -91
- package/package.json +8 -7
- package/public/app.js +1140 -100
- package/public/aur-review-payload.mjs +108 -0
- package/public/guided-git-command-state.mjs +34 -0
- package/public/guided-git-review-state.mjs +137 -0
- package/public/index.html +54 -1
- package/public/styles.css +290 -20
- package/tests/aur-review-payload.test.mjs +57 -0
- package/tests/aur-review-widget-static.test.mjs +38 -0
- package/tests/compaction-resume-harness.test.mjs +55 -3
- package/tests/compaction-static.test.mjs +3 -3
- package/tests/fixtures/compacting-pi.mjs +10 -5
- package/tests/fixtures/fake-pi.mjs +46 -0
- package/tests/guided-git-aur-review.test.mjs +183 -0
- package/tests/http-endpoints-harness.test.mjs +118 -1
- package/tests/mobile-static.test.mjs +123 -12
- package/tests/staged-content-hash-contract.test.mjs +174 -0
- package/tests/subagents-helper.test.mjs +83 -4
- package/tests/transport-hardening-harness.test.mjs +157 -0
- package/webui-rpc-helper.mjs +108 -25
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
+
import vm from "node:vm";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
|
|
@@ -26,6 +27,13 @@ const manifest = JSON.parse(manifestRaw);
|
|
|
26
27
|
const lock = JSON.parse(await readFile(join(root, "package-lock.json"), "utf8"));
|
|
27
28
|
const helper = await readFile(join(root, "webui-rpc-helper.mjs"), "utf8");
|
|
28
29
|
const codexAuth = await readFile(join(root, "lib", "codex-usage-auth.mjs"), "utf8");
|
|
30
|
+
|
|
31
|
+
function appFunctionSource(name, nextName) {
|
|
32
|
+
const start = app.indexOf(`function ${name}(`);
|
|
33
|
+
const end = app.indexOf(`\nfunction ${nextName}(`, start);
|
|
34
|
+
assert.ok(start >= 0 && end > start, `${name} should remain a standalone frontend helper`);
|
|
35
|
+
return app.slice(start, end);
|
|
36
|
+
}
|
|
29
37
|
const nativeExportPayload = await readFile(join(root, "lib", "native-export-payload.mjs"), "utf8");
|
|
30
38
|
const companionDependencies = {
|
|
31
39
|
"@firstpick/pi-extension-bang-command-autocomplete": "^0.2.1",
|
|
@@ -60,6 +68,7 @@ assert.match(html, /id="newTabWorktreeButton" class="terminal-new-tab-menu-item
|
|
|
60
68
|
assert.match(html, /id="closeAllTabsButton"[\s\S]*?>Close all Tabs<\/button>/, "tab header should expose a top-right close-all tabs action");
|
|
61
69
|
assert.match(html, /id="sidePanelBackdrop"/, "mobile side panel needs an overlay/backdrop close target");
|
|
62
70
|
assert.match(html, /<div class="side-panel-heading">[\s\S]*<strong class="side-panel-title">Control Deck<\/strong>[\s\S]*<div class="side-panel-version-row"[\s\S]*<button id="piVersionButton"[\s\S]*aria-controls="piReleaseNotesDialog"[\s\S]*<button id="webuiVersionButton"[\s\S]*aria-controls="confirmationDialog"[\s\S]*id="webuiDevBadge"/, "Control Deck header should keep its title separate from an aligned version and build row");
|
|
71
|
+
assert.match(html, /<div class="side-panel-brand-row">[\s\S]*<span class="side-panel-kicker">Pi Web UI<\/span>[\s\S]*<a class="sponsor-link" href="https:\/\/github\.com\/sponsors\/Firstp1ck" target="_blank" rel="noopener noreferrer" aria-label="Sponsor Firstp1ck on GitHub"[^>]*>♡<\/a>/, "Control Deck brand should expose a subtle, accessible sponsor link beside the Pi Web UI name");
|
|
63
72
|
assert.match(html, /<dialog id="piReleaseNotesDialog"[\s\S]*id="piReleaseNotesTitle"[\s\S]*id="piReleaseNotesStatus"[\s\S]*id="piReleaseNotesBody"[\s\S]*id="piReleaseNotesGithubLink"/, "Pi release notes should use a dedicated accessible dialog");
|
|
64
73
|
assert.doesNotMatch(html, /Safer option|confirmationAlternative/, "shared confirmation dialogs should not render a safer-option row");
|
|
65
74
|
assert.doesNotMatch(app, /confirmationAlternative|\balternative:\s*options\.alternative/, "confirmation logic should not populate a removed safer-option row");
|
|
@@ -104,6 +113,8 @@ assert.doesNotMatch(html, /id="btwOverlayDialog"/, "/btw should not use a blocki
|
|
|
104
113
|
assert.match(html, /id="codexUsageBox"/, "side panel should expose Codex subscription usage status");
|
|
105
114
|
assert.match(html, /data-side-panel-section="codex-usage"/, "Codex usage should live in a collapsible side-panel section");
|
|
106
115
|
assert.match(html, /data-side-panel-section="subagents"[\s\S]*class="side-panel-section-label">Subagents<\/span>[\s\S]*id="subagentCountBadge"[\s\S]*class="subagents-help"[\s\S]*<code>subagent<\/code>[\s\S]*foreground or async mode[\s\S]*id="subagentsBox"/, "side panel should explain how to launch tracked subagents and expose grouped running agents with a live count");
|
|
116
|
+
assert.match(html, /id="subagentOpenModeSelect"[\s\S]*<option value="overlay">Overlay<\/option>[\s\S]*<option value="tab">Tab \/ terminal<\/option>[\s\S]*id="subagentOpenModeStatus"/, "Subagents should offer a browser-persisted overlay or terminal-tab opening choice");
|
|
117
|
+
assert.match(html, /id="subagentTerminalView"[\s\S]*Subagent · view only[\s\S]*id="subagentTerminalTranscript"[\s\S]*id="subagentTerminalStatus"[^>]*aria-live="off"[\s\S]*id="subagentTerminalInput"[^>]*placeholder="View only — send messages from the parent terminal"[^>]*disabled[\s\S]*Use its parent terminal to interact with the run/, "dedicated subagent tabs should expose a view-only transcript, non-announcing routine status, and disabled input");
|
|
107
118
|
assert.doesNotMatch(html, /id="subagentOverlayDialog"/, "subagent output should not use a blocking modal dialog");
|
|
108
119
|
assert.match(html, /data-side-panel-section="session"[\s\S]*data-side-panel-section="subagents"[\s\S]*data-side-panel-section="queue"/, "Subagents should appear between Session and Queue in the side panel");
|
|
109
120
|
assert.match(html, /data-side-panel-section="queue"[\s\S]*id="createPromptListButton"[\s\S]*>Create prompt list<\/button>/, "Queue section should expose prompt-list creation");
|
|
@@ -328,6 +339,8 @@ assert.match(css, /\.session-detail-value\.truncate[\s\S]*?text-overflow:\s*elli
|
|
|
328
339
|
assert.match(css, /\.server-restart-panel \{[\s\S]*?z-index:\s*62/, "server restart overlay should render above the offline shell");
|
|
329
340
|
assert.match(css, /@keyframes server-restart-spin/, "server restart overlay should show a loading spinner");
|
|
330
341
|
assert.match(css, /\.side-panel-version-row \{[\s\S]*?display:\s*flex[\s\S]*?align-items:\s*center[\s\S]*?flex-wrap:\s*wrap/, "Control Deck versions and build status should use a dedicated responsive row");
|
|
342
|
+
assert.match(css, /\.side-panel-brand-row \{[\s\S]*?display:\s*flex[\s\S]*?align-items:\s*center[\s\S]*?\.sponsor-link \{[\s\S]*?text-decoration:\s*none/, "Sponsor heart should sit inline with the Pi Web UI brand and remain visually subtle");
|
|
343
|
+
assert.match(css, /\.sponsor-link:hover,[\s\S]*?\.sponsor-link:focus-visible/, "Sponsor heart should expose visible hover and keyboard focus states");
|
|
331
344
|
assert.match(css, /\.pi-version-button,\n\.webui-version-button,\n\.webui-dev-badge \{[\s\S]*?border-radius:\s*999px/, "Pi and Web UI version buttons plus the dev indicator should render as compact title controls");
|
|
332
345
|
assert.match(css, /\.webui-version-button:hover,[\s\S]*?\.webui-version-button:focus-visible/, "Web UI version button should expose visible hover and keyboard focus states");
|
|
333
346
|
assert.match(css, /\.pi-version-button:hover,[\s\S]*?\.pi-version-button:focus-visible/, "Pi version button should expose visible hover and keyboard focus states");
|
|
@@ -339,7 +352,10 @@ assert.match(css, /\.subagents-help \{[\s\S]*border-left:[\s\S]*font-size:\s*0\.
|
|
|
339
352
|
assert.match(css, /\.subagents-box\.has-items[\s\S]*\.subagent-tab-group[\s\S]*\.subagent-agent-row/, "running subagents should render as grouped terminal/session cards");
|
|
340
353
|
assert.match(css, /\.subagent-agent-row:hover,[\s\S]*\.subagent-agent-row:focus-visible/, "subagent rows should expose clickable hover and keyboard focus states");
|
|
341
354
|
assert.match(css, /\.subagent-overlay-widget[\s\S]*\.subagent-overlay-transcript[\s\S]*\.subagent-overlay-message[\s\S]*\.subagent-overlay-close-action/, "subagent output should combine the non-blocking widget shell with the main transcript message styling");
|
|
342
|
-
assert.match(css, /\.subagent-
|
|
355
|
+
assert.match(css, /\.terminal-tab-subagent-indicator[\s\S]*\.terminal-tab-subagent[\s\S]*\.subagent-terminal-view[\s\S]*\.subagent-terminal-composer textarea:disabled/, "subagent terminal tabs should be visibly marked and retain an explicit disabled composer");
|
|
356
|
+
assert.match(css, /body\.subagent-terminal-active \.workspace-dashboard,[\s\S]*body\.subagent-terminal-active \.composer[\s\S]*display: none !important/, "the dedicated child view should replace parent terminal content without mutating it");
|
|
357
|
+
assert.match(css, /\.subagent-run-indicator[\s\S]*\.subagent-run-indicator \.run-indicator-meta/, "subagent output should reuse the main live run-indicator treatment with wrapping activity metadata");
|
|
358
|
+
assert.match(css, /\.subagent-terminal-transcript > \.message \{[\s\S]*width: 100%;[\s\S]*max-width: none;/, "dedicated subagent transcript cards should fill the available tab width");
|
|
343
359
|
assert.doesNotMatch(css, /\.extension-dialog\.subagent-overlay-dialog/, "subagent output should not retain blocking dialog styles");
|
|
344
360
|
assert.match(css, /@keyframes subagent-running-pulse/, "running subagents should expose a live activity indicator");
|
|
345
361
|
assert.match(css, /\.optional-feature-pill\.enabled/, "optional features should visually distinguish enabled state");
|
|
@@ -703,22 +719,109 @@ assert.match(
|
|
|
703
719
|
);
|
|
704
720
|
assert.match(app, /function renderCodexUsage\(\)/, "frontend should render Codex usage buckets in the side panel");
|
|
705
721
|
assert.match(app, /function renderSubagents\(\)[\s\S]*subagentTabsWithRunningAgents\(\)[\s\S]*renderSubagentTabGroup\(tab\)/, "frontend should group running subagents by terminal and session");
|
|
706
|
-
assert.match(app, /
|
|
707
|
-
assert.match(app, /function
|
|
722
|
+
assert.match(app, /SUBAGENT_OPEN_MODE_STORAGE_KEY = "pi-webui-subagent-open-mode"[\s\S]*function normalizeSubagentOpenMode\(value\)[\s\S]*function restoreSubagentOpenModeSetting\(\)/, "subagent opening mode should default safely and persist in this browser");
|
|
723
|
+
assert.match(app, /function openSubagentOutput\(tab, run, agent\) \{[\s\S]*subagentOpenMode === "tab" \? openSubagentTerminal\(tab, run, agent\) : openSubagentOverlay\(tab, run, agent\)/, "clicking an agent should dispatch to the selected overlay or terminal-tab view");
|
|
724
|
+
assert.match(app, /function openSubagentOverlay\(tab, run, agent\)[\s\S]*activeSubagentTerminalId[\s\S]*deactivateSubagentTerminalView\(\{ render: false \}\)[\s\S]*activeTabId !== tab\.tabId[\s\S]*await switchTab\(tab\.tabId\)[\s\S]*renderWidgets\(\)/, "opening an overlay should first leave any virtual child tab, then switch to its owning terminal before rendering the widget");
|
|
725
|
+
assert.match(app, /function renderWidgets\(\)[\s\S]*renderAppRunnerWidget\(\)[\s\S]*renderSubagentOverlayWidgetSafely\(\)/, "subagent output should render in the shared non-blocking top widget area after App Runner");
|
|
708
726
|
assert.doesNotMatch(app, /subagentOverlayDialog\.showModal|elements\.subagentOverlayDialog/, "subagent output should not open or depend on a modal dialog");
|
|
709
727
|
assert.match(app, /api\(`\/api\/subagents\/output\?\$\{query\}`, \{ scoped: false \}\)/, "subagent overlay should fetch selected live output from the owning tab");
|
|
728
|
+
assert.match(app, /function subagentRunIndicatorActivity\(agent = \{\}\)[\s\S]*currentToolArgs[\s\S]*activityState[\s\S]*function appendSubagentRunIndicator\(parent,[\s\S]*run-indicator-pulse[\s\S]*Agent is running:[\s\S]*subagent-run-indicator-elapsed[\s\S]*updateSubagentRunIndicatorElapsed\(parent, run\)/, "running child output should show the main-style pulse, current tool or activity, and separately refreshed elapsed runtime");
|
|
729
|
+
assert.match(app, /const facts = \[[\s\S]*view\.finished \? "finished" : running \? "running"/, "retained completed child views should not keep contradictory running header metadata");
|
|
730
|
+
assert.match(app, /function renderSubagentTerminalView\(\)[\s\S]*if \(running\) appendSubagentRunIndicator\(elements\.subagentTerminalTranscript, \{ agent, run: view\.run \}\)/, "the dedicated child tab should append a live run indicator whenever the selected child is running");
|
|
731
|
+
const subagentTerminalSignatureSource = appFunctionSource("subagentTerminalViewMeaningfulSignature", "updateSubagentTerminalRefreshState");
|
|
732
|
+
const subagentTerminalRefreshSource = appFunctionSource("refreshSubagentTerminalView", "deactivateSubagentTerminalView");
|
|
733
|
+
assert.ok(subagentTerminalRefreshSource.includes("tab: view.parentTabId, run: view.runId, agent: view.agentId"), "subagent terminal refresh should stay scoped to the child and its owning parent terminal");
|
|
734
|
+
assert.ok(subagentTerminalRefreshSource.includes("view.finished = true"), "an open child tab should retain its last snapshot after the run is no longer tracked");
|
|
735
|
+
assert.ok(subagentTerminalRefreshSource.includes("previousSignature !== subagentTerminalViewMeaningfulSignature(view)"), "automatic child polling should compare meaningful snapshots before rebuilding the transcript");
|
|
736
|
+
let unchangedSubagentRenderCount = 0;
|
|
737
|
+
let unchangedSubagentTabRenderCount = 0;
|
|
738
|
+
let unchangedSubagentElapsedUpdateCount = 0;
|
|
739
|
+
const unchangedSubagentView = {
|
|
740
|
+
id: "child-view",
|
|
741
|
+
parentTabId: "parent-tab",
|
|
742
|
+
runId: "run-1",
|
|
743
|
+
agentId: "agent-1",
|
|
744
|
+
data: { updatedAt: 1, agent: { id: "agent-1", status: "running", currentTool: "read" } },
|
|
745
|
+
error: "",
|
|
746
|
+
finished: false,
|
|
747
|
+
loading: false,
|
|
748
|
+
requestSerial: 0,
|
|
749
|
+
};
|
|
750
|
+
await vm.runInNewContext(`${subagentTerminalSignatureSource}\nasync ${subagentTerminalRefreshSource}\nrefreshSubagentTerminalView("child-view");`, {
|
|
751
|
+
activeSubagentTerminalId: "child-view",
|
|
752
|
+
elements: { subagentTerminalTranscript: {} },
|
|
753
|
+
subagentTerminalViews: new Map([["child-view", unchangedSubagentView]]),
|
|
754
|
+
URLSearchParams,
|
|
755
|
+
api: async () => ({ data: { updatedAt: 2, agent: { id: "agent-1", status: "running", currentTool: "read" } } }),
|
|
756
|
+
renderSubagentTerminalView() { unchangedSubagentRenderCount += 1; },
|
|
757
|
+
renderTabs() { unchangedSubagentTabRenderCount += 1; },
|
|
758
|
+
updateSubagentRunIndicatorElapsed() { unchangedSubagentElapsedUpdateCount += 1; },
|
|
759
|
+
updateSubagentTerminalRefreshState() { throw new Error("background polls must not announce routine loading state"); },
|
|
760
|
+
});
|
|
761
|
+
assert.equal(unchangedSubagentRenderCount, 0, "an unchanged background poll should preserve the existing transcript DOM");
|
|
762
|
+
assert.equal(unchangedSubagentTabRenderCount, 0, "an unchanged background poll should not rebuild terminal tabs");
|
|
763
|
+
assert.equal(unchangedSubagentElapsedUpdateCount, 1, "an unchanged background poll should refresh only the existing visual elapsed-time node");
|
|
764
|
+
assert.equal(unchangedSubagentView.loading, false, "an unchanged background poll should still clear its internal loading flag");
|
|
765
|
+
const subagentTerminalCloseStart = app.indexOf("function closeSubagentTerminalTab(");
|
|
766
|
+
const subagentTerminalCloseEnd = app.indexOf("\nasync function copySubagentTerminalOutput(", subagentTerminalCloseStart);
|
|
767
|
+
assert.ok(subagentTerminalCloseStart >= 0 && subagentTerminalCloseEnd > subagentTerminalCloseStart, "closeSubagentTerminalTab should remain a standalone frontend helper");
|
|
768
|
+
const subagentTerminalCloseSource = app.slice(subagentTerminalCloseStart, subagentTerminalCloseEnd);
|
|
769
|
+
assert.ok(subagentTerminalCloseSource.includes("subagentTerminalViews.delete(viewId)"), "closing a subagent tab should remove only its client-side view record");
|
|
770
|
+
assert.doesNotMatch(subagentTerminalCloseSource, /\bapi\(|closeTerminalTabs\(|closeSubagentOverlay\(/, "closing a subagent tab must not call backend terminal or subagent lifecycle APIs");
|
|
771
|
+
assert.match(app, /function renderSubagentTerminalTab\(view\)[\s\S]*terminal-tab-subagent[\s\S]*subagent: true[\s\S]*closeSubagentTerminalTab\(view\.id\)/, "virtual tabs should be marked as subagents and have a view-only close action");
|
|
772
|
+
assert.match(app, /function subagentTerminalViewId\(tab, run, agent\)[\s\S]*JSON\.stringify\(\[tab\?\.tabId[\s\S]*run\?\.id[\s\S]*agent\?\.id/, "virtual child tabs should be uniquely keyed by parent terminal, run, and child agent");
|
|
710
773
|
assert.match(app, /SUBAGENT_OVERLAY_REFRESH_MS = 1000/, "subagent overlay should poll selected live output at a fast cadence");
|
|
711
774
|
assert.match(app, /function createMessageBubble\(message,[\s\S]*renderContent\(body, message\.content, \{ markdown: message\.role === "assistant" \}\)[\s\S]*function appendMessage\(message, options = \{\}\)[\s\S]*createMessageBubble\(message, options\)/, "main transcript output should use the reusable message bubble renderer");
|
|
712
|
-
|
|
713
|
-
assert.
|
|
775
|
+
const subagentTranscriptMessagesSource = appFunctionSource("subagentOverlayTranscriptMessages", "subagentOverlayToolArguments");
|
|
776
|
+
assert.ok(subagentTranscriptMessagesSource.includes("message.role === \"assistant\" || message.role === \"toolResult\""), "subagent overlays should retain structured assistant and tool-result entries");
|
|
777
|
+
const subagentToolArgumentsSource = appFunctionSource("subagentOverlayToolArguments", "subagentOverlayTranscriptDisplayMessages");
|
|
778
|
+
assert.ok(subagentToolArgumentsSource.includes("JSON.parse(value)"), "structured tool arguments should be restored for specialized tool renderers");
|
|
779
|
+
const subagentDisplaySource = appFunctionSource("subagentOverlayTranscriptDisplayMessages", "subagentOverlayTranscriptOutputLines");
|
|
780
|
+
assert.ok(subagentDisplaySource.includes("const toolResults = buildToolResultMap(messages);"), "subagent rendering should pair calls with the shared result lookup");
|
|
781
|
+
assert.ok(subagentDisplaySource.includes("role: \"toolExecution\""), "paired subagent calls should use main-transcript toolExecution cards");
|
|
782
|
+
assert.ok(subagentDisplaySource.includes("const result = toolResults.get(displayMessage.toolCallId) || null;") && subagentDisplaySource.includes(" result,"), "incomplete subagent tool calls should remain pending tool cards");
|
|
783
|
+
assert.ok(subagentDisplaySource.includes("if (pairedToolCallIds.has(toolResultCallId(message))) continue;"), "paired tool results should not render as duplicate generic cards");
|
|
784
|
+
const subagentAppendSource = appFunctionSource("appendSubagentOverlayTranscript", "subagentOverlayStateFacts");
|
|
785
|
+
assert.ok(subagentAppendSource.includes("subagentOverlayTranscriptDisplayMessages(messages)"), "subagent bubbles should use the paired structured display sequence");
|
|
786
|
+
assert.ok(subagentAppendSource.includes("createMessageBubble(displayMessage, { transient: true })"), "subagent bubbles should reuse the main message renderer");
|
|
787
|
+
const thinkingVisibilitySource = appFunctionSource("setThinkingOutputVisible", "applyToolOutputExpansionToDom");
|
|
788
|
+
assert.ok(thinkingVisibilitySource.includes("if (subagentOverlaySelection?.tabId === activeTabId) renderWidgets();"), "changing thinking visibility should rerender an open subagent overlay transcript, including finished agents");
|
|
789
|
+
assert.ok(thinkingVisibilitySource.includes("if (activeSubagentTerminalId) renderSubagentTerminalView();"), "changing thinking visibility should rerender an open subagent terminal transcript, including finished agents");
|
|
790
|
+
const subagentCopySource = appFunctionSource("subagentOverlayTranscriptOutputLines", "subagentOverlayOutputLines");
|
|
791
|
+
assert.ok(subagentCopySource.includes("messageCopyText(message)"), "global subagent copy should derive from the same structured bubble messages");
|
|
792
|
+
const subagentOutputSource = appFunctionSource("subagentOverlayOutputLines", "subagentOverlayOutputText");
|
|
793
|
+
assert.ok(subagentOutputSource.includes("if (transcriptMessages.length) return subagentOverlayTranscriptOutputLines(data);"), "global subagent copy should prefer structured transcript content over flattened recent output");
|
|
794
|
+
const subagentEmptySource = appFunctionSource("subagentOverlayEmptyTranscriptText", "appendSubagentRunIndicator");
|
|
795
|
+
assert.ok(subagentEmptySource.includes("No visible output was captured."), "hidden or non-renderable structured output should have explicit fallback text");
|
|
796
|
+
const subagentRenderErrorSource = appFunctionSource("renderSubagentOverlayErrorWidget", "renderSubagentOverlayWidgetSafely");
|
|
797
|
+
assert.ok(subagentRenderErrorSource.includes("Subagent output unavailable"), "a failed subagent renderer should show a minimal recoverable widget");
|
|
798
|
+
assert.ok(subagentRenderErrorSource.includes("appRunnerActionButton(\"Close\", closeSubagentOverlay"), "the recoverable subagent renderer error widget should provide a Close action");
|
|
799
|
+
assert.doesNotMatch(subagentRenderErrorSource, /addEvent\(/, "renderer failures should not create repeated event-log entries while a refresh retries");
|
|
800
|
+
const subagentSafeRenderSource = appFunctionSource("renderSubagentOverlayWidgetSafely", "renderSubagentOverlayWidget");
|
|
801
|
+
assert.match(subagentSafeRenderSource, /try \{[\s\S]*renderSubagentOverlayWidget\(\)[\s\S]*\} catch \{[\s\S]*renderSubagentOverlayErrorWidget\(\)/, "subagent renderer exceptions should be isolated from the shared widget render pass");
|
|
802
|
+
const rendererFallbackSentinel = {};
|
|
803
|
+
const rendererContainmentResult = vm.runInNewContext(`${subagentSafeRenderSource}\nrenderSubagentOverlayWidgetSafely();`, {
|
|
804
|
+
renderSubagentOverlayWidget() { throw new Error("fixture renderer failure"); },
|
|
805
|
+
renderSubagentOverlayErrorWidget() { return rendererFallbackSentinel; },
|
|
806
|
+
});
|
|
807
|
+
assert.equal(rendererContainmentResult, rendererFallbackSentinel, "subagent renderer failures should return the recoverable fallback widget");
|
|
808
|
+
const subagentWidgetSource = appFunctionSource("renderSubagentOverlayWidget", "scheduleSubagentOverlayRefresh");
|
|
809
|
+
assert.ok(subagentWidgetSource.includes("const visibleFallbackText = !hasStructuredTranscript ? fallbackText : emptyTranscriptFallback;"), "the widget should render a fallback instead of leaving structured-but-hidden output blank");
|
|
810
|
+
assert.ok(subagentWidgetSource.includes("if (visibleFallbackText) {"), "the widget should append the nonblank fallback bubble");
|
|
811
|
+
assert.ok(subagentWidgetSource.includes("if (running) appendSubagentRunIndicator(output, { agent, run: selection.run });"), "running subagent widgets should append the shared live activity indicator");
|
|
714
812
|
assert.match(app, /api\("\/api\/subagents", \{ scoped: false \}\)/, "frontend should refresh the cross-tab subagent overview");
|
|
715
813
|
assert.match(app, /SUBAGENTS_ACTIVE_REFRESH_MS = 1500/, "running subagents should receive a fast live refresh cadence");
|
|
716
814
|
assert.match(server, /url\.pathname === "\/api\/subagents" && req\.method === "GET"[\s\S]*webuiSubagentsData\(\)/, "server should expose a cross-tab running-subagent endpoint");
|
|
717
815
|
assert.match(server, /url\.pathname === "\/api\/subagents\/output" && req\.method === "GET"[\s\S]*webuiSubagentOutputData\(tab, runId, agentId\)/, "server should expose selected running subagent output only through its owning tab");
|
|
718
816
|
assert.match(server, /rememberWebuiSubagentsStatusEvent\(tab, event\)/, "server should ingest the helper's structured subagent status without forwarding internal JSON to the browser footer");
|
|
817
|
+
assert.match(server, /PI_RPC_JSONL_LINE_MAX_BYTES = 32 \* 1024 \* 1024/, "Pi RPC JSONL parsing should use an explicit line-size limit with inline-image headroom");
|
|
818
|
+
assert.match(server, /function ensureStderrMirrorErrorHandler\(stream\)[\s\S]*stream\.on\("error"/, "Pi stderr mirroring should contain asynchronous closed-sink failures");
|
|
819
|
+
assert.match(server, /type: "pi_stdout_line_too_large"[\s\S]*discardingOversizedLine/, "oversized unterminated Pi RPC lines should be discarded until their newline");
|
|
719
820
|
assert.match(helper, /SUBAGENT_RPC_REQUEST_EVENT = "subagents:rpc:v1:request"/, "Web UI helper should use pi-subagents' stable status RPC");
|
|
720
821
|
assert.match(helper, /case "subagent-output":[\s\S]*subagentOutputSnapshot\(payload\)/, "Web UI helper should return bounded live state and recent output for the selected child agent");
|
|
822
|
+
assert.match(helper, /function subagentTranscriptOutput\(sessionFile\)[\s\S]*const empty = \{ recentOutput: \[\], transcript: \[\] \}[\s\S]*transcript: subagentTranscriptMessages\(boundedCandidates\)/, "subagent transcript extraction should return bounded structured entries alongside recentOutput");
|
|
721
823
|
assert.match(helper, /line\.trim\(\)\.toLowerCase\(\) === "\(no output\)"/, "subagent transcript extraction should suppress empty tool-result markers");
|
|
824
|
+
assert.match(server, /function normalizeWebuiSubagentTranscript\(value\)[\s\S]*remainingParts = WEBUI_SUBAGENT_OUTPUT_LINE_LIMIT[\s\S]*const transcript = normalizeWebuiSubagentTranscript\(rawAgent\.transcript\)/, "server output normalization should preserve the structured transcript under the existing line limit");
|
|
722
825
|
assert.match(helper, /SUBAGENT_ASYNC_STARTED_EVENT = "subagent:async-started"[\s\S]*SUBAGENT_ASYNC_COMPLETE_EVENT = "subagent:async-complete"/, "Web UI helper should track async subagent lifecycle events");
|
|
723
826
|
assert.match(helper, /pi\.on\("tool_execution_start"[\s\S]*event\.toolName !== "subagent"[\s\S]*pi\.on\("tool_execution_end"/, "Web UI helper should track foreground subagent executions");
|
|
724
827
|
assert.match(app, /if \(normalized === "prolite"\) return "Usage";/, "Codex Prolite plan labels should display as Usage in the side panel");
|
|
@@ -764,8 +867,11 @@ assert.match(app, /function renderFooterBranchCreateForm\(state = footerBranchPi
|
|
|
764
867
|
assert.match(app, /let footerBranchCreateDraft = \{ type: "", name: "" \}/, "new branch creation should not default the editable type prefix to feat");
|
|
765
868
|
assert.match(app, /function footerBranchCreateType\(value = footerBranchCreateDraft\.type\) \{\n\s+return slugifyGitBranchPart\(value\);\n\}/, "branch type suggestions should not restrict or default custom user-entered prefixes");
|
|
766
869
|
assert.match(app, /const slash = make\("span", "footer-branch-create-slash", "\/"\)/, "branch creation should visibly separate the prefix and user input with a slash");
|
|
767
|
-
assert.match(app, /function gitWorktreeCreateCommandDisplay\(branch, state = footerBranchPickerState\)[\s\S]*git worktree add -b[\s\S]*preview\.textContent = gitWorktreeCreateCommandDisplay\(branchName \|\| footerBranchCreatePreviewName\(\), state\)/, "branch worktree creation should
|
|
768
|
-
assert.match(app, /function footerBranchCreateTooltip\(branchName = footerBranchCreateName\(\), state = footerBranchPickerState\)[\s\S]*A branch worktree is a separate checkout for parallel changes\.[\s\S]*does not switch this tab's branch, commit, push, or delete anything[\s\S]*ignored dependencies such as node_modules or \.venv are not copied/, "create worktree button should
|
|
870
|
+
assert.match(app, /function gitWorktreeCreateCommandDisplay\(branch, state = footerBranchPickerState, baseRef = "origin\/main"\)[\s\S]*git worktree add -b[\s\S]*preview\.textContent = gitWorktreeCreateCommandDisplay\(branchName \|\| footerBranchCreatePreviewName\(\), state\)/, "branch worktree creation should preview the default origin/main start point");
|
|
871
|
+
assert.match(app, /function footerBranchCreateTooltip\(branchName = footerBranchCreateName\(\), state = footerBranchPickerState\)[\s\S]*A branch worktree is a separate checkout for parallel changes\.[\s\S]*origin\/main \(default\)[\s\S]*does not switch this tab's branch, commit, push, or delete anything[\s\S]*ignored dependencies such as node_modules or \.venv are not copied/, "create worktree button should explain the base choice and worktree behavior");
|
|
872
|
+
assert.match(html, /id="gitWorktreeBaseDialog"[\s\S]*id="gitWorktreeBaseOriginMain"[^>]*value="origin\/main" checked[\s\S]*id="gitWorktreeBaseCurrentHead"[^>]*value="HEAD"[\s\S]*id="gitWorktreeBaseCreateButton"/, "worktree creation should present an origin/main-default base picker with a current-HEAD alternative");
|
|
873
|
+
assert.match(app, /function chooseGitWorktreeBase\(branch\)[\s\S]*gitWorktreeBaseOriginMain\.checked = true[\s\S]*gitWorktreeBaseCurrentHead\.checked = false/, "the worktree base picker should reset to origin/main for every creation");
|
|
874
|
+
assert.match(css, /\.git-worktree-base-option:has\(input:checked\)[\s\S]*border-color:/, "the selected worktree base should be visibly highlighted");
|
|
769
875
|
assert.match(app, /submitButton\.dataset\.tooltip = footerBranchCreateTooltip\(branchName\);[\s\S]*submitButton\.removeAttribute\("title"\)/, "create branch button should use the styled tooltip instead of a native title tooltip");
|
|
770
876
|
assert.match(css, /\.footer-branch-create-submit\[data-tooltip\]::after \{[\s\S]*?content:\s*attr\(data-tooltip\);[\s\S]*?white-space:\s*pre-wrap;[\s\S]*?overflow-wrap:\s*anywhere;/, "create branch button tooltip should be styled and support detailed multiline copy");
|
|
771
877
|
assert.match(app, /submitButton\.disabled = false;[\s\S]*submitButton\.classList\.toggle\("footer-branch-create-submit-disabled", submitDisabled\);[\s\S]*submitButton\.setAttribute\("aria-disabled", submitDisabled \? "true" : "false"\)/, "branch creation should use aria-disabled styling so the tooltip is not dimmed by disabled button opacity");
|
|
@@ -777,7 +883,7 @@ assert.match(css, /\.footer-branch-option-row \{[\s\S]*?grid-template-columns:\s
|
|
|
777
883
|
assert.match(css, /\.footer-branch-advanced-action:disabled \{[\s\S]*?cursor:\s*not-allowed/, "advanced branch switch action should visibly disable occupied branches");
|
|
778
884
|
assert.match(css, /\.footer-worktree \.footer-meta-value,[\s\S]*?\.footer-tui-worktree \{[\s\S]*?color:\s*var\(--ctp-green\)/, "worktree footer chips should have distinct green styling");
|
|
779
885
|
assert.match(css, /\.workspace-dashboard-action\.worktree \{[\s\S]*?color:\s*var\(--ctp-green\)/, "workspace dashboard should style the branch worktree action distinctly");
|
|
780
|
-
assert.match(app, /async function createFooterGitBranchWorktree\(branch = footerBranchCreateName\(\)[\s\S]*api\("\/api\/git-worktrees", \{ method: "POST", body: \{ branchName, sessionMode: "fork-current", openTab: true \}/, "branch
|
|
886
|
+
assert.match(app, /async function createFooterGitBranchWorktree\(branch = footerBranchCreateName\(\)[\s\S]*chooseGitWorktreeBase\(branchName\)[\s\S]*api\("\/api\/git-worktrees", \{ method: "POST", body: \{ branchName, baseRef, sessionMode: "fork-current", openTab: true \}/, "new footer branch worktrees should ask for and submit the selected base ref");
|
|
781
887
|
assert.match(app, /async function openFooterGitWorktree\(path,[\s\S]*api\("\/api\/git-worktrees\/open", \{ method: "POST", body: \{ path: worktreePath, sessionMode: "fork-current", openTab: true \}/, "existing worktree actions should call the worktree open endpoint");
|
|
782
888
|
assert.match(app, /elements\.newTabWorktreeButton\?\.addEventListener\("click", \(\) => openBranchWorktreePicker\(\)\)/, "new-tab menu branch worktree item should open the picker");
|
|
783
889
|
assert.match(app, /\{ kind: "Git", label: "Branch worktree"[\s\S]*openBranchWorktreePicker\(\)/, "command palette should include branch worktree actions");
|
|
@@ -904,7 +1010,7 @@ assert.match(app, /window\.addEventListener\("storage"[\s\S]*OPTIONAL_FEATURES_S
|
|
|
904
1010
|
assert.match(app, /if \(key === "pi-remote-webui"\) return "remoteWebui"/, "optional feature handling should recognize Remote WebUI widget events without rendering them as overlays");
|
|
905
1011
|
assert.match(app, /REMOTE_WEBUI_CONTROLS_PAYLOAD_TYPE = "firstpick\.pi-package-remote-webui\.controls"/, "Remote WebUI package should announce browser controls through a package-owned status payload");
|
|
906
1012
|
assert.match(app, /function combineIdenticalDuplicateCommands\(commands\)[\s\S]*duplicateGroups[\s\S]*duplicateCount: group\.length/, "identical duplicate RPC commands should be combined into one visible command entry");
|
|
907
|
-
assert.match(app, /if \(kind === "prompt" && attachments\.length === 0\) message = resolveRpcSlashCommandMessage\(message\)/, "manual slash prompts should resolve combined duplicate command aliases before reaching Pi RPC");
|
|
1013
|
+
assert.match(app, /if \(kind === "prompt" && attachments\.length === 0\) message = resolveRpcSlashCommandMessage\(message, \{ tabId: targetTabId \}\)/, "manual targeted slash prompts should resolve combined duplicate command aliases from their captured target tab before reaching Pi RPC");
|
|
908
1014
|
assert.match(app, /if \(!isOptionalFeatureEnabled\("todoProgressWidget"\)\) return String\(text \|\| ""\)/, "todo progress line stripping should only run when the todo feature is detected and enabled");
|
|
909
1015
|
assert.match(app, /const releasePrompt = detectedReleasePrompt && isOptionalFeatureEnabled\(detectedReleasePrompt\.featureId\) \? detectedReleasePrompt : null/, "release confirmation dialogs should use specialized rendering only when their release optional feature is enabled");
|
|
910
1016
|
assert.match(app, /case "webui_tab_reloaded":[\s\S]*resetOptionalFeatureAvailability\(\)/, "optional feature state should reset when the RPC tab reloads resources");
|
|
@@ -939,7 +1045,7 @@ assert.match(css, /\.git-workflow-message-input-row \{[\s\S]*flex:\s*1 1 100%/,
|
|
|
939
1045
|
assert.match(css, /\.git-workflow-actions button\[data-tooltip\]::after \{[\s\S]*content:\s*attr\(data-tooltip\)[\s\S]*white-space:\s*pre-line/, "guided git workflow action tooltips should render multiline step lists");
|
|
940
1046
|
assert.match(app, /function gitBranchNamePromptMessage\(\)[\s\S]*hasAvailableCommand\("git-branch-name"\)[\s\S]*return "\/git-branch-name"/, "guided git workflow should ask the agent to generate PR branch names when the prompt is available");
|
|
941
1047
|
assert.match(app, /async function loadGitWorkflowBranchName\([\s\S]*gitWorkflowRequest\("\/api\/git-workflow\/branch-name"/, "guided git workflow should load generated agent branch names before branch creation");
|
|
942
|
-
assert.match(app, /async function createGitPrBranchWithSuggestion\([\s\S]*prompt\("New PR branch worktree name[\s\S]*gitWorkflowRequest\("\/api\/git-workflow\/branch", \{ body: \{ branch, sessionMode: "fork-current", openTab: true \
|
|
1048
|
+
assert.match(app, /async function createGitPrBranchWithSuggestion\([\s\S]*prompt\("New PR branch worktree name[\s\S]*chooseGitWorktreeBase\(branch\)[\s\S]*assertGuidedGitStagedContentBinding\(tabId, "PR worktree creation"\)[\s\S]*gitWorkflowRequest\("\/api\/git-workflow\/branch", \{ body: \{ branch, baseRef, sessionMode: "fork-current", openTab: true, [\s\S]*expectedStagedContentHash/, "guided git worktrees should ask for a base ref before verifying and carrying staged content");
|
|
943
1049
|
assert.match(app, /function syncGitWorkflowWorktreeTabs\(result\)[\s\S]*Array\.isArray\(result\?\.tabs\)[\s\S]*applyTabMetadata\(result\.tab\)/, "guided git workflow should merge worktree tab metadata returned by the branch endpoint");
|
|
944
1050
|
assert.match(app, /const targetTabId = result\.tab\?\.id[\s\S]*setGitWorkflow\(nextState, \{ tabId: targetTabId \}\)[\s\S]*switchTab\(targetTabId\)/, "guided git workflow should transfer PR state to the opened worktree tab");
|
|
945
1051
|
assert.match(app, /addGitWorkflowAction\("Push and Create PR", \(\) => pushAndCreatePrGitWorkflow\(\), "primary", false\)/, "guided git workflow should replace push with Push and Create PR in PR mode");
|
|
@@ -954,7 +1060,7 @@ assert.match(server, /async function startGitWorkflowGeneration\([\s\S]*set_mode
|
|
|
954
1060
|
assert.match(server, /event\?\.type === "agent_settled"[\s\S]*restoreGitWorkflowGenerationProfile\(tab\)/, "server should restore the active tab model and effort after generation settles");
|
|
955
1061
|
assert.match(server, /case "\/api\/git-workflow\/branch-name":[\s\S]*readGitWorkflowBranchName\(cwd\)/, "server should expose generated branch-name file loading for the guided PR workflow");
|
|
956
1062
|
assert.match(server, /case "\/api\/git-workflow\/branch":[\s\S]*createGitWorkflowBranchWorktree\(tab, body\)/, "server should route guided PR branch creation through worktree tabs");
|
|
957
|
-
assert.match(server, /async function createGitWorkflowBranchWorktree\(tab, body = \{\}\)[\s\S]*snapshotGitWorkflowBranchState\(root, tab\.cwd\)[\s\S]*applyGitWorkflowBranchStateToWorktree\(snapshot, worktreePath\)[\s\S]*openWorktreeResultForTab\(tab, createdResult/, "guided PR worktree creation should copy staged state before opening the worktree tab");
|
|
1063
|
+
assert.match(server, /async function createGitWorkflowBranchWorktree\(tab, body = \{\}\)[\s\S]*expectedStagedContentHashFromBody\(body\)[\s\S]*snapshotGitWorkflowBranchState\(root, tab\.cwd, expectedStagedContentHash\)[\s\S]*applyGitWorkflowBranchStateToWorktree\(snapshot, worktreePath\)[\s\S]*openWorktreeResultForTab\(tab, createdResult/, "guided PR worktree creation should verify and copy exact staged state before opening the worktree tab");
|
|
958
1064
|
assert.match(server, /case "\/api\/git-workflow\/create-pr":[\s\S]*runGitHubWorkflowCommand\(\["pr", "create"/, "server should create PRs with the GitHub CLI after confirmation");
|
|
959
1065
|
assert.doesNotMatch(app, /gitWorkflowVisibleTabId|Workflow belongs to/, "guided git workflow should not pin or show workflows outside their owning terminal tab");
|
|
960
1066
|
assert.match(app, /function renderReleaseNpmOutputWidget\(\)/, "release-npm live output should use a specialized Web UI renderer");
|
|
@@ -1290,7 +1396,7 @@ assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(p
|
|
|
1290
1396
|
assert.match(css, /@media \(max-width: 720px\), \(max-device-width: 720px\), \(pointer: coarse\) and \(hover: none\) \{[\s\S]*?\.terminal-tab-group-menu \{[\s\S]*?grid-column:\s*1 \/ -1;[\s\S]*?margin:\s*0\.34rem 0 0;/, "mobile terminal tab group menus should not add horizontal margins that overflow and distort the tab card");
|
|
1291
1397
|
assert.match(app, /let openTerminalTabGroupKey = null/, "frontend should track the open terminal tab group across tab bar rerenders");
|
|
1292
1398
|
assert.match(app, /function updateTerminalTabGroupOpenState\(\)/, "frontend should be able to reapply open terminal tab group state after rerenders");
|
|
1293
|
-
assert.match(app, /classList\.toggle\("terminal-tabs-dense",
|
|
1399
|
+
assert.match(app, /const totalTabCount = tabs\.length \+ subagentTerminalViews\.size;[\s\S]*classList\.toggle\("terminal-tabs-dense", totalTabCount >= 10\)/, "frontend should include virtual subagent tabs when enabling dense tab layout");
|
|
1294
1400
|
assert.match(app, /appendTerminalTabContent\(button, \{ title: activeTitle,[\s\S]*?count: groupTabs\.length,[^}]*\}\)/, "group buttons should show the active terminal name instead of only the cwd label");
|
|
1295
1401
|
assert.match(app, /wrapper\.addEventListener\("pointerenter", \(\) => setOpenTerminalTabGroup\(group\.key\)\)/, "terminal tab groups should mark themselves open while hovered");
|
|
1296
1402
|
assert.match(app, /if \(openTerminalTabGroupKey\) \{\n\s+scheduleRefreshTabs\(600\);/, "tab polling should defer full tab refreshes while a group menu is open");
|
|
@@ -1304,6 +1410,8 @@ assert.match(app, /function closeAllTerminalTabs\(\)[\s\S]*?closeTerminalTabs\(t
|
|
|
1304
1410
|
assert.match(app, /WARNING: \$\{activeAgentTabs\.length\}[\s\S]*?still running or waiting for input/, "tab close confirmations should warn when agents are still running");
|
|
1305
1411
|
assert.match(app, /elements\.closeAllTabsButton\.addEventListener\("click", \(\) => closeAllTerminalTabs\(\)\)/, "close-all tabs button should be wired in JS");
|
|
1306
1412
|
assert.match(app, /const groups = tabCwdGroups\(\);[\s\S]*?for \(const group of groups\) \{\n\s+if \(shouldRenderTerminalTabGroup\(group, groups\.length\)\)[\s\S]*?renderTerminalTabGroup\(group, groups\.length\)[\s\S]*?for \(const tab of group\.tabs\) elements\.tabBar\.append\(renderTerminalTab\(tab\)\);/, "terminal tabs should render groups with group count and ungrouped tabs when grouping is skipped");
|
|
1413
|
+
assert.match(app, /for \(const view of \[\.\.\.subagentTerminalViews\.values\(\)\][\s\S]*renderSubagentTerminalTab\(view\)/, "open subagent views should render as first-class virtual terminal tabs");
|
|
1414
|
+
assert.match(readme, /Tracked subagent output[\s\S]*dedicated \*\*Subagent\*\* terminal tab[\s\S]*view-only[\s\S]*close without stopping or interrupting/, "README should document the selectable view-only child terminal behavior");
|
|
1307
1415
|
assert.match(app, /let tabSeenCompletionSerials = new Map\(\)/, "frontend should track which tab completions have been seen");
|
|
1308
1416
|
assert.match(app, /let activeTabGeneration = 0/, "frontend should version active-tab UI state to reject stale async work");
|
|
1309
1417
|
assert.match(app, /function isCurrentTabContext\(context\)/, "frontend should identify stale active-tab refresh contexts");
|
|
@@ -1601,6 +1709,9 @@ for (const [name, range] of Object.entries(companionDependencies)) {
|
|
|
1601
1709
|
}
|
|
1602
1710
|
assert.equal(pkg.bundledDependencies, undefined, "webui optional companion packages should not be bundled into the tarball");
|
|
1603
1711
|
assert.equal(pkg.optionalDependencies?.["@firstpick/pi-package-natural-conversation"], undefined, "webui package should not optionally depend on the standalone Natural Conversation package");
|
|
1712
|
+
assert.equal(pkg.optionalDependencies?.["@firstpick/pi-extension-aur-review"], undefined, "webui package should not reference the unpublished aur-review extension");
|
|
1713
|
+
assert.equal(lock.packages?.["node_modules/@firstpick/pi-extension-aur-review"], undefined, "package lock should not retain an unpublished aur-review tarball");
|
|
1714
|
+
assert.ok(!pkg.pi?.extensions?.some((entry) => String(entry).includes("pi-extension-aur-review")), "webui Pi manifest should not bundle the unpublished aur-review path");
|
|
1604
1715
|
assert.ok(!pkg.pi?.extensions?.some((entry) => String(entry).includes("pi-package-natural-conversation")), "webui Pi manifest should not load Natural Conversation directly; /talk must come from the standalone package");
|
|
1605
1716
|
assert.ok(pkg.pi?.extensions?.includes("./index.ts"), "webui Pi manifest should load its own extension");
|
|
1606
1717
|
for (const extensionPath of [
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { chmod, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
|
+
|
|
9
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
+
const workspaceRoot = join(root, "..");
|
|
11
|
+
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
12
|
+
const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
13
|
+
const reviewModuleUrl = pathToFileURL(join(workspaceRoot, "pi-extension-aur-review", "src", "git.ts")).href;
|
|
14
|
+
const port = 41000 + Math.floor(Math.random() * 10000);
|
|
15
|
+
|
|
16
|
+
function git(cwd, ...args) {
|
|
17
|
+
const result = spawnSync("git", args, { cwd, encoding: "utf8" });
|
|
18
|
+
assert.equal(result.status, 0, `git ${args.join(" ")} failed:\n${result.stderr || result.stdout}`);
|
|
19
|
+
return result.stdout;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function request(pathname, { method = "GET", body } = {}) {
|
|
23
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
24
|
+
method,
|
|
25
|
+
headers: body === undefined ? undefined : { "content-type": "application/json" },
|
|
26
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
27
|
+
signal: AbortSignal.timeout(8_000),
|
|
28
|
+
});
|
|
29
|
+
return { status: response.status, body: await response.json().catch(() => ({})) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function extensionSnapshot(repo) {
|
|
33
|
+
const script = `
|
|
34
|
+
import { captureGitSnapshot } from ${JSON.stringify(reviewModuleUrl)};
|
|
35
|
+
try {
|
|
36
|
+
const snapshot = await captureGitSnapshot(process.env.HASH_CONTRACT_REPO, [], "staged");
|
|
37
|
+
process.stdout.write(JSON.stringify({ ok: true, stagedContentHash: snapshot.stagedContentHash }));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
process.stdout.write(JSON.stringify({ ok: false, error: error instanceof Error ? error.message : String(error) }));
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
const result = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module", "--eval", script], {
|
|
43
|
+
encoding: "utf8",
|
|
44
|
+
env: { ...process.env, HASH_CONTRACT_REPO: repo },
|
|
45
|
+
});
|
|
46
|
+
assert.equal(result.status, 0, `extension hash helper failed: ${result.stderr}`);
|
|
47
|
+
return JSON.parse(result.stdout);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const repo = await mkdtemp(path.join(tmpdir(), "pi-webui-staged-hash-contract-"));
|
|
51
|
+
const agentDir = await mkdtemp(path.join(tmpdir(), "pi-webui-staged-hash-agent-"));
|
|
52
|
+
await chmod(fakePi, 0o755);
|
|
53
|
+
const child = spawn(process.execPath, [serverScript, "--cwd", repo, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
54
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
55
|
+
env: {
|
|
56
|
+
...process.env,
|
|
57
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
58
|
+
PI_WEBUI_SETTINGS_FILE: path.join(agentDir, "settings.json"),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
let serverOutput = "";
|
|
62
|
+
child.stdout.on("data", (chunk) => { serverOutput += String(chunk); });
|
|
63
|
+
child.stderr.on("data", (chunk) => { serverOutput += String(chunk); });
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
let health;
|
|
67
|
+
for (let attempt = 0; attempt < 60; attempt++) {
|
|
68
|
+
try {
|
|
69
|
+
health = await request("/api/health");
|
|
70
|
+
if (health.status === 200) break;
|
|
71
|
+
} catch {
|
|
72
|
+
// Server is still starting.
|
|
73
|
+
}
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
75
|
+
}
|
|
76
|
+
assert.equal(health?.status, 200, `server did not start:\n${serverOutput}`);
|
|
77
|
+
const tabs = await request("/api/tabs");
|
|
78
|
+
const tabId = tabs.body?.data?.tabs?.[0]?.id;
|
|
79
|
+
assert.ok(tabId, "contract server should expose its startup tab");
|
|
80
|
+
const staged = async () => {
|
|
81
|
+
const result = await request(`/api/git-workflow/staged-content?tab=${encodeURIComponent(tabId)}`);
|
|
82
|
+
assert.equal(result.status, 200, `staged-content endpoint should be read-only and available: ${result.body?.error || ""}`);
|
|
83
|
+
assert.equal(result.body?.ok, true, result.body?.error || "staged-content endpoint failed");
|
|
84
|
+
return result.body.data;
|
|
85
|
+
};
|
|
86
|
+
const assertMatchesExtension = async (label) => {
|
|
87
|
+
const server = await staged();
|
|
88
|
+
const extension = extensionSnapshot(repo);
|
|
89
|
+
assert.equal(server.hasStagedChanges, true, `${label}: server should find staged content`);
|
|
90
|
+
assert.equal(extension.ok, true, `${label}: extension should capture staged content (${extension.error || ""})`);
|
|
91
|
+
assert.match(server.stagedContentHash || "", /^[a-f0-9]{64}$/i, `${label}: server should return a SHA-256 staged-content hash`);
|
|
92
|
+
assert.equal(server.stagedContentHash, extension.stagedContentHash, `${label}: extension and server staged-content hashes must match`);
|
|
93
|
+
return server.stagedContentHash;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
git(repo, "init", "-q");
|
|
97
|
+
git(repo, "config", "user.name", "Hash Contract");
|
|
98
|
+
git(repo, "config", "user.email", "hash-contract@example.invalid");
|
|
99
|
+
|
|
100
|
+
// Empty/unborn state has no substantive index content and exposes no token.
|
|
101
|
+
assert.deepEqual(await staged(), { root: repo, hasStagedChanges: false, stagedContentHash: null });
|
|
102
|
+
const emptyExtension = extensionSnapshot(repo);
|
|
103
|
+
assert.equal(emptyExtension.ok, false, "extension should reject an empty staged review");
|
|
104
|
+
assert.match(emptyExtension.error, /No substantive staged changes/i);
|
|
105
|
+
|
|
106
|
+
// Unborn HEAD must use the index-vs-empty-tree diff without a HEAD lookup.
|
|
107
|
+
await writeFile(path.join(repo, "normal.txt"), "unborn normal\n");
|
|
108
|
+
git(repo, "add", "normal.txt");
|
|
109
|
+
await assertMatchesExtension("unborn normal");
|
|
110
|
+
git(repo, "commit", "-qm", "base");
|
|
111
|
+
await writeFile(path.join(repo, "deleted.txt"), "delete\n");
|
|
112
|
+
await writeFile(path.join(repo, "rename-from.txt"), "rename\n");
|
|
113
|
+
git(repo, "add", ".");
|
|
114
|
+
git(repo, "commit", "-qm", "fixtures");
|
|
115
|
+
|
|
116
|
+
const reset = () => git(repo, "reset", "--hard", "HEAD");
|
|
117
|
+
await writeFile(path.join(repo, "normal.txt"), "ordinary staged edit\n");
|
|
118
|
+
git(repo, "add", "normal.txt");
|
|
119
|
+
await assertMatchesExtension("normal text");
|
|
120
|
+
reset();
|
|
121
|
+
|
|
122
|
+
await writeFile(path.join(repo, "binary.bin"), Buffer.from([0, 1, 2, 0xff, 0x0a]));
|
|
123
|
+
git(repo, "add", "binary.bin");
|
|
124
|
+
await assertMatchesExtension("binary");
|
|
125
|
+
reset();
|
|
126
|
+
|
|
127
|
+
await writeFile(path.join(repo, "normal.txt"), "#!/bin/sh\necho mode\n");
|
|
128
|
+
await chmod(path.join(repo, "normal.txt"), 0o755);
|
|
129
|
+
git(repo, "add", "normal.txt");
|
|
130
|
+
await assertMatchesExtension("mode");
|
|
131
|
+
reset();
|
|
132
|
+
|
|
133
|
+
await symlink("normal.txt", path.join(repo, "normal-link"));
|
|
134
|
+
git(repo, "add", "normal-link");
|
|
135
|
+
await assertMatchesExtension("symlink");
|
|
136
|
+
reset();
|
|
137
|
+
|
|
138
|
+
await writeFile(path.join(repo, "added.txt"), "added\n");
|
|
139
|
+
git(repo, "rm", "-q", "deleted.txt");
|
|
140
|
+
git(repo, "mv", "rename-from.txt", "rename-to.txt");
|
|
141
|
+
git(repo, "add", "added.txt");
|
|
142
|
+
await assertMatchesExtension("add delete rename");
|
|
143
|
+
reset();
|
|
144
|
+
|
|
145
|
+
// A server mutation rechecks an untrusted expected token at its own action
|
|
146
|
+
// boundary, rejecting drift before either generation or commit can consume it.
|
|
147
|
+
await writeFile(path.join(repo, "normal.txt"), "approved v1\n");
|
|
148
|
+
git(repo, "add", "normal.txt");
|
|
149
|
+
const approvedHash = await assertMatchesExtension("post-approval baseline");
|
|
150
|
+
await writeFile(path.join(repo, "normal.txt"), "drifted v2\n");
|
|
151
|
+
git(repo, "add", "normal.txt");
|
|
152
|
+
const driftedGeneration = await request("/api/git-workflow/generate", { method: "POST", body: { tab: tabId, kind: "commit", expectedStagedContentHash: approvedHash } });
|
|
153
|
+
assert.equal(driftedGeneration.status, 409, "staged drift must be rejected before commit-message generation");
|
|
154
|
+
assert.match(driftedGeneration.body?.error || "", /Staged content changed after manual approval/i);
|
|
155
|
+
const driftedCommit = await request("/api/git-workflow/commit", { method: "POST", body: { tab: tabId, variant: "input", message: "must not commit", expectedStagedContentHash: approvedHash } });
|
|
156
|
+
assert.equal(driftedCommit.status, 200);
|
|
157
|
+
assert.equal(driftedCommit.body?.ok, false, "staged drift must be rejected before commit");
|
|
158
|
+
assert.match(driftedCommit.body?.error || "", /Staged content changed after manual approval/i);
|
|
159
|
+
reset();
|
|
160
|
+
|
|
161
|
+
assert.deepEqual(await staged(), { root: repo, hasStagedChanges: false, stagedContentHash: null }, "reset index should return the no-staged state");
|
|
162
|
+
const resetExtension = extensionSnapshot(repo);
|
|
163
|
+
assert.equal(resetExtension.ok, false, "extension should reject reset/no-staged content");
|
|
164
|
+
|
|
165
|
+
console.log("staged content hash contract tests passed");
|
|
166
|
+
} finally {
|
|
167
|
+
child.kill("SIGTERM");
|
|
168
|
+
await Promise.race([
|
|
169
|
+
new Promise((resolve) => child.once("close", resolve)),
|
|
170
|
+
new Promise((resolve) => setTimeout(resolve, 2_000)),
|
|
171
|
+
]);
|
|
172
|
+
if (child.exitCode === null) child.kill("SIGKILL");
|
|
173
|
+
await Promise.all([rm(repo, { recursive: true, force: true }), rm(agentDir, { recursive: true, force: true })]);
|
|
174
|
+
}
|
|
@@ -63,11 +63,12 @@ const ctx = {
|
|
|
63
63
|
const asyncRunDir = await mkdtemp(path.join(tmpdir(), "pi-webui-subagent-output-test-"));
|
|
64
64
|
const asyncSessionFile = path.join(asyncRunDir, "reviewer-session.jsonl");
|
|
65
65
|
await writeFile(asyncSessionFile, [
|
|
66
|
-
JSON.stringify({ type: "message", message: { role: "assistant", content: [{ type: "text", text: "REVIEWER STREAM 1 OF 18" }, { type: "toolCall", name: "bash", arguments: { command: "sleep 5" } }] } }),
|
|
67
|
-
JSON.stringify({ type: "message", message: { role: "toolResult", content: [{ type: "text", text: "(no output)\nreviewer tool output line" }] } }),
|
|
66
|
+
JSON.stringify({ type: "message", timestamp: "2026-07-19T12:00:00.000Z", message: { role: "assistant", content: [{ type: "thinking", thinking: "Checking structured transcript extraction" }, { type: "text", text: "REVIEWER STREAM 1 OF 18" }, { type: "toolCall", id: "review-call", name: "bash", arguments: { command: "sleep 5" } }, { type: "text", text: "Review complete." }] } }),
|
|
67
|
+
JSON.stringify({ type: "message", timestamp: "2026-07-19T12:00:01.000Z", message: { role: "toolResult", toolCallId: "review-call", toolName: "bash", isError: false, content: [{ type: "text", text: "(no output)\nreviewer tool output line" }] } }),
|
|
68
68
|
"",
|
|
69
69
|
].join("\n"));
|
|
70
|
-
|
|
70
|
+
const asyncStatusFile = path.join(asyncRunDir, "status.json");
|
|
71
|
+
await writeFile(asyncStatusFile, JSON.stringify({
|
|
71
72
|
runId: "run-a",
|
|
72
73
|
mode: "parallel",
|
|
73
74
|
state: "running",
|
|
@@ -136,8 +137,85 @@ assert.equal(asyncOutputResponse.ok, true);
|
|
|
136
137
|
assert.deepEqual(asyncOutputResponse.data.agent.recentOutput, [
|
|
137
138
|
"REVIEWER STREAM 1 OF 18",
|
|
138
139
|
"▶ bash {\"command\":\"sleep 5\"}",
|
|
140
|
+
"Review complete.",
|
|
139
141
|
"reviewer tool output line",
|
|
140
|
-
], "async output should
|
|
142
|
+
], "async output should remain available as a bounded text fallback when status recentOutput is empty");
|
|
143
|
+
assert.deepEqual(asyncOutputResponse.data.agent.transcript, [
|
|
144
|
+
{
|
|
145
|
+
role: "assistant",
|
|
146
|
+
timestamp: "2026-07-19T12:00:00.000Z",
|
|
147
|
+
content: [
|
|
148
|
+
{ type: "thinking", thinking: "Checking structured transcript extraction" },
|
|
149
|
+
{ type: "text", text: "REVIEWER STREAM 1 OF 18" },
|
|
150
|
+
{ type: "toolCall", id: "review-call", name: "bash", arguments: "{\"command\":\"sleep 5\"}" },
|
|
151
|
+
{ type: "text", text: "Review complete." },
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
role: "toolResult",
|
|
156
|
+
timestamp: "2026-07-19T12:00:01.000Z",
|
|
157
|
+
toolCallId: "review-call",
|
|
158
|
+
toolName: "bash",
|
|
159
|
+
content: [{ type: "text", text: "reviewer tool output line" }],
|
|
160
|
+
},
|
|
161
|
+
], "async output should preserve assistant thinking, tool calls, final text, and tool results for the main transcript renderer");
|
|
162
|
+
|
|
163
|
+
const boundedSessionFile = path.join(asyncRunDir, "bounded-reviewer-session.jsonl");
|
|
164
|
+
await writeFile(boundedSessionFile, Array.from({ length: 122 }, (_unused, index) => JSON.stringify({
|
|
165
|
+
type: "message",
|
|
166
|
+
timestamp: `2026-07-19T12:01:${String(index).padStart(2, "0")}.000Z`,
|
|
167
|
+
message: { role: "assistant", content: [{ type: "text", text: `bounded transcript line ${index}` }] },
|
|
168
|
+
})).join("\n"));
|
|
169
|
+
await writeFile(asyncStatusFile, JSON.stringify({
|
|
170
|
+
runId: "run-a",
|
|
171
|
+
mode: "parallel",
|
|
172
|
+
state: "running",
|
|
173
|
+
startedAt: Date.now() - 1000,
|
|
174
|
+
lastUpdate: Date.now(),
|
|
175
|
+
steps: [{ agent: "reviewer", status: "running", sessionFile: boundedSessionFile }],
|
|
176
|
+
}));
|
|
177
|
+
await helperCommand.handler(JSON.stringify({
|
|
178
|
+
requestId: "bounded-subagent-output-test",
|
|
179
|
+
action: "subagent-output",
|
|
180
|
+
payload: { runId: "run-a", agentId: "run-a:step:0:reviewer" },
|
|
181
|
+
}), ctx);
|
|
182
|
+
const boundedOutputNotice = notifications.find((entry) => entry.message.startsWith("__PI_WEBUI_HELPER_RESPONSE__:")
|
|
183
|
+
&& JSON.parse(entry.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length)).requestId === "bounded-subagent-output-test");
|
|
184
|
+
assert.ok(boundedOutputNotice, "bounded async output helper action should return a response notification");
|
|
185
|
+
const boundedOutputResponse = JSON.parse(boundedOutputNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
186
|
+
assert.equal(boundedOutputResponse.data.agent.recentOutput.length, 120, "structured child extraction should retain the existing 120-line output bound");
|
|
187
|
+
assert.equal(boundedOutputResponse.data.agent.recentOutput[0], "bounded transcript line 2");
|
|
188
|
+
assert.equal(boundedOutputResponse.data.agent.recentOutput.at(-1), "bounded transcript line 121");
|
|
189
|
+
assert.equal(boundedOutputResponse.data.agent.transcript.length, 120, "structured child extraction should apply the same tail bound to rendered entries");
|
|
190
|
+
|
|
191
|
+
const incompleteToolSessionFile = path.join(asyncRunDir, "incomplete-tool-session.jsonl");
|
|
192
|
+
await writeFile(incompleteToolSessionFile, JSON.stringify({
|
|
193
|
+
type: "message",
|
|
194
|
+
timestamp: "2026-07-19T12:02:00.000Z",
|
|
195
|
+
message: { role: "assistant", content: [{ type: "toolCall", id: "tail-call", name: "read", arguments: { path: "README.md" } }] },
|
|
196
|
+
}));
|
|
197
|
+
await writeFile(asyncStatusFile, JSON.stringify({
|
|
198
|
+
runId: "run-a",
|
|
199
|
+
mode: "parallel",
|
|
200
|
+
state: "running",
|
|
201
|
+
startedAt: Date.now() - 1000,
|
|
202
|
+
lastUpdate: Date.now(),
|
|
203
|
+
steps: [{ agent: "reviewer", status: "running", sessionFile: incompleteToolSessionFile }],
|
|
204
|
+
}));
|
|
205
|
+
await helperCommand.handler(JSON.stringify({
|
|
206
|
+
requestId: "incomplete-tool-subagent-output-test",
|
|
207
|
+
action: "subagent-output",
|
|
208
|
+
payload: { runId: "run-a", agentId: "run-a:step:0:reviewer" },
|
|
209
|
+
}), ctx);
|
|
210
|
+
const incompleteToolNotice = notifications.find((entry) => entry.message.startsWith("__PI_WEBUI_HELPER_RESPONSE__:")
|
|
211
|
+
&& JSON.parse(entry.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length)).requestId === "incomplete-tool-subagent-output-test");
|
|
212
|
+
assert.ok(incompleteToolNotice, "incomplete tool output helper action should return a response notification");
|
|
213
|
+
const incompleteToolResponse = JSON.parse(incompleteToolNotice.message.slice("__PI_WEBUI_HELPER_RESPONSE__:".length));
|
|
214
|
+
assert.deepEqual(incompleteToolResponse.data.agent.transcript, [{
|
|
215
|
+
role: "assistant",
|
|
216
|
+
timestamp: "2026-07-19T12:02:00.000Z",
|
|
217
|
+
content: [{ type: "toolCall", id: "tail-call", name: "read", arguments: "{\"path\":\"README.md\"}" }],
|
|
218
|
+
}], "a live or truncated session tail should retain an unpaired tool call for a pending tool card");
|
|
141
219
|
|
|
142
220
|
for (const handler of extensionHandlers.get("tool_execution_start") || []) {
|
|
143
221
|
handler({
|
|
@@ -195,6 +273,7 @@ assert.equal(outputResponse.ok, true);
|
|
|
195
273
|
assert.equal(outputResponse.data.agent.currentTool, "bash");
|
|
196
274
|
assert.equal(outputResponse.data.agent.currentToolArgs, "npm test");
|
|
197
275
|
assert.deepEqual(outputResponse.data.agent.recentOutput, ["Running focused tests", "12 assertions passed"]);
|
|
276
|
+
assert.deepEqual(outputResponse.data.agent.transcript, [], "foreground snapshots without a child session transcript should retain the recentOutput-only fallback");
|
|
198
277
|
assert.deepEqual(outputResponse.data.agent.recentTools, [{ tool: "read", args: "package.json", endMs: 1000 }]);
|
|
199
278
|
|
|
200
279
|
for (const handler of extensionHandlers.get("tool_execution_end") || []) {
|