@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,189 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { after, test } from "node:test";
|
|
4
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
9
|
+
import { CodexCliUsageError, projectCodexCliUsage, readCodexCliUsage, resolveCodexCliInvocation } from "../lib/codex-cli-usage.mjs";
|
|
10
|
+
import { terminateProcessTree } from "../lib/process-tree.mjs";
|
|
11
|
+
|
|
12
|
+
const fixture = fileURLToPath(new URL("./fixtures/fake-codex-app-server.mjs", import.meta.url));
|
|
13
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-codex-cli-"));
|
|
14
|
+
const children = [];
|
|
15
|
+
let serial = 0;
|
|
16
|
+
after(async () => {
|
|
17
|
+
for (const child of children) terminateProcessTree(child, "SIGKILL");
|
|
18
|
+
await rm(root, { recursive: true, force: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function run(mode, options = {}) {
|
|
22
|
+
const log = path.join(root, `${++serial}.jsonl`);
|
|
23
|
+
return {
|
|
24
|
+
log,
|
|
25
|
+
result: readCodexCliUsage({
|
|
26
|
+
invocation: { command: process.execPath, args: [fixture, "app-server", "--listen", "stdio://"] },
|
|
27
|
+
env: { ...process.env, FAKE_CODEX_MODE: mode, FAKE_CODEX_LOG: log },
|
|
28
|
+
timeoutMs: 3_000,
|
|
29
|
+
spawn: (...args) => { const child = spawn(...args); children.push(child); return child; },
|
|
30
|
+
...options,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function entries(log) {
|
|
36
|
+
return (await readFile(log, "utf8")).split("\n").filter(Boolean).map(JSON.parse);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function alive(pid) {
|
|
40
|
+
try { process.kill(pid, 0); return true; } catch (error) { return error.code === "EPERM"; }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function assertExited(pid) {
|
|
44
|
+
for (let attempt = 0; attempt < 100 && alive(pid); attempt++) await delay(20);
|
|
45
|
+
assert.equal(alive(pid), false, `fixture process ${pid} should have exited`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
test("the usage client performs only initialization and read-only account requests", async () => {
|
|
49
|
+
const { result, log } = run("success");
|
|
50
|
+
const data = await result;
|
|
51
|
+
assert.equal(data.planType, "plus");
|
|
52
|
+
assert.equal(data.rateLimits.primary.usedPercent, 25);
|
|
53
|
+
assert.equal(data.rateLimits.secondary.usedPercent, 42);
|
|
54
|
+
assert.equal(data.rateLimits.credits.balance, "12.50");
|
|
55
|
+
const messages = await entries(log);
|
|
56
|
+
const frames = messages.filter((entry) => entry.kind === "frame");
|
|
57
|
+
assert.deepEqual(frames.map((frame) => frame.method), ["initialize", "initialized", "account/read", "account/rateLimits/read"]);
|
|
58
|
+
assert.deepEqual(frames[2].params, { refreshToken: false });
|
|
59
|
+
assert.equal(frames[3].params, null);
|
|
60
|
+
assert.doesNotMatch(JSON.stringify(data), /secret|private-account|email|profile|accessToken/);
|
|
61
|
+
await assertExited(messages[0].pid);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("fragmented UTF-8 JSONL and harmless notifications preserve usage data", async () => {
|
|
65
|
+
const data = await run("fragmented").result;
|
|
66
|
+
assert.equal(data.rateLimits.primary.usedPercent, 25);
|
|
67
|
+
assert.equal(data.rateLimits.limitName, "Codex 漢字");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("weekly-only and multi-bucket usage remain usable", async () => {
|
|
71
|
+
const weekly = await run("weekly-only").result;
|
|
72
|
+
assert.equal(weekly.rateLimits.primary, null);
|
|
73
|
+
assert.equal(weekly.rateLimits.secondary.usedPercent, 42);
|
|
74
|
+
const multiple = await run("multi-bucket").result;
|
|
75
|
+
assert.equal(multiple.rateLimitsByLimitId.extra.primary.usedPercent, 70);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("unsolicited server auth requests are rejected without providing credentials", async () => {
|
|
79
|
+
const { result, log } = run("server-request");
|
|
80
|
+
await result;
|
|
81
|
+
const reply = (await entries(log)).find((frame) => frame.id === "server-auth-request");
|
|
82
|
+
assert.equal(reply.error.code, -32601);
|
|
83
|
+
assert.equal(reply.result, undefined);
|
|
84
|
+
assert.equal(reply.error.data, undefined);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("signed-out and API-key CLI accounts never request subscription limits", async () => {
|
|
88
|
+
for (const [mode, code] of [["logged-out", "CODEX_CLI_LOGIN_REQUIRED"], ["api-key", "CODEX_CLI_AUTH_TYPE"]]) {
|
|
89
|
+
const { result, log } = run(mode);
|
|
90
|
+
await assert.rejects(result, (error) => error.code === code && error.statusCode === 401);
|
|
91
|
+
assert.equal((await entries(log)).some((frame) => frame.method === "account/rateLimits/read"), false);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("upstream errors and stderr are replaced with static sanitized diagnostics", async () => {
|
|
96
|
+
await assert.rejects(run("rpc-error").result, (error) => {
|
|
97
|
+
assert.ok(error instanceof CodexCliUsageError);
|
|
98
|
+
assert.equal(error.code, "CODEX_CLI_REQUEST");
|
|
99
|
+
assert.doesNotMatch(error.message, /fixture-|Bearer|refreshToken|private/);
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("malformed, empty, oversized and prematurely closed peers fail safely", async () => {
|
|
105
|
+
for (const [mode, code] of [["malformed", "CODEX_CLI_PROTOCOL"], ["empty", "CODEX_CLI_NO_USAGE"], ["oversized", "CODEX_CLI_OUTPUT_LIMIT"], ["stderr-flood", "CODEX_CLI_OUTPUT_LIMIT"], ["early-exit", "CODEX_CLI_EXIT"]]) {
|
|
106
|
+
await assert.rejects(run(mode).result, (error) => error.code === code);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a silent app server times out and is terminated", async () => {
|
|
111
|
+
const start = Date.now();
|
|
112
|
+
const { result, log } = run("hang", { timeoutMs: 250 });
|
|
113
|
+
await assert.rejects(result, (error) => error.code === "CODEX_CLI_TIMEOUT" && error.statusCode === 504);
|
|
114
|
+
assert.ok(Date.now() - start < 7_000, "timeout and cleanup must remain bounded");
|
|
115
|
+
await assertExited((await entries(log))[0].pid);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("successful reads also terminate stubborn processes and their descendants", async () => {
|
|
119
|
+
for (const mode of ["stubborn", "tree"]) {
|
|
120
|
+
const { result, log } = run(mode);
|
|
121
|
+
await result;
|
|
122
|
+
for (const entry of (await entries(log)).filter((entry) => entry.pid)) await assertExited(entry.pid);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("cancellation cleans up the child and pre-cancellation does not spawn", async () => {
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const { result, log } = run("hang", { signal: controller.signal });
|
|
129
|
+
await delay(200);
|
|
130
|
+
controller.abort();
|
|
131
|
+
await assert.rejects(result, (error) => error.code === "CODEX_CLI_ABORTED");
|
|
132
|
+
await assertExited((await entries(log))[0].pid);
|
|
133
|
+
await assert.rejects(readCodexCliUsage({ signal: controller.signal, spawn: () => assert.fail("must not spawn") }), (error) => error.code === "CODEX_CLI_ABORTED");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("completed reads leave no parent-exit listener behind", async () => {
|
|
137
|
+
const before = process.listenerCount("exit");
|
|
138
|
+
await run("success").result;
|
|
139
|
+
assert.equal(process.listenerCount("exit"), before);
|
|
140
|
+
await assert.rejects(run("rpc-error").result);
|
|
141
|
+
assert.equal(process.listenerCount("exit"), before);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("parent shutdown terminates an in-flight usage process", async () => {
|
|
145
|
+
const log = path.join(root, `${++serial}.jsonl`);
|
|
146
|
+
const moduleUrl = new URL("../lib/codex-cli-usage.mjs", import.meta.url).href;
|
|
147
|
+
const script = `import {readCodexCliUsage} from ${JSON.stringify(moduleUrl)};
|
|
148
|
+
void readCodexCliUsage({ invocation: {command: process.execPath, args: [${JSON.stringify(fixture)}]}, timeoutMs: 3000 }).catch(() => {});
|
|
149
|
+
setTimeout(() => process.exit(0), 500);`;
|
|
150
|
+
const parent = spawn(process.execPath, ["--input-type=module", "-e", script], {
|
|
151
|
+
env: { ...process.env, FAKE_CODEX_MODE: "hang", FAKE_CODEX_LOG: log },
|
|
152
|
+
detached: process.platform !== "win32", stdio: "ignore",
|
|
153
|
+
});
|
|
154
|
+
children.push(parent);
|
|
155
|
+
await new Promise((resolve, reject) => { parent.once("close", resolve); parent.once("error", reject); });
|
|
156
|
+
assert.equal(parent.exitCode, 0);
|
|
157
|
+
const pid = (await entries(log))[0].pid;
|
|
158
|
+
try { await assertExited(pid); } finally { if (alive(pid)) process.kill(pid, "SIGKILL"); }
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("missing executables and synchronous spawn errors do not leak raw details", async () => {
|
|
162
|
+
await assert.rejects(readCodexCliUsage({ invocation: { command: path.join(root, "missing-codex"), args: [] } }), (error) => error.code === "CODEX_CLI_NOT_FOUND");
|
|
163
|
+
await assert.rejects(readCodexCliUsage({ spawn: () => { throw new Error("fixture-secret"); }, invocation: { command: "codex", args: [] } }), (error) => error.code === "CODEX_CLI_START" && !error.message.includes("fixture-secret"));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("quota projection allowlists fields, caps buckets and rejects malformed windows", () => {
|
|
167
|
+
const window = { usedPercent: 0, windowDurationMins: 300, resetsAt: 2000000000, token: "fixture-secret" };
|
|
168
|
+
const byId = Object.fromEntries(Array.from({ length: 100 }, (_, index) => [`bucket-${index}`, { primary: window }]));
|
|
169
|
+
const projected = projectCodexCliUsage({ rateLimits: { primary: window, credits: { balance: { token: "fixture-secret" } } }, rateLimitsByLimitId: byId, accountId: "private" }, "plus");
|
|
170
|
+
assert.equal(Object.keys(projected.rateLimitsByLimitId).length, 16);
|
|
171
|
+
assert.equal(projected.rateLimits.primary.usedPercent, 0);
|
|
172
|
+
assert.equal(projected.rateLimits.credits.balance, null);
|
|
173
|
+
assert.doesNotMatch(JSON.stringify(projected), /fixture-secret|private|token/);
|
|
174
|
+
for (const value of [null, [], { rateLimits: { primary: { usedPercent: "25" } } }, { rateLimits: { primary: { usedPercent: -1 } } }]) {
|
|
175
|
+
assert.throws(() => projectCodexCliUsage(value), CodexCliUsageError);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("command resolution supports native binaries, scripts and Windows npm shims without a shell", () => {
|
|
180
|
+
assert.deepEqual(resolveCodexCliInvocation({ platform: "linux", env: {} }), { command: "codex", args: ["app-server", "--listen", "stdio://"] });
|
|
181
|
+
assert.deepEqual(resolveCodexCliInvocation({ platform: "win32", env: { PI_WEBUI_CODEX_BIN: "C:\\Codex Tools\\codex.exe" } }), { command: "C:\\Codex Tools\\codex.exe", args: ["app-server", "--listen", "stdio://"] });
|
|
182
|
+
const script = "C:\\Node Tools\\node_modules\\@openai\\codex\\bin\\codex.js";
|
|
183
|
+
const exists = new Set(["C:\\Node Tools\\codex.cmd", script].map((value) => value.toLowerCase()));
|
|
184
|
+
const invocation = resolveCodexCliInvocation({ platform: "win32", execPath: "C:\\Node Tools\\node.exe", env: { PATH: "C:\\Node Tools", PATHEXT: ".EXE;.CMD" }, existsSync: (value) => exists.has(value.toLowerCase()) });
|
|
185
|
+
assert.equal(invocation.command, "C:\\Node Tools\\node.exe");
|
|
186
|
+
assert.deepEqual(invocation.args, [script, "app-server", "--listen", "stdio://"]);
|
|
187
|
+
assert.throws(() => resolveCodexCliInvocation({ platform: "win32", env: { PI_WEBUI_CODEX_BIN: "C:\\unknown\\custom.cmd" }, existsSync: () => false }), (error) => error.code === "CODEX_CLI_SHIM");
|
|
188
|
+
assert.equal(resolveCodexCliInvocation({ platform: "linux", env: { PI_WEBUI_CODEX_BIN: "codex;echo hacked" } }).command, "codex;echo hacked");
|
|
189
|
+
});
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
|
|
7
|
+
const codexSpeed = await readFile(new URL("../lib/server/codex-fast-mode.mjs", import.meta.url), "utf8");
|
|
8
|
+
|
|
6
9
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
10
|
const [server, app, html, styles, serviceWorker, technical, development, packageRaw, lockRaw, optionalFeatureCatalog] = await Promise.all([
|
|
8
11
|
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
@@ -27,26 +30,26 @@ assert.equal(lock.packages?.[`node_modules/${packageName}`], undefined, "lockfil
|
|
|
27
30
|
assert.match(optionalFeatureCatalog, /\["codexFastMode", "@firstpick\/pi-extension-codex-fast-mode", "\^0\.1\.0"\]/, "Optional Features should retain the Pi-installable Fast-mode package mapping");
|
|
28
31
|
|
|
29
32
|
assert.match(server, /const OPTIONAL_FEATURE_PACKAGES = new Map\(OPTIONAL_FEATURE_CATALOG/, "server should derive Fast-mode installation from the shared Optional Features catalog");
|
|
30
|
-
assert.match(
|
|
31
|
-
assert.match(
|
|
32
|
-
assert.match(
|
|
33
|
-
assert.match(
|
|
34
|
-
assert.match(
|
|
35
|
-
assert.match(
|
|
36
|
-
assert.doesNotMatch(
|
|
33
|
+
assert.match(codexSpeed, /CODEX_FAST_MODE_STATUS_KEY = "codex-fast-mode"[\s\S]*?CODEX_FAST_MODE_COMMAND_NAME = "fast-mode"/, "server should use the extension-owned status and command contracts");
|
|
34
|
+
assert.match(codexSpeed, /function codexFastModeStatusState\(statusText\)[\s\S]*?codexSpeedModeFromStatus\(stripAnsi\(statusText\)\)/, "server should use the tested exact status parser");
|
|
35
|
+
assert.match(codexSpeed, /function codexFastModeSnapshot\(tab, patch = \{\}\)[\s\S]*?extensionStatusMap\(tab\)\.get\(CODEX_FAST_MODE_STATUS_KEY\)/, "server snapshots should come from remembered extension status");
|
|
36
|
+
assert.match(codexSpeed, /async function codexFastModeFeatureData[\s\S]*?codexFastModeSnapshot\(tab\)[\s\S]*?tabHasActiveOutput\(tab\)[\s\S]*?ultrafastModelEligible:[\s\S]*?CODEX_FAST_MODE_CREDIT_NOTICE/, "GET state should be tab-scoped, extension-owned, busy-aware, model-gated, and disclose credit use");
|
|
37
|
+
assert.match(codexSpeed, /async function waitForCodexFastModeStatus\(tab, desired\)[\s\S]*?snapshot\.statusKnown && snapshot\.mode === desired[\s\S]*?makeHttpError\(409,[\s\S]*?did not confirm/, "server should require bounded exact-mode confirmation");
|
|
38
|
+
assert.match(codexSpeed, /async function setCodexFastMode[\s\S]*?codexSpeedModeFromIntent\(body\)[\s\S]*?feature\.busy[\s\S]*?desired === "ultrafast" && !feature\.ultrafastModelEligible[\s\S]*?type: "prompt", message: `\/\$\{feature\.commandName\} \$\{argument\}`[\s\S]*?waitForCodexFastModeStatus\(tab, desired\)/, "PUT should validate intent, reject busy or ineligible tabs, invoke the extension, and require exact confirmed state");
|
|
39
|
+
assert.doesNotMatch(codexSpeed, /codexFastModeSnapshot\(tab, \{ enabled: desired/, "server must not infer effective Fast state from RPC success");
|
|
37
40
|
assert.match(server, /url\.pathname === "\/api\/codex-fast-mode" && req\.method === "GET"[\s\S]*?url\.pathname === "\/api\/codex-fast-mode" && req\.method === "PUT"/, "server should expose GET and PUT routes");
|
|
38
41
|
|
|
39
42
|
assert.match(html, /<label for="fastOutputModeSelect">Compact mode \(Experimental\)<\/label>[\s\S]*?<option value="compact-v1">Compact<\/option>/, "legacy output processing should be presented as Compact mode while retaining compact-v1");
|
|
40
43
|
assert.doesNotMatch(html, /<label for="fastOutputModeSelect">Fast mode/, "legacy output processing should no longer be presented as Fast mode");
|
|
41
44
|
assert.match(html, /data-side-panel-section="codex-usage"[\s\S]*?id="codexUsageBox"[\s\S]*?class="control-field codex-fast-mode-control"[\s\S]*?class="codex-fast-mode-row"[\s\S]*?id="codexFastModeLabel"[\s\S]*?id="codexFastModeSelect"[\s\S]*?<option value="normal">Normal<\/option>[\s\S]*?<option value="fast">Fast<\/option>[\s\S]*?<option value="ultrafast" disabled>Ultrafast<\/option>[\s\S]*?id="setCodexFastModeButton"[\s\S]*?id="codexFastModeStatus"/, "Codex Usage should render before the compact session Fast-mode row");
|
|
42
45
|
assert.match(styles, /\.codex-fast-mode-control \{[\s\S]*?margin-top: 0\.58rem[\s\S]*?padding: 0\.48rem 0\.55rem[\s\S]*?\.codex-fast-mode-row \{[\s\S]*?grid-template-columns: minmax\(0, 1fr\) minmax\(6\.5rem, 8rem\) auto/, "Codex Fast mode should use a compact horizontal control surface");
|
|
43
|
-
assert.match(app, /function codexFastModeStatusText\(\)[\s\S]*?codexSpeedModeLabel\(codexFastModeState\.mode\)[\s\S]*?return `\$\{label\} · This
|
|
46
|
+
assert.match(app, /function codexFastModeStatusText\(\)[\s\S]*?codexSpeedModeLabel\(codexFastModeState\.mode\)[\s\S]*?return `\$\{label\} · This thread`;/, "mode status should distinguish all three preferences concisely");
|
|
44
47
|
|
|
45
48
|
assert.match(app, /id: "codexFastMode"[\s\S]*?packageName: "@firstpick\/pi-extension-codex-fast-mode"[\s\S]*?capabilityLabel: "\/fast-mode"/, "browser Optional Features should catalog Fast mode");
|
|
46
49
|
assert.match(app, /OPTIONAL_FEATURE_DISABLE_PREREQUISITES = new Map\([\s\S]*?\["codexFastMode", \(\) => disableCodexFastModeIntegration\(\)\]/, "browser should register disable-off-first behavior");
|
|
47
50
|
assert.match(app, /if \(disabled\) \{[\s\S]*?OPTIONAL_FEATURE_DISABLE_PREREQUISITES\.get\(feature\.id\)[\s\S]*?await turnOff\(\)[\s\S]*?setOptionalFeatureDisabled\(feature\.id, disabled\)/, "Optional Features Disable should abort before hiding integration if turn-off fails");
|
|
48
51
|
assert.match(app, /function applyCodexFastModeStatus\(statusText\)[\s\S]*?codexSpeedModeFromStatus\(statusText\)[\s\S]*?if \(mode === null\) return false[\s\S]*?enabled: mode !== "normal"[\s\S]*?statusKnown: true/, "browser should consume only exact extension status values");
|
|
49
|
-
assert.match(app, /async function refreshCodexFastMode\(tabContext = activeTabContext\(\)\)[\s\S]*?api\("\/api\/codex-fast-mode", \{ tabId: tabContext\.tabId \}\)[\s\S]*?!featureEnabled && data\.available[\s\S]*?enabled: false[\s\S]*?isCurrentTabContext\(tabContext\)/, "browser status refresh should stay tab-scoped and disarm restored branches while the feature is hidden");
|
|
52
|
+
assert.match(app, /async function refreshCodexFastMode\(tabContext = activeTabContext\(\), \{ readOnly = false \} = \{\}\)[\s\S]*?api\("\/api\/codex-fast-mode", \{ tabId: tabContext\.tabId \}\)[\s\S]*?!readOnly && !featureEnabled && data\.available[\s\S]*?enabled: false[\s\S]*?isCurrentTabContext\(tabContext\)/, "browser status refresh should stay tab-scoped and disarm restored branches while the feature is hidden");
|
|
50
53
|
assert.match(app, /async function applyCodexFastMode\(\)[\s\S]*?await appConfirm\([\s\S]*?8x Standard included usage[\s\S]*?6x purchased-credit[\s\S]*?if \(!confirmed[\s\S]*?body: \{ mode \}, tabId: tabContext\.tabId/, "browser should confirm Ultrafast costs before applying explicit mode intent");
|
|
51
54
|
assert.match(app, /async function disableCodexFastModeIntegration\(\)[\s\S]*?tabs\.filter[\s\S]*?Promise\.all\(tabIds\.map[\s\S]*?data\.busy[\s\S]*?enabled: false[\s\S]*?codexFastModeConfirmedOff\(response\.data\)/, "browser-global Disable should preflight every live tab and require each mutation to confirm off");
|
|
52
55
|
assert.match(app, /refreshNaturalConversationMode\(tabContext\),[\s\S]*?refreshCodexFastMode\(tabContext\),/, "tab refreshes should reload branch-scoped Fast-mode state");
|
|
@@ -56,7 +59,9 @@ assert.match(technical, /## Normal and compact output[\s\S]*?select \*\*Compact\
|
|
|
56
59
|
assert.match(development, /### Codex subscription Fast mode[\s\S]*?service_tier: "priority"[\s\S]*?service_tier: "ultrafast"[\s\S]*?8× Standard included usage[\s\S]*?6×/, "development guide should document both tiers and cost semantics");
|
|
57
60
|
assert.match(technical, /Normal \/ Fast \/ Ultrafast[\s\S]*?Pro \$500/, "technical reference should document the third mode and subscription eligibility");
|
|
58
61
|
// Intent preserved: browser-asset changes must advance the coherent cache tuple.
|
|
59
|
-
assert.match(serviceWorker, /pi-webui-pwa-
|
|
60
|
-
assert.match(html, /data-app-src="\/app\.js\?v=
|
|
62
|
+
assert.match(serviceWorker, /pi-webui-pwa-v200[\s\S]*?"\/codex-speed-mode\.mjs"/, "PWA should refresh and cache the shared mode helper");
|
|
63
|
+
assert.match(html, /data-app-src="\/app\.js\?v=220"/, "browser module URL should be cache-busted for speed-mode wiring");
|
|
64
|
+
|
|
65
|
+
assert.match(server, /createCodexFastModeService\(\{[\s\S]*packageName: OPTIONAL_FEATURE_PACKAGES\.get\("codexFastMode"\)/, "server must wire the speed adapter to the canonical package catalog");
|
|
61
66
|
|
|
62
67
|
console.log("codex-fast-mode-static.test.mjs passed");
|
|
@@ -5,7 +5,7 @@ import * as modes from "../public/codex-speed-mode.mjs";
|
|
|
5
5
|
|
|
6
6
|
const source = await readFile(new URL("../public/app.js", import.meta.url), "utf8");
|
|
7
7
|
const start = source.indexOf("// Codex subscription Fast mode is owned");
|
|
8
|
-
const end = source.indexOf("
|
|
8
|
+
const end = source.indexOf("const SUBAGENT_LAUNCHER_LABELS", start);
|
|
9
9
|
assert.ok(start >= 0 && end > start, "execute the actual browser speed-control implementation");
|
|
10
10
|
const controlSource = source.slice(start, end);
|
|
11
11
|
|
|
@@ -13,6 +13,7 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
|
|
|
13
13
|
const calls = [];
|
|
14
14
|
const confirmations = [];
|
|
15
15
|
const events = [];
|
|
16
|
+
let shellRenders = 0;
|
|
16
17
|
const ultrafastOption = { disabled: true };
|
|
17
18
|
const select = { value: "normal", disabled: true, querySelector: () => ultrafastOption };
|
|
18
19
|
let currentTab = "tab-one";
|
|
@@ -36,6 +37,7 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
|
|
|
36
37
|
normalizeSelectedModel: (model) => model,
|
|
37
38
|
modelStateKey: (model) => `${model?.provider}/${model?.id}`,
|
|
38
39
|
renderStatus() {},
|
|
40
|
+
scheduleFocusedShellRender() { shellRenders++; },
|
|
39
41
|
requestGitFooterWebuiPayload() {},
|
|
40
42
|
queueMicrotask,
|
|
41
43
|
async appConfirm(options) {
|
|
@@ -57,14 +59,14 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
|
|
|
57
59
|
context.applyCodexFastModeData(data("normal"));
|
|
58
60
|
vm.runInContext("codexFastModeLoaded = true", context);
|
|
59
61
|
context.renderCodexFastModeControl();
|
|
60
|
-
return { context, calls, confirmations, events, select, tabModes, ultrafastOption, data, setEligible(value) { eligible = value; } };
|
|
62
|
+
return { context, calls, confirmations, events, get shellRenders() { return shellRenders; }, select, tabModes, ultrafastOption, data, setEligible(value) { eligible = value; } };
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
{
|
|
64
66
|
const h = harness();
|
|
65
67
|
assert.equal(h.context.applyCodexFastModeStatus("ultrafast"), true);
|
|
66
68
|
assert.equal(h.select.value, "ultrafast");
|
|
67
|
-
assert.equal(h.context.codexFastModeStatusText(), "Ultrafast · This
|
|
69
|
+
assert.equal(h.context.codexFastModeStatusText(), "Ultrafast · This thread");
|
|
68
70
|
assert.equal(h.context.applyCodexFastModeStatus("ultrafast now"), false);
|
|
69
71
|
assert.equal(h.select.value, "ultrafast");
|
|
70
72
|
assert.equal(h.context.codexFastModeConfirmedOff({ statusKnown: true, mode: "ultrafast", enabled: false }), false);
|
|
@@ -98,6 +100,7 @@ function harness({ confirm = true, eligible = true, enabledFeature = true } = {}
|
|
|
98
100
|
h.select.value = "ultrafast";
|
|
99
101
|
await h.context.applyCodexFastMode();
|
|
100
102
|
assert.equal(h.calls.length, 0, "changing tabs during cost confirmation must cancel the mutation");
|
|
103
|
+
assert.equal(h.shellRenders, 1, "settling the old confirmation schedules current Settings controls");
|
|
101
104
|
}
|
|
102
105
|
{
|
|
103
106
|
const h = harness({ eligible: false });
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
-
import {
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import vm from "node:vm";
|
|
5
|
+
import { CODEX_TOKEN_REFRESH_SKEW_MS, CODEX_USAGE_DIRECT_TOKEN_MESSAGE, codexUsageLoginGuidance, resolveCodexUsageAuth } from "../lib/codex-usage-auth.mjs";
|
|
4
6
|
|
|
5
|
-
function fakeRuntime(initial, refresh) {
|
|
6
|
-
|
|
7
|
+
function fakeRuntime(initial, refresh, { providerId = "openai-codex", additionalCredentials = {}, additionalProviders = {} } = {}) {
|
|
8
|
+
const stored = new Map(Object.entries({ ...additionalCredentials, [providerId]: structuredClone(initial) }));
|
|
7
9
|
let tail = Promise.resolve();
|
|
8
10
|
const credentials = {
|
|
9
|
-
async read() { return structuredClone(
|
|
10
|
-
modify(
|
|
11
|
+
async read(id) { return structuredClone(stored.get(id)); },
|
|
12
|
+
modify(id, update) {
|
|
11
13
|
const operation = tail.then(async () => {
|
|
12
|
-
const next = await update(structuredClone(
|
|
13
|
-
if (next !== undefined)
|
|
14
|
-
return structuredClone(
|
|
14
|
+
const next = await update(structuredClone(stored.get(id)));
|
|
15
|
+
if (next !== undefined) stored.set(id, structuredClone(next));
|
|
16
|
+
return structuredClone(stored.get(id));
|
|
15
17
|
});
|
|
16
18
|
tail = operation.then(() => undefined, () => undefined);
|
|
17
19
|
return operation;
|
|
@@ -19,7 +21,9 @@ function fakeRuntime(initial, refresh) {
|
|
|
19
21
|
};
|
|
20
22
|
return {
|
|
21
23
|
credentials,
|
|
22
|
-
getProvider() {
|
|
24
|
+
getProvider(id) {
|
|
25
|
+
return id === providerId ? { auth: { oauth: { refresh, isSubscription: true } } } : additionalProviders[id];
|
|
26
|
+
},
|
|
23
27
|
async getAuth() { throw new Error("OAuth tests must not use ordinary auth resolution"); },
|
|
24
28
|
};
|
|
25
29
|
}
|
|
@@ -63,3 +67,158 @@ test("forced refresh never returns the same rejected credential", async () => {
|
|
|
63
67
|
/rejected credential/,
|
|
64
68
|
);
|
|
65
69
|
});
|
|
70
|
+
|
|
71
|
+
const mustNotRefresh = async () => { throw new Error("unexpired credentials must not refresh"); };
|
|
72
|
+
|
|
73
|
+
test("Codex usage finds ChatGPT OAuth stored under the unified OpenAI provider", async () => {
|
|
74
|
+
const credential = oauth("chatgpt", NOW + 60 * 60 * 1000);
|
|
75
|
+
delete credential.accountId;
|
|
76
|
+
const runtime = fakeRuntime(credential, mustNotRefresh, { providerId: "openai" });
|
|
77
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
78
|
+
assert.equal(result.providerId, "openai");
|
|
79
|
+
assert.equal(result.accessToken, "chatgpt");
|
|
80
|
+
assert.deepEqual(result.credential, credential, "JWT-only account metadata must remain available to the server");
|
|
81
|
+
assert.equal(result.refreshed, false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("unified OpenAI credentials refresh under their own storage key", async () => {
|
|
85
|
+
let refreshCalls = 0;
|
|
86
|
+
const runtime = fakeRuntime(oauth("near", NOW + CODEX_TOKEN_REFRESH_SKEW_MS - 1), async (current) => {
|
|
87
|
+
refreshCalls += 1;
|
|
88
|
+
return { ...current, access: "replacement", expires: NOW + 60 * 60 * 1000 };
|
|
89
|
+
}, { providerId: "openai" });
|
|
90
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
91
|
+
assert.equal(refreshCalls, 1);
|
|
92
|
+
assert.equal(result.providerId, "openai");
|
|
93
|
+
assert.equal(result.accessToken, "replacement");
|
|
94
|
+
assert.equal(result.refreshed, true);
|
|
95
|
+
assert.equal((await runtime.credentials.read("openai")).access, "replacement");
|
|
96
|
+
assert.equal(await runtime.credentials.read("openai-codex"), undefined, "refresh must not copy or migrate credentials");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("concurrent forced refreshes reuse the newer unified OpenAI credential", async () => {
|
|
100
|
+
let refreshCalls = 0;
|
|
101
|
+
const runtime = fakeRuntime(oauth("rejected", NOW + 60 * 60 * 1000), async (current) => {
|
|
102
|
+
refreshCalls += 1;
|
|
103
|
+
return { ...current, access: "replacement", expires: NOW + 2 * 60 * 60 * 1000 };
|
|
104
|
+
}, { providerId: "openai" });
|
|
105
|
+
const results = await Promise.all([
|
|
106
|
+
resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW, forceRefresh: true }),
|
|
107
|
+
resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW, forceRefresh: true }),
|
|
108
|
+
]);
|
|
109
|
+
assert.equal(refreshCalls, 1);
|
|
110
|
+
assert.ok(results.every((result) => result.accessToken === "replacement" && result.refreshed));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("unified OpenAI forced refresh rejects an unchanged token", async () => {
|
|
114
|
+
const runtime = fakeRuntime(oauth("rejected", NOW + 60 * 60 * 1000), async (current) => ({ ...current }), { providerId: "openai" });
|
|
115
|
+
await assert.rejects(resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW, forceRefresh: true }), /rejected credential/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("a usable legacy Codex login keeps precedence when both providers exist", async () => {
|
|
119
|
+
const runtime = fakeRuntime(oauth("legacy", NOW + 60 * 60 * 1000), mustNotRefresh, {
|
|
120
|
+
additionalCredentials: { openai: oauth("unified", NOW + 60 * 60 * 1000) },
|
|
121
|
+
additionalProviders: { openai: { auth: { oauth: { isSubscription: true, refresh: mustNotRefresh } } } },
|
|
122
|
+
});
|
|
123
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
124
|
+
assert.equal(result.providerId, "openai-codex");
|
|
125
|
+
assert.equal(result.accessToken, "legacy");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("an orphaned legacy credential does not hide a usable unified OpenAI login", async () => {
|
|
129
|
+
const runtime = fakeRuntime(oauth("unified", NOW + 60 * 60 * 1000), mustNotRefresh, {
|
|
130
|
+
providerId: "openai",
|
|
131
|
+
additionalCredentials: { "openai-codex": oauth("orphaned", NOW + 60 * 60 * 1000) },
|
|
132
|
+
});
|
|
133
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
134
|
+
assert.equal(result.providerId, "openai");
|
|
135
|
+
assert.equal(result.accessToken, "unified");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("a runtime with both providers can use unified OAuth when legacy login is absent", async () => {
|
|
139
|
+
const runtime = fakeRuntime(undefined, mustNotRefresh, {
|
|
140
|
+
additionalCredentials: { openai: oauth("unified", NOW + 60 * 60 * 1000) },
|
|
141
|
+
additionalProviders: { openai: { auth: { oauth: { isSubscription: true, refresh: mustNotRefresh } } } },
|
|
142
|
+
});
|
|
143
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
144
|
+
assert.equal(result.providerId, "openai");
|
|
145
|
+
assert.equal(result.accessToken, "unified");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("unified OpenAI API keys and environment auth are never resolved for subscription usage", async () => {
|
|
149
|
+
for (const credential of [undefined, { type: "api_key", key: "fake-api-key" }]) {
|
|
150
|
+
const runtime = fakeRuntime(credential, mustNotRefresh, { providerId: "openai" });
|
|
151
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
152
|
+
assert.equal(result.providerId, "openai");
|
|
153
|
+
assert.equal(result.accessToken, undefined);
|
|
154
|
+
assert.deepEqual(result.credential, credential);
|
|
155
|
+
assert.equal(result.refreshed, false);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("older API-key-only OpenAI providers are not treated as subscription OAuth aliases", async () => {
|
|
160
|
+
const runtime = fakeRuntime(undefined, mustNotRefresh, {
|
|
161
|
+
additionalCredentials: { openai: oauth("wrong-provider", NOW + 60 * 60 * 1000) },
|
|
162
|
+
additionalProviders: { openai: { auth: { apiKey: {} } } },
|
|
163
|
+
});
|
|
164
|
+
runtime.getAuth = async (id) => { assert.equal(id, "openai-codex"); return undefined; };
|
|
165
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW });
|
|
166
|
+
assert.equal(result.providerId, "openai-codex");
|
|
167
|
+
assert.equal(result.accessToken, undefined);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("login guidance follows the runtime's available subscription provider", () => {
|
|
171
|
+
assert.equal(codexUsageLoginGuidance(fakeRuntime(undefined, mustNotRefresh)), "Run /login and choose ChatGPT Plus/Pro (Codex Subscription).");
|
|
172
|
+
assert.equal(codexUsageLoginGuidance(fakeRuntime(undefined, mustNotRefresh, { providerId: "openai" })), "Run /login, choose OpenAI, then Sign in with ChatGPT.");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("direct ChatGPT logins are recognized but never refreshed or forwarded to Codex usage", async () => {
|
|
176
|
+
for (const providerId of ["openai", "openai-codex"]) {
|
|
177
|
+
for (const forceRefresh of [false, true]) {
|
|
178
|
+
const credential = { ...oauth("direct-access", NOW - 1), clientId: "fake-client", scopes: ["openid", "chatgpt.tokens.use.direct"] };
|
|
179
|
+
delete credential.accountId;
|
|
180
|
+
const runtime = fakeRuntime(credential, mustNotRefresh, { providerId });
|
|
181
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW, forceRefresh });
|
|
182
|
+
assert.equal(result.providerId, providerId);
|
|
183
|
+
assert.equal(result.unsupportedReason, "chatgpt-direct-token");
|
|
184
|
+
assert.equal(result.accessToken, undefined);
|
|
185
|
+
assert.equal(result.refreshed, false);
|
|
186
|
+
assert.deepEqual(await runtime.credentials.read(providerId), credential);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("a concurrent switch to direct ChatGPT login is rechecked under the credential lock", async () => {
|
|
192
|
+
const runtime = fakeRuntime(oauth("rejected", NOW - 1), mustNotRefresh, { providerId: "openai" });
|
|
193
|
+
const modify = runtime.credentials.modify;
|
|
194
|
+
runtime.credentials.modify = async (id, update) => {
|
|
195
|
+
await modify(id, () => ({ ...oauth("direct-access", NOW - 1), scopes: ["chatgpt.tokens.use.direct"] }));
|
|
196
|
+
return modify(id, update);
|
|
197
|
+
};
|
|
198
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { now: NOW, forceRefresh: true });
|
|
199
|
+
assert.equal(result.unsupportedReason, "chatgpt-direct-token");
|
|
200
|
+
assert.equal(result.accessToken, undefined);
|
|
201
|
+
assert.equal(result.refreshed, false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("the legacy reader reports direct ChatGPT usage as unsupported without calling the Codex backend", async () => {
|
|
205
|
+
const source = await readFile(new URL("../bin/pi-webui.mjs", import.meta.url), "utf8");
|
|
206
|
+
const start = source.indexOf("async function getOpenAICodexUsageCredentials(");
|
|
207
|
+
const end = source.indexOf("const getOpenAICodexUsageStatus = createCodexUsageReader", start);
|
|
208
|
+
assert.ok(start >= 0 && end > start);
|
|
209
|
+
for (const providerId of ["openai", "openai-codex"]) {
|
|
210
|
+
const runtime = fakeRuntime({ ...oauth("direct-access", NOW - 1), scopes: ["chatgpt.tokens.use.direct"] }, mustNotRefresh, { providerId });
|
|
211
|
+
const status = vm.runInNewContext(`${source.slice(start, end)}\ngetLegacyOpenAICodexUsageStatus;`, {
|
|
212
|
+
authContext: async () => ({ modelRuntime: runtime }),
|
|
213
|
+
CODEX_USAGE_DIRECT_TOKEN_MESSAGE,
|
|
214
|
+
codexUsageLoginGuidance,
|
|
215
|
+
resolveCodexUsageAuth,
|
|
216
|
+
OPENAI_CODEX_PROVIDER_ID: "openai-codex",
|
|
217
|
+
makeHttpError: (statusCode, message) => Object.assign(new Error(message), { statusCode }),
|
|
218
|
+
fetch: () => assert.fail("direct ChatGPT credentials must not reach the Codex backend"),
|
|
219
|
+
});
|
|
220
|
+
for (const forceRefresh of [false, true]) {
|
|
221
|
+
await assert.rejects(status({ forceRefresh }), (error) => error.statusCode === 501 && error.message === CODEX_USAGE_DIRECT_TOKEN_MESSAGE);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { terminateProcessTree } from "../lib/process-tree.mjs";
|
|
10
|
+
|
|
11
|
+
const packageRoot = fileURLToPath(new URL("../", import.meta.url));
|
|
12
|
+
const root = await mkdtemp(path.join(tmpdir(), "pi-webui-codex-usage-http-"));
|
|
13
|
+
const children = [];
|
|
14
|
+
const legacyRequests = [];
|
|
15
|
+
const legacy = createServer((req, res) => {
|
|
16
|
+
legacyRequests.push(req.headers.authorization);
|
|
17
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
18
|
+
res.end(JSON.stringify({ plan_type: "plus", rate_limit: { primary_window: { used_percent: 8, limit_window_seconds: 18000 } }, accountId: "fixture-private-account", accessToken: "fixture-private-token" }));
|
|
19
|
+
});
|
|
20
|
+
await new Promise((resolve) => legacy.listen(0, "127.0.0.1", resolve));
|
|
21
|
+
|
|
22
|
+
async function freePort() {
|
|
23
|
+
const server = createServer();
|
|
24
|
+
await new Promise((resolve, reject) => server.once("error", reject).listen(0, "127.0.0.1", resolve));
|
|
25
|
+
const port = server.address().port;
|
|
26
|
+
await new Promise((resolve) => server.close(resolve));
|
|
27
|
+
return port;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function request(port, pathname, method = "GET") {
|
|
31
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, { method, signal: AbortSignal.timeout(10_000) });
|
|
32
|
+
return { status: response.status, body: await response.json() };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function start(name, codex, credentials = {}) {
|
|
36
|
+
const agentDir = path.join(root, name, "agent");
|
|
37
|
+
await mkdir(agentDir, { recursive: true });
|
|
38
|
+
await writeFile(path.join(agentDir, "auth.json"), JSON.stringify(credentials));
|
|
39
|
+
const log = path.join(root, name, "codex.jsonl");
|
|
40
|
+
const port = await freePort();
|
|
41
|
+
// Omit --cwd so this harness needs no Pi child or model turn.
|
|
42
|
+
const child = spawn(process.execPath, [path.join(packageRoot, "bin", "pi-webui.mjs"), "--host", "127.0.0.1", "--port", String(port), "--pi", path.join(packageRoot, "tests", "fixtures", "fake-pi.mjs")], {
|
|
43
|
+
detached: process.platform !== "win32",
|
|
44
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
45
|
+
env: {
|
|
46
|
+
...process.env,
|
|
47
|
+
NODE_ENV: "test",
|
|
48
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
49
|
+
PI_WEBUI_SETTINGS_FILE: path.join(root, name, "settings.json"),
|
|
50
|
+
PI_WEBUI_RPC_SUPERVISOR: "0",
|
|
51
|
+
PI_WEBUI_UPDATE_TEST_HOME: path.join(root, "coordination"),
|
|
52
|
+
PI_WEBUI_CODEX_BIN: codex,
|
|
53
|
+
PI_WEBUI_CODEX_USAGE_URL: `http://127.0.0.1:${legacy.address().port}/usage`,
|
|
54
|
+
FAKE_CODEX_MODE: "success",
|
|
55
|
+
FAKE_CODEX_LOG: log,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
children.push(child);
|
|
59
|
+
let output = "";
|
|
60
|
+
for (const stream of [child.stdout, child.stderr]) stream.on("data", (chunk) => { output = (output + chunk.toString()).slice(-65536); });
|
|
61
|
+
let ready = false;
|
|
62
|
+
for (let attempt = 0; attempt < 100 && child.exitCode === null; attempt++) {
|
|
63
|
+
try { if ((await request(port, "/api/health")).status === 200) { ready = true; break; } } catch {}
|
|
64
|
+
await delay(100);
|
|
65
|
+
}
|
|
66
|
+
assert.ok(ready, `isolated WebUI should start\n${output}`);
|
|
67
|
+
return { child, port, log };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function stop(server) {
|
|
71
|
+
if (server.child.exitCode !== null) return;
|
|
72
|
+
try { await request(server.port, "/api/shutdown", "POST"); } catch {}
|
|
73
|
+
for (let attempt = 0; attempt < 100 && server.child.exitCode === null; attempt++) await delay(50);
|
|
74
|
+
terminateProcessTree(server.child, "SIGKILL");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function launches(log) {
|
|
78
|
+
return (await readFile(log, "utf8")).split("\n").filter(Boolean).map(JSON.parse).filter((entry) => entry.kind === "start");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const cli = await start("cli", path.join(packageRoot, "tests", "fixtures", "fake-codex-app-server.mjs"));
|
|
83
|
+
const [first, simultaneous] = await Promise.all([request(cli.port, "/api/codex-usage"), request(cli.port, "/api/codex-usage")]);
|
|
84
|
+
assert.equal(first.status, 200);
|
|
85
|
+
assert.equal(simultaneous.status, 200);
|
|
86
|
+
assert.equal(first.body.data.source, "codex-cli");
|
|
87
|
+
assert.equal(first.body.data.selected.primary.usedPercent, 25);
|
|
88
|
+
assert.equal(first.body.data.selected.secondary.usedPercent, 42);
|
|
89
|
+
assert.doesNotMatch(JSON.stringify(first.body), /private-|fixture-.*secret|email|accessToken|accountId/);
|
|
90
|
+
assert.equal((await launches(cli.log)).length, 1, "concurrent HTTP requests must share one CLI process");
|
|
91
|
+
await request(cli.port, "/api/codex-usage");
|
|
92
|
+
assert.equal((await launches(cli.log)).length, 1, "normal reads use the successful cache");
|
|
93
|
+
assert.equal((await request(cli.port, "/api/codex-usage?refresh=1")).status, 200);
|
|
94
|
+
assert.equal((await launches(cli.log)).length, 2, "explicit refresh bypasses the completed cache");
|
|
95
|
+
assert.equal(legacyRequests.length, 0, "CLI success must not touch the legacy endpoint");
|
|
96
|
+
await stop(cli);
|
|
97
|
+
|
|
98
|
+
const credential = { type: "oauth", access: "fixture-legacy-access", refresh: "fixture-legacy-refresh", expires: Date.now() + 60 * 60 * 1000, accountId: "fixture-legacy-account" };
|
|
99
|
+
const fallback = await start("fallback", path.join(root, "missing-codex.exe"), { "openai-codex": credential });
|
|
100
|
+
const legacyResult = await request(fallback.port, "/api/codex-usage");
|
|
101
|
+
assert.equal(legacyResult.status, 200);
|
|
102
|
+
assert.equal(legacyResult.body.data.source, "chatgpt.com");
|
|
103
|
+
assert.equal(legacyResult.body.data.selected.primary.usedPercent, 8);
|
|
104
|
+
assert.match(legacyResult.body.data.sourceNotice, /legacy Codex login/);
|
|
105
|
+
assert.deepEqual(legacyRequests, ["Bearer fixture-legacy-access"]);
|
|
106
|
+
assert.doesNotMatch(JSON.stringify(legacyResult.body), /fixture-legacy|fixture-private/);
|
|
107
|
+
await stop(fallback);
|
|
108
|
+
|
|
109
|
+
const unavailable = await start("unavailable", path.join(root, "missing-codex.exe"));
|
|
110
|
+
const error = await request(unavailable.port, "/api/codex-usage");
|
|
111
|
+
assert.equal(error.status, 503);
|
|
112
|
+
assert.match(error.body.error, /Codex CLI was not found/);
|
|
113
|
+
assert.match(error.body.error, /legacy Codex usage fallback/);
|
|
114
|
+
assert.doesNotMatch(error.body.error, /stack|fixture-|auth\.json|AppData/);
|
|
115
|
+
await stop(unavailable);
|
|
116
|
+
console.log("codex-usage-http.test.mjs passed");
|
|
117
|
+
} finally {
|
|
118
|
+
for (const child of children) terminateProcessTree(child, "SIGKILL");
|
|
119
|
+
await new Promise((resolve) => legacy.close(resolve));
|
|
120
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
121
|
+
try { await rm(root, { recursive: true, force: true }); break; }
|
|
122
|
+
catch (error) { if (attempt === 19 || !["EBUSY", "EPERM", "ENOTEMPTY"].includes(error.code)) throw error; await delay(100); }
|
|
123
|
+
}
|
|
124
|
+
}
|