import assert from "node:assert/strict"; import test from "node:test"; import { createHermesBackendForTesting } from "../src/lib/execution/backends/hermes-backend.ts"; test("Hermes backend 只在启用且请求类型受支持时 canHandle", async () => { const backend = createHermesBackendForTesting({ config: { enabled: true, command: "hermes", args: [], timeoutMs: 45_000, sourceTag: "tool", }, runner: async () => ({ status: "completed", backendId: "hermes-runtime", output: "ok", }), }); assert.equal( await backend.canHandle({ kind: "master_agent_reply", projectId: "master-agent", requestMessageId: "msg-1", body: "继续", }), true, ); assert.equal( await backend.canHandle({ kind: "dispatch_execution", projectId: "project-1", requestMessageId: "msg-2", body: "继续", }), false, ); }); test("Hermes backend 执行时会把 executionPrompt、模型、toolsets 和 skills 交给 runner", async () => { const calls: unknown[] = []; const backend = createHermesBackendForTesting({ config: { enabled: true, command: "hermes", args: ["--profile", "prod"], timeoutMs: 45_000, defaultModel: "gpt-5.4", toolsets: ["web", "terminal"], skills: ["boss-dev"], sourceTag: "tool", }, runner: async (input) => { calls.push(input); return { status: "completed", backendId: "hermes-runtime", output: "链路正常", }; }, }); const result = await backend.execute({ kind: "master_agent_reply", projectId: "master-agent", requestMessageId: "msg-1", body: "继续推进", executionPrompt: "系统提示词 + 用户提示词 + 当前消息", modelOverride: "gpt-5.5", reasoningEffortOverride: "high", }); assert.equal(result.status, "completed"); assert.deepEqual(calls, [ { config: { enabled: true, command: "hermes", args: ["--profile", "prod"], timeoutMs: 45_000, defaultModel: "gpt-5.4", toolsets: ["web", "terminal"], skills: ["boss-dev"], sourceTag: "tool", }, payload: { kind: "master_agent_reply", projectId: "master-agent", requestMessageId: "msg-1", body: "继续推进", executionPrompt: "系统提示词 + 用户提示词 + 当前消息", model: "gpt-5.5", reasoningEffort: "high", toolsets: ["web", "terminal"], skills: ["boss-dev"], }, }, ]); }); test("Hermes backend describe 返回稳定描述", async () => { const backend = createHermesBackendForTesting({ config: { enabled: true, command: "hermes", args: [], timeoutMs: 45_000, sourceTag: "tool", }, runner: async () => ({ status: "completed", backendId: "hermes-runtime", output: "ok", }), }); const description = await backend.describe({ kind: "thread_reply", projectId: "project-1", requestMessageId: "msg-1", body: "继续", }); assert.deepEqual(description, { backendId: "hermes-runtime", label: "Hermes Runtime", mode: "local", }); });