@firstpick/pi-package-webui 0.11.1 → 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 +151 -12
- package/README.md +34 -6
- package/TECHNICAL.md +75 -8
- package/bin/pi-webui.mjs +5390 -11423
- package/index.ts +10 -3
- 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 +4 -4
- 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 -3886
- 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/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-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-source.test.mjs +4 -3
- 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-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 +21 -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-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,536 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdtemp, mkdir, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
+
import { stripVTControlCharacters } from "node:util";
|
|
8
|
+
import test from "node:test";
|
|
9
|
+
import { createAppRunnerService } from "../lib/server/app-runners.mjs";
|
|
10
|
+
|
|
11
|
+
const configName = ".pi-webui-runners.json";
|
|
12
|
+
const errorStatus = (code) => (error) => error.statusCode === code;
|
|
13
|
+
|
|
14
|
+
async function waitFor(probe, description, timeoutMs = 6_000) {
|
|
15
|
+
const deadline = Date.now() + timeoutMs;
|
|
16
|
+
do {
|
|
17
|
+
const result = await probe();
|
|
18
|
+
if (result) return result;
|
|
19
|
+
await delay(20);
|
|
20
|
+
} while (Date.now() < deadline);
|
|
21
|
+
assert.fail(`Timed out waiting for ${description}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function fixture(t, { available = [process.execPath], commandResult, helper } = {}) {
|
|
25
|
+
const root = await mkdtemp(path.join(tmpdir(), "webui-runner-service-"));
|
|
26
|
+
const tab = { id: "runner-tab", title: "Runner fixture", cwd: root, appRunner: null };
|
|
27
|
+
const tabs = new Map([[tab.id, tab]]);
|
|
28
|
+
const probes = [];
|
|
29
|
+
const updates = [];
|
|
30
|
+
const events = [];
|
|
31
|
+
const deliveries = [];
|
|
32
|
+
const service = createAppRunnerService({
|
|
33
|
+
defaultCwd: root,
|
|
34
|
+
runCommand: async (command, args, options) => {
|
|
35
|
+
probes.push({ command, args, options });
|
|
36
|
+
if (commandResult) return commandResult(command, args, options);
|
|
37
|
+
return available.includes(command)
|
|
38
|
+
? { exitCode: 0, stdout: "fixture version", stderr: "" }
|
|
39
|
+
: { exitCode: 127, stdout: "", stderr: "", error: "not available" };
|
|
40
|
+
},
|
|
41
|
+
resolveCwd: async (value, base) => {
|
|
42
|
+
const target = path.resolve(base, value);
|
|
43
|
+
assert.equal((await stat(target)).isDirectory(), true);
|
|
44
|
+
return target;
|
|
45
|
+
},
|
|
46
|
+
normalizeSuggestionPath: (value) => String(value || "").replace(/\\/g, "/"),
|
|
47
|
+
readJsonFileIfExists: async (file) => {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(await readFile(file, "utf8"));
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error.code === "ENOENT") return undefined;
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
makeHttpError: (statusCode, message) => Object.assign(new Error(message), { statusCode }),
|
|
56
|
+
formatCliError: (error) => error.message || String(error),
|
|
57
|
+
sanitizeError: (error) => error.message || String(error),
|
|
58
|
+
displayPath: (value) => value,
|
|
59
|
+
stripAnsi: stripVTControlCharacters,
|
|
60
|
+
hasTab: (id) => tabs.has(id),
|
|
61
|
+
broadcastTabEvent: (target, event) => updates.push({ target, event, at: Date.now() }),
|
|
62
|
+
tabActivitySnapshot: (target) => ({ tab: target.id, fixture: true }),
|
|
63
|
+
recordEvent: (event) => events.push(event),
|
|
64
|
+
sendWebuiHelperCommand: async (target, command, payload) => {
|
|
65
|
+
deliveries.push({ target, command, payload });
|
|
66
|
+
return helper ? helper(target, command, payload) : { delivery: "context" };
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
await writeFile(path.join(root, configName), JSON.stringify({ version: 2, searchPaths: [], runners: [] }));
|
|
70
|
+
t.after(async () => {
|
|
71
|
+
service.stopAppRunnerForTab(tab, "fixture cleanup", { force: true });
|
|
72
|
+
if (tab.appRunner?.status === "running") {
|
|
73
|
+
await waitFor(() => tab.appRunner.status !== "running", "fixture process cleanup");
|
|
74
|
+
}
|
|
75
|
+
clearTimeout(tab.appRunnerBroadcastTimer);
|
|
76
|
+
clearTimeout(tab.appRunner?.stopTimer);
|
|
77
|
+
await rm(root, { recursive: true, force: true });
|
|
78
|
+
});
|
|
79
|
+
return { root, tab, tabs, service, probes, updates, events, deliveries };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function pipeMode(t) {
|
|
83
|
+
const previous = process.env.PI_WEBUI_APP_RUNNER_PTY;
|
|
84
|
+
process.env.PI_WEBUI_APP_RUNNER_PTY = "off";
|
|
85
|
+
t.after(() => {
|
|
86
|
+
if (previous === undefined) delete process.env.PI_WEBUI_APP_RUNNER_PTY;
|
|
87
|
+
else process.env.PI_WEBUI_APP_RUNNER_PTY = previous;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function addNodeRunner(f, code, { id = "fixture", args = [] } = {}) {
|
|
92
|
+
const file = `${id}.mjs`;
|
|
93
|
+
await writeFile(path.join(f.root, file), code);
|
|
94
|
+
const data = await f.service.saveCustomAppRunner(f.tab, {
|
|
95
|
+
id, label: id, command: process.execPath, path: file, args,
|
|
96
|
+
});
|
|
97
|
+
return data.runners.find((runner) => runner.id === `custom:${id}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function output(f) {
|
|
101
|
+
const run = f.service.publicAppRunnerState(f.tab.appRunner);
|
|
102
|
+
return [...(run?.lines || []), run?.pendingLine || ""].join("\n");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
test("factory exposes the fixed interface and imports without starting a server", async (t) => {
|
|
106
|
+
const f = await fixture(t);
|
|
107
|
+
assert.deepEqual(Object.keys(f.service).sort(), [
|
|
108
|
+
"getAppRunnerData", "getCustomAppRunnerConfigData", "saveCustomAppRunner",
|
|
109
|
+
"saveAppRunnerSearchPaths", "deleteCustomAppRunner", "getAppRunnerFileBrowserData",
|
|
110
|
+
"startAppRunner", "sendAppRunnerInput", "transferAppRunnerContext",
|
|
111
|
+
"stopAppRunnerForTab", "clearAppRunnerForTab", "publicAppRunnerState",
|
|
112
|
+
].sort());
|
|
113
|
+
assert.deepEqual(f.probes, []);
|
|
114
|
+
assert.deepEqual(f.updates, []);
|
|
115
|
+
assert.deepEqual(f.events, []);
|
|
116
|
+
assert.equal(f.service.publicAppRunnerState(null), null);
|
|
117
|
+
assert.equal(f.tab.appRunner, null);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("discovery preserves language candidates, manager preference, deduplication and bounded probes", async (t) => {
|
|
121
|
+
const commands = ["bun", "pnpm", "npm", "yarn", "npx", "cargo", "go", "zig", "uv", "python3", "bash", "sh", "cc", "c++", "cmake", "docker", "docker-compose", "deno", "just", "make"];
|
|
122
|
+
const f = await fixture(t, { available: commands });
|
|
123
|
+
const files = {
|
|
124
|
+
"package.json": JSON.stringify({ scripts: { dev: "vite", start: "node index.js" }, packageManager: "pnpm@10", dependencies: { vite: "*", storybook: "*", "@storybook/react": "*" } }),
|
|
125
|
+
"pnpm-lock.yaml": "", "Cargo.toml": "", "main.go": "", "main.py": "",
|
|
126
|
+
"build.zig": 'b.step("run", "Run");', "main.zig": "",
|
|
127
|
+
"CMakeLists.txt": "add_executable(my-app main.cpp)", "compose.yaml": "services: {}",
|
|
128
|
+
"dev.sh": "echo fixture", "deno.json": '{\n "tasks": {\n "dev": "deno run main.ts"\n }\n}',
|
|
129
|
+
"justfile": "dev:\n echo fixture", "Makefile": "run:\n\techo fixture",
|
|
130
|
+
};
|
|
131
|
+
for (const [name, content] of Object.entries(files)) await writeFile(path.join(f.root, name), content);
|
|
132
|
+
const data = await f.service.getAppRunnerData(f.tab);
|
|
133
|
+
const ids = data.runners.map((runner) => runner.id);
|
|
134
|
+
assert.equal(ids[0], "rust:cargo-run");
|
|
135
|
+
for (const id of ["pkg:pnpm:dev", "pkg:npm:dev", "npx:vite", "go:.", "zig:build-run", "deno:dev", "just:dev", "make:run", "shell:bash:dev.sh"]) {
|
|
136
|
+
assert.ok(ids.includes(id), `missing ${id}`);
|
|
137
|
+
}
|
|
138
|
+
assert.ok(ids.indexOf("pkg:pnpm:dev") < ids.indexOf("pkg:npm:dev"));
|
|
139
|
+
assert.equal(data.runners.filter((runner) => runner.displayCommand === "npx --no-install storybook dev").length, 1);
|
|
140
|
+
assert.deepEqual(data.runners.find((runner) => runner.id === "pkg:pnpm:dev").args, ["run", "dev"]);
|
|
141
|
+
assert.ok(data.runners.every((runner) => !("priority" in runner)));
|
|
142
|
+
const firstProbeCount = f.probes.filter((probe) => probe.args[0] === "--version").length;
|
|
143
|
+
await f.service.getAppRunnerData(f.tab);
|
|
144
|
+
assert.equal(f.probes.filter((probe) => probe.args[0] === "--version").length, firstProbeCount);
|
|
145
|
+
for (const probe of f.probes) {
|
|
146
|
+
assert.equal(probe.options.timeoutMs, 1_200);
|
|
147
|
+
assert.equal(probe.options.maxOutputLength, 2_000);
|
|
148
|
+
assert.equal(probe.options.cwd, f.root);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("availability accepts version stderr and isolates caches by factory", async (t) => {
|
|
153
|
+
const f = await fixture(t, {
|
|
154
|
+
commandResult: (command) => command === "node"
|
|
155
|
+
? { exitCode: 1, stdout: "", stderr: "node fixture version" }
|
|
156
|
+
: { exitCode: 127, error: "unavailable" },
|
|
157
|
+
});
|
|
158
|
+
await writeFile(path.join(f.root, "main.js"), "");
|
|
159
|
+
assert.ok((await f.service.getAppRunnerData(f.tab)).runners.some((runner) => runner.id === "node:main.js"));
|
|
160
|
+
const g = await fixture(t, { available: [] });
|
|
161
|
+
await writeFile(path.join(g.root, "main.js"), "");
|
|
162
|
+
assert.deepEqual((await g.service.getAppRunnerData(g.tab)).runners, []);
|
|
163
|
+
assert.ok(g.probes.some((probe) => probe.command === "node"));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("v2 config writes, ancestor discovery, command arguments, deletion and file picker remain compatible", async (t) => {
|
|
167
|
+
const f = await fixture(t);
|
|
168
|
+
await mkdir(path.join(f.root, "nested"));
|
|
169
|
+
await mkdir(path.join(f.root, ".git"));
|
|
170
|
+
await writeFile(path.join(f.root, "a.txt"), "text");
|
|
171
|
+
await writeFile(path.join(f.root, ".hidden"), "private");
|
|
172
|
+
await writeFile(path.join(f.root, "entry.mjs"), "");
|
|
173
|
+
f.tab.cwd = path.join(f.root, "nested");
|
|
174
|
+
const data = await f.service.saveCustomAppRunner(f.tab, {
|
|
175
|
+
id: "example", label: "Example", command: `${process.execPath} --no-warnings`, path: "entry.mjs", args: ["two words", "--flag"],
|
|
176
|
+
});
|
|
177
|
+
const runner = data.runners.find((item) => item.id === "custom:example");
|
|
178
|
+
assert.equal(runner.cwd, f.root);
|
|
179
|
+
assert.deepEqual(runner.args, ["--no-warnings", "entry.mjs", "two words", "--flag"]);
|
|
180
|
+
assert.match(runner.displayCommand, /"two words"/);
|
|
181
|
+
const saved = JSON.parse(await readFile(path.join(f.root, configName), "utf8"));
|
|
182
|
+
assert.equal(saved.version, 2);
|
|
183
|
+
assert.deepEqual(saved.searchPaths, []);
|
|
184
|
+
assert.deepEqual(saved.runners[0].args, ["two words", "--flag"]);
|
|
185
|
+
if (process.platform !== "win32") assert.equal((await stat(path.join(f.root, configName))).mode & 0o777, 0o600);
|
|
186
|
+
const config = await f.service.getCustomAppRunnerConfigData();
|
|
187
|
+
assert.equal(config.projectRoot, f.root);
|
|
188
|
+
assert.equal(config.relativeConfigFile, configName);
|
|
189
|
+
assert.equal(config.runners[0].available, true);
|
|
190
|
+
const browser = await f.service.getAppRunnerFileBrowserData(f.tab, "");
|
|
191
|
+
assert.equal(browser.parent, null);
|
|
192
|
+
assert.deepEqual(browser.directories.map((item) => item.name), ["nested"]);
|
|
193
|
+
assert.ok(browser.files.some((item) => item.name === ".hidden" && item.hidden));
|
|
194
|
+
const nested = await f.service.getAppRunnerFileBrowserData(f.tab, "nested");
|
|
195
|
+
assert.equal(nested.parent, "");
|
|
196
|
+
assert.equal(nested.relativeDir, "nested");
|
|
197
|
+
const deleted = await f.service.deleteCustomAppRunner(f.tab, "custom:example");
|
|
198
|
+
assert.deepEqual(deleted.customRunnerConfig.runners, []);
|
|
199
|
+
await assert.rejects(f.service.deleteCustomAppRunner(f.tab, "example"), errorStatus(404));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("runner path validation and config limits reject invalid writes without replacing saved configuration", async (t) => {
|
|
203
|
+
const f = await fixture(t);
|
|
204
|
+
await writeFile(path.join(f.root, "entry.mjs"), "");
|
|
205
|
+
const initial = await readFile(path.join(f.root, configName), "utf8");
|
|
206
|
+
const invalid = [
|
|
207
|
+
{ path: "../entry.mjs" }, { path: "/entry.mjs" }, { path: "C:/entry.mjs" },
|
|
208
|
+
{ path: "entry.mjs", command: "node\n--help" },
|
|
209
|
+
{ path: "entry.mjs", args: ["bad\0arg"] },
|
|
210
|
+
{ path: "entry.mjs", args: Array(33).fill("arg") },
|
|
211
|
+
{ path: "missing.mjs" },
|
|
212
|
+
];
|
|
213
|
+
for (const runner of invalid) {
|
|
214
|
+
await assert.rejects(f.service.saveCustomAppRunner(f.tab, { command: process.execPath, ...runner }), errorStatus(400));
|
|
215
|
+
assert.equal(await readFile(path.join(f.root, configName), "utf8"), initial);
|
|
216
|
+
}
|
|
217
|
+
for (const paths of [[".."], [".".repeat(4)], ["/tmp"], ["a/../b"], ["bad\0path"], ["missing"], [".", "."], Array(25).fill(".")]) {
|
|
218
|
+
await assert.rejects(f.service.saveAppRunnerSearchPaths(f.tab, paths), errorStatus(400));
|
|
219
|
+
}
|
|
220
|
+
await assert.rejects(f.service.getAppRunnerFileBrowserData(f.tab, "../"), errorStatus(400));
|
|
221
|
+
await assert.rejects(f.service.getAppRunnerFileBrowserData(f.tab, "entry.mjs"), errorStatus(400));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("legacy config reads and malformed collection diagnostics retain strict write refusal", async (t) => {
|
|
225
|
+
const f = await fixture(t);
|
|
226
|
+
await writeFile(path.join(f.root, "entry.mjs"), "");
|
|
227
|
+
await writeFile(path.join(f.root, configName), JSON.stringify({ version: 1, runners: [{ id: "legacy", command: process.execPath, path: "entry.mjs" }] }));
|
|
228
|
+
const legacy = await f.service.getCustomAppRunnerConfigData(f.tab);
|
|
229
|
+
assert.equal(legacy.version, 2);
|
|
230
|
+
assert.deepEqual(legacy.searchPaths, []);
|
|
231
|
+
assert.equal(legacy.runners[0].available, true);
|
|
232
|
+
await f.service.saveAppRunnerSearchPaths(f.tab, ["."]);
|
|
233
|
+
const migrated = JSON.parse(await readFile(path.join(f.root, configName), "utf8"));
|
|
234
|
+
assert.equal(migrated.version, 2);
|
|
235
|
+
assert.equal(migrated.runners[0].id, "legacy");
|
|
236
|
+
const malformed = JSON.stringify({ version: 2, runners: {}, searchPaths: {} });
|
|
237
|
+
await writeFile(path.join(f.root, configName), malformed);
|
|
238
|
+
const diagnosed = await f.service.getCustomAppRunnerConfigData(f.tab);
|
|
239
|
+
assert.deepEqual(diagnosed.runners, []);
|
|
240
|
+
assert.equal(diagnosed.diagnostics.length, 2);
|
|
241
|
+
assert.ok(diagnosed.diagnostics.every((entry) => entry.severity === "error"));
|
|
242
|
+
await assert.rejects(f.service.saveAppRunnerSearchPaths(f.tab, []), errorStatus(400));
|
|
243
|
+
await assert.rejects(f.service.saveCustomAppRunner(f.tab, { command: process.execPath, path: "entry.mjs" }), errorStatus(400));
|
|
244
|
+
assert.equal(await readFile(path.join(f.root, configName), "utf8"), malformed);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("configured discovery canonicalizes paths and excludes files and directories escaping through symlinks", { skip: process.platform === "win32" ? "POSIX symlink fixture; Windows junction/permission coverage belongs to parent" : false }, async (t) => {
|
|
248
|
+
const f = await fixture(t, { available: [process.execPath, "bash", "python3"] });
|
|
249
|
+
const outside = await mkdtemp(path.join(tmpdir(), "webui-runner-outside-"));
|
|
250
|
+
t.after(() => rm(outside, { recursive: true, force: true }));
|
|
251
|
+
await mkdir(path.join(f.root, "tools"));
|
|
252
|
+
await writeFile(path.join(f.root, "tools", "task.py"), "print('fixture')");
|
|
253
|
+
await writeFile(path.join(f.root, "tools", "dev.sh"), "echo fixture");
|
|
254
|
+
await writeFile(path.join(outside, "external.py"), "print('outside')");
|
|
255
|
+
await symlink(outside, path.join(f.root, "external-dir"), "dir");
|
|
256
|
+
await symlink(path.join(outside, "external.py"), path.join(f.root, "tools", "external.py"));
|
|
257
|
+
await symlink(path.join(f.root, "tools", "task.py"), path.join(f.root, "tools", "internal.py"));
|
|
258
|
+
const data = await f.service.saveAppRunnerSearchPaths(f.tab, ["./tools/"]);
|
|
259
|
+
assert.deepEqual(data.customRunnerConfig.searchPaths, ["tools"]);
|
|
260
|
+
assert.ok(data.runners.some((runner) => runner.projectFile === "tools/task.py" && runner.cwd === f.root));
|
|
261
|
+
assert.ok(data.runners.some((runner) => runner.projectFile === "tools/internal.py"));
|
|
262
|
+
assert.ok(data.runners.some((runner) => runner.projectFile === "tools/dev.sh"));
|
|
263
|
+
assert.ok(data.runners.every((runner) => runner.projectFile !== "tools/external.py"));
|
|
264
|
+
await assert.rejects(f.service.saveAppRunnerSearchPaths(f.tab, ["external-dir"]), /outside the project root/);
|
|
265
|
+
await assert.rejects(f.service.saveCustomAppRunner(f.tab, { command: process.execPath, path: "tools/external.py" }), /outside the project root/);
|
|
266
|
+
// The runner picker retains its independent lexical browsing policy.
|
|
267
|
+
const browser = await f.service.getAppRunnerFileBrowserData(f.tab, "external-dir");
|
|
268
|
+
assert.ok(browser.files.some((entry) => entry.name === "external.py"));
|
|
269
|
+
await writeFile(path.join(f.root, configName), JSON.stringify({ version: 2, searchPaths: ["external-dir", "tools", "tools", "missing"], runners: [] }));
|
|
270
|
+
const diagnosed = await f.service.getAppRunnerData(f.tab);
|
|
271
|
+
assert.ok(diagnosed.customRunnerConfig.diagnostics.some((entry) => /outside/.test(entry.message)));
|
|
272
|
+
assert.ok(diagnosed.customRunnerConfig.diagnostics.some((entry) => /Duplicate/.test(entry.message)));
|
|
273
|
+
assert.ok(diagnosed.customRunnerConfig.diagnostics.some((entry) => /does not exist/.test(entry.message)));
|
|
274
|
+
assert.ok(diagnosed.runners.every((runner) => !runner.projectFile.startsWith("external-dir/")));
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("pipe process preserves partial terminal output, stdin validation, EOF, state snapshots and context delivery", async (t) => {
|
|
278
|
+
pipeMode(t);
|
|
279
|
+
const f = await fixture(t, { helper: async () => ({ delivery: "followUp" }) });
|
|
280
|
+
const runner = await addNodeRunner(f, `
|
|
281
|
+
process.stdout.write('old progress\\rready');
|
|
282
|
+
process.stdin.setEncoding('utf8');
|
|
283
|
+
process.stdin.on('data', (chunk) => process.stdout.write('\\necho:' + chunk));
|
|
284
|
+
process.stdin.on('end', () => { process.stdout.write('\\nEOF\\n'); });
|
|
285
|
+
`);
|
|
286
|
+
const started = await f.service.startAppRunner(f.tab, runner.id);
|
|
287
|
+
assert.equal(started.activeRun.status, "running");
|
|
288
|
+
assert.equal(started.activeRun.executionMode, "pipe");
|
|
289
|
+
assert.equal(started.cwd, f.root);
|
|
290
|
+
await waitFor(() => output(f).includes("ready"), "partial stdout");
|
|
291
|
+
assert.equal(f.service.publicAppRunnerState(f.tab.appRunner).pendingLine, "ready");
|
|
292
|
+
assert.ok(!output(f).includes("old progress"));
|
|
293
|
+
await assert.rejects(f.service.startAppRunner(f.tab, runner.id), errorStatus(409));
|
|
294
|
+
assert.equal(f.service.clearAppRunnerForTab(f.tab), false);
|
|
295
|
+
assert.throws(() => f.service.sendAppRunnerInput(f.tab, "bad\0input"), errorStatus(400));
|
|
296
|
+
assert.throws(() => f.service.sendAppRunnerInput(f.tab, "x".repeat(16_001)), errorStatus(413));
|
|
297
|
+
assert.throws(() => f.service.sendAppRunnerInput(f.tab, "", { appendNewline: false }), errorStatus(400));
|
|
298
|
+
const accepted = f.service.sendAppRunnerInput(f.tab, "hello");
|
|
299
|
+
assert.equal(typeof accepted.inputBuffered, "boolean");
|
|
300
|
+
await waitFor(() => output(f).includes("echo:hello"), "stdin echo");
|
|
301
|
+
const context = await f.service.transferAppRunnerContext(f.tab, { lineCount: 2 });
|
|
302
|
+
assert.equal(context.delivery, "followUp");
|
|
303
|
+
assert.equal(context.requestedLineCount, 2);
|
|
304
|
+
assert.equal(context.lineCount, 2);
|
|
305
|
+
assert.equal(f.deliveries[0].target, f.tab);
|
|
306
|
+
assert.equal(f.deliveries[0].command, "app-runner-context");
|
|
307
|
+
assert.match(f.deliveries[0].payload.content, /Command:.*fixture.mjs/);
|
|
308
|
+
assert.match(f.deliveries[0].payload.content, /echo:hello/);
|
|
309
|
+
assert.ok(f.events.some((event) => event.type === "webui_app_runner_stdin" && event.chars === 5));
|
|
310
|
+
const snapshot = f.service.publicAppRunnerState(f.tab.appRunner);
|
|
311
|
+
snapshot.lines.push("caller mutation");
|
|
312
|
+
assert.ok(!f.tab.appRunner.lines.includes("caller mutation"));
|
|
313
|
+
assert.ok(!("child" in snapshot));
|
|
314
|
+
const closed = f.service.sendAppRunnerInput(f.tab, "", { appendNewline: false, closeStdin: true });
|
|
315
|
+
assert.equal(closed.activeRun.stdinClosed, true);
|
|
316
|
+
assert.throws(() => f.service.sendAppRunnerInput(f.tab, "late"), errorStatus(409));
|
|
317
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "EOF process exit");
|
|
318
|
+
assert.equal(f.tab.appRunner.status, "done");
|
|
319
|
+
assert.equal(f.tab.appRunner.child, null);
|
|
320
|
+
assert.equal(f.tab.appRunner.stdinClosed, true);
|
|
321
|
+
assert.equal(f.tab.appRunner.stdinWrites, 2);
|
|
322
|
+
assert.equal(f.tab.appRunnerBroadcastTimer, null);
|
|
323
|
+
assert.match(output(f), /EOF/);
|
|
324
|
+
assert.equal(f.events.filter((event) => event.type === "webui_app_runner_exit").length, 1);
|
|
325
|
+
assert.equal(f.service.stopAppRunnerForTab(f.tab), false);
|
|
326
|
+
assert.equal(f.service.clearAppRunnerForTab(f.tab), true);
|
|
327
|
+
assert.equal(f.updates.at(-1).event.activeRun, null);
|
|
328
|
+
await assert.rejects(f.service.transferAppRunnerContext(f.tab), errorStatus(409));
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("stdin accepts the 16k boundary without a newline and records real broken-pipe errors", { skip: process.platform === "win32" ? "POSIX closed-fd pipe error fixture; Windows stdin error delivery requires its own fixture" : false }, async (t) => {
|
|
332
|
+
pipeMode(t);
|
|
333
|
+
const f = await fixture(t);
|
|
334
|
+
const runner = await addNodeRunner(f, `
|
|
335
|
+
let received = 0;
|
|
336
|
+
process.stdin.on('data', (chunk) => { received += chunk.length; process.stdout.write('received=' + received + '\\n'); });
|
|
337
|
+
`);
|
|
338
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
339
|
+
const sent = f.service.sendAppRunnerInput(f.tab, "x".repeat(16_000), { appendNewline: false });
|
|
340
|
+
assert.equal(sent.activeRun.stdinWrites, 1);
|
|
341
|
+
await waitFor(() => output(f).includes("received=16000"), "16k input without newline");
|
|
342
|
+
f.service.sendAppRunnerInput(f.tab, "", { appendNewline: false, closeStdin: true });
|
|
343
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "16k process EOF");
|
|
344
|
+
const broken = await addNodeRunner(f, `
|
|
345
|
+
import { closeSync } from 'node:fs';
|
|
346
|
+
closeSync(0);
|
|
347
|
+
console.log('closed-reader');
|
|
348
|
+
setInterval(() => {}, 1000);
|
|
349
|
+
`, { id: "broken-pipe" });
|
|
350
|
+
await f.service.startAppRunner(f.tab, broken.id);
|
|
351
|
+
await waitFor(() => output(f).includes("closed-reader"), "closed child stdin");
|
|
352
|
+
f.service.sendAppRunnerInput(f.tab, "pipe-error");
|
|
353
|
+
await waitFor(() => f.tab.appRunner.stdinClosed && f.tab.appRunner.stdinError, "stdin write error");
|
|
354
|
+
assert.equal(f.tab.appRunner.status, "running");
|
|
355
|
+
assert.match(f.tab.appRunner.stdinError, /EPIPE/);
|
|
356
|
+
assert.throws(() => f.service.sendAppRunnerInput(f.tab, "later"), errorStatus(409));
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("short output retains exactly 1000 lines while preserving the total produced count", async (t) => {
|
|
360
|
+
pipeMode(t);
|
|
361
|
+
const f = await fixture(t);
|
|
362
|
+
const runner = await addNodeRunner(f, `
|
|
363
|
+
process.stdout.write(Array.from({ length: 1100 }, (_, i) => 'short-' + i).join('\\n') + '\\n', () => setTimeout(() => process.exit(0), 50));
|
|
364
|
+
`);
|
|
365
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
366
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "line-bounded output exit");
|
|
367
|
+
const state = f.service.publicAppRunnerState(f.tab.appRunner);
|
|
368
|
+
assert.equal(state.lines.length, 1000);
|
|
369
|
+
assert.equal(state.lineCount, 1102);
|
|
370
|
+
assert.equal(state.truncated, true);
|
|
371
|
+
assert.equal(state.lines[0], "short-101");
|
|
372
|
+
assert.match(state.lines.at(-1), /^# exit 0/);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("output history obeys line and character bounds and context caps without leaking ANSI escapes", async (t) => {
|
|
376
|
+
pipeMode(t);
|
|
377
|
+
const f = await fixture(t);
|
|
378
|
+
const runner = await addNodeRunner(f, `
|
|
379
|
+
const lines = Array.from({ length: 1200 }, (_, i) => 'line-' + i + '-' + 'x'.repeat(250));
|
|
380
|
+
process.stdout.write(lines.join('\\n') + '\\n\\x1b[31mLAST\\x1b[0m\\n', () => setTimeout(() => process.exit(0), 50));
|
|
381
|
+
`);
|
|
382
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
383
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "bounded output process exit");
|
|
384
|
+
const state = f.service.publicAppRunnerState(f.tab.appRunner);
|
|
385
|
+
assert.equal(state.status, "done");
|
|
386
|
+
assert.equal(state.truncated, true);
|
|
387
|
+
assert.ok(state.lineCount >= 1203);
|
|
388
|
+
assert.ok(state.lines.length <= 1000);
|
|
389
|
+
assert.ok(state.lines.reduce((sum, line) => sum + line.length + 1, 0) <= 240_000);
|
|
390
|
+
assert.ok(!state.lines.includes("line-0-" + "x".repeat(250)));
|
|
391
|
+
const context = await f.service.transferAppRunnerContext(f.tab, { count: 99_999 });
|
|
392
|
+
assert.equal(context.requestedLineCount, 1000);
|
|
393
|
+
assert.equal(context.truncated, true);
|
|
394
|
+
assert.ok(!f.deliveries[0].payload.content.includes("\x1b"));
|
|
395
|
+
assert.match(f.deliveries[0].payload.content, /earlier app runner output had already been truncated/);
|
|
396
|
+
const last = await f.service.transferAppRunnerContext(f.tab, { lines: 0 });
|
|
397
|
+
assert.equal(last.requestedLineCount, 1);
|
|
398
|
+
const defaults = await f.service.transferAppRunnerContext(f.tab);
|
|
399
|
+
assert.equal(defaults.requestedLineCount, 80);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test("stream bursts coalesce at the existing cadence and removed tabs suppress scheduled updates", async (t) => {
|
|
403
|
+
pipeMode(t);
|
|
404
|
+
const f = await fixture(t);
|
|
405
|
+
const runner = await addNodeRunner(f, `
|
|
406
|
+
process.stdout.write('ready\\n');
|
|
407
|
+
process.stdin.once('data', () => {
|
|
408
|
+
for (let i = 0; i < 40; i++) process.stdout.write('burst-' + i + '\\n');
|
|
409
|
+
});
|
|
410
|
+
setInterval(() => {}, 1000);
|
|
411
|
+
`);
|
|
412
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
413
|
+
await waitFor(() => output(f).includes("ready"), "burst fixture readiness");
|
|
414
|
+
await waitFor(() => f.tab.appRunnerBroadcastTimer === null, "initial output broadcast");
|
|
415
|
+
const before = f.updates.length;
|
|
416
|
+
const sentAt = Date.now();
|
|
417
|
+
f.service.sendAppRunnerInput(f.tab, "go");
|
|
418
|
+
await waitFor(() => output(f).includes("burst-39"), "burst output");
|
|
419
|
+
await waitFor(() => f.updates.length > before, "coalesced broadcast");
|
|
420
|
+
assert.equal(f.updates.length, before + 1);
|
|
421
|
+
assert.ok(f.updates.at(-1).at - sentAt >= 100);
|
|
422
|
+
assert.equal(f.updates.at(-1).event.type, "webui_app_runner_update");
|
|
423
|
+
assert.deepEqual(f.updates.at(-1).event.tabActivity, { tab: f.tab.id, fixture: true });
|
|
424
|
+
f.tabs.delete(f.tab.id);
|
|
425
|
+
const retiredCount = f.updates.length;
|
|
426
|
+
f.service.sendAppRunnerInput(f.tab, "retired");
|
|
427
|
+
await waitFor(() => f.tab.appRunnerBroadcastTimer === null, "retired tab timer cleanup");
|
|
428
|
+
assert.equal(f.updates.length, retiredCount);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test("spawn errors and nonzero process exits settle once and preserve the public failure contract", async (t) => {
|
|
432
|
+
pipeMode(t);
|
|
433
|
+
const f = await fixture(t, { available: [process.execPath, "missing-webui-fixture-command"] });
|
|
434
|
+
await writeFile(path.join(f.root, "entry.mjs"), "");
|
|
435
|
+
const data = await f.service.saveCustomAppRunner(f.tab, { id: "missing", command: "missing-webui-fixture-command", path: "entry.mjs" });
|
|
436
|
+
await f.service.startAppRunner(f.tab, data.runners.find((runner) => runner.custom).id);
|
|
437
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "spawn error settlement");
|
|
438
|
+
assert.equal(f.tab.appRunner.status, "error");
|
|
439
|
+
assert.match(output(f), /ENOENT/);
|
|
440
|
+
assert.equal(f.tab.appRunner.child, null);
|
|
441
|
+
assert.equal(f.events.filter((event) => event.type === "webui_app_runner_exit").length, 1);
|
|
442
|
+
const runner = await addNodeRunner(f, "process.stderr.write('failed fixture\\n'); process.exitCode = 7;", { id: "nonzero" });
|
|
443
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
444
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "nonzero exit");
|
|
445
|
+
assert.equal(f.tab.appRunner.status, "failed");
|
|
446
|
+
assert.equal(f.tab.appRunner.exitCode, 7);
|
|
447
|
+
assert.match(output(f), /failed fixture/);
|
|
448
|
+
assert.match(output(f), /exit 7/);
|
|
449
|
+
await assert.rejects(f.service.startAppRunner(f.tab, "unknown"), errorStatus(400));
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test("context errors propagate without recording success or changing runner state", async (t) => {
|
|
453
|
+
const f = await fixture(t, { helper: async () => { throw new Error("helper unavailable"); } });
|
|
454
|
+
f.tab.appRunner = { id: "record", status: "done", lines: ["\x1b[31m\x1b[0m"], displayCommand: "fixture", cwd: f.root };
|
|
455
|
+
await assert.rejects(f.service.transferAppRunnerContext(f.tab), errorStatus(400));
|
|
456
|
+
f.tab.appRunner.lines = ["captured text"];
|
|
457
|
+
await assert.rejects(f.service.transferAppRunnerContext(f.tab), /helper unavailable/);
|
|
458
|
+
assert.equal(f.events.length, 0);
|
|
459
|
+
assert.equal(f.tab.appRunner.status, "done");
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test("graceful stop signals the complete POSIX process group and cleans tab-owned timers", { skip: process.platform === "win32" ? "POSIX signal group contract; Windows process-tree/ConPTY coverage belongs to parent" : false }, async (t) => {
|
|
463
|
+
pipeMode(t);
|
|
464
|
+
const f = await fixture(t);
|
|
465
|
+
await writeFile(path.join(f.root, "descendant.mjs"), `
|
|
466
|
+
import { writeFileSync } from 'node:fs';
|
|
467
|
+
process.on('SIGINT', () => { writeFileSync('descendant-stopped', 'SIGINT'); process.exit(0); });
|
|
468
|
+
process.stdout.write('descendant-ready\\n');
|
|
469
|
+
setInterval(() => {}, 1000);
|
|
470
|
+
`);
|
|
471
|
+
const runner = await addNodeRunner(f, `
|
|
472
|
+
import { spawn } from 'node:child_process';
|
|
473
|
+
const child = spawn(process.execPath, ['descendant.mjs'], { stdio: ['ignore', 'inherit', 'inherit'] });
|
|
474
|
+
process.on('SIGINT', () => {});
|
|
475
|
+
child.on('exit', () => process.exit(0));
|
|
476
|
+
setInterval(() => {}, 1000);
|
|
477
|
+
`);
|
|
478
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
479
|
+
await waitFor(() => output(f).includes("descendant-ready"), "descendant signal handler");
|
|
480
|
+
assert.equal(f.service.stopAppRunnerForTab(f.tab, "test stop"), true);
|
|
481
|
+
assert.equal(f.service.publicAppRunnerState(f.tab.appRunner).stopping, true);
|
|
482
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "process group stop");
|
|
483
|
+
assert.equal(await readFile(path.join(f.root, "descendant-stopped"), "utf8"), "SIGINT");
|
|
484
|
+
assert.match(output(f), /test stop; sending Ctrl\+C/);
|
|
485
|
+
assert.equal(f.tab.appRunner.stopping, false);
|
|
486
|
+
assert.equal(f.tab.appRunner.stdinClosed, true);
|
|
487
|
+
assert.equal(f.tab.appRunnerBroadcastTimer, null);
|
|
488
|
+
assert.equal(f.tab.appRunner.settled, true);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
test("unresponsive POSIX runners are force-stopped after the 2.5 second grace period", { skip: process.platform === "win32" ? "Windows pipe stop immediately terminates the process tree" : false }, async (t) => {
|
|
492
|
+
pipeMode(t);
|
|
493
|
+
const f = await fixture(t);
|
|
494
|
+
const runner = await addNodeRunner(f, "process.on('SIGINT', () => {}); console.log('ready'); setInterval(() => {}, 1000);");
|
|
495
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
496
|
+
await waitFor(() => output(f).includes("ready"), "signal-resistant runner");
|
|
497
|
+
const stoppedAt = Date.now();
|
|
498
|
+
f.service.stopAppRunnerForTab(f.tab);
|
|
499
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "stop grace escalation");
|
|
500
|
+
assert.ok(Date.now() - stoppedAt >= 2_400);
|
|
501
|
+
assert.equal(f.tab.appRunner.signal, "SIGKILL");
|
|
502
|
+
assert.match(output(f), /forcing process-tree termination/);
|
|
503
|
+
assert.equal(f.tab.appRunner.child, null);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
const scriptProbe = process.platform === "win32" ? null : spawnSync("script", ["--version"], { encoding: "utf8", timeout: 1_200 });
|
|
507
|
+
const scriptAvailable = scriptProbe && !scriptProbe.error && /util-linux/i.test(`${scriptProbe.stdout}\n${scriptProbe.stderr}`);
|
|
508
|
+
|
|
509
|
+
test("util-linux script PTY preserves interactive input and Ctrl+C stop", { skip: scriptAvailable ? false : "util-linux script PTY unavailable on this platform" }, async (t) => {
|
|
510
|
+
const previous = process.env.PI_WEBUI_APP_RUNNER_PTY;
|
|
511
|
+
delete process.env.PI_WEBUI_APP_RUNNER_PTY;
|
|
512
|
+
t.after(() => {
|
|
513
|
+
if (previous === undefined) delete process.env.PI_WEBUI_APP_RUNNER_PTY;
|
|
514
|
+
else process.env.PI_WEBUI_APP_RUNNER_PTY = previous;
|
|
515
|
+
});
|
|
516
|
+
const f = await fixture(t, {
|
|
517
|
+
commandResult: (command) => command === "script"
|
|
518
|
+
? { exitCode: scriptProbe.status, stdout: scriptProbe.stdout, stderr: scriptProbe.stderr }
|
|
519
|
+
: command === process.execPath ? { exitCode: 0, stdout: "fixture version" } : { exitCode: 127, error: "unavailable" },
|
|
520
|
+
});
|
|
521
|
+
const runner = await addNodeRunner(f, `
|
|
522
|
+
process.stdout.write('tty=' + Boolean(process.stdin.isTTY) + '\\n');
|
|
523
|
+
process.stdin.on('data', (chunk) => process.stdout.write('pty-input:' + chunk));
|
|
524
|
+
setInterval(() => {}, 1000);
|
|
525
|
+
`);
|
|
526
|
+
await f.service.startAppRunner(f.tab, runner.id);
|
|
527
|
+
assert.equal(f.tab.appRunner.executionMode, "pty");
|
|
528
|
+
await waitFor(() => output(f).includes("tty=true"), "PTY initialization");
|
|
529
|
+
f.service.sendAppRunnerInput(f.tab, "interactive");
|
|
530
|
+
await waitFor(() => output(f).includes("pty-input:interactive"), "PTY stdin");
|
|
531
|
+
f.service.stopAppRunnerForTab(f.tab);
|
|
532
|
+
await waitFor(() => f.tab.appRunner.status !== "running", "PTY Ctrl+C stop");
|
|
533
|
+
assert.equal(f.tab.appRunner.stdinClosed, true);
|
|
534
|
+
assert.equal(f.tab.appRunner.child, null);
|
|
535
|
+
assert.equal(f.probes.filter((probe) => probe.command === "script").length, 1);
|
|
536
|
+
});
|