122 lines
2.9 KiB
TypeScript
122 lines
2.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { createClawBackendForTesting } from "../src/lib/execution/backends/claw-backend.ts";
|
|
|
|
test("Claw backend 只在启用且请求类型受支持时 canHandle", async () => {
|
|
const backend = createClawBackendForTesting({
|
|
config: {
|
|
enabled: true,
|
|
command: "claw",
|
|
args: ["run"],
|
|
timeoutMs: 45_000,
|
|
},
|
|
runner: async () => ({
|
|
status: "completed",
|
|
backendId: "claw-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("Claw backend 执行时会把 executionPrompt、模型和推理强度交给 runner", async () => {
|
|
const calls: unknown[] = [];
|
|
const backend = createClawBackendForTesting({
|
|
config: {
|
|
enabled: true,
|
|
command: "claw",
|
|
args: ["run"],
|
|
timeoutMs: 45_000,
|
|
defaultModel: "claude-sonnet",
|
|
},
|
|
runner: async (input) => {
|
|
calls.push(input);
|
|
return {
|
|
status: "completed",
|
|
backendId: "claw-runtime",
|
|
output: "链路正常",
|
|
};
|
|
},
|
|
});
|
|
|
|
const result = await backend.execute({
|
|
kind: "master_agent_reply",
|
|
projectId: "master-agent",
|
|
requestMessageId: "msg-1",
|
|
body: "继续推进",
|
|
executionPrompt: "系统提示词 + 用户提示词 + 当前消息",
|
|
modelOverride: "gpt-5.4",
|
|
reasoningEffortOverride: "high",
|
|
});
|
|
|
|
assert.equal(result.status, "completed");
|
|
assert.deepEqual(calls, [
|
|
{
|
|
config: {
|
|
enabled: true,
|
|
command: "claw",
|
|
args: ["run"],
|
|
timeoutMs: 45_000,
|
|
defaultModel: "claude-sonnet",
|
|
},
|
|
payload: {
|
|
kind: "master_agent_reply",
|
|
projectId: "master-agent",
|
|
requestMessageId: "msg-1",
|
|
body: "继续推进",
|
|
executionPrompt: "系统提示词 + 用户提示词 + 当前消息",
|
|
model: "gpt-5.4",
|
|
reasoningEffort: "high",
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("Claw backend describe 返回稳定描述", async () => {
|
|
const backend = createClawBackendForTesting({
|
|
config: {
|
|
enabled: true,
|
|
command: "claw",
|
|
args: ["run"],
|
|
timeoutMs: 45_000,
|
|
},
|
|
runner: async () => ({
|
|
status: "completed",
|
|
backendId: "claw-runtime",
|
|
output: "ok",
|
|
}),
|
|
});
|
|
|
|
const description = await backend.describe({
|
|
kind: "thread_reply",
|
|
projectId: "project-1",
|
|
requestMessageId: "msg-1",
|
|
body: "继续",
|
|
});
|
|
|
|
assert.deepEqual(description, {
|
|
backendId: "claw-runtime",
|
|
label: "Claw Runtime",
|
|
mode: "local",
|
|
});
|
|
});
|