Skip to content

Commit 041d48e

Browse files
authored
refactor(config): simplify allowed-value formatting (#129064)
* refactor(config): simplify allowed-value formatting * chore(config): tighten allowed-value assertion baseline
1 parent fd571f5 commit 041d48e

2 files changed

Lines changed: 6 additions & 19 deletions

File tree

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,7 @@ src/commands/tasks.ts 2
26572657
src/commands/telemetry-exporter-summary.ts 3
26582658
src/commands/test-runtime-config-helpers.ts 3
26592659
src/config/agent-dirs.ts 1
2660-
src/config/allowed-values.ts 2
2660+
src/config/allowed-values.ts 1
26612661
src/config/bundled-channel-config-metadata.generated.ts 1
26622662
src/config/channel-alias-migration.ts 2
26632663
src/config/channel-capabilities.ts 2

‎src/config/allowed-values.ts‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,13 @@ function toAllowedValueLabel(value: unknown): string {
4444
}
4545

4646
function toAllowedValueValue(value: unknown): string {
47-
if (typeof value === "string") {
48-
return value;
49-
}
50-
return safeStringify(value);
47+
return typeof value === "string" ? value : safeStringify(value);
5148
}
5249

5350
function toAllowedValueDedupKey(value: unknown): string {
54-
if (value === null) {
55-
return "null:null";
56-
}
57-
const kind = typeof value;
51+
const kind = value === null ? "null" : typeof value;
5852
// Preserve schema distinctions such as numeric 1 vs string "1" even when labels match.
59-
if (kind === "string") {
60-
return `string:${value as string}`;
61-
}
62-
return `${kind}:${safeStringify(value)}`;
53+
return `${kind}:${toAllowedValueValue(value)}`;
6354
}
6455

6556
/** Summarizes enum/allowed-value candidates for compact validation error hints. */
@@ -97,14 +88,10 @@ export function summarizeAllowedValues(
9788
};
9889
}
9990

100-
function messageAlreadyIncludesAllowedValues(message: string): boolean {
101-
const lower = normalizeLowercaseStringOrEmpty(message);
102-
return lower.includes("(allowed:") || lower.includes("expected one of");
103-
}
104-
10591
/** Appends an allowed-values hint unless the validation message already includes one. */
10692
export function appendAllowedValuesHint(message: string, summary: AllowedValuesSummary): string {
107-
if (messageAlreadyIncludesAllowedValues(message)) {
93+
const lower = normalizeLowercaseStringOrEmpty(message);
94+
if (lower.includes("(allowed:") || lower.includes("expected one of")) {
10895
return message;
10996
}
11097
return `${message} (allowed: ${summary.formatted})`;

0 commit comments

Comments
 (0)