fix: correct merge order so project agents override user agents
Address PR review comment: project agents should take precedence over user agents when both define the same agent name.
This commit is contained in:
@@ -622,6 +622,36 @@ describe("resolveSubagentExecution", () => {
|
||||
connectedSpy.mockRestore()
|
||||
})
|
||||
|
||||
test("project agent takes precedence over user agent with same name", async () => {
|
||||
//#given
|
||||
mockLoadUserAgents.mockReturnValue({
|
||||
"my-custom-agent": {
|
||||
description: "User agent",
|
||||
mode: "subagent",
|
||||
prompt: "User prompt",
|
||||
model: "minimaxi/claude-3-haiku",
|
||||
},
|
||||
})
|
||||
mockLoadProjectAgents.mockReturnValue({
|
||||
"my-custom-agent": {
|
||||
description: "Project agent",
|
||||
mode: "subagent",
|
||||
prompt: "Project prompt",
|
||||
model: "minimaxi/MiniMax-M2.7-highspeed",
|
||||
},
|
||||
})
|
||||
|
||||
const args = createBaseArgs({ subagent_type: "my-custom-agent" })
|
||||
const executorCtx = createExecutorContext(async () => [])
|
||||
|
||||
//#when
|
||||
const result = await resolveSubagentExecution(args, executorCtx, "sisyphus", "deep")
|
||||
|
||||
//#then
|
||||
expect(result.error).toBeUndefined()
|
||||
expect(result.agentToUse).toBe("my-custom-agent")
|
||||
})
|
||||
|
||||
test("filters out primary agents from user/project when resolving", async () => {
|
||||
//#given
|
||||
mockLoadUserAgents.mockReturnValue({
|
||||
|
||||
@@ -92,14 +92,14 @@ Create the work plan directly - that's your job as the planning agent.`,
|
||||
mergedAgentMap.set(agent.name.toLowerCase(), agent)
|
||||
}
|
||||
|
||||
// Then add user agents (server wins on collision)
|
||||
// Then add user agents (server/project agents win on collision)
|
||||
for (const agent of userAgentsList) {
|
||||
if (!mergedAgentMap.has(agent.name.toLowerCase())) {
|
||||
mergedAgentMap.set(agent.name.toLowerCase(), agent)
|
||||
}
|
||||
}
|
||||
|
||||
// Then add project agents (server wins on collision)
|
||||
// Then add project agents (overrides user agents, server wins on collision)
|
||||
for (const agent of projectAgentsList) {
|
||||
if (!mergedAgentMap.has(agent.name.toLowerCase())) {
|
||||
mergedAgentMap.set(agent.name.toLowerCase(), agent)
|
||||
|
||||
Reference in New Issue
Block a user