feat: wire code agent runs to tool mode

This commit is contained in:
John
2026-07-02 07:16:47 +08:00
parent e17dcaf4a8
commit 0271d83756
6 changed files with 343 additions and 22 deletions
+74
View File
@@ -93,11 +93,85 @@ test('POST /agent/runs creates a run and returns 202', async () => {
sessionId: 'session-1',
requestId: 'req-1',
userMessage: { role: 'user', content: [] },
toolMode: 'chat',
taskType: null,
},
},
]);
});
test('POST /agent/runs accepts explicit code tool mode and task type', async () => {
const created = [];
const handler = createPostAgentRunsHandler({
userAuth: {
async ownsSession() {
return true;
},
},
agentRunGateway: {
async createRun(userId, payload) {
created.push({ userId, payload });
return { id: 'run-code', status: 'queued' };
},
},
});
const res = createResponseRecorder();
await handler(
{
currentUser: { id: 'user-1' },
body: {
session_id: 'session-1',
request_id: 'req-code',
user_message: { role: 'user', content: [] },
tool_mode: 'code-task',
task_type: 'repo_refactor',
},
},
res,
);
assert.equal(res.statusCode, 202);
assert.deepEqual(created[0].payload, {
sessionId: 'session-1',
requestId: 'req-code',
userMessage: { role: 'user', content: [] },
toolMode: 'code',
taskType: 'repo_refactor',
});
});
test('POST /agent/runs rejects unsupported tool mode', async () => {
const handler = createPostAgentRunsHandler({
userAuth: {
async ownsSession() {
throw new Error('should not check ownership after invalid mode');
},
},
agentRunGateway: {
async createRun() {
throw new Error('should not be called');
},
},
});
const res = createResponseRecorder();
await handler(
{
currentUser: { id: 'user-1' },
body: {
request_id: 'req-1',
user_message: { role: 'user', content: [] },
tool_mode: 'admin',
},
},
res,
);
assert.equal(res.statusCode, 400);
assert.match(res.body.message, /tool_mode/);
});
test('POST /agent/runs rejects a session the user does not own', async () => {
const handler = createPostAgentRunsHandler({
userAuth: {