Files
t3code/apps/web/src/components/settings/ProviderInstanceCard.test.ts
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

235 lines
7.1 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,
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,
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 },
]);
});
});