mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-15 11:22:15 +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.
153 lines
4.8 KiB
TypeScript
153 lines
4.8 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-cid-substr-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const callLogs = await import("../../src/lib/usage/callLogs.ts");
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
});
|
|
|
|
// Seed test data
|
|
function seedLogs() {
|
|
const db = core.getDbInstance();
|
|
const now = new Date().toISOString();
|
|
db.prepare(
|
|
`INSERT OR REPLACE INTO call_logs (id, timestamp, method, path, status, model, provider, account, duration, tokens_in, tokens_out, correlation_id)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
).run(
|
|
"log-1",
|
|
now,
|
|
"POST",
|
|
"/v1/chat/completions",
|
|
200,
|
|
"gpt-4",
|
|
"openai",
|
|
"acc1",
|
|
100,
|
|
10,
|
|
20,
|
|
"abc123-def456-ghi789"
|
|
);
|
|
db.prepare(
|
|
`INSERT OR REPLACE INTO call_logs (id, timestamp, method, path, status, model, provider, account, duration, tokens_in, tokens_out, correlation_id)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
).run(
|
|
"log-2",
|
|
now,
|
|
"POST",
|
|
"/v1/chat/completions",
|
|
200,
|
|
"claude-3",
|
|
"anthropic",
|
|
"acc2",
|
|
200,
|
|
15,
|
|
30,
|
|
"xyz999-uvw888-tsr777"
|
|
);
|
|
db.prepare(
|
|
`INSERT OR REPLACE INTO call_logs (id, timestamp, method, path, status, model, provider, account, duration, tokens_in, tokens_out, correlation_id)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
).run(
|
|
"log-3",
|
|
now,
|
|
"POST",
|
|
"/v1/chat/completions",
|
|
500,
|
|
"gpt-4",
|
|
"openai",
|
|
"acc1",
|
|
50,
|
|
0,
|
|
0,
|
|
null
|
|
);
|
|
}
|
|
|
|
// ── Exact match ───────────────────────────────────────────────────────────
|
|
|
|
test("correlationId exact match returns single entry", async () => {
|
|
seedLogs();
|
|
const results = await callLogs.getCallLogs({ correlationId: "abc123-def456-ghi789" });
|
|
assert.equal(results.length, 1);
|
|
assert.equal(results[0].correlationId, "abc123-def456-ghi789");
|
|
});
|
|
|
|
// ── Substring match ───────────────────────────────────────────────────────
|
|
|
|
test("correlationId substring match (prefix)", async () => {
|
|
seedLogs();
|
|
const results = await callLogs.getCallLogs({ correlationId: "abc123" });
|
|
assert.equal(results.length, 1);
|
|
assert.equal(results[0].id, "log-1");
|
|
});
|
|
|
|
test("correlationId substring match (middle)", async () => {
|
|
seedLogs();
|
|
const results = await callLogs.getCallLogs({ correlationId: "def456" });
|
|
assert.equal(results.length, 1);
|
|
assert.equal(results[0].id, "log-1");
|
|
});
|
|
|
|
test("correlationId substring match (suffix)", async () => {
|
|
seedLogs();
|
|
const results = await callLogs.getCallLogs({ correlationId: "ghi789" });
|
|
assert.equal(results.length, 1);
|
|
assert.equal(results[0].id, "log-1");
|
|
});
|
|
|
|
test("correlationId substring match returns multiple when shared", async () => {
|
|
const db = core.getDbInstance();
|
|
const now = new Date().toISOString();
|
|
// Add another log sharing a substring
|
|
db.prepare(
|
|
`INSERT OR REPLACE INTO call_logs (id, timestamp, method, path, status, model, provider, account, duration, tokens_in, tokens_out, correlation_id)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
).run(
|
|
"log-4",
|
|
now,
|
|
"POST",
|
|
"/v1/chat/completions",
|
|
200,
|
|
"gpt-4",
|
|
"openai",
|
|
"acc1",
|
|
100,
|
|
10,
|
|
20,
|
|
"abc123-RETRY-suffix"
|
|
);
|
|
|
|
const results = await callLogs.getCallLogs({ correlationId: "abc123" });
|
|
assert.equal(results.length, 2);
|
|
const ids = results.map((r: { id: string }) => r.id).sort();
|
|
assert.deepEqual(ids, ["log-1", "log-4"]);
|
|
});
|
|
|
|
// ── No match ──────────────────────────────────────────────────────────────
|
|
|
|
test("correlationId no match returns empty", async () => {
|
|
seedLogs();
|
|
const results = await callLogs.getCallLogs({ correlationId: "nonexistent" });
|
|
assert.equal(results.length, 0);
|
|
});
|
|
|
|
// ── Null/empty correlationId rows excluded ─────────────────────────────────
|
|
|
|
test("rows with null correlationId are excluded from substring search", async () => {
|
|
seedLogs();
|
|
// Search for a unique substring that only matches log-1
|
|
const results = await callLogs.getCallLogs({ correlationId: "ghi789" });
|
|
const ids = results.map((r: { id: string }) => r.id);
|
|
assert.ok(!ids.includes("log-3"), "null correlation_id rows must be excluded");
|
|
assert.equal(results.length, 1);
|
|
});
|