feat(plugin): register team-mode tools and expand registry tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { beforeEach, describe, expect, mock, spyOn, test } from "bun:test"
|
||||
const { beforeEach, describe, expect, mock, spyOn, test } = require("bun:test")
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
|
||||
import type { OhMyOpenCodeConfig } from "../config"
|
||||
import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "../config"
|
||||
import * as openclawRuntimeDispatch from "../openclaw/runtime-dispatch"
|
||||
import type { ToolsRecord } from "./types"
|
||||
|
||||
@@ -28,6 +28,21 @@ const syncSessionCreatedCallbacks: Array<
|
||||
const trackedPaneBySession = new Map<string, string>()
|
||||
let dispatchOpenClawEvent: ReturnType<typeof spyOn>
|
||||
|
||||
const TEAM_TOOL_NAMES = [
|
||||
"team_create",
|
||||
"team_delete",
|
||||
"team_shutdown_request",
|
||||
"team_approve_shutdown",
|
||||
"team_reject_shutdown",
|
||||
"team_send_message",
|
||||
"team_task_create",
|
||||
"team_task_list",
|
||||
"team_task_update",
|
||||
"team_task_get",
|
||||
"team_status",
|
||||
"team_list",
|
||||
] as const
|
||||
|
||||
const { createToolRegistry, trimToolsToCap } = await import("./tool-registry")
|
||||
|
||||
const toolFactories: NonNullable<Parameters<typeof createToolRegistry>[0]["toolFactories"]> = {
|
||||
@@ -52,17 +67,33 @@ const toolFactories: NonNullable<Parameters<typeof createToolRegistry>[0]["toolF
|
||||
createTaskList: mock(() => fakeTool),
|
||||
createTaskUpdateTool: mock(() => fakeTool),
|
||||
createHashlineEditTool: mock(() => fakeTool),
|
||||
createTeamApproveShutdownTool: mock(() => fakeTool),
|
||||
createTeamCreateTool: mock(() => fakeTool),
|
||||
createTeamDeleteTool: mock(() => fakeTool),
|
||||
createTeamRejectShutdownTool: mock(() => fakeTool),
|
||||
createTeamShutdownRequestTool: mock(() => fakeTool),
|
||||
createTeamSendMessageTool: mock(() => fakeTool),
|
||||
createTeamTaskCreateTool: mock(() => fakeTool),
|
||||
createTeamTaskGetTool: mock(() => fakeTool),
|
||||
createTeamTaskListTool: mock(() => fakeTool),
|
||||
createTeamTaskUpdateTool: mock(() => fakeTool),
|
||||
createTeamStatusTool: mock(() => fakeTool),
|
||||
createTeamListTool: mock(() => fakeTool),
|
||||
}
|
||||
|
||||
function createPluginConfig(overrides: Partial<OhMyOpenCodeConfig> = {}): OhMyOpenCodeConfig {
|
||||
return {
|
||||
type PluginConfigOverrides = Omit<Partial<OhMyOpenCodeConfig>, "team_mode"> & {
|
||||
team_mode?: Partial<NonNullable<OhMyOpenCodeConfig["team_mode"]>>
|
||||
}
|
||||
|
||||
function createPluginConfig(overrides: PluginConfigOverrides = {}): OhMyOpenCodeConfig {
|
||||
return OhMyOpenCodeConfigSchema.parse({
|
||||
git_master: {
|
||||
commit_footer: false,
|
||||
include_co_authored_by: false,
|
||||
git_env_prefix: "",
|
||||
},
|
||||
...overrides,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -146,6 +177,68 @@ describe("#given task_system configuration", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given team_mode configuration", () => {
|
||||
test("#when team_mode is enabled #then all 12 team tools are registered", () => {
|
||||
syncSessionCreatedCallbacks.length = 0
|
||||
|
||||
const result = createToolRegistry({
|
||||
ctx: { directory: "/tmp" } as Parameters<typeof createToolRegistry>[0]["ctx"],
|
||||
pluginConfig: createPluginConfig({
|
||||
team_mode: {
|
||||
enabled: true,
|
||||
},
|
||||
}),
|
||||
managers: {
|
||||
backgroundManager: {},
|
||||
tmuxSessionManager: {},
|
||||
skillMcpManager: {},
|
||||
} as Parameters<typeof createToolRegistry>[0]["managers"],
|
||||
skillContext: {
|
||||
mergedSkills: [],
|
||||
availableSkills: [],
|
||||
browserProvider: "playwright",
|
||||
disabledSkills: new Set(),
|
||||
},
|
||||
availableCategories: [],
|
||||
toolFactories,
|
||||
})
|
||||
|
||||
for (const teamToolName of TEAM_TOOL_NAMES) {
|
||||
expect(result.filteredTools).toHaveProperty(teamToolName)
|
||||
}
|
||||
})
|
||||
|
||||
test("#when team_mode is disabled #then zero team tools are registered", () => {
|
||||
syncSessionCreatedCallbacks.length = 0
|
||||
|
||||
const result = createToolRegistry({
|
||||
ctx: { directory: "/tmp" } as Parameters<typeof createToolRegistry>[0]["ctx"],
|
||||
pluginConfig: createPluginConfig({
|
||||
team_mode: {
|
||||
enabled: false,
|
||||
},
|
||||
}),
|
||||
managers: {
|
||||
backgroundManager: {},
|
||||
tmuxSessionManager: {},
|
||||
skillMcpManager: {},
|
||||
} as Parameters<typeof createToolRegistry>[0]["managers"],
|
||||
skillContext: {
|
||||
mergedSkills: [],
|
||||
availableSkills: [],
|
||||
browserProvider: "playwright",
|
||||
disabledSkills: new Set(),
|
||||
},
|
||||
availableCategories: [],
|
||||
toolFactories,
|
||||
})
|
||||
|
||||
const registeredTeamToolNames = Object.keys(result.filteredTools).filter((toolName) => toolName.startsWith("team_"))
|
||||
|
||||
expect(registeredTeamToolNames).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given tmux integration is disabled", () => {
|
||||
test("#when system tmux is available #then interactive_bash remains registered", () => {
|
||||
syncSessionCreatedCallbacks.length = 0
|
||||
|
||||
Reference in New Issue
Block a user