Skip to content

Commit a539568

Browse files
refactor(shared): keep persisted settings helpers private
1 parent 32142cf commit a539568

2 files changed

Lines changed: 15 additions & 24 deletions

File tree

‎packages/shared/src/serverSettings.test.ts‎

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,34 @@ import { resolveServerBackgroundActivitySettings } from "./backgroundActivitySet
1111
import { createModelSelection } from "./model.ts";
1212
import {
1313
applyServerSettingsPatch,
14-
extractPersistedServerObservabilitySettings,
1514
isModelSelectionProviderEnabled,
16-
normalizePersistedServerSettingString,
1715
parsePersistedServerObservabilitySettings,
1816
resolveSourceControlWriterModelSelection,
1917
} from "./serverSettings.ts";
2018

2119
describe("serverSettings helpers", () => {
22-
it("normalizes optional persisted strings", () => {
23-
expect(normalizePersistedServerSettingString(undefined)).toBeUndefined();
24-
expect(normalizePersistedServerSettingString(" ")).toBeUndefined();
25-
expect(normalizePersistedServerSettingString(" http://localhost:4318/v1/traces ")).toBe(
26-
"http://localhost:4318/v1/traces",
27-
);
28-
});
29-
30-
it("extracts persisted observability settings", () => {
20+
it("ignores missing and blank persisted observability URLs", () => {
21+
expect(parsePersistedServerObservabilitySettings("{}")).toEqual({
22+
otlpTracesUrl: undefined,
23+
otlpMetricsUrl: undefined,
24+
});
3125
expect(
32-
extractPersistedServerObservabilitySettings({
33-
observability: {
34-
otlpTracesUrl: " http://localhost:4318/v1/traces ",
35-
otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
36-
},
37-
}),
26+
parsePersistedServerObservabilitySettings(
27+
JSON.stringify({ observability: { otlpTracesUrl: " ", otlpMetricsUrl: "" } }),
28+
),
3829
).toEqual({
39-
otlpTracesUrl: "http://localhost:4318/v1/traces",
40-
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
30+
otlpTracesUrl: undefined,
31+
otlpMetricsUrl: undefined,
4132
});
4233
});
4334

44-
it("parses lenient persisted settings JSON", () => {
35+
it("parses lenient persisted settings JSON and trims observability URLs", () => {
4536
expect(
4637
parsePersistedServerObservabilitySettings(
4738
JSON.stringify({
4839
observability: {
49-
otlpTracesUrl: "http://localhost:4318/v1/traces",
50-
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
40+
otlpTracesUrl: " http://localhost:4318/v1/traces ",
41+
otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
5142
},
5243
}),
5344
),

‎packages/shared/src/serverSettings.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ export interface PersistedServerObservabilitySettings {
6969
readonly otlpMetricsUrl: string | undefined;
7070
}
7171

72-
export function normalizePersistedServerSettingString(
72+
function normalizePersistedServerSettingString(
7373
value: string | null | undefined,
7474
): string | undefined {
7575
const trimmed = value?.trim();
7676
return trimmed && trimmed.length > 0 ? trimmed : undefined;
7777
}
7878

79-
export function extractPersistedServerObservabilitySettings(input: {
79+
function extractPersistedServerObservabilitySettings(input: {
8080
readonly observability?: {
8181
readonly otlpTracesUrl?: string;
8282
readonly otlpMetricsUrl?: string;

0 commit comments

Comments
 (0)