mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
`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
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
import { expect } from "vitest";
|
|
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
cliTest.for([
|
|
{
|
|
command: "inspect-sqlite-database",
|
|
field: "rowLimit",
|
|
flag: "--row-limit",
|
|
accepted: ["1", "0001", "9007199254740991"],
|
|
rejected: ["0", "0000", "9007199254740992"],
|
|
},
|
|
{
|
|
command: "inspect-byte-entropy",
|
|
field: "blockSize",
|
|
flag: "--block-size",
|
|
accepted: ["256", "00256", "65536"],
|
|
rejected: ["0", "255", "65537", "0065537"],
|
|
},
|
|
])(
|
|
"advertises and enforces $command decimal bounds",
|
|
async (entry, { cli }) => {
|
|
const discovery = await cli.run({
|
|
arguments: [entry.command, "--schema", "--format", "json"],
|
|
});
|
|
expect(discovery.exitCode).toBe(0);
|
|
const schema = JSON.parse(discovery.stdout).options.properties[entry.field];
|
|
const validate = new Ajv2020({ strict: false }).compile(schema);
|
|
for (const token of entry.accepted)
|
|
expect(validate(token), token).toBe(true);
|
|
for (const token of entry.rejected) {
|
|
expect(validate(token), token).toBe(false);
|
|
const execution = await cli.run({
|
|
arguments: [
|
|
entry.command,
|
|
"/nonexistent/decimal-bounds-target",
|
|
`${entry.flag}=${token}`,
|
|
"--format",
|
|
"json",
|
|
],
|
|
});
|
|
expect(execution.exitCode).toBe(1);
|
|
expect(JSON.parse(execution.stdout)).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
fieldErrors: expect.arrayContaining([
|
|
expect.objectContaining({ path: entry.field }),
|
|
]),
|
|
});
|
|
}
|
|
},
|
|
);
|