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
+3
-3
@@ -1,7 +1,7 @@
|
||||
import type { WebhookMode } from "../domains/seal/types.js";
|
||||
import type { MaterialPackFilePolicyPatch } from "../domains/seal/material-pack/policy.js";
|
||||
import type { ParsedArgs } from "./types.js";
|
||||
import { type DurationToken, expireSeconds, tokenizeDuration } from "../core/duration.js";
|
||||
import { type DurationToken, EXPIRE_UNITS, expireSeconds, tokenizeDuration } from "../core/duration.js";
|
||||
import { usageError } from "./errors.js";
|
||||
|
||||
/**
|
||||
@@ -453,7 +453,7 @@ function readExpireToken(
|
||||
`Invalid --expire: ${value}。必须为大于 0 的有效时长${options.unitlessHint ? `,推荐使用 ${options.unitlessHint}` : ""}。`
|
||||
);
|
||||
}
|
||||
const token = tokenizeDuration(value);
|
||||
const token = tokenizeDuration(value, { units: EXPIRE_UNITS });
|
||||
if (!token) throw usageError(`Invalid --expire: ${value}。`);
|
||||
return token;
|
||||
}
|
||||
@@ -462,7 +462,7 @@ function readExpireToken(
|
||||
throw usageError(`Invalid --expire: ${String(value)}。`);
|
||||
}
|
||||
|
||||
const token = tokenizeDuration(value);
|
||||
const token = tokenizeDuration(value, { units: EXPIRE_UNITS });
|
||||
if (!token) {
|
||||
throw usageError(`Invalid --expire: '${value}'。必须为有效时长格式${options.formatHint}`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user