mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-23 02:45:38 -06:00
refactor: consolidate coercion contracts (#122458)
* refactor: consolidate coercion contracts Centralize exact string, record, numeric, date, Boolean, argument, and structured-error coercions while preserving call-site semantics. Migrate canonical-name collisions and deprecated internal SDK bypasses, deleting 55 net production/tooling lines. Expand declaration ownership enforcement to 101 allowed helpers and add a narrow export-completeness audit. * fix: preserve standalone script coercions Keep copied Control UI tooling self-contained and retain the trusted release harness module-relative source seam when the harness runs against an old target cwd.
This commit is contained in:
committed by
GitHub
parent
66fe424590
commit
b080dd1e76
@@ -2,13 +2,84 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
booleanFlag,
|
||||
classifyBoundedUnsignedDecimal,
|
||||
intFlag,
|
||||
parseFlagArgs,
|
||||
parsePermissiveBooleanToken,
|
||||
parseStrictBooleanArg,
|
||||
readFlagValue,
|
||||
stringFlag,
|
||||
stringListFlag,
|
||||
} from "../../scripts/lib/arg-utils.runtime.mjs";
|
||||
|
||||
describe("scripts/lib/arg-utils strict scalar grammars", () => {
|
||||
it.each([
|
||||
{ input: "true", expected: true },
|
||||
{ input: "false", expected: false },
|
||||
{ input: "", error: "--enabled must be true or false." },
|
||||
{ input: " ", error: "--enabled must be true or false." },
|
||||
{ input: " true", error: "--enabled must be true or false." },
|
||||
{ input: "false ", error: "--enabled must be true or false." },
|
||||
{ input: "TRUE", error: "--enabled must be true or false." },
|
||||
{ input: "False", error: "--enabled must be true or false." },
|
||||
{ input: "1", error: "--enabled must be true or false." },
|
||||
{ input: "0", error: "--enabled must be true or false." },
|
||||
{ input: "yes", error: "--enabled must be true or false." },
|
||||
{ input: true, error: "--enabled must be true or false." },
|
||||
{ input: 1, error: "--enabled must be true or false." },
|
||||
])("parses strict Boolean token %#", ({ input, expected, error }) => {
|
||||
if (error) {
|
||||
expect(() => parseStrictBooleanArg(input, "--enabled")).toThrow(error);
|
||||
return;
|
||||
}
|
||||
expect(parseStrictBooleanArg(input, "--enabled")).toBe(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ input: "0", min: 0, max: 10, expected: { kind: "value", value: 0 } },
|
||||
{ input: "001", min: 1, max: 10, expected: { kind: "value", value: 1 } },
|
||||
{ input: "10", min: 0, max: 10, expected: { kind: "value", value: 10 } },
|
||||
{ input: "0", min: 1, max: 10, expected: { kind: "below" } },
|
||||
{ input: "11", min: 0, max: 10, expected: { kind: "above" } },
|
||||
{ input: "9".repeat(400), min: 0, max: 10, expected: { kind: "above" } },
|
||||
{ input: "", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: " ", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: " 1", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "1 ", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "+1", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "-1", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "1.0", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "1e1", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "0x10", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "0b10", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
{ input: "1ms", min: 0, max: 10, expected: { kind: "syntax" } },
|
||||
])("classifies bounded unsigned decimal %#", ({ input, min, max, expected }) => {
|
||||
expect(classifyBoundedUnsignedDecimal(input, min, max)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("scripts/lib/arg-utils permissive Boolean tokens", () => {
|
||||
it.each([
|
||||
{ input: "true", expected: true },
|
||||
{ input: "1", expected: true },
|
||||
{ input: "yes", expected: true },
|
||||
{ input: "on", expected: true },
|
||||
{ input: "false", expected: false },
|
||||
{ input: "0", expected: false },
|
||||
{ input: "no", expected: false },
|
||||
{ input: "off", expected: false },
|
||||
{ input: " TRUE ", expected: true },
|
||||
{ input: " Off ", expected: false },
|
||||
{ input: "", expected: undefined },
|
||||
{ input: " ", expected: undefined },
|
||||
{ input: "enabled", expected: undefined },
|
||||
{ input: true, expected: undefined },
|
||||
{ input: 1, expected: undefined },
|
||||
])("parses $input as $expected", ({ input, expected }) => {
|
||||
expect(parsePermissiveBooleanToken(input)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("scripts/lib/arg-utils parseFlagArgs", () => {
|
||||
it("uses the last value when a flag is repeated", () => {
|
||||
expect(readFlagValue(["-p", "first.json", "-p", "second.json"], "-p")).toBe("second.json");
|
||||
|
||||
Reference in New Issue
Block a user