feat: add claw backend adapter

This commit is contained in:
kris
2026-04-03 01:36:29 +08:00
parent 8daaea01fd
commit 39b576cc42
23 changed files with 1212 additions and 23 deletions

View File

@@ -1,6 +1,9 @@
import assert from "node:assert/strict";
import test from "node:test";
import { selectExecutionBackendForTesting } from "@/lib/execution/backend-selector";
import {
listExecutionBackendChoices,
selectExecutionBackendForTesting,
} from "@/lib/execution/backend-selector";
test("selectExecutionBackendForTesting prefers the ready primary master codex node", async () => {
const backend = await selectExecutionBackendForTesting({
@@ -73,3 +76,46 @@ test("selectExecutionBackendForTesting falls back to master node last when highe
assert.equal(backend.backendId, "master-codex-node");
});
test("listExecutionBackendChoices keeps claw disabled by default", () => {
const backends = listExecutionBackendChoices({
primary: { provider: "master_codex_node", status: "ready" },
backups: [{ provider: "openai_api", status: "ready" }],
requestKind: "master_agent_reply",
});
assert.deepEqual(
backends.map((backend) => backend.backendId),
["master-codex-node", "openai-api"],
);
});
test("selectExecutionBackendForTesting honors an explicit claw request when claw is enabled", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "master_codex_node", status: "ready" },
backups: [{ provider: "openai_api", status: "ready" }],
requestKind: "master_agent_reply",
requestedBackendId: "claw-runtime",
claw: {
enabled: true,
supportsKinds: ["master_agent_reply", "thread_reply"],
},
});
assert.equal(backend.backendId, "claw-runtime");
});
test("selectExecutionBackendForTesting falls back when claw is requested but unavailable", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "master_codex_node", status: "ready" },
backups: [{ provider: "openai_api", status: "ready" }],
requestKind: "master_agent_reply",
requestedBackendId: "claw-runtime",
claw: {
enabled: false,
supportsKinds: ["master_agent_reply"],
},
});
assert.equal(backend.backendId, "master-codex-node");
});