Files
OmniRoute/tests/unit/terminal-status-origin.test.ts
backryun 79c5bdf681 fix(release): repair v3.8.50 base-red tail after latest root lift (#10964)
Merged after conflict triage: the six base-red repair files (vi.json, opencode.ts JSDoc, context-manager test, the three webhook dispatcher tests, the uncloseai orphan-test rename) were already drained on the tip by today's #11130/#11157/#11160/#11113 — those hunks resolved to the tip shape. What lands is the production-fix set: GLM transport-aware Anthropic headers, Claude Code-compatible model-listing rejection, combo live-test single-probe, zero-cost Auto-Combo interval normalization, recovery-clearing union handling, LLMLingua real-path compare, macOS netstat PID discovery, AI Horde R2 strict public-host validation. Sweep of every touched test file: 243/243 green; typecheck + file-size clean. (guide-settings-route's 4 reds reproduce on the pure tip — pre-existing drift from #11079, not from here.) Thank you @backryun!
2026-08-22 23:09:16 -03:00

81 lines
2.3 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-t11-"));
process.env.DATA_DIR = DIR;
const core = await import("../../src/lib/db/core.ts");
const { createProviderConnection } = await import("../../src/lib/db/providers.ts");
const { runAsProbe } = await import("../../src/shared/utils/probeOrigin.ts");
const { writeTerminalStatus } = await import("../../src/shared/utils/terminalStatus.ts");
test.after(() => {
core.resetDbInstance();
fs.rmSync(DIR, { recursive: true, force: true });
});
function row(id: string): { is_active: number; test_status: string } {
const result = core
.getDbInstance()
.prepare("SELECT is_active, test_status FROM provider_connections WHERE id=?")
.get(id);
assert.ok(result && typeof result === "object");
return result as { is_active: number; test_status: string };
}
test("probe-origin writeTerminalStatus records error but never deactivates", async () => {
const conn = await createProviderConnection({
provider: "openai",
authType: "apikey",
name: "t11",
apiKey: "sk-t11",
isActive: true,
testStatus: "active",
});
const id = String(conn.id);
await runAsProbe(async () => {
await writeTerminalStatus(
id,
{
testStatus: "banned",
isActive: false,
lastError: "probe 403",
errorCode: "403",
lastErrorType: "FORBIDDEN",
},
"probe"
);
});
const r = row(id);
assert.equal(r.is_active, 1); // probe n'a jamais désactivé
assert.equal(r.test_status, "active"); // terminal non posé
});
test("production writeTerminalStatus deactivates on terminal", async () => {
const conn = await createProviderConnection({
provider: "openai",
authType: "apikey",
name: "t11b",
apiKey: "sk-t11b",
isActive: true,
testStatus: "active",
});
const id = String(conn.id);
await writeTerminalStatus(
id,
{
testStatus: "banned",
isActive: false,
lastError: "real 403",
errorCode: "403",
lastErrorType: "FORBIDDEN",
},
"production"
);
const r = row(id);
assert.equal(r.is_active, 0);
assert.equal(r.test_status, "banned");
});