mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 19:02:17 +03:00
* 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.
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { describe, it, before, after } from "node:test";
|
|
import assert from "node:assert";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { NextRequest } from "next/server";
|
|
|
|
// Hermetic auth context (6A re-wire fix): without a configured password,
|
|
// isAuthRequired() is false on a fresh DB (CI) and the route answers 200 —
|
|
// these 401/403 assertions only held locally because the dev DATA_DIR had a
|
|
// real password. Create an isolated DATA_DIR with login protection enabled.
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cli-detect-"));
|
|
const originalDataDir = process.env.DATA_DIR;
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../../../src/lib/db/core.ts");
|
|
const settingsDb = await import("../../../../src/lib/db/settings.ts");
|
|
const { GET } = await import("../../../../src/app/api/cli-tools/detect/route.ts");
|
|
|
|
describe("GET /api/cli-tools/detect", () => {
|
|
before(async () => {
|
|
await settingsDb.updateSettings({
|
|
requireLogin: true,
|
|
setupComplete: true,
|
|
password: "test-password-hash",
|
|
});
|
|
});
|
|
|
|
after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
if (originalDataDir === undefined) delete process.env.DATA_DIR;
|
|
else process.env.DATA_DIR = originalDataDir;
|
|
});
|
|
|
|
it("returns 401 without authorization", async () => {
|
|
// @ts-ignore - we can call the handler directly
|
|
const req = new NextRequest("http://localhost:3000/api/cli-tools/detect");
|
|
const res = await GET(req);
|
|
assert.strictEqual(res.status, 401);
|
|
});
|
|
|
|
it("returns 403 with wrong authorization (invalid API key)", async () => {
|
|
// @ts-ignore
|
|
const req = new NextRequest("http://localhost:3000/api/cli-tools/detect", {
|
|
headers: { authorization: "Bearer wrong-key" },
|
|
});
|
|
const res = await GET(req);
|
|
assert.strictEqual(res.status, 403);
|
|
});
|
|
|
|
it("returns 200 with valid auth and returns tools array", async () => {
|
|
// Mock the auth - check that requireCliToolsAuth is called
|
|
// Since requireCliToolsAuth uses DB, we need a more involved mock.
|
|
// For quick coverage, we'll test that the handler structure is right.
|
|
assert.ok(true);
|
|
});
|
|
|
|
it("returns single tool when tool query param provided", async () => {
|
|
// Verify route reads searchParams correctly
|
|
assert.ok(true);
|
|
});
|
|
});
|