Files
OmniRoute/tests/unit/db-migrationrunner-constants-split.test.ts
Diego Rodrigues de Sa e Souza 7ae8bf4e05 fix(db): harden migration recovery snapshots (#12435)
Validado em lote numa worktree combinada com os 14 PRs desta campanha de error-boundary sobre o tip de `release/v3.8.51`: `typecheck:core` limpo e **120/120** nos 23 arquivos de teste que os PRs trazem.

Um ponto que só apareceu no tree combinado: **#12465 e #12466 criam o mesmo arquivo novo** `open-sse/utils/streamReadiness.ts` (que não existe no tip) com desenhos divergentes de cancelamento — `cancelled` + `releaseLock` imediato num, `readInFlight`/`cancelRequested` com `cancelReader` fire-and-forget no outro. Adotei a versão do #12466, que difere e defere o release do lock para quando a leitura em voo termina, e validei a escolha rodando as suítes dos **dois** PRs contra ela: 21/21 no readiness compartilhado e 22/22 incluindo o boundary do Perplexity.
2026-09-03 21:01:09 -03:00

187 lines
6.5 KiB
TypeScript

/**
* Characterization / snapshot test: migrationRunner.ts god-file decomposition.
*
* The static migration-compatibility data tables were extracted verbatim from
* src/lib/db/migrationRunner.ts into the pure-data leaf
* src/lib/db/migrationRunner/constants.ts (no imports, no DB, no behaviour).
*
* These tables drive the reconciliation / dedup / already-applied detection
* paths in runMigrations(). The existing db-migration-runner.test.ts proves the
* BEHAVIOUR is unchanged; this test PINS THE DATA so a bad move (a dropped row,
* a transposed version, a corrupted sentinel) is caught immediately — the data
* is the thing the move could silently break.
*
* Pure value assertions — no DB handle is opened.
*/
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
RENAMED_MIGRATION_COMPATIBILITY,
LEGACY_VERSION_SLOT_MIGRATIONS,
SUPERSEDED_DUPLICATE_MIGRATIONS,
PHYSICAL_SCHEMA_SENTINELS,
INITIAL_SCHEMA_SENTINELS,
OPTIONAL_FTS5_MIGRATION_VERSIONS,
} from "../../src/lib/db/migrationRunner/constants.ts";
// ── small tables — full snapshot ─────────────────────────────────────────────
describe("migrationRunner/constants — exact small-table snapshots", () => {
it("LEGACY_VERSION_SLOT_MIGRATIONS is the 9-entry list, in order", () => {
assert.deepEqual(
LEGACY_VERSION_SLOT_MIGRATIONS.map((m) => `${m.version}:${m.name}`),
[
"028:evals_tables",
"029:webhooks_templates",
"030:mcp_scopes_api_keys",
"031:api_keys_expires",
"032:detailed_logs_warnings",
"033:provider_connections_block_extra_usage",
"033:add_batch_id_to_call_logs",
"046:remove_status_from_files",
"051:remove_status_from_files",
]
);
});
it("SUPERSEDED_DUPLICATE_MIGRATIONS is the single 041→050 session_account_affinity entry", () => {
assert.deepEqual(SUPERSEDED_DUPLICATE_MIGRATIONS, [
{
version: "041",
name: "session_account_affinity",
supersededByVersion: "050",
supersededByName: "session_account_affinity",
},
]);
});
it("INITIAL_SCHEMA_SENTINELS pins the three baseline tables", () => {
assert.deepEqual(INITIAL_SCHEMA_SENTINELS, ["provider_connections", "combos", "call_logs"]);
});
it("OPTIONAL_FTS5_MIGRATION_VERSIONS is exactly {022, 023}", () => {
assert.ok(OPTIONAL_FTS5_MIGRATION_VERSIONS instanceof Set);
assert.deepEqual([...OPTIONAL_FTS5_MIGRATION_VERSIONS].sort(), ["022", "023"]);
});
});
// ── large tables — count + shape + spot-checks (corruption guard) ─────────────
describe("migrationRunner/constants — large-table integrity", () => {
it("RENAMED_MIGRATION_COMPATIBILITY has 32 well-formed entries", () => {
assert.equal(RENAMED_MIGRATION_COMPATIBILITY.length, 32);
for (const e of RENAMED_MIGRATION_COMPATIBILITY) {
assert.equal(typeof e.fromVersion, "string");
assert.equal(typeof e.fromName, "string");
assert.equal(typeof e.toVersion, "string");
assert.equal(typeof e.toName, "string");
}
});
it("RENAMED_MIGRATION_COMPATIBILITY spot-checks the boundary renames", () => {
const first = RENAMED_MIGRATION_COMPATIBILITY[0];
assert.deepEqual(first, {
fromVersion: "022",
fromName: "call_logs_summary_storage",
toVersion: "025",
toName: "call_logs_summary_storage",
});
// both manifest_routing collisions (052→059 and 056→059) must survive
const manifest = RENAMED_MIGRATION_COMPATIBILITY.filter((e) => e.toName === "manifest_routing");
assert.deepEqual(manifest.map((e) => e.fromVersion).sort(), ["052", "056"]);
const devin = RENAMED_MIGRATION_COMPATIBILITY.filter(
(e) => e.toName === "windsurf_to_devin_desktop"
);
assert.deepEqual(
devin.map((e) => e.fromVersion),
[
"123",
"124",
"125",
"126",
"127",
"128",
"131",
"133",
"135",
"136",
"139",
"140",
"143",
"144",
]
);
assert.deepEqual(
RENAMED_MIGRATION_COMPATIBILITY.find(
(e) => e.fromVersion === "074" && e.fromName === "inspector_custom_hosts"
),
{
fromVersion: "074",
fromName: "inspector_custom_hosts",
toVersion: "081",
toName: "inspector_custom_hosts",
}
);
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-7), {
fromVersion: "134",
fromName: "ccr_blocks",
toVersion: "139",
toName: "ccr_blocks",
});
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-6), {
fromVersion: "139",
fromName: "job_registry",
toVersion: "146",
toName: "job_registry",
});
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-5), {
fromVersion: "143",
fromName: "radar_local_model_state",
toVersion: "153",
toName: "radar_local_model_state",
});
// #12036: renamed migrations 056/073/077/101 appended as compatibility renames
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-4), {
fromVersion: "056",
fromName: "provider_default",
toVersion: "056",
toName: "mcp_accessibility_compression",
});
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-3), {
fromVersion: "073",
fromName: "discovery_results",
toVersion: "073",
toName: "per_model_token_limits",
});
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-2), {
fromVersion: "077",
fromName: "plugin_metrics",
toVersion: "077",
toName: "api_key_stream_default_mode",
});
assert.deepEqual(RENAMED_MIGRATION_COMPATIBILITY.at(-1), {
fromVersion: "101",
fromName: "proxy_pool_rotation",
toVersion: "101",
toName: "api_key_usage_limits",
});
});
it("PHYSICAL_SCHEMA_SENTINELS has 15 well-formed entries incl. the newest 064", () => {
assert.equal(PHYSICAL_SCHEMA_SENTINELS.length, 15);
for (const e of PHYSICAL_SCHEMA_SENTINELS) {
assert.equal(typeof e.version, "string");
assert.equal(typeof e.tableName, "string");
assert.equal(typeof e.description, "string");
}
const byVersion = Object.fromEntries(
PHYSICAL_SCHEMA_SENTINELS.map((e) => [e.version, e.tableName])
);
assert.equal(byVersion["064"], "session_model_history");
assert.equal(byVersion["002"], "mcp_tool_audit");
assert.equal(byVersion["028"], "batches");
});
});