refactor: add execution backend selection
This commit is contained in:
75
tests/execution-backend-selector.test.ts
Normal file
75
tests/execution-backend-selector.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { 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");
|
||||
});
|
||||
Reference in New Issue
Block a user