Files
OmniRoute/tests/unit/model-sync-custom-preservation.test.ts
backryun 67a0b99240 feat(providers): add GPT-5.6 model family (#6862)
* feat(providers): add GPT-5.6 model family

* fix(chatgpt-web): resume temporary chat handoffs

* fix(codex): auto-merge discovery, filter denylist, revalidate on lifecycle

Restore live/GitHub auto-merge for Codex catalogs, drop models via
explicit denylist (GPT-5.4 family), and run scrub+live re-sync once on
first-start, app upgrade, or setup completion. Success log:
kill deprecated models complete.

* fix(codex): preserve live catalog reconciliation

Expose remote-only Codex models without dropping user custom entries, and complete lifecycle revalidation only after a successful internal sync. Keep credentialed self-fetches pinned to the active dashboard listener.

---------

Co-authored-by: backryun <backryun@daonlab.local>
2026-07-12 03:30:47 -03:00

79 lines
2.7 KiB
TypeScript

import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test from "node:test";
const TEST_DATA_DIR = fs.mkdtempSync(
path.join(os.tmpdir(), "omniroute-model-sync-custom-preservation-")
);
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET ||= `test-model-sync-custom-${Date.now()}`;
const core = await import("../../src/lib/db/core.ts");
const providersDb = await import("../../src/lib/db/providers.ts");
const modelsDb = await import("../../src/lib/db/models.ts");
const modelSyncRoute = await import("../../src/app/api/providers/[id]/sync-models/route.ts");
const scheduler = await import("../../src/shared/services/modelSyncScheduler.ts");
const originalFetch = globalThis.fetch;
test.after(() => {
globalThis.fetch = originalFetch;
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("model sync preserves response-only custom models during discovery", async () => {
const connection = await providersDb.createProviderConnection({
provider: "codex",
authType: "oauth",
name: "Codex Custom Preservation",
accessToken: "test-codex-token",
providerSpecificData: { workspaceId: "workspace-custom-preservation" },
});
await modelsDb.addCustomModel(
"codex",
"operator-private-codex",
"Operator Private Codex",
"manual",
"responses",
["responses"],
"openai-responses",
{ inputTokenLimit: 123456, outputTokenLimit: 6543 }
);
const before = await modelsDb.getCustomModels("codex");
globalThis.fetch = async (input) => {
const url = new URL(String(input));
if (url.pathname.includes("__readiness_probe__")) {
return new Response(null, { status: 404 });
}
if (url.pathname === `/api/providers/${connection.id}/models`) {
const models = [{ id: "future-codex-experimental", name: "Future Codex" }];
if (url.searchParams.get("excludeCustom") !== "true") {
models.push({ id: "operator-private-codex", name: "Operator Private Codex" });
}
return Response.json({ models, source: "api" });
}
throw new Error(`Unexpected fetch in custom preservation test: ${url.href}`);
};
const response = await modelSyncRoute.POST(
new Request(`http://localhost/api/providers/${connection.id}/sync-models?quiet=1`, {
method: "POST",
headers: scheduler.buildModelSyncInternalHeaders(),
}),
{ params: { id: connection.id } }
);
assert.equal(response.status, 200);
assert.deepEqual(await modelsDb.getCustomModels("codex"), before);
assert.deepEqual(
(await modelsDb.getSyncedAvailableModelsForConnection("codex", connection.id)).map(
(model) => model.id
),
["future-codex-experimental"]
);
});