feat: wire code agent runs to tool mode
This commit is contained in:
@@ -114,6 +114,34 @@ test('agent run creation is idempotent by user and request id', async () => {
|
||||
assert.equal(second.status, 'queued');
|
||||
});
|
||||
|
||||
test('agent run creation stores code tool metadata in the queued message', async () => {
|
||||
const pool = createFakePool();
|
||||
const gateway = createAgentRunGateway({
|
||||
pool,
|
||||
userAuth: {},
|
||||
tkmindProxy: {},
|
||||
autoDispatch: false,
|
||||
});
|
||||
|
||||
const run = await gateway.createRun('user-1', {
|
||||
requestId: 'req-code',
|
||||
userMessage: {
|
||||
role: 'user',
|
||||
content: [{ type: 'text', text: '修改仓库代码' }],
|
||||
metadata: { source: 'h5' },
|
||||
},
|
||||
toolMode: 'code-task',
|
||||
taskType: 'repo_refactor',
|
||||
});
|
||||
|
||||
const stored = JSON.parse(pool.runs.get(run.id).user_message_json);
|
||||
assert.equal(stored.metadata.source, 'h5');
|
||||
assert.deepEqual(stored.metadata.memindRun, {
|
||||
toolMode: 'code',
|
||||
taskType: 'repo_refactor',
|
||||
});
|
||||
});
|
||||
|
||||
test('agent run starts a session and marks submitted reply as succeeded', async () => {
|
||||
const pool = createFakePool();
|
||||
const submitted = [];
|
||||
@@ -141,6 +169,44 @@ test('agent run starts a session and marks submitted reply as succeeded', async
|
||||
assert.equal(pool.runs.get(run.id).attempts, 1);
|
||||
});
|
||||
|
||||
test('agent run with code tool mode starts and submits with code policy', async () => {
|
||||
const pool = createFakePool();
|
||||
const submitted = [];
|
||||
const codePolicy = {
|
||||
extensionOverrides: { aider: { allowed: true } },
|
||||
};
|
||||
const gateway = createAgentRunGateway({
|
||||
pool,
|
||||
userAuth: {
|
||||
async getCodeAgentSessionPolicy(userId) {
|
||||
assert.equal(userId, 'user-1');
|
||||
return codePolicy;
|
||||
},
|
||||
},
|
||||
tkmindProxy: {
|
||||
async startSessionForUser(userId, options = {}) {
|
||||
assert.equal(userId, 'user-1');
|
||||
assert.equal(options.sessionPolicy, codePolicy);
|
||||
return { id: 'session-code' };
|
||||
},
|
||||
async submitSessionReplyForUser(userId, sessionId, requestId, userMessage, options = {}) {
|
||||
submitted.push({ userId, sessionId, requestId, userMessage, options });
|
||||
},
|
||||
},
|
||||
retryDelaysMs: [],
|
||||
});
|
||||
|
||||
const run = await gateway.createRun('user-1', {
|
||||
requestId: 'req-code',
|
||||
userMessage: { role: 'user', content: [{ type: 'text', text: 'run code task' }] },
|
||||
toolMode: 'code',
|
||||
});
|
||||
|
||||
await waitFor(() => pool.runs.get(run.id)?.status === 'succeeded');
|
||||
assert.deepEqual(submitted.map((item) => item.options), [{ toolMode: 'code' }]);
|
||||
assert.equal(submitted[0].userMessage.metadata.memindRun.toolMode, 'code');
|
||||
});
|
||||
|
||||
test('agent run retries transient failures and then becomes terminal', async () => {
|
||||
const pool = createFakePool();
|
||||
const gateway = createAgentRunGateway({
|
||||
|
||||
Reference in New Issue
Block a user