mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:00:42 +00:00
test: share subagent command fixtures
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -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.",
|
||||
});
|
||||
|
||||
@@ -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<HandleCommandsParams["ctx"]>;
|
||||
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",
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
|
||||
@@ -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<typeof handleSubagentsSendAction>[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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user