authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 00:26:54-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 00:26:54-07:00
log1584076d7651278863f7ee90f5bf70c2aba981b3
tree81062a70838d10ea053d3325392667ad3ec59150
parent8d48a3134f4d789f54128ccbb65919812ffc7921
signature Signed by PGP key B5690EEEBB952194

refactor(shared): keep persisted settings helpers private (#10004)


2 files changed, 15 insertions(+), 24 deletions(-)

packages/shared/src/serverSettings.test.ts+13-22
...@@ -11,43 +11,34 @@ import { resolveServerBackgroundActivitySettings } from "./backgroundActivitySet...@@ -11,43 +11,34 @@ import { resolveServerBackgroundActivitySettings } from "./backgroundActivitySet
11import { createModelSelection } from "./model.ts";11import { createModelSelection } from "./model.ts";
12import {12import {
13 applyServerSettingsPatch,13 applyServerSettingsPatch,
14 extractPersistedServerObservabilitySettings,
15 isModelSelectionProviderEnabled,14 isModelSelectionProviderEnabled,
16 normalizePersistedServerSettingString,
17 parsePersistedServerObservabilitySettings,15 parsePersistedServerObservabilitySettings,
18 resolveSourceControlWriterModelSelection,16 resolveSourceControlWriterModelSelection,
19} from "./serverSettings.ts";17} from "./serverSettings.ts";
2018
21describe("serverSettings helpers", () => {19describe("serverSettings helpers", () => {
22 it("normalizes optional persisted strings", () => {20 it("ignores missing and blank persisted observability URLs", () => {
23 expect(normalizePersistedServerSettingString(undefined)).toBeUndefined();21 expect(parsePersistedServerObservabilitySettings("{}")).toEqual({
24 expect(normalizePersistedServerSettingString(" ")).toBeUndefined();22 otlpTracesUrl: undefined,
25 expect(normalizePersistedServerSettingString(" http://localhost:4318/v1/traces ")).toBe(23 otlpMetricsUrl: undefined,
26 "http://localhost:4318/v1/traces",24 });
27 );
28 });
29
30 it("extracts persisted observability settings", () => {
31 expect(25 expect(
32 extractPersistedServerObservabilitySettings({26 parsePersistedServerObservabilitySettings(
33 observability: {27 JSON.stringify({ observability: { otlpTracesUrl: " ", otlpMetricsUrl: "" } }),
34 otlpTracesUrl: " http://localhost:4318/v1/traces ",28 ),
35 otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
36 },
37 }),
38 ).toEqual({29 ).toEqual({
39 otlpTracesUrl: "http://localhost:4318/v1/traces",30 otlpTracesUrl: undefined,
40 otlpMetricsUrl: "http://localhost:4318/v1/metrics",31 otlpMetricsUrl: undefined,
41 });32 });
42 });33 });
4334
44 it("parses lenient persisted settings JSON", () => {35 it("parses lenient persisted settings JSON and trims observability URLs", () => {
45 expect(36 expect(
46 parsePersistedServerObservabilitySettings(37 parsePersistedServerObservabilitySettings(
47 JSON.stringify({38 JSON.stringify({
48 observability: {39 observability: {
49 otlpTracesUrl: "http://localhost:4318/v1/traces",40 otlpTracesUrl: " http://localhost:4318/v1/traces ",
50 otlpMetricsUrl: "http://localhost:4318/v1/metrics",41 otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
51 },42 },
52 }),43 }),
53 ),44 ),
packages/shared/src/serverSettings.ts+2-2
...@@ -69,14 +69,14 @@ export interface PersistedServerObservabilitySettings {...@@ -69,14 +69,14 @@ export interface PersistedServerObservabilitySettings {
69 readonly otlpMetricsUrl: string | undefined;69 readonly otlpMetricsUrl: string | undefined;
70}70}
7171
72export function normalizePersistedServerSettingString(72function normalizePersistedServerSettingString(
73 value: string | null | undefined,73 value: string | null | undefined,
74): string | undefined {74): string | undefined {
75 const trimmed = value?.trim();75 const trimmed = value?.trim();
76 return trimmed && trimmed.length > 0 ? trimmed : undefined;76 return trimmed && trimmed.length > 0 ? trimmed : undefined;
77}77}
7878
79export function extractPersistedServerObservabilitySettings(input: {79function extractPersistedServerObservabilitySettings(input: {
80 readonly observability?: {80 readonly observability?: {
81 readonly otlpTracesUrl?: string;81 readonly otlpTracesUrl?: string;
82 readonly otlpMetricsUrl?: string;82 readonly otlpMetricsUrl?: string;