diff --git a/src/auto-reply/reply/commands-subagents-focus.test.ts b/src/auto-reply/reply/commands-subagents-focus.test.ts index 06fbe0a98f5..0fd7f7c3672 100644 --- a/src/auto-reply/reply/commands-subagents-focus.test.ts +++ b/src/auto-reply/reply/commands-subagents-focus.test.ts @@ -2,10 +2,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../../config/config.js"; import type { SessionEntry } from "../../config/sessions/types.js"; import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js"; +import { createEmptyInlineDirectives } from "./commands-subagents.test-helpers.js"; import { handleSubagentsFocusAction } from "./commands-subagents/action-focus.js"; import { handleSubagentsUnfocusAction } from "./commands-subagents/action-unfocus.js"; import type { HandleCommandsParams } from "./commands-types.js"; -import type { InlineDirectives } from "./directive-handling.js"; const THREAD_CHANNEL = "thread-chat"; const ROOM_CHANNEL = "room-chat"; @@ -159,26 +159,6 @@ function buildCommandParams(params?: { senderId?: string; sessionEntry?: SessionEntry; }): HandleCommandsParams { - const directives: InlineDirectives = { - cleaned: "", - hasThinkDirective: false, - hasVerboseDirective: false, - hasFastDirective: false, - hasReasoningDirective: false, - hasTraceDirective: false, - hasElevatedDirective: false, - hasExecDirective: false, - hasExecOptions: false, - invalidExecHost: false, - invalidExecSecurity: false, - invalidExecAsk: false, - invalidExecNode: false, - hasStatusDirective: false, - hasModelDirective: false, - hasQueueDirective: false, - queueReset: false, - hasQueueOptions: false, - }; return { cfg: params?.cfg ?? baseCfg, ctx: { @@ -194,7 +174,7 @@ function buildCommandParams(params?: { rawBodyNormalized: "", commandBodyNormalized: "", }, - directives, + directives: createEmptyInlineDirectives(), elevated: { enabled: false, allowed: false, failures: [] }, sessionEntry: params?.sessionEntry, sessionKey: "agent:main:main", diff --git a/src/auto-reply/reply/commands-subagents-send-steer.test-support.ts b/src/auto-reply/reply/commands-subagents-send-steer.test-support.ts index e1c950ab207..85aeb4bf48f 100644 --- a/src/auto-reply/reply/commands-subagents-send-steer.test-support.ts +++ b/src/auto-reply/reply/commands-subagents-send-steer.test-support.ts @@ -1,5 +1,16 @@ +import { vi } from "vitest"; import { buildSubagentsSendContext } from "./commands-subagents.test-helpers.js"; +export const subagentControlMocks = { + sendControlledSubagentMessage: vi.fn(), + steerControlledSubagentRun: vi.fn(), +}; + +vi.doMock("./commands-subagents-control.runtime.js", () => ({ + sendControlledSubagentMessage: subagentControlMocks.sendControlledSubagentMessage, + steerControlledSubagentRun: subagentControlMocks.steerControlledSubagentRun, +})); + export function buildSubagentsDispatchContext(params: { handledPrefix: string; restTokens: string[]; diff --git a/src/auto-reply/reply/commands-subagents-send.test.ts b/src/auto-reply/reply/commands-subagents-send.test.ts index dafc0f8c455..33793f948d8 100644 --- a/src/auto-reply/reply/commands-subagents-send.test.ts +++ b/src/auto-reply/reply/commands-subagents-send.test.ts @@ -1,15 +1,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; -import { buildSubagentsDispatchContext } from "./commands-subagents-send-steer.test-support.js"; +import { + buildSubagentsDispatchContext, + subagentControlMocks, +} from "./commands-subagents-send-steer.test-support.js"; import { handleSubagentsSendAction } from "./commands-subagents/action-send.js"; -const sendControlledSubagentMessageMock = vi.hoisted(() => vi.fn()); -const steerControlledSubagentRunMock = vi.hoisted(() => vi.fn()); - -vi.mock("./commands-subagents-control.runtime.js", () => ({ - sendControlledSubagentMessage: sendControlledSubagentMessageMock, - steerControlledSubagentRun: steerControlledSubagentRunMock, -})); - const buildContext = () => buildSubagentsDispatchContext({ handledPrefix: "/subagents", @@ -22,7 +17,7 @@ describe("subagents send action", () => { }); it("formats accepted send replies", async () => { - sendControlledSubagentMessageMock.mockResolvedValue({ + subagentControlMocks.sendControlledSubagentMessage.mockResolvedValue({ status: "accepted", runId: "run-followup-1", replyText: "custom reply", @@ -35,7 +30,7 @@ describe("subagents send action", () => { }); it("formats forbidden send replies", async () => { - sendControlledSubagentMessageMock.mockResolvedValue({ + subagentControlMocks.sendControlledSubagentMessage.mockResolvedValue({ status: "forbidden", error: "Leaf subagents cannot control other sessions.", }); diff --git a/src/auto-reply/reply/commands-subagents-spawn-action.test.ts b/src/auto-reply/reply/commands-subagents-spawn-action.test.ts index 9abbad931bf..ff7f5517813 100644 --- a/src/auto-reply/reply/commands-subagents-spawn-action.test.ts +++ b/src/auto-reply/reply/commands-subagents-spawn-action.test.ts @@ -2,9 +2,9 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import type { SpawnSubagentResult } from "../../agents/subagent-spawn.js"; import type { OpenClawConfig } from "../../config/config.js"; import type { SessionEntry } from "../../config/sessions/types.js"; +import { createEmptyInlineDirectives } from "./commands-subagents.test-helpers.js"; import { handleSubagentsSpawnAction } from "./commands-subagents/action-spawn.js"; import type { HandleCommandsParams } from "./commands-types.js"; -import type { InlineDirectives } from "./directive-handling.js"; const spawnSubagentDirectMock = vi.hoisted(() => vi.fn()); @@ -41,26 +41,6 @@ function buildContext(params?: { context?: Partial; sessionEntry?: SessionEntry | undefined; }) { - const directives: InlineDirectives = { - cleaned: "", - hasThinkDirective: false, - hasVerboseDirective: false, - hasFastDirective: false, - hasReasoningDirective: false, - hasTraceDirective: false, - hasElevatedDirective: false, - hasExecDirective: false, - hasExecOptions: false, - invalidExecHost: false, - invalidExecSecurity: false, - invalidExecAsk: false, - invalidExecNode: false, - hasStatusDirective: false, - hasModelDirective: false, - hasQueueDirective: false, - queueReset: false, - hasQueueOptions: false, - }; const ctx = { OriginatingChannel: "whatsapp", OriginatingTo: "channel:origin", @@ -82,7 +62,7 @@ function buildContext(params?: { commandBodyNormalized: "", to: params?.commandTo ?? "channel:command", }, - directives, + directives: createEmptyInlineDirectives(), elevated: { enabled: false, allowed: false, failures: [] }, sessionKey: "agent:main:main", workspaceDir: "/tmp/openclaw-subagents-spawn", diff --git a/src/auto-reply/reply/commands-subagents-steer.test.ts b/src/auto-reply/reply/commands-subagents-steer.test.ts index b883b467f5d..a1ca8e9e311 100644 --- a/src/auto-reply/reply/commands-subagents-steer.test.ts +++ b/src/auto-reply/reply/commands-subagents-steer.test.ts @@ -1,15 +1,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; -import { buildSubagentsDispatchContext } from "./commands-subagents-send-steer.test-support.js"; +import { + buildSubagentsDispatchContext, + subagentControlMocks, +} from "./commands-subagents-send-steer.test-support.js"; import { handleSubagentsSendAction } from "./commands-subagents/action-send.js"; -const sendControlledSubagentMessageMock = vi.hoisted(() => vi.fn()); -const steerControlledSubagentRunMock = vi.hoisted(() => vi.fn()); - -vi.mock("./commands-subagents-control.runtime.js", () => ({ - sendControlledSubagentMessage: sendControlledSubagentMessageMock, - steerControlledSubagentRun: steerControlledSubagentRunMock, -})); - const buildContext = () => buildSubagentsDispatchContext({ handledPrefix: "/steer", @@ -22,7 +17,7 @@ describe("subagents steer action", () => { }); it("formats accepted steer replies", async () => { - steerControlledSubagentRunMock.mockResolvedValue({ + subagentControlMocks.steerControlledSubagentRun.mockResolvedValue({ status: "accepted", runId: "run-steer-1", }); @@ -34,7 +29,7 @@ describe("subagents steer action", () => { }); it("formats steer dispatch errors", async () => { - steerControlledSubagentRunMock.mockResolvedValue({ + subagentControlMocks.steerControlledSubagentRun.mockResolvedValue({ status: "error", error: "dispatch failed", }); diff --git a/src/auto-reply/reply/commands-subagents.test-helpers.ts b/src/auto-reply/reply/commands-subagents.test-helpers.ts index cf0756125bf..cbf9f117423 100644 --- a/src/auto-reply/reply/commands-subagents.test-helpers.ts +++ b/src/auto-reply/reply/commands-subagents.test-helpers.ts @@ -1,6 +1,7 @@ import type { SubagentRunRecord } from "../../agents/subagent-registry.types.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; import type { handleSubagentsSendAction } from "./commands-subagents/action-send.js"; +import type { InlineDirectives } from "./directive-handling.js"; export function buildSubagentRun(): SubagentRunRecord { return { @@ -42,3 +43,26 @@ export function buildSubagentsSendContext(params?: { restTokens: params?.restTokens ?? [], } as Parameters[0]; } + +export function createEmptyInlineDirectives(): InlineDirectives { + return { + cleaned: "", + hasThinkDirective: false, + hasVerboseDirective: false, + hasFastDirective: false, + hasReasoningDirective: false, + hasTraceDirective: false, + hasElevatedDirective: false, + hasExecDirective: false, + hasExecOptions: false, + invalidExecHost: false, + invalidExecSecurity: false, + invalidExecAsk: false, + invalidExecNode: false, + hasStatusDirective: false, + hasModelDirective: false, + hasQueueDirective: false, + queueReset: false, + hasQueueOptions: false, + }; +}