mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
fix: parse queue caps strictly
This commit is contained in:
@@ -44,4 +44,14 @@ describe("maybeHandleQueueDirective", () => {
|
||||
"Options: modes steer, followup, collect, interrupt; debounce:<ms|s|m>, cap:<n>, drop:old|new|summarize.",
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["cap:1e3", "cap:0x10", "cap:4.9"])("rejects non-decimal-integer caps: %s", (cap) => {
|
||||
const invalid = maybeHandleQueueDirective({
|
||||
directives: parseInlineDirectives(`/queue collect ${cap}`),
|
||||
cfg: {} as OpenClawConfig,
|
||||
channel: "quietchat",
|
||||
});
|
||||
|
||||
expect(invalid?.text).toContain("Invalid cap");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { parseDurationMs } from "../../../cli/parse-duration.js";
|
||||
import { parseStrictPositiveInteger } from "../../../infra/parse-finite-number.js";
|
||||
import { normalizeOptionalLowercaseString } from "../../../shared/string-coerce.js";
|
||||
import { skipDirectiveArgPrefix, takeDirectiveToken } from "../directive-parsing.js";
|
||||
import { normalizeQueueDropPolicy, normalizeQueueMode } from "./normalize.js";
|
||||
@@ -23,15 +24,7 @@ function parseQueueCap(raw?: string): number | undefined {
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const num = Number(raw);
|
||||
if (!Number.isFinite(num)) {
|
||||
return undefined;
|
||||
}
|
||||
const cap = Math.floor(num);
|
||||
if (cap < 1) {
|
||||
return undefined;
|
||||
}
|
||||
return cap;
|
||||
return parseStrictPositiveInteger(raw);
|
||||
}
|
||||
|
||||
function parseQueueDirectiveArgs(raw: string): {
|
||||
|
||||
Reference in New Issue
Block a user