Files
OmniRoute/tests/unit/combos-duplicate-resolution-audit.test.ts
Jay Ongg 74c9e7e0d2 feat(combo): Auto-Combo snapshot generation/duplication in the UX (#10354)
Adds a snapshot-generation button to each Auto-Combo catalog card: computeSnapshotWeights() scores candidates (taskFit/stability/tierPriority/costInv) at combo-creation time instead of the previous hardcoded weight:1, and the new POST /api/combos/duplicate endpoint materializes any auto/* template into a persistent, editable static combo with normalized weights. Closes #10231.

Validated in an isolated worktree boarded onto origin/release/v3.8.50 (0 conflicts, 51 files):
- 19/19 focused tests pass (snapshot-weights, combos-duplicate-route, combos-duplicate-resolution-audit) — covers auth gate (401/403), input validation (400/422), success shape, weight normalization, naming/dedup, and error-response sanitization (no stack traces).
- check-file-size, check-changelog-integrity: OK.
- typecheck:core: clean.
- check-complexity / check-cognitive-complexity: OK, both under baseline.

Co-authored-by: swingtempo <swingtempo@users.noreply.github.com>
2026-08-20 23:14:00 -03:00

55 lines
1.8 KiB
TypeScript

/**
* Audit: every built-in auto-combo template must resolve to SOME spec or variant
* (not an empty object that produces a full unfiltered pool).
*/
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-duplicate-audit-"));
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET ?? "dup-audit-secret";
const core = await import("../../src/lib/db/core.ts");
const settingsDb = await import("../../src/lib/db/settings.ts");
const { AUTO_TEMPLATE_VARIANTS, AUTO_SUFFIX_VARIANTS, AUTO_FAMILY_IDS } =
await import("@omniroute/open-sse/services/autoCombo/builtinCatalog");
const { resolveBuiltinAutoSpec } =
await import("@omniroute/open-sse/services/autoCombo/builtinCatalog");
test.after(() => {
core.resetDbInstance();
try {
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
} catch {}
});
const ALL_TEMPLATES = [
...Object.keys(AUTO_TEMPLATE_VARIANTS),
...AUTO_SUFFIX_VARIANTS,
...AUTO_FAMILY_IDS,
];
test("every template resolves to a non-empty spec or variant (not bare unfiltered pool)", async () => {
for (const name of ALL_TEMPLATES) {
const suffix = name.slice("auto/".length);
const r = resolveBuiltinAutoSpec(name, suffix);
// auto/chat-style templates legitimately return {variant: undefined} — that IS the "unconstrained" spec.
if (Object.prototype.hasOwnProperty.call(AUTO_TEMPLATE_VARIANTS, name)) {
continue;
}
// Family IDs handled by duplicate route fallback
if (AUTO_FAMILY_IDS.includes(name)) {
continue;
}
assert.ok(
JSON.stringify(r) !== "{}",
`${name} resolved to empty spec — would produce full unfiltered pool`
);
}
});