repoburg 1.3.202 → 1.3.209
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 +2103 -32003
- package/agent-pane/backend/dist/server.js +45313 -0
- package/backend/dist/src/agent-runtime/agent-runtime.types.d.ts +1 -0
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js +6 -6
- package/backend/dist/src/llm-orchestration/hooks/frontend-notification.hook.js.map +1 -1
- package/backend/dist/src/llm-orchestration/llm-turn-processor.service.js +1 -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/index.js +28 -8
- package/daemon/package.json +1 -1
- package/model-selector-scroll.png +0 -0
- package/package.json +10 -2
- 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 -236
- 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 -49
- package/agent-pane/backend/src/repoburg/action-mapping.test.ts +0 -122
- package/agent-pane/backend/src/repoburg/action-mapping.ts +0 -294
- package/agent-pane/backend/src/repoburg/agent-runtime-client.test.ts +0 -271
- package/agent-pane/backend/src/repoburg/agent-runtime-client.ts +0 -285
- package/agent-pane/backend/src/repoburg/backend-resolver.test.ts +0 -356
- package/agent-pane/backend/src/repoburg/backend-resolver.ts +0 -261
- package/agent-pane/backend/src/repoburg/repoburg-client.test.ts +0 -180
- package/agent-pane/backend/src/repoburg/repoburg-client.ts +0 -194
- package/agent-pane/backend/src/repoburg/repoburg-provider.test.ts +0 -780
- package/agent-pane/backend/src/repoburg/repoburg-provider.ts +0 -471
- package/agent-pane/backend/src/repoburg/turn-projector.test.ts +0 -621
- package/agent-pane/backend/src/repoburg/turn-projector.ts +0 -637
- 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 -772
- package/agent-pane/backend/src/routes/sessions.ts +0 -565
- 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-CJxD4YmJ.js +0 -370
- package/agent-pane/frontend/dist/assets/index-r-xwfOKQ.css +0 -1
- 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 -246
- 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 -240
- 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/AskUserItem.test.tsx +0 -143
- package/agent-pane/frontend/src/components/AskUserItem.tsx +0 -207
- 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 -377
- package/agent-pane/frontend/src/components/TurnContent.tsx +0 -594
- 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 -131
- package/agent-pane/frontend/src/components/panels/TurnsPanel.tsx +0 -131
- 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 -1338
- 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 -368
- package/agent-pane/frontend/src/styles/app.css +0 -627
- 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 -101
- 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 -134
- 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 -76
- 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 -184
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App-server replay mock for integration tests.
|
|
3
|
-
*
|
|
4
|
-
* Replaces the old `@openai/codex-sdk` replay mock. The mock AppServerClient
|
|
5
|
-
* replays fixture events as JSON-RPC notifications (item/started, item/completed,
|
|
6
|
-
* turn/completed, turn/failed) instead of SDK async generators.
|
|
7
|
-
*
|
|
8
|
-
* The fixture format is unchanged — events use SDK-style names (thread.started,
|
|
9
|
-
* item.started, etc.) which are translated to app-server notification names
|
|
10
|
-
* (thread/started, item/started, etc.) by the mock.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { EventEmitter } from 'node:events';
|
|
14
|
-
|
|
15
|
-
/** A single event captured from the real SDK (or app-server). */
|
|
16
|
-
type FixtureEvent = Record<string, unknown>;
|
|
17
|
-
|
|
18
|
-
/** A captured interaction (events for one turn). */
|
|
19
|
-
interface ReplayCall {
|
|
20
|
-
prompt: string;
|
|
21
|
-
events: FixtureEvent[];
|
|
22
|
-
eventDelay?: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** A captured title generation interaction. */
|
|
26
|
-
interface TitleCall {
|
|
27
|
-
prompt: string;
|
|
28
|
-
result: { finalResponse: string };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** A complete fixture — all interactions for one test scenario. */
|
|
32
|
-
export interface Fixture {
|
|
33
|
-
name: string;
|
|
34
|
-
description: string;
|
|
35
|
-
threadId: string;
|
|
36
|
-
runStreamedCalls: ReplayCall[];
|
|
37
|
-
runCalls: TitleCall[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Read a fixture from a JSON string. */
|
|
41
|
-
export function parseFixture(json: string): Fixture {
|
|
42
|
-
return JSON.parse(json) as Fixture;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Map SDK event type to app-server notification method. */
|
|
46
|
-
function sdkEventToNotification(eventType: string): string {
|
|
47
|
-
switch (eventType) {
|
|
48
|
-
case 'thread.started':
|
|
49
|
-
return 'thread/started';
|
|
50
|
-
case 'item.started':
|
|
51
|
-
return 'item/started';
|
|
52
|
-
case 'item.updated':
|
|
53
|
-
return 'item/updated';
|
|
54
|
-
case 'item.completed':
|
|
55
|
-
return 'item/completed';
|
|
56
|
-
case 'item.agentMessage.delta':
|
|
57
|
-
return 'item/agentMessage/delta';
|
|
58
|
-
case 'turn.completed':
|
|
59
|
-
return 'turn/completed';
|
|
60
|
-
case 'thread.tokenUsage.updated':
|
|
61
|
-
return 'thread/tokenUsage/updated';
|
|
62
|
-
case 'error':
|
|
63
|
-
return 'turn/failed';
|
|
64
|
-
default:
|
|
65
|
-
return eventType;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Map an SDK event to app-server notification params. */
|
|
70
|
-
function sdkEventToParams(event: FixtureEvent, threadId: string, turnId: string): Record<string, unknown> {
|
|
71
|
-
const type = event.type as string;
|
|
72
|
-
|
|
73
|
-
if (type === 'turn.completed') {
|
|
74
|
-
// Real app-server sends { threadId, turn: { id, status } } — no usage.
|
|
75
|
-
// Token usage arrives via separate thread/tokenUsage/updated notification.
|
|
76
|
-
return {
|
|
77
|
-
threadId,
|
|
78
|
-
turnId,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (type === 'error') {
|
|
83
|
-
return {
|
|
84
|
-
threadId,
|
|
85
|
-
turnId,
|
|
86
|
-
error: { message: event.message as string },
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (type === 'item.agentMessage.delta') {
|
|
91
|
-
return {
|
|
92
|
-
threadId,
|
|
93
|
-
turnId,
|
|
94
|
-
itemId: event.itemId as string,
|
|
95
|
-
delta: event.delta as string,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (type === 'thread.tokenUsage.updated') {
|
|
100
|
-
const usage = event.tokenUsage as {
|
|
101
|
-
inputTokens: number;
|
|
102
|
-
cachedInputTokens: number;
|
|
103
|
-
cacheWriteInputTokens: number;
|
|
104
|
-
outputTokens: number;
|
|
105
|
-
reasoningOutputTokens: number;
|
|
106
|
-
totalTokens: number;
|
|
107
|
-
};
|
|
108
|
-
return {
|
|
109
|
-
threadId,
|
|
110
|
-
turnId,
|
|
111
|
-
tokenUsage: {
|
|
112
|
-
total: usage,
|
|
113
|
-
last: usage,
|
|
114
|
-
modelContextWindow: event.modelContextWindow ?? 258400,
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// item.* events
|
|
120
|
-
return {
|
|
121
|
-
threadId,
|
|
122
|
-
turnId,
|
|
123
|
-
item: event.item as Record<string, unknown>,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Create a mock AppServerClient class that replays fixture events.
|
|
129
|
-
*
|
|
130
|
-
* @param fixture — The fixture to replay.
|
|
131
|
-
* @returns A class that can be used to mock the AppServerClient module.
|
|
132
|
-
*/
|
|
133
|
-
export function createAppServerMock(fixture: Fixture) {
|
|
134
|
-
return class MockAppServerClient {
|
|
135
|
-
readonly events = new EventEmitter();
|
|
136
|
-
private notificationHandlers = new Map<string, Array<(params: unknown) => void>>();
|
|
137
|
-
private closed = false;
|
|
138
|
-
private interrupted = false;
|
|
139
|
-
private turnStartIndex = 0;
|
|
140
|
-
private titleCallIndex = 0;
|
|
141
|
-
|
|
142
|
-
async initialize(): Promise<{ userAgent: string }> {
|
|
143
|
-
return { userAgent: 'mock/0.147.0' };
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async request<T>(method: string, params?: unknown): Promise<T> {
|
|
147
|
-
if (this.closed) throw new Error('MockAppServerClient is closed');
|
|
148
|
-
|
|
149
|
-
switch (method) {
|
|
150
|
-
case 'thread/start':
|
|
151
|
-
case 'thread/resume':
|
|
152
|
-
return { thread: { id: fixture.threadId } } as T;
|
|
153
|
-
|
|
154
|
-
case 'turn/start': {
|
|
155
|
-
// Detect title generation by checking input prompt prefix
|
|
156
|
-
const inputText = (params as { input?: Array<{ text?: string }> })?.input?.[0]?.text ?? '';
|
|
157
|
-
const isTitleGen = inputText.startsWith('Generate a concise 3-5 word title');
|
|
158
|
-
|
|
159
|
-
if (isTitleGen) {
|
|
160
|
-
// Title generation — use runCalls
|
|
161
|
-
if (this.titleCallIndex < fixture.runCalls.length) {
|
|
162
|
-
const call = fixture.runCalls[this.titleCallIndex];
|
|
163
|
-
this.titleCallIndex++;
|
|
164
|
-
|
|
165
|
-
const turnId = `title_${this.titleCallIndex}`;
|
|
166
|
-
this.replayTitleCall(call, fixture.threadId, turnId);
|
|
167
|
-
|
|
168
|
-
return { turn: { id: turnId } } as T;
|
|
169
|
-
}
|
|
170
|
-
// No more title calls — return empty turn
|
|
171
|
-
return { turn: { id: 'empty_title' } } as T;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Main turns use runStreamedCalls
|
|
175
|
-
if (this.turnStartIndex < fixture.runStreamedCalls.length) {
|
|
176
|
-
const call = fixture.runStreamedCalls[this.turnStartIndex];
|
|
177
|
-
this.turnStartIndex++;
|
|
178
|
-
|
|
179
|
-
const turnId = `turn_${this.turnStartIndex}`;
|
|
180
|
-
this.replayEvents(call, fixture.threadId, turnId);
|
|
181
|
-
|
|
182
|
-
return { turn: { id: turnId } } as T;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// No more fixture calls — return empty turn (no events)
|
|
186
|
-
return { turn: { id: 'empty' } } as T;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
case 'turn/interrupt':
|
|
190
|
-
this.interrupted = true;
|
|
191
|
-
return {} as T;
|
|
192
|
-
|
|
193
|
-
default:
|
|
194
|
-
return {} as T;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
notify(): void {
|
|
199
|
-
// No-op
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
onNotification(method: string, handler: (params: unknown) => void): void {
|
|
203
|
-
const handlers = this.notificationHandlers.get(method) ?? [];
|
|
204
|
-
handlers.push(handler);
|
|
205
|
-
this.notificationHandlers.set(method, handlers);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
onRequest(): void {
|
|
209
|
-
// No-op
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
isClosed(): boolean {
|
|
213
|
-
return this.closed;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
async close(): Promise<void> {
|
|
217
|
-
this.closed = true;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Replay fixture events as notifications with optional delay. */
|
|
221
|
-
private async replayEvents(call: ReplayCall, threadId: string, turnId: string): Promise<void> {
|
|
222
|
-
for (const event of call.events) {
|
|
223
|
-
if (this.interrupted) {
|
|
224
|
-
// On interrupt, stop replaying — codex-provider handles DB update + broadcast
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (call.eventDelay) {
|
|
229
|
-
await new Promise((r) => setTimeout(r, call.eventDelay));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const type = event.type as string;
|
|
233
|
-
const method = sdkEventToNotification(type);
|
|
234
|
-
const params = sdkEventToParams(event, threadId, turnId);
|
|
235
|
-
|
|
236
|
-
this.emitNotification(method, params);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/** Replay a title generation call as notifications (item/completed + turn/completed). */
|
|
241
|
-
private async replayTitleCall(call: TitleCall, threadId: string, turnId: string): Promise<void> {
|
|
242
|
-
// Simulate: agent_message item started → completed → turn completed
|
|
243
|
-
this.emitNotification('item/started', {
|
|
244
|
-
threadId,
|
|
245
|
-
turnId,
|
|
246
|
-
item: { id: 'title_item', type: 'agent_message', text: '' },
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
this.emitNotification('item/completed', {
|
|
250
|
-
threadId,
|
|
251
|
-
turnId,
|
|
252
|
-
item: { id: 'title_item', type: 'agent_message', text: call.result.finalResponse },
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
this.emitNotification('turn/completed', {
|
|
256
|
-
threadId,
|
|
257
|
-
turnId,
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/** Emit a notification to all registered handlers for the method. */
|
|
262
|
-
private emitNotification(method: string, params: unknown): void {
|
|
263
|
-
const handlers = this.notificationHandlers.get(method);
|
|
264
|
-
if (handlers) {
|
|
265
|
-
for (const handler of handlers) {
|
|
266
|
-
handler(params);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
this.events.emit('notification', method, params);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test app factory for integration tests.
|
|
3
|
-
*
|
|
4
|
-
* Sets up a Fastify instance with all route handlers registered, using
|
|
5
|
-
* an in-memory SQLite database. The `app-server-client.ts` module is mocked
|
|
6
|
-
* by the test file (not here) using `createAppServerMock(fixture)`.
|
|
7
|
-
*
|
|
8
|
-
* Usage in a test file:
|
|
9
|
-
* ```ts
|
|
10
|
-
* vi.mock('../codex/app-server-client.ts', () => ({ AppServerClient: createAppServerMock(fixture) }));
|
|
11
|
-
* vi.mock('../../ws/index.ts', () => ({ ...realWs, broadcast: mockBroadcast }));
|
|
12
|
-
* const { app, db } = await createTestApp();
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import Fastify, { type FastifyInstance } from 'fastify';
|
|
17
|
-
import type Database from 'better-sqlite3';
|
|
18
|
-
import { initDb } from '../../db/index.ts';
|
|
19
|
-
import { initWs } from '../../ws/index.ts';
|
|
20
|
-
import { registerSessionRoutes } from '../../routes/sessions.ts';
|
|
21
|
-
import { registerTurnRoutes } from '../../routes/turns.ts';
|
|
22
|
-
import { registerThreadRoutes } from '../../routes/threads.ts';
|
|
23
|
-
import { registerWorkspaceRoutes } from '../../routes/workspaces.ts';
|
|
24
|
-
import { clearAllProviders } from '../../providers/registry.ts';
|
|
25
|
-
import '../../providers/index.ts'; // register providers for integration tests
|
|
26
|
-
|
|
27
|
-
export interface TestApp {
|
|
28
|
-
app: FastifyInstance;
|
|
29
|
-
db: Database.Database;
|
|
30
|
-
/** Close the Fastify instance and close the DB. */
|
|
31
|
-
cleanup: () => Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Create a test Fastify app with all routes and an in-memory DB.
|
|
36
|
-
*
|
|
37
|
-
* @returns `{ app, db, cleanup }`. Call `cleanup()` in `afterEach`.
|
|
38
|
-
*/
|
|
39
|
-
export async function createTestApp(): Promise<TestApp> {
|
|
40
|
-
const db = initDb(':memory:');
|
|
41
|
-
|
|
42
|
-
const app = Fastify();
|
|
43
|
-
|
|
44
|
-
await registerSessionRoutes(app);
|
|
45
|
-
await registerTurnRoutes(app);
|
|
46
|
-
await registerThreadRoutes(app);
|
|
47
|
-
await registerWorkspaceRoutes(app);
|
|
48
|
-
|
|
49
|
-
initWs();
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
app,
|
|
53
|
-
db,
|
|
54
|
-
cleanup: async () => {
|
|
55
|
-
clearAllProviders();
|
|
56
|
-
await app.close();
|
|
57
|
-
db.close();
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Wait for a turn to reach a terminal status by polling the DB.
|
|
64
|
-
*
|
|
65
|
-
* `startTurn()` is fire-and-forget — the HTTP POST returns immediately.
|
|
66
|
-
* Integration tests must wait for the async turn to finish before
|
|
67
|
-
* asserting on DB state or WS broadcasts.
|
|
68
|
-
*
|
|
69
|
-
* @param db — The in-memory DB instance.
|
|
70
|
-
* @param turnId — The turn ID to poll.
|
|
71
|
-
* @param timeoutMs — Max wait time (default 5000ms).
|
|
72
|
-
* @throws If the turn does not reach a terminal status within the timeout.
|
|
73
|
-
*/
|
|
74
|
-
export async function waitForTurn(db: Database.Database, turnId: string, timeoutMs = 5000): Promise<void> {
|
|
75
|
-
const start = Date.now();
|
|
76
|
-
while (Date.now() - start < timeoutMs) {
|
|
77
|
-
const row = db.prepare('SELECT status FROM turns WHERE id = ?').get(turnId) as { status: string } | undefined;
|
|
78
|
-
if (!row) {
|
|
79
|
-
throw new Error(`Turn ${turnId} not found in DB`);
|
|
80
|
-
}
|
|
81
|
-
if (row.status === 'completed' || row.status === 'failed' || row.status === 'aborted') {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
85
|
-
}
|
|
86
|
-
throw new Error(`Turn ${turnId} did not complete within ${timeoutMs}ms`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Insert a session row with sensible defaults for integration tests. */
|
|
90
|
-
export function insertTestSession(db: Database.Database, id: string, overrides: Record<string, unknown> = {}): void {
|
|
91
|
-
const now = new Date().toISOString();
|
|
92
|
-
db.prepare(
|
|
93
|
-
`INSERT INTO sessions (id, title, runtime_type, model, model_reasoning_effort, cwd, external_thread_id, status, is_running, lifecycle, has_unreviewed, created_at, updated_at)
|
|
94
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
95
|
-
).run(
|
|
96
|
-
id,
|
|
97
|
-
(overrides['title'] as string | null) ?? null,
|
|
98
|
-
(overrides['runtime_type'] as string) ?? 'codex',
|
|
99
|
-
(overrides['model'] as string | null) ?? null,
|
|
100
|
-
(overrides['model_reasoning_effort'] as string | null) ?? null,
|
|
101
|
-
(overrides['cwd'] as string | null) ?? null,
|
|
102
|
-
(overrides['external_thread_id'] as string | null) ?? null,
|
|
103
|
-
(overrides['status'] as string) ?? 'active',
|
|
104
|
-
(overrides['is_running'] as number) ?? 0,
|
|
105
|
-
(overrides['lifecycle'] as string) ?? 'working',
|
|
106
|
-
(overrides['has_unreviewed'] as number) ?? 0,
|
|
107
|
-
(overrides['created_at'] as string) ?? now,
|
|
108
|
-
(overrides['updated_at'] as string) ?? now,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Broadcast capture helper for integration tests.
|
|
3
|
-
*
|
|
4
|
-
* Replaces the real `broadcast()` function in `ws/index.ts` with a spy
|
|
5
|
-
* that records every call. This lets integration tests assert on the
|
|
6
|
-
* exact sequence of WS events without connecting a real WebSocket client.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export interface CapturedBroadcast {
|
|
10
|
-
event: string;
|
|
11
|
-
data: unknown;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** A list of captured broadcast calls, populated by the mock. */
|
|
15
|
-
export const capturedBroadcasts: CapturedBroadcast[] = [];
|
|
16
|
-
|
|
17
|
-
/** Clear all captured broadcasts. Call in `beforeEach`. */
|
|
18
|
-
export function clearBroadcasts(): void {
|
|
19
|
-
capturedBroadcasts.length = 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Mock broadcast function — records the call into `capturedBroadcasts`.
|
|
24
|
-
* Drop-in replacement for the real `broadcast()` in `ws/index.ts`.
|
|
25
|
-
*/
|
|
26
|
-
export function mockBroadcast(event: string, data: unknown): void {
|
|
27
|
-
capturedBroadcasts.push({ event, data });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Assert that broadcasts contain a specific event type.
|
|
32
|
-
* @param event — The event name to find (e.g. 'turn:started').
|
|
33
|
-
* @returns The first matching broadcast's data.
|
|
34
|
-
* @throws If no matching broadcast is found.
|
|
35
|
-
*/
|
|
36
|
-
export function findBroadcast(event: string): unknown {
|
|
37
|
-
const found = capturedBroadcasts.find((b) => b.event === event);
|
|
38
|
-
if (!found) {
|
|
39
|
-
const events = capturedBroadcasts.map((b) => b.event).join(', ');
|
|
40
|
-
throw new Error(`Expected broadcast "${event}" not found. Actual broadcasts: [${events}]`);
|
|
41
|
-
}
|
|
42
|
-
return found.data;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Assert the ordered sequence of broadcast event names.
|
|
47
|
-
* @param expected — Array of event names in expected order.
|
|
48
|
-
*/
|
|
49
|
-
export function expectBroadcastSequence(expected: string[]): void {
|
|
50
|
-
const actual = capturedBroadcasts.map((b) => b.event);
|
|
51
|
-
if (actual.length < expected.length) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Expected ${expected.length} broadcasts but got ${actual.length}. ` +
|
|
54
|
-
`Expected: [${expected.join(', ')}]. Actual: [${actual.join(', ')}]`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
for (let i = 0; i < expected.length; i++) {
|
|
58
|
-
if (actual[i] !== expected[i]) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
`Broadcast ${i}: expected "${expected[i]}" but got "${actual[i]}". ` + `Full actual: [${actual.join(', ')}]`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration test: item lifecycle across multiple item types.
|
|
3
|
-
*
|
|
4
|
-
* Verifies that handleEvent correctly processes all item types through
|
|
5
|
-
* item-mapper, including status transitions, thoughts accumulation,
|
|
6
|
-
* and WS broadcasts for each item event.
|
|
7
|
-
*
|
|
8
|
-
* Uses HTTP POST to trigger the turn (fire-and-forget startTurn).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
12
|
-
import { readFileSync } from 'node:fs';
|
|
13
|
-
import { resolve } from 'node:path';
|
|
14
|
-
import type Database from 'better-sqlite3';
|
|
15
|
-
import { createAppServerMock, type Fixture } from './helpers/app-server-mock.ts';
|
|
16
|
-
import { clearBroadcasts, capturedBroadcasts } from './helpers/ws-capture.ts';
|
|
17
|
-
import type { TestApp } from './helpers/test-app.ts';
|
|
18
|
-
|
|
19
|
-
const fixture = JSON.parse(readFileSync(resolve(__dirname, '__fixtures__/multi-item-turn.json'), 'utf-8')) as Fixture;
|
|
20
|
-
|
|
21
|
-
vi.mock('../codex/app-server-client.ts', () => ({
|
|
22
|
-
AppServerClient: createAppServerMock(fixture),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
vi.mock('../ws/index.ts', async (importOriginal) => {
|
|
26
|
-
const actual = (await importOriginal()) as Record<string, unknown>;
|
|
27
|
-
return {
|
|
28
|
-
...actual,
|
|
29
|
-
broadcast: vi.fn((event: string, data: unknown) => {
|
|
30
|
-
capturedBroadcasts.push({ event, data });
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const { getDb } = await import('../db/index.ts');
|
|
36
|
-
const { createTestApp, waitForTurn } = await import('./helpers/test-app.ts');
|
|
37
|
-
|
|
38
|
-
describe('Integration: item lifecycle', () => {
|
|
39
|
-
let testApp: TestApp;
|
|
40
|
-
|
|
41
|
-
beforeEach(async () => {
|
|
42
|
-
vi.clearAllMocks();
|
|
43
|
-
clearBroadcasts();
|
|
44
|
-
testApp = await createTestApp();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
afterEach(async () => {
|
|
48
|
-
await testApp.cleanup();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('processes reasoning, command, file_change, agent_message items correctly', async () => {
|
|
52
|
-
const db: Database.Database = getDb();
|
|
53
|
-
|
|
54
|
-
// Create session
|
|
55
|
-
const createRes = await testApp.app.inject({
|
|
56
|
-
method: 'POST',
|
|
57
|
-
url: '/api/sessions',
|
|
58
|
-
payload: {},
|
|
59
|
-
});
|
|
60
|
-
const session = createRes.json();
|
|
61
|
-
|
|
62
|
-
// Submit turn via HTTP
|
|
63
|
-
const turnRes = await testApp.app.inject({
|
|
64
|
-
method: 'POST',
|
|
65
|
-
url: `/api/sessions/${session.id}/turns`,
|
|
66
|
-
payload: { user_prompt: 'List files and create a test file' },
|
|
67
|
-
});
|
|
68
|
-
const turn = turnRes.json();
|
|
69
|
-
|
|
70
|
-
await waitForTurn(db, turn.id);
|
|
71
|
-
|
|
72
|
-
// Assert items in DB — all 4 types mapped correctly
|
|
73
|
-
const items = db.prepare('SELECT * FROM items WHERE turn_id = ? ORDER BY created_at ASC').all(turn.id) as {
|
|
74
|
-
type: string;
|
|
75
|
-
data: string;
|
|
76
|
-
status: string;
|
|
77
|
-
}[];
|
|
78
|
-
|
|
79
|
-
expect(items).toHaveLength(4);
|
|
80
|
-
|
|
81
|
-
// Reasoning
|
|
82
|
-
expect(items[0].type).toBe('reasoning');
|
|
83
|
-
expect(items[0].status).toBe('completed');
|
|
84
|
-
expect(JSON.parse(items[0].data)).toEqual({
|
|
85
|
-
text: 'I need to list files first, then create a test file.',
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Command execution
|
|
89
|
-
expect(items[1].type).toBe('command_execution');
|
|
90
|
-
expect(items[1].status).toBe('completed');
|
|
91
|
-
expect(JSON.parse(items[1].data)).toEqual({
|
|
92
|
-
command: 'ls -la',
|
|
93
|
-
aggregated_output: 'total 0\ndrwxr-xr-x 2 user staff 64 Jan 1 00:00 .',
|
|
94
|
-
exit_code: 0,
|
|
95
|
-
status: 'completed',
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// File change
|
|
99
|
-
expect(items[2].type).toBe('file_change');
|
|
100
|
-
expect(items[2].status).toBe('completed');
|
|
101
|
-
expect(JSON.parse(items[2].data)).toEqual({
|
|
102
|
-
changes: [{ path: 'test.txt', change_type: 'added' }],
|
|
103
|
-
status: 'completed',
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Agent message
|
|
107
|
-
expect(items[3].type).toBe('agent_message');
|
|
108
|
-
expect(items[3].status).toBe('completed');
|
|
109
|
-
expect(JSON.parse(items[3].data)).toEqual({
|
|
110
|
-
text: 'I listed the files and created test.txt for you.',
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Assert turn-level fields updated from items
|
|
114
|
-
const dbTurn = db.prepare('SELECT thoughts, agent_response FROM turns WHERE id = ?').get(turn.id) as {
|
|
115
|
-
thoughts: string | null;
|
|
116
|
-
agent_response: string | null;
|
|
117
|
-
};
|
|
118
|
-
expect(dbTurn.thoughts).toBe('I need to list files first, then create a test file.');
|
|
119
|
-
expect(dbTurn.agent_response).toBe('I listed the files and created test.txt for you.');
|
|
120
|
-
|
|
121
|
-
// Assert WS broadcasts — 4 item:started + 4 item:completed
|
|
122
|
-
const startedCount = capturedBroadcasts.filter((b) => b.event === 'item:started').length;
|
|
123
|
-
const completedCount = capturedBroadcasts.filter((b) => b.event === 'item:completed').length;
|
|
124
|
-
expect(startedCount).toBe(4);
|
|
125
|
-
expect(completedCount).toBe(4);
|
|
126
|
-
|
|
127
|
-
// Verify item:completed broadcasts contain correct item types
|
|
128
|
-
const completedTypes = capturedBroadcasts
|
|
129
|
-
.filter((b) => b.event === 'item:completed')
|
|
130
|
-
.map((b) => (b.data as { item: { type: string } }).item.type);
|
|
131
|
-
expect(completedTypes).toEqual(['reasoning', 'command_execution', 'file_change', 'agent_message']);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration test: MCP tool call item type.
|
|
3
|
-
*
|
|
4
|
-
* Verifies that mcp_tool_call items are correctly mapped via item-mapper
|
|
5
|
-
* and stored in DB with the right data shape.
|
|
6
|
-
*
|
|
7
|
-
* Uses HTTP POST to trigger the turn (fire-and-forget startTurn).
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
11
|
-
import { readFileSync } from 'node:fs';
|
|
12
|
-
import { resolve } from 'node:path';
|
|
13
|
-
import type Database from 'better-sqlite3';
|
|
14
|
-
import { createAppServerMock, type Fixture } from './helpers/app-server-mock.ts';
|
|
15
|
-
import { clearBroadcasts, capturedBroadcasts } from './helpers/ws-capture.ts';
|
|
16
|
-
import type { TestApp } from './helpers/test-app.ts';
|
|
17
|
-
|
|
18
|
-
const fixture = JSON.parse(readFileSync(resolve(__dirname, '__fixtures__/mcp-tool-call.json'), 'utf-8')) as Fixture;
|
|
19
|
-
|
|
20
|
-
vi.mock('../codex/app-server-client.ts', () => ({
|
|
21
|
-
AppServerClient: createAppServerMock(fixture),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
vi.mock('../ws/index.ts', async (importOriginal) => {
|
|
25
|
-
const actual = (await importOriginal()) as Record<string, unknown>;
|
|
26
|
-
return {
|
|
27
|
-
...actual,
|
|
28
|
-
broadcast: vi.fn((event: string, data: unknown) => {
|
|
29
|
-
capturedBroadcasts.push({ event, data });
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const { getDb } = await import('../db/index.ts');
|
|
35
|
-
const { createTestApp, waitForTurn } = await import('./helpers/test-app.ts');
|
|
36
|
-
|
|
37
|
-
describe('Integration: MCP tool call', () => {
|
|
38
|
-
let testApp: TestApp;
|
|
39
|
-
|
|
40
|
-
beforeEach(async () => {
|
|
41
|
-
vi.clearAllMocks();
|
|
42
|
-
clearBroadcasts();
|
|
43
|
-
testApp = await createTestApp();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
afterEach(async () => {
|
|
47
|
-
await testApp.cleanup();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('maps mcp_tool_call item with server, tool, arguments, result', async () => {
|
|
51
|
-
const db: Database.Database = getDb();
|
|
52
|
-
|
|
53
|
-
// Create session
|
|
54
|
-
const createRes = await testApp.app.inject({
|
|
55
|
-
method: 'POST',
|
|
56
|
-
url: '/api/sessions',
|
|
57
|
-
payload: {},
|
|
58
|
-
});
|
|
59
|
-
const session = createRes.json();
|
|
60
|
-
|
|
61
|
-
// Submit turn via HTTP
|
|
62
|
-
const turnRes = await testApp.app.inject({
|
|
63
|
-
method: 'POST',
|
|
64
|
-
url: `/api/sessions/${session.id}/turns`,
|
|
65
|
-
payload: { user_prompt: 'Search the web for cats' },
|
|
66
|
-
});
|
|
67
|
-
const turn = turnRes.json();
|
|
68
|
-
|
|
69
|
-
await waitForTurn(db, turn.id);
|
|
70
|
-
|
|
71
|
-
const items = db.prepare('SELECT * FROM items WHERE turn_id = ? ORDER BY created_at ASC').all(turn.id) as {
|
|
72
|
-
type: string;
|
|
73
|
-
data: string;
|
|
74
|
-
status: string;
|
|
75
|
-
}[];
|
|
76
|
-
expect(items).toHaveLength(2);
|
|
77
|
-
|
|
78
|
-
// MCP tool call
|
|
79
|
-
expect(items[0].type).toBe('mcp_tool_call');
|
|
80
|
-
expect(items[0].status).toBe('completed');
|
|
81
|
-
expect(JSON.parse(items[0].data)).toEqual({
|
|
82
|
-
server: 'web-search',
|
|
83
|
-
tool: 'search',
|
|
84
|
-
arguments: { query: 'cats' },
|
|
85
|
-
result: { urls: ['https://example.com/cats'] },
|
|
86
|
-
error: null,
|
|
87
|
-
status: 'completed',
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Agent message
|
|
91
|
-
expect(items[1].type).toBe('agent_message');
|
|
92
|
-
expect(items[1].status).toBe('completed');
|
|
93
|
-
|
|
94
|
-
// Verify WS: mcp item:started has in_progress status
|
|
95
|
-
const mcpStarted = capturedBroadcasts.find(
|
|
96
|
-
(b) => b.event === 'item:started' && (b.data as { item: { type: string } }).item.type === 'mcp_tool_call',
|
|
97
|
-
);
|
|
98
|
-
expect(mcpStarted).toBeDefined();
|
|
99
|
-
const mcpStartedData = mcpStarted!.data as { item: { status: string } };
|
|
100
|
-
expect(mcpStartedData.item.status).toBe('in_progress');
|
|
101
|
-
});
|
|
102
|
-
});
|