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