Files
OmniRoute/tests/unit/nvidia-410-model-scope.test.ts
Diego Rodrigues de Sa e Souza 93265eede3 test(infra): retry recursive temp-dir removal on main (main twin of #11968) (#12246)
* test(infra): retry recursive temp-dir removal on main (main twin of #11968)

`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.

* chore(scripts): carry the rm-maxretries codemod onto main alongside its output

The codemod that generated the previous commit lives in the repo on
release/v3.8.51 (added by #11968) but was never on main. Bringing it over keeps
the tool next to the change it produced, so the transformation stays
reproducible and auditable from either branch.
2026-09-01 01:48:00 -03:00

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"
);
});