mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 13:52:28 +03:00
`main` has been red since b342c1a361 on the vitest and integration gates:
✖ tests/unit/autoCombo/provider-family-combos.test.ts > auto/<family>
✖ chat pipeline applies Codex OAuth fingerprint and priority tier inside combos
Both call resetStorage() from beforeEach, which does an fs.rmSync(TEST_DATA_DIR,
{recursive: true, force: true}) with no retry, and intermittently loses the race
with a not-yet-released SQLite handle (ENOTEMPTY).
release/v3.8.51 fixed this in #11968 with a mechanical codemod adding
maxRetries/retryDelay to every recursive rm/rmSync/rmdirSync under tests/, but
that PR landed only on the release branch. Because main only receives work at
the release squash, it stayed broken for the whole cycle — and repo-wide gates
then turn every open PR into main red on checks unrelated to their diff.
This is the --base main twin: re-runs the same codemod that already shipped on
the release branch (scripts/ad-hoc/codemod-rm-maxretries.mjs), so the two
branches converge on identical test-teardown semantics. Test-only; no product
logic is touched.
The remaining three failures reported on #12133 (unit full suite exceeding its
4800s ceiling, package-artifact exceeding 1200s, and the boot-smoke that is
skipped as a consequence) are runner-contention timeouts, not code defects —
validate-release-green.mjs runs those heavy gates concurrently on one shared
hosted runner. There is no fix to port for those.
96 lines
3.5 KiB
TypeScript
96 lines
3.5 KiB
TypeScript
/**
|
|
* TDD — proxy resolution must not hand out a proxy that has been explicitly
|
|
* marked dead (status inactive/error/disabled). Today the resolution queries
|
|
* JOIN proxy_registry without any status filter, so an operator (or a health
|
|
* check) marking a proxy dead has no effect — it keeps being assigned, every
|
|
* request pays the timeout, and accounts fail. Part of the codex-invalidation
|
|
* proxy hardening.
|
|
*
|
|
* Conservative: only EXCLUDE explicit dead states; active/null/unknown stay
|
|
* usable so we never strand a working proxy.
|
|
*/
|
|
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 TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-proxy-status-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
process.env.API_KEY_SECRET = "test-secret";
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const proxiesDb = await import("../../src/lib/db/proxies.ts");
|
|
|
|
async function resetStorage() {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
}
|
|
|
|
test.after(async () => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("resolution SKIPS an account proxy marked inactive", async () => {
|
|
await resetStorage();
|
|
const proxy = await proxiesDb.createProxy({
|
|
name: "Dead Account Proxy",
|
|
type: "http",
|
|
host: "127.0.0.1",
|
|
port: 9991,
|
|
});
|
|
await proxiesDb.updateProxy(proxy!.id, { status: "inactive" });
|
|
await proxiesDb.assignProxyToScope("account", "conn-dead", proxy!.id);
|
|
|
|
const resolved = await proxiesDb.resolveProxyForConnectionFromRegistry("conn-dead");
|
|
assert.equal(resolved, null, "a dead account proxy must not be resolved");
|
|
});
|
|
|
|
test("resolution STILL returns an active account proxy", async () => {
|
|
await resetStorage();
|
|
const proxy = await proxiesDb.createProxy({
|
|
name: "Live Account Proxy",
|
|
type: "http",
|
|
host: "127.0.0.1",
|
|
port: 8081,
|
|
});
|
|
await proxiesDb.assignProxyToScope("account", "conn-live", proxy!.id);
|
|
|
|
const resolved = await proxiesDb.resolveProxyForConnectionFromRegistry("conn-live");
|
|
assert.ok(resolved, "active proxy must resolve");
|
|
assert.equal((resolved as any).proxy.host, "127.0.0.1");
|
|
assert.equal((resolved as any).level, "account");
|
|
});
|
|
|
|
test("scope resolver skips a dead provider proxy (status=error)", async () => {
|
|
await resetStorage();
|
|
const provProxy = await proxiesDb.createProxy({
|
|
name: "Dead Provider Proxy",
|
|
type: "http",
|
|
host: "10.0.0.1",
|
|
port: 9992,
|
|
});
|
|
await proxiesDb.updateProxy(provProxy!.id, { status: "error" });
|
|
await proxiesDb.assignProxyToScope("provider", "codex", provProxy!.id);
|
|
|
|
const resolved = await proxiesDb.resolveProxyForScopeFromRegistry("provider", "codex");
|
|
assert.equal(resolved, null, "a dead provider proxy must not be resolved");
|
|
});
|
|
|
|
test("scope resolver still returns a live global proxy", async () => {
|
|
await resetStorage();
|
|
const globalProxy = await proxiesDb.createProxy({
|
|
name: "Live Global Proxy",
|
|
type: "http",
|
|
host: "10.0.0.2",
|
|
port: 8082,
|
|
});
|
|
await proxiesDb.assignProxyToScope("global", null, globalProxy!.id);
|
|
|
|
const resolved = await proxiesDb.resolveProxyForScopeFromRegistry("global");
|
|
assert.ok(resolved, "live global proxy must resolve");
|
|
assert.equal((resolved as any).proxy.host, "10.0.0.2");
|
|
});
|