Files
OmniRoute/tests/unit/call-logs-correlation-substring.test.ts
Diego Rodrigues de Sa e Souza fecf888fd9 fix(quality): clear the cycle's 11 net-new ESLint errors + make validate-release-green suppressions-aware
- executor-kiro/save-call-log/call-logs-correlation tests: replace 15 'as any'
  casts with typed shapes (net-new no-explicit-any errors from #6213/#6216);
  prune the now-empty suppression entries so the frozen baseline stays exact
- github-skills + usage/call-logs routes: raw toLowerCase().includes() search
  replaced by matchesSearch() (no-restricted-syntax — Turkish-safe search,
  behavior covered by tests/unit/call-logs-correlation-substring.test.ts and
  tests/unit/github-collector.test.ts)
- validate-release-green.mjs: run ESLint with --suppressions-location (match
  the npm run lint contract — frozen debt is not a release red) and raise the
  lint timeout 15->30min (a full pass takes ~14min alone; the 15min ceiling
  expired under concurrent suite load and surfaced as 'could not parse eslint
  json')
2026-07-05 14:49:18 -03:00

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 });
});
// 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);
});