Restore strict --expire units in the shared duration tokenizer
The shared tokenizer accepts `ms` for the simulation windows, and without a per-caller unit set that grammar leaked into --expire: `--expire 500ms` was a usage error before the parsers were unified and became silently rounded to a 1h / 1s link after. tokenizeDuration now takes an allowed-unit set; the expire flags pass EXPIRE_UNITS (d/h/m/s) while parseDurationMs keeps the full set. Adds a regression test asserting sub-second input stays exit 2 on both flags.
This commit is contained in:
1 parent
8c3d98fd98
commit
19c8dd3146
3 files changed
+34
-4
No files matched your search
@@ -177,6 +177,15 @@ describe("option helpers", () => {
|
||||
expect(parseDelegationExpireHours(2)).toBe(2);
|
||||
expect(parseHoseExpireSeconds(2)).toBe(7200);
|
||||
});
|
||||
|
||||
test("sub-second input stays a usage error on both --expire flags", () => {
|
||||
// Regression: the shared tokenizer understands `ms` for the simulation
|
||||
// windows, and without a per-caller unit set that grammar leaked into
|
||||
// --expire, silently rounding 500ms up to a 1h / 1s link.
|
||||
expect(() => parseDelegationExpireHours("500ms")).toThrow("必须为有效时长格式");
|
||||
expect(() => parseHoseExpireSeconds("500ms")).toThrow("必须为有效时长");
|
||||
expect(() => parseHoseExpireSeconds("200ms")).toThrow("必须为有效时长");
|
||||
});
|
||||
});
|
||||
|
||||
describe("flag registry cross-check", () => {
|
||||
|
||||
Reference in new issue
Block a user