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

serverSettings.test.ts

138 lines3.8 KB

1import { DEFAULT_SERVER_SETTINGS } from "@workbench/contracts";
2import { describe, expect, it } from "vitest";
3import {
4 applyServerSettingsPatch,
5 extractPersistedServerObservabilitySettings,
6 normalizePersistedServerSettingString,
7 parsePersistedServerObservabilitySettings,
8} from "./serverSettings.ts";
9​
10describe("serverSettings helpers", () => {
11 it("normalizes optional persisted strings", () => {
12 expect(normalizePersistedServerSettingString(undefined)).toBeUndefined();
13 expect(normalizePersistedServerSettingString(" ")).toBeUndefined();
14 expect(normalizePersistedServerSettingString(" http://localhost:4318/v1/traces ")).toBe(
15 "http://localhost:4318/v1/traces",
16 );
17 });
18​
19 it("extracts persisted observability settings", () => {
20 expect(
21 extractPersistedServerObservabilitySettings({
22 observability: {
23 otlpTracesUrl: " http://localhost:4318/v1/traces ",
24 otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
25 },
26 }),
27 ).toEqual({
28 otlpTracesUrl: "http://localhost:4318/v1/traces",
29 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
30 });
31 });
32​
33 it("parses lenient persisted settings JSON", () => {
34 expect(
35 parsePersistedServerObservabilitySettings(
36 JSON.stringify({
37 observability: {
38 otlpTracesUrl: "http://localhost:4318/v1/traces",
39 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
40 },
41 }),
42 ),
43 ).toEqual({
44 otlpTracesUrl: "http://localhost:4318/v1/traces",
45 otlpMetricsUrl: "http://localhost:4318/v1/metrics",
46 });
47 });
48​
49 it("falls back cleanly when persisted settings are invalid", () => {
50 expect(parsePersistedServerObservabilitySettings("{")).toEqual({
51 otlpTracesUrl: undefined,
52 otlpMetricsUrl: undefined,
53 });
54 });
55​
56 it("replaces text generation selection when provider/model are provided", () => {
57 const current = {
58 ...DEFAULT_SERVER_SETTINGS,
59 textGenerationModelSelection: {
60 provider: "codex" as const,
61 model: "gpt-5.4-mini",
62 options: {
63 reasoningEffort: "high" as const,
64 fastMode: true,
65 },
66 },
67 };
68​
69 expect(
70 applyServerSettingsPatch(current, {
71 textGenerationModelSelection: {
72 provider: "codex",
73 model: "gpt-5.4-mini",
74 },
75 }).textGenerationModelSelection,
76 ).toEqual({
77 provider: "codex",
78 model: "gpt-5.4-mini",
79 });
80 });
81​
82 it("still deep merges text generation selection when only options are provided", () => {
83 const current = {
84 ...DEFAULT_SERVER_SETTINGS,
85 textGenerationModelSelection: {
86 provider: "codex" as const,
87 model: "gpt-5.4-mini",
88 options: {
89 reasoningEffort: "high" as const,
90 fastMode: true,
91 },
92 },
93 };
94​
95 expect(
96 applyServerSettingsPatch(current, {
97 textGenerationModelSelection: {
98 options: {
99 fastMode: false,
100 },
101 },
102 }).textGenerationModelSelection,
103 ).toEqual({
104 provider: "codex",
105 model: "gpt-5.4-mini",
106 options: {
107 reasoningEffort: "high",
108 fastMode: false,
109 },
110 });
111 });
112​
113 it("replaces text generation selection across providers without leaking stale options", () => {
114 const current = {
115 ...DEFAULT_SERVER_SETTINGS,
116 textGenerationModelSelection: {
117 provider: "codex" as const,
118 model: "gpt-5.4-mini",
119 options: {
120 reasoningEffort: "high" as const,
121 fastMode: true,
122 },
123 },
124 };
125​
126 expect(
127 applyServerSettingsPatch(current, {
128 textGenerationModelSelection: {
129 provider: "opencode",
130 model: "openai/gpt-5",
131 },
132 }).textGenerationModelSelection,
133 ).toEqual({
134 provider: "opencode",
135 model: "openai/gpt-5",
136 });
137 });
138});