fix(cli): bound advertised decimal-token schemas by the domain range (#9808)

`cliDecimalField` published the domain range on the integer branch and only
the fixed `^[0-9]+$` guard on the decimal-token branch, and JSON Schema
bounds do not constrain strings. A client validating raw argv text against
`--schema` therefore admitted out-of-range tokens such as `--row-limit=0` or
`--block-size=255` that the parser rejects with `VALIDATION_ERROR`.

Publish the domain range on the token branch through the schema-constraint
owner, keeping the CLI's decimal leading-zero convention and the existing
parser diagnostics: the declaration is metadata, so accepted values and
`too_small`/`too_big` messages are unchanged. Non-range refinements such as
the power-of-two entropy block size stay parser-only, and an open-ended
domain still publishes its floor. The getting-started guide states the same
contract.

Fixes #9348
This commit is contained in:
IvenKoo authored and GitHub committed 2026-11-18 09:11:20 -05:00
1 parent 41cf9654da
commit 80f533da8a
9 files changed
+338 -61

No files matched your search

+7 -3
View File
@@ -1,5 +1,8 @@
import { z } from "zod";
import { declaredTokenPattern } from "../domain/schemaConstraints.js";
import { decimalTokenPattern } from "./decimalTokenPattern.js";
import { OPEN_BINARY_TOOL_CONTRACT } from "../contracts/sessionToolContracts.js";
import type { CliSessionTarget } from "./contractCliDescription.js";
@@ -14,9 +17,10 @@ type DecimalWrapper =
};
const decimalToken = (domain: z.ZodNumber) =>
z
.string()
.regex(DECIMAL_INTEGER_TOKEN, "Expected a decimal integer")
declaredTokenPattern(
z.string().regex(DECIMAL_INTEGER_TOKEN, "Expected a decimal integer"),
new RegExp(decimalTokenPattern(domain), "u"),
)
.pipe(z.coerce.number<string>())
.pipe(domain);