refactor(shared): keep persisted settings helpers private (#10004)
This commit is contained in:
1 parent
8d48a3134f
commit
1584076d76
2 files changed
+15
-24
No files matched your search
@@ -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 ",
|
||||
},
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user