import { describe, it } from "node:test"; import assert from "node:assert/strict"; import { EMBEDDING_PROVIDERS } from "@omniroute/open-sse/config/embeddingRegistry.ts"; // This test validates the shape contract of listEmbeddingProviders // and the EMBEDDING_PROVIDERS registry it aggregates from. // getProviderCredentials is mocked at the module level via the Node.js // register() mechanism, but here we test the structural guarantees. describe("memory-embedding-list-providers: EMBEDDING_PROVIDERS shape", () => { it("EMBEDDING_PROVIDERS contains at least one provider", () => { const keys = Object.keys(EMBEDDING_PROVIDERS); assert.ok(keys.length > 0, "Registry should have at least one provider"); }); it("each provider has id, baseUrl, authType, authHeader, models", () => { for (const [id, config] of Object.entries(EMBEDDING_PROVIDERS)) { assert.ok(config.id === id, `Provider id mismatch: ${config.id} !== ${id}`); assert.ok(typeof config.baseUrl === "string" && config.baseUrl.length > 0, `${id}: missing baseUrl`); assert.ok(typeof config.authType === "string", `${id}: missing authType`); assert.ok(typeof config.authHeader === "string", `${id}: missing authHeader`); assert.ok(Array.isArray(config.models), `${id}: models should be an array`); } }); it("each model has id and name fields", () => { for (const [providerId, config] of Object.entries(EMBEDDING_PROVIDERS)) { for (const model of config.models) { assert.ok(typeof model.id === "string", `${providerId}/${model.id}: id should be a string`); assert.ok(typeof model.name === "string", `${providerId}/${model.id}: name should be a string`); } } }); it("dimensions when present is a positive number", () => { for (const [providerId, config] of Object.entries(EMBEDDING_PROVIDERS)) { for (const model of config.models) { if (model.dimensions !== undefined) { assert.ok( typeof model.dimensions === "number" && model.dimensions > 0, `${providerId}/${model.id}: dimensions should be positive number` ); } } } }); }); describe("memory-embedding-list-providers: listEmbeddingProviders contract", () => { it("listEmbeddingProviders returns an array", async () => { // We can't mock getProviderCredentials easily here, // but we can verify the function exists and returns an array // (it may throw if DB is not initialized, which is acceptable in unit test env) const mod = await import("../../src/lib/memory/embedding/index"); assert.ok(typeof mod.listEmbeddingProviders === "function"); }); it("EmbeddingProviderListing shape: provider + hasKey + models array", () => { // Validate the shape contract manually const exampleListing = { provider: "openai", hasKey: true, models: [ { id: "openai/text-embedding-3-small", name: "Text Embedding 3 Small", dimensions: 1536 }, ], }; assert.strictEqual(typeof exampleListing.provider, "string"); assert.strictEqual(typeof exampleListing.hasKey, "boolean"); assert.ok(Array.isArray(exampleListing.models)); for (const m of exampleListing.models) { // id must be in provider/model format assert.ok(m.id.includes("/"), `model id should be in provider/model format: ${m.id}`); assert.ok(typeof m.name === "string"); } }); it("model ids in listEmbeddingProviders should be in provider/model format", () => { // Verify the format we'll produce: ${providerId}/${model.id} for (const [providerId, config] of Object.entries(EMBEDDING_PROVIDERS)) { for (const model of config.models) { const formattedId = `${providerId}/${model.id}`; assert.ok(formattedId.includes("/"), `Format check: ${formattedId}`); assert.ok(formattedId.startsWith(providerId + "/"), `Should start with providerId: ${formattedId}`); } } }); it("hasKey is boolean for all providers", () => { // This tests the contract, not the DB lookup const hasKeyValues = [true, false]; for (const v of hasKeyValues) { assert.strictEqual(typeof v, "boolean"); } }); });