Files
OmniRoute/tests/unit/repro-6524.test.ts
Diego Rodrigues de Sa e Souza 3d4f3e4960 test(infra): retry recursive temp-dir removal instead of failing a shard on ENOTEMPTY (#11966) (#11968)
* 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.
2026-08-29 01:17:40 -03:00

103 lines
4.4 KiB
TypeScript

/**
* Regression test for issue #6524.
*
* Reporter observed: for `ollama-cloud/deepseek-v4-flash`, a synced capability row
* with `limit_output=1048576` (wrongly equal to `limit_context`, while the real
* upstream output cap is `65536`) caused the reasoning-token-buffer heuristic to
* expand `max_tokens` 64000 -> 96000, which upstream rejected with
* "exceeds model's maximum output tokens (65536)".
*
* Root cause (confirmed by reading `resolveReasoningBufferedMaxTokens` and its
* `getExplicitModelOutputCap` clamp source): the clamp math itself is correct, but
* `getExplicitModelOutputCap()` only ever read the unvalidated synced
* `limit_output` (or registry/static fallbacks) — it ignored the operator-settable
* `max_output_tokens` capability override (`src/lib/db/modelCapabilityOverrides.ts`,
* `/api/model-capability-overrides`) that `getResolvedModelCapabilities()` already
* consulted. That inconsistency meant an operator manually correcting a bad synced
* output cap (the existing, already-shipped remediation path for wrong catalog
* data) had no effect on the reasoning buffer, which kept inflating past the real
* cap regardless.
*
* Fix: `getExplicitModelOutputCap()` now checks the same `max_output_tokens` override
* before falling back to synced/registry/static data, via a helper shared with
* `getResolvedModelCapabilities()`.
*/
import assert from "node:assert/strict";
import test from "node:test";
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-repro-6524-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const { saveModelsDevCapabilities, clearModelsDevCapabilities } =
await import("../../src/lib/modelsDevSync.ts");
const { setModelCapabilityOverride, removeModelCapabilityOverride } =
await import("../../src/lib/db/modelCapabilityOverrides.ts");
const { resolveReasoningBufferedMaxTokens } =
await import("../../open-sse/services/reasoningTokenBuffer.ts");
const PROVIDER = "ollama-cloud";
const MODEL = "deepseek-v4-flash";
const TARGET = `${PROVIDER}/${MODEL}`;
const REAL_UPSTREAM_OUTPUT_CAP = 65536; // per reporter's boundary test table
function capabilityEntry(limitContext: unknown, overrides: Record<string, unknown> = {}) {
return {
reasoning: false,
tool_call: true,
attachment: false,
temperature: true,
structured_output: true,
limit: { context: limitContext, output: limitContext },
...overrides,
};
}
test.before(() => {
clearModelsDevCapabilities();
// Mirrors the exact production row from the issue: limit_context and limit_output
// both wrongly synced to 1048576 for ollama-cloud/deepseek-v4-flash, while the real
// upstream output cap (per the reporter's boundary test) is 65536.
saveModelsDevCapabilities({
[PROVIDER]: {
[MODEL]: capabilityEntry(1048576, { reasoning: true, limit_output: 1048576 }),
},
});
});
test.after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
test("#6524: with only the (wrong) synced catalog data, the buffer no longer inflates (#9507)", () => {
// #9507: the reasoning-token buffer never enlarges an explicit client
// max_tokens, so even with a wrong synced output cap (1048576) the client's
// 64000 is forwarded verbatim — which already stays under the real upstream
// cap (65536), fully resolving the reporter's symptom without needing an
// operator override. (Previously this asserted 96000, the inflation past the
// real cap; that inflation is the defect #9507 removes.)
const result = resolveReasoningBufferedMaxTokens(TARGET, 64000);
assert.equal(result, 64000);
});
test("#6524: an operator-set max_output_tokens override clamps the reasoning buffer", () => {
assert.ok(
setModelCapabilityOverride(TARGET, "max_output_tokens", REAL_UPSTREAM_OUTPUT_CAP),
"expected the max_output_tokens override to be written"
);
try {
const result = resolveReasoningBufferedMaxTokens(TARGET, 64000);
assert.ok(
result === null || result <= REAL_UPSTREAM_OUTPUT_CAP,
`expected max_tokens to stay <= ${REAL_UPSTREAM_OUTPUT_CAP}, got ${result} ` +
`(reproduces reported 64000 -> 96000 inflation, upstream then 400s)`
);
} finally {
removeModelCapabilityOverride(TARGET, "max_output_tokens");
}
});