@openchamber/web 1.24.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/commands-connect-url.js +3 -8
- package/bin/lib/commands-tunnel.js +3 -0
- package/dist/assets/{CodeMirrorCommentWidgets-B_vBPQYm.js → CodeMirrorCommentWidgets-zm3C1FvM.js} +1 -1
- package/dist/assets/DiffView-DNExNi1z.js +4 -0
- package/dist/assets/FilesView-DUCLmHBi.js +17 -0
- package/dist/assets/{GitView-k0hUF8KB.js → GitView-Bz9z6gZA.js} +4 -4
- package/dist/assets/{GuestAttachDialog-DIf2U85Z.js → GuestAttachDialog-UGp4KDlK.js} +1 -1
- package/dist/assets/GuestSurfacePane-B3pdB_2u.js +1 -0
- package/dist/assets/{JsonTreeView-4AnJ04Pw.js → JsonTreeView-7lVecnZl.js} +1 -1
- package/dist/assets/LinearIssuesView-CTGRS9Vq.js +1 -0
- package/dist/assets/MarkdownImageGallery-DQk5adUs.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +12 -0
- package/dist/assets/OnboardingScreen-CBx6cXPP.js +1 -0
- package/dist/assets/{PatchDiff-DpGmHRnV.js → PatchDiff-D7VVpR_l.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CgLl_tp7.js → PierreDiffViewer-Gbfks1pk.js} +3 -3
- package/dist/assets/PlanView-CPSK0x97.js +5 -0
- package/dist/assets/PluginPane-BIGsUx69.js +3 -0
- package/dist/assets/SettingsView-Dql7z6Ww.js +30 -0
- package/dist/assets/SettingsWindow-D6oi-UmV.js +1 -0
- package/dist/assets/SubmoduleDiffSummary-BXA0FAWj.js +1 -0
- package/dist/assets/ToolOutputDialog-BQJsSbDm.js +15 -0
- package/dist/assets/ToolPartDiffPreview-FY9w0TVT.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-BK4aU5qJ.js → VirtualizedFileDiff-B9YhAya5.js} +4 -4
- package/dist/assets/{WalkthroughView-Bk6TPNFw.js → WalkthroughView-CmFgOUFN.js} +2 -2
- package/dist/assets/appThemeRegistry-BebxalUt.js +1 -0
- package/dist/assets/changesTree-CePHbFcj.js +1 -0
- package/dist/assets/commitAndPush-Wfxng_IK.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-BVTujWSX.js → computeVirtualFileMetrics-BCOqgixN.js} +2 -2
- package/dist/assets/de-CMA45TC-.js +10 -0
- package/dist/assets/es-DPL4fBtl.js +16 -0
- package/dist/assets/fr-OHBKBseP.js +14 -0
- package/dist/assets/index-3TiDNtfN.js +1 -0
- package/dist/assets/index-BLUZa5u0.js +41 -0
- package/dist/assets/index-Cm2rrq69.css +1 -0
- package/dist/assets/{isDiffPlainText-D3yX_vx4.js → isDiffPlainText-DnDYQmWK.js} +1 -1
- package/dist/assets/{isFilePlainText-CZR9TcHV.js → isFilePlainText-BA_AHX7d.js} +1 -1
- package/dist/assets/ja-DvX4WSRf.js +16 -0
- package/dist/assets/ko-BUcLd8YZ.js +16 -0
- package/dist/assets/main-B_jri4i-.js +896 -0
- package/dist/assets/main-DtUmJp9B.js +2 -0
- package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
- package/dist/assets/markdownCore-BSnlUXBf.js +7 -0
- package/dist/assets/miniChat-BYfLUnDK.js +2 -0
- package/dist/assets/mobile-DH3hI6gd.js +2 -0
- package/dist/assets/patchFileDiff--L7lt_GZ.js +13 -0
- package/dist/assets/pl-BkI_xHqz.js +16 -0
- package/dist/assets/pt-BR-7wFtQlV9.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-C7kpNW_-.js +2 -0
- package/dist/assets/renderMobileApp-i0nq7Dwy.js +25 -0
- package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +27 -0
- package/dist/assets/scheduledTasksApi-Cy7uZCaI.js +1 -0
- package/dist/assets/{shikiHighlight-BfjuB3CD.js → shikiHighlight-D4vxipfr.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-BP60t9SX.js → textMateThemeFromAppTheme-BYAHtJwQ.js} +1 -1
- package/dist/assets/tr-TsD-AqEH.js +7 -0
- package/dist/assets/uk-B-qspCmD.js +16 -0
- package/dist/assets/useAppFontEffects-DHZ9-L30.js +7338 -0
- package/dist/assets/useInlineCommentController-CvpOMK-R.js +2 -0
- package/dist/assets/useRootScrollLock-DzNFi-fn.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BFm1Ju2w.js → vendor-codemirror-language-data-j3fhlwUM.js} +2 -2
- package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
- package/dist/assets/vendor-opencode-client-DYdsLbCM.js +12 -0
- package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
- package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
- package/dist/assets/{web-components-2vo9YsZc.js → web-components-BvHNFSEG.js} +2 -2
- package/dist/assets/zh-CN-DYuPJV5i.js +16 -0
- package/dist/assets/zh-TW-BX_2D_lV.js +16 -0
- package/dist/index.html +13 -7
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +6 -5
- package/server/index.d.ts +1 -0
- package/server/index.js +264 -91
- package/server/lib/agent-tool/DOCUMENTATION.md +38 -16
- package/server/lib/agent-tool/runtime.js +167 -58
- package/server/lib/agent-tool/runtime.test.js +170 -87
- package/server/lib/browser-control/DOCUMENTATION.md +51 -4
- package/server/lib/browser-control/provider.js +217 -0
- package/server/lib/browser-control/provider.test.js +251 -0
- package/server/lib/context-obligatory/runtime.js +61 -50
- package/server/lib/context-obligatory/runtime.test.js +62 -162
- package/server/lib/event-stream/DOCUMENTATION.md +12 -1
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +68 -57
- package/server/lib/event-stream/directory-ws-bridge.js +1 -1
- package/server/lib/event-stream/global-hub.js +10 -1
- package/server/lib/event-stream/global-hub.test.js +27 -26
- package/server/lib/event-stream/index.js +6 -0
- package/server/lib/event-stream/protocol.js +26 -19
- package/server/lib/event-stream/protocol.test.js +18 -7
- package/server/lib/event-stream/rebind.test.js +5 -5
- package/server/lib/event-stream/runtime.test.js +17 -15
- package/server/lib/event-stream/translate-v2.js +313 -0
- package/server/lib/event-stream/translate-v2.test.js +209 -0
- package/server/lib/event-stream/upstream-reader.test.js +16 -16
- package/server/lib/fs/DOCUMENTATION.md +4 -2
- package/server/lib/fs/byte-range.js +35 -0
- package/server/lib/fs/byte-range.test.js +31 -0
- package/server/lib/fs/routes.js +47 -42
- package/server/lib/fs/routes.test.js +123 -18
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +34 -0
- package/server/lib/git/service.test.js +8 -0
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/github/pr-status.js +22 -2
- package/server/lib/github/pr-status.test.js +27 -14
- package/server/lib/guests/DOCUMENTATION.md +16 -2
- package/server/lib/guests/catalog.js +31 -1
- package/server/lib/guests/catalog.test.js +55 -0
- package/server/lib/guests/html-styles.js +5 -3
- package/server/lib/guests/html-styles.test.js +3 -1
- package/server/lib/guests/routes.js +21 -4
- package/server/lib/guests/service.js +197 -14
- package/server/lib/guests/service.test.js +201 -1
- package/server/lib/guests/surface.js +676 -0
- package/server/lib/guests/surface.test.js +536 -0
- package/server/lib/markdown-image-grants/routes.js +18 -5
- package/server/lib/markdown-image-grants/routes.test.js +9 -6
- package/server/lib/message-queue/DOCUMENTATION.md +33 -22
- package/server/lib/message-queue/runtime.js +155 -100
- package/server/lib/message-queue/runtime.test.js +168 -82
- package/server/lib/notifications/DOCUMENTATION.md +38 -0
- package/server/lib/notifications/control-stream.http.test.js +68 -0
- package/server/lib/notifications/emit-route.js +118 -0
- package/server/lib/notifications/emit-route.test.js +112 -0
- package/server/lib/notifications/emitter-runtime.js +15 -0
- package/server/lib/notifications/emitter-runtime.test.js +32 -0
- package/server/lib/notifications/push-runtime.js +5 -1
- package/server/lib/notifications/push-runtime.test.js +2 -2
- package/server/lib/notifications/routes.js +1 -1
- package/server/lib/notifications/runtime.js +115 -26
- package/server/lib/notifications/template-runtime.js +13 -15
- package/server/lib/notifications/template-runtime.test.js +16 -9
- package/server/lib/notifications/trigger-runtime.test.js +187 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
- package/server/lib/openchamber-control/actions.js +19 -4
- package/server/lib/openchamber-control/error.js +1 -1
- package/server/lib/openchamber-control/file-open.js +59 -0
- package/server/lib/openchamber-control/file-open.test.js +57 -0
- package/server/lib/openchamber-control/routes.test.js +12 -0
- package/server/lib/openchamber-control/service.js +125 -49
- package/server/lib/openchamber-control/service.test.js +115 -44
- package/server/lib/openchamber-sessions/archive-store.js +224 -0
- package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
- package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
- package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
- package/server/lib/openchamber-sessions/opencode-client.js +22 -0
- package/server/lib/openchamber-sessions/routes.js +409 -328
- package/server/lib/openchamber-sessions/routes.test.js +795 -740
- package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
- package/server/lib/opencode/DOCUMENTATION.md +458 -29
- package/server/lib/opencode/agents.js +233 -327
- package/server/lib/opencode/auth.js +41 -44
- package/server/lib/opencode/auth.test.js +92 -0
- package/server/lib/opencode/bootstrap-runtime.js +12 -0
- package/server/lib/opencode/cli-upgrade.d.ts +4 -0
- package/server/lib/opencode/cli-upgrade.js +18 -0
- package/server/lib/opencode/cli-upgrade.test.js +36 -0
- package/server/lib/opencode/commands.js +164 -145
- package/server/lib/opencode/compatibility.d.ts +16 -0
- package/server/lib/opencode/compatibility.js +91 -0
- package/server/lib/opencode/compatibility.test.js +70 -0
- package/server/lib/opencode/config-entity-routes.js +58 -29
- package/server/lib/opencode/config-entity-v2.test.js +290 -0
- package/server/lib/opencode/config-mutation-response.js +17 -7
- package/server/lib/opencode/config-mutation-response.test.js +4 -7
- package/server/lib/opencode/config-paths.test.js +2 -2
- package/server/lib/opencode/config-v2.d.ts +185 -0
- package/server/lib/opencode/config-v2.js +843 -0
- package/server/lib/opencode/config-v2.test.js +483 -0
- package/server/lib/opencode/core-routes.js +3 -0
- package/server/lib/opencode/core-routes.test.js +15 -0
- package/server/lib/opencode/credential-db.js +144 -0
- package/server/lib/opencode/credential-db.test.js +104 -0
- package/server/lib/opencode/env-runtime.js +47 -15
- package/server/lib/opencode/env-runtime.test.js +45 -0
- package/server/lib/opencode/feature-routes-runtime.js +16 -5
- package/server/lib/opencode/lifecycle-process.test.js +7 -4
- package/server/lib/opencode/lifecycle.js +113 -30
- package/server/lib/opencode/lifecycle.test.js +107 -8
- package/server/lib/opencode/login-shell-env.js +27 -0
- package/server/lib/opencode/managed-config-file.js +131 -0
- package/server/lib/opencode/managed-config-file.test.js +168 -0
- package/server/lib/opencode/managed-plugin-config.js +33 -13
- package/server/lib/opencode/mcp.js +43 -149
- package/server/lib/opencode/network-runtime.js +6 -7
- package/server/lib/opencode/openchamber-routes.js +29 -11
- package/server/lib/opencode/openchamber-routes.test.js +18 -1
- package/server/lib/opencode/plugin-routes.js +3 -3
- package/server/lib/opencode/plugin-routes.test.js +6 -24
- package/server/lib/opencode/plugins.js +91 -40
- package/server/lib/opencode/plugins.test.js +28 -15
- package/server/lib/opencode/provider-source-route.test.js +59 -0
- package/server/lib/opencode/providers.js +66 -83
- package/server/lib/opencode/providers.test.js +190 -59
- package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
- package/server/lib/opencode/proxy.js +179 -129
- package/server/lib/opencode/pwa-manifest-routes.js +4 -2
- package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
- package/server/lib/opencode/response-envelope.js +14 -0
- package/server/lib/opencode/response-envelope.test.js +23 -0
- package/server/lib/opencode/routes-upgrade.test.js +73 -116
- package/server/lib/opencode/routes.js +138 -428
- package/server/lib/opencode/server-utils-runtime.js +10 -4
- package/server/lib/opencode/session-activity.js +78 -0
- package/server/lib/opencode/session-runtime.js +21 -10
- package/server/lib/opencode/session-runtime.test.js +9 -9
- package/server/lib/opencode/settings-helpers.js +15 -8
- package/server/lib/opencode/settings-helpers.test.js +7 -12
- package/server/lib/opencode/settings-registry.json +20 -8
- package/server/lib/opencode/settings-runtime.js +19 -1
- package/server/lib/opencode/settings-runtime.test.js +31 -2
- package/server/lib/opencode/shared.js +86 -24
- package/server/lib/opencode/shared.test.js +87 -5
- package/server/lib/opencode/shutdown-runtime.js +54 -7
- package/server/lib/opencode/shutdown-runtime.test.js +224 -30
- package/server/lib/opencode/skill-routes.js +51 -36
- package/server/lib/opencode/skill-routes.test.js +121 -1
- package/server/lib/opencode/skills.js +7 -5
- package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
- package/server/lib/opencode/upgrade-capability.js +0 -14
- package/server/lib/opencode/upgrade-capability.test.js +1 -1
- package/server/lib/opencode/v1-migration-topup.js +294 -0
- package/server/lib/opencode/v1-migration-topup.test.js +274 -0
- package/server/lib/opencode/v2-install.d.ts +9 -0
- package/server/lib/opencode/v2-install.js +159 -0
- package/server/lib/opencode/v2-install.test.js +133 -0
- package/server/lib/opencode/watcher.js +10 -3
- package/server/lib/opencode/watcher.test.js +17 -21
- package/server/lib/opencode/websearch-config.js +78 -0
- package/server/lib/permission-auto-accept/runtime.js +38 -22
- package/server/lib/permission-auto-accept/runtime.test.js +39 -17
- package/server/lib/quota/DOCUMENTATION.md +4 -0
- package/server/lib/quota/providers/kimi.js +1 -1
- package/server/lib/quota/providers/xai.js +4 -4
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +7 -0
- package/server/lib/routing/DOCUMENTATION.md +52 -21
- package/server/lib/routing/defaults.js +23 -6
- package/server/lib/routing/jev.js +17 -7
- package/server/lib/routing/routes.http.test.js +68 -33
- package/server/lib/routing/routes.js +65 -22
- package/server/lib/routing/runtime.js +145 -48
- package/server/lib/routing/runtime.test.js +79 -55
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
- package/server/lib/scheduled-tasks/runtime.js +81 -74
- package/server/lib/scheduled-tasks/runtime.test.js +53 -1
- package/server/lib/session-assist/DOCUMENTATION.md +25 -8
- package/server/lib/session-assist/context.js +122 -46
- package/server/lib/session-assist/context.test.js +117 -49
- package/server/lib/session-assist/runtime.js +71 -24
- package/server/lib/session-assist/runtime.test.js +153 -173
- package/server/lib/session-goal/DOCUMENTATION.md +34 -15
- package/server/lib/session-goal/create.js +9 -12
- package/server/lib/session-goal/create.test.js +27 -28
- package/server/lib/session-goal/runtime.js +164 -77
- package/server/lib/session-goal/runtime.test.js +271 -519
- package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
- package/server/lib/session-knowledge/runtime.js +59 -41
- package/server/lib/session-knowledge/runtime.test.js +90 -20
- package/server/lib/small-model/DOCUMENTATION.md +154 -208
- package/server/lib/small-model/client.js +113 -0
- package/server/lib/small-model/index.js +296 -158
- package/server/lib/small-model/index.test.js +423 -256
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/spaces/DOCUMENTATION.md +807 -0
- package/server/lib/spaces/code-in-bait.js +185 -0
- package/server/lib/spaces/code-in.js +641 -0
- package/server/lib/spaces/code-in.test.js +1048 -0
- package/server/lib/spaces/errors.js +8 -0
- package/server/lib/spaces/exec-http.js +94 -0
- package/server/lib/spaces/gatekeeper-channel.js +202 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
- package/server/lib/spaces/gatekeeper-program.cjs +914 -0
- package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
- package/server/lib/spaces/hardening.js +457 -0
- package/server/lib/spaces/hardening.test.js +368 -0
- package/server/lib/spaces/host-git.js +127 -0
- package/server/lib/spaces/host-git.test.js +137 -0
- package/server/lib/spaces/labels.js +234 -0
- package/server/lib/spaces/labels.test.js +219 -0
- package/server/lib/spaces/layout.js +184 -0
- package/server/lib/spaces/layout.test.js +30 -0
- package/server/lib/spaces/manager.js +82 -0
- package/server/lib/spaces/manager.test.js +114 -0
- package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
- package/server/lib/spaces/places/contract-suite.js +156 -0
- package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
- package/server/lib/spaces/places/contract.test.js +6 -0
- package/server/lib/spaces/places/docker-engine.js +126 -0
- package/server/lib/spaces/places/docker-live-support.js +202 -0
- package/server/lib/spaces/places/docker-tools.js +186 -0
- package/server/lib/spaces/places/docker.js +587 -0
- package/server/lib/spaces/places/docker.test.js +1610 -0
- package/server/lib/spaces/places/escape-suite.js +1018 -0
- package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
- package/server/lib/spaces/places/fake-docker.js +375 -0
- package/server/lib/spaces/places/memory-place.js +103 -0
- package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
- package/server/lib/spaces/places/registry.js +43 -0
- package/server/lib/spaces/places/registry.test.js +50 -0
- package/server/lib/spaces/places/server.docker.live.test.js +225 -0
- package/server/lib/spaces/run-command.js +261 -0
- package/server/lib/spaces/run-command.test.js +396 -0
- package/server/lib/spaces/space-server.js +190 -0
- package/server/lib/spaces/space-server.test.js +335 -0
- package/server/lib/spaces/tools-filler.js +82 -0
- package/server/lib/spaces/tools-filler.test.js +148 -0
- package/server/lib/spaces/tools-pack.js +49 -0
- package/server/lib/spaces/tools-pack.test.js +57 -0
- package/server/lib/spaces/tools.js +137 -0
- package/server/lib/spaces/tools.test.js +153 -0
- package/server/lib/tts/openai-sdk.js +11 -0
- package/server/lib/tts/service.js +7 -5
- package/server/lib/tts/stt.js +3 -2
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +7 -0
- package/server/lib/tunnels/routes.test.js +55 -0
- package/server/lib/ui-auth/ui-auth.js +38 -2
- package/server/lib/ui-auth/ui-auth.test.js +42 -0
- package/server/lib/ui-auth/ui-passkeys.js +12 -10
- package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
- package/server/lib/walkthrough/pull-request.js +61 -8
- package/server/lib/walkthrough/pull-request.test.js +54 -1
- package/server/lib/walkthrough/routes.js +20 -0
- package/server/lib/walkthrough/routes.test.js +19 -0
- package/server/opencode-proxy.test.js +190 -166
- package/server/opencode-worktree-readiness.test.js +5 -4
- package/dist/assets/DiffView-Ce0oBXXQ.js +0 -4
- package/dist/assets/FilesView-DtXueAWP.js +0 -13
- package/dist/assets/LinearIssuesView-z_9p2GuO.js +0 -1
- package/dist/assets/MarkdownImageGallery-BC-BNN-s.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DyaBTUbH.js +0 -12
- package/dist/assets/OnboardingScreen-DKU_yTb6.js +0 -1
- package/dist/assets/PlanView-CrfB4qqY.js +0 -5
- package/dist/assets/PluginPane-B5cn-jPy.js +0 -3
- package/dist/assets/SettingsView-DMKKwezx.js +0 -29
- package/dist/assets/SettingsWindow-DwbnVzOC.js +0 -1
- package/dist/assets/SubmoduleDiffSummary-hkGcvs0E.js +0 -1
- package/dist/assets/ToolOutputDialog-DuoIOc0j.js +0 -15
- package/dist/assets/ToolPartDiffPreview-t1Bvq_2Y.js +0 -8
- package/dist/assets/appThemeRegistry-DnOVbJjF.js +0 -1
- package/dist/assets/commitAndPush-DLWNZkkY.js +0 -1
- package/dist/assets/de-zEHaAIi3.js +0 -10
- package/dist/assets/es-CBDgEzgk.js +0 -16
- package/dist/assets/fr-DjiTptT_.js +0 -14
- package/dist/assets/index-AgOdanig.css +0 -1
- package/dist/assets/index-B-2_X4DD.js +0 -40
- package/dist/assets/index-CkA4p2IK.js +0 -1
- package/dist/assets/ja-CerMgj3r.js +0 -16
- package/dist/assets/ko-DHYDAze5.js +0 -16
- package/dist/assets/main-BDka4W43.js +0 -896
- package/dist/assets/main-Dl7Dyge_.js +0 -2
- package/dist/assets/markdownCore-DFmr0rUR.js +0 -5
- package/dist/assets/miniChat-CLKQPPpO.js +0 -2
- package/dist/assets/mobile--giD2Q1L.js +0 -2
- package/dist/assets/patchFileDiff-DRh-AQvd.js +0 -13
- package/dist/assets/pl-BTB_93bq.js +0 -16
- package/dist/assets/pt-BR-BwA3oyCK.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +0 -2
- package/dist/assets/renderMobileApp-pMfOuQfl.js +0 -25
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +0 -25
- package/dist/assets/scheduledTasksApi-CeRAIUmW.js +0 -1
- package/dist/assets/tr-CcPsJoNM.js +0 -7
- package/dist/assets/uk-B68WibXi.js +0 -16
- package/dist/assets/useAppFontEffects-DcdrFv2Z.js +0 -7333
- package/dist/assets/useInlineCommentController-Cq4SUjsA.js +0 -2
- package/dist/assets/useRootScrollLock-CSdR6Wnm.js +0 -2
- package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
- package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
- package/dist/assets/vendor-zod-CgAdXWZO.js +0 -39
- package/dist/assets/zh-CN-DbFHYXwP.js +0 -16
- package/dist/assets/zh-TW-DmXAwdty.js +0 -16
- package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
- package/server/lib/routing/feature-flag.js +0 -11
- package/server/lib/small-model/call.js +0 -851
- package/server/lib/small-model/call.test.js +0 -1292
- package/server/lib/small-model/catalog.js +0 -13
- package/server/lib/small-model/resolve.js +0 -131
- package/server/lib/small-model/resolve.test.js +0 -197
- package/server/lib/small-model/runtime-providers.js +0 -164
- package/server/lib/small-model/runtime-providers.test.js +0 -118
- package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
- package/server/lib/system-prompt/runtime.js +0 -49
- package/server/lib/system-prompt/runtime.test.js +0 -76
- package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
|
@@ -37,10 +37,39 @@ const runtimes = new Map();
|
|
|
37
37
|
/** @type {Map<string, Promise<ServiceRuntime>>} */
|
|
38
38
|
const startingByGuest = new Map();
|
|
39
39
|
|
|
40
|
+
/** @type {Map<string, Promise<void>>} */
|
|
41
|
+
const stoppingByGuest = new Map();
|
|
42
|
+
|
|
43
|
+
// Requests retain their lifecycle object across awaits. A later host start
|
|
44
|
+
// cannot reopen admission for work that belonged to the previous host.
|
|
45
|
+
let hostLifecycle = { accepting: true };
|
|
46
|
+
|
|
47
|
+
export const beginGuestServiceHost = () => {
|
|
48
|
+
if (runtimes.size || startingByGuest.size || stoppingByGuest.size) {
|
|
49
|
+
throw new Error('Guest services must finish stopping before a new host starts.');
|
|
50
|
+
}
|
|
51
|
+
hostLifecycle.accepting = false;
|
|
52
|
+
hostLifecycle = { accepting: true };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const beginGuestServiceShutdown = () => {
|
|
56
|
+
hostLifecycle.accepting = false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const assertGuestHostActive = (lifecycle) => {
|
|
60
|
+
if (!lifecycle.accepting) {
|
|
61
|
+
throw new GuestServiceError('The host is shutting down.', 'NO_SERVICE');
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
40
65
|
export class GuestServiceError extends Error {
|
|
41
66
|
/**
|
|
42
67
|
* @param {string} message
|
|
43
|
-
* @param {'NO_SERVICE' | 'SERVICE_FAILED' | 'BAD_PATH' | 'BAD_METHOD'} code
|
|
68
|
+
* @param {'NO_SERVICE' | 'SERVICE_FAILED' | 'REQUEST_FAILED' | 'BAD_PATH' | 'BAD_METHOD' | 'DISABLED' | 'CANCELLED'} code
|
|
69
|
+
* `SERVICE_FAILED` is a service that never became ready: nothing was sent
|
|
70
|
+
* to it. `REQUEST_FAILED` is a request that was sent and got no usable
|
|
71
|
+
* answer (timeout, dropped connection, unreadable body): the service may
|
|
72
|
+
* have acted on it.
|
|
44
73
|
*/
|
|
45
74
|
constructor(message, code) {
|
|
46
75
|
super(message);
|
|
@@ -175,6 +204,72 @@ const stopEpochs = new Map();
|
|
|
175
204
|
|
|
176
205
|
const stopEpochOf = (guestId) => stopEpochs.get(guestId) ?? 0;
|
|
177
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Services the host starts on its own (a provider role) have no panel whose
|
|
209
|
+
* closing would end them, so they end themselves: a request arms a timer, the
|
|
210
|
+
* next request re-arms it, and when it fires with nothing in flight the
|
|
211
|
+
* process goes away. The next request starts it again. A panel-driven service
|
|
212
|
+
* passes no `idleStopMs` and keeps today's lifetime.
|
|
213
|
+
* @type {Map<string, { timer: ReturnType<typeof setTimeout>, inflight: number, idleMs: number }>}
|
|
214
|
+
*/
|
|
215
|
+
const idleStops = new Map();
|
|
216
|
+
|
|
217
|
+
const clearIdleStop = (guestId) => {
|
|
218
|
+
const entry = idleStops.get(guestId);
|
|
219
|
+
if (!entry) return;
|
|
220
|
+
clearTimeout(entry.timer);
|
|
221
|
+
idleStops.delete(guestId);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** Long-lived consumers (a surface viewer) that keep an idle-stopping service up. */
|
|
225
|
+
const holds = new Map();
|
|
226
|
+
|
|
227
|
+
const armIdleStop = (guestId, idleMs) => {
|
|
228
|
+
const previous = idleStops.get(guestId);
|
|
229
|
+
const inflight = previous?.inflight ?? 0;
|
|
230
|
+
if (previous) clearTimeout(previous.timer);
|
|
231
|
+
const timer = setTimeout(() => {
|
|
232
|
+
const current = idleStops.get(guestId);
|
|
233
|
+
if (!current || current.inflight > 0 || (holds.get(guestId) ?? 0) > 0) {
|
|
234
|
+
// A request is running or a viewer is attached; whichever ends last
|
|
235
|
+
// re-arms the timer.
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
idleStops.delete(guestId);
|
|
239
|
+
void discardRuntime(guestId);
|
|
240
|
+
}, idleMs);
|
|
241
|
+
timer.unref?.();
|
|
242
|
+
idleStops.set(guestId, { timer, inflight, idleMs });
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Keeps an idle-stopping service alive while the returned release function
|
|
247
|
+
* has not been called. Releasing the last hold restarts the idle window.
|
|
248
|
+
* @param {string} guestId
|
|
249
|
+
*/
|
|
250
|
+
export const holdGuestService = (guestId) => {
|
|
251
|
+
holds.set(guestId, (holds.get(guestId) ?? 0) + 1);
|
|
252
|
+
let released = false;
|
|
253
|
+
return () => {
|
|
254
|
+
if (released) return;
|
|
255
|
+
released = true;
|
|
256
|
+
const remaining = (holds.get(guestId) ?? 1) - 1;
|
|
257
|
+
if (remaining > 0) {
|
|
258
|
+
holds.set(guestId, remaining);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
holds.delete(guestId);
|
|
262
|
+
const entry = idleStops.get(guestId);
|
|
263
|
+
if (entry && runtimes.get(guestId)) armIdleStop(guestId, entry.idleMs);
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const trackInflight = (guestId, delta) => {
|
|
268
|
+
const entry = idleStops.get(guestId);
|
|
269
|
+
if (!entry) return;
|
|
270
|
+
entry.inflight = Math.max(0, entry.inflight + delta);
|
|
271
|
+
};
|
|
272
|
+
|
|
178
273
|
/**
|
|
179
274
|
* A user-facing stop (Pause, Remove, withdrawn approval, socket change,
|
|
180
275
|
* host quit): ends the process and cancels any request or start in flight.
|
|
@@ -182,6 +277,7 @@ const stopEpochOf = (guestId) => stopEpochs.get(guestId) ?? 0;
|
|
|
182
277
|
*/
|
|
183
278
|
export const stopGuestService = async (guestId) => {
|
|
184
279
|
stopEpochs.set(guestId, stopEpochOf(guestId) + 1);
|
|
280
|
+
clearIdleStop(guestId);
|
|
185
281
|
await discardRuntime(guestId);
|
|
186
282
|
};
|
|
187
283
|
|
|
@@ -192,6 +288,8 @@ export const stopGuestService = async (guestId) => {
|
|
|
192
288
|
* @param {string} guestId
|
|
193
289
|
*/
|
|
194
290
|
const discardRuntime = async (guestId) => {
|
|
291
|
+
const stopping = stoppingByGuest.get(guestId);
|
|
292
|
+
if (stopping) return stopping;
|
|
195
293
|
const runtime = runtimes.get(guestId);
|
|
196
294
|
if (!runtime) {
|
|
197
295
|
return;
|
|
@@ -202,7 +300,7 @@ const discardRuntime = async (guestId) => {
|
|
|
202
300
|
if (child.exitCode !== null || child.signalCode) {
|
|
203
301
|
return;
|
|
204
302
|
}
|
|
205
|
-
|
|
303
|
+
const stopped = new Promise((resolve) => {
|
|
206
304
|
const timer = setTimeout(() => {
|
|
207
305
|
child.kill('SIGKILL');
|
|
208
306
|
resolve(undefined);
|
|
@@ -213,14 +311,24 @@ const discardRuntime = async (guestId) => {
|
|
|
213
311
|
});
|
|
214
312
|
child.kill('SIGTERM');
|
|
215
313
|
});
|
|
314
|
+
stoppingByGuest.set(guestId, stopped);
|
|
315
|
+
try {
|
|
316
|
+
await stopped;
|
|
317
|
+
} finally {
|
|
318
|
+
stoppingByGuest.delete(guestId);
|
|
319
|
+
}
|
|
216
320
|
};
|
|
217
321
|
|
|
218
322
|
/** Test seam: the pid of a guest's running service, or `null`. */
|
|
219
323
|
export const readServicePid = (guestId) => runtimes.get(guestId)?.child.pid ?? null;
|
|
220
324
|
|
|
221
325
|
export const stopAllGuestServices = async () => {
|
|
222
|
-
const
|
|
223
|
-
|
|
326
|
+
const starts = [...startingByGuest.values()];
|
|
327
|
+
const ids = new Set([...runtimes.keys(), ...startingByGuest.keys(), ...stoppingByGuest.keys()]);
|
|
328
|
+
const stops = [...ids].map((id) => stopGuestService(id));
|
|
329
|
+
// Cancelled starts reject normally. Await their cleanup as well as children
|
|
330
|
+
// already registered when shutdown began.
|
|
331
|
+
await Promise.allSettled([...starts, ...stops]);
|
|
224
332
|
};
|
|
225
333
|
|
|
226
334
|
/**
|
|
@@ -266,7 +374,14 @@ const startGuestService = async ({
|
|
|
266
374
|
socketBindings = [],
|
|
267
375
|
socketOverrides = {},
|
|
268
376
|
epoch,
|
|
377
|
+
lifecycle,
|
|
269
378
|
}) => {
|
|
379
|
+
assertGuestHostActive(lifecycle);
|
|
380
|
+
// A replacement must not occupy the same guest slot while its previous
|
|
381
|
+
// child is still stopping; host shutdown must be able to drain both.
|
|
382
|
+
const previousStop = stoppingByGuest.get(guestId);
|
|
383
|
+
if (previousStop) await previousStop;
|
|
384
|
+
assertGuestHostActive(lifecycle);
|
|
270
385
|
const existing = runtimes.get(guestId);
|
|
271
386
|
if (existing?.status === 'ready' && existing.child.exitCode === null && !existing.child.signalCode) {
|
|
272
387
|
return existing;
|
|
@@ -276,7 +391,7 @@ const startGuestService = async ({
|
|
|
276
391
|
}
|
|
277
392
|
// The request's epoch, read before its first store access: a Pause that
|
|
278
393
|
// finished anywhere since then is a cancellation, spawn included.
|
|
279
|
-
const cancelled = () => stopEpochOf(guestId) !== epoch;
|
|
394
|
+
const cancelled = () => !lifecycle.accepting || stopEpochOf(guestId) !== epoch;
|
|
280
395
|
const stoppedError = () => new GuestServiceError('The service was stopped before it became ready.', 'NO_SERVICE');
|
|
281
396
|
|
|
282
397
|
const absoluteEntry = path.resolve(packageRoot, entry);
|
|
@@ -294,6 +409,7 @@ const startGuestService = async ({
|
|
|
294
409
|
throw stoppedError();
|
|
295
410
|
}
|
|
296
411
|
const port = await reserveLoopbackPort();
|
|
412
|
+
if (cancelled()) throw stoppedError();
|
|
297
413
|
const token = crypto.randomBytes(24).toString('hex');
|
|
298
414
|
const socketEnv = socketBindings.length > 0
|
|
299
415
|
? await resolveServiceSocketEnv(socketBindings, socketOverrides)
|
|
@@ -418,8 +534,15 @@ const ensureGuestService = async (params) => {
|
|
|
418
534
|
};
|
|
419
535
|
|
|
420
536
|
/**
|
|
537
|
+
* Starts the guest's service if needed and sends it one HTTP request, giving
|
|
538
|
+
* back the raw `Response`. This is the one place a host-driven caller (a
|
|
539
|
+
* provider role, a shared surface) or a panel proxy talks to the loopback:
|
|
540
|
+
* the enabled check, the grant, the spawn, the epoch, and the bearer live
|
|
541
|
+
* here. The caller reads the body as it needs it (text, JSON, image bytes).
|
|
542
|
+
*
|
|
421
543
|
* @param {{
|
|
422
544
|
* guestId: string,
|
|
545
|
+
* guestName?: string,
|
|
423
546
|
* packageRoot: string,
|
|
424
547
|
* service: { entry: string, permissions?: { sockets?: Array<{ id: string, candidatesByPlatform?: Partial<Record<'linux' | 'darwin' | 'win32', string[]>> }>, exec?: string[] } },
|
|
425
548
|
* granted: string[],
|
|
@@ -428,9 +551,17 @@ const ensureGuestService = async (params) => {
|
|
|
428
551
|
* path: string,
|
|
429
552
|
* query?: Record<string, string>,
|
|
430
553
|
* body?: string,
|
|
431
|
-
*
|
|
554
|
+
* accept?: string,
|
|
555
|
+
* headers?: Record<string, string>,
|
|
556
|
+
* timeoutMs?: number,
|
|
557
|
+
* idleStopMs?: number,
|
|
558
|
+
* signal?: AbortSignal,
|
|
559
|
+
* }} params `timeoutMs` and `idleStopMs` are for host-driven calls; a
|
|
560
|
+
* panel's `serviceRequest` keeps the SDK limits. With `idleStopMs` the
|
|
561
|
+
* service stops itself after that long without a request; `holdGuestService`
|
|
562
|
+
* suspends that while a long-lived consumer (a surface viewer) is attached.
|
|
432
563
|
*/
|
|
433
|
-
export const
|
|
564
|
+
export const openGuestServiceRequest = async ({
|
|
434
565
|
guestId,
|
|
435
566
|
guestName,
|
|
436
567
|
packageRoot,
|
|
@@ -441,7 +572,14 @@ export const proxyGuestServiceRequest = async ({
|
|
|
441
572
|
path: requestPath,
|
|
442
573
|
query,
|
|
443
574
|
body,
|
|
575
|
+
accept = 'application/json',
|
|
576
|
+
headers: extraHeaders,
|
|
577
|
+
timeoutMs = GUEST_REQUEST_TIMEOUT_MS,
|
|
578
|
+
idleStopMs,
|
|
579
|
+
signal,
|
|
444
580
|
}) => {
|
|
581
|
+
const lifecycle = hostLifecycle;
|
|
582
|
+
assertGuestHostActive(lifecycle);
|
|
445
583
|
if (!METHODS.has(method)) {
|
|
446
584
|
throw new GuestServiceError('Unsupported request method.', 'BAD_METHOD');
|
|
447
585
|
}
|
|
@@ -453,6 +591,7 @@ export const proxyGuestServiceRequest = async ({
|
|
|
453
591
|
// enabled flag it read before the pause.
|
|
454
592
|
const epoch = stopEpochOf(guestId);
|
|
455
593
|
const store = await readExtensionStore(persistPath);
|
|
594
|
+
assertGuestHostActive(lifecycle);
|
|
456
595
|
if (store.disabledGuests?.[guestId]) {
|
|
457
596
|
const label = typeof guestName === 'string' && guestName.trim() ? guestName.trim() : 'This extension';
|
|
458
597
|
throw new GuestServiceError(
|
|
@@ -481,9 +620,10 @@ export const proxyGuestServiceRequest = async ({
|
|
|
481
620
|
socketBindings,
|
|
482
621
|
socketOverrides,
|
|
483
622
|
epoch,
|
|
623
|
+
lifecycle,
|
|
484
624
|
});
|
|
485
625
|
}
|
|
486
|
-
if (stopEpochOf(guestId) !== epoch) {
|
|
626
|
+
if (!lifecycle.accepting || stopEpochOf(guestId) !== epoch) {
|
|
487
627
|
if (runtimes.get(guestId) === runtime) {
|
|
488
628
|
await discardRuntime(guestId);
|
|
489
629
|
}
|
|
@@ -507,13 +647,27 @@ export const proxyGuestServiceRequest = async ({
|
|
|
507
647
|
|
|
508
648
|
/** @type {Record<string, string>} */
|
|
509
649
|
const headers = {
|
|
510
|
-
|
|
650
|
+
// Host-set context (surface viewer headers) first: nothing in it can
|
|
651
|
+
// replace the bearer or the content type below.
|
|
652
|
+
...extraHeaders,
|
|
653
|
+
Accept: accept,
|
|
511
654
|
[OPENCHAMBER_SERVICE_AUTH_HEADER]: `Bearer ${runtime.token}`,
|
|
512
655
|
};
|
|
513
656
|
if (body !== undefined && method !== 'GET') {
|
|
514
657
|
headers['Content-Type'] = 'application/json';
|
|
515
658
|
}
|
|
516
659
|
|
|
660
|
+
if (idleStopMs) {
|
|
661
|
+
armIdleStop(guestId, idleStopMs);
|
|
662
|
+
trackInflight(guestId, 1);
|
|
663
|
+
}
|
|
664
|
+
const settleIdle = () => {
|
|
665
|
+
if (!idleStopMs) return;
|
|
666
|
+
trackInflight(guestId, -1);
|
|
667
|
+
// Measured from the end of the last request, not its start: a long
|
|
668
|
+
// action must not be cut short by a timer armed before it began.
|
|
669
|
+
if (runtimes.get(guestId) === runtime) armIdleStop(guestId, idleStopMs);
|
|
670
|
+
};
|
|
517
671
|
let response;
|
|
518
672
|
try {
|
|
519
673
|
response = await fetch(url, {
|
|
@@ -521,18 +675,47 @@ export const proxyGuestServiceRequest = async ({
|
|
|
521
675
|
headers,
|
|
522
676
|
body: method === 'GET' || body === undefined ? undefined : body,
|
|
523
677
|
redirect: 'manual',
|
|
524
|
-
signal: AbortSignal.timeout(
|
|
678
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs),
|
|
525
679
|
});
|
|
526
680
|
} catch {
|
|
681
|
+
settleIdle();
|
|
682
|
+
if (signal?.aborted) {
|
|
683
|
+
throw new GuestServiceError('The request was cancelled.', 'CANCELLED');
|
|
684
|
+
}
|
|
527
685
|
runtime.status = 'failed';
|
|
528
|
-
throw new GuestServiceError('Guest service request failed.', '
|
|
686
|
+
throw new GuestServiceError('Guest service request failed.', 'REQUEST_FAILED');
|
|
529
687
|
}
|
|
688
|
+
// The body is still streaming when we return; the idle window starts once
|
|
689
|
+
// the caller has read it (or dropped it), which is what `finished` marks.
|
|
690
|
+
return {
|
|
691
|
+
response,
|
|
692
|
+
finished: settleIdle,
|
|
693
|
+
};
|
|
694
|
+
};
|
|
530
695
|
|
|
531
|
-
|
|
696
|
+
/**
|
|
697
|
+
* Panel-shaped proxy: text answer, capped. Same params as
|
|
698
|
+
* `openGuestServiceRequest` plus `responseMax`.
|
|
699
|
+
*/
|
|
700
|
+
export const proxyGuestServiceRequest = async ({ responseMax = GUEST_REQUEST_RESPONSE_MAX, ...params }) => {
|
|
701
|
+
const { response, finished } = await openGuestServiceRequest(params);
|
|
702
|
+
let text;
|
|
703
|
+
try {
|
|
704
|
+
text = await response.text();
|
|
705
|
+
} catch {
|
|
706
|
+
finished();
|
|
707
|
+
if (params.signal?.aborted) {
|
|
708
|
+
throw new GuestServiceError('The request was cancelled.', 'CANCELLED');
|
|
709
|
+
}
|
|
710
|
+
const runtime = runtimes.get(params.guestId);
|
|
711
|
+
if (runtime) runtime.status = 'failed';
|
|
712
|
+
throw new GuestServiceError('Guest service request failed.', 'REQUEST_FAILED');
|
|
713
|
+
}
|
|
714
|
+
finished();
|
|
532
715
|
return {
|
|
533
716
|
status: response.status,
|
|
534
|
-
body: text.length <=
|
|
717
|
+
body: text.length <= responseMax
|
|
535
718
|
? text
|
|
536
|
-
: text.slice(0,
|
|
719
|
+
: text.slice(0, responseMax),
|
|
537
720
|
};
|
|
538
721
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { afterEach, describe, expect, test } from 'bun:test';
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, spyOn, test } from 'bun:test';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
getServiceStatus,
|
|
8
|
+
beginGuestServiceHost,
|
|
9
|
+
beginGuestServiceShutdown,
|
|
8
10
|
proxyGuestServiceRequest,
|
|
9
11
|
readServicePid,
|
|
10
12
|
stopAllGuestServices,
|
|
@@ -45,6 +47,8 @@ http.createServer((req, res) => {
|
|
|
45
47
|
return { dir, persistPath, packageRoot };
|
|
46
48
|
};
|
|
47
49
|
|
|
50
|
+
beforeEach(() => beginGuestServiceHost());
|
|
51
|
+
|
|
48
52
|
afterEach(async () => {
|
|
49
53
|
await stopAllGuestServices();
|
|
50
54
|
});
|
|
@@ -194,6 +198,86 @@ describe('guest service proxy', () => {
|
|
|
194
198
|
});
|
|
195
199
|
});
|
|
196
200
|
|
|
201
|
+
describe('host-driven services', () => {
|
|
202
|
+
const request = (extra) => ({
|
|
203
|
+
guestId: 'docker',
|
|
204
|
+
packageRoot: extra.packageRoot,
|
|
205
|
+
service: { entry: 'service/main.js' },
|
|
206
|
+
granted: ['service'],
|
|
207
|
+
persistPath: extra.persistPath,
|
|
208
|
+
method: 'GET',
|
|
209
|
+
path: '/ping',
|
|
210
|
+
...extra,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('stops itself after the idle window and restarts on the next request', async () => {
|
|
214
|
+
const { dir, persistPath, packageRoot } = await writeFixture();
|
|
215
|
+
try {
|
|
216
|
+
await setCapabilityGrants('docker', persistPath, ['service']);
|
|
217
|
+
const first = await proxyGuestServiceRequest(request({ packageRoot, persistPath, idleStopMs: 150 }));
|
|
218
|
+
expect(first.status).toBe(200);
|
|
219
|
+
const pid = readServicePid('docker');
|
|
220
|
+
expect(pid).not.toBeNull();
|
|
221
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
222
|
+
expect(getServiceStatus('docker')).toBe('stopped');
|
|
223
|
+
expect(readServicePid('docker')).toBeNull();
|
|
224
|
+
|
|
225
|
+
const second = await proxyGuestServiceRequest(request({ packageRoot, persistPath, idleStopMs: 150 }));
|
|
226
|
+
expect(second.status).toBe(200);
|
|
227
|
+
expect(readServicePid('docker')).not.toBe(pid);
|
|
228
|
+
} finally {
|
|
229
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('a request keeps re-arming the window, and a panel request never arms one', async () => {
|
|
234
|
+
const { dir, persistPath, packageRoot } = await writeFixture();
|
|
235
|
+
try {
|
|
236
|
+
await setCapabilityGrants('docker', persistPath, ['service']);
|
|
237
|
+
await proxyGuestServiceRequest(request({ packageRoot, persistPath, idleStopMs: 200 }));
|
|
238
|
+
const pid = readServicePid('docker');
|
|
239
|
+
for (let i = 0; i < 3; i += 1) {
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
241
|
+
await proxyGuestServiceRequest(request({ packageRoot, persistPath, idleStopMs: 200 }));
|
|
242
|
+
}
|
|
243
|
+
expect(readServicePid('docker')).toBe(pid);
|
|
244
|
+
|
|
245
|
+
await stopGuestService('docker');
|
|
246
|
+
await proxyGuestServiceRequest(request({ packageRoot, persistPath }));
|
|
247
|
+
await new Promise((resolve) => setTimeout(resolve, 350));
|
|
248
|
+
expect(getServiceStatus('docker')).toBe('ready');
|
|
249
|
+
} finally {
|
|
250
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('a longer timeout and a bigger response cap are honoured', async () => {
|
|
255
|
+
const { dir, persistPath, packageRoot } = await writeFixture();
|
|
256
|
+
try {
|
|
257
|
+
await setCapabilityGrants('docker', persistPath, ['service']);
|
|
258
|
+
const result = await proxyGuestServiceRequest(request({ packageRoot, persistPath, timeoutMs: 45_000, responseMax: 5 }));
|
|
259
|
+
expect(result).toEqual({ status: 200, body: '{"pon' });
|
|
260
|
+
} finally {
|
|
261
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('an aborted request reports cancellation, not a failed service', async () => {
|
|
266
|
+
const { dir, persistPath, packageRoot } = await writeFixture();
|
|
267
|
+
try {
|
|
268
|
+
await setCapabilityGrants('docker', persistPath, ['service']);
|
|
269
|
+
await proxyGuestServiceRequest(request({ packageRoot, persistPath }));
|
|
270
|
+
const controller = new AbortController();
|
|
271
|
+
controller.abort();
|
|
272
|
+
await expect(proxyGuestServiceRequest(request({ packageRoot, persistPath, signal: controller.signal })))
|
|
273
|
+
.rejects.toMatchObject({ code: 'CANCELLED' });
|
|
274
|
+
expect(getServiceStatus('docker')).toBe('ready');
|
|
275
|
+
} finally {
|
|
276
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
197
281
|
describe('pause during startup', () => {
|
|
198
282
|
test('a stop that lands while the service is coming up wins', async () => {
|
|
199
283
|
const { dir, persistPath, packageRoot } = await writeFixture();
|
|
@@ -275,3 +359,119 @@ describe('restart after the process died', () => {
|
|
|
275
359
|
}
|
|
276
360
|
});
|
|
277
361
|
});
|
|
362
|
+
|
|
363
|
+
describe('host shutdown', () => {
|
|
364
|
+
const request = (fixture) => ({
|
|
365
|
+
guestId: 'docker', packageRoot: fixture.packageRoot,
|
|
366
|
+
service: { entry: 'service/main.js' }, granted: ['service'],
|
|
367
|
+
persistPath: fixture.persistPath, method: 'GET', path: '/ping',
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('a replacement waits for the previous child and cannot escape host shutdown', async () => {
|
|
371
|
+
const fixture = await writeFixture();
|
|
372
|
+
await fs.appendFile(path.join(fixture.packageRoot, 'service/main.js'), '\nprocess.on("SIGTERM", () => {});\n');
|
|
373
|
+
let pid;
|
|
374
|
+
let reading;
|
|
375
|
+
let accessing;
|
|
376
|
+
try {
|
|
377
|
+
await proxyGuestServiceRequest(request(fixture));
|
|
378
|
+
pid = readServicePid('docker');
|
|
379
|
+
const previousStop = stopGuestService('docker');
|
|
380
|
+
accessing = spyOn(fs, 'access');
|
|
381
|
+
const storeRead = Promise.withResolvers();
|
|
382
|
+
const readFile = fs.readFile.bind(fs);
|
|
383
|
+
reading = spyOn(fs, 'readFile').mockImplementation(async (...args) => {
|
|
384
|
+
const result = await readFile(...args);
|
|
385
|
+
if (args[0] === fixture.persistPath) storeRead.resolve();
|
|
386
|
+
return result;
|
|
387
|
+
});
|
|
388
|
+
const replacement = proxyGuestServiceRequest(request(fixture)).catch((error) => error);
|
|
389
|
+
await storeRead.promise;
|
|
390
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
391
|
+
expect(accessing).not.toHaveBeenCalledWith(path.join(fixture.packageRoot, 'service/main.js'));
|
|
392
|
+
expect(readServicePid('docker')).toBeNull();
|
|
393
|
+
beginGuestServiceShutdown();
|
|
394
|
+
const stopping = stopAllGuestServices();
|
|
395
|
+
process.kill(pid, 'SIGKILL');
|
|
396
|
+
await Promise.all([previousStop, stopping]);
|
|
397
|
+
expect(await replacement).toMatchObject({ code: 'NO_SERVICE' });
|
|
398
|
+
expect(readServicePid('docker')).toBeNull();
|
|
399
|
+
expect(() => process.kill(pid, 0)).toThrow();
|
|
400
|
+
} finally {
|
|
401
|
+
reading?.mockRestore();
|
|
402
|
+
accessing?.mockRestore();
|
|
403
|
+
if (pid) { try { process.kill(pid, 'SIGKILL'); } catch {} }
|
|
404
|
+
await stopAllGuestServices();
|
|
405
|
+
await fs.rm(fixture.dir, { recursive: true, force: true });
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test('rejects new requests, drains a live child, and only reopens on a new host lifecycle', async () => {
|
|
410
|
+
const fixture = await writeFixture();
|
|
411
|
+
try {
|
|
412
|
+
expect((await proxyGuestServiceRequest(request(fixture))).status).toBe(200);
|
|
413
|
+
const pid = readServicePid('docker');
|
|
414
|
+
beginGuestServiceShutdown();
|
|
415
|
+
const stopping = stopAllGuestServices();
|
|
416
|
+
await expect(proxyGuestServiceRequest(request(fixture))).rejects.toMatchObject({ code: 'NO_SERVICE' });
|
|
417
|
+
await stopping;
|
|
418
|
+
expect(readServicePid('docker')).toBeNull();
|
|
419
|
+
expect(() => process.kill(pid, 0)).toThrow();
|
|
420
|
+
await expect(proxyGuestServiceRequest(request(fixture))).rejects.toMatchObject({ code: 'NO_SERVICE' });
|
|
421
|
+
beginGuestServiceHost();
|
|
422
|
+
expect((await proxyGuestServiceRequest(request(fixture))).status).toBe(200);
|
|
423
|
+
} finally {
|
|
424
|
+
await stopAllGuestServices();
|
|
425
|
+
await fs.rm(fixture.dir, { recursive: true, force: true });
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test('drains a first start paused before spawn and prevents it from surviving shutdown', async () => {
|
|
430
|
+
const fixture = await writeFixture();
|
|
431
|
+
const entered = Promise.withResolvers();
|
|
432
|
+
const release = Promise.withResolvers();
|
|
433
|
+
const access = fs.access.bind(fs);
|
|
434
|
+
const pausedAccess = spyOn(fs, 'access').mockImplementation(async (...args) => {
|
|
435
|
+
if (args[0] === path.join(fixture.packageRoot, 'service/main.js')) {
|
|
436
|
+
entered.resolve();
|
|
437
|
+
await release.promise;
|
|
438
|
+
}
|
|
439
|
+
return access(...args);
|
|
440
|
+
});
|
|
441
|
+
try {
|
|
442
|
+
const pending = proxyGuestServiceRequest(request(fixture)).catch((error) => error);
|
|
443
|
+
await entered.promise;
|
|
444
|
+
expect(readServicePid('docker')).toBeNull();
|
|
445
|
+
beginGuestServiceShutdown();
|
|
446
|
+
let drained = false;
|
|
447
|
+
const stopping = stopAllGuestServices().then(() => { drained = true; });
|
|
448
|
+
await Promise.resolve();
|
|
449
|
+
expect(drained).toBe(false);
|
|
450
|
+
expect(() => beginGuestServiceHost()).toThrow();
|
|
451
|
+
release.resolve();
|
|
452
|
+
expect(await pending).toMatchObject({ code: 'NO_SERVICE' });
|
|
453
|
+
await stopping;
|
|
454
|
+
expect(readServicePid('docker')).toBeNull();
|
|
455
|
+
expect(getServiceStatus('docker')).toBe('stopped');
|
|
456
|
+
} finally {
|
|
457
|
+
release.resolve();
|
|
458
|
+
pausedAccess.mockRestore();
|
|
459
|
+
await stopAllGuestServices();
|
|
460
|
+
await fs.rm(fixture.dir, { recursive: true, force: true });
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
test('a request still reading the store cannot enter a later host lifecycle', async () => {
|
|
465
|
+
const fixture = await writeFixture();
|
|
466
|
+
try {
|
|
467
|
+
const pending = proxyGuestServiceRequest(request(fixture));
|
|
468
|
+
beginGuestServiceShutdown();
|
|
469
|
+
await stopAllGuestServices();
|
|
470
|
+
beginGuestServiceHost();
|
|
471
|
+
await expect(pending).rejects.toMatchObject({ code: 'NO_SERVICE' });
|
|
472
|
+
expect(readServicePid('docker')).toBeNull();
|
|
473
|
+
} finally {
|
|
474
|
+
await fs.rm(fixture.dir, { recursive: true, force: true });
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|