mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +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.
131 lines
4.9 KiB
TypeScript
131 lines
4.9 KiB
TypeScript
/**
|
|
* #6714 follow-up — `getExplicitModelOutputCap` must fall through to the
|
|
* registry/spec output cap when a `synced` capability row exists but its
|
|
* `limit_output` is not a number.
|
|
*
|
|
* Root cause: the function used to short-circuit to `null` on ANY truthy
|
|
* `synced` row:
|
|
*
|
|
* if (synced) return typeof synced.limit_output === "number" ? synced.limit_output : null;
|
|
*
|
|
* models.dev rows commonly omit `limit_output` (it stays `null`) even when
|
|
* the model itself has a well-known output cap registered in
|
|
* `providerRegistry.ts`. In that case the old code returned `null` instead
|
|
* of falling through — silently disabling the reasoning-token-buffer
|
|
* clamp added by #6714 (`clampReasoningTokensToOutputCap` in
|
|
* open-sse/services/combo.ts) for any model that happens to have a synced
|
|
* row without an output limit.
|
|
*
|
|
* The fix mirrors the `??`-chain precedence already used by
|
|
* `getResolvedModelCapabilities().maxOutputTokens`:
|
|
*
|
|
* synced?.limit_output ?? registryModel?.maxOutputTokens ?? spec?.maxOutputTokens ?? null
|
|
*
|
|
* i.e. only return the synced value when it actually IS a number; otherwise
|
|
* fall through to the registry cap, then the static spec cap.
|
|
*/
|
|
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-output-cap-synced-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const modelsDevSync = await import("../../src/lib/modelsDevSync.ts");
|
|
const modelCapabilities = await import("../../src/lib/modelCapabilities.ts");
|
|
const { PROVIDER_MODELS } = await import("../../open-sse/config/providerModels.ts");
|
|
|
|
// Pick a real registry model that has a known, positive maxOutputTokens so the
|
|
// test proves the fallthrough resolves an ACTUAL registry cap, not a fixture.
|
|
function findRegistryModelWithOutputCap() {
|
|
for (const [provider, models] of Object.entries(PROVIDER_MODELS)) {
|
|
for (const model of models as Array<{ id: string; maxOutputTokens?: number | null }>) {
|
|
if (typeof model.maxOutputTokens === "number" && model.maxOutputTokens > 0) {
|
|
return { provider, modelId: model.id, maxOutputTokens: model.maxOutputTokens };
|
|
}
|
|
}
|
|
}
|
|
throw new Error("no registry model with maxOutputTokens found — fixture assumption broke");
|
|
}
|
|
|
|
const { provider, modelId, maxOutputTokens } = findRegistryModelWithOutputCap();
|
|
|
|
function buildCapability(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
tool_call: null,
|
|
reasoning: null,
|
|
attachment: null,
|
|
structured_output: null,
|
|
temperature: null,
|
|
modalities_input: "[]",
|
|
modalities_output: "[]",
|
|
knowledge_cutoff: null,
|
|
release_date: null,
|
|
last_updated: null,
|
|
status: null,
|
|
family: null,
|
|
open_weights: null,
|
|
limit_context: null,
|
|
limit_input: null,
|
|
limit_output: null,
|
|
interleaved_field: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function resetStorage() {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
// The synced-capabilities module keeps an in-memory cache across DB resets
|
|
// (`cachedCapabilitiesLoadedAll`) — clear it too so each test starts from a
|
|
// truly empty synced-capability set instead of leaking the previous test's row.
|
|
modelsDevSync.clearModelsDevCapabilities();
|
|
}
|
|
|
|
test.beforeEach(() => {
|
|
resetStorage();
|
|
});
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
test("#6714 synced row present but limit_output missing falls through to the registry output cap", () => {
|
|
// Seed a synced capability row for this exact provider/model with
|
|
// limit_output left null (mirrors real models.dev rows that omit it).
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
[provider]: {
|
|
[modelId]: buildCapability({ limit_output: null, status: "stable" }),
|
|
},
|
|
});
|
|
|
|
const cap = modelCapabilities.getExplicitModelOutputCap(`${provider}/${modelId}`);
|
|
assert.equal(
|
|
cap,
|
|
maxOutputTokens,
|
|
"must fall through to the registry maxOutputTokens, not short-circuit to null"
|
|
);
|
|
});
|
|
|
|
test("#6714 synced row with a real numeric limit_output still wins over the registry cap", () => {
|
|
const syncedOutputCap = maxOutputTokens + 1234;
|
|
modelsDevSync.saveModelsDevCapabilities({
|
|
[provider]: {
|
|
[modelId]: buildCapability({ limit_output: syncedOutputCap, status: "stable" }),
|
|
},
|
|
});
|
|
|
|
const cap = modelCapabilities.getExplicitModelOutputCap(`${provider}/${modelId}`);
|
|
assert.equal(cap, syncedOutputCap, "a real numeric synced limit_output must take precedence");
|
|
});
|
|
|
|
test("#6714 no synced row at all still resolves the registry output cap (no regression)", () => {
|
|
const cap = modelCapabilities.getExplicitModelOutputCap(`${provider}/${modelId}`);
|
|
assert.equal(cap, maxOutputTokens);
|
|
});
|