fix(mcp): inherit agent when creating conversations

This commit is contained in:
shiyue
2026-06-17 15:25:34 +08:00
parent 0812763c75
commit 216f87e3b4
3 changed files with 10 additions and 15 deletions

View File

@@ -726,12 +726,13 @@ async function main() {
sourceSessionId: codexSession.sessionId,
sourceHopCount: 0,
args: {
agent: 'codex',
agent: 'claude',
title: 'MCP Created Conversation',
initialMessage: 'mcp created initial prompt',
},
});
assert(mcpCreate.status === 200 && mcpCreate.body?.ok, `MCP create conversation should succeed: ${JSON.stringify(mcpCreate.body)}`);
assert(mcpCreate.body.agent === 'codex', 'MCP create conversation should ignore agent args and inherit the source agent');
assert(mcpCreate.body.cwd === codexInitCwd, 'MCP create conversation should inherit source cwd by default');
assert(mcpCreate.body.mode === 'plan', 'MCP create conversation should inherit source mode by default');
assert(mcpCreate.body.status === 'running', 'MCP create with initialMessage should start the new conversation');
@@ -739,6 +740,7 @@ async function main() {
await nextMessage(messages, ws, (msg) => msg.type === 'background_done' && msg.sessionId === mcpCreate.body.conversationId);
const storedMcpCreated = JSON.parse(fs.readFileSync(path.join(sessionsDir, `${mcpCreate.body.conversationId}.json`), 'utf8'));
assert(storedMcpCreated.title === 'MCP Created Conversation', 'MCP created conversation should persist the requested title');
assert(storedMcpCreated.agent === 'codex', 'MCP created conversation should persist the inherited source agent');
assert(storedMcpCreated.createdFrom?.sourceSessionId === codexSession.sessionId, 'MCP created conversation should persist source metadata');
assert(storedMcpCreated.messages.some((message) => message.content === 'mcp created initial prompt' && message.crossConversation?.sourceSessionId === codexSession.sessionId), 'MCP created conversation should persist the initial cross-conversation message');
assert(storedMcpCreated.messages.some((message) => message.role === 'assistant' && /mcp created initial prompt/.test(String(message.content || ''))), 'MCP created conversation should run the initial prompt');
@@ -750,7 +752,7 @@ async function main() {
sourceSessionId: codexSession.sessionId,
sourceHopCount: 0,
args: {
agent: 'codex',
agent: 'claude',
cwd: mcpReplyCreateCwd,
title: 'MCP Reply Conversation',
initialMessage: 'mcp create request reply',
@@ -758,6 +760,7 @@ async function main() {
},
});
assert(mcpCreateReply.status === 200 && mcpCreateReply.body?.ok, `MCP create conversation with requestReply should succeed: ${JSON.stringify(mcpCreateReply.body)}`);
assert(mcpCreateReply.body.agent === 'codex', 'MCP create requestReply should inherit source agent even if args.agent is passed');
assert(mcpCreateReply.body.cwd === mcpReplyCreateCwd, 'MCP create conversation should use an explicit absolute cwd');
assert(mcpCreateReply.body.requestId && mcpCreateReply.body.replyStatus === 'waiting', 'MCP create requestReply should return a waiting request id');
await nextMessage(messages, ws, (msg) => msg.type === 'background_done' && msg.sessionId === mcpCreateReply.body.conversationId);