Open History to see the last commit
1import { createElement } from "react";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4import {
5 ProviderDriverKind,
6 ProviderInstanceId,
7 type ServerProvider,
8 type ServerProviderModel,
9} from "@t3tools/contracts";
10
11import { deriveProviderModelsForDisplay, ProviderInstanceCard } from "./ProviderInstanceCard";
12
13describe("deriveProviderModelsForDisplay", () => {
14 it("uses current config custom models instead of stale live custom rows", () => {
15 const liveModels: ReadonlyArray<ServerProviderModel> = [
16 {
17 slug: "server-model",
18 name: "Server Model",
19 isCustom: false,
20 capabilities: null,
21 },
22 {
23 slug: "removed-custom",
24 name: "Removed Custom",
25 isCustom: true,
26 capabilities: null,
27 },
28 {
29 slug: "kept-custom",
30 name: "Kept Custom",
31 isCustom: true,
32 capabilities: null,
33 },
34 ];
35
36 expect(
37 deriveProviderModelsForDisplay({
38 liveModels,
39 customModels: [{ slug: "kept-custom", name: "kept-custom", capabilities: null }],
40 }).map((model) => model.slug),
41 ).toEqual(["server-model", "kept-custom"]);
42 });
43
44 it("prefers the entry's name and capabilities over the stale live custom row", () => {
45 const liveCapabilities = { optionDescriptors: [] };
46 const customCapabilities = {
47 optionDescriptors: [
48 {
49 id: "reasoningEffort",
50 label: "Reasoning",
51 type: "select" as const,
52 options: [{ id: "high", label: "High", isDefault: true }],
53 currentValue: "high",
54 },
55 ],
56 };
57 const liveModels: ReadonlyArray<ServerProviderModel> = [
58 { slug: "bare", name: "bare", isCustom: true, capabilities: liveCapabilities },
59 { slug: "named", name: "named", isCustom: true, capabilities: liveCapabilities },
60 ];
61
62 const display = deriveProviderModelsForDisplay({
63 liveModels,
64 customModels: [
65 { slug: "bare", name: "bare", capabilities: null },
66 { slug: "named", name: "My Model", capabilities: customCapabilities },
67 ],
68 });
69
70 // A bare entry keeps the driver default the server filled in.
71 expect(display[0]).toEqual({
72 slug: "bare",
73 name: "bare",
74 isCustom: true,
75 capabilities: liveCapabilities,
76 });
77 expect(display[1]).toEqual({
78 slug: "named",
79 name: "My Model",
80 isCustom: true,
81 capabilities: customCapabilities,
82 });
83 });
84
85 it("shows a redacted provider email in the editor header status line", () => {
86 const instanceId = ProviderInstanceId.make("codex");
87 const driver = ProviderDriverKind.make("codex");
88 const liveProvider: ServerProvider = {
89 instanceId,
90 driver,
91 enabled: true,
92 installed: true,
93 version: "1.0.0",
94 status: "ready",
95 auth: { status: "authenticated", email: "developer@example.com" },
96 checkedAt: "2026-08-27T12:00:00.000Z",
97 models: [],
98 slashCommands: [],
99 skills: [],
100 };
101
102 const markup = renderToStaticMarkup(
103 createElement(ProviderInstanceCard, {
104 instanceId,
105 instance: { driver },
106 driverOption: undefined,
107 liveProvider,
108 mode: "editor",
109 onUpdate: () => undefined,
110 hiddenModels: [],
111 favoriteModels: [],
112 modelOrder: [],
113 onHiddenModelsChange: () => undefined,
114 onFavoriteModelsChange: () => undefined,
115 onModelOrderChange: () => undefined,
116 }),
117 );
118
119 expect(markup).toContain("Authenticated as");
120 expect(markup).toContain('aria-label="Toggle account email visibility"');
121 expect(markup).toContain("blur-xs");
122 expect(markup).not.toContain("developer@example.com");
123 });
124 it("surfaces a failed probe message in both the list row and the editor", () => {
125 const instanceId = ProviderInstanceId.make("codex_work");
126 const driver = ProviderDriverKind.make("codex");
127 const message =
128 "Codex app-server provider probe failed: Cannot create Codex shadow home entry 'auth.json' because '/home/me/.codex-t3/work/auth.json' already exists and is not a symlink.";
129 const liveProvider: ServerProvider = {
130 instanceId,
131 driver,
132 enabled: true,
133 installed: true,
134 version: null,
135 status: "error",
136 auth: { status: "unknown" },
137 checkedAt: "2026-08-28T12:00:00.000Z",
138 models: [],
139 slashCommands: [],
140 skills: [],
141 message,
142 };
143 const props = {
144 instanceId,
145 instance: { driver },
146 driverOption: undefined,
147 liveProvider,
148 onUpdate: () => undefined,
149 hiddenModels: [],
150 favoriteModels: [],
151 modelOrder: [],
152 onHiddenModelsChange: () => undefined,
153 onFavoriteModelsChange: () => undefined,
154 onModelOrderChange: () => undefined,
155 } as const;
156
157 for (const mode of ["list", "editor"] as const) {
158 const markup = renderToStaticMarkup(createElement(ProviderInstanceCard, { ...props, mode }));
159 expect(markup).toContain("Unavailable");
160 expect(markup).toContain("is not a symlink");
161 }
162 });
163});