vellum 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/ipc-snapshot.test.ts.snap +28 -0
- package/src/__tests__/app-bundler.test.ts +12 -33
- package/src/__tests__/browser-skill-endstate.test.ts +1 -5
- package/src/__tests__/call-orchestrator.test.ts +328 -0
- package/src/__tests__/call-state.test.ts +133 -0
- package/src/__tests__/call-store.test.ts +476 -0
- package/src/__tests__/commit-message-enrichment-service.test.ts +409 -0
- package/src/__tests__/config-schema.test.ts +49 -0
- package/src/__tests__/doordash-session.test.ts +9 -0
- package/src/__tests__/ipc-snapshot.test.ts +34 -0
- package/src/__tests__/registry.test.ts +13 -8
- package/src/__tests__/run-orchestrator-assistant-events.test.ts +218 -0
- package/src/__tests__/run-orchestrator.test.ts +3 -3
- package/src/__tests__/runtime-attachment-metadata.test.ts +17 -19
- package/src/__tests__/runtime-runs-http.test.ts +1 -19
- package/src/__tests__/runtime-runs.test.ts +7 -7
- package/src/__tests__/session-queue.test.ts +50 -0
- package/src/__tests__/turn-commit.test.ts +56 -0
- package/src/__tests__/workspace-git-service.test.ts +217 -0
- package/src/__tests__/workspace-heartbeat-service.test.ts +129 -0
- package/src/bundler/app-bundler.ts +29 -12
- package/src/calls/call-constants.ts +10 -0
- package/src/calls/call-orchestrator.ts +364 -0
- package/src/calls/call-state.ts +64 -0
- package/src/calls/call-store.ts +229 -0
- package/src/calls/relay-server.ts +298 -0
- package/src/calls/twilio-config.ts +34 -0
- package/src/calls/twilio-provider.ts +169 -0
- package/src/calls/twilio-routes.ts +236 -0
- package/src/calls/types.ts +37 -0
- package/src/calls/voice-provider.ts +14 -0
- package/src/cli/doordash.ts +5 -24
- package/src/config/bundled-skills/doordash/SKILL.md +104 -0
- package/src/config/bundled-skills/image-studio/TOOLS.json +2 -2
- package/src/config/bundled-skills/image-studio/tools/media-generate-image.ts +1 -1
- package/src/config/defaults.ts +11 -0
- package/src/config/schema.ts +57 -0
- package/src/config/system-prompt.ts +50 -1
- package/src/config/types.ts +1 -0
- package/src/daemon/handlers/config.ts +30 -0
- package/src/daemon/handlers/index.ts +6 -0
- package/src/daemon/handlers/work-items.ts +142 -2
- package/src/daemon/ipc-contract-inventory.json +12 -0
- package/src/daemon/ipc-contract.ts +52 -0
- package/src/daemon/lifecycle.ts +27 -5
- package/src/daemon/server.ts +10 -12
- package/src/daemon/session-tool-setup.ts +6 -0
- package/src/daemon/session.ts +40 -1
- package/src/index.ts +2 -0
- package/src/media/gemini-image-service.ts +1 -1
- package/src/memory/db.ts +266 -0
- package/src/memory/schema.ts +42 -0
- package/src/runtime/http-server.ts +189 -25
- package/src/runtime/http-types.ts +0 -2
- package/src/runtime/routes/attachment-routes.ts +6 -6
- package/src/runtime/routes/channel-routes.ts +16 -18
- package/src/runtime/routes/conversation-routes.ts +5 -9
- package/src/runtime/routes/run-routes.ts +4 -8
- package/src/runtime/run-orchestrator.ts +32 -5
- package/src/tools/calls/call-end.ts +117 -0
- package/src/tools/calls/call-start.ts +134 -0
- package/src/tools/calls/call-status.ts +97 -0
- package/src/tools/credentials/vault.ts +1 -1
- package/src/tools/registry.ts +2 -4
- package/src/tools/tasks/index.ts +2 -0
- package/src/tools/tasks/task-delete.ts +49 -8
- package/src/tools/tasks/task-run.ts +9 -1
- package/src/tools/tasks/work-item-enqueue.ts +93 -3
- package/src/tools/tasks/work-item-list.ts +10 -25
- package/src/tools/tasks/work-item-remove.ts +112 -0
- package/src/tools/tasks/work-item-update.ts +186 -0
- package/src/tools/tool-manifest.ts +39 -31
- package/src/tools/ui-surface/definitions.ts +3 -0
- package/src/work-items/work-item-store.ts +209 -0
- package/src/workspace/commit-message-enrichment-service.ts +260 -0
- package/src/workspace/commit-message-provider.ts +95 -0
- package/src/workspace/git-service.ts +187 -32
- package/src/workspace/heartbeat-service.ts +70 -13
- package/src/workspace/turn-commit.ts +39 -49
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests that HTTP-triggered run/session flows mirror messages into the
|
|
3
|
+
* assistant-events hub with payload parity to IPC outbound messages.
|
|
4
|
+
*
|
|
5
|
+
* The Session class has two distinct outbound paths:
|
|
6
|
+
* 1. updateClient handler — used by the prompter for confirmation_request,
|
|
7
|
+
* trace emitter, secret prompter.
|
|
8
|
+
* 2. runAgentLoop onEvent callback — used for the primary streaming events:
|
|
9
|
+
* assistant_text_delta, message_complete, tool_use_start, tool_result, etc.
|
|
10
|
+
*
|
|
11
|
+
* Both paths must publish to the hub.
|
|
12
|
+
*
|
|
13
|
+
* Tests:
|
|
14
|
+
* - confirmation_request (updateClient path) → hub emits one AssistantEvent
|
|
15
|
+
* - assistant_text_delta + message_complete (onEvent path) → hub emits in order
|
|
16
|
+
* - sessionId falls back to conversationId when the message lacks it
|
|
17
|
+
*/
|
|
18
|
+
import { describe, test, expect, beforeEach, mock } from 'bun:test';
|
|
19
|
+
import { mkdtempSync } from 'node:fs';
|
|
20
|
+
import { tmpdir } from 'node:os';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import type { ServerMessage } from '../daemon/ipc-protocol.js';
|
|
23
|
+
import type { Session } from '../daemon/session.js';
|
|
24
|
+
import type { AssistantEvent } from '../runtime/assistant-event.js';
|
|
25
|
+
|
|
26
|
+
const testDir = mkdtempSync(join(tmpdir(), 'run-orch-hub-test-'));
|
|
27
|
+
|
|
28
|
+
mock.module('../util/platform.js', () => ({
|
|
29
|
+
getRootDir: () => testDir,
|
|
30
|
+
getDataDir: () => testDir,
|
|
31
|
+
isMacOS: () => process.platform === 'darwin',
|
|
32
|
+
isLinux: () => process.platform === 'linux',
|
|
33
|
+
isWindows: () => process.platform === 'win32',
|
|
34
|
+
getSocketPath: () => join(testDir, 'test.sock'),
|
|
35
|
+
getPidPath: () => join(testDir, 'test.pid'),
|
|
36
|
+
getDbPath: () => join(testDir, 'test.db'),
|
|
37
|
+
getLogPath: () => join(testDir, 'test.log'),
|
|
38
|
+
ensureDataDir: () => {},
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
mock.module('../util/logger.js', () => ({
|
|
42
|
+
getLogger: () => new Proxy({} as Record<string, unknown>, {
|
|
43
|
+
get: () => () => {},
|
|
44
|
+
}),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
import { initializeDb, getDb } from '../memory/db.js';
|
|
48
|
+
import { createConversation } from '../memory/conversation-store.js';
|
|
49
|
+
import { RunOrchestrator } from '../runtime/run-orchestrator.js';
|
|
50
|
+
import { assistantEventHub } from '../runtime/assistant-event-hub.js';
|
|
51
|
+
|
|
52
|
+
initializeDb();
|
|
53
|
+
|
|
54
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Build a session that calls the updateClient handler with the given messages
|
|
58
|
+
* (simulates prompter / confirmation path).
|
|
59
|
+
*/
|
|
60
|
+
function makeSessionEmittingViaClient(...messages: ServerMessage[]): Session {
|
|
61
|
+
let clientHandler: (msg: ServerMessage) => void = () => {};
|
|
62
|
+
return {
|
|
63
|
+
isProcessing: () => false,
|
|
64
|
+
persistUserMessage: () => undefined as unknown as string,
|
|
65
|
+
setAssistantId: () => {},
|
|
66
|
+
updateClient: (handler: (msg: ServerMessage) => void) => {
|
|
67
|
+
clientHandler = handler;
|
|
68
|
+
},
|
|
69
|
+
runAgentLoop: async () => {
|
|
70
|
+
for (const msg of messages) {
|
|
71
|
+
clientHandler(msg);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
handleConfirmationResponse: () => {},
|
|
75
|
+
} as unknown as Session;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Build a session that calls the onEvent callback with the given messages
|
|
80
|
+
* (simulates the primary agent-loop streaming path).
|
|
81
|
+
*/
|
|
82
|
+
function makeSessionEmittingViaAgentLoop(...messages: ServerMessage[]): Session {
|
|
83
|
+
return {
|
|
84
|
+
isProcessing: () => false,
|
|
85
|
+
persistUserMessage: () => undefined as unknown as string,
|
|
86
|
+
setAssistantId: () => {},
|
|
87
|
+
updateClient: () => {},
|
|
88
|
+
runAgentLoop: async (_content: string, _messageId: string, onEvent: (msg: ServerMessage) => void) => {
|
|
89
|
+
for (const msg of messages) {
|
|
90
|
+
onEvent(msg);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
handleConfirmationResponse: () => {},
|
|
94
|
+
} as unknown as Session;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── Tests ─────────────────────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
describe('HTTP run → confirmation_request mirrors to assistant-events hub', () => {
|
|
100
|
+
beforeEach(() => {
|
|
101
|
+
const db = getDb();
|
|
102
|
+
db.run('DELETE FROM message_runs');
|
|
103
|
+
db.run('DELETE FROM messages');
|
|
104
|
+
db.run('DELETE FROM conversations');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('confirmation_request (updateClient path) emits one AssistantEvent', async () => {
|
|
108
|
+
const conversation = createConversation('http-confirmation-test');
|
|
109
|
+
const confirmationMsg: ServerMessage = {
|
|
110
|
+
type: 'confirmation_request',
|
|
111
|
+
requestId: 'req-http-1',
|
|
112
|
+
toolName: 'bash',
|
|
113
|
+
input: { command: 'ls' },
|
|
114
|
+
riskLevel: 'medium',
|
|
115
|
+
allowlistOptions: [{ label: 'ls', description: 'List files', pattern: 'ls' }],
|
|
116
|
+
scopeOptions: [{ label: 'everywhere', scope: 'everywhere' }],
|
|
117
|
+
};
|
|
118
|
+
const session = makeSessionEmittingViaClient(confirmationMsg);
|
|
119
|
+
|
|
120
|
+
const received: AssistantEvent[] = [];
|
|
121
|
+
const sub = assistantEventHub.subscribe(
|
|
122
|
+
{ assistantId: 'self' },
|
|
123
|
+
(e) => { received.push(e); },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const orchestrator = new RunOrchestrator({
|
|
127
|
+
getOrCreateSession: async () => session,
|
|
128
|
+
resolveAttachments: () => [],
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
await orchestrator.startRun(conversation.id, 'Do something');
|
|
132
|
+
// Wait for the async hub chain to flush.
|
|
133
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
134
|
+
|
|
135
|
+
sub.dispose();
|
|
136
|
+
|
|
137
|
+
expect(received).toHaveLength(1);
|
|
138
|
+
expect(received[0].assistantId).toBe('self');
|
|
139
|
+
expect(received[0].sessionId).toBe(conversation.id);
|
|
140
|
+
expect(received[0].message.type).toBe('confirmation_request');
|
|
141
|
+
expect(received[0].message).toBe(confirmationMsg);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('HTTP run → message flow mirrors to assistant-events hub', () => {
|
|
146
|
+
beforeEach(() => {
|
|
147
|
+
const db = getDb();
|
|
148
|
+
db.run('DELETE FROM message_runs');
|
|
149
|
+
db.run('DELETE FROM messages');
|
|
150
|
+
db.run('DELETE FROM conversations');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('assistant_text_delta and message_complete (onEvent path) emit in order', async () => {
|
|
154
|
+
const conversation = createConversation('http-message-flow-test');
|
|
155
|
+
const deltaMsg: ServerMessage = {
|
|
156
|
+
type: 'assistant_text_delta',
|
|
157
|
+
sessionId: conversation.id,
|
|
158
|
+
text: 'Working on it...',
|
|
159
|
+
};
|
|
160
|
+
const completeMsg: ServerMessage = {
|
|
161
|
+
type: 'message_complete',
|
|
162
|
+
sessionId: conversation.id,
|
|
163
|
+
};
|
|
164
|
+
const session = makeSessionEmittingViaAgentLoop(deltaMsg, completeMsg);
|
|
165
|
+
|
|
166
|
+
const received: AssistantEvent[] = [];
|
|
167
|
+
const sub = assistantEventHub.subscribe(
|
|
168
|
+
{ assistantId: 'self' },
|
|
169
|
+
(e) => { received.push(e); },
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const orchestrator = new RunOrchestrator({
|
|
173
|
+
getOrCreateSession: async () => session,
|
|
174
|
+
resolveAttachments: () => [],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await orchestrator.startRun(conversation.id, 'Hello');
|
|
178
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
179
|
+
|
|
180
|
+
sub.dispose();
|
|
181
|
+
|
|
182
|
+
expect(received).toHaveLength(2);
|
|
183
|
+
expect(received[0].message.type).toBe('assistant_text_delta');
|
|
184
|
+
expect(received[1].message.type).toBe('message_complete');
|
|
185
|
+
// Both should carry the session id
|
|
186
|
+
expect(received[0].sessionId).toBe(conversation.id);
|
|
187
|
+
expect(received[1].sessionId).toBe(conversation.id);
|
|
188
|
+
// Messages are the unmodified originals
|
|
189
|
+
expect(received[0].message).toBe(deltaMsg);
|
|
190
|
+
expect(received[1].message).toBe(completeMsg);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('sessionId falls back to conversationId when message lacks it (onEvent path)', async () => {
|
|
194
|
+
const conversation = createConversation('http-session-fallback-test');
|
|
195
|
+
// pong has no sessionId field
|
|
196
|
+
const msg: ServerMessage = { type: 'pong' };
|
|
197
|
+
const session = makeSessionEmittingViaAgentLoop(msg);
|
|
198
|
+
|
|
199
|
+
const received: AssistantEvent[] = [];
|
|
200
|
+
const sub = assistantEventHub.subscribe(
|
|
201
|
+
{ assistantId: 'self' },
|
|
202
|
+
(e) => { received.push(e); },
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const orchestrator = new RunOrchestrator({
|
|
206
|
+
getOrCreateSession: async () => session,
|
|
207
|
+
resolveAttachments: () => [],
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await orchestrator.startRun(conversation.id, 'ping');
|
|
211
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
212
|
+
|
|
213
|
+
sub.dispose();
|
|
214
|
+
|
|
215
|
+
expect(received).toHaveLength(1);
|
|
216
|
+
expect(received[0].sessionId).toBe(conversation.id);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -92,7 +92,7 @@ describe('run failure detection', () => {
|
|
|
92
92
|
resolveAttachments: () => [],
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
const run = await orchestrator.startRun(
|
|
95
|
+
const run = await orchestrator.startRun(conversation.id, 'Hello');
|
|
96
96
|
|
|
97
97
|
// The agent loop fires asynchronously; give it a tick to settle.
|
|
98
98
|
await new Promise((r) => setTimeout(r, 50));
|
|
@@ -114,7 +114,7 @@ describe('run failure detection', () => {
|
|
|
114
114
|
resolveAttachments: () => [],
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
const run = await orchestrator.startRun(
|
|
117
|
+
const run = await orchestrator.startRun(conversation.id, 'Hello');
|
|
118
118
|
|
|
119
119
|
await new Promise((r) => setTimeout(r, 50));
|
|
120
120
|
|
|
@@ -192,7 +192,7 @@ describe('run approval state executionTarget', () => {
|
|
|
192
192
|
resolveAttachments: () => [],
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
const run = await orchestrator.startRun(
|
|
195
|
+
const run = await orchestrator.startRun(conversation.id, 'Run host command');
|
|
196
196
|
const stored = orchestrator.getRun(run.id);
|
|
197
197
|
expect(stored?.status).toBe('needs_confirmation');
|
|
198
198
|
expect(stored?.pendingConfirmation?.executionTarget).toBe('host');
|
|
@@ -79,11 +79,10 @@ describe('Runtime attachment metadata', () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test('GET /messages includes attachment metadata for assistant messages', async () => {
|
|
82
|
-
const assistantId = 'ast-test-1';
|
|
83
82
|
const conversationKey = 'test-conv-1';
|
|
84
83
|
|
|
85
|
-
// Set up conversation and messages
|
|
86
|
-
const mapping = getOrCreateConversation(
|
|
84
|
+
// Set up conversation and messages using "self" as the assistantId
|
|
85
|
+
const mapping = getOrCreateConversation("self", conversationKey);
|
|
87
86
|
conversationStore.addMessage(mapping.conversationId, 'user', 'Hello');
|
|
88
87
|
const assistantMsg = conversationStore.addMessage(
|
|
89
88
|
mapping.conversationId,
|
|
@@ -91,12 +90,12 @@ describe('Runtime attachment metadata', () => {
|
|
|
91
90
|
JSON.stringify([{ type: 'text', text: 'Here is a chart' }]),
|
|
92
91
|
);
|
|
93
92
|
|
|
94
|
-
// Upload and link an attachment
|
|
95
|
-
const stored = uploadAttachment(
|
|
93
|
+
// Upload and link an attachment using "self" as the assistantId
|
|
94
|
+
const stored = uploadAttachment("self", 'chart.png', 'image/png', 'iVBOR');
|
|
96
95
|
linkAttachmentToMessage(assistantMsg.id, stored.id, 0);
|
|
97
96
|
|
|
98
97
|
const res = await fetch(
|
|
99
|
-
`http://127.0.0.1:${port}/v1/
|
|
98
|
+
`http://127.0.0.1:${port}/v1/messages?conversationKey=${conversationKey}`,
|
|
100
99
|
{ headers: AUTH_HEADERS },
|
|
101
100
|
);
|
|
102
101
|
const body = await res.json() as { messages: Array<{ role: string; content: string; attachments: Array<{ id: string; filename: string; mimeType: string; sizeBytes: number; kind: string }> }> };
|
|
@@ -120,10 +119,9 @@ describe('Runtime attachment metadata', () => {
|
|
|
120
119
|
});
|
|
121
120
|
|
|
122
121
|
test('GET /messages returns empty attachments when none linked', async () => {
|
|
123
|
-
const assistantId = 'ast-test-2';
|
|
124
122
|
const conversationKey = 'test-conv-2';
|
|
125
123
|
|
|
126
|
-
const mapping = getOrCreateConversation(
|
|
124
|
+
const mapping = getOrCreateConversation("self", conversationKey);
|
|
127
125
|
conversationStore.addMessage(mapping.conversationId, 'user', 'Hello');
|
|
128
126
|
conversationStore.addMessage(
|
|
129
127
|
mapping.conversationId,
|
|
@@ -132,7 +130,7 @@ describe('Runtime attachment metadata', () => {
|
|
|
132
130
|
);
|
|
133
131
|
|
|
134
132
|
const res = await fetch(
|
|
135
|
-
`http://127.0.0.1:${port}/v1/
|
|
133
|
+
`http://127.0.0.1:${port}/v1/messages?conversationKey=${conversationKey}`,
|
|
136
134
|
{ headers: AUTH_HEADERS },
|
|
137
135
|
);
|
|
138
136
|
const body = await res.json() as { messages: Array<{ role: string; attachments: unknown[] }> };
|
|
@@ -144,11 +142,10 @@ describe('Runtime attachment metadata', () => {
|
|
|
144
142
|
});
|
|
145
143
|
|
|
146
144
|
test('GET /attachments/:id returns attachment with payload', async () => {
|
|
147
|
-
const
|
|
148
|
-
const stored = uploadAttachment(assistantId, 'report.pdf', 'application/pdf', 'JVBER');
|
|
145
|
+
const stored = uploadAttachment("self", 'report.pdf', 'application/pdf', 'JVBER');
|
|
149
146
|
|
|
150
147
|
const res = await fetch(
|
|
151
|
-
`http://127.0.0.1:${port}/v1/
|
|
148
|
+
`http://127.0.0.1:${port}/v1/attachments/${stored.id}`,
|
|
152
149
|
{ headers: AUTH_HEADERS },
|
|
153
150
|
);
|
|
154
151
|
const body = await res.json() as {
|
|
@@ -164,22 +161,23 @@ describe('Runtime attachment metadata', () => {
|
|
|
164
161
|
expect(body.sizeBytes).toBeGreaterThan(0);
|
|
165
162
|
});
|
|
166
163
|
|
|
167
|
-
test('GET /attachments/:id returns
|
|
168
|
-
const stored = uploadAttachment(
|
|
164
|
+
test('GET /attachments/:id returns attachment stored under "self"', async () => {
|
|
165
|
+
const stored = uploadAttachment("self", 'shared.txt', 'text/plain', 'c2hhcmVk');
|
|
169
166
|
|
|
170
167
|
const res = await fetch(
|
|
171
|
-
`http://127.0.0.1:${port}/v1/
|
|
168
|
+
`http://127.0.0.1:${port}/v1/attachments/${stored.id}`,
|
|
172
169
|
{ headers: AUTH_HEADERS },
|
|
173
170
|
);
|
|
174
|
-
const body = await res.json() as {
|
|
171
|
+
const body = await res.json() as { id: string; filename: string };
|
|
175
172
|
|
|
176
|
-
expect(res.status).toBe(
|
|
177
|
-
expect(body.
|
|
173
|
+
expect(res.status).toBe(200);
|
|
174
|
+
expect(body.id).toBe(stored.id);
|
|
175
|
+
expect(body.filename).toBe('shared.txt');
|
|
178
176
|
});
|
|
179
177
|
|
|
180
178
|
test('GET /attachments/:id returns 404 for nonexistent attachment', async () => {
|
|
181
179
|
const res = await fetch(
|
|
182
|
-
`http://127.0.0.1:${port}/v1/
|
|
180
|
+
`http://127.0.0.1:${port}/v1/attachments/nonexistent-id`,
|
|
183
181
|
{ headers: AUTH_HEADERS },
|
|
184
182
|
);
|
|
185
183
|
const body = await res.json() as { error: string };
|
|
@@ -127,7 +127,6 @@ function makeHangingSession(): Session {
|
|
|
127
127
|
// Tests
|
|
128
128
|
// ---------------------------------------------------------------------------
|
|
129
129
|
|
|
130
|
-
const ASSISTANT_ID = 'ast-run-http';
|
|
131
130
|
const TEST_TOKEN = 'test-bearer-token-runs';
|
|
132
131
|
const AUTH_HEADERS = { Authorization: `Bearer ${TEST_TOKEN}` };
|
|
133
132
|
|
|
@@ -164,7 +163,7 @@ describe('runtime runs — HTTP layer', () => {
|
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
function runsUrl(path = ''): string {
|
|
167
|
-
return `http://127.0.0.1:${port}/v1/
|
|
166
|
+
return `http://127.0.0.1:${port}/v1/runs${path}`;
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
// ── Auth ────────────────────────────────────────────────────────────
|
|
@@ -363,23 +362,6 @@ describe('runtime runs — HTTP layer', () => {
|
|
|
363
362
|
await stopServer();
|
|
364
363
|
});
|
|
365
364
|
|
|
366
|
-
test('GET /runs/:id returns 404 for different assistant', async () => {
|
|
367
|
-
await startServer(() => makeCompletingSession());
|
|
368
|
-
|
|
369
|
-
const createRes = await fetch(runsUrl(), {
|
|
370
|
-
method: 'POST',
|
|
371
|
-
headers: { 'Content-Type': 'application/json', ...AUTH_HEADERS },
|
|
372
|
-
body: JSON.stringify({ conversationKey: 'conv-scope', content: 'Test' }),
|
|
373
|
-
});
|
|
374
|
-
const { id } = await createRes.json() as { id: string };
|
|
375
|
-
|
|
376
|
-
// Try to access via a different assistant
|
|
377
|
-
const res = await fetch(`http://127.0.0.1:${port}/v1/assistants/other-assistant/runs/${id}`, { headers: AUTH_HEADERS });
|
|
378
|
-
expect(res.status).toBe(404);
|
|
379
|
-
|
|
380
|
-
await stopServer();
|
|
381
|
-
});
|
|
382
|
-
|
|
383
365
|
// ── POST /runs/:id/decision ─────────────────────────────────────────
|
|
384
366
|
|
|
385
367
|
test('POST /runs/:id/decision returns accepted for pending confirmation', async () => {
|
|
@@ -145,7 +145,7 @@ describe('runtime runs — swarm lifecycle', () => {
|
|
|
145
145
|
resolveAttachments: () => [],
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
const run = await orchestrator.startRun(
|
|
148
|
+
const run = await orchestrator.startRun(conversation.id, 'Build a feature');
|
|
149
149
|
expect(run.status).toBe('running');
|
|
150
150
|
|
|
151
151
|
// Wait for agent loop to complete
|
|
@@ -162,7 +162,7 @@ describe('runtime runs — swarm lifecycle', () => {
|
|
|
162
162
|
resolveAttachments: () => [],
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
const run = await orchestrator.startRun(
|
|
165
|
+
const run = await orchestrator.startRun(conversation.id, 'Run swarm');
|
|
166
166
|
|
|
167
167
|
await new Promise((r) => setTimeout(r, 50));
|
|
168
168
|
|
|
@@ -178,7 +178,7 @@ describe('runtime runs — swarm lifecycle', () => {
|
|
|
178
178
|
resolveAttachments: () => [],
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
const run = await orchestrator.startRun(
|
|
181
|
+
const run = await orchestrator.startRun(conversation.id, 'Delegate a swarm task');
|
|
182
182
|
|
|
183
183
|
// Give agent loop time to emit confirmation_request
|
|
184
184
|
await new Promise((r) => setTimeout(r, 50));
|
|
@@ -195,7 +195,7 @@ describe('runtime runs — swarm lifecycle', () => {
|
|
|
195
195
|
resolveAttachments: () => [],
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
-
const run = await orchestrator.startRun(
|
|
198
|
+
const run = await orchestrator.startRun(conversation.id, 'Run with approval');
|
|
199
199
|
await new Promise((r) => setTimeout(r, 50));
|
|
200
200
|
|
|
201
201
|
// Verify pending state
|
|
@@ -220,12 +220,12 @@ describe('runtime runs — swarm lifecycle', () => {
|
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
// First run starts and hangs
|
|
223
|
-
await orchestrator.startRun(
|
|
223
|
+
await orchestrator.startRun(conversation.id, 'First run');
|
|
224
224
|
await new Promise((r) => setTimeout(r, 20));
|
|
225
225
|
|
|
226
226
|
// Second run on the same session should be rejected
|
|
227
227
|
try {
|
|
228
|
-
await orchestrator.startRun(
|
|
228
|
+
await orchestrator.startRun(conversation.id, 'Second run');
|
|
229
229
|
// Should not reach here
|
|
230
230
|
expect(true).toBe(false);
|
|
231
231
|
} catch (err) {
|
|
@@ -252,7 +252,7 @@ describe('runtime runs — swarm lifecycle', () => {
|
|
|
252
252
|
resolveAttachments: () => [],
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
-
const run = await orchestrator.startRun(
|
|
255
|
+
const run = await orchestrator.startRun(conversation.id, 'Run with principal');
|
|
256
256
|
await new Promise((r) => setTimeout(r, 50));
|
|
257
257
|
|
|
258
258
|
const stored = orchestrator.getRun(run.id);
|
|
@@ -143,6 +143,7 @@ mock.module('../context/window-manager.js', () => ({
|
|
|
143
143
|
// ---------------------------------------------------------------------------
|
|
144
144
|
|
|
145
145
|
const turnCommitCalls: Array<{ workspaceDir: string; sessionId: string; turnNumber: number }> = [];
|
|
146
|
+
let turnCommitHangForever = false;
|
|
146
147
|
|
|
147
148
|
mock.module('../workspace/git-service.js', () => ({
|
|
148
149
|
getWorkspaceGitService: () => ({
|
|
@@ -153,6 +154,10 @@ mock.module('../workspace/git-service.js', () => ({
|
|
|
153
154
|
mock.module('../workspace/turn-commit.js', () => ({
|
|
154
155
|
commitTurnChanges: async (workspaceDir: string, sessionId: string, turnNumber: number) => {
|
|
155
156
|
turnCommitCalls.push({ workspaceDir, sessionId, turnNumber });
|
|
157
|
+
if (turnCommitHangForever) {
|
|
158
|
+
// Simulate a commit that never resolves within the timeout budget
|
|
159
|
+
await new Promise<void>(() => {});
|
|
160
|
+
}
|
|
156
161
|
},
|
|
157
162
|
}));
|
|
158
163
|
|
|
@@ -280,6 +285,7 @@ function resolveRun(index: number) {
|
|
|
280
285
|
|
|
281
286
|
beforeEach(() => {
|
|
282
287
|
turnCommitCalls.length = 0;
|
|
288
|
+
turnCommitHangForever = false;
|
|
283
289
|
linkAttachmentShouldThrow = false;
|
|
284
290
|
});
|
|
285
291
|
|
|
@@ -1459,4 +1465,48 @@ describe('Regression: cancel semantics and error channel split', () => {
|
|
|
1459
1465
|
expect(sessionErr).toBeUndefined();
|
|
1460
1466
|
}
|
|
1461
1467
|
});
|
|
1468
|
+
|
|
1469
|
+
test('commitTurnChanges never resolving within budget -> turn still completes and drains queue', async () => {
|
|
1470
|
+
const session = makeSession();
|
|
1471
|
+
await session.loadFromDb();
|
|
1472
|
+
|
|
1473
|
+
turnCommitHangForever = true;
|
|
1474
|
+
|
|
1475
|
+
const events1: ServerMessage[] = [];
|
|
1476
|
+
const events2: ServerMessage[] = [];
|
|
1477
|
+
|
|
1478
|
+
// Start first message (promise intentionally not awaited — we test queue drain behavior)
|
|
1479
|
+
const _p1 = session.processMessage('msg-1', [], (e) => events1.push(e), 'req-1');
|
|
1480
|
+
await waitForPendingRun(1);
|
|
1481
|
+
|
|
1482
|
+
// Enqueue a second message while the first is processing
|
|
1483
|
+
session.enqueueMessage('msg-2', [], (e) => events2.push(e), 'req-2');
|
|
1484
|
+
|
|
1485
|
+
// Complete the first agent loop run
|
|
1486
|
+
resolveRun(0);
|
|
1487
|
+
|
|
1488
|
+
// The turn should still complete (timeout fires) and drain the queue
|
|
1489
|
+
// even though commitTurnChanges never resolves.
|
|
1490
|
+
// The default turnCommitMaxWaitMs is 4000ms in the config mock,
|
|
1491
|
+
// but the mock config doesn't set it, so it defaults to 4000ms.
|
|
1492
|
+
// We wait for the second run to be registered, which proves the
|
|
1493
|
+
// turn completed and the queue drained despite the hanging commit.
|
|
1494
|
+
await waitForPendingRun(2, 10_000);
|
|
1495
|
+
|
|
1496
|
+
// First message should have completed
|
|
1497
|
+
const completion1 = events1.find((e) => e.type === 'message_complete');
|
|
1498
|
+
expect(completion1).toBeDefined();
|
|
1499
|
+
|
|
1500
|
+
// Second message should have been dequeued
|
|
1501
|
+
const dequeued = events2.find((e) => e.type === 'message_dequeued');
|
|
1502
|
+
expect(dequeued).toBeDefined();
|
|
1503
|
+
|
|
1504
|
+
// The turn commit should have been called
|
|
1505
|
+
expect(turnCommitCalls).toHaveLength(1);
|
|
1506
|
+
|
|
1507
|
+
// Complete the second run so the test can clean up
|
|
1508
|
+
turnCommitHangForever = false;
|
|
1509
|
+
resolveRun(1);
|
|
1510
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
1511
|
+
}, 15_000);
|
|
1462
1512
|
});
|
|
@@ -5,6 +5,7 @@ import { tmpdir } from 'node:os';
|
|
|
5
5
|
import { execFileSync } from 'node:child_process';
|
|
6
6
|
import { commitTurnChanges } from '../workspace/turn-commit.js';
|
|
7
7
|
import { WorkspaceGitService, _resetGitServiceRegistry } from '../workspace/git-service.js';
|
|
8
|
+
import type { CommitMessageProvider, CommitContext, CommitMessageResult } from '../workspace/commit-message-provider.js';
|
|
8
9
|
|
|
9
10
|
describe('commitTurnChanges', () => {
|
|
10
11
|
let testDir: string;
|
|
@@ -216,4 +217,59 @@ describe('commitTurnChanges', () => {
|
|
|
216
217
|
});
|
|
217
218
|
expect(turn1Msg).toContain('Turn: 1');
|
|
218
219
|
});
|
|
220
|
+
|
|
221
|
+
test('custom commit message provider output is used in commit', async () => {
|
|
222
|
+
const service = new WorkspaceGitService(testDir);
|
|
223
|
+
await service.ensureInitialized();
|
|
224
|
+
|
|
225
|
+
const customProvider: CommitMessageProvider = {
|
|
226
|
+
buildImmediateMessage(ctx: CommitContext): CommitMessageResult {
|
|
227
|
+
return {
|
|
228
|
+
message: `CUSTOM-TURN: session=${ctx.sessionId} turn=${ctx.turnNumber} files=${ctx.changedFiles.length}`,
|
|
229
|
+
metadata: { custom: true, provider: 'test-provider' },
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
writeFileSync(join(testDir, 'provider-test.txt'), 'provider test content');
|
|
235
|
+
|
|
236
|
+
await commitTurnChanges(testDir, 'sess_provider', 42, customProvider);
|
|
237
|
+
|
|
238
|
+
const fullMessage = execFileSync('git', ['log', '-1', '--pretty=%B'], {
|
|
239
|
+
cwd: testDir,
|
|
240
|
+
encoding: 'utf-8',
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Verify the custom provider's message was used, not the default
|
|
244
|
+
expect(fullMessage).toContain('CUSTOM-TURN: session=sess_provider turn=42 files=1');
|
|
245
|
+
expect(fullMessage).toContain('custom: true');
|
|
246
|
+
expect(fullMessage).toContain('provider: "test-provider"');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('custom provider metadata is included in commit message', async () => {
|
|
250
|
+
const service = new WorkspaceGitService(testDir);
|
|
251
|
+
await service.ensureInitialized();
|
|
252
|
+
|
|
253
|
+
const customProvider: CommitMessageProvider = {
|
|
254
|
+
buildImmediateMessage(_ctx: CommitContext): CommitMessageResult {
|
|
255
|
+
return {
|
|
256
|
+
message: 'Minimal custom message',
|
|
257
|
+
metadata: { enriched: false, source: 'unit-test' },
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
writeFileSync(join(testDir, 'meta-test.txt'), 'metadata test');
|
|
263
|
+
|
|
264
|
+
await commitTurnChanges(testDir, 'sess_meta', 1, customProvider);
|
|
265
|
+
|
|
266
|
+
const fullMessage = execFileSync('git', ['log', '-1', '--pretty=%B'], {
|
|
267
|
+
cwd: testDir,
|
|
268
|
+
encoding: 'utf-8',
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
expect(fullMessage).toContain('Minimal custom message');
|
|
272
|
+
expect(fullMessage).toContain('enriched: false');
|
|
273
|
+
expect(fullMessage).toContain('source: "unit-test"');
|
|
274
|
+
});
|
|
219
275
|
});
|