mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
* test(infra): retry recursive temp-dir removal instead of failing a shard on ENOTEMPTY (#11966) Two shards on release/v3.8.51 went red in one day with the same signature — "ENOTEMPTY, Directory not empty: /tmp/omniroute-<test>-XXXXXX" — from combo-same-provider-cascade (Unit Tests fast-path 4/4, on a PR that touches only .github/) and auth-policy-embeddings-webfetch-7785 (the 20k-test TIA step). Both pass alone and on re-run: the cleanup races something still writing into the directory (SQLite WAL/-shm checkpoint, a worker, the backup) and under a loaded hosted runner the window opens. 1154 test files do their own cleanup with fs.rmSync(dir, { recursive: true, force: true }); 57 already asked for retries. One-shot codemod (scripts/ad-hoc/codemod-rm-maxretries.mjs, kept for the record): every rm / rmSync / rmdirSync option object with `recursive: true` and no `maxRetries` gains `maxRetries: 5, retryDelay: 100` — Node itself then retries ENOTEMPTY/EBUSY/EPERM for up to ~0.5 s before giving up. 2243 call sites in 1292 files under tests/, the shared tests/_setup/isolateDataDir.ts exit hook included. Only the option object changes: no call site, assertion or import is touched. Validation: prettier and ESLint (with the frozen suppressions) clean on all 1292 files; a random 20-file sample runs green (quota-redis-store hangs identically on the untouched tree — it needs a Redis on localhost, an environment matter). The four unit shards on this PR are the full run. * fix(quality): let check-forgotten-sibling-tests read a 1,000-file diff The gate shells out to `git diff` through execFileSync with Node's default 1 MB maxBuffer; the 1,292-file codemod in this PR is the first diff large enough to overflow it, and the gate died with `spawnSync git ENOBUFS` before comparing anything. 64 MB is far above any real PR and costs nothing when unused.
197 lines
5.2 KiB
TypeScript
197 lines
5.2 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 TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-nvidia-410-model-scope-"));
|
|
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "nvidia-410-model-scope-test-secret";
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const providersDb = await import("../../src/lib/db/providers.ts");
|
|
const auth = await import("../../src/sse/services/auth.ts");
|
|
const fallback = await import("../../open-sse/services/accountFallback.ts");
|
|
|
|
const DEAD_MODEL = "deepseek-ai/deepseek-v4-pro";
|
|
const HEALTHY_MODEL = "z-ai/glm-5.2";
|
|
|
|
const GONE_BODY = JSON.stringify({
|
|
type: "about:blank",
|
|
title: "Gone",
|
|
status: 410,
|
|
detail:
|
|
"The model 'deepseek-ai/deepseek-v4-pro' has reached its end of life " +
|
|
"and is no longer available.",
|
|
});
|
|
|
|
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 });
|
|
}
|
|
|
|
async function seedNvidiaConnection() {
|
|
return providersDb.createProviderConnection({
|
|
provider: "nvidia",
|
|
authType: "apikey",
|
|
name: "nvidia-410-model-scope",
|
|
apiKey: "sk-nvidia-410-model-scope",
|
|
isActive: true,
|
|
testStatus: "active",
|
|
providerSpecificData: {},
|
|
});
|
|
}
|
|
|
|
test.beforeEach(async () => {
|
|
await resetStorage();
|
|
});
|
|
|
|
test.after(async () => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("NVIDIA 410 Gone stays model-scoped and leaves the connection usable", async () => {
|
|
const connection = await seedNvidiaConnection();
|
|
|
|
assert.equal(
|
|
fallback.hasPerModelQuota("nvidia", DEAD_MODEL),
|
|
true,
|
|
"NVIDIA must use per-model failure scoping"
|
|
);
|
|
|
|
const result = await auth.markAccountUnavailable(
|
|
connection.id,
|
|
410,
|
|
GONE_BODY,
|
|
"nvidia",
|
|
DEAD_MODEL
|
|
);
|
|
|
|
assert.equal(result.shouldFallback, true);
|
|
|
|
const after = await providersDb.getProviderConnectionById(connection.id);
|
|
|
|
assert.equal(
|
|
after?.rateLimitedUntil ?? null,
|
|
null,
|
|
"410 for one retired NVIDIA model must not apply a connection-wide cooldown"
|
|
);
|
|
|
|
assert.equal(
|
|
after?.testStatus,
|
|
"active",
|
|
"410 for one retired NVIDIA model must leave the NVIDIA connection active"
|
|
);
|
|
|
|
assert.equal(
|
|
fallback.isModelLocked("nvidia", connection.id, DEAD_MODEL),
|
|
true,
|
|
"the retired model itself should be locked"
|
|
);
|
|
|
|
assert.equal(
|
|
fallback.isModelLocked("nvidia", connection.id, HEALTHY_MODEL),
|
|
false,
|
|
"a healthy sibling NVIDIA model must remain unlocked"
|
|
);
|
|
|
|
const healthyCredentials = await auth.getProviderCredentials("nvidia", null, null, HEALTHY_MODEL);
|
|
|
|
assert.equal(
|
|
healthyCredentials?.connectionId,
|
|
connection.id,
|
|
"the same NVIDIA connection must remain selectable for healthy sibling models"
|
|
);
|
|
});
|
|
|
|
test("non-per-model provider keeps 410 connection-scoped", async () => {
|
|
assert.equal(
|
|
fallback.hasPerModelQuota("openai", DEAD_MODEL),
|
|
false,
|
|
"plain OpenAI API-key connections are not per-model quota providers"
|
|
);
|
|
|
|
const connection = await providersDb.createProviderConnection({
|
|
provider: "openai",
|
|
authType: "apikey",
|
|
name: "openai-410-connection-scope",
|
|
apiKey: "sk-openai-410-connection-scope",
|
|
isActive: true,
|
|
testStatus: "active",
|
|
providerSpecificData: {},
|
|
});
|
|
|
|
const result = await auth.markAccountUnavailable(
|
|
connection.id,
|
|
410,
|
|
"Gone",
|
|
"openai",
|
|
DEAD_MODEL
|
|
);
|
|
|
|
assert.equal(result.shouldFallback, true);
|
|
|
|
const after = await providersDb.getProviderConnectionById(connection.id);
|
|
|
|
assert.ok(
|
|
after?.rateLimitedUntil,
|
|
"non-per-model providers should retain the existing connection-level 410 behavior"
|
|
);
|
|
|
|
assert.equal(
|
|
after?.testStatus,
|
|
"unavailable",
|
|
"410 model scoping must not be applied globally to every provider"
|
|
);
|
|
});
|
|
|
|
test("other per-model providers retain existing 410 connection scope", async () => {
|
|
assert.equal(
|
|
fallback.hasPerModelQuota("gemini", DEAD_MODEL),
|
|
true,
|
|
"Gemini provides a non-NVIDIA per-model control case"
|
|
);
|
|
|
|
const connection = await providersDb.createProviderConnection({
|
|
provider: "gemini",
|
|
authType: "apikey",
|
|
name: "gemini-410-control",
|
|
apiKey: "sk-gemini-410-control",
|
|
isActive: true,
|
|
testStatus: "active",
|
|
providerSpecificData: {},
|
|
});
|
|
|
|
const result = await auth.markAccountUnavailable(
|
|
connection.id,
|
|
410,
|
|
"Gone",
|
|
"gemini",
|
|
DEAD_MODEL
|
|
);
|
|
|
|
assert.equal(result.shouldFallback, true);
|
|
|
|
const after = await providersDb.getProviderConnectionById(connection.id);
|
|
|
|
assert.ok(
|
|
after?.rateLimitedUntil,
|
|
"410 must remain connection-scoped for per-model providers without an explicit 410 contract"
|
|
);
|
|
|
|
assert.equal(
|
|
after?.testStatus,
|
|
"unavailable",
|
|
"the NVIDIA-specific 410 fix must not change other provider semantics"
|
|
);
|
|
|
|
assert.equal(
|
|
fallback.isModelLocked("gemini", connection.id, DEAD_MODEL),
|
|
false,
|
|
"a generic per-model provider must not inherit NVIDIA's 410 model lock"
|
|
);
|
|
});
|