refactor(config): simplify allowed-value formatting (#129064)

* refactor(config): simplify allowed-value formatting

* chore(config): tighten allowed-value assertion baseline
This commit is contained in:
Peter Steinberger
2026-08-25 00:22:20 -07:00
committed by GitHub
parent fd571f5295
commit 041d48eccb
2 changed files with 6 additions and 19 deletions
+1 -1
View File
@@ -2657,7 +2657,7 @@ src/commands/tasks.ts 2
src/commands/telemetry-exporter-summary.ts 3
src/commands/test-runtime-config-helpers.ts 3
src/config/agent-dirs.ts 1
src/config/allowed-values.ts 2
src/config/allowed-values.ts 1
src/config/bundled-channel-config-metadata.generated.ts 1
src/config/channel-alias-migration.ts 2
src/config/channel-capabilities.ts 2
+5 -18
View File
@@ -44,22 +44,13 @@ function toAllowedValueLabel(value: unknown): string {
}
function toAllowedValueValue(value: unknown): string {
if (typeof value === "string") {
return value;
}
return safeStringify(value);
return typeof value === "string" ? value : safeStringify(value);
}
function toAllowedValueDedupKey(value: unknown): string {
if (value === null) {
return "null:null";
}
const kind = typeof value;
const kind = value === null ? "null" : typeof value;
// Preserve schema distinctions such as numeric 1 vs string "1" even when labels match.
if (kind === "string") {
return `string:${value as string}`;
}
return `${kind}:${safeStringify(value)}`;
return `${kind}:${toAllowedValueValue(value)}`;
}
/** Summarizes enum/allowed-value candidates for compact validation error hints. */
@@ -97,14 +88,10 @@ export function summarizeAllowedValues(
};
}
function messageAlreadyIncludesAllowedValues(message: string): boolean {
const lower = normalizeLowercaseStringOrEmpty(message);
return lower.includes("(allowed:") || lower.includes("expected one of");
}
/** Appends an allowed-values hint unless the validation message already includes one. */
export function appendAllowedValuesHint(message: string, summary: AllowedValuesSummary): string {
if (messageAlreadyIncludesAllowedValues(message)) {
const lower = normalizeLowercaseStringOrEmpty(message);
if (lower.includes("(allowed:") || lower.includes("expected one of")) {
return message;
}
return `${message} (allowed: ${summary.formatted})`;