Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SettingsPanels.logic.test.ts

104 lines3.3 KB

1import {
2 DEFAULT_SERVER_SETTINGS,
3 ProviderDriverKind,
4 ProviderInstanceId,
5 type ProviderInstanceConfig,
6} from "@t3tools/contracts";
7import { describe, expect, it } from "vite-plus/test";
8import {
9 buildProviderInstanceUpdatePatch,
10 formatDiagnosticsDescription,
11} from "./SettingsPanels.logic";
12​
13describe("formatDiagnosticsDescription", () => {
14 it("collapses trace and metric URLs that share the same OTEL base path", () => {
15 expect(
16 formatDiagnosticsDescription({
17 localTracingEnabled: true,
18 otlpTracesEnabled: true,
19 otlpTracesUrl: "http://localhost:4318/v1/traces",
20 otlpMetricsEnabled: true,
21 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
22 }),
23 ).toBe("Local trace file. Exporting OTEL to http://localhost:4318/v1/{traces,metrics}.");
24 });
25​
26 it("keeps separate trace and metric URLs when their base paths differ", () => {
27 expect(
28 formatDiagnosticsDescription({
29 localTracingEnabled: true,
30 otlpTracesEnabled: true,
31 otlpTracesUrl: "http://localhost:4318/v1/traces",
32 otlpMetricsEnabled: true,
33 otlpMetricsUrl: "http://localhost:9000/v1/metrics",
34 }),
35 ).toBe(
36 "Local trace file. Exporting OTEL traces to http://localhost:4318/v1/traces and metrics to http://localhost:9000/v1/metrics.",
37 );
38 });
39​
40 it("omits OTEL text when no exporter is enabled", () => {
41 expect(
42 formatDiagnosticsDescription({
43 localTracingEnabled: true,
44 otlpTracesEnabled: false,
45 otlpMetricsEnabled: false,
46 }),
47 ).toBe("Local trace file.");
48 });
49});
50​
51describe("buildProviderInstanceUpdatePatch", () => {
52 it("promotes an edited default provider into providerInstances and resets the legacy provider", () => {
53 const instanceId = ProviderInstanceId.make("codex");
54 const nextInstance = {
55 driver: ProviderDriverKind.make("codex"),
56 enabled: true,
57 config: {
58 binaryPath: "/opt/t3/codex",
59 },
60 } satisfies ProviderInstanceConfig;
61​
62 const patch = buildProviderInstanceUpdatePatch({
63 settings: {
64 ...DEFAULT_SERVER_SETTINGS,
65 providers: {
66 ...DEFAULT_SERVER_SETTINGS.providers,
67 codex: {
68 ...DEFAULT_SERVER_SETTINGS.providers.codex,
69 binaryPath: "/legacy/codex",
70 },
71 },
72 },
73 instanceId,
74 instance: nextInstance,
75 driver: ProviderDriverKind.make("codex"),
76 isDefault: true,
77 });
78​
79 expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
80 expect(patch.providers?.codex).toEqual(DEFAULT_SERVER_SETTINGS.providers.codex);
81 });
82​
83 it("updates custom instances without touching legacy provider settings", () => {
84 const instanceId = ProviderInstanceId.make("codex_personal");
85 const nextInstance = {
86 driver: ProviderDriverKind.make("codex"),
87 enabled: true,
88 config: {
89 homePath: "/Users/example/.codex-personal",
90 },
91 } satisfies ProviderInstanceConfig;
92​
93 const patch = buildProviderInstanceUpdatePatch({
94 settings: DEFAULT_SERVER_SETTINGS,
95 instanceId,
96 instance: nextInstance,
97 driver: ProviderDriverKind.make("codex"),
98 isDefault: false,
99 });
100​
101 expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
102 expect(patch.providers).toBeUndefined();
103 });
104});