Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
237 lines
7.2 KiB
TypeScript
237 lines
7.2 KiB
TypeScript
import { createElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
import {
|
|
ProviderDriverKind,
|
|
ProviderInstanceId,
|
|
type ServerProvider,
|
|
type ServerProviderModel,
|
|
} from "@t3tools/contracts";
|
|
|
|
import {
|
|
deriveProviderModelsForDisplay,
|
|
nextProviderEnvironmentWithFieldValue,
|
|
providerEnvironmentWithoutNames,
|
|
ProviderInstanceCard,
|
|
readProviderEnvironmentVariable,
|
|
} from "./ProviderInstanceCard";
|
|
|
|
describe("deriveProviderModelsForDisplay", () => {
|
|
it("uses current config custom models instead of stale live custom rows", () => {
|
|
const liveModels: ReadonlyArray<ServerProviderModel> = [
|
|
{
|
|
slug: "server-model",
|
|
name: "Server Model",
|
|
isCustom: false,
|
|
capabilities: null,
|
|
},
|
|
{
|
|
slug: "removed-custom",
|
|
name: "Removed Custom",
|
|
isCustom: true,
|
|
capabilities: null,
|
|
},
|
|
{
|
|
slug: "kept-custom",
|
|
name: "Kept Custom",
|
|
isCustom: true,
|
|
capabilities: null,
|
|
},
|
|
];
|
|
|
|
expect(
|
|
deriveProviderModelsForDisplay({
|
|
liveModels,
|
|
customModels: [{ slug: "kept-custom", name: "kept-custom", capabilities: null }],
|
|
}).map((model) => model.slug),
|
|
).toEqual(["server-model", "kept-custom"]);
|
|
});
|
|
|
|
it("prefers the entry's name and capabilities over the stale live custom row", () => {
|
|
const liveCapabilities = { optionDescriptors: [] };
|
|
const customCapabilities = {
|
|
optionDescriptors: [
|
|
{
|
|
id: "reasoningEffort",
|
|
label: "Reasoning",
|
|
type: "select" as const,
|
|
options: [{ id: "high", label: "High", isDefault: true }],
|
|
currentValue: "high",
|
|
},
|
|
],
|
|
};
|
|
const liveModels: ReadonlyArray<ServerProviderModel> = [
|
|
{ slug: "bare", name: "bare", isCustom: true, capabilities: liveCapabilities },
|
|
{ slug: "named", name: "named", isCustom: true, capabilities: liveCapabilities },
|
|
];
|
|
|
|
const display = deriveProviderModelsForDisplay({
|
|
liveModels,
|
|
customModels: [
|
|
{ slug: "bare", name: "bare", capabilities: null },
|
|
{ slug: "named", name: "My Model", capabilities: customCapabilities },
|
|
],
|
|
});
|
|
|
|
// A bare entry keeps the driver default the server filled in.
|
|
expect(display[0]).toEqual({
|
|
slug: "bare",
|
|
name: "bare",
|
|
isCustom: true,
|
|
capabilities: liveCapabilities,
|
|
});
|
|
expect(display[1]).toEqual({
|
|
slug: "named",
|
|
name: "My Model",
|
|
isCustom: true,
|
|
capabilities: customCapabilities,
|
|
});
|
|
});
|
|
|
|
it("shows a redacted provider email in the editor header status line", () => {
|
|
const instanceId = ProviderInstanceId.make("codex");
|
|
const driver = ProviderDriverKind.make("codex");
|
|
const liveProvider: ServerProvider = {
|
|
instanceId,
|
|
driver,
|
|
enabled: true,
|
|
installed: true,
|
|
version: "1.0.0",
|
|
status: "ready",
|
|
auth: { status: "authenticated", email: "[email protected]" },
|
|
checkedAt: "2026-08-27T12:00:00.000Z",
|
|
models: [],
|
|
slashCommands: [],
|
|
skills: [],
|
|
};
|
|
|
|
const markup = renderToStaticMarkup(
|
|
createElement(ProviderInstanceCard, {
|
|
instanceId,
|
|
instance: { driver },
|
|
driverOption: undefined,
|
|
liveProvider,
|
|
mode: "editor",
|
|
onUpdate: () => undefined,
|
|
hiddenModels: [],
|
|
favoriteModels: [],
|
|
modelOrder: [],
|
|
onHiddenModelsChange: () => undefined,
|
|
onFavoriteModelsChange: () => undefined,
|
|
onToggleFavorite: () => undefined,
|
|
onModelOrderChange: () => undefined,
|
|
}),
|
|
);
|
|
|
|
expect(markup).toContain("Authenticated as");
|
|
expect(markup).toContain('aria-label="Toggle account email visibility"');
|
|
expect(markup).toContain("blur-xs");
|
|
expect(markup).not.toContain("[email protected]");
|
|
});
|
|
it("surfaces a failed probe message in both the list row and the editor", () => {
|
|
const instanceId = ProviderInstanceId.make("codex_work");
|
|
const driver = ProviderDriverKind.make("codex");
|
|
const message =
|
|
"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.";
|
|
const liveProvider: ServerProvider = {
|
|
instanceId,
|
|
driver,
|
|
enabled: true,
|
|
installed: true,
|
|
version: null,
|
|
status: "error",
|
|
auth: { status: "unknown" },
|
|
checkedAt: "2026-08-28T12:00:00.000Z",
|
|
models: [],
|
|
slashCommands: [],
|
|
skills: [],
|
|
message,
|
|
};
|
|
const props = {
|
|
instanceId,
|
|
instance: { driver },
|
|
driverOption: undefined,
|
|
liveProvider,
|
|
onUpdate: () => undefined,
|
|
hiddenModels: [],
|
|
favoriteModels: [],
|
|
modelOrder: [],
|
|
onHiddenModelsChange: () => undefined,
|
|
onFavoriteModelsChange: () => undefined,
|
|
onToggleFavorite: () => undefined,
|
|
onModelOrderChange: () => undefined,
|
|
} as const;
|
|
|
|
for (const mode of ["list", "editor"] as const) {
|
|
const markup = renderToStaticMarkup(createElement(ProviderInstanceCard, { ...props, mode }));
|
|
expect(markup).toContain("Unavailable");
|
|
expect(markup).toContain("is not a symlink");
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("provider environment helpers", () => {
|
|
const cursorApiKeyField = {
|
|
name: "CURSOR_API_KEY",
|
|
label: "Cursor API key",
|
|
sensitive: true,
|
|
};
|
|
|
|
it("writes dedicated provider secrets as sensitive environment variables", () => {
|
|
expect(
|
|
nextProviderEnvironmentWithFieldValue(
|
|
[{ name: "EXTRA_FLAG", value: "1", sensitive: false }],
|
|
cursorApiKeyField,
|
|
" cursor-key ",
|
|
),
|
|
).toEqual([
|
|
{ name: "EXTRA_FLAG", value: "1", sensitive: false },
|
|
{ name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
|
|
]);
|
|
});
|
|
|
|
it("replaces redacted provider secrets without preserving redaction markers", () => {
|
|
expect(
|
|
nextProviderEnvironmentWithFieldValue(
|
|
[
|
|
{
|
|
name: "CURSOR_API_KEY",
|
|
value: "",
|
|
sensitive: true,
|
|
valueRedacted: true,
|
|
},
|
|
],
|
|
cursorApiKeyField,
|
|
"new-key",
|
|
),
|
|
).toEqual([{ name: "CURSOR_API_KEY", value: "new-key", sensitive: true }]);
|
|
});
|
|
|
|
it("applies the secure field default when replacing an existing non-sensitive value", () => {
|
|
expect(
|
|
nextProviderEnvironmentWithFieldValue(
|
|
[{ name: "OPENAI_API_KEY", value: "old-key", sensitive: false }],
|
|
{
|
|
name: "OPENAI_API_KEY",
|
|
label: "OpenAI API key",
|
|
},
|
|
"new-key",
|
|
),
|
|
).toEqual([{ name: "OPENAI_API_KEY", value: "new-key", sensitive: true }]);
|
|
});
|
|
|
|
it("separates dedicated provider secrets from the generic environment table", () => {
|
|
const environment = [
|
|
{ name: "CURSOR_API_KEY", value: "cursor-key", sensitive: true },
|
|
{ name: "EXTRA_FLAG", value: "1", sensitive: false },
|
|
];
|
|
|
|
expect(readProviderEnvironmentVariable(environment, "CURSOR_API_KEY")?.value).toBe(
|
|
"cursor-key",
|
|
);
|
|
expect(providerEnvironmentWithoutNames(environment, new Set(["CURSOR_API_KEY"]))).toEqual([
|
|
{ name: "EXTRA_FLAG", value: "1", sensitive: false },
|
|
]);
|
|
});
|
|
});
|