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

serverSettings.test.ts

147 lines4.4 KB

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