Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderInstanceCard.test.ts

106 lines3.1 KB

1import { describe, expect, it } from "vite-plus/test";
2import type { ServerProviderModel } from "@t3tools/contracts";
3​
4import {
5 deriveProviderModelsForDisplay,
6 nextProviderEnvironmentWithFieldValue,
7 providerEnvironmentWithoutNames,
8 readProviderEnvironmentVariable,
9} from "./ProviderInstanceCard";
10​
11describe("deriveProviderModelsForDisplay", () => {
12 it("uses current config custom models instead of stale live custom rows", () => {
13 const liveModels: ReadonlyArray<ServerProviderModel> = [
14 {
15 slug: "server-model",
16 name: "Server Model",
17 isCustom: false,
18 capabilities: null,
19 },
20 {
21 slug: "removed-custom",
22 name: "Removed Custom",
23 isCustom: true,
24 capabilities: null,
25 },
26 {
27 slug: "kept-custom",
28 name: "Kept Custom",
29 isCustom: true,
30 capabilities: null,
31 },
32 ];
33​
34 expect(
35 deriveProviderModelsForDisplay({
36 liveModels,
37 customModels: ["kept-custom"],
38 }).map((model) => model.slug),
39 ).toEqual(["server-model", "kept-custom"]);
40 });
41});
42​
43describe("provider environment helpers", () => {
44 const cursorApiKeyField = {
45 name: "CURSOR_API_KEY",
46 label: "Cursor API key",
47 sensitive: true,
48 };
49​
50 it("writes dedicated provider secrets as sensitive environment variables", () => {
51 expect(
52 nextProviderEnvironmentWithFieldValue(
53 [{ name: "EXTRA_FLAG", value: "1", sensitive: false }],
54 cursorApiKeyField,
55 " cursor-key ",
56 ),
57 ).toEqual([
58 { name: "EXTRA_FLAG", value: "1", sensitive: false },
59 { name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
60 ]);
61 });
62​
63 it("replaces redacted provider secrets without preserving redaction markers", () => {
64 expect(
65 nextProviderEnvironmentWithFieldValue(
66 [
67 {
68 name: "CURSOR_API_KEY",
69 value: "",
70 sensitive: true,
71 valueRedacted: true,
72 },
73 ],
74 cursorApiKeyField,
75 "new-key",
76 ),
77 ).toEqual([{ name: "CURSOR_API_KEY", value: "new-key", sensitive: true }]);
78 });
79​
80 it("applies the secure field default when replacing an existing non-sensitive value", () => {
81 expect(
82 nextProviderEnvironmentWithFieldValue(
83 [{ name: "OPENAI_API_KEY", value: "old-key", sensitive: false }],
84 {
85 name: "OPENAI_API_KEY",
86 label: "OpenAI API key",
87 },
88 "new-key",
89 ),
90 ).toEqual([{ name: "OPENAI_API_KEY", value: "new-key", sensitive: true }]);
91 });
92​
93 it("separates dedicated provider secrets from the generic environment table", () => {
94 const environment = [
95 { name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
96 { name: "EXTRA_FLAG", value: "1", sensitive: false },
97 ];
98​
99 expect(readProviderEnvironmentVariable(environment, "CURSOR_API_KEY")?.value).toBe(
100 "cursor-key",
101 );
102 expect(providerEnvironmentWithoutNames(environment, new Set(["CURSOR_API_KEY"]))).toEqual([
103 { name: "EXTRA_FLAG", value: "1", sensitive: false },
104 ]);
105 });
106});