| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { type AiProvider, AI_PROVIDERS } from "@g1t/contracts/ai"; |
| 5 | import { CONNECTORS } from "@g1t/contracts/connectors"; |
| 6 | |
| 7 | import { AI_PROVIDER_GROUPS, AI_PROVIDER_LOOKS, aiProvidersIn, isEndpoint } from "./ai-providers.ts"; |
| 8 | import { aiPagePath, providerPage, sectionKind } from "./integration-sections.ts"; |
| 9 | |
| 10 | test("every AI provider is shown, once, in a group", () => { |
| 11 | const providers = Object.keys(AI_PROVIDERS) as AiProvider[]; |
| 12 | assert.equal(providers.length, 14); |
| 13 | assert.deepEqual(Object.keys(AI_PROVIDER_LOOKS).sort(), [...providers].sort()); |
| 14 | const grouped = AI_PROVIDER_GROUPS.flatMap(({ group }) => aiProvidersIn(group)); |
| 15 | assert.deepEqual(grouped, providers); |
| 16 | for (const provider of providers) { |
| 17 | const look = AI_PROVIDER_LOOKS[provider]; |
| 18 | assert.ok(look.blurb.length > 0, provider); |
| 19 | if (look.keyUrl) assert.ok(look.keyUrl.startsWith("https://"), provider); |
| 20 | // Only the endpoints show an icon in place of initials. |
| 21 | assert.equal(look.mark === "", isEndpoint(provider), provider); |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | test("AI providers are the workspace's AI settings, not integrations", () => { |
| 26 | // None is in the integrations directory. |
| 27 | const ai = new Set<string>(Object.keys(AI_PROVIDERS)); |
| 28 | assert.deepEqual(CONNECTORS.filter((connector) => connector.provider && ai.has(connector.provider)), []); |
| 29 | assert.equal(providerPage("alerts"), "integrations/alerts"); |
| 30 | assert.equal(providerPage("tracker"), "integrations/trackers"); |
| 31 | assert.equal(sectionKind("models"), null); |
| 32 | assert.equal(sectionKind("alerts"), "alerts"); |
| 33 | assert.equal(sectionKind("trackers"), "tracker"); |
| 34 | assert.equal(sectionKind("gateway"), null); |
| 35 | }); |
| 36 | |
| 37 | test("older links to the AI providers' page open the AI page", () => { |
| 38 | assert.equal(aiPagePath("acme", ""), "/acme/-/ai"); |
| 39 | assert.equal(aiPagePath("acme", "?add=openai"), "/acme/-/ai?add=openai#add"); |
| 40 | assert.equal(aiPagePath("acme", "?_routes=root&add=openai"), "/acme/-/ai?add=openai#add"); |
| 41 | }); |