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 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("separates dedicated provider secrets from the generic environment table", () => {
81 const environment = [
82 { name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
83 { name: "EXTRA_FLAG", value: "1", sensitive: false },
84 ];
85
86 expect(readProviderEnvironmentVariable(environment, "CURSOR_API_KEY")?.value).toBe(
87 "cursor-key",
88 );
89 expect(providerEnvironmentWithoutNames(environment, new Set(["CURSOR_API_KEY"]))).toEqual([
90 { name: "EXTRA_FLAG", value: "1", sensitive: false },
91 ]);
92 });
93});