@firstpick/pi-package-webui 0.11.0 → 0.11.2
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/DEVELOPMENT.md +181 -12
- package/README.md +41 -9
- package/TECHNICAL.md +91 -8
- package/bin/pi-webui.mjs +5432 -11428
- package/index.ts +10 -3
- package/lib/codex-cli-usage.mjs +232 -0
- package/lib/codex-usage-auth.mjs +39 -3
- package/lib/codex-usage-source.mjs +36 -0
- package/lib/component-update-state.mjs +2 -2
- package/lib/git-workflow-preference-values.mjs +122 -0
- package/lib/git-workflow-preferences.mjs +35 -563
- package/lib/package-updates.mjs +260 -0
- package/lib/rpc-supervisor-client.mjs +8 -4
- package/lib/server/app-runners.mjs +1667 -0
- package/lib/server/codex-fast-mode.mjs +161 -0
- package/lib/server/conversation-mode.mjs +218 -0
- package/lib/server/conversation-voice.mjs +318 -0
- package/lib/server/extension-ui-requests.mjs +114 -0
- package/lib/server/git-generation.mjs +459 -0
- package/lib/server/git-mutations.mjs +1827 -0
- package/lib/server/git-reads.mjs +608 -0
- package/lib/server/git-worktree-sessions.mjs +408 -0
- package/lib/server/helper-requests.mjs +82 -0
- package/lib/server/no-project-workspaces.mjs +103 -0
- package/lib/server/rpc-transports.mjs +394 -0
- package/lib/server/settings-store.mjs +544 -0
- package/lib/server/sse-delivery.mjs +138 -0
- package/lib/server/workspace-files.mjs +563 -0
- package/lib/update/supervisor.mjs +4 -0
- package/lib/webui-workspaces.mjs +2 -0
- package/package.json +5 -5
- package/public/activity-agents-controller.mjs +269 -0
- package/public/activity-events-controller.mjs +236 -0
- package/public/activity-intercom-controller.mjs +627 -0
- package/public/activity-queue-controller.mjs +534 -0
- package/public/activity-todo-view.mjs +89 -0
- package/public/activity-usage-controller.mjs +589 -0
- package/public/app.js +3761 -3878
- package/public/conversation-overview.css +84 -0
- package/public/conversation-overview.mjs +193 -0
- package/public/draft-conversations.mjs +135 -0
- package/public/focused-composer-controls.css +111 -0
- package/public/focused-composer-controls.mjs +143 -0
- package/public/focused-composer-disclosure.mjs +223 -0
- package/public/focused-shell-adapter.css +264 -0
- package/public/focused-shell-adapter.mjs +257 -0
- package/public/index.html +137 -80
- package/public/model-catalog-order.mjs +63 -0
- package/public/platform-event-stream.mjs +64 -0
- package/public/project-artifact-controller.mjs +218 -0
- package/public/project-file-viewer-controller.mjs +383 -0
- package/public/project-git-tools-controller.mjs +181 -0
- package/public/project-runners-controller.mjs +220 -0
- package/public/service-worker.js +52 -1
- package/public/session-attention-scheduler.mjs +182 -0
- package/public/session-composer-store.mjs +56 -0
- package/public/session-context.mjs +51 -0
- package/public/session-extension-requests.mjs +63 -0
- package/public/session-shelf-state.mjs +151 -0
- package/public/session-shelves.css +171 -0
- package/public/session-shelves.mjs +95 -0
- package/public/settings-navigation-controller.mjs +249 -0
- package/public/settings-navigation.css +61 -0
- package/public/settings-resource-controller.mjs +232 -0
- package/public/settings-workspace.css +19 -0
- package/public/settings-workspace.mjs +175 -0
- package/public/shell-actions.mjs +87 -0
- package/public/shell-attention-inbox.css +72 -0
- package/public/shell-attention-inbox.mjs +198 -0
- package/public/shell-context-actions.css +61 -0
- package/public/shell-context-actions.mjs +168 -0
- package/public/shell-inspector-resize.mjs +124 -0
- package/public/shell-navigation-resize.mjs +107 -0
- package/public/shell-navigation.mjs +127 -0
- package/public/shell-preferences.mjs +108 -0
- package/public/shell-surfaces.mjs +99 -0
- package/public/shell-tools-launcher.css +97 -0
- package/public/shell-tools-launcher.mjs +222 -0
- package/public/shell-view-host.mjs +115 -0
- package/public/shell-workspace.css +266 -0
- package/public/shell-workspace.mjs +402 -0
- package/public/sidebar-update-menu.css +190 -0
- package/public/sidebar-update-menu.mjs +512 -0
- package/public/styles.css +320 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- package/public/theme-contract.mjs +1 -1
- package/public/themed-selects.css +156 -0
- package/public/workspace-choices.mjs +104 -0
- package/tests/activity-agents-controller.test.mjs +652 -0
- package/tests/activity-events-controller.test.mjs +511 -0
- package/tests/app-runner-terminal-static.test.mjs +3 -3
- package/tests/append-system-http.test.mjs +7 -6
- package/tests/append-system-selector-static.test.mjs +6 -6
- package/tests/aur-review-widget-static.test.mjs +11 -3
- package/tests/boot-failure-diagnostics.test.mjs +8 -3
- package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
- package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
- package/tests/browser/activity-owner-integration.spec.mjs +201 -0
- package/tests/browser/activity-queue-controller.spec.mjs +405 -0
- package/tests/browser/activity-section-picker.spec.mjs +294 -0
- package/tests/browser/activity-todo-view.spec.mjs +60 -0
- package/tests/browser/activity-usage-controller.spec.mjs +416 -0
- package/tests/browser/compact-layout-integration.spec.mjs +58 -0
- package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
- package/tests/browser/composer-disclosure.spec.mjs +389 -0
- package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
- package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
- package/tests/browser/control-visibility.spec.mjs +5 -0
- package/tests/browser/controls-layout.spec.mjs +21 -2
- package/tests/browser/conversation-overview.spec.mjs +251 -0
- package/tests/browser/draft-conversations.spec.mjs +276 -0
- package/tests/browser/empty-startup-fixture.mjs +135 -0
- package/tests/browser/empty-startup.spec.mjs +282 -0
- package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
- package/tests/browser/focused-composer-more.spec.mjs +127 -0
- package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
- package/tests/browser/focused-navigation-fixture.mjs +32 -0
- package/tests/browser/focused-project-activity.spec.mjs +111 -0
- package/tests/browser/focused-shell-integration.spec.mjs +208 -0
- package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
- package/tests/browser/folder-picker-layout.spec.mjs +302 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
- package/tests/browser/git-setup-cancel.spec.mjs +251 -0
- package/tests/browser/guided-git-fallback.spec.mjs +40 -21
- package/tests/browser/inspector-header.spec.mjs +221 -0
- package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
- package/tests/browser/inspector-resize.spec.mjs +227 -0
- package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
- package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
- package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
- package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
- package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
- package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
- package/tests/browser/interaction-continuity.spec.mjs +50 -26
- package/tests/browser/interaction-model-picker.spec.mjs +86 -0
- package/tests/browser/last-terminal-close.spec.mjs +280 -0
- package/tests/browser/mobile-foundation.spec.mjs +172 -20
- package/tests/browser/model-catalog-groups.spec.mjs +104 -0
- package/tests/browser/more-row-menus.spec.mjs +258 -0
- package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
- package/tests/browser/no-project-conversation.spec.mjs +113 -0
- package/tests/browser/optimistic-prompt.spec.mjs +3 -0
- package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
- package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
- package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
- package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
- package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
- package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
- package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
- package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
- package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
- package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
- package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
- package/tests/browser/project-artifact-controller.spec.mjs +324 -0
- package/tests/browser/project-artifact-integration.spec.mjs +103 -0
- package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
- package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
- package/tests/browser/session-fixture.mjs +118 -0
- package/tests/browser/session-ownership.spec.mjs +175 -0
- package/tests/browser/session-shelves-integration.spec.mjs +219 -0
- package/tests/browser/session-shelves.spec.mjs +340 -0
- package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
- package/tests/browser/session-summary.spec.mjs +17 -12
- package/tests/browser/settings-complete-home.spec.mjs +463 -0
- package/tests/browser/settings-entrypoint.spec.mjs +104 -0
- package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
- package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
- package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
- package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
- package/tests/browser/shell-ownership.spec.mjs +398 -0
- package/tests/browser/shell-rollout-fixture.mjs +259 -0
- package/tests/browser/shell-rollout.spec.mjs +357 -0
- package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
- package/tests/browser/shell-workspace.spec.mjs +433 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
- package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
- package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
- package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
- package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
- package/tests/browser/stream-output-isolation.spec.mjs +6 -3
- package/tests/browser/themed-selects.spec.mjs +297 -0
- package/tests/browser/thread-start-flow.spec.mjs +481 -0
- package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
- package/tests/browser/ui-polish-features.spec.mjs +85 -0
- package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
- package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
- package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
- package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
- package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
- package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
- package/tests/browser/windows-drive-parent.spec.mjs +4 -2
- package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
- package/tests/codex-cli-usage.test.mjs +189 -0
- package/tests/codex-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-auth.test.mjs +168 -9
- package/tests/codex-usage-http.test.mjs +124 -0
- package/tests/codex-usage-source.test.mjs +146 -0
- package/tests/component-update-api-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +9 -4
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +5 -5
- package/tests/conversation-overview-adapter.test.mjs +100 -0
- package/tests/document-artifact-static.test.mjs +2 -1
- package/tests/draft-conversations.test.mjs +205 -0
- package/tests/empty-startup-launcher.test.mjs +197 -0
- package/tests/events-tree-context-menu-static.test.mjs +22 -18
- package/tests/fake-pi-session-ownership.test.mjs +302 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +15 -11
- package/tests/file-viewer-search-static.test.mjs +5 -5
- package/tests/fixtures/fake-codex-app-server.mjs +61 -0
- package/tests/fixtures/fake-pi.mjs +41 -9
- package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
- package/tests/git-footer-context-menu-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +41 -48
- package/tests/git-panel-live-updates-static.test.mjs +2 -1
- package/tests/git-workflow-dispatch.test.mjs +66 -0
- package/tests/git-workflow-preferences.test.mjs +9 -1
- package/tests/guided-git-activation-static.test.mjs +14 -11
- package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
- package/tests/guided-git-message-reliability-static.test.mjs +10 -6
- package/tests/guided-git-publication-backend-static.test.mjs +16 -11
- package/tests/http-endpoints-harness.test.mjs +29 -9
- package/tests/interaction-state-stability-static.test.mjs +4 -3
- package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
- package/tests/intercom-tag-layout-static.test.mjs +13 -12
- package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
- package/tests/main-output-loading-static.test.mjs +4 -4
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +10 -7
- package/tests/mobile-phone-experience-static.test.mjs +3 -2
- package/tests/mobile-static.test.mjs +173 -135
- package/tests/model-catalog-order.test.mjs +103 -0
- package/tests/native-parity.test.mjs +6 -4
- package/tests/native-session-choice-owner.test.mjs +102 -0
- package/tests/native-update-lifecycle.test.mjs +10 -5
- package/tests/no-project-http-harness.test.mjs +328 -0
- package/tests/no-project-navigation.test.mjs +54 -0
- package/tests/no-project-workspaces.test.mjs +77 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +4 -4
- package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
- package/tests/package-updates.test.mjs +630 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/platform-event-stream.test.mjs +253 -0
- package/tests/project-file-viewer-controller.test.mjs +652 -0
- package/tests/project-git-tools-adapter.test.mjs +103 -0
- package/tests/project-git-tools-controller.test.mjs +577 -0
- package/tests/project-runners-controller.test.mjs +453 -0
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +6 -6
- package/tests/queue-edit-reorder-static.test.mjs +48 -51
- package/tests/rpc-supervisor-host.test.mjs +4 -1
- package/tests/safety-guard-auto-review-static.test.mjs +1 -1
- package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
- package/tests/server-app-runners.test.mjs +536 -0
- package/tests/server-codex-fast-mode.test.mjs +346 -0
- package/tests/server-conversation-mode.test.mjs +386 -0
- package/tests/server-conversation-voice.test.mjs +426 -0
- package/tests/server-extension-ui-requests.test.mjs +357 -0
- package/tests/server-git-generation.test.mjs +558 -0
- package/tests/server-git-mutations.test.mjs +729 -0
- package/tests/server-git-reads.test.mjs +381 -0
- package/tests/server-git-worktree-sessions.test.mjs +502 -0
- package/tests/server-helper-requests.test.mjs +364 -0
- package/tests/server-rpc-transports.test.mjs +553 -0
- package/tests/server-settings-store.test.mjs +132 -0
- package/tests/server-shell-rollout.test.mjs +478 -0
- package/tests/server-sse-delivery.test.mjs +410 -0
- package/tests/server-workspace-files.test.mjs +546 -0
- package/tests/session-attention-scheduler.test.mjs +514 -0
- package/tests/session-composer-store.test.mjs +153 -0
- package/tests/session-context.test.mjs +134 -0
- package/tests/session-extension-requests.test.mjs +193 -0
- package/tests/session-ownership-adapter.test.mjs +130 -0
- package/tests/session-sampling-ui-static.test.mjs +10 -4
- package/tests/session-send-lifetime.test.mjs +140 -0
- package/tests/session-shelf-state.test.mjs +348 -0
- package/tests/session-shelves-adapter.test.mjs +79 -0
- package/tests/session-summary-lifetime.test.mjs +54 -0
- package/tests/settings-resource-controller.test.mjs +548 -0
- package/tests/shell-action-adapter.test.mjs +169 -0
- package/tests/shell-actions.test.mjs +182 -0
- package/tests/shell-navigation.test.mjs +348 -0
- package/tests/shell-preferences.test.mjs +367 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slot-state.test.mjs +2 -2
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagent-reliability-integration.test.mjs +13 -30
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +1 -1
- package/tests/tab-metadata-ordering.test.mjs +99 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
- package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
- package/tests/terminal-tab-workspace-static.test.mjs +5 -4
- package/tests/terminal-tabs-resize-static.test.mjs +1 -1
- package/tests/theme-contract.test.mjs +10 -3
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thread-display-title.test.mjs +44 -0
- package/tests/update-api-harness.test.mjs +15 -14
- package/tests/update-tab-restore-harness.test.mjs +3 -0
- package/tests/webui-settings-locking.test.mjs +2 -2
- package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
- package/tests/workspace-choices.test.mjs +114 -0
- package/tests/workspace-save-load-static.test.mjs +7 -4
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import vm from "node:vm";
|
|
5
|
+
import { CodexCliUsageError } from "../lib/codex-cli-usage.mjs";
|
|
6
|
+
import { createCodexUsageReader } from "../lib/codex-usage-source.mjs";
|
|
7
|
+
|
|
8
|
+
const unavailable = () => { throw new CodexCliUsageError("CODEX_CLI_NOT_FOUND", "Codex CLI was not found."); };
|
|
9
|
+
|
|
10
|
+
test("CLI usage has precedence and does not touch Pi authentication", async () => {
|
|
11
|
+
const snapshot = { source: "codex-cli", selected: { primary: { usedPercent: 25 } } };
|
|
12
|
+
const reader = createCodexUsageReader({ readCli: async () => snapshot, readLegacy: () => assert.fail("CLI success must not resolve Pi auth") });
|
|
13
|
+
assert.equal(await reader({ forceRefresh: true }), snapshot);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("a compatible legacy login supplies an explicitly labelled fallback", async () => {
|
|
17
|
+
let received;
|
|
18
|
+
const reader = createCodexUsageReader({ readCli: unavailable, readLegacy: async (options) => { received = options; return { source: "chatgpt.com", selected: {} }; } });
|
|
19
|
+
const result = await reader({ forceRefresh: true });
|
|
20
|
+
assert.deepEqual(received, { forceRefresh: true });
|
|
21
|
+
assert.equal(result.source, "chatgpt.com");
|
|
22
|
+
assert.match(result.sourceNotice, /Pi's legacy Codex login/);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("concurrent polls coalesce and refresh bypasses only the completed cache", async () => {
|
|
26
|
+
let calls = 0;
|
|
27
|
+
let complete;
|
|
28
|
+
const pending = new Promise((resolve) => { complete = resolve; });
|
|
29
|
+
const reader = createCodexUsageReader({ readCli: async () => { calls++; return pending; }, readLegacy: () => assert.fail("must not fall back") });
|
|
30
|
+
const first = reader();
|
|
31
|
+
const second = reader({ forceRefresh: true });
|
|
32
|
+
assert.equal(calls, 1);
|
|
33
|
+
complete({ source: "codex-cli" });
|
|
34
|
+
assert.deepEqual(await first, await second);
|
|
35
|
+
await reader();
|
|
36
|
+
assert.equal(calls, 1);
|
|
37
|
+
await reader({ forceRefresh: true });
|
|
38
|
+
assert.equal(calls, 2);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("successful caches expire, while failures never enter the cache", async () => {
|
|
42
|
+
let now = 100;
|
|
43
|
+
let calls = 0;
|
|
44
|
+
const reader = createCodexUsageReader({ readCli: async () => ({ source: "codex-cli", count: ++calls }), readLegacy: unavailable, cacheMs: 30, now: () => now });
|
|
45
|
+
assert.equal((await reader()).count, 1);
|
|
46
|
+
now = 129;
|
|
47
|
+
assert.equal((await reader()).count, 1);
|
|
48
|
+
now = 130;
|
|
49
|
+
assert.equal((await reader()).count, 2);
|
|
50
|
+
let failures = 0;
|
|
51
|
+
const failing = createCodexUsageReader({ readCli: async () => { failures++; unavailable(); }, readLegacy: async () => { throw new Error("private-token"); } });
|
|
52
|
+
for (let index = 0; index < 2; index++) await assert.rejects(failing(), (error) => error.code === "CODEX_CLI_NOT_FOUND" && !error.message.includes("private-token"));
|
|
53
|
+
assert.equal(failures, 2);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("unexpected CLI errors and legacy exceptions never expose raw diagnostics", async () => {
|
|
57
|
+
const reader = createCodexUsageReader({ readCli: async () => { throw new Error("Bearer private-cli-token"); }, readLegacy: async () => { throw new Error("private-refresh-token"); } });
|
|
58
|
+
await assert.rejects(reader(), (error) => {
|
|
59
|
+
assert.equal(error.statusCode, 503);
|
|
60
|
+
assert.match(error.message, /legacy Codex usage fallback/);
|
|
61
|
+
assert.doesNotMatch(error.message, /private-|Bearer/);
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const serverSource = await readFile(new URL("../bin/pi-webui.mjs", import.meta.url), "utf8");
|
|
67
|
+
function serverUsageReader(readCli, fetchLegacy, resolveAuth) {
|
|
68
|
+
const start = serverSource.indexOf("function firstDefined(");
|
|
69
|
+
const end = serverSource.indexOf("const CLAUDE_USAGE_MONTHS", start);
|
|
70
|
+
assert.ok(start >= 0 && end > start);
|
|
71
|
+
return vm.runInNewContext(`${serverSource.slice(start, end)}\ngetOpenAICodexUsageStatus;`, {
|
|
72
|
+
Buffer, AbortController, setTimeout, clearTimeout,
|
|
73
|
+
createCodexUsageReader,
|
|
74
|
+
readCodexCliUsage: readCli,
|
|
75
|
+
fetch: fetchLegacy,
|
|
76
|
+
OPENAI_CODEX_PROVIDER_ID: "openai-codex",
|
|
77
|
+
OPENAI_CODEX_USAGE_ENDPOINT: "https://fixture.invalid/usage",
|
|
78
|
+
CODEX_USAGE_TIMEOUT_MS: 1000,
|
|
79
|
+
CODEX_USAGE_DIRECT_TOKEN_MESSAGE: "Direct ChatGPT login cannot supply legacy usage.",
|
|
80
|
+
codexUsageLoginGuidance: () => "Run /login.",
|
|
81
|
+
authContext: async () => ({ modelRuntime: {} }),
|
|
82
|
+
resolveCodexUsageAuth: resolveAuth,
|
|
83
|
+
makeHttpError: (statusCode, message) => Object.assign(new Error(message), { statusCode }),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
test("the server normalizes CLI weekly-only usage and records its source", async () => {
|
|
88
|
+
const reader = serverUsageReader(async () => ({ planType: "plus", rateLimits: { limitId: "codex", primary: null, secondary: { usedPercent: 42, windowDurationMins: 10080, resetsAt: 2_000_500_000 } } }), () => assert.fail("must not call legacy backend"), () => assert.fail("must not resolve Pi auth"));
|
|
89
|
+
const data = await reader();
|
|
90
|
+
assert.equal(data.source, "codex-cli");
|
|
91
|
+
assert.equal(data.auth.source, "codex-cli");
|
|
92
|
+
assert.equal(data.planType, "plus");
|
|
93
|
+
assert.equal(data.selected.primary, null);
|
|
94
|
+
assert.equal(data.selected.secondary.usedPercent, 42);
|
|
95
|
+
assert.equal(data.snapshots.length, 1);
|
|
96
|
+
assert.equal(data.selected.secondary.resetsAt, new Date(2_000_500_000 * 1000).toISOString());
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("the server retains legacy usage as a fallback with no CLI credentials involved", async () => {
|
|
100
|
+
let legacyCalls = 0;
|
|
101
|
+
const reader = serverUsageReader(unavailable, async (_url, options) => {
|
|
102
|
+
legacyCalls++;
|
|
103
|
+
assert.equal(options.headers.authorization, "Bearer fixture-legacy-token");
|
|
104
|
+
return { ok: true, text: async () => JSON.stringify({ plan_type: "plus", rate_limit: { primary_window: { used_percent: 12, limit_window_seconds: 18000 } } }) };
|
|
105
|
+
}, async () => ({ providerId: "openai-codex", accessToken: "fixture-legacy-token", credential: { type: "oauth", accountId: "fixture-account" } }));
|
|
106
|
+
const data = await reader();
|
|
107
|
+
assert.equal(legacyCalls, 1);
|
|
108
|
+
assert.equal(data.source, "chatgpt.com");
|
|
109
|
+
assert.equal(data.selected.primary.usedPercent, 12);
|
|
110
|
+
assert.match(data.sourceNotice, /legacy Codex login/);
|
|
111
|
+
assert.doesNotMatch(JSON.stringify(data), /fixture-legacy-token|fixture-account/);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("the server gives a sanitized combined error when CLI and direct-flow Pi fallback fail", async () => {
|
|
115
|
+
const reader = serverUsageReader(unavailable, () => assert.fail("direct-flow token must not reach backend"), async () => ({ unsupportedReason: "chatgpt-direct-token" }));
|
|
116
|
+
await assert.rejects(reader(), (error) => error.code === "CODEX_CLI_NOT_FOUND" && /legacy Codex usage fallback/.test(error.message));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("the browser labels the usage account and redraws when source changes", async () => {
|
|
120
|
+
const source = await readFile(new URL("../public/activity-usage-controller.mjs", import.meta.url), "utf8");
|
|
121
|
+
const signatureStart = source.indexOf("function codexUsageStructureSignature(");
|
|
122
|
+
const signatureEnd = source.indexOf("function updateCodexUsageValues(", signatureStart);
|
|
123
|
+
const renderStart = source.indexOf("function renderCodexUsage(");
|
|
124
|
+
const renderEnd = source.indexOf("function renderClaudeUsageWindow(", renderStart);
|
|
125
|
+
const nodes = [];
|
|
126
|
+
let rebuilds = 0;
|
|
127
|
+
const box = { replaceChildren: () => { nodes.length = 0; rebuilds++; }, classList: { toggle() {} }, append: (...items) => nodes.push(...items) };
|
|
128
|
+
const context = vm.createContext({
|
|
129
|
+
latestCodexUsage: { source: "codex-cli", planType: "plus" },
|
|
130
|
+
codexUsageLoading: false, codexUsageError: null, codexUsageRenderSignature: "",
|
|
131
|
+
nodes: { codexUsageBox: box },
|
|
132
|
+
disposed: false,
|
|
133
|
+
formatCodexPlanType: (value) => value,
|
|
134
|
+
codexUsageBuckets: () => [],
|
|
135
|
+
updateCodexUsageValues: () => true,
|
|
136
|
+
make: (_tag, _className, text) => ({ text, append() {} }),
|
|
137
|
+
});
|
|
138
|
+
vm.runInContext(`${source.slice(signatureStart, signatureEnd)}\n${source.slice(renderStart, renderEnd)}\nrenderCodexUsage();`, context);
|
|
139
|
+
assert.ok(nodes.some((node) => /Codex CLI account/.test(node.text)));
|
|
140
|
+
assert.ok(nodes.some((node) => /separate from Pi/.test(node.text)));
|
|
141
|
+
context.latestCodexUsage = { source: "chatgpt.com", planType: "plus", sourceNotice: "Showing fallback usage." };
|
|
142
|
+
vm.runInContext("renderCodexUsage()", context);
|
|
143
|
+
assert.equal(rebuilds, 2, "source changes must invalidate the structural cache");
|
|
144
|
+
assert.ok(nodes.some((node) => /Pi's legacy Codex login/.test(node.text)));
|
|
145
|
+
assert.ok(nodes.some((node) => node.text === "Showing fallback usage."));
|
|
146
|
+
});
|
|
@@ -14,8 +14,8 @@ const [server, state, launcher, runner, trust] = await Promise.all([
|
|
|
14
14
|
assert.match(state, /validateUpdatePlanRequest[\s\S]*targets must contain exactly one value/);
|
|
15
15
|
assert.match(state, /validateUpdateApplyRequest[\s\S]*Apply accepts only transactionId and planDigest/);
|
|
16
16
|
assert.match(server, /url\.pathname === "\/api\/update\/plan"[\s\S]*requireLocalhostRoute[\s\S]*validateUpdatePlanRequest[\s\S]*sendJson\(res, 201/);
|
|
17
|
-
assert.match(server, /url\.pathname === "\/api\/update\/apply"[\s\S]*requireLocalhostRoute[\s\S]*validateUpdateApplyRequest[\s\S]*
|
|
18
|
-
assert.match(server, /
|
|
17
|
+
assert.match(server, /url\.pathname === "\/api\/update\/apply"[\s\S]*requireLocalhostRoute[\s\S]*validateUpdateApplyRequest[\s\S]*packageUpdates\.apply/);
|
|
18
|
+
assert.match(server, /packageUpdates\.plan\(validation\.targets\[0\]\)/);
|
|
19
19
|
assert.match(server, /validateNativePlan\(job\.plan, digest\)/);
|
|
20
20
|
assert.match(server, /url\.pathname === "\/api\/restart"[\s\S]*requireLocalhostRoute[\s\S]*assertNativeMutationAdmission\(\)/,
|
|
21
21
|
"ordinary server restarts must not race a native update fence");
|
|
@@ -57,8 +57,8 @@ assert.match(app, /function initializeComposerActionOrdering\(\)[\s\S]*MutationO
|
|
|
57
57
|
assert.match(app, /event\.key === COMPOSER_ACTION_ORDER_STORAGE_KEY\) restoreComposerActionOrder\(\)[\s\S]*event\.key === COMPOSER_ACTION_LAYOUT_STORAGE_KEY\) restoreComposerActionSlotLayout\(\)/, "other tabs should apply persisted composer order and sparse-layout changes");
|
|
58
58
|
assert.match(app, /initializeComposerActionOrdering\(\);[\s\S]*restoreSidePanelSectionOrder\(\);/, "composer ordering should initialize during guarded app startup");
|
|
59
59
|
|
|
60
|
-
assert.match(html, /styles\.css\?v=
|
|
61
|
-
assert.match(html, /app\.js\?v=
|
|
62
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
60
|
+
assert.match(html, /styles\.css\?v=167/, "changed composer styles should advance the stylesheet revision");
|
|
61
|
+
assert.match(html, /app\.js\?v=220/, "changed composer behavior should advance the app revision");
|
|
62
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "changed browser assets should advance the PWA cache identity");
|
|
63
63
|
|
|
64
64
|
console.log("composer-action-grid-reorder-static.test.mjs passed");
|
|
@@ -10,6 +10,9 @@ const [html, css, app, development] = await Promise.all([
|
|
|
10
10
|
readFile(join(root, "public/app.js"), "utf8"),
|
|
11
11
|
readFile(join(root, "DEVELOPMENT.md"), "utf8"),
|
|
12
12
|
]);
|
|
13
|
+
assert.match(app, /const COMPONENT_UPDATE_TARGETS = \["all", "pi", "webui"\]/);
|
|
14
|
+
assert.match(app, /createSidebarUpdateMenu\(\{ button: elements\.sidebarUpdateButton, onSelect: startComponentUpdate \}\)/);
|
|
15
|
+
assert.match(html, /id="sidebarUpdateButton"[^>]*aria-label="Updates"/);
|
|
13
16
|
for (const target of ["pi", "webui"]) {
|
|
14
17
|
assert.match(app, new RegExp(`startComponentUpdate\\("${target}"\\)`));
|
|
15
18
|
assert.match(html, new RegExp(`id="${target}ComponentUpdateStatus"[^>]*aria-live="polite"`));
|
|
@@ -20,14 +23,16 @@ assert.doesNotMatch(html, /update-all|Update all|Pi \+ Web UI update/);
|
|
|
20
23
|
assert.doesNotMatch(app, /runPiUpdateAndRestart|managed Web UI activation|side-by-side managed runtime/);
|
|
21
24
|
assert.match(app, /body: \{ targets: \[target\] \}/);
|
|
22
25
|
assert.match(app, /body: \{ transactionId: plan.transactionId, planDigest: plan.digest \}/);
|
|
23
|
-
|
|
26
|
+
const startUpdate = app.slice(app.indexOf("async function startComponentUpdate(target)"), app.indexOf("async function openWebuiPackageDialog()"));
|
|
27
|
+
assert.doesNotMatch(startUpdate, /appConfirm|window\.confirm/);
|
|
28
|
+
assert.match(startUpdate, /plan\?\.requested !== target[\s\S]*!plan\.transactionId[\s\S]*!plan\.digest[\s\S]*!Array\.isArray\(plan\.targets\)/);
|
|
24
29
|
assert.match(app, /nativeJobs[\s\S]*nativeJobDiscoveryError/);
|
|
25
|
-
assert.match(app, /
|
|
30
|
+
assert.match(app, /sidebarUpdateError = "Update preview is incomplete; no command was launched\."/);
|
|
26
31
|
assert.match(app, /uncertainApplyJobs\[target\] = plan\.transactionId[\s\S]*phase: "launching"/);
|
|
27
32
|
assert.match(app, /if \(latestUpdateStatus\?\.nativeJobs && !latestUpdateStatus\.nativeJobDiscoveryError\) nativeJobPollError = ""/);
|
|
28
33
|
assert.match(app, /api\/update\/transactions\/\$\{encodeURIComponent\(job\.transactionId\)\}/);
|
|
29
|
-
assert.match(app, /case "unknown"[\s\S]*
|
|
30
|
-
assert.match(app, /case "partial"[\s\S]*
|
|
34
|
+
assert.match(app, /case "unknown"[\s\S]*Check the command output/);
|
|
35
|
+
assert.match(app, /case "partial"[\s\S]*Some commands failed/);
|
|
31
36
|
assert.match(css, /\.component-update-status\[data-update-running\]::before[\s\S]*component-update-spin/);
|
|
32
37
|
assert.match(development, /Native Pi and Web UI updates[\s\S]*GET \/api\/update\/transactions\/.*[\s\S]*Native lifecycle scripts are not sandboxed/);
|
|
33
38
|
console.log("control deck component update static tests passed");
|
|
@@ -348,10 +348,10 @@ assert.match(
|
|
|
348
348
|
|
|
349
349
|
assert.match(
|
|
350
350
|
serviceWorker,
|
|
351
|
-
/const CACHE_NAME = "pi-webui-pwa-
|
|
351
|
+
/const CACHE_NAME = "pi-webui-pwa-v200";/,
|
|
352
352
|
"browser asset changes should advance the PWA cache identity",
|
|
353
353
|
);
|
|
354
|
-
assert.match(html, /styles\.css\?v=
|
|
355
|
-
assert.match(html, /data-app-src="\/app\.js\?v=
|
|
354
|
+
assert.match(html, /styles\.css\?v=167/, "visibility styles should advance the stylesheet query revision");
|
|
355
|
+
assert.match(html, /data-app-src="\/app\.js\?v=220"/, "visibility behavior should advance the app query revision");
|
|
356
356
|
|
|
357
357
|
console.log("control-visibility-static.test.mjs passed");
|
|
@@ -9,14 +9,14 @@ const css = readFileSync(join(root, "public/styles.css"), "utf8");
|
|
|
9
9
|
const app = readFileSync(join(root, "public/app.js"), "utf8");
|
|
10
10
|
const serviceWorker = readFileSync(join(root, "public/service-worker.js"), "utf8");
|
|
11
11
|
|
|
12
|
-
assert.equal((html.match(/class="control-row(?:\s[^"]*)?"/g) || []).length,
|
|
12
|
+
assert.equal((html.match(/class="control-row(?:\s[^"]*)?"/g) || []).length, 16, "Controls should render one two-column row per setting, including optional remote-access settings");
|
|
13
13
|
assert.match(css, /\.control-row \{[\s\S]*grid-template-columns:\s*minmax\(6\.2rem, 0\.44fr\) minmax\(0, 1fr\)/, "Controls settings should use stable name and parameter columns");
|
|
14
|
-
assert.equal((html.match(/class="control-row-label"[^>]*data-tooltip=/g) || []).length,
|
|
14
|
+
assert.equal((html.match(/class="control-row-label"[^>]*data-tooltip=/g) || []).length, 16, "Every Controls setting name should provide user-friendly help");
|
|
15
15
|
assert.match(app, /function initializeControlSettingTooltips\(\)[\s\S]*#sidePanelSectionControls \.control-row-label\[data-tooltip\][\s\S]*bindStyledTooltipEvents\(label\)[\s\S]*showFooterTooltip\(label\)/, "Controls help should use the viewport-safe floating tooltip for hover and keyboard access");
|
|
16
16
|
assert.match(html, /class="control-row remote-auth-control-row" hidden[\s\S]*id="remoteAuthToggle"/, "optional PIN protection should retain its guarded visibility");
|
|
17
17
|
assert.match(app, /remoteAuthToggle\?\.closest\("\.remote-auth-control-row"\)[\s\S]*remoteAuthRow\.hidden = false/, "loading remote status should reveal the optional PIN protection setting");
|
|
18
|
-
assert.match(html, /styles\.css\?v=
|
|
19
|
-
assert.match(html, /app\.js\?v=
|
|
20
|
-
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-
|
|
18
|
+
assert.match(html, /styles\.css\?v=167/, "Controls stylesheet changes should advance the cache query");
|
|
19
|
+
assert.match(html, /app\.js\?v=220/, "Controls tooltip wiring should advance the app cache query");
|
|
20
|
+
assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v200"/, "Controls browser assets should advance the PWA cache identity");
|
|
21
21
|
|
|
22
22
|
console.log("controls-layout-static.test.mjs passed");
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import vm from 'node:vm';
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import { checkActionTarget } from '../public/shell-actions.mjs';
|
|
6
|
+
|
|
7
|
+
const source = readFileSync(new URL('../public/app.js', import.meta.url), 'utf8');
|
|
8
|
+
const functions = ['threadDisplayTitle', 'focusedOverviewSnapshot', 'invokeOverviewAction'].map(name => {
|
|
9
|
+
const start = source.indexOf(`function ${name}(`);
|
|
10
|
+
assert.ok(start >= 0);
|
|
11
|
+
return source.slice(start, source.indexOf('\n}', start) + 2);
|
|
12
|
+
}).join('\n');
|
|
13
|
+
|
|
14
|
+
function fixture() {
|
|
15
|
+
const context = vm.createContext({ checkActionTarget });
|
|
16
|
+
vm.runInContext(`
|
|
17
|
+
let shellPreferenceState = {value:{overviewOpen:true}};
|
|
18
|
+
let enabled = true, dataReads = 0, focusedShellState = {destination:'conversation'};
|
|
19
|
+
let tab = {id:'tab-a',title:'A',cwd:'/a',gitWorkspace:{branch:'feature'}};
|
|
20
|
+
let target = {tabId:'tab-a',generation:1,sessionIdentity:'session-a',cwd:'/a'};
|
|
21
|
+
let payload = null, currentState = {pendingMessageCount:2}, runner = null;
|
|
22
|
+
let agentState = {data:null}, usageContext = null, events = [], invoked = [];
|
|
23
|
+
const activeTab = () => tab;
|
|
24
|
+
const shellActionTarget = () => ({...target});
|
|
25
|
+
const isFocusedShellRequested = () => enabled;
|
|
26
|
+
const parseGitFooterWebuiPayload = () => {dataReads++; return payload;};
|
|
27
|
+
const normalizeGitWorkspaceInfo = value => value;
|
|
28
|
+
const tabAppRunnerRun = () => runner;
|
|
29
|
+
const activityAgents = {getSnapshot:() => agentState};
|
|
30
|
+
const subagentOverviewGroups = data => data.groups;
|
|
31
|
+
const contextUsageSnapshot = () => usageContext;
|
|
32
|
+
const contextUsageDisplay = value => value ? '25% of 200k' : 'Context unknown';
|
|
33
|
+
const contextUsageDetail = () => 'Current session context';
|
|
34
|
+
const cleanStatusText = value => String(value || '');
|
|
35
|
+
const tabIndicator = () => ({label:'Working'});
|
|
36
|
+
const focusedToolsActions = () => ['files','git','runners','subagents','queue','session','codex-usage','claude-usage'].map(id => ({id:'view:'+id,scope:'browser',available:true}));
|
|
37
|
+
const addEvent = (message,level) => events.push({message,level});
|
|
38
|
+
const invokeFocusedTool = action => invoked.push(action);
|
|
39
|
+
${functions}
|
|
40
|
+
`, context);
|
|
41
|
+
return code => vm.runInContext(code, context);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
test('closed and noncompact overview read no feature data', () => {
|
|
45
|
+
const run = fixture();
|
|
46
|
+
run('shellPreferenceState.value.overviewOpen=false');
|
|
47
|
+
assert.equal(run('focusedOverviewSnapshot().open'), false);
|
|
48
|
+
run('shellPreferenceState.value.overviewOpen=true; enabled=false');
|
|
49
|
+
assert.equal(run('focusedOverviewSnapshot().open'), false);
|
|
50
|
+
assert.equal(run('dataReads'), 0);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('overview distinguishes unknown data and scopes agent counts to the selected session', () => {
|
|
54
|
+
const run = fixture();
|
|
55
|
+
assert.equal(run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').value"), 'Not loaded');
|
|
56
|
+
assert.equal(run("focusedOverviewSnapshot().sections[2].items.find(row=>row.id==='usage-unknown').value"), 'Not loaded');
|
|
57
|
+
run("agentState.data={groups:[{groupKind:'tab',tabId:'tab-a',runningAgents:1,agentCount:3},{groupKind:'tab',tabId:'tab-b',runningAgents:9,agentCount:20}]}");
|
|
58
|
+
assert.equal(run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').value"), '1 running · 3 total');
|
|
59
|
+
run("payload={meta:[{key:'git',value:'main'},{key:'changes',value:'+3 -1'}],providerUsage:{provider:'anthropic',capturedAt:1700000000000,secondary:{label:'Weekly',usedPercent:42}}}; usageContext={percent:25}");
|
|
60
|
+
assert.equal(run("focusedOverviewSnapshot().sections[0].items.find(row=>row.id==='branch').value"), 'main');
|
|
61
|
+
assert.equal(run("focusedOverviewSnapshot().sections[2].items.find(row=>row.id==='usage-secondary').progress"), 42);
|
|
62
|
+
assert.equal(run("focusedOverviewSnapshot().sections[2].items.find(row=>row.id==='usage-secondary').actionId"), 'view:claude-usage');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
for (const mutation of ["target.tabId='tab-b'", "target.generation=2", "target.sessionIdentity='replacement'", "target.cwd='/b'"]) {
|
|
66
|
+
test(`overview rejects a stale action after ${mutation}`, () => {
|
|
67
|
+
const run = fixture();
|
|
68
|
+
run('const captured=focusedOverviewSnapshot().target');
|
|
69
|
+
run(mutation);
|
|
70
|
+
run("invokeOverviewAction('view:git',captured)");
|
|
71
|
+
assert.equal(run('invoked.length'), 0);
|
|
72
|
+
assert.equal(run('events.length'), 1);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
test('current overview actions use the canonical catalog; no-session actions are unavailable', () => {
|
|
77
|
+
const run = fixture();
|
|
78
|
+
run("invokeOverviewAction('view:queue',focusedOverviewSnapshot().target)");
|
|
79
|
+
assert.equal(run('invoked[0].id'), 'view:queue');
|
|
80
|
+
run("invokeOverviewAction('made-up',focusedOverviewSnapshot().target)");
|
|
81
|
+
assert.equal(run('invoked.length'), 1);
|
|
82
|
+
run("tab=null;target={tabId:null,generation:2,sessionIdentity:'',cwd:''}");
|
|
83
|
+
assert.equal(run('focusedOverviewSnapshot().sections.flatMap(section=>section.items).filter(row=>row.actionId).every(row=>row.disabled)'), true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
test('overview separates external agents, capability absence and stale observations', () => {
|
|
88
|
+
const run = fixture();
|
|
89
|
+
const value = () => run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').value");
|
|
90
|
+
run("agentState.data={tabs:[{tabId:'tab-a',available:true},{tabId:'tab-b',available:false}],groups:[{groupKind:'external',tabId:'tab-a',runningAgents:4,agentCount:4}]}");
|
|
91
|
+
assert.equal(value(), '0 running · 0 total');
|
|
92
|
+
run("tab={id:'tab-b'}");
|
|
93
|
+
assert.equal(value(), 'Reporting unavailable');
|
|
94
|
+
run("tab={id:'unknown'}");
|
|
95
|
+
assert.equal(value(), 'Not loaded');
|
|
96
|
+
run("tab={id:'tab-b'};agentState.data.groups.push({groupKind:'tab',tabId:'tab-b',runningAgents:1,agentCount:2})");
|
|
97
|
+
assert.equal(value(), '1 running · 2 total');
|
|
98
|
+
run("agentState.error='offline'");
|
|
99
|
+
assert.match(run("focusedOverviewSnapshot().sections[1].items.find(row=>row.id==='agents').detail"), /previous snapshot/);
|
|
100
|
+
});
|
|
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
|
+
const artifactOwner = await readFile(new URL("../public/project-artifact-controller.mjs", import.meta.url), "utf8");
|
|
6
7
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
8
|
const [server, app, styles] = await Promise.all([
|
|
8
9
|
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
@@ -12,7 +13,7 @@ const [server, app, styles] = await Promise.all([
|
|
|
12
13
|
|
|
13
14
|
for (const contract of ["pi.artifact/v1", "registerDocumentArtifact", "rewriteArtifactsForTab", "documentArtifactRecord", "sendDocumentArtifactFile", "/api/artifacts/"]) assert.ok(server.includes(contract), `server should contain ${contract}`);
|
|
14
15
|
for (const privateField of ["manifestPath", "downloadPath", "outputPath", "sourcePath", "stagedPath", "pdfPath", "workspace", "recoveryPath"]) assert.match(server, new RegExp(`PRIVATE_ARTIFACT_KEYS[^;]+[\\s\\S]*?${privateField}`), `artifact sanitizer should cover ${privateField}`);
|
|
15
|
-
for (const feature of ["openDocumentArtifact", "appendDocumentArtifact", "Send page to composer", "Previous", "Rotate", "Semantic structure, revisions, warnings, and diff"]) assert.ok(app.includes(feature), `browser viewer should contain ${feature}`);
|
|
16
|
+
for (const feature of ["openDocumentArtifact", "appendDocumentArtifact", "Send page to composer", "Previous", "Rotate", "Semantic structure, revisions, warnings, and diff"]) assert.ok((app + artifactOwner).includes(feature), `browser viewer should contain ${feature}`);
|
|
16
17
|
for (const selector of [".document-artifact-dialog", ".document-artifact-sidebar", ".document-artifact-page", "@media (max-width: 720px)"]) assert.ok(styles.includes(selector), `viewer stylesheet should contain ${selector}`);
|
|
17
18
|
assert.equal(/details\.artifact\s*=/.test(server), false, "server should replace details immutably rather than mutating raw RPC artifacts");
|
|
18
19
|
console.log("document-artifact-static.test.mjs passed");
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { createDraftConversations, DRAFT_STORAGE_KEY, DRAFT_LIMITS } from "../public/draft-conversations.mjs";
|
|
4
|
+
|
|
5
|
+
function fixture(initial = null) {
|
|
6
|
+
let raw = initial;
|
|
7
|
+
let blocked = false;
|
|
8
|
+
let serial = 0;
|
|
9
|
+
const storage = {
|
|
10
|
+
getItem: () => raw,
|
|
11
|
+
setItem(key, value) {
|
|
12
|
+
assert.equal(key, DRAFT_STORAGE_KEY);
|
|
13
|
+
if (blocked) throw new Error("Storage denied");
|
|
14
|
+
raw = value;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const options = { storage: () => storage, randomId: () => `test-${++serial}`, now: () => 100 };
|
|
18
|
+
return { store: createDraftConversations(options), reload: () => createDraftConversations(options), raw: () => raw, block: value => { blocked = value; } };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test("blank identities stay separate and only meaningful saved text enters the roster", () => {
|
|
22
|
+
const { store, reload } = fixture();
|
|
23
|
+
const first = store.create();
|
|
24
|
+
store.edit(first, " \n\t");
|
|
25
|
+
store.save(first);
|
|
26
|
+
assert.deepEqual(store.list(), []);
|
|
27
|
+
const second = store.create();
|
|
28
|
+
assert.notEqual(first, second);
|
|
29
|
+
store.edit(second, " Exact text\nwith λ ");
|
|
30
|
+
store.save(second);
|
|
31
|
+
assert.deepEqual(store.list().map(record => record.text), [" Exact text\nwith λ "]);
|
|
32
|
+
const restored = reload();
|
|
33
|
+
assert.equal(restored.activeId, second);
|
|
34
|
+
assert.equal(restored.get(second).text, " Exact text\nwith λ ");
|
|
35
|
+
assert.equal(restored.get(first), null);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("revisions detect edits back to original and returned records cannot mutate ownership", () => {
|
|
39
|
+
const { store } = fixture();
|
|
40
|
+
const id = store.create();
|
|
41
|
+
store.edit(id, "original");
|
|
42
|
+
const captured = store.get(id);
|
|
43
|
+
store.edit(id, "edit");
|
|
44
|
+
store.edit(id, "original");
|
|
45
|
+
assert.ok(store.get(id).revision > captured.revision);
|
|
46
|
+
captured.text = "external";
|
|
47
|
+
assert.equal(store.get(id).text, "original");
|
|
48
|
+
assert.equal(store.select("server-tab"), false);
|
|
49
|
+
assert.equal(store.edit("server-tab", "invalid"), false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("saved draft edits persist, close discards only one identity, blank selection survives reload", () => {
|
|
53
|
+
const { store, reload } = fixture();
|
|
54
|
+
const first = store.create();
|
|
55
|
+
store.edit(first, "first");
|
|
56
|
+
store.save(first);
|
|
57
|
+
const second = store.create();
|
|
58
|
+
store.edit(second, "second");
|
|
59
|
+
store.save(second);
|
|
60
|
+
store.select(first);
|
|
61
|
+
store.edit(first, "updated");
|
|
62
|
+
assert.equal(reload().get(first).text, "updated");
|
|
63
|
+
store.remove(first);
|
|
64
|
+
assert.deepEqual(reload().list().map(record => record.id), [second]);
|
|
65
|
+
store.select(store.create());
|
|
66
|
+
assert.ok(reload().activeId);
|
|
67
|
+
store.select(null);
|
|
68
|
+
assert.equal(reload().activeId, null);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("denied writes retain all edits in memory and expose failure until recovery", () => {
|
|
72
|
+
const f = fixture();
|
|
73
|
+
const id = f.store.create();
|
|
74
|
+
f.store.edit(id, "saved");
|
|
75
|
+
f.store.save(id);
|
|
76
|
+
const previous = f.raw();
|
|
77
|
+
f.block(true);
|
|
78
|
+
f.store.edit(id, "newer memory edit");
|
|
79
|
+
assert.match(f.store.error, /could not be saved.*Storage denied/);
|
|
80
|
+
assert.equal(f.store.get(id).text, "newer memory edit");
|
|
81
|
+
assert.equal(f.raw(), previous);
|
|
82
|
+
f.block(false);
|
|
83
|
+
assert.equal(f.store.persist(), true);
|
|
84
|
+
assert.equal(f.reload().get(id).text, "newer memory edit");
|
|
85
|
+
assert.equal(f.store.error, "");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("denied reads retain new memory drafts and report storage failure", () => {
|
|
89
|
+
const store = createDraftConversations({ storage: () => { throw new Error("Storage disabled"); }, randomId: () => "new" });
|
|
90
|
+
const id = store.create();
|
|
91
|
+
store.edit(id, "memory");
|
|
92
|
+
assert.equal(store.save(id), false);
|
|
93
|
+
assert.equal(store.get(id).text, "memory");
|
|
94
|
+
assert.match(store.error, /could not be loaded.*Storage disabled/);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
for (const raw of ["{broken", JSON.stringify({ version: 2, records: [], activeId: null }), JSON.stringify({ version: 1, records: [{ id: "backend-tab", text: "hello" }], activeId: null })]) {
|
|
98
|
+
test(`unreadable data remains untouched: ${raw.slice(0, 30)}`, () => {
|
|
99
|
+
const f = fixture(raw);
|
|
100
|
+
assert.match(f.store.error, /could not be loaded/);
|
|
101
|
+
const id = f.store.create();
|
|
102
|
+
f.store.edit(id, "new draft");
|
|
103
|
+
f.store.save(id);
|
|
104
|
+
assert.equal(f.raw(), raw);
|
|
105
|
+
assert.equal(f.store.get(id).text, "new draft");
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
test("oversized edits stay in memory without truncation or replacing stored drafts", () => {
|
|
110
|
+
const f = fixture();
|
|
111
|
+
const id = f.store.create();
|
|
112
|
+
f.store.edit(id, "stored");
|
|
113
|
+
f.store.save(id);
|
|
114
|
+
const previous = f.raw();
|
|
115
|
+
const oversized = "x".repeat(DRAFT_LIMITS.text + 1);
|
|
116
|
+
f.store.edit(id, oversized);
|
|
117
|
+
assert.equal(f.store.get(id).text, oversized);
|
|
118
|
+
assert.equal(f.raw(), previous);
|
|
119
|
+
assert.match(f.store.error, /storage limit/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("record count and total size limits preserve the last stored value and all in-memory drafts", () => {
|
|
123
|
+
const f = fixture();
|
|
124
|
+
for (let index = 0; index < DRAFT_LIMITS.records; index += 1) {
|
|
125
|
+
const id = f.store.create();
|
|
126
|
+
f.store.edit(id, `Draft ${index}`);
|
|
127
|
+
assert.equal(f.store.save(id), true);
|
|
128
|
+
}
|
|
129
|
+
const previous = f.raw();
|
|
130
|
+
const extra = f.store.create();
|
|
131
|
+
f.store.edit(extra, "One more draft");
|
|
132
|
+
assert.equal(f.store.save(extra), false);
|
|
133
|
+
assert.equal(f.raw(), previous);
|
|
134
|
+
assert.equal(f.store.list().length, DRAFT_LIMITS.records + 1);
|
|
135
|
+
f.store.remove(extra);
|
|
136
|
+
for (const record of f.store.list().slice(0, 11)) f.store.edit(record.id, "x".repeat(DRAFT_LIMITS.text));
|
|
137
|
+
assert.match(f.store.error, /storage limit/);
|
|
138
|
+
assert.equal(f.store.list().filter(record => record.text.length === DRAFT_LIMITS.text).length, 11);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("invalid revisions, duplicate identities and invalid selections preserve unreadable storage", () => {
|
|
142
|
+
const record = { id: "draft:example", text: "saved", revision: 1, updatedAt: 100 };
|
|
143
|
+
for (const value of [
|
|
144
|
+
{ version: 1, activeId: null, records: [record, record] },
|
|
145
|
+
{ version: 1, activeId: "draft:missing", records: [record] },
|
|
146
|
+
{ version: 1, activeId: null, records: [{ ...record, revision: -1 }] },
|
|
147
|
+
{ version: 1, activeId: null, records: [{ ...record, updatedAt: 1.5 }] },
|
|
148
|
+
{ version: 1, activeId: null, records: [{ ...record, text: "" }] },
|
|
149
|
+
{ version: 1, activeId: null, records: Array.from({ length: DRAFT_LIMITS.records + 1 }, (_, index) => ({ ...record, id: `draft:${index}` })) },
|
|
150
|
+
]) {
|
|
151
|
+
const raw = JSON.stringify(value);
|
|
152
|
+
const f = fixture(raw);
|
|
153
|
+
assert.match(f.store.error, /could not be loaded/);
|
|
154
|
+
assert.equal(f.store.persist(), false);
|
|
155
|
+
assert.equal(f.raw(), raw);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("optional workspace survives saved draft navigation and version-1 reload without saving blanks", () => {
|
|
160
|
+
const f = fixture();
|
|
161
|
+
const blank = f.store.create();
|
|
162
|
+
assert.equal(f.store.setCwd(blank, "/tmp/blank workspace"), true);
|
|
163
|
+
assert.equal(f.store.save(blank), true);
|
|
164
|
+
assert.deepEqual(f.store.list(), []);
|
|
165
|
+
assert.deepEqual(JSON.parse(f.raw()).records, []);
|
|
166
|
+
f.store.edit(blank, "Text with a workspace");
|
|
167
|
+
f.store.save(blank);
|
|
168
|
+
const revision = f.store.get(blank).revision;
|
|
169
|
+
f.store.setCwd(blank, "/tmp/updated workspace");
|
|
170
|
+
assert.ok(f.store.get(blank).revision > revision);
|
|
171
|
+
f.store.select(f.store.create());
|
|
172
|
+
const restored = f.reload();
|
|
173
|
+
restored.select(blank);
|
|
174
|
+
assert.equal(restored.get(blank).text, "Text with a workspace");
|
|
175
|
+
assert.equal(restored.get(blank).cwd, "/tmp/updated workspace");
|
|
176
|
+
const copy = restored.get(blank);
|
|
177
|
+
copy.cwd = "/external";
|
|
178
|
+
assert.equal(restored.get(blank).cwd, "/tmp/updated workspace");
|
|
179
|
+
const beforeClear = restored.get(blank).revision;
|
|
180
|
+
assert.equal(restored.setCwd(blank, ""), true);
|
|
181
|
+
assert.equal(restored.get(blank).cwd, undefined, "clearing removes the folder so the draft starts a No Project thread");
|
|
182
|
+
assert.equal(Object.hasOwn(restored.get(blank), "cwd"), false);
|
|
183
|
+
assert.equal(restored.get(blank).revision, beforeClear + 1);
|
|
184
|
+
restored.setCwd(blank, "");
|
|
185
|
+
assert.equal(restored.get(blank).revision, beforeClear + 1, "clearing an unset folder is not an edit");
|
|
186
|
+
assert.equal(f.reload().get(blank).cwd, undefined);
|
|
187
|
+
assert.equal(Object.hasOwn(JSON.parse(f.raw()).records.find(record => record.id === blank), "cwd"), false);
|
|
188
|
+
assert.equal(restored.setCwd("draft:missing", "/tmp/valid"), false);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("old version-1 drafts remain readable and invalid workspace metadata never replaces storage", () => {
|
|
192
|
+
const record = { id: "draft:legacy", text: "Legacy text", revision: 1, updatedAt: 100 };
|
|
193
|
+
const legacy = fixture(JSON.stringify({ version: 1, records: [record], activeId: record.id }));
|
|
194
|
+
assert.equal(legacy.store.error, "");
|
|
195
|
+
assert.equal(legacy.store.get(record.id).cwd, undefined);
|
|
196
|
+
for (const cwd of [null, 123, "x".repeat(DRAFT_LIMITS.cwd + 1), "/tmp/\u0000bad"]) {
|
|
197
|
+
const raw = JSON.stringify({ version: 1, records: [{ ...record, cwd }], activeId: record.id });
|
|
198
|
+
const f = fixture(raw);
|
|
199
|
+
assert.match(f.store.error, /could not be loaded/);
|
|
200
|
+
assert.equal(f.store.persist(), false);
|
|
201
|
+
assert.equal(f.raw(), raw);
|
|
202
|
+
assert.throws(() => legacy.store.setCwd(record.id, cwd), /invalid or too long/);
|
|
203
|
+
assert.equal(legacy.store.get(record.id).cwd, undefined);
|
|
204
|
+
}
|
|
205
|
+
});
|