import { readFileSync } from "node:fs"; import { rootPath } from "./src/config"; function assertCondition(condition: unknown, message: string, detail: unknown = {}): void { if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`); } const configPath = rootPath("config", "platform-infra", "sub2api-codex-pool.yaml"); const parsed = Bun.YAML.parse(readFileSync(configPath, "utf8")) as { pool?: { defaultAccountCapacity?: number; defaultTempUnschedulable?: { enabled?: boolean; rules?: Array<{ statusCode?: number; keywords?: string[]; durationMinutes?: number }>; }; }; profiles?: { entries?: Array<{ profile?: string; accountName?: string; capacity?: number; openaiResponsesWebSocketsV2Mode?: string | null }> }; }; const entries = parsed.profiles?.entries ?? []; const hy = entries.find((entry) => entry.profile === "HY"); const wsEnabled = entries.filter((entry) => entry.openaiResponsesWebSocketsV2Mode && entry.openaiResponsesWebSocketsV2Mode !== "off"); const rules = parsed.pool?.defaultTempUnschedulable?.rules ?? []; const overload429 = rules.find((rule) => rule.statusCode === 429); assertCondition(parsed.pool?.defaultAccountCapacity === 5, "Codex pool default capacity should remain explicit YAML", parsed.pool); assertCondition(hy !== undefined, "HY profile should remain declared as a candidate, not a special scheduler target", entries); assertCondition(hy?.capacity === undefined, "HY must not carry a hard-coded capacity override", hy); assertCondition(wsEnabled.length >= 2, "Responses WSv2 should be a capability set with multiple candidates", wsEnabled); assertCondition(parsed.pool?.defaultTempUnschedulable?.enabled === true, "temporary unschedulable policy must be enabled from YAML", parsed.pool?.defaultTempUnschedulable); assertCondition(overload429 !== undefined, "temporary unschedulable policy must include 429 handling", rules); assertCondition(overload429?.keywords?.includes("too many requests"), "429 handling must catch provider concurrency/rate-limit text", overload429); assertCondition((overload429?.durationMinutes ?? 0) > 0, "429 handling must cool down for a positive duration", overload429); console.log(JSON.stringify({ ok: true, checks: [ "HY is not capacity-pinned", "WSv2 routing is represented as a multi-account capability set", "temporary unschedulable rules are YAML-controlled", ], }));