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