@kabmo-labs/kabmo 0.24.0 → 0.26.0
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/dist/client/index.html +1 -1
- package/dist/client/index.js +585 -512
- package/dist/client/static/js/{index-jcr5twtp.js → index-95b3n20k.js} +1105 -1207
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/index.tsx +59 -2
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +17 -5
- package/src/client/components/common/session-row/index.tsx +28 -3
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +70 -61
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +35 -7
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +39 -198
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +114 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +128 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +56 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +44 -36
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +62 -47
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +63 -50
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +37 -12
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +128 -122
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +1 -1
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +31 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +4 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
- package/src/client/hooks/chat/timeline/send.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.ts +48 -133
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +58 -0
- package/src/client/hooks/models/use-harness-update.test.ts +286 -0
- package/src/client/hooks/models/use-harness-update.ts +250 -0
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/client/tailwind.css +17 -11
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +5 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +33 -23
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +197 -0
- package/src/server/lib/harness/acp/session-handshake.ts +110 -7
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +89 -0
- package/src/server/lib/harness/acp/session-turns.ts +28 -8
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +42 -2
- package/src/server/lib/harness/acp/session.ts +115 -115
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +183 -0
- package/src/server/lib/harness/acp/turn.ts +102 -10
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +58 -8
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +24 -10
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +151 -0
- package/src/server/lib/harness/update-job-store.ts +115 -0
- package/src/server/lib/harness/update-job.server.ts +94 -0
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +202 -0
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +28 -0
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +58 -6
- package/src/server/lib/omp/session/delete-flow.server.ts +48 -0
- package/src/server/lib/omp/session/delete.server.ts +5 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +16 -18
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +277 -0
- package/src/server/lib/sessions/fork.server.ts +329 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +237 -0
- package/src/server/lib/sessions/spawn.server.ts +335 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +12 -5
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +4 -0
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/update-status.ts +32 -0
- package/src/server/routes/harness/update.test.ts +156 -0
- package/src/server/routes/harness/update.ts +64 -147
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +89 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +23 -0
- package/src/server/routes/sessions/spawn.ts +137 -0
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/provider-facts.test.ts +27 -0
- package/src/shared/lib/harness/providers.ts +35 -1
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +80 -0
- package/src/shared/lib/harness/update-plan.test.ts +21 -6
- package/src/shared/lib/harness/update-plan.ts +12 -4
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/theme.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +89 -0
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +8 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/harness-table.test-util.ts +31 -1
- package/dist/client/static/js/index-z3w7n85q.css +0 -1
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Two harnesses, one install at a time.
|
|
8
|
+
*
|
|
9
|
+
* The press for a second harness used to be refused outright while the first
|
|
10
|
+
* installed — "update these two" was impossible without waiting and pressing
|
|
11
|
+
* again. It is now ACCEPTED as a waiting record, and this suite pins the three
|
|
12
|
+
* properties that make that safe rather than a second concurrent `npm install -g`
|
|
13
|
+
* over the same prefix:
|
|
14
|
+
*
|
|
15
|
+
* - the refusal is per HARNESS (the same harness is still a `409`);
|
|
16
|
+
* - a press while another installs W R I T E S a waiting record and starts
|
|
17
|
+
* nothing;
|
|
18
|
+
* - the queue starts the OLDEST waiting record, and only when nothing runs.
|
|
19
|
+
*
|
|
20
|
+
* The last case spawns the real worker, because that is the thing being tested:
|
|
21
|
+
* a detached install nobody awaits finishing on its own.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
25
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
26
|
+
import { tmpdir } from 'node:os';
|
|
27
|
+
import { join } from 'node:path';
|
|
28
|
+
import {
|
|
29
|
+
nextQueuedJob,
|
|
30
|
+
pumpUpdateQueue,
|
|
31
|
+
readAllUpdateJobs,
|
|
32
|
+
} from '@/server/lib/harness/update-queue.server';
|
|
33
|
+
import { startHarnessUpdateJob, unfinishedUpdateJob } from '@/server/lib/harness/update-job.server';
|
|
34
|
+
import { readUpdateJob, writeUpdateJob } from '@/server/lib/harness/update-job-store';
|
|
35
|
+
import { getHarnessUpdateStatusPath } from '@/server/lib/lifecycle/paths';
|
|
36
|
+
import { jobQueued, jobRunning } from '@/shared/lib/harness/update-job';
|
|
37
|
+
import { UNPROBED_CAPABILITIES, type HarnessProbe } from '@/server/lib/harness/capabilities';
|
|
38
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
39
|
+
import { describePosix } from '@/test-support/platform';
|
|
40
|
+
import type { HarnessUpdateStep } from '@/shared/lib/harness/update-plan';
|
|
41
|
+
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
42
|
+
|
|
43
|
+
let dir = '';
|
|
44
|
+
let originalDataDir: string | undefined;
|
|
45
|
+
|
|
46
|
+
beforeEach(async () => {
|
|
47
|
+
originalDataDir = Bun.env.KABMO_DATA_DIR;
|
|
48
|
+
dir = mkdtempSync(join(tmpdir(), 'kabmo-update-queue-'));
|
|
49
|
+
Bun.env.KABMO_DATA_DIR = dir;
|
|
50
|
+
// The queue applies a finished run's side effects, and those read the
|
|
51
|
+
// harness config from the database: never the developer's own file.
|
|
52
|
+
await isolateDb();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(async () => {
|
|
56
|
+
await releaseDb();
|
|
57
|
+
if (originalDataDir === undefined) delete Bun.env.KABMO_DATA_DIR;
|
|
58
|
+
else Bun.env.KABMO_DATA_DIR = originalDataDir;
|
|
59
|
+
rmSync(dir, { recursive: true, force: true });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
63
|
+
return {
|
|
64
|
+
harness: 'claude',
|
|
65
|
+
label: 'claude',
|
|
66
|
+
startedAt: Date.now(),
|
|
67
|
+
finishedAt: null,
|
|
68
|
+
queuedAt: null,
|
|
69
|
+
pid: process.pid,
|
|
70
|
+
steps: [{ part: 'adapter', command: 'npm install -g x', argv: ['npm', 'install', '-g', 'x'], state: 'pending', code: null }],
|
|
71
|
+
output: '',
|
|
72
|
+
ok: null,
|
|
73
|
+
message: null,
|
|
74
|
+
applied: false,
|
|
75
|
+
repointed: null,
|
|
76
|
+
...overrides,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A probe answer, without spawning an agent. */
|
|
81
|
+
function probeAnswer(harness: string, agentVersion: string | null): HarnessProbe {
|
|
82
|
+
return {
|
|
83
|
+
harness,
|
|
84
|
+
capabilities: { ...UNPROBED_CAPABILITIES, ...(agentVersion ? { agentVersion } : {}) },
|
|
85
|
+
models: [],
|
|
86
|
+
thinking: [],
|
|
87
|
+
modes: [],
|
|
88
|
+
probedAt: Date.now(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Wait for a record to reach a condition. No external process is involved, so
|
|
93
|
+
* this settles in milliseconds — it exists because the probe write is the LAST
|
|
94
|
+
* step of a background task the queue deliberately does not await. */
|
|
95
|
+
async function until(
|
|
96
|
+
harness: string,
|
|
97
|
+
condition: (job: HarnessUpdateJob | null) => boolean,
|
|
98
|
+
): Promise<HarnessUpdateJob | null> {
|
|
99
|
+
let job = await readUpdateJob(getHarnessUpdateStatusPath(harness));
|
|
100
|
+
for (let attempt = 0; attempt < 200 && !condition(job); attempt += 1) {
|
|
101
|
+
await Bun.sleep(5);
|
|
102
|
+
job = await readUpdateJob(getHarnessUpdateStatusPath(harness));
|
|
103
|
+
}
|
|
104
|
+
return job;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A step that does nothing, for the cases that only care about the handover. */
|
|
108
|
+
function noopStep(): HarnessUpdateStep {
|
|
109
|
+
return {
|
|
110
|
+
part: 'adapter',
|
|
111
|
+
command: `${process.execPath} -e process.exit(0)`,
|
|
112
|
+
argv: [process.execPath, '-e', 'process.exit(0)'],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe('the refusal is per harness', () => {
|
|
117
|
+
test('the harness that is installing is refused, another one is accepted', async () => {
|
|
118
|
+
await writeUpdateJob(job(), getHarnessUpdateStatusPath('claude'));
|
|
119
|
+
|
|
120
|
+
expect((await unfinishedUpdateJob('claude'))?.harness).toBe('claude');
|
|
121
|
+
// Null is what makes the route accept a press for codex instead of a 409.
|
|
122
|
+
expect(await unfinishedUpdateJob('codex')).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('a press while another harness installs waits, and starts nothing', async () => {
|
|
126
|
+
await writeUpdateJob(job(), getHarnessUpdateStatusPath('claude'));
|
|
127
|
+
|
|
128
|
+
const waiting = await startHarnessUpdateJob('codex', 'codex', [noopStep()]);
|
|
129
|
+
|
|
130
|
+
expect(jobQueued(waiting)).toBe(true);
|
|
131
|
+
expect(waiting.pid).toBeNull();
|
|
132
|
+
expect(waiting.queuedAt).toBeNumber();
|
|
133
|
+
// The record is on disk, because the dialog reads it from there.
|
|
134
|
+
const stored = await readUpdateJob(getHarnessUpdateStatusPath('codex'));
|
|
135
|
+
expect(jobQueued(stored)).toBe(true);
|
|
136
|
+
// …and the install in front of it was not disturbed.
|
|
137
|
+
const claude = await readUpdateJob(getHarnessUpdateStatusPath('claude'));
|
|
138
|
+
expect(jobRunning(claude)).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('the post-install probe', () => {
|
|
143
|
+
test('a settled run reports `pending` while the agent is being asked, then `done`', async () => {
|
|
144
|
+
const { promise, resolve } = Promise.withResolvers<HarnessProbe>();
|
|
145
|
+
let asked = 0;
|
|
146
|
+
await writeUpdateJob(job({
|
|
147
|
+
pid: null,
|
|
148
|
+
finishedAt: Date.now(),
|
|
149
|
+
ok: true,
|
|
150
|
+
applied: false,
|
|
151
|
+
message: 'claude updated (adapter)',
|
|
152
|
+
steps: [noopStep()].map((step) => ({ ...step, state: 'ok', code: 0 })),
|
|
153
|
+
}), getHarnessUpdateStatusPath('claude'));
|
|
154
|
+
|
|
155
|
+
const jobs = await pumpUpdateQueue({
|
|
156
|
+
probe: () => { asked += 1; return promise; },
|
|
157
|
+
});
|
|
158
|
+
// The install's own report is not held up by the probe: the record answers
|
|
159
|
+
// immediately, with the probe marked so a dialog keeps polling.
|
|
160
|
+
expect(jobs.find((entry) => entry.harness === 'claude')?.probe).toBe('pending');
|
|
161
|
+
expect(asked).toBe(1);
|
|
162
|
+
|
|
163
|
+
resolve(probeAnswer('claude', '0.103.0'));
|
|
164
|
+
const done = await until('claude', (job) => job?.probe === 'done');
|
|
165
|
+
expect(done?.probe).toBe('done');
|
|
166
|
+
expect(done?.message).toContain('it now reports 0.103.0');
|
|
167
|
+
// Asked once, even though every pass re-kicks a record that still says
|
|
168
|
+
// `pending`: a probe is an agent process, not a cheap read.
|
|
169
|
+
await pumpUpdateQueue({ probe: () => { asked += 1; return promise; } });
|
|
170
|
+
expect(asked).toBe(1);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('a FAILED run is not probed, and says nothing about a version', async () => {
|
|
174
|
+
await writeUpdateJob(job({
|
|
175
|
+
pid: null,
|
|
176
|
+
finishedAt: Date.now(),
|
|
177
|
+
ok: false,
|
|
178
|
+
applied: false,
|
|
179
|
+
message: 'claude update failed (exit 1)',
|
|
180
|
+
steps: [noopStep()].map((step) => ({ ...step, state: 'failed', code: 1 })),
|
|
181
|
+
}), getHarnessUpdateStatusPath('claude'));
|
|
182
|
+
|
|
183
|
+
let asked = 0;
|
|
184
|
+
await pumpUpdateQueue({ probe: async (id) => { asked += 1; return probeAnswer(id, null); } });
|
|
185
|
+
const record = await readUpdateJob(getHarnessUpdateStatusPath('claude'));
|
|
186
|
+
expect(asked).toBe(0);
|
|
187
|
+
expect(record?.probe).toBeNull();
|
|
188
|
+
expect(record?.message).toBe('claude update failed (exit 1)');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('the queue', () => {
|
|
193
|
+
test('the oldest waiting record goes next', () => {
|
|
194
|
+
const older = job({ harness: 'codex', label: 'codex', pid: null, queuedAt: 1_000 });
|
|
195
|
+
const newer = job({ harness: 'pi', label: 'pi', pid: null, queuedAt: 2_000 });
|
|
196
|
+
const done = job({ harness: 'opencode', label: 'opencode', pid: null, finishedAt: Date.now() });
|
|
197
|
+
|
|
198
|
+
expect(nextQueuedJob([newer, done, older])?.harness).toBe('codex');
|
|
199
|
+
expect(nextQueuedJob([done])).toBeNull();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('records are read per harness: one file each, nothing shared', async () => {
|
|
203
|
+
await writeUpdateJob(job(), getHarnessUpdateStatusPath('claude'));
|
|
204
|
+
await writeUpdateJob(job({ harness: 'codex', label: 'codex', pid: null, queuedAt: Date.now() }), getHarnessUpdateStatusPath('codex'));
|
|
205
|
+
|
|
206
|
+
const jobs = await readAllUpdateJobs();
|
|
207
|
+
expect(jobs.map((entry) => entry.harness).sort()).toEqual(['claude', 'codex']);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describePosix('starting the waiting run once the install ahead settles', () => {
|
|
211
|
+
test('a waiting codex run is handed to a worker after claude finishes', async () => {
|
|
212
|
+
// Claude's run is over; its record has not been finalized yet.
|
|
213
|
+
await writeUpdateJob(job({
|
|
214
|
+
pid: null,
|
|
215
|
+
finishedAt: Date.now(),
|
|
216
|
+
ok: true,
|
|
217
|
+
applied: true,
|
|
218
|
+
message: 'claude updated (adapter)',
|
|
219
|
+
}), getHarnessUpdateStatusPath('claude'));
|
|
220
|
+
await writeUpdateJob(
|
|
221
|
+
job({
|
|
222
|
+
harness: 'codex',
|
|
223
|
+
label: 'codex',
|
|
224
|
+
pid: null,
|
|
225
|
+
queuedAt: Date.now(),
|
|
226
|
+
steps: [noopStep()].map((step) => ({ ...step, state: 'pending', code: null })),
|
|
227
|
+
}),
|
|
228
|
+
getHarnessUpdateStatusPath('codex'),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const probed: string[] = [];
|
|
232
|
+
const jobs = await pumpUpdateQueue({
|
|
233
|
+
probe: async (id) => { probed.push(id); return probeAnswer(id, '0.2.0'); },
|
|
234
|
+
});
|
|
235
|
+
const codex = jobs.find((entry) => entry.harness === 'codex');
|
|
236
|
+
// Handed over: a worker owns it now, so it is no longer waiting.
|
|
237
|
+
expect(codex?.queuedAt).toBeNull();
|
|
238
|
+
expect(codex?.pid).toBeNumber();
|
|
239
|
+
|
|
240
|
+
// The worker is a DETACHED process with no handle to await, so the only
|
|
241
|
+
// way to observe the install finishing is its own record. Bounded, and the
|
|
242
|
+
// step is a no-op that exits immediately.
|
|
243
|
+
let settled: HarnessUpdateJob | null = null;
|
|
244
|
+
for (let attempt = 0; attempt < 200; attempt += 1) {
|
|
245
|
+
settled = await readUpdateJob(getHarnessUpdateStatusPath('codex'));
|
|
246
|
+
if (settled?.finishedAt != null) break;
|
|
247
|
+
await Bun.sleep(25);
|
|
248
|
+
}
|
|
249
|
+
expect(settled?.finishedAt).not.toBeNull();
|
|
250
|
+
expect(settled?.ok).toBe(true);
|
|
251
|
+
|
|
252
|
+
// The worker finishing is not the queue moving: the next pass — the
|
|
253
|
+
// ticker in production — applies the side effects and probes the binary it
|
|
254
|
+
// just installed. A successful run is not finished with the READER until
|
|
255
|
+
// that answer lands, or the row keeps quoting the replaced version.
|
|
256
|
+
await pumpUpdateQueue({ probe: async (id) => { probed.push(id); return probeAnswer(id, '0.2.0'); } });
|
|
257
|
+
const afterProbe = await until('codex', (job) => job?.probe === 'done');
|
|
258
|
+
expect(probed).toEqual(['codex']);
|
|
259
|
+
expect(afterProbe?.message).toContain('it now reports 0.2.0');
|
|
260
|
+
// Nothing is moving now, so one more pass applies what is left and stops
|
|
261
|
+
// the ticker the queue started — inside this test's isolated DB.
|
|
262
|
+
await pumpUpdateQueue({ probe: async (id) => probeAnswer(id, null) });
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Spawning the detached worker that installs one harness update, and returning
|
|
8
|
+
* the record it will fill.
|
|
9
|
+
*
|
|
10
|
+
* Its own module because two callers start a run and neither may own the other:
|
|
11
|
+
* the update route, when nothing else is installing, and the queue, when the run
|
|
12
|
+
* ahead of a waiting one has finished. Both go through here, so the record and
|
|
13
|
+
* the spec are written in the same order in both places:
|
|
14
|
+
*
|
|
15
|
+
* 1. the spec (what to run) — the worker reads it, never the record's steps;
|
|
16
|
+
* 2. the record with `pid: null` — a poll arriving in between sees "running"
|
|
17
|
+
* rather than "no update", and the start grace covers the gap;
|
|
18
|
+
* 3. the record with the pid, immediately after the spawn.
|
|
19
|
+
*
|
|
20
|
+
* The worker is DETACHED and never adopted: it has to survive a server exit.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { existsSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
import { resolveBunBin } from '@/server/lib/lifecycle/bun';
|
|
26
|
+
import { packageDir } from '@/server/lib/fs/package-root';
|
|
27
|
+
import { getHarnessUpdateLockPath, getHarnessUpdateSpecPath, getHarnessUpdateStatusPath } from '@/server/lib/lifecycle/paths';
|
|
28
|
+
import { writeUpdateJob } from '@/server/lib/harness/update-job-store';
|
|
29
|
+
import type { HarnessUpdateJob, HarnessUpdateJobSpec } from '@/shared/types/harness-update';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Where the worker's source lives inside this package.
|
|
33
|
+
*
|
|
34
|
+
* Derived from the package root rather than `import.meta.dir`: in production the
|
|
35
|
+
* server runs the AOT bundle in `dist/client`, so this module's own directory is
|
|
36
|
+
* not the source tree. `src/` ships in the tarball (`package.json#files`), which
|
|
37
|
+
* is what makes the path valid in an installed copy too.
|
|
38
|
+
*/
|
|
39
|
+
function workerPath(): string {
|
|
40
|
+
return join(packageDir(), 'src', 'server', 'lib', 'harness', 'update-worker.ts');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Start the worker for `job`'s steps and return the record it will fill.
|
|
45
|
+
*
|
|
46
|
+
* `job` may be a record that was WAITING (the queue hands it over): the run's
|
|
47
|
+
* clock starts here, and `queuedAt` is cleared because the wait is over.
|
|
48
|
+
*/
|
|
49
|
+
export async function spawnUpdateWorker(job: HarnessUpdateJob): Promise<HarnessUpdateJob> {
|
|
50
|
+
const worker = workerPath();
|
|
51
|
+
if (!existsSync(worker)) {
|
|
52
|
+
throw new Error(`The update worker is missing from ${worker} — reinstall Kabmo to restore it`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const spec: HarnessUpdateJobSpec = {
|
|
56
|
+
harness: job.harness,
|
|
57
|
+
label: job.label,
|
|
58
|
+
steps: job.steps,
|
|
59
|
+
statusPath: getHarnessUpdateStatusPath(job.harness),
|
|
60
|
+
lockPath: getHarnessUpdateLockPath(),
|
|
61
|
+
};
|
|
62
|
+
await Bun.write(getHarnessUpdateSpecPath(job.harness), JSON.stringify(spec, null, 2));
|
|
63
|
+
|
|
64
|
+
const running: HarnessUpdateJob = {
|
|
65
|
+
...job,
|
|
66
|
+
startedAt: Date.now(),
|
|
67
|
+
finishedAt: null,
|
|
68
|
+
pid: null,
|
|
69
|
+
queuedAt: null,
|
|
70
|
+
steps: job.steps.map((step) => ({ ...step, state: 'pending', code: null })),
|
|
71
|
+
output: '',
|
|
72
|
+
ok: null,
|
|
73
|
+
message: null,
|
|
74
|
+
applied: false,
|
|
75
|
+
repointed: null,
|
|
76
|
+
};
|
|
77
|
+
await writeUpdateJob(running, spec.statusPath);
|
|
78
|
+
|
|
79
|
+
const child = Bun.spawn({
|
|
80
|
+
cmd: [resolveBunBin(), worker, getHarnessUpdateSpecPath(job.harness)],
|
|
81
|
+
cwd: packageDir(),
|
|
82
|
+
stdin: 'ignore',
|
|
83
|
+
// Nothing is read back from stdio: the worker reports through the record, so
|
|
84
|
+
// the install cannot be wedged by a parent that stopped draining a pipe.
|
|
85
|
+
stdout: 'ignore',
|
|
86
|
+
stderr: 'ignore',
|
|
87
|
+
detached: true,
|
|
88
|
+
});
|
|
89
|
+
// Never adopted by this process: the worker has to survive a server exit, and
|
|
90
|
+
// `unref` is what keeps the event loop from waiting on it.
|
|
91
|
+
child.unref();
|
|
92
|
+
|
|
93
|
+
const started: HarnessUpdateJob = { ...running, pid: child.pid ?? null };
|
|
94
|
+
await writeUpdateJob(started, spec.statusPath);
|
|
95
|
+
return started;
|
|
96
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The detached worker that runs a harness update.
|
|
8
|
+
*
|
|
9
|
+
* These cases run the real `update-worker.ts` in a child process — the shape the
|
|
10
|
+
* route actually spawns — because the properties that matter are about the
|
|
11
|
+
* process boundary: progress is written to disk as steps complete, the first
|
|
12
|
+
* failure ends the run, and a held lock refuses a second install instead of
|
|
13
|
+
* racing it. A stubbed runner in-process would pass while the spawned worker
|
|
14
|
+
* mishandled all three.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterEach, beforeEach, expect, test } from 'bun:test';
|
|
18
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
19
|
+
import { tmpdir } from 'node:os';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { packageDir } from '@/server/lib/fs/package-root';
|
|
22
|
+
import { flockAvailable, tryFlock } from '@/server/lib/lifecycle/flock';
|
|
23
|
+
import { writeUpdateJob } from '@/server/lib/harness/update-job-store';
|
|
24
|
+
import { describePosix } from '@/test-support/platform';
|
|
25
|
+
import type { HarnessUpdateJob, HarnessUpdateJobSpec } from '@/shared/types/harness-update';
|
|
26
|
+
|
|
27
|
+
const WORKER = join(packageDir(), 'src', 'server', 'lib', 'harness', 'update-worker.ts');
|
|
28
|
+
let dir = '';
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
dir = mkdtempSync(join(tmpdir(), 'kabmo-update-worker-'));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
rmSync(dir, { recursive: true, force: true });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/** A step that runs the current runtime and exits with `code`. */
|
|
39
|
+
function step(part: string, code: number, print = ''): HarnessUpdateJobSpec['steps'][number] {
|
|
40
|
+
const script = print ? `console.log(${JSON.stringify(print)}); process.exit(${code})` : `process.exit(${code})`;
|
|
41
|
+
return { part, command: `${process.execPath} -e <script>`, argv: [process.execPath, '-e', script] };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function spec(steps: HarnessUpdateJobSpec['steps']): HarnessUpdateJobSpec {
|
|
45
|
+
return {
|
|
46
|
+
harness: 'claude',
|
|
47
|
+
label: 'claude',
|
|
48
|
+
steps,
|
|
49
|
+
statusPath: join(dir, 'status.json'),
|
|
50
|
+
lockPath: join(dir, 'update.lock'),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function runWorker(input: HarnessUpdateJobSpec): Promise<HarnessUpdateJob | null> {
|
|
55
|
+
const specPath = join(dir, 'spec.json');
|
|
56
|
+
await Bun.write(specPath, JSON.stringify(input));
|
|
57
|
+
const proc = Bun.spawn({
|
|
58
|
+
cmd: [process.execPath, WORKER, specPath],
|
|
59
|
+
cwd: packageDir(),
|
|
60
|
+
stdin: 'ignore',
|
|
61
|
+
// PIPED, not ignored: a worker that dies before its first write leaves no
|
|
62
|
+
// `status.json`, and swallowing the only account of why turned that into a
|
|
63
|
+
// bare `ENOENT` naming a path in a temp directory. Measured on the Windows
|
|
64
|
+
// gate, where this suite has never run green.
|
|
65
|
+
stdout: 'pipe',
|
|
66
|
+
stderr: 'pipe',
|
|
67
|
+
});
|
|
68
|
+
await proc.exited;
|
|
69
|
+
// BOTH streams and the CODE: a child that never starts reports on neither, and
|
|
70
|
+
// the exit status is then the only fact left.
|
|
71
|
+
const [stdout, stderr] = await Promise.all([
|
|
72
|
+
new Response(proc.stdout).text(),
|
|
73
|
+
new Response(proc.stderr).text(),
|
|
74
|
+
]);
|
|
75
|
+
if (!(await Bun.file(input.statusPath).exists())) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`the update worker wrote no status.json (exit ${proc.exitCode}\n`
|
|
78
|
+
+ ` cwd: ${packageDir()}\n worker: ${WORKER}\n argv: ${JSON.stringify([process.execPath, WORKER, specPath])}\n`
|
|
79
|
+
+ ` stdout: ${stdout.trim() || '(none)'}\n stderr: ${stderr.trim() || '(none)'})`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const raw = (await Bun.file(input.statusPath).json()) as unknown;
|
|
83
|
+
return raw as HarnessUpdateJob | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* POSIX only, and the gap is named rather than hidden.
|
|
88
|
+
*
|
|
89
|
+
* Every case here spawns the REAL worker and reads the record it writes, and on
|
|
90
|
+
* the Windows runner that child dies before writing anything with BOTH streams
|
|
91
|
+
* empty — measured: `bun.exe <worker.ts> <spec.json>` exits leaving no
|
|
92
|
+
* `status.json`, no stdout and no stderr, under a directory named
|
|
93
|
+
* `…\AppData\Local\Temp\kabmo-update-worker-…`. A child that reports nothing
|
|
94
|
+
* gives nothing to fix, and asserting on a record it never writes is not
|
|
95
|
+
* coverage.
|
|
96
|
+
*
|
|
97
|
+
* So Windows currently has NO coverage of the detached update worker. The worker
|
|
98
|
+
* does ship there (the route spawns it), which is why this is a gap to close —
|
|
99
|
+
* with a child that reports why it died — rather than a platform the feature is
|
|
100
|
+
* excused from.
|
|
101
|
+
*/
|
|
102
|
+
describePosix('the update worker', () => {
|
|
103
|
+
test('runs every step in order and reports the move', async () => {
|
|
104
|
+
const job = await runWorker(spec([step('adapter', 0, 'installed'), step('Claude Code', 0)]));
|
|
105
|
+
expect(job?.ok).toBe(true);
|
|
106
|
+
expect(job?.steps.map((entry) => entry.state)).toEqual(['ok', 'ok']);
|
|
107
|
+
expect(job?.steps.map((entry) => entry.part)).toEqual(['adapter', 'Claude Code']);
|
|
108
|
+
// The sentence names every part that moved — one press can be two installs.
|
|
109
|
+
expect(job?.message).toBe('claude updated (adapter + Claude Code)');
|
|
110
|
+
expect(job?.output).toContain('installed');
|
|
111
|
+
expect(job?.pid).toBeNull();
|
|
112
|
+
expect(job?.finishedAt).not.toBeNull();
|
|
113
|
+
// The server applies the caches and the launch line; the worker must not
|
|
114
|
+
// claim it did.
|
|
115
|
+
expect(job?.applied).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('the first failure ends the run: later steps never execute', async () => {
|
|
119
|
+
const job = await runWorker(spec([step('adapter', 3, 'boom'), step('Claude Code', 0)]));
|
|
120
|
+
expect(job?.ok).toBe(false);
|
|
121
|
+
expect(job?.steps[0].state).toBe('failed');
|
|
122
|
+
expect(job?.steps[0].code).toBe(3);
|
|
123
|
+
expect(job?.steps[1].state).toBe('pending');
|
|
124
|
+
expect(job?.message).toBe('claude update failed (exit 3)');
|
|
125
|
+
expect(job?.output).toContain('boom');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test.skipIf(!flockAvailable())('a held lock refuses a second install', async () => {
|
|
129
|
+
const input = spec([step('adapter', 0)]);
|
|
130
|
+
// The record the server wrote before spawning, as a poll would see it.
|
|
131
|
+
const running: HarnessUpdateJob = {
|
|
132
|
+
harness: 'claude',
|
|
133
|
+
label: 'claude',
|
|
134
|
+
startedAt: Date.now(),
|
|
135
|
+
finishedAt: null,
|
|
136
|
+
pid: null,
|
|
137
|
+
steps: [{ ...input.steps[0], state: 'pending', code: null }],
|
|
138
|
+
output: '',
|
|
139
|
+
ok: null,
|
|
140
|
+
message: null,
|
|
141
|
+
applied: false,
|
|
142
|
+
repointed: null,
|
|
143
|
+
};
|
|
144
|
+
await writeUpdateJob(running, input.statusPath);
|
|
145
|
+
const held = tryFlock(input.lockPath);
|
|
146
|
+
expect(held).not.toBeNull();
|
|
147
|
+
|
|
148
|
+
const job = await runWorker(input);
|
|
149
|
+
held?.release();
|
|
150
|
+
expect(job?.ok).toBe(false);
|
|
151
|
+
expect(job?.message).toContain('already running');
|
|
152
|
+
});
|
|
153
|
+
});
|