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

SettingsPanels.logic.test.ts

121 lines4.0 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 isProjectGroupingEnabled,
12 projectGroupingModeFromToggle,
13} from "./SettingsPanels.logic";
14​
15describe("project grouping toggle", () => {
16 it("enables repository grouping and disables into separate projects", () => {
17 expect(isProjectGroupingEnabled("repository")).toBe(true);
18 expect(isProjectGroupingEnabled("repository_path")).toBe(true);
19 expect(isProjectGroupingEnabled("separate")).toBe(false);
20 expect(projectGroupingModeFromToggle(true)).toBe("repository");
21 expect(projectGroupingModeFromToggle(false)).toBe("separate");
22 });
23​
24 it("restores repository path grouping when the toggle is cycled", () => {
25 expect(projectGroupingModeFromToggle(false, "repository_path")).toBe("separate");
26 expect(projectGroupingModeFromToggle(true, "repository_path")).toBe("repository_path");
27 });
28});
29​
30describe("formatDiagnosticsDescription", () => {
31 it("collapses trace and metric URLs that share the same OTEL base path", () => {
32 expect(
33 formatDiagnosticsDescription({
34 localTracingEnabled: true,
35 otlpTracesEnabled: true,
36 otlpTracesUrl: "http://localhost:4318/v1/traces",
37 otlpMetricsEnabled: true,
38 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
39 }),
40 ).toBe("Local trace file. Exporting OTEL to http://localhost:4318/v1/{traces,metrics}.");
41 });
42​
43 it("keeps separate trace and metric URLs when their base paths differ", () => {
44 expect(
45 formatDiagnosticsDescription({
46 localTracingEnabled: true,
47 otlpTracesEnabled: true,
48 otlpTracesUrl: "http://localhost:4318/v1/traces",
49 otlpMetricsEnabled: true,
50 otlpMetricsUrl: "http://localhost:9000/v1/metrics",
51 }),
52 ).toBe(
53 "Local trace file. Exporting OTEL traces to http://localhost:4318/v1/traces and metrics to http://localhost:9000/v1/metrics.",
54 );
55 });
56​
57 it("omits OTEL text when no exporter is enabled", () => {
58 expect(
59 formatDiagnosticsDescription({
60 localTracingEnabled: true,
61 otlpTracesEnabled: false,
62 otlpMetricsEnabled: false,
63 }),
64 ).toBe("Local trace file.");
65 });
66});
67​
68describe("buildProviderInstanceUpdatePatch", () => {
69 it("promotes an edited default provider into providerInstances and resets the legacy provider", () => {
70 const instanceId = ProviderInstanceId.make("codex");
71 const nextInstance = {
72 driver: ProviderDriverKind.make("codex"),
73 enabled: true,
74 config: {
75 binaryPath: "/opt/t3/codex",
76 },
77 } satisfies ProviderInstanceConfig;
78​
79 const patch = buildProviderInstanceUpdatePatch({
80 settings: {
81 ...DEFAULT_SERVER_SETTINGS,
82 providers: {
83 ...DEFAULT_SERVER_SETTINGS.providers,
84 codex: {
85 ...DEFAULT_SERVER_SETTINGS.providers.codex,
86 binaryPath: "/legacy/codex",
87 },
88 },
89 },
90 instanceId,
91 instance: nextInstance,
92 driver: ProviderDriverKind.make("codex"),
93 isDefault: true,
94 });
95​
96 expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
97 expect(patch.providers?.codex).toEqual(DEFAULT_SERVER_SETTINGS.providers.codex);
98 });
99​
100 it("updates custom instances without touching legacy provider settings", () => {
101 const instanceId = ProviderInstanceId.make("codex_personal");
102 const nextInstance = {
103 driver: ProviderDriverKind.make("codex"),
104 enabled: true,
105 config: {
106 homePath: "/Users/example/.codex-personal",
107 },
108 } satisfies ProviderInstanceConfig;
109​
110 const patch = buildProviderInstanceUpdatePatch({
111 settings: DEFAULT_SERVER_SETTINGS,
112 instanceId,
113 instance: nextInstance,
114 driver: ProviderDriverKind.make("codex"),
115 isDefault: false,
116 });
117​
118 expect(patch.providerInstances?.[instanceId]).toEqual(nextInstance);
119 expect(patch.providers).toBeUndefined();
120 });
121});