Skip to content

Commit 01fcc4b

Browse files
committed
fix(config): append numeric bounds in validation errors
1 parent 5c591a4 commit 01fcc4b

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/config/validation.allowed-values.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ describe("config validation allowed-values metadata", () => {
4444
expect(issue.allowedValuesHiddenCount).toBe(0);
4545
});
4646

47+
it("appends numeric max constraints to schema errors", () => {
48+
const result = validateConfigObjectRaw({
49+
session: {
50+
agentToAgent: {
51+
maxPingPongTurns: 10,
52+
},
53+
},
54+
});
55+
56+
expect(result.ok).toBe(false);
57+
if (!result.ok) {
58+
const issue = result.issues.find(
59+
(entry) => entry.path === "session.agentToAgent.maxPingPongTurns",
60+
);
61+
expect(issue).toBeDefined();
62+
expect(issue?.message).toContain("maximum allowed value is 5");
63+
}
64+
});
65+
4766
it("includes boolean variants for boolean-or-enum unions", () => {
4867
const issue = __testing.mapZodIssueToConfigIssue({
4968
code: "custom",

src/config/validation.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,33 @@ function collectLegacySecretRefEnvMarkerIssues(raw: unknown): ConfigValidationIs
484484
}));
485485
}
486486

487+
function appendNumericConstraintHint(record: UnknownIssueRecord | null, message: string): string {
488+
if (!record || typeof record.code !== "string") {
489+
return message;
490+
}
491+
492+
if (record.code === "too_big") {
493+
const maximum = typeof record.maximum === "number" ? record.maximum : null;
494+
if (maximum !== null) {
495+
return `${message} (maximum allowed value is ${maximum})`;
496+
}
497+
}
498+
499+
if (record.code === "too_small") {
500+
const minimum = typeof record.minimum === "number" ? record.minimum : null;
501+
if (minimum !== null) {
502+
return `${message} (minimum allowed value is ${minimum})`;
503+
}
504+
}
505+
506+
return message;
507+
}
508+
487509
function mapZodIssueToConfigIssue(issue: unknown): ConfigValidationIssue {
488510
const record = toIssueRecord(issue);
489511
const path = formatConfigPath(toConfigPathSegments(record?.path));
490-
const message = typeof record?.message === "string" ? record.message : "Invalid input";
512+
const rawMessage = typeof record?.message === "string" ? record.message : "Invalid input";
513+
const message = appendNumericConstraintHint(record, rawMessage);
491514

492515
const allowedValuesSummary = summarizeAllowedValues(collectAllowedValuesFromUnknownIssue(issue));
493516

0 commit comments

Comments
 (0)