fix: route native subagent spawns to target session

This commit is contained in:
Peter Steinberger
2026-02-18 02:35:51 +00:00
parent 40a6661597
commit c1928845ac
2 changed files with 28 additions and 3 deletions

View File

@@ -150,6 +150,22 @@ describe("/subagents spawn command", () => {
});
});
it("prefers CommandTargetSessionKey for native /subagents spawn", async () => {
spawnSubagentDirectMock.mockResolvedValue(acceptedResult());
const params = buildCommandTestParams("/subagents spawn beta do the thing", baseCfg, {
CommandSource: "native",
CommandTargetSessionKey: "agent:main:main",
});
params.sessionKey = "agent:main:slack:slash:u1";
const result = await handleSubagentsCommand(params, true);
expect(result).not.toBeNull();
expect(result?.reply?.text).toContain("Spawned subagent beta");
const [, spawnCtx] = spawnSubagentDirectMock.mock.calls[0];
expect(spawnCtx.agentSessionKey).toBe("agent:main:main");
});
it("returns forbidden for unauthorized cross-agent spawn", async () => {
spawnSubagentDirectMock.mockResolvedValue(
forbiddenResult("agentId is not allowed for sessions_spawn (allowed: alpha)"),