Files
t3code/apps/web/src/components/settings/ProviderInstanceCard.test.ts
T
Julius Marminge 29cd06590a Require Cursor API key for provider checks
- Switch Cursor provider status and model discovery to the SDK catalog
- Improve chat content lane alignment and provider secret handling
2026-08-14 11:23:24 +02:00

94 lines
2.6 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import type { ServerProviderModel } from "@t3tools/contracts";
import {
deriveProviderModelsForDisplay,
nextProviderEnvironmentWithFieldValue,
providerEnvironmentWithoutNames,
readProviderEnvironmentVariable,
} from "./ProviderInstanceCard";
describe("deriveProviderModelsForDisplay", () => {
it("uses current config custom models instead of stale live custom rows", () => {
const liveModels: ReadonlyArray<ServerProviderModel> = [
{
slug: "server-model",
name: "Server Model",
isCustom: false,
capabilities: null,
},
{
slug: "removed-custom",
name: "Removed Custom",
isCustom: true,
capabilities: null,
},
{
slug: "kept-custom",
name: "Kept Custom",
isCustom: true,
capabilities: null,
},
];
expect(
deriveProviderModelsForDisplay({
liveModels,
customModels: ["kept-custom"],
}).map((model) => model.slug),
).toEqual(["server-model", "kept-custom"]);
});
});
describe("provider environment helpers", () => {
const cursorApiKeyField = {
name: "CURSOR_API_KEY",
label: "Cursor API key",
sensitive: true,
};
it("writes dedicated provider secrets as sensitive environment variables", () => {
expect(
nextProviderEnvironmentWithFieldValue(
[{ name: "EXTRA_FLAG", value: "1", sensitive: false }],
cursorApiKeyField,
" cursor-key ",
),
).toEqual([
{ name: "EXTRA_FLAG", value: "1", sensitive: false },
{ name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
]);
});
it("replaces redacted provider secrets without preserving redaction markers", () => {
expect(
nextProviderEnvironmentWithFieldValue(
[
{
name: "CURSOR_API_KEY",
value: "",
sensitive: true,
valueRedacted: true,
},
],
cursorApiKeyField,
"new-key",
),
).toEqual([{ name: "CURSOR_API_KEY", value: "new-key", sensitive: true }]);
});
it("separates dedicated provider secrets from the generic environment table", () => {
const environment = [
{ name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
{ name: "EXTRA_FLAG", value: "1", sensitive: false },
];
expect(readProviderEnvironmentVariable(environment, "CURSOR_API_KEY")?.value).toBe(
"cursor-key",
);
expect(providerEnvironmentWithoutNames(environment, new Set(["CURSOR_API_KEY"]))).toEqual([
{ name: "EXTRA_FLAG", value: "1", sensitive: false },
]);
});
});