197 lines
6.5 KiB
TypeScript
197 lines
6.5 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("listExecutionBackendChoices keeps hermes 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,
|
|
selectable: true,
|
|
availability: {
|
|
status: "ready",
|
|
selectable: true,
|
|
configured: true,
|
|
reason: "ready",
|
|
reasonLabel: "Claw Runtime 可用。",
|
|
},
|
|
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,
|
|
selectable: false,
|
|
availability: {
|
|
status: "disabled",
|
|
selectable: false,
|
|
configured: false,
|
|
reason: "disabled",
|
|
reasonLabel: "Claw Runtime 当前未启用。",
|
|
},
|
|
supportsKinds: ["master_agent_reply"],
|
|
},
|
|
});
|
|
|
|
assert.equal(backend.backendId, "master-codex-node");
|
|
});
|
|
|
|
test("selectExecutionBackendForTesting honors an explicit hermes request when hermes 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: "hermes-runtime",
|
|
hermes: {
|
|
enabled: true,
|
|
selectable: true,
|
|
availability: {
|
|
status: "ready",
|
|
selectable: true,
|
|
configured: true,
|
|
reason: "ready",
|
|
reasonLabel: "Hermes Runtime 可用。",
|
|
},
|
|
supportsKinds: ["master_agent_reply", "thread_reply"],
|
|
},
|
|
});
|
|
|
|
assert.equal(backend.backendId, "hermes-runtime");
|
|
});
|
|
|
|
test("selectExecutionBackendForTesting falls back when hermes 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: "hermes-runtime",
|
|
hermes: {
|
|
enabled: false,
|
|
selectable: false,
|
|
availability: {
|
|
status: "disabled",
|
|
selectable: false,
|
|
configured: false,
|
|
reason: "disabled",
|
|
reasonLabel: "Hermes Runtime 当前未启用。",
|
|
},
|
|
supportsKinds: ["master_agent_reply"],
|
|
},
|
|
});
|
|
|
|
assert.equal(backend.backendId, "master-codex-node");
|
|
});
|