fix: route manual subagent spawn replies via OriginatingTo fallback

This commit is contained in:
Peter Steinberger
2026-02-18 03:48:02 +01:00
parent 4134875c31
commit 34851a78b2
2 changed files with 25 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
import type { SpawnSubagentResult } from "../../agents/subagent-spawn.js";
import type { OpenClawConfig } from "../../config/config.js";
import { resetSubagentRegistryForTests } from "../../agents/subagent-registry.js";
const hoisted = vi.hoisted(() => {
const spawnSubagentDirectMock = vi.fn();
@@ -170,6 +170,21 @@ describe("/subagents spawn command", () => {
expect(spawnCtx.agentTo).toBe("channel:12345");
});
it("falls back to OriginatingTo for agentTo when command.to is missing", async () => {
spawnSubagentDirectMock.mockResolvedValue(acceptedResult());
const params = buildCommandTestParams("/subagents spawn beta do the thing", baseCfg, {
OriginatingTo: "channel:manual",
To: "channel:fallback-from-to",
});
params.command.to = undefined;
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).toMatchObject({ agentTo: "channel:manual" });
});
it("returns forbidden for unauthorized cross-agent spawn", async () => {
spawnSubagentDirectMock.mockResolvedValue(
forbiddenResult("agentId is not allowed for sessions_spawn (allowed: alpha)"),