mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +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.
115 lines
4.5 KiB
TypeScript
115 lines
4.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { spawnSync } from "node:child_process";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { createRequire } from "node:module";
|
|
import { after, it } from "node:test";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
// Read the pin from the installed package instead of hard-coding it: the constant
|
|
// was frozen at 1.18.8 and silently went stale when Dependabot bumped opencode-ai
|
|
// to 1.18.18 (#10626), turning this into a base-red. Sourcing it from the resolved
|
|
// package.json keeps the assertion just as strict (the binary must report exactly
|
|
// the version this repo pins) while surviving future bumps.
|
|
const OPENCODE_VERSION: string = require("opencode-ai/package.json").version;
|
|
const testHome = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-opencode-8849-"));
|
|
const originalHome = process.env.HOME;
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
process.env.HOME = testHome;
|
|
|
|
after(() => {
|
|
globalThis.fetch = originalFetch;
|
|
if (originalHome === undefined) delete process.env.HOME;
|
|
else process.env.HOME = originalHome;
|
|
fs.rmSync(testHome, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
function runOpencode(binary: string, args: string[]) {
|
|
const xdgRoot = path.join(testHome, "xdg");
|
|
const result = spawnSync(binary, args, {
|
|
cwd: testHome,
|
|
encoding: "utf8",
|
|
timeout: 30_000,
|
|
env: {
|
|
...process.env,
|
|
HOME: testHome,
|
|
XDG_CONFIG_HOME: path.join(xdgRoot, "config"),
|
|
XDG_DATA_HOME: path.join(xdgRoot, "data"),
|
|
XDG_CACHE_HOME: path.join(xdgRoot, "cache"),
|
|
XDG_STATE_HOME: path.join(xdgRoot, "state"),
|
|
NO_COLOR: "1",
|
|
OPENCODE_DISABLE_AUTOUPDATE: "1",
|
|
},
|
|
});
|
|
|
|
assert.ifError(result.error);
|
|
return result;
|
|
}
|
|
|
|
it("#8849 generated config is accepted by pinned OpenCode schema and startup", async () => {
|
|
const packageJsonPath = require.resolve("opencode-ai/package.json");
|
|
const opencodeBinary = path.join(path.dirname(packageJsonPath), "bin", "opencode.exe");
|
|
assert.ok(fs.existsSync(opencodeBinary), `missing pinned OpenCode ${OPENCODE_VERSION} binary`);
|
|
|
|
const version = runOpencode(opencodeBinary, ["--version"]);
|
|
assert.strictEqual(version.status, 0, version.stderr);
|
|
assert.strictEqual(version.stdout.trim(), OPENCODE_VERSION);
|
|
|
|
const catalog = {
|
|
object: "list",
|
|
data: [
|
|
{ id: "context-only", context_length: 131072 },
|
|
{ id: "context-input", context_length: 131072, max_input_tokens: 100000 },
|
|
{
|
|
id: "context-input-output",
|
|
context_length: 131072,
|
|
max_input_tokens: 100000,
|
|
max_output_tokens: 32768,
|
|
},
|
|
{ id: "no-limit-metadata" },
|
|
],
|
|
};
|
|
globalThis.fetch = (async () =>
|
|
new Response(JSON.stringify(catalog), {
|
|
status: 200,
|
|
headers: { "content-type": "application/json" },
|
|
})) as typeof fetch;
|
|
|
|
const { generateOpencodeConfig } =
|
|
await import("../../src/lib/cli-helper/config-generator/opencode.ts");
|
|
const generatedConfig = await generateOpencodeConfig({
|
|
baseUrl: "http://127.0.0.1:9/v1",
|
|
apiKey: "sk-test",
|
|
providerId: "issue8849",
|
|
});
|
|
|
|
const configDir = path.join(testHome, "xdg", "config", "opencode");
|
|
fs.mkdirSync(configDir, { recursive: true });
|
|
fs.writeFileSync(path.join(configDir, "opencode.json"), generatedConfig);
|
|
|
|
const configCheck = runOpencode(opencodeBinary, ["debug", "config", "--pure"]);
|
|
assert.strictEqual(configCheck.status, 0, configCheck.stderr);
|
|
assert.doesNotMatch(configCheck.stderr, /Missing key .*\.limit\.output/);
|
|
const resolvedConfig = JSON.parse(configCheck.stdout);
|
|
assert.ok(resolvedConfig.provider.issue8849.models["context-only"].limit.output > 0);
|
|
assert.strictEqual(
|
|
resolvedConfig.provider.issue8849.models["context-input-output"].limit.output,
|
|
32768
|
|
);
|
|
// #11035/#11032 (PR #11054) made the generator ALWAYS emit both limit keys: a model
|
|
// the catalog knows nothing about now gets the 128K context / 8K output fallbacks,
|
|
// because OpenCode's v1 provider schema rejects the whole config on a missing
|
|
// `limit.context` / `limit.output`. Before that fix the entry carried no `limit` at all.
|
|
assert.deepStrictEqual(resolvedConfig.provider.issue8849.models["no-limit-metadata"].limit, {
|
|
context: 128_000,
|
|
output: 8_192,
|
|
});
|
|
|
|
const startup = runOpencode(opencodeBinary, ["debug", "startup", "--pure"]);
|
|
assert.strictEqual(startup.status, 0, startup.stderr);
|
|
assert.match(startup.stdout.trim(), /^\d+(?:\.\d+)?$/);
|
|
assert.doesNotMatch(startup.stderr, /Missing key .*\.limit\.output/);
|
|
});
|