113 lines
3.2 KiB
TypeScript
113 lines
3.2 KiB
TypeScript
import { DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyServerSettingsPatch,
|
|
extractPersistedServerObservabilitySettings,
|
|
normalizePersistedServerSettingString,
|
|
parsePersistedServerObservabilitySettings,
|
|
} from "./serverSettings";
|
|
|
|
describe("serverSettings helpers", () => {
|
|
it("normalizes optional persisted strings", () => {
|
|
expect(normalizePersistedServerSettingString(undefined)).toBeUndefined();
|
|
expect(normalizePersistedServerSettingString(" ")).toBeUndefined();
|
|
expect(normalizePersistedServerSettingString(" http://localhost:4318/v1/traces ")).toBe(
|
|
"http://localhost:4318/v1/traces",
|
|
);
|
|
});
|
|
|
|
it("extracts persisted observability settings", () => {
|
|
expect(
|
|
extractPersistedServerObservabilitySettings({
|
|
observability: {
|
|
otlpTracesUrl: " http://localhost:4318/v1/traces ",
|
|
otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
|
|
},
|
|
}),
|
|
).toEqual({
|
|
otlpTracesUrl: "http://localhost:4318/v1/traces",
|
|
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
|
|
});
|
|
});
|
|
|
|
it("parses lenient persisted settings JSON", () => {
|
|
expect(
|
|
parsePersistedServerObservabilitySettings(
|
|
JSON.stringify({
|
|
observability: {
|
|
otlpTracesUrl: "http://localhost:4318/v1/traces",
|
|
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
|
|
},
|
|
}),
|
|
),
|
|
).toEqual({
|
|
otlpTracesUrl: "http://localhost:4318/v1/traces",
|
|
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
|
|
});
|
|
});
|
|
|
|
it("falls back cleanly when persisted settings are invalid", () => {
|
|
expect(parsePersistedServerObservabilitySettings("{")).toEqual({
|
|
otlpTracesUrl: undefined,
|
|
otlpMetricsUrl: undefined,
|
|
});
|
|
});
|
|
|
|
it("replaces text generation selection when provider/model are provided", () => {
|
|
const current = {
|
|
...DEFAULT_SERVER_SETTINGS,
|
|
textGenerationModelSelection: {
|
|
provider: "codex" as const,
|
|
model: "gpt-5.4-mini",
|
|
options: {
|
|
reasoningEffort: "high" as const,
|
|
fastMode: true,
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(
|
|
applyServerSettingsPatch(current, {
|
|
textGenerationModelSelection: {
|
|
provider: "codex",
|
|
model: "gpt-5.4-mini",
|
|
},
|
|
}).textGenerationModelSelection,
|
|
).toEqual({
|
|
provider: "codex",
|
|
model: "gpt-5.4-mini",
|
|
});
|
|
});
|
|
|
|
it("still deep merges text generation selection when only options are provided", () => {
|
|
const current = {
|
|
...DEFAULT_SERVER_SETTINGS,
|
|
textGenerationModelSelection: {
|
|
provider: "codex" as const,
|
|
model: "gpt-5.4-mini",
|
|
options: {
|
|
reasoningEffort: "high" as const,
|
|
fastMode: true,
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(
|
|
applyServerSettingsPatch(current, {
|
|
textGenerationModelSelection: {
|
|
options: {
|
|
fastMode: false,
|
|
},
|
|
},
|
|
}).textGenerationModelSelection,
|
|
).toEqual({
|
|
provider: "codex",
|
|
model: "gpt-5.4-mini",
|
|
options: {
|
|
reasoningEffort: "high",
|
|
fastMode: false,
|
|
},
|
|
});
|
|
});
|
|
});
|