Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions packages/shared/src/serverSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,34 @@ import { resolveServerBackgroundActivitySettings } from "./backgroundActivitySet
import { createModelSelection } from "./model.ts";
import {
applyServerSettingsPatch,
extractPersistedServerObservabilitySettings,
isModelSelectionProviderEnabled,
normalizePersistedServerSettingString,
parsePersistedServerObservabilitySettings,
resolveSourceControlWriterModelSelection,
} from "./serverSettings.ts";

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", () => {
it("ignores missing and blank persisted observability URLs", () => {
expect(parsePersistedServerObservabilitySettings("{}")).toEqual({
otlpTracesUrl: undefined,
otlpMetricsUrl: undefined,
});
expect(
extractPersistedServerObservabilitySettings({
observability: {
otlpTracesUrl: " http://localhost:4318/v1/traces ",
otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
},
}),
parsePersistedServerObservabilitySettings(
JSON.stringify({ observability: { otlpTracesUrl: " ", otlpMetricsUrl: "" } }),
),
).toEqual({
otlpTracesUrl: "http://localhost:4318/v1/traces",
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
otlpTracesUrl: undefined,
otlpMetricsUrl: undefined,
});
});

it("parses lenient persisted settings JSON", () => {
it("parses lenient persisted settings JSON and trims observability URLs", () => {
expect(
parsePersistedServerObservabilitySettings(
JSON.stringify({
observability: {
otlpTracesUrl: "http://localhost:4318/v1/traces",
otlpMetricsUrl: "http://localhost:4318/v1/metrics",
otlpTracesUrl: " http://localhost:4318/v1/traces ",
otlpMetricsUrl: " http://localhost:4318/v1/metrics ",
},
}),
),
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/serverSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ export interface PersistedServerObservabilitySettings {
readonly otlpMetricsUrl: string | undefined;
}

export function normalizePersistedServerSettingString(
function normalizePersistedServerSettingString(
value: string | null | undefined,
): string | undefined {
const trimmed = value?.trim();
return trimmed && trimmed.length > 0 ? trimmed : undefined;
}

export function extractPersistedServerObservabilitySettings(input: {
function extractPersistedServerObservabilitySettings(input: {
readonly observability?: {
readonly otlpTracesUrl?: string;
readonly otlpMetricsUrl?: string;
Expand Down
Loading