Files
OmniRoute/tests/unit/rerank-providers-route.test.ts
Diego Rodrigues de Sa e Souza 7c119dd7ed fix(memory): resolve rerank provider node cache import (#12421)
The rerank-provider listing route dynamically imported @/lib/localDb — the barrel Hard Rule #2 forbids — and the stale path meant local rerank-capable provider nodes never appeared in GET /api/memory/rerank-providers. Now imports the specific @/lib/db/readCache module, with a route-level regression test through the public GET handler.

Validated in a combined worktree with the batch's ready set boarded onto the current tip: parse sweep clean on every changed TypeScript file, typecheck:core clean, check:dashboard-typecheck OK (207 pre-existing errors, all within baseline), check:cycles OK, check-file-size OK, 203/205 focused node tests and 94/94 vitest — the two failures belong to #12427, which is held back.
2026-09-02 10:01:47 -03:00

43 lines
1.4 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";
import { NextRequest } from "next/server";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-rerank-providers-route-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const { createProviderNode } = await import("../../src/lib/db/providers/nodes.ts");
const rerankProvidersRoute = await import("../../src/app/api/memory/rerank-providers/route.ts");
test.after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
});
test("GET /api/memory/rerank-providers includes rerank-capable local provider nodes", async () => {
await createProviderNode({
id: "rerank-route-test-node",
type: "openai-compatible",
name: "Local reranker",
prefix: "local-reranker",
apiType: "rerank",
baseUrl: "http://127.0.0.1:8099/v1",
});
const response = await rerankProvidersRoute.GET(
new NextRequest("http://localhost/api/memory/rerank-providers")
);
const body = await response.json();
assert.equal(response.status, 200);
assert.deepEqual(
body.providers.find(
(provider: { provider?: string }) => provider.provider === "local-reranker"
),
{ provider: "local-reranker", hasKey: true, models: [] }
);
});