Files
boss/tests/execution-backend-selector.test.ts
2026-04-03 01:36:29 +08:00

122 lines
4.2 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
listExecutionBackendChoices,
selectExecutionBackendForTesting,
} from "@/lib/execution/backend-selector";
test("selectExecutionBackendForTesting prefers the ready primary master codex node", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "master_codex_node", status: "ready" },
backups: [
{ provider: "aliyun_qwen_api", status: "ready" },
{ provider: "openai_api", status: "ready" },
],
});
assert.equal(backend.backendId, "master-codex-node");
});
test("selectExecutionBackendForTesting falls back to ready aliyun qwen before openai", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "master_codex_node", status: "degraded" },
backups: [
{ provider: "openai_api", status: "ready" },
{ provider: "aliyun_qwen_api", status: "ready" },
],
});
assert.equal(backend.backendId, "aliyun-qwen");
});
test("selectExecutionBackendForTesting falls back to ready openai when aliyun qwen is unavailable", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "master_codex_node", status: "degraded" },
backups: [
{ provider: "openai_api", status: "ready" },
{ provider: "aliyun_qwen_api", status: "disabled" },
],
});
assert.equal(backend.backendId, "openai-api");
});
test("selectExecutionBackendForTesting uses fixed backend order when an API primary is not ready", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "openai_api", status: "degraded" },
backups: [
{ provider: "master_codex_node", status: "ready" },
{ provider: "aliyun_qwen_api", status: "ready" },
],
});
assert.equal(backend.backendId, "aliyun-qwen");
});
test("selectExecutionBackendForTesting does not let an earlier disabled backup hide a later ready account", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "master_codex_node", status: "degraded" },
backups: [
{ provider: "openai_api", status: "disabled" },
{ provider: "openai_api", status: "ready" },
],
});
assert.equal(backend.backendId, "openai-api");
});
test("selectExecutionBackendForTesting falls back to master node last when higher-priority API backends are unavailable", async () => {
const backend = await selectExecutionBackendForTesting({
primary: { provider: "openai_api", status: "degraded" },
backups: [
{ provider: "aliyun_qwen_api", status: "disabled" },
{ provider: "master_codex_node", status: "ready" },
],
});
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");
});