mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:18:28 +00:00
fix: route manual subagent spawn replies via OriginatingTo fallback
This commit is contained in:
@@ -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)"),
|
||||
|
||||
Reference in New Issue
Block a user