repoburg 1.3.201 → 1.3.204
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/agent-pane/backend/dist/index.js +2714 -32395
- package/agent-pane/backend/dist/server.js +45304 -0
- package/askuser-after-step5-postgres-selected.png +0 -0
- package/askuser-after-step7-answer-sent.png +0 -0
- package/askuser-card-visible.png +0 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.d.ts +16 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js +87 -0
- package/backend/dist/src/agent-runtime/agent-runtime-event-emitter.js.map +1 -1
- package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +16 -1
- package/backend/dist/src/app.controller.d.ts +1 -0
- package/backend/dist/src/app.service.d.ts +1 -0
- package/backend/dist/src/app.service.js +4 -1
- package/backend/dist/src/app.service.js.map +1 -1
- package/backend/dist/src/interactive-chat/chat.service.d.ts +4 -0
- package/backend/dist/src/interactive-chat/chat.service.js +21 -1
- package/backend/dist/src/interactive-chat/chat.service.js.map +1 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js +12 -1
- package/backend/dist/src/llm-orchestration/action-handlers/invoke-subagent.handler.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.d.ts +1 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js +1 -0
- package/backend/dist/src/llm-orchestration/llm-orchestration.interfaces.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +2 -0
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js.map +1 -1
- package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
- package/daemon/dist/agentPane.js +128 -0
- package/daemon/dist/agentPane.spec.js +183 -0
- package/daemon/dist/api/services.js +4 -0
- package/daemon/dist/index.js +28 -8
- package/daemon/dist/serviceManager.js +30 -11
- package/daemon/dist/serviceManager.spec.js +26 -0
- package/daemon/dist/workspace-validation.js +63 -0
- package/daemon/dist/workspace-validation.spec.js +63 -0
- package/daemon/package.json +1 -1
- package/package.json +15 -2
- package/r2-step4-apple-banana.png +0 -0
- package/r2-step5-after-rewind-apple-last.png +0 -0
- package/r2-step7-apple-cherry.png +0 -0
- package/r2-step8-cherry-menu-no-restore.png +0 -0
- package/r3-step3-live-task-card-running.png +0 -0
- package/r3-step4-after-completion.png +0 -0
- package/r3-step5-persistence-after-reload.png +0 -0
- package/r3-step6-tasks-tab-card.png +0 -0
- package/reverify-answered-state-answer-sent.png +0 -0
- package/reverify-card-visible-after-completion.png +0 -0
- package/rewind-step3-apple-banana-turns.png +0 -0
- package/rewind-step5-ui-unchanged-after-confirmed-rewind.png +0 -0
- package/rewind-step6-apple-menu-no-restore.png +0 -0
- package/rewind-step7-final-turnlist-unchanged.png +0 -0
- package/rewind-step7-negative-error-toast.png +0 -0
- package/rewind-step7-negative-error-toast2.png +0 -0
- package/subagent-r2-step5-turn-after-reload-no-card.png +0 -0
- package/subagent-r2-step6-tasks-panel-card.png +0 -0
- package/subagent-step3-tasks-tab-done-card.png +0 -0
- package/subagent-step4-turn-stuck-no-cards.png +0 -0
- package/agent-pane/.prettierignore +0 -5
- package/agent-pane/.prettierrc +0 -8
- package/agent-pane/backend/coverage/base.css +0 -224
- package/agent-pane/backend/coverage/block-navigation.js +0 -87
- package/agent-pane/backend/coverage/clover.xml +0 -887
- package/agent-pane/backend/coverage/coverage-final.json +0 -10
- package/agent-pane/backend/coverage/favicon.png +0 -0
- package/agent-pane/backend/coverage/index.html +0 -176
- package/agent-pane/backend/coverage/prettify.css +0 -1
- package/agent-pane/backend/coverage/prettify.js +0 -2
- package/agent-pane/backend/coverage/sort-arrow-sprite.png +0 -0
- package/agent-pane/backend/coverage/sorter.js +0 -210
- package/agent-pane/backend/coverage/src/codex/codex-provider.ts.html +0 -1402
- package/agent-pane/backend/coverage/src/codex/index.html +0 -131
- package/agent-pane/backend/coverage/src/codex/item-mapper.ts.html +0 -331
- package/agent-pane/backend/coverage/src/db/index.html +0 -131
- package/agent-pane/backend/coverage/src/db/index.ts.html +0 -436
- package/agent-pane/backend/coverage/src/db/schema.ts.html +0 -175
- package/agent-pane/backend/coverage/src/index.html +0 -116
- package/agent-pane/backend/coverage/src/index.ts.html +0 -262
- package/agent-pane/backend/coverage/src/routes/index.html +0 -146
- package/agent-pane/backend/coverage/src/routes/sessions.ts.html +0 -991
- package/agent-pane/backend/coverage/src/routes/turns.ts.html +0 -256
- package/agent-pane/backend/coverage/src/routes/workspaces.ts.html +0 -406
- package/agent-pane/backend/coverage/src/ws/index.html +0 -116
- package/agent-pane/backend/coverage/src/ws/index.ts.html +0 -238
- package/agent-pane/backend/data.db +0 -0
- package/agent-pane/backend/data.db-shm +0 -0
- package/agent-pane/backend/data.db-wal +0 -0
- package/agent-pane/backend/package-lock.json +0 -5945
- package/agent-pane/backend/package.json +0 -33
- package/agent-pane/backend/scripts/backfill-from-jsonl.ts +0 -206
- package/agent-pane/backend/scripts/import-session-from-jsonl.ts +0 -264
- package/agent-pane/backend/src/claude/claude-message-mapper.test.ts +0 -271
- package/agent-pane/backend/src/claude/claude-message-mapper.ts +0 -259
- package/agent-pane/backend/src/claude/claude-provider.test.ts +0 -455
- package/agent-pane/backend/src/claude/claude-provider.ts +0 -1319
- package/agent-pane/backend/src/claude/claude-types.ts +0 -45
- package/agent-pane/backend/src/codex/app-server-client.test.ts +0 -183
- package/agent-pane/backend/src/codex/app-server-client.ts +0 -247
- package/agent-pane/backend/src/codex/app-server-types.ts +0 -259
- package/agent-pane/backend/src/codex/codex-provider-runtime-config.test.ts +0 -56
- package/agent-pane/backend/src/codex/codex-provider.test.ts +0 -60
- package/agent-pane/backend/src/codex/codex-provider.ts +0 -619
- package/agent-pane/backend/src/codex/item-mapper.test.ts +0 -221
- package/agent-pane/backend/src/codex/item-mapper.ts +0 -86
- package/agent-pane/backend/src/codex/shared-app-server.ts +0 -25
- package/agent-pane/backend/src/db/index.test.ts +0 -125
- package/agent-pane/backend/src/db/index.ts +0 -230
- package/agent-pane/backend/src/db/schema.ts +0 -34
- package/agent-pane/backend/src/index.ts +0 -89
- package/agent-pane/backend/src/integration/__fixtures__/cancel-turn.json +0 -29
- package/agent-pane/backend/src/integration/__fixtures__/delta-streaming.json +0 -40
- package/agent-pane/backend/src/integration/__fixtures__/failed-turn.json +0 -16
- package/agent-pane/backend/src/integration/__fixtures__/mcp-tool-call.json +0 -60
- package/agent-pane/backend/src/integration/__fixtures__/missing-item-started.json +0 -34
- package/agent-pane/backend/src/integration/__fixtures__/multi-item-turn.json +0 -85
- package/agent-pane/backend/src/integration/__fixtures__/multi-turn.json +0 -48
- package/agent-pane/backend/src/integration/__fixtures__/simple-turn.json +0 -35
- package/agent-pane/backend/src/integration/delta-streaming.test.ts +0 -130
- package/agent-pane/backend/src/integration/helpers/app-server-mock.ts +0 -272
- package/agent-pane/backend/src/integration/helpers/test-app.ts +0 -110
- package/agent-pane/backend/src/integration/helpers/ws-capture.ts +0 -64
- package/agent-pane/backend/src/integration/item-lifecycle.test.ts +0 -133
- package/agent-pane/backend/src/integration/mcp-tool-call.test.ts +0 -102
- package/agent-pane/backend/src/integration/missing-item-started.test.ts +0 -91
- package/agent-pane/backend/src/integration/multi-turn.test.ts +0 -121
- package/agent-pane/backend/src/integration/session-operations.test.ts +0 -175
- package/agent-pane/backend/src/integration/threads-claude-fork.test.ts +0 -241
- package/agent-pane/backend/src/integration/threads.test.ts +0 -309
- package/agent-pane/backend/src/integration/title-generation.test.ts +0 -109
- package/agent-pane/backend/src/integration/turn-cancel.test.ts +0 -111
- package/agent-pane/backend/src/integration/turn-failure.test.ts +0 -97
- package/agent-pane/backend/src/integration/turn-lifecycle.test.ts +0 -141
- package/agent-pane/backend/src/providers/index.ts +0 -16
- package/agent-pane/backend/src/providers/registry.test.ts +0 -92
- package/agent-pane/backend/src/providers/registry.ts +0 -43
- package/agent-pane/backend/src/providers/runtime-provider.ts +0 -43
- package/agent-pane/backend/src/repoburg/action-mapping.ts +0 -216
- package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +0 -271
- package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +0 -262
- package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +0 -271
- package/agent-pane/backend/src/repoburg/backend-resolver.ts +0 -246
- package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +0 -159
- package/agent-pane/backend/src/repoburg/repoburg-client.ts +0 -181
- package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +0 -723
- package/agent-pane/backend/src/repoburg/repoburg-provider.ts +0 -422
- package/agent-pane/backend/src/repoburg/turn-projector.test.ts +0 -475
- package/agent-pane/backend/src/repoburg/turn-projector.ts +0 -537
- package/agent-pane/backend/src/routes/files.ts +0 -31
- package/agent-pane/backend/src/routes/mcp.ts +0 -33
- package/agent-pane/backend/src/routes/models.test.ts +0 -92
- package/agent-pane/backend/src/routes/models.ts +0 -16
- package/agent-pane/backend/src/routes/plugins.ts +0 -40
- package/agent-pane/backend/src/routes/providers.test.ts +0 -86
- package/agent-pane/backend/src/routes/providers.ts +0 -86
- package/agent-pane/backend/src/routes/sessions.test.ts +0 -558
- package/agent-pane/backend/src/routes/sessions.ts +0 -504
- package/agent-pane/backend/src/routes/skills.test.ts +0 -114
- package/agent-pane/backend/src/routes/skills.ts +0 -70
- package/agent-pane/backend/src/routes/threads.ts +0 -323
- package/agent-pane/backend/src/routes/turns.test.ts +0 -196
- package/agent-pane/backend/src/routes/turns.ts +0 -103
- package/agent-pane/backend/src/routes/workspaces.test.ts +0 -197
- package/agent-pane/backend/src/routes/workspaces.ts +0 -128
- package/agent-pane/backend/src/ws/index.test.ts +0 -107
- package/agent-pane/backend/src/ws/index.ts +0 -51
- package/agent-pane/backend/tsconfig.json +0 -25
- package/agent-pane/backend/vitest.config.ts +0 -20
- package/agent-pane/eslint.config.js +0 -33
- package/agent-pane/frontend/coverage/base.css +0 -224
- package/agent-pane/frontend/coverage/block-navigation.js +0 -87
- package/agent-pane/frontend/coverage/clover.xml +0 -2962
- package/agent-pane/frontend/coverage/coverage-final.json +0 -37
- package/agent-pane/frontend/coverage/favicon.png +0 -0
- package/agent-pane/frontend/coverage/index.html +0 -251
- package/agent-pane/frontend/coverage/prettify.css +0 -1
- package/agent-pane/frontend/coverage/prettify.js +0 -2
- package/agent-pane/frontend/coverage/sort-arrow-sprite.png +0 -0
- package/agent-pane/frontend/coverage/sorter.js +0 -210
- package/agent-pane/frontend/coverage/src/App.tsx.html +0 -217
- package/agent-pane/frontend/coverage/src/AppInitializer.tsx.html +0 -223
- package/agent-pane/frontend/coverage/src/api/client.ts.html +0 -187
- package/agent-pane/frontend/coverage/src/api/index.html +0 -161
- package/agent-pane/frontend/coverage/src/api/sessions.ts.html +0 -316
- package/agent-pane/frontend/coverage/src/api/websocket.ts.html +0 -544
- package/agent-pane/frontend/coverage/src/api/workspaces.ts.html +0 -199
- package/agent-pane/frontend/coverage/src/components/CollapsibleToolCalls.tsx.html +0 -226
- package/agent-pane/frontend/coverage/src/components/CommandInputBar.tsx.html +0 -382
- package/agent-pane/frontend/coverage/src/components/CommandPalette.tsx.html +0 -715
- package/agent-pane/frontend/coverage/src/components/IdeWorkspace.tsx.html +0 -160
- package/agent-pane/frontend/coverage/src/components/ModelSelector.tsx.html +0 -478
- package/agent-pane/frontend/coverage/src/components/NewSessionDialog.tsx.html +0 -472
- package/agent-pane/frontend/coverage/src/components/RenderArea.tsx.html +0 -574
- package/agent-pane/frontend/coverage/src/components/RightPanel.tsx.html +0 -205
- package/agent-pane/frontend/coverage/src/components/RuntimeIcon.tsx.html +0 -133
- package/agent-pane/frontend/coverage/src/components/SessionTabs.tsx.html +0 -217
- package/agent-pane/frontend/coverage/src/components/StatusBar.tsx.html +0 -271
- package/agent-pane/frontend/coverage/src/components/StatusDot.tsx.html +0 -109
- package/agent-pane/frontend/coverage/src/components/Toast.tsx.html +0 -313
- package/agent-pane/frontend/coverage/src/components/TurnContent.tsx.html +0 -1216
- package/agent-pane/frontend/coverage/src/components/WorkspaceSidebar.tsx.html +0 -1138
- package/agent-pane/frontend/coverage/src/components/index.html +0 -326
- package/agent-pane/frontend/coverage/src/components/panels/ChangesPanel.tsx.html +0 -247
- package/agent-pane/frontend/coverage/src/components/panels/LogsPanel.tsx.html +0 -160
- package/agent-pane/frontend/coverage/src/components/panels/MetricsPanel.tsx.html +0 -427
- package/agent-pane/frontend/coverage/src/components/panels/TurnsPanel.tsx.html +0 -397
- package/agent-pane/frontend/coverage/src/components/panels/index.html +0 -161
- package/agent-pane/frontend/coverage/src/constants/index.html +0 -116
- package/agent-pane/frontend/coverage/src/constants/models.ts.html +0 -406
- package/agent-pane/frontend/coverage/src/hooks/index.html +0 -146
- package/agent-pane/frontend/coverage/src/hooks/useEscapeKey.ts.html +0 -124
- package/agent-pane/frontend/coverage/src/hooks/useOutsideClick.ts.html +0 -142
- package/agent-pane/frontend/coverage/src/hooks/useSessionStatus.ts.html +0 -187
- package/agent-pane/frontend/coverage/src/index.html +0 -146
- package/agent-pane/frontend/coverage/src/main.tsx.html +0 -115
- package/agent-pane/frontend/coverage/src/store/index.html +0 -116
- package/agent-pane/frontend/coverage/src/store/store.ts.html +0 -2404
- package/agent-pane/frontend/coverage/src/test/component-helpers.ts.html +0 -190
- package/agent-pane/frontend/coverage/src/test/fixtures.ts.html +0 -367
- package/agent-pane/frontend/coverage/src/test/index.html +0 -131
- package/agent-pane/frontend/coverage/src/types/index.html +0 -116
- package/agent-pane/frontend/coverage/src/types/index.ts.html +0 -466
- package/agent-pane/frontend/coverage/src/utils/changes.ts.html +0 -202
- package/agent-pane/frontend/coverage/src/utils/duration.ts.html +0 -127
- package/agent-pane/frontend/coverage/src/utils/index.html +0 -131
- package/agent-pane/frontend/dist/assets/index-34WaZYsW.css +0 -1
- package/agent-pane/frontend/dist/assets/index-y7xlT86e.js +0 -362
- package/agent-pane/frontend/dist/index.html +0 -19
- package/agent-pane/frontend/index.html +0 -18
- package/agent-pane/frontend/package-lock.json +0 -4211
- package/agent-pane/frontend/package.json +0 -35
- package/agent-pane/frontend/src/App.test.tsx +0 -74
- package/agent-pane/frontend/src/App.tsx +0 -44
- package/agent-pane/frontend/src/AppInitializer.test.tsx +0 -142
- package/agent-pane/frontend/src/AppInitializer.tsx +0 -46
- package/agent-pane/frontend/src/__tests__/ThreadsPanel.test.tsx +0 -192
- package/agent-pane/frontend/src/api/client.test.ts +0 -126
- package/agent-pane/frontend/src/api/client.ts +0 -34
- package/agent-pane/frontend/src/api/models.ts +0 -7
- package/agent-pane/frontend/src/api/providers.ts +0 -17
- package/agent-pane/frontend/src/api/sessions.test.ts +0 -245
- package/agent-pane/frontend/src/api/sessions.ts +0 -97
- package/agent-pane/frontend/src/api/skills.ts +0 -12
- package/agent-pane/frontend/src/api/websocket.test.ts +0 -288
- package/agent-pane/frontend/src/api/websocket.ts +0 -238
- package/agent-pane/frontend/src/api/workspaces.test.ts +0 -112
- package/agent-pane/frontend/src/api/workspaces.ts +0 -38
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.test.tsx +0 -49
- package/agent-pane/frontend/src/components/CollapsibleToolCalls.tsx +0 -56
- package/agent-pane/frontend/src/components/CommandInputBar.test.tsx +0 -133
- package/agent-pane/frontend/src/components/CommandInputBar.tsx +0 -584
- package/agent-pane/frontend/src/components/CommandPalette.test.tsx +0 -226
- package/agent-pane/frontend/src/components/CommandPalette.tsx +0 -194
- package/agent-pane/frontend/src/components/CommentableText.test.tsx +0 -196
- package/agent-pane/frontend/src/components/CommentableText.tsx +0 -379
- package/agent-pane/frontend/src/components/IdeWorkspace.test.tsx +0 -39
- package/agent-pane/frontend/src/components/IdeWorkspace.tsx +0 -51
- package/agent-pane/frontend/src/components/ModelSelector.test.tsx +0 -129
- package/agent-pane/frontend/src/components/ModelSelector.tsx +0 -191
- package/agent-pane/frontend/src/components/NewSessionDialog.test.tsx +0 -95
- package/agent-pane/frontend/src/components/NewSessionDialog.tsx +0 -129
- package/agent-pane/frontend/src/components/RenderArea.test.tsx +0 -160
- package/agent-pane/frontend/src/components/RenderArea.tsx +0 -170
- package/agent-pane/frontend/src/components/ResizeHandle.tsx +0 -29
- package/agent-pane/frontend/src/components/RightPanel.test.tsx +0 -43
- package/agent-pane/frontend/src/components/RightPanel.tsx +0 -46
- package/agent-pane/frontend/src/components/RuntimeIcon.test.tsx +0 -32
- package/agent-pane/frontend/src/components/RuntimeIcon.tsx +0 -16
- package/agent-pane/frontend/src/components/SessionTabs.test.tsx +0 -72
- package/agent-pane/frontend/src/components/SessionTabs.tsx +0 -49
- package/agent-pane/frontend/src/components/StatusBar.test.tsx +0 -56
- package/agent-pane/frontend/src/components/StatusBar.tsx +0 -129
- package/agent-pane/frontend/src/components/StatusDot.test.tsx +0 -25
- package/agent-pane/frontend/src/components/StatusDot.tsx +0 -8
- package/agent-pane/frontend/src/components/Toast.test.tsx +0 -79
- package/agent-pane/frontend/src/components/Toast.tsx +0 -76
- package/agent-pane/frontend/src/components/TurnContent.test.tsx +0 -298
- package/agent-pane/frontend/src/components/TurnContent.tsx +0 -548
- package/agent-pane/frontend/src/components/WorkspaceSidebar.test.tsx +0 -297
- package/agent-pane/frontend/src/components/WorkspaceSidebar.tsx +0 -351
- package/agent-pane/frontend/src/components/input/OptionSubPopup.tsx +0 -32
- package/agent-pane/frontend/src/components/input/SkillMentionPopup.test.tsx +0 -63
- package/agent-pane/frontend/src/components/input/SkillMentionPopup.tsx +0 -78
- package/agent-pane/frontend/src/components/input/SlashPopup.test.tsx +0 -96
- package/agent-pane/frontend/src/components/input/SlashPopup.tsx +0 -82
- package/agent-pane/frontend/src/components/panels/ChangesPanel.test.tsx +0 -61
- package/agent-pane/frontend/src/components/panels/ChangesPanel.tsx +0 -54
- package/agent-pane/frontend/src/components/panels/TasksPanel.test.tsx +0 -97
- package/agent-pane/frontend/src/components/panels/TasksPanel.tsx +0 -208
- package/agent-pane/frontend/src/components/panels/ThreadsPanel.tsx +0 -382
- package/agent-pane/frontend/src/components/panels/TurnsPanel.test.tsx +0 -83
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +0 -126
- package/agent-pane/frontend/src/constants/models.test.ts +0 -97
- package/agent-pane/frontend/src/constants/models.ts +0 -166
- package/agent-pane/frontend/src/hooks/useEscapeKey.test.ts +0 -42
- package/agent-pane/frontend/src/hooks/useEscapeKey.ts +0 -13
- package/agent-pane/frontend/src/hooks/useOutsideClick.test.ts +0 -92
- package/agent-pane/frontend/src/hooks/useOutsideClick.ts +0 -19
- package/agent-pane/frontend/src/hooks/useProvider.ts +0 -44
- package/agent-pane/frontend/src/hooks/useResizable.test.ts +0 -97
- package/agent-pane/frontend/src/hooks/useResizable.ts +0 -75
- package/agent-pane/frontend/src/hooks/useSessionStatus.test.ts +0 -116
- package/agent-pane/frontend/src/hooks/useSessionStatus.ts +0 -34
- package/agent-pane/frontend/src/main.test.tsx +0 -37
- package/agent-pane/frontend/src/main.tsx +0 -10
- package/agent-pane/frontend/src/store/sessionSlice.ts +0 -440
- package/agent-pane/frontend/src/store/store.test.ts +0 -1319
- package/agent-pane/frontend/src/store/store.ts +0 -37
- package/agent-pane/frontend/src/store/threadSlice.ts +0 -136
- package/agent-pane/frontend/src/store/uiSlice.ts +0 -133
- package/agent-pane/frontend/src/store/workspaceSlice.ts +0 -77
- package/agent-pane/frontend/src/store/wsSlice.ts +0 -361
- package/agent-pane/frontend/src/styles/app.css +0 -611
- package/agent-pane/frontend/src/styles/tokens.css +0 -62
- package/agent-pane/frontend/src/test/component-helpers.ts +0 -38
- package/agent-pane/frontend/src/test/fixtures.ts +0 -100
- package/agent-pane/frontend/src/test-setup.ts +0 -5
- package/agent-pane/frontend/src/types/index.test.ts +0 -128
- package/agent-pane/frontend/src/types/index.ts +0 -132
- package/agent-pane/frontend/src/utils/changes.test.ts +0 -81
- package/agent-pane/frontend/src/utils/changes.ts +0 -39
- package/agent-pane/frontend/src/utils/duration.test.ts +0 -75
- package/agent-pane/frontend/src/utils/duration.ts +0 -14
- package/agent-pane/frontend/tsconfig.json +0 -25
- package/agent-pane/frontend/vite.config.ts +0 -22
- package/agent-pane/frontend/vitest.config.ts +0 -29
- package/agent-pane/package-lock.json +0 -1527
- package/agent-pane/package.json +0 -19
- package/agent-pane/shared/provider-types.ts +0 -67
- package/agent-pane/shared/types.ts +0 -167
|
@@ -1,1319 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { useStore } from './store.ts';
|
|
3
|
-
|
|
4
|
-
// Shared test fixtures and helpers
|
|
5
|
-
import { makeSession, makeDetail, makeTurn, makeItem, makeUsage, makeWorkspace } from '../test/fixtures.ts';
|
|
6
|
-
import { resetStore } from '../test/component-helpers.ts';
|
|
7
|
-
|
|
8
|
-
// Mock API modules — must be at top level for vitest hoisting
|
|
9
|
-
vi.mock('../api/sessions.ts', () => ({
|
|
10
|
-
fetchSessions: vi.fn(),
|
|
11
|
-
fetchSessionDetail: vi.fn(),
|
|
12
|
-
createSession: vi.fn(),
|
|
13
|
-
deleteSession: vi.fn(),
|
|
14
|
-
submitPrompt: vi.fn(),
|
|
15
|
-
cancelTurn: vi.fn(),
|
|
16
|
-
renameSession: vi.fn(),
|
|
17
|
-
markFinished: vi.fn(),
|
|
18
|
-
reopenSession: vi.fn(),
|
|
19
|
-
clearUnreviewed: vi.fn(),
|
|
20
|
-
rewindSession: vi.fn(),
|
|
21
|
-
branchSession: vi.fn(),
|
|
22
|
-
updateModelConfig: vi.fn(),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
vi.mock('../api/workspaces.ts', () => ({
|
|
26
|
-
fetchWorkspaces: vi.fn(),
|
|
27
|
-
createWorkspace: vi.fn(),
|
|
28
|
-
hideWorkspace: vi.fn(),
|
|
29
|
-
deleteWorkspace: vi.fn(),
|
|
30
|
-
pickDirectory: vi.fn(),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
// Import mocked functions for assertions
|
|
34
|
-
import {
|
|
35
|
-
fetchSessions,
|
|
36
|
-
fetchSessionDetail,
|
|
37
|
-
createSession as apiCreateSession,
|
|
38
|
-
deleteSession as apiDeleteSession,
|
|
39
|
-
submitPrompt,
|
|
40
|
-
cancelTurn,
|
|
41
|
-
renameSession as apiRenameSession,
|
|
42
|
-
markFinished as apiMarkFinished,
|
|
43
|
-
reopenSession as apiReopenSession,
|
|
44
|
-
clearUnreviewed,
|
|
45
|
-
rewindSession as apiRewindSession,
|
|
46
|
-
branchSession as apiBranchSession,
|
|
47
|
-
updateModelConfig as apiUpdateModelConfig,
|
|
48
|
-
} from '../api/sessions.ts';
|
|
49
|
-
import {
|
|
50
|
-
fetchWorkspaces,
|
|
51
|
-
createWorkspace as apiCreateWorkspace,
|
|
52
|
-
hideWorkspace as apiHideWorkspace,
|
|
53
|
-
pickDirectory as apiPickDirectory,
|
|
54
|
-
} from '../api/workspaces.ts';
|
|
55
|
-
|
|
56
|
-
// === Existing tests (unchanged) ===
|
|
57
|
-
|
|
58
|
-
describe('upsertItem (via onItemStarted)', () => {
|
|
59
|
-
beforeEach(() => {
|
|
60
|
-
vi.clearAllMocks();
|
|
61
|
-
resetStore();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('inserts a new item when no match by external_item_id', () => {
|
|
65
|
-
const turn = makeTurn('t1', 's1');
|
|
66
|
-
const detail = makeDetail('s1', [turn]);
|
|
67
|
-
resetStore({ activeSessionId: 's1', sessionDetails: { s1: detail } });
|
|
68
|
-
|
|
69
|
-
const item = makeItem('i1', 't1');
|
|
70
|
-
useStore.getState().onItemStarted('s1', 't1', item);
|
|
71
|
-
|
|
72
|
-
const updated = useStore.getState().sessionDetails['s1'];
|
|
73
|
-
expect(updated.turns[0].items).toHaveLength(1);
|
|
74
|
-
expect(updated.turns[0].items[0].external_item_id).toBe('ext-i1');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('replaces existing item matching by external_item_id, uses WS event id', () => {
|
|
78
|
-
const existingItem = makeItem('local-i1', 't1');
|
|
79
|
-
const turn = makeTurn('t1', 's1', { items: [existingItem] });
|
|
80
|
-
const detail = makeDetail('s1', [turn]);
|
|
81
|
-
resetStore({ activeSessionId: 's1', sessionDetails: { s1: detail } });
|
|
82
|
-
|
|
83
|
-
const updatedItem = {
|
|
84
|
-
...makeItem('different-local-id', 't1'),
|
|
85
|
-
external_item_id: 'ext-local-i1',
|
|
86
|
-
data: { text: 'updated' },
|
|
87
|
-
};
|
|
88
|
-
useStore.getState().onItemStarted('s1', 't1', updatedItem);
|
|
89
|
-
|
|
90
|
-
const updated = useStore.getState().sessionDetails['s1'];
|
|
91
|
-
expect(updated.turns[0].items).toHaveLength(1);
|
|
92
|
-
expect(updated.turns[0].items[0].id).toBe('different-local-id');
|
|
93
|
-
expect(updated.turns[0].items[0].data).toEqual({ text: 'updated' });
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('submitPrompt', () => {
|
|
98
|
-
beforeEach(() => {
|
|
99
|
-
vi.clearAllMocks();
|
|
100
|
-
resetStore();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('sets submittingPrompt and marks session as running', async () => {
|
|
104
|
-
const detail = makeDetail('s1', []);
|
|
105
|
-
resetStore({ activeSessionId: 's1', sessionDetails: { s1: detail }, sessions: [makeSession('s1')] });
|
|
106
|
-
vi.mocked(submitPrompt).mockResolvedValue(makeTurn('t1', 's1', { status: 'pending', user_prompt: 'hello' }));
|
|
107
|
-
|
|
108
|
-
await useStore.getState().submitPrompt('hello');
|
|
109
|
-
|
|
110
|
-
const state = useStore.getState();
|
|
111
|
-
expect(state.submittingPrompt).toBeNull();
|
|
112
|
-
expect(state.sessionDetails['s1'].is_running).toBe(1);
|
|
113
|
-
expect(state.sessionDetails['s1'].status).toBe('running');
|
|
114
|
-
expect(state.sessionDetails['s1'].turns).toHaveLength(1);
|
|
115
|
-
expect(state.sessionDetails['s1'].turns[0].user_prompt).toBe('hello');
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('reverts running state on error', async () => {
|
|
119
|
-
const detail = makeDetail('s1', []);
|
|
120
|
-
resetStore({ activeSessionId: 's1', sessionDetails: { s1: detail }, sessions: [makeSession('s1')] });
|
|
121
|
-
vi.mocked(submitPrompt).mockRejectedValue(new Error('Network error'));
|
|
122
|
-
|
|
123
|
-
await useStore.getState().submitPrompt('hello');
|
|
124
|
-
|
|
125
|
-
const state = useStore.getState();
|
|
126
|
-
expect(state.submittingPrompt).toBeNull();
|
|
127
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
128
|
-
expect(state.sessionDetails['s1'].status).toBe('active');
|
|
129
|
-
expect(state.error).toBe('Network error');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('does nothing when no active session', async () => {
|
|
133
|
-
resetStore({ activeSessionId: null });
|
|
134
|
-
await useStore.getState().submitPrompt('hello');
|
|
135
|
-
expect(submitPrompt).not.toHaveBeenCalled();
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe('cancelTurn', () => {
|
|
140
|
-
beforeEach(() => {
|
|
141
|
-
vi.clearAllMocks();
|
|
142
|
-
resetStore();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('calls apiCancelTurn with active session id', async () => {
|
|
146
|
-
resetStore({ activeSessionId: 's1' });
|
|
147
|
-
vi.mocked(cancelTurn).mockResolvedValue({ success: true });
|
|
148
|
-
|
|
149
|
-
await useStore.getState().cancelTurn();
|
|
150
|
-
|
|
151
|
-
expect(cancelTurn).toHaveBeenCalledWith('s1');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('does nothing when no active session', async () => {
|
|
155
|
-
resetStore({ activeSessionId: null });
|
|
156
|
-
await useStore.getState().cancelTurn();
|
|
157
|
-
expect(cancelTurn).not.toHaveBeenCalled();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('onTurnCancelled', () => {
|
|
162
|
-
beforeEach(() => {
|
|
163
|
-
vi.clearAllMocks();
|
|
164
|
-
resetStore();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('removes the cancelled turn and restores prompt', () => {
|
|
168
|
-
const turn = makeTurn('t1', 's1', { user_prompt: 'my prompt', status: 'running' });
|
|
169
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
170
|
-
resetStore({
|
|
171
|
-
activeSessionId: 's1',
|
|
172
|
-
sessionDetails: { s1: detail },
|
|
173
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
174
|
-
activeTurnIndex: 0,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
useStore.getState().onTurnCancelled('s1', 't1');
|
|
178
|
-
|
|
179
|
-
const state = useStore.getState();
|
|
180
|
-
expect(state.sessionDetails['s1'].turns).toHaveLength(0);
|
|
181
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
182
|
-
expect(state.sessionDetails['s1'].status).toBe('active');
|
|
183
|
-
expect(state.restoredPrompt).toBe('my prompt');
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe('selectSession', () => {
|
|
188
|
-
beforeEach(() => {
|
|
189
|
-
vi.clearAllMocks();
|
|
190
|
-
resetStore();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('uses cached detail without fetching', async () => {
|
|
194
|
-
const detail = makeDetail('s1', [makeTurn('t1', 's1')]);
|
|
195
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
196
|
-
|
|
197
|
-
await useStore.getState().selectSession('s1');
|
|
198
|
-
|
|
199
|
-
expect(fetchSessionDetail).not.toHaveBeenCalled();
|
|
200
|
-
expect(useStore.getState().activeSessionId).toBe('s1');
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it('fetches detail on cache miss', async () => {
|
|
204
|
-
const detail = makeDetail('s1', [makeTurn('t1', 's1')]);
|
|
205
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(detail);
|
|
206
|
-
await useStore.getState().selectSession('s1');
|
|
207
|
-
|
|
208
|
-
expect(fetchSessionDetail).toHaveBeenCalledWith('s1');
|
|
209
|
-
expect(useStore.getState().sessionDetails['s1']).toEqual(detail);
|
|
210
|
-
expect(useStore.getState().activeSessionId).toBe('s1');
|
|
211
|
-
expect(useStore.getState().loading).toBe(false);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('clears has_unreviewed when set', async () => {
|
|
215
|
-
const detail = makeDetail('s1', [], { has_unreviewed: 1 });
|
|
216
|
-
resetStore({ sessionDetails: { s1: detail }, sessions: [makeSession('s1', { has_unreviewed: 1 })] });
|
|
217
|
-
vi.mocked(clearUnreviewed).mockResolvedValue(makeSession('s1'));
|
|
218
|
-
|
|
219
|
-
await useStore.getState().selectSession('s1');
|
|
220
|
-
|
|
221
|
-
expect(clearUnreviewed).toHaveBeenCalledWith('s1');
|
|
222
|
-
expect(useStore.getState().sessionDetails['s1'].has_unreviewed).toBe(0);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe('closeTab', () => {
|
|
227
|
-
beforeEach(() => {
|
|
228
|
-
vi.clearAllMocks();
|
|
229
|
-
resetStore();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('removes tab and switches active to last remaining', () => {
|
|
233
|
-
resetStore({
|
|
234
|
-
openTabs: ['s1', 's2', 's3'],
|
|
235
|
-
activeSessionId: 's2',
|
|
236
|
-
sessionDetails: { s3: makeDetail('s3', [makeTurn('t1', 's3')]) },
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
useStore.getState().closeTab('s2');
|
|
240
|
-
|
|
241
|
-
const state = useStore.getState();
|
|
242
|
-
expect(state.openTabs).toEqual(['s1', 's3']);
|
|
243
|
-
expect(state.activeSessionId).toBe('s3');
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('sets activeSessionId to null when closing last tab', () => {
|
|
247
|
-
resetStore({ openTabs: ['s1'], activeSessionId: 's1' });
|
|
248
|
-
|
|
249
|
-
useStore.getState().closeTab('s1');
|
|
250
|
-
|
|
251
|
-
const state = useStore.getState();
|
|
252
|
-
expect(state.openTabs).toEqual([]);
|
|
253
|
-
expect(state.activeSessionId).toBeNull();
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
describe('deleteSession', () => {
|
|
258
|
-
beforeEach(() => {
|
|
259
|
-
vi.clearAllMocks();
|
|
260
|
-
resetStore();
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('removes session from sessions, sessionDetails, and openTabs', async () => {
|
|
264
|
-
const detail = makeDetail('s1', []);
|
|
265
|
-
const detail2 = makeDetail('s2', [makeTurn('t1', 's2')]);
|
|
266
|
-
resetStore({
|
|
267
|
-
sessions: [makeSession('s1'), makeSession('s2')],
|
|
268
|
-
sessionDetails: { s1: detail, s2: detail2 },
|
|
269
|
-
openTabs: ['s1', 's2'],
|
|
270
|
-
activeSessionId: 's1',
|
|
271
|
-
});
|
|
272
|
-
vi.mocked(cancelTurn).mockResolvedValue({ success: true });
|
|
273
|
-
vi.mocked(apiDeleteSession).mockResolvedValue({ success: true });
|
|
274
|
-
|
|
275
|
-
await useStore.getState().deleteSession('s1');
|
|
276
|
-
|
|
277
|
-
const state = useStore.getState();
|
|
278
|
-
expect(state.sessions).toHaveLength(1);
|
|
279
|
-
expect(state.sessions[0].id).toBe('s2');
|
|
280
|
-
expect(state.sessionDetails['s1']).toBeUndefined();
|
|
281
|
-
expect(state.openTabs).toEqual(['s2']);
|
|
282
|
-
expect(state.activeSessionId).toBe('s2');
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// === New tests: WebSocket event handlers ===
|
|
287
|
-
|
|
288
|
-
describe('onTurnStarted', () => {
|
|
289
|
-
beforeEach(() => {
|
|
290
|
-
vi.clearAllMocks();
|
|
291
|
-
resetStore();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('sets session and turn to running state', () => {
|
|
295
|
-
const turn = makeTurn('t1', 's1', { status: 'pending' });
|
|
296
|
-
const detail = makeDetail('s1', [turn], { is_running: 0, status: 'active' });
|
|
297
|
-
resetStore({
|
|
298
|
-
activeSessionId: 's1',
|
|
299
|
-
sessionDetails: { s1: detail },
|
|
300
|
-
sessions: [makeSession('s1', { is_running: 0, status: 'active' })],
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
useStore.getState().onTurnStarted('s1', 't1');
|
|
304
|
-
|
|
305
|
-
const state = useStore.getState();
|
|
306
|
-
expect(state.sessionDetails['s1'].is_running).toBe(1);
|
|
307
|
-
expect(state.sessionDetails['s1'].status).toBe('running');
|
|
308
|
-
expect(state.sessionDetails['s1'].turns[0].status).toBe('running');
|
|
309
|
-
expect(state.sessions[0].is_running).toBe(1);
|
|
310
|
-
expect(state.sessions[0].status).toBe('running');
|
|
311
|
-
expect(state.activeTurnIndex).toBe(0);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it('does nothing when session detail not found', () => {
|
|
315
|
-
resetStore({ sessionDetails: {} });
|
|
316
|
-
useStore.getState().onTurnStarted('s1', 't1');
|
|
317
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
describe('onItemUpdated', () => {
|
|
322
|
-
beforeEach(() => {
|
|
323
|
-
vi.clearAllMocks();
|
|
324
|
-
resetStore();
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it('updates existing item data via upsertItem', () => {
|
|
328
|
-
const existingItem = makeItem('i1', 't1', 'command_execution');
|
|
329
|
-
const turn = makeTurn('t1', 's1', { items: [existingItem] });
|
|
330
|
-
const detail = makeDetail('s1', [turn]);
|
|
331
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
332
|
-
|
|
333
|
-
const updatedItem = {
|
|
334
|
-
...makeItem('i2', 't1', 'command_execution'),
|
|
335
|
-
external_item_id: 'ext-i1',
|
|
336
|
-
data: { command: 'ls -la', output: 'done' },
|
|
337
|
-
};
|
|
338
|
-
useStore.getState().onItemUpdated('s1', 't1', updatedItem);
|
|
339
|
-
|
|
340
|
-
const items = useStore.getState().sessionDetails['s1'].turns[0].items;
|
|
341
|
-
expect(items).toHaveLength(1);
|
|
342
|
-
expect(items[0].id).toBe('i2'); // uses WS event id (real DB id)
|
|
343
|
-
expect(items[0].data).toEqual({ command: 'ls -la', output: 'done' });
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('does nothing when session detail not found', () => {
|
|
347
|
-
resetStore({ sessionDetails: {} });
|
|
348
|
-
useStore.getState().onItemUpdated('s1', 't1', makeItem('i1', 't1'));
|
|
349
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
describe('onItemCompleted', () => {
|
|
354
|
-
beforeEach(() => {
|
|
355
|
-
vi.clearAllMocks();
|
|
356
|
-
resetStore();
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('updates item and sets agent_response for agent_message type', () => {
|
|
360
|
-
const turn = makeTurn('t1', 's1', { agent_response: null });
|
|
361
|
-
const detail = makeDetail('s1', [turn]);
|
|
362
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
363
|
-
|
|
364
|
-
const item = makeItem('i1', 't1', 'agent_message');
|
|
365
|
-
item.data = { text: 'Task completed successfully' };
|
|
366
|
-
useStore.getState().onItemCompleted('s1', 't1', item);
|
|
367
|
-
|
|
368
|
-
const state = useStore.getState();
|
|
369
|
-
expect(state.sessionDetails['s1'].turns[0].agent_response).toBe('Task completed successfully');
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it('appends to thoughts for reasoning type', () => {
|
|
373
|
-
const turn = makeTurn('t1', 's1', { thoughts: 'First thought' });
|
|
374
|
-
const detail = makeDetail('s1', [turn]);
|
|
375
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
376
|
-
|
|
377
|
-
const item = makeItem('i1', 't1', 'reasoning');
|
|
378
|
-
item.data = { text: 'Second thought' };
|
|
379
|
-
useStore.getState().onItemCompleted('s1', 't1', item);
|
|
380
|
-
|
|
381
|
-
const state = useStore.getState();
|
|
382
|
-
expect(state.sessionDetails['s1'].turns[0].thoughts).toBe('First thought\nSecond thought');
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('sets thoughts for reasoning when previously null', () => {
|
|
386
|
-
const turn = makeTurn('t1', 's1', { thoughts: null });
|
|
387
|
-
const detail = makeDetail('s1', [turn]);
|
|
388
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
389
|
-
|
|
390
|
-
const item = makeItem('i1', 't1', 'reasoning');
|
|
391
|
-
item.data = { text: 'Initial thought' };
|
|
392
|
-
useStore.getState().onItemCompleted('s1', 't1', item);
|
|
393
|
-
|
|
394
|
-
expect(useStore.getState().sessionDetails['s1'].turns[0].thoughts).toBe('Initial thought');
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('does nothing when session detail not found', () => {
|
|
398
|
-
resetStore({ sessionDetails: {} });
|
|
399
|
-
useStore.getState().onItemCompleted('s1', 't1', makeItem('i1', 't1'));
|
|
400
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
describe('onTurnCompleted', () => {
|
|
405
|
-
beforeEach(() => {
|
|
406
|
-
vi.clearAllMocks();
|
|
407
|
-
resetStore();
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
it('sets turn to completed with usage and clears running state', () => {
|
|
411
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
412
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
413
|
-
resetStore({
|
|
414
|
-
sessionDetails: { s1: detail },
|
|
415
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
const usage = makeUsage({ input_tokens: 500, output_tokens: 1000 });
|
|
419
|
-
useStore.getState().onTurnCompleted('s1', 't1', usage);
|
|
420
|
-
|
|
421
|
-
const state = useStore.getState();
|
|
422
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
423
|
-
expect(state.sessionDetails['s1'].status).toBe('active');
|
|
424
|
-
expect(state.sessionDetails['s1'].turns[0].status).toBe('completed');
|
|
425
|
-
expect(state.sessionDetails['s1'].turns[0].token_usage).toEqual(usage);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it('sets has_unreviewed when hasUnreviewed=true', () => {
|
|
429
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
430
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, has_unreviewed: 0 });
|
|
431
|
-
resetStore({
|
|
432
|
-
sessionDetails: { s1: detail },
|
|
433
|
-
sessions: [makeSession('s1', { is_running: 1, has_unreviewed: 0 })],
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
useStore.getState().onTurnCompleted('s1', 't1', makeUsage(), true);
|
|
437
|
-
|
|
438
|
-
expect(useStore.getState().sessionDetails['s1'].has_unreviewed).toBe(1);
|
|
439
|
-
expect(useStore.getState().sessions[0].has_unreviewed).toBe(1);
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it('does not change has_unreviewed when hasUnreviewed is falsy', () => {
|
|
443
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
444
|
-
const detail = makeDetail('s1', [turn], { has_unreviewed: 1 });
|
|
445
|
-
resetStore({
|
|
446
|
-
sessionDetails: { s1: detail },
|
|
447
|
-
sessions: [makeSession('s1', { has_unreviewed: 1 })],
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
useStore.getState().onTurnCompleted('s1', 't1', makeUsage(), false);
|
|
451
|
-
|
|
452
|
-
expect(useStore.getState().sessionDetails['s1'].has_unreviewed).toBe(1);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it('does nothing when session detail not found', () => {
|
|
456
|
-
resetStore({ sessionDetails: {} });
|
|
457
|
-
useStore.getState().onTurnCompleted('s1', 't1', makeUsage());
|
|
458
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
it('handles undefined usage without crashing', () => {
|
|
462
|
-
const turn = makeTurn('t1', 's1', { status: 'running', token_usage: null });
|
|
463
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
464
|
-
resetStore({
|
|
465
|
-
sessionDetails: { s1: detail },
|
|
466
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
// Simulate real app-server: turn:completed broadcast WITHOUT usage
|
|
470
|
-
useStore.getState().onTurnCompleted('s1', 't1', undefined);
|
|
471
|
-
|
|
472
|
-
const state = useStore.getState();
|
|
473
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
474
|
-
expect(state.sessionDetails['s1'].status).toBe('active');
|
|
475
|
-
expect(state.sessionDetails['s1'].turns[0].status).toBe('completed');
|
|
476
|
-
// When usage is undefined, existing token_usage is preserved (may have been set by onTokenUsageUpdated)
|
|
477
|
-
expect(state.sessionDetails['s1'].turns[0].token_usage).toBeNull();
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it('preserves existing token_usage when usage is undefined', () => {
|
|
481
|
-
const existingUsage = makeUsage({ input_tokens: 500, output_tokens: 1000 });
|
|
482
|
-
const turn = makeTurn('t1', 's1', { status: 'running', token_usage: existingUsage });
|
|
483
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
484
|
-
resetStore({
|
|
485
|
-
sessionDetails: { s1: detail },
|
|
486
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
// Simulate real app-server: turn:completed broadcast WITHOUT usage
|
|
490
|
-
// but token_usage was already set by thread/tokenUsage/updated handler
|
|
491
|
-
useStore.getState().onTurnCompleted('s1', 't1', undefined);
|
|
492
|
-
|
|
493
|
-
const state = useStore.getState();
|
|
494
|
-
expect(state.sessionDetails['s1'].turns[0].token_usage).toEqual(existingUsage);
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
it('handles null usage without crashing', () => {
|
|
498
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
499
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
500
|
-
resetStore({
|
|
501
|
-
sessionDetails: { s1: detail },
|
|
502
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
useStore.getState().onTurnCompleted('s1', 't1', null);
|
|
506
|
-
|
|
507
|
-
const state = useStore.getState();
|
|
508
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
509
|
-
expect(state.sessionDetails['s1'].turns[0].token_usage).toBeNull();
|
|
510
|
-
});
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
describe('onItemDelta', () => {
|
|
514
|
-
beforeEach(() => {
|
|
515
|
-
vi.clearAllMocks();
|
|
516
|
-
resetStore();
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
it('appends delta to existing agent_message item text', () => {
|
|
520
|
-
const item = makeItem('i1', 't1', 'agent_message');
|
|
521
|
-
item.data = { text: 'Hello' };
|
|
522
|
-
const turn = makeTurn('t1', 's1', { items: [item], agent_response: 'Hello' });
|
|
523
|
-
const detail = makeDetail('s1', [turn]);
|
|
524
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
525
|
-
|
|
526
|
-
useStore.getState().onItemDelta('s1', 't1', 'ext-i1', ' world');
|
|
527
|
-
|
|
528
|
-
const state = useStore.getState();
|
|
529
|
-
expect(state.sessionDetails['s1'].turns[0].items[0].data).toEqual({ text: 'Hello world' });
|
|
530
|
-
expect(state.sessionDetails['s1'].turns[0].agent_response).toBe('Hello world');
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
it('creates new in-progress agent_message item when item not found', () => {
|
|
534
|
-
const turn = makeTurn('t1', 's1', { items: [] });
|
|
535
|
-
const detail = makeDetail('s1', [turn]);
|
|
536
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
537
|
-
|
|
538
|
-
useStore.getState().onItemDelta('s1', 't1', 'ext-new-item', 'Hello');
|
|
539
|
-
|
|
540
|
-
const state = useStore.getState();
|
|
541
|
-
expect(state.sessionDetails['s1'].turns[0].items).toHaveLength(1);
|
|
542
|
-
expect(state.sessionDetails['s1'].turns[0].items[0].type).toBe('agent_message');
|
|
543
|
-
expect(state.sessionDetails['s1'].turns[0].items[0].status).toBe('in_progress');
|
|
544
|
-
expect(state.sessionDetails['s1'].turns[0].items[0].data).toEqual({ text: 'Hello' });
|
|
545
|
-
expect(state.sessionDetails['s1'].turns[0].items[0].external_item_id).toBe('ext-new-item');
|
|
546
|
-
expect(state.sessionDetails['s1'].turns[0].agent_response).toBe('Hello');
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
it('accumulates multiple deltas correctly', () => {
|
|
550
|
-
const turn = makeTurn('t1', 's1', { items: [] });
|
|
551
|
-
const detail = makeDetail('s1', [turn]);
|
|
552
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
553
|
-
|
|
554
|
-
useStore.getState().onItemDelta('s1', 't1', 'ext-d1', 'Hello');
|
|
555
|
-
useStore.getState().onItemDelta('s1', 't1', 'ext-d1', ' there');
|
|
556
|
-
useStore.getState().onItemDelta('s1', 't1', 'ext-d1', '!');
|
|
557
|
-
|
|
558
|
-
const state = useStore.getState();
|
|
559
|
-
expect(state.sessionDetails['s1'].turns[0].items).toHaveLength(1);
|
|
560
|
-
expect(state.sessionDetails['s1'].turns[0].items[0].data).toEqual({ text: 'Hello there!' });
|
|
561
|
-
expect(state.sessionDetails['s1'].turns[0].agent_response).toBe('Hello there!');
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
it('does nothing when session detail not found', () => {
|
|
565
|
-
resetStore({ sessionDetails: {} });
|
|
566
|
-
useStore.getState().onItemDelta('s1', 't1', 'ext-i1', 'Hello');
|
|
567
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
describe('onTokenUsageUpdated', () => {
|
|
572
|
-
beforeEach(() => {
|
|
573
|
-
vi.clearAllMocks();
|
|
574
|
-
resetStore();
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
it('sets token_usage on matching turn', () => {
|
|
578
|
-
const turn = makeTurn('t1', 's1', { token_usage: null, status: 'running' });
|
|
579
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
580
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
581
|
-
|
|
582
|
-
const usage = makeUsage({ input_tokens: 500, output_tokens: 1000 });
|
|
583
|
-
useStore.getState().onTokenUsageUpdated('s1', 't1', usage);
|
|
584
|
-
|
|
585
|
-
expect(useStore.getState().sessionDetails['s1'].turns[0].token_usage).toEqual(usage);
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
it('overwrites previously null token_usage', () => {
|
|
589
|
-
const turn = makeTurn('t1', 's1', { token_usage: null });
|
|
590
|
-
const detail = makeDetail('s1', [turn]);
|
|
591
|
-
resetStore({ sessionDetails: { s1: detail } });
|
|
592
|
-
|
|
593
|
-
const usage = makeUsage({ input_tokens: 200, output_tokens: 300 });
|
|
594
|
-
useStore.getState().onTokenUsageUpdated('s1', 't1', usage);
|
|
595
|
-
|
|
596
|
-
expect(useStore.getState().sessionDetails['s1'].turns[0].token_usage).toEqual(usage);
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
it('does nothing when session detail not found', () => {
|
|
600
|
-
resetStore({ sessionDetails: {} });
|
|
601
|
-
useStore.getState().onTokenUsageUpdated('s1', 't1', makeUsage());
|
|
602
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
describe('onTurnFailed', () => {
|
|
607
|
-
beforeEach(() => {
|
|
608
|
-
vi.clearAllMocks();
|
|
609
|
-
resetStore();
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
it('sets turn to failed with error message', () => {
|
|
613
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
614
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
615
|
-
resetStore({
|
|
616
|
-
sessionDetails: { s1: detail },
|
|
617
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
useStore.getState().onTurnFailed('s1', 't1', 'Something went wrong');
|
|
621
|
-
|
|
622
|
-
const state = useStore.getState();
|
|
623
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
624
|
-
expect(state.sessionDetails['s1'].status).toBe('failed');
|
|
625
|
-
expect(state.sessionDetails['s1'].turns[0].status).toBe('failed');
|
|
626
|
-
expect(state.sessionDetails['s1'].turns[0].error).toBe('Something went wrong');
|
|
627
|
-
expect(state.sessions[0].status).toBe('failed');
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
it('sets status to aborted when error contains "cancelled"', () => {
|
|
631
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
632
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
633
|
-
resetStore({
|
|
634
|
-
sessionDetails: { s1: detail },
|
|
635
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
useStore.getState().onTurnFailed('s1', 't1', 'The operation was cancelled by user');
|
|
639
|
-
|
|
640
|
-
const state = useStore.getState();
|
|
641
|
-
expect(state.sessionDetails['s1'].status).toBe('active');
|
|
642
|
-
expect(state.sessionDetails['s1'].turns[0].status).toBe('aborted');
|
|
643
|
-
expect(state.sessions[0].status).toBe('active');
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
it('sets status to aborted when error contains "aborted"', () => {
|
|
647
|
-
const turn = makeTurn('t1', 's1', { status: 'running' });
|
|
648
|
-
const detail = makeDetail('s1', [turn], { is_running: 1, status: 'running' });
|
|
649
|
-
resetStore({
|
|
650
|
-
sessionDetails: { s1: detail },
|
|
651
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
useStore.getState().onTurnFailed('s1', 't1', 'Turn aborted');
|
|
655
|
-
|
|
656
|
-
const state = useStore.getState();
|
|
657
|
-
expect(state.sessionDetails['s1'].turns[0].status).toBe('aborted');
|
|
658
|
-
expect(state.sessionDetails['s1'].status).toBe('active');
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
it('does nothing when session detail not found', () => {
|
|
662
|
-
resetStore({ sessionDetails: {} });
|
|
663
|
-
useStore.getState().onTurnFailed('s1', 't1', 'error');
|
|
664
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
665
|
-
});
|
|
666
|
-
});
|
|
667
|
-
|
|
668
|
-
describe('onSessionTitle', () => {
|
|
669
|
-
beforeEach(() => {
|
|
670
|
-
vi.clearAllMocks();
|
|
671
|
-
resetStore();
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
it('updates title in sessions array', () => {
|
|
675
|
-
resetStore({ sessions: [makeSession('s1', { title: null })] });
|
|
676
|
-
useStore.getState().onSessionTitle('s1', 'New Title');
|
|
677
|
-
expect(useStore.getState().sessions[0].title).toBe('New Title');
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
it('updates title in sessionDetails when cached', () => {
|
|
681
|
-
const detail = makeDetail('s1', [], { title: null });
|
|
682
|
-
resetStore({ sessions: [makeSession('s1')], sessionDetails: { s1: detail } });
|
|
683
|
-
useStore.getState().onSessionTitle('s1', 'New Title');
|
|
684
|
-
expect(useStore.getState().sessionDetails['s1'].title).toBe('New Title');
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
it('does not add sessionDetails when not cached', () => {
|
|
688
|
-
resetStore({ sessions: [makeSession('s1')], sessionDetails: {} });
|
|
689
|
-
useStore.getState().onSessionTitle('s1', 'New Title');
|
|
690
|
-
expect(useStore.getState().sessionDetails['s1']).toBeUndefined();
|
|
691
|
-
});
|
|
692
|
-
});
|
|
693
|
-
|
|
694
|
-
// === New tests: REST actions ===
|
|
695
|
-
|
|
696
|
-
describe('createSession', () => {
|
|
697
|
-
beforeEach(() => {
|
|
698
|
-
vi.clearAllMocks();
|
|
699
|
-
resetStore();
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
it('creates session, adds to list, and selects it', async () => {
|
|
703
|
-
const newSession = makeSession('s1', { title: 'Test Session' });
|
|
704
|
-
vi.mocked(apiCreateSession).mockResolvedValue(newSession);
|
|
705
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', []));
|
|
706
|
-
|
|
707
|
-
await useStore.getState().createSession({ title: 'Test Session' });
|
|
708
|
-
|
|
709
|
-
const state = useStore.getState();
|
|
710
|
-
expect(apiCreateSession).toHaveBeenCalledWith({ title: 'Test Session' });
|
|
711
|
-
expect(state.sessions[0].id).toBe('s1');
|
|
712
|
-
expect(state.showNewSessionDialog).toBe(false);
|
|
713
|
-
expect(state.activeSessionId).toBe('s1');
|
|
714
|
-
expect(state.lastModelConfig).toEqual({ provider: 'codex', model: '', reasoning: '' });
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
it('shows error toast on failure', async () => {
|
|
718
|
-
vi.mocked(apiCreateSession).mockRejectedValue(new Error('API error'));
|
|
719
|
-
await useStore.getState().createSession({ title: 'Test' });
|
|
720
|
-
const state = useStore.getState();
|
|
721
|
-
expect(state.error).toBe('API error');
|
|
722
|
-
expect(state.toasts).toHaveLength(1);
|
|
723
|
-
expect(state.toasts[0].type).toBe('error');
|
|
724
|
-
});
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
describe('renameSession', () => {
|
|
728
|
-
beforeEach(() => {
|
|
729
|
-
vi.clearAllMocks();
|
|
730
|
-
resetStore();
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
it('updates session title in sessions and sessionDetails', async () => {
|
|
734
|
-
const detail = makeDetail('s1', []);
|
|
735
|
-
resetStore({
|
|
736
|
-
sessions: [makeSession('s1', { title: 'Old' })],
|
|
737
|
-
sessionDetails: { s1: detail },
|
|
738
|
-
});
|
|
739
|
-
vi.mocked(apiRenameSession).mockResolvedValue(makeSession('s1', { title: 'New' }));
|
|
740
|
-
|
|
741
|
-
await useStore.getState().renameSession('s1', 'New');
|
|
742
|
-
|
|
743
|
-
const state = useStore.getState();
|
|
744
|
-
expect(apiRenameSession).toHaveBeenCalledWith('s1', 'New');
|
|
745
|
-
expect(state.sessions[0].title).toBe('New');
|
|
746
|
-
expect(state.sessionDetails['s1'].title).toBe('New');
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
it('shows error toast on failure', async () => {
|
|
750
|
-
vi.mocked(apiRenameSession).mockRejectedValue(new Error('Rename failed'));
|
|
751
|
-
await useStore.getState().renameSession('s1', 'New');
|
|
752
|
-
expect(useStore.getState().error).toBe('Rename failed');
|
|
753
|
-
});
|
|
754
|
-
});
|
|
755
|
-
|
|
756
|
-
describe('markFinished', () => {
|
|
757
|
-
beforeEach(() => {
|
|
758
|
-
vi.clearAllMocks();
|
|
759
|
-
resetStore();
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
it('updates lifecycle to finished', async () => {
|
|
763
|
-
resetStore({ sessions: [makeSession('s1', { lifecycle: 'working' })] });
|
|
764
|
-
vi.mocked(apiMarkFinished).mockResolvedValue(makeSession('s1', { lifecycle: 'finished' }));
|
|
765
|
-
|
|
766
|
-
await useStore.getState().markFinished('s1');
|
|
767
|
-
|
|
768
|
-
expect(apiMarkFinished).toHaveBeenCalledWith('s1');
|
|
769
|
-
expect(useStore.getState().sessions[0].lifecycle).toBe('finished');
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
it('shows error toast on failure', async () => {
|
|
773
|
-
vi.mocked(apiMarkFinished).mockRejectedValue(new Error('Failed'));
|
|
774
|
-
await useStore.getState().markFinished('s1');
|
|
775
|
-
expect(useStore.getState().error).toBe('Failed');
|
|
776
|
-
});
|
|
777
|
-
});
|
|
778
|
-
|
|
779
|
-
describe('reopenSession', () => {
|
|
780
|
-
beforeEach(() => {
|
|
781
|
-
vi.clearAllMocks();
|
|
782
|
-
resetStore();
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
it('updates lifecycle to working', async () => {
|
|
786
|
-
resetStore({ sessions: [makeSession('s1', { lifecycle: 'finished' })] });
|
|
787
|
-
vi.mocked(apiReopenSession).mockResolvedValue(makeSession('s1', { lifecycle: 'working' }));
|
|
788
|
-
|
|
789
|
-
await useStore.getState().reopenSession('s1');
|
|
790
|
-
|
|
791
|
-
expect(apiReopenSession).toHaveBeenCalledWith('s1');
|
|
792
|
-
expect(useStore.getState().sessions[0].lifecycle).toBe('working');
|
|
793
|
-
});
|
|
794
|
-
|
|
795
|
-
it('shows error toast on failure', async () => {
|
|
796
|
-
vi.mocked(apiReopenSession).mockRejectedValue(new Error('Failed'));
|
|
797
|
-
await useStore.getState().reopenSession('s1');
|
|
798
|
-
expect(useStore.getState().error).toBe('Failed');
|
|
799
|
-
});
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
describe('rewindToTurn', () => {
|
|
803
|
-
beforeEach(() => {
|
|
804
|
-
vi.clearAllMocks();
|
|
805
|
-
resetStore();
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
it('calls api rewind and refreshes detail', async () => {
|
|
809
|
-
const turn1 = makeTurn('t1', 's1');
|
|
810
|
-
const turn2 = makeTurn('t2', 's1');
|
|
811
|
-
const detail = makeDetail('s1', [turn1, turn2], { external_thread_id: 'ext-1', is_running: 1 });
|
|
812
|
-
resetStore({
|
|
813
|
-
sessions: [makeSession('s1', { external_thread_id: 'ext-1', is_running: 1, status: 'running' })],
|
|
814
|
-
sessionDetails: { s1: detail },
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
vi.mocked(apiRewindSession).mockResolvedValue(makeSession('s1', { external_thread_id: null }));
|
|
818
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', [turn1], { external_thread_id: null }));
|
|
819
|
-
|
|
820
|
-
await useStore.getState().rewindToTurn('s1', 't1');
|
|
821
|
-
|
|
822
|
-
const state = useStore.getState();
|
|
823
|
-
expect(apiRewindSession).toHaveBeenCalledWith('s1', 't1');
|
|
824
|
-
expect(fetchSessionDetail).toHaveBeenCalledWith('s1');
|
|
825
|
-
expect(state.sessionDetails['s1'].turns).toHaveLength(1);
|
|
826
|
-
expect(state.sessions[0].external_thread_id).toBeNull();
|
|
827
|
-
expect(state.sessions[0].is_running).toBe(0);
|
|
828
|
-
expect(state.activeTurnIndex).toBe(0);
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
it('shows error toast on failure', async () => {
|
|
832
|
-
vi.mocked(apiRewindSession).mockRejectedValue(new Error('Rewind failed'));
|
|
833
|
-
await useStore.getState().rewindToTurn('s1', 't1');
|
|
834
|
-
expect(useStore.getState().error).toBe('Rewind failed');
|
|
835
|
-
});
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
describe('branchFromTurn', () => {
|
|
839
|
-
beforeEach(() => {
|
|
840
|
-
vi.clearAllMocks();
|
|
841
|
-
resetStore();
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
it('creates branched session and selects it', async () => {
|
|
845
|
-
const newSession = makeSession('s2', { title: 'Branched' });
|
|
846
|
-
resetStore({ sessions: [makeSession('s1')] });
|
|
847
|
-
vi.mocked(apiBranchSession).mockResolvedValue(newSession);
|
|
848
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s2', []));
|
|
849
|
-
|
|
850
|
-
await useStore.getState().branchFromTurn('s1', 't1');
|
|
851
|
-
|
|
852
|
-
const state = useStore.getState();
|
|
853
|
-
expect(apiBranchSession).toHaveBeenCalledWith('s1', 't1', undefined);
|
|
854
|
-
expect(state.sessions[0].id).toBe('s2'); // prepended
|
|
855
|
-
expect(state.activeSessionId).toBe('s2');
|
|
856
|
-
});
|
|
857
|
-
|
|
858
|
-
it('passes title when provided', async () => {
|
|
859
|
-
const newSession = makeSession('s2', { title: 'Custom Branch' });
|
|
860
|
-
vi.mocked(apiBranchSession).mockResolvedValue(newSession);
|
|
861
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s2', []));
|
|
862
|
-
|
|
863
|
-
await useStore.getState().branchFromTurn('s1', 't1', 'Custom Branch');
|
|
864
|
-
|
|
865
|
-
expect(apiBranchSession).toHaveBeenCalledWith('s1', 't1', 'Custom Branch');
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
it('shows error toast on failure', async () => {
|
|
869
|
-
vi.mocked(apiBranchSession).mockRejectedValue(new Error('Branch failed'));
|
|
870
|
-
await useStore.getState().branchFromTurn('s1', 't1');
|
|
871
|
-
expect(useStore.getState().error).toBe('Branch failed');
|
|
872
|
-
});
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
describe('refreshActiveSession', () => {
|
|
876
|
-
beforeEach(() => {
|
|
877
|
-
vi.clearAllMocks();
|
|
878
|
-
resetStore();
|
|
879
|
-
});
|
|
880
|
-
|
|
881
|
-
it('re-fetches and updates session detail', async () => {
|
|
882
|
-
const oldDetail = makeDetail('s1', [makeTurn('t1', 's1')], { is_running: 1, status: 'running' });
|
|
883
|
-
const newDetail = makeDetail('s1', [makeTurn('t1', 's1'), makeTurn('t2', 's1')], { is_running: 0, status: 'active' });
|
|
884
|
-
resetStore({
|
|
885
|
-
activeSessionId: 's1',
|
|
886
|
-
sessionDetails: { s1: oldDetail },
|
|
887
|
-
sessions: [makeSession('s1', { is_running: 1, status: 'running' })],
|
|
888
|
-
activeTurnIndex: 0,
|
|
889
|
-
});
|
|
890
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(newDetail);
|
|
891
|
-
|
|
892
|
-
await useStore.getState().refreshActiveSession();
|
|
893
|
-
|
|
894
|
-
const state = useStore.getState();
|
|
895
|
-
expect(fetchSessionDetail).toHaveBeenCalledWith('s1');
|
|
896
|
-
expect(state.sessionDetails['s1'].turns).toHaveLength(2);
|
|
897
|
-
expect(state.sessionDetails['s1'].is_running).toBe(0);
|
|
898
|
-
expect(state.sessions[0].is_running).toBe(0);
|
|
899
|
-
expect(state.sessions[0].status).toBe('active');
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
it('does nothing when no active session', async () => {
|
|
903
|
-
resetStore({ activeSessionId: null });
|
|
904
|
-
await useStore.getState().refreshActiveSession();
|
|
905
|
-
expect(fetchSessionDetail).not.toHaveBeenCalled();
|
|
906
|
-
});
|
|
907
|
-
|
|
908
|
-
it('sets error on failure', async () => {
|
|
909
|
-
resetStore({ activeSessionId: 's1' });
|
|
910
|
-
vi.mocked(fetchSessionDetail).mockRejectedValue(new Error('Fetch failed'));
|
|
911
|
-
await useStore.getState().refreshActiveSession();
|
|
912
|
-
expect(useStore.getState().error).toBe('Fetch failed');
|
|
913
|
-
});
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
describe('updateModelConfig', () => {
|
|
917
|
-
beforeEach(() => {
|
|
918
|
-
vi.clearAllMocks();
|
|
919
|
-
resetStore();
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
it('calls API and updates model fields in sessions + detail', async () => {
|
|
923
|
-
const detail = makeDetail('s1', [], { model: 'old-model', external_thread_id: 'ext-1' });
|
|
924
|
-
resetStore({
|
|
925
|
-
activeSessionId: 's1',
|
|
926
|
-
sessions: [makeSession('s1', { model: 'old-model', external_thread_id: 'ext-1' })],
|
|
927
|
-
sessionDetails: { s1: detail },
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
const updated = makeSession('s1', { model: 'new-model', model_reasoning_effort: 'high', external_thread_id: null });
|
|
931
|
-
vi.mocked(apiUpdateModelConfig).mockResolvedValue(updated);
|
|
932
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', [], { model: 'new-model', external_thread_id: null }));
|
|
933
|
-
|
|
934
|
-
await useStore.getState().updateModelConfig('new-model', 'high');
|
|
935
|
-
|
|
936
|
-
const state = useStore.getState();
|
|
937
|
-
expect(apiUpdateModelConfig).toHaveBeenCalledWith('s1', 'new-model', 'high', undefined);
|
|
938
|
-
expect(state.sessions[0].model).toBe('new-model');
|
|
939
|
-
expect(state.lastModelConfig).toEqual({ provider: 'codex', model: 'new-model', reasoning: 'high' });
|
|
940
|
-
});
|
|
941
|
-
|
|
942
|
-
it('does nothing when no active session', async () => {
|
|
943
|
-
resetStore({ activeSessionId: null });
|
|
944
|
-
await useStore.getState().updateModelConfig('model', 'low');
|
|
945
|
-
expect(apiUpdateModelConfig).not.toHaveBeenCalled();
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
it('shows error toast on failure', async () => {
|
|
949
|
-
resetStore({ activeSessionId: 's1', sessions: [makeSession('s1')] });
|
|
950
|
-
vi.mocked(apiUpdateModelConfig).mockRejectedValue(new Error('Update failed'));
|
|
951
|
-
await useStore.getState().updateModelConfig('model', 'low');
|
|
952
|
-
expect(useStore.getState().error).toBe('Update failed');
|
|
953
|
-
expect(useStore.getState().toasts[0].type).toBe('error');
|
|
954
|
-
});
|
|
955
|
-
|
|
956
|
-
it('passes runtimeType to API when switching provider', async () => {
|
|
957
|
-
const detail = makeDetail('s1', [], { model: 'gpt-5.6-sol', runtime_type: 'codex' });
|
|
958
|
-
resetStore({
|
|
959
|
-
activeSessionId: 's1',
|
|
960
|
-
sessions: [makeSession('s1', { model: 'gpt-5.6-sol', runtime_type: 'codex' })],
|
|
961
|
-
sessionDetails: { s1: detail },
|
|
962
|
-
});
|
|
963
|
-
|
|
964
|
-
const updated = makeSession('s1', { runtime_type: 'claude', model: null, model_reasoning_effort: null });
|
|
965
|
-
vi.mocked(apiUpdateModelConfig).mockResolvedValue(updated);
|
|
966
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', [], { runtime_type: 'claude' }));
|
|
967
|
-
|
|
968
|
-
await useStore.getState().updateModelConfig('', '', 'claude');
|
|
969
|
-
|
|
970
|
-
expect(apiUpdateModelConfig).toHaveBeenCalledWith('s1', '', '', 'claude');
|
|
971
|
-
expect(useStore.getState().sessions[0].runtime_type).toBe('claude');
|
|
972
|
-
});
|
|
973
|
-
});
|
|
974
|
-
|
|
975
|
-
// === New tests: Workspace actions ===
|
|
976
|
-
|
|
977
|
-
describe('addWorkspace', () => {
|
|
978
|
-
beforeEach(() => {
|
|
979
|
-
vi.clearAllMocks();
|
|
980
|
-
resetStore();
|
|
981
|
-
});
|
|
982
|
-
|
|
983
|
-
it('creates workspace and adds to list', async () => {
|
|
984
|
-
const ws = makeWorkspace('w1', '/path/to/project');
|
|
985
|
-
vi.mocked(apiCreateWorkspace).mockResolvedValue(ws);
|
|
986
|
-
|
|
987
|
-
await useStore.getState().addWorkspace('/path/to/project');
|
|
988
|
-
|
|
989
|
-
const state = useStore.getState();
|
|
990
|
-
expect(apiCreateWorkspace).toHaveBeenCalledWith('/path/to/project');
|
|
991
|
-
expect(state.workspaces).toHaveLength(1);
|
|
992
|
-
expect(state.workspaces[0].path).toBe('/path/to/project');
|
|
993
|
-
expect(state.toasts[0].type).toBe('success');
|
|
994
|
-
});
|
|
995
|
-
|
|
996
|
-
it('trims path before sending', async () => {
|
|
997
|
-
const ws = makeWorkspace('w1', '/path');
|
|
998
|
-
vi.mocked(apiCreateWorkspace).mockResolvedValue(ws);
|
|
999
|
-
await useStore.getState().addWorkspace(' /path ');
|
|
1000
|
-
expect(apiCreateWorkspace).toHaveBeenCalledWith('/path');
|
|
1001
|
-
});
|
|
1002
|
-
|
|
1003
|
-
it('shows error toast on failure', async () => {
|
|
1004
|
-
vi.mocked(apiCreateWorkspace).mockRejectedValue(new Error('Create failed'));
|
|
1005
|
-
await useStore.getState().addWorkspace('/path');
|
|
1006
|
-
expect(useStore.getState().toasts[0].type).toBe('error');
|
|
1007
|
-
});
|
|
1008
|
-
});
|
|
1009
|
-
|
|
1010
|
-
describe('removeWorkspace', () => {
|
|
1011
|
-
beforeEach(() => {
|
|
1012
|
-
vi.clearAllMocks();
|
|
1013
|
-
resetStore();
|
|
1014
|
-
});
|
|
1015
|
-
|
|
1016
|
-
it('hides workspace and re-fetches list', async () => {
|
|
1017
|
-
resetStore({ workspaces: [makeWorkspace('w1', '/path1'), makeWorkspace('w2', '/path2')] });
|
|
1018
|
-
vi.mocked(apiHideWorkspace).mockResolvedValue({ success: true });
|
|
1019
|
-
vi.mocked(fetchWorkspaces).mockResolvedValue([makeWorkspace('w2', '/path2')]);
|
|
1020
|
-
|
|
1021
|
-
await useStore.getState().removeWorkspace('/path1');
|
|
1022
|
-
|
|
1023
|
-
const state = useStore.getState();
|
|
1024
|
-
expect(apiHideWorkspace).toHaveBeenCalledWith('/path1');
|
|
1025
|
-
expect(fetchWorkspaces).toHaveBeenCalled();
|
|
1026
|
-
expect(state.workspaces).toHaveLength(1);
|
|
1027
|
-
expect(state.workspaces[0].path).toBe('/path2');
|
|
1028
|
-
});
|
|
1029
|
-
|
|
1030
|
-
it('shows error toast on failure', async () => {
|
|
1031
|
-
vi.mocked(apiHideWorkspace).mockRejectedValue(new Error('Hide failed'));
|
|
1032
|
-
await useStore.getState().removeWorkspace('/path');
|
|
1033
|
-
expect(useStore.getState().toasts[0].type).toBe('error');
|
|
1034
|
-
});
|
|
1035
|
-
});
|
|
1036
|
-
|
|
1037
|
-
describe('createSessionInWorkspace', () => {
|
|
1038
|
-
beforeEach(() => {
|
|
1039
|
-
vi.clearAllMocks();
|
|
1040
|
-
resetStore();
|
|
1041
|
-
});
|
|
1042
|
-
|
|
1043
|
-
it('creates session with cwd and selects it', async () => {
|
|
1044
|
-
const newSession = makeSession('s1', { cwd: '/workspace' });
|
|
1045
|
-
vi.mocked(apiCreateSession).mockResolvedValue(newSession);
|
|
1046
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', []));
|
|
1047
|
-
|
|
1048
|
-
await useStore.getState().createSessionInWorkspace('/workspace');
|
|
1049
|
-
|
|
1050
|
-
const state = useStore.getState();
|
|
1051
|
-
expect(apiCreateSession).toHaveBeenCalledWith(expect.objectContaining({ cwd: '/workspace' }));
|
|
1052
|
-
expect(state.sessions[0].id).toBe('s1');
|
|
1053
|
-
expect(state.activeSessionId).toBe('s1');
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
it('uses lastModelConfig for runtime_type and model', async () => {
|
|
1057
|
-
resetStore({ lastModelConfig: { provider: 'codex', model: 'gpt-5.6-sol', reasoning: 'high' } });
|
|
1058
|
-
const newSession = makeSession('s1', { cwd: '/ws' });
|
|
1059
|
-
vi.mocked(apiCreateSession).mockResolvedValue(newSession);
|
|
1060
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', []));
|
|
1061
|
-
|
|
1062
|
-
await useStore.getState().createSessionInWorkspace('/ws');
|
|
1063
|
-
|
|
1064
|
-
expect(apiCreateSession).toHaveBeenCalledWith(expect.objectContaining({
|
|
1065
|
-
runtime_type: 'codex',
|
|
1066
|
-
model: 'gpt-5.6-sol',
|
|
1067
|
-
model_reasoning_effort: 'high',
|
|
1068
|
-
}));
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
it('shows error toast on failure', async () => {
|
|
1072
|
-
vi.mocked(apiCreateSession).mockRejectedValue(new Error('Create failed'));
|
|
1073
|
-
await useStore.getState().createSessionInWorkspace('/ws');
|
|
1074
|
-
expect(useStore.getState().toasts[0].type).toBe('error');
|
|
1075
|
-
});
|
|
1076
|
-
});
|
|
1077
|
-
|
|
1078
|
-
describe('pickAndAddWorkspace', () => {
|
|
1079
|
-
beforeEach(() => {
|
|
1080
|
-
vi.clearAllMocks();
|
|
1081
|
-
resetStore();
|
|
1082
|
-
});
|
|
1083
|
-
|
|
1084
|
-
it('picks directory and adds workspace', async () => {
|
|
1085
|
-
vi.mocked(apiPickDirectory).mockResolvedValue({ path: '/selected/path' });
|
|
1086
|
-
const ws = makeWorkspace('w1', '/selected/path');
|
|
1087
|
-
vi.mocked(apiCreateWorkspace).mockResolvedValue(ws);
|
|
1088
|
-
|
|
1089
|
-
await useStore.getState().pickAndAddWorkspace();
|
|
1090
|
-
|
|
1091
|
-
expect(apiPickDirectory).toHaveBeenCalled();
|
|
1092
|
-
expect(apiCreateWorkspace).toHaveBeenCalledWith('/selected/path');
|
|
1093
|
-
});
|
|
1094
|
-
|
|
1095
|
-
it('does nothing when cancelled', async () => {
|
|
1096
|
-
vi.mocked(apiPickDirectory).mockResolvedValue({ cancelled: true });
|
|
1097
|
-
|
|
1098
|
-
await useStore.getState().pickAndAddWorkspace();
|
|
1099
|
-
|
|
1100
|
-
expect(apiCreateWorkspace).not.toHaveBeenCalled();
|
|
1101
|
-
});
|
|
1102
|
-
|
|
1103
|
-
it('does nothing when path is missing', async () => {
|
|
1104
|
-
vi.mocked(apiPickDirectory).mockResolvedValue({});
|
|
1105
|
-
|
|
1106
|
-
await useStore.getState().pickAndAddWorkspace();
|
|
1107
|
-
|
|
1108
|
-
expect(apiCreateWorkspace).not.toHaveBeenCalled();
|
|
1109
|
-
});
|
|
1110
|
-
|
|
1111
|
-
it('shows error toast on failure', async () => {
|
|
1112
|
-
vi.mocked(apiPickDirectory).mockRejectedValue(new Error('Picker failed'));
|
|
1113
|
-
await useStore.getState().pickAndAddWorkspace();
|
|
1114
|
-
expect(useStore.getState().toasts[0].type).toBe('error');
|
|
1115
|
-
});
|
|
1116
|
-
});
|
|
1117
|
-
|
|
1118
|
-
// === New tests: UI state actions ===
|
|
1119
|
-
|
|
1120
|
-
describe('addToast', () => {
|
|
1121
|
-
beforeEach(() => {
|
|
1122
|
-
vi.clearAllMocks();
|
|
1123
|
-
resetStore();
|
|
1124
|
-
});
|
|
1125
|
-
|
|
1126
|
-
it('adds a toast with a unique id', () => {
|
|
1127
|
-
useStore.getState().addToast('info', 'Test message');
|
|
1128
|
-
const toasts = useStore.getState().toasts;
|
|
1129
|
-
expect(toasts).toHaveLength(1);
|
|
1130
|
-
expect(toasts[0].type).toBe('info');
|
|
1131
|
-
expect(toasts[0].message).toBe('Test message');
|
|
1132
|
-
expect(toasts[0].id).toBeTruthy();
|
|
1133
|
-
});
|
|
1134
|
-
|
|
1135
|
-
it('adds toast with undoAction and undoLabel', () => {
|
|
1136
|
-
const undo = vi.fn();
|
|
1137
|
-
useStore.getState().addToast('error', 'Deleted', undo, 'Undo delete');
|
|
1138
|
-
const toast = useStore.getState().toasts[0];
|
|
1139
|
-
expect(toast.undoAction).toBe(undo);
|
|
1140
|
-
expect(toast.undoLabel).toBe('Undo delete');
|
|
1141
|
-
});
|
|
1142
|
-
});
|
|
1143
|
-
|
|
1144
|
-
describe('removeToast', () => {
|
|
1145
|
-
beforeEach(() => {
|
|
1146
|
-
vi.clearAllMocks();
|
|
1147
|
-
resetStore();
|
|
1148
|
-
});
|
|
1149
|
-
|
|
1150
|
-
it('removes toast by id', () => {
|
|
1151
|
-
useStore.getState().addToast('info', 'Toast 1');
|
|
1152
|
-
useStore.getState().addToast('info', 'Toast 2');
|
|
1153
|
-
const id = useStore.getState().toasts[0].id;
|
|
1154
|
-
useStore.getState().removeToast(id);
|
|
1155
|
-
expect(useStore.getState().toasts).toHaveLength(1);
|
|
1156
|
-
expect(useStore.getState().toasts[0].message).toBe('Toast 2');
|
|
1157
|
-
});
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
describe('addLogEntry', () => {
|
|
1161
|
-
beforeEach(() => {
|
|
1162
|
-
vi.clearAllMocks();
|
|
1163
|
-
resetStore();
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
it('adds entry to event log', () => {
|
|
1167
|
-
useStore.getState().addLogEntry('INFO', 'Test log message');
|
|
1168
|
-
const log = useStore.getState().eventLog;
|
|
1169
|
-
expect(log).toHaveLength(1);
|
|
1170
|
-
expect(log[0].level).toBe('INFO');
|
|
1171
|
-
expect(log[0].message).toBe('Test log message');
|
|
1172
|
-
expect(log[0].time).toBeTruthy();
|
|
1173
|
-
});
|
|
1174
|
-
});
|
|
1175
|
-
|
|
1176
|
-
describe('setWsConnected', () => {
|
|
1177
|
-
beforeEach(() => {
|
|
1178
|
-
vi.clearAllMocks();
|
|
1179
|
-
resetStore();
|
|
1180
|
-
});
|
|
1181
|
-
|
|
1182
|
-
it('sets wsConnected flag', () => {
|
|
1183
|
-
useStore.getState().setWsConnected(true);
|
|
1184
|
-
expect(useStore.getState().wsConnected).toBe(true);
|
|
1185
|
-
useStore.getState().setWsConnected(false);
|
|
1186
|
-
expect(useStore.getState().wsConnected).toBe(false);
|
|
1187
|
-
});
|
|
1188
|
-
});
|
|
1189
|
-
|
|
1190
|
-
describe('simple setters', () => {
|
|
1191
|
-
beforeEach(() => {
|
|
1192
|
-
vi.clearAllMocks();
|
|
1193
|
-
resetStore();
|
|
1194
|
-
});
|
|
1195
|
-
|
|
1196
|
-
it('setActiveTurnIndex sets value', () => {
|
|
1197
|
-
useStore.getState().setActiveTurnIndex(3);
|
|
1198
|
-
expect(useStore.getState().activeTurnIndex).toBe(3);
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
it('switchRightTab sets value', () => {
|
|
1202
|
-
useStore.getState().switchRightTab('changes');
|
|
1203
|
-
expect(useStore.getState().activeRightTab).toBe('changes');
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
it('setChangesScope sets value', () => {
|
|
1207
|
-
useStore.getState().setChangesScope('turngroup');
|
|
1208
|
-
expect(useStore.getState().changesScope).toBe('turngroup');
|
|
1209
|
-
});
|
|
1210
|
-
|
|
1211
|
-
it('setShowNewSessionDialog sets value', () => {
|
|
1212
|
-
useStore.getState().setShowNewSessionDialog(true);
|
|
1213
|
-
expect(useStore.getState().showNewSessionDialog).toBe(true);
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
it('setShowCommandPalette sets value', () => {
|
|
1217
|
-
useStore.getState().setShowCommandPalette(true);
|
|
1218
|
-
expect(useStore.getState().showCommandPalette).toBe(true);
|
|
1219
|
-
});
|
|
1220
|
-
|
|
1221
|
-
it('setSelectedChangePath sets value', () => {
|
|
1222
|
-
useStore.getState().setSelectedChangePath('/file.ts');
|
|
1223
|
-
expect(useStore.getState().selectedChangePath).toBe('/file.ts');
|
|
1224
|
-
});
|
|
1225
|
-
});
|
|
1226
|
-
|
|
1227
|
-
// === New tests: init ===
|
|
1228
|
-
|
|
1229
|
-
describe('setSidebarWidth / setRightPanelWidth', () => {
|
|
1230
|
-
beforeEach(() => {
|
|
1231
|
-
vi.clearAllMocks();
|
|
1232
|
-
resetStore();
|
|
1233
|
-
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {});
|
|
1234
|
-
});
|
|
1235
|
-
|
|
1236
|
-
it('clamps sidebar width to [SIDEBAR_MIN, SIDEBAR_MAX] and persists', () => {
|
|
1237
|
-
const setItem = vi.mocked(Storage.prototype.setItem);
|
|
1238
|
-
useStore.getState().setSidebarWidth(900);
|
|
1239
|
-
expect(useStore.getState().sidebarWidth).toBe(480);
|
|
1240
|
-
expect(setItem).toHaveBeenCalledWith('agentpane:sidebar-width', '480');
|
|
1241
|
-
|
|
1242
|
-
useStore.getState().setSidebarWidth(50);
|
|
1243
|
-
expect(useStore.getState().sidebarWidth).toBe(160);
|
|
1244
|
-
expect(setItem).toHaveBeenCalledWith('agentpane:sidebar-width', '160');
|
|
1245
|
-
});
|
|
1246
|
-
|
|
1247
|
-
it('clamps right panel width to [RIGHT_PANEL_MIN, RIGHT_PANEL_MAX] and persists', () => {
|
|
1248
|
-
const setItem = vi.mocked(Storage.prototype.setItem);
|
|
1249
|
-
useStore.getState().setRightPanelWidth(9999);
|
|
1250
|
-
expect(useStore.getState().rightPanelWidth).toBe(600);
|
|
1251
|
-
expect(setItem).toHaveBeenCalledWith('agentpane:right-panel-width', '600');
|
|
1252
|
-
|
|
1253
|
-
useStore.getState().setRightPanelWidth(10);
|
|
1254
|
-
expect(useStore.getState().rightPanelWidth).toBe(220);
|
|
1255
|
-
expect(setItem).toHaveBeenCalledWith('agentpane:right-panel-width', '220');
|
|
1256
|
-
});
|
|
1257
|
-
|
|
1258
|
-
it('rounds fractional widths', () => {
|
|
1259
|
-
useStore.getState().setSidebarWidth(240.7);
|
|
1260
|
-
expect(useStore.getState().sidebarWidth).toBe(241);
|
|
1261
|
-
});
|
|
1262
|
-
});
|
|
1263
|
-
|
|
1264
|
-
describe('init', () => {
|
|
1265
|
-
beforeEach(() => {
|
|
1266
|
-
vi.clearAllMocks();
|
|
1267
|
-
resetStore();
|
|
1268
|
-
vi.spyOn(Storage.prototype, 'getItem').mockReturnValue(null);
|
|
1269
|
-
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {});
|
|
1270
|
-
});
|
|
1271
|
-
|
|
1272
|
-
it('loads sessions and workspaces', async () => {
|
|
1273
|
-
const sessions = [makeSession('s1'), makeSession('s2')];
|
|
1274
|
-
const workspaces = [makeWorkspace('w1', '/path')];
|
|
1275
|
-
vi.mocked(fetchSessions).mockResolvedValue(sessions);
|
|
1276
|
-
vi.mocked(fetchWorkspaces).mockResolvedValue(workspaces);
|
|
1277
|
-
vi.mocked(fetchSessionDetail).mockResolvedValue(makeDetail('s1', []));
|
|
1278
|
-
|
|
1279
|
-
await useStore.getState().init();
|
|
1280
|
-
|
|
1281
|
-
const state = useStore.getState();
|
|
1282
|
-
expect(fetchSessions).toHaveBeenCalled();
|
|
1283
|
-
expect(fetchWorkspaces).toHaveBeenCalled();
|
|
1284
|
-
expect(state.sessions).toHaveLength(2);
|
|
1285
|
-
expect(state.workspaces).toHaveLength(1);
|
|
1286
|
-
expect(state.loading).toBe(false);
|
|
1287
|
-
// First session auto-selected
|
|
1288
|
-
expect(state.activeSessionId).toBe('s1');
|
|
1289
|
-
});
|
|
1290
|
-
|
|
1291
|
-
it('does not auto-select when no sessions', async () => {
|
|
1292
|
-
vi.mocked(fetchSessions).mockResolvedValue([]);
|
|
1293
|
-
vi.mocked(fetchWorkspaces).mockResolvedValue([]);
|
|
1294
|
-
|
|
1295
|
-
await useStore.getState().init();
|
|
1296
|
-
|
|
1297
|
-
expect(useStore.getState().activeSessionId).toBeNull();
|
|
1298
|
-
});
|
|
1299
|
-
|
|
1300
|
-
it('loads lastModelConfig from localStorage', async () => {
|
|
1301
|
-
const savedConfig = { provider: 'codex', model: 'gpt-5.6-sol', reasoning: 'high' };
|
|
1302
|
-
vi.mocked(Storage.prototype.getItem).mockReturnValue(JSON.stringify(savedConfig));
|
|
1303
|
-
vi.mocked(fetchSessions).mockResolvedValue([]);
|
|
1304
|
-
vi.mocked(fetchWorkspaces).mockResolvedValue([]);
|
|
1305
|
-
|
|
1306
|
-
await useStore.getState().init();
|
|
1307
|
-
|
|
1308
|
-
expect(useStore.getState().lastModelConfig).toEqual(savedConfig);
|
|
1309
|
-
});
|
|
1310
|
-
|
|
1311
|
-
it('sets error on failure', async () => {
|
|
1312
|
-
vi.mocked(fetchSessions).mockRejectedValue(new Error('Network error'));
|
|
1313
|
-
|
|
1314
|
-
await useStore.getState().init();
|
|
1315
|
-
|
|
1316
|
-
expect(useStore.getState().error).toBe('Network error');
|
|
1317
|
-
expect(useStore.getState().loading).toBe(false);
|
|
1318
|
-
});
|
|
1319
|
-
});
|