Skip to content

Commit 346fae9

Browse files
authored
fix(cli): reject partial approval grant limits (#133361)
1 parent 2f6a671 commit 346fae9

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎src/cli/exec-approvals-cli.pending-resolve.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ describe("exec approvals pending and resolve CLI", () => {
143143
defaultRuntime.exit.mockClear();
144144
});
145145

146+
it.each(["10junk", "1.5", "0"])(
147+
"rejects a malformed grants list limit before the Gateway request (%s)",
148+
async (limit) => {
149+
await expect(
150+
runApprovalsCommand(["approvals", "grants", "list", "--limit", limit, "--json"]),
151+
).rejects.toThrow("--limit must be a positive integer.");
152+
153+
expect(callGatewayFromCli).not.toHaveBeenCalled();
154+
},
155+
);
156+
157+
it("forwards a valid grants list limit as a number", async () => {
158+
callGatewayFromCli.mockResolvedValueOnce({ grants: [] });
159+
160+
await runApprovalsCommand(["approvals", "grants", "list", "--limit", "25", "--json"]);
161+
162+
const call = callGatewayFromCli.mock.calls[0];
163+
expect(call?.[0]).toBe("exec.approval.grants.list");
164+
expect(call?.[2]).toEqual({ limit: 25 });
165+
});
166+
146167
it("renders pending approvals from all three approval kinds", async () => {
147168
const now = Date.now();
148169
callGatewayFromCli.mockImplementation(async (method: string) => {

‎src/cli/exec-approvals-cli.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fs from "node:fs/promises";
33
import { readByteStreamWithLimit } from "@openclaw/media-core/read-byte-stream-with-limit";
44
import { expectDefined } from "@openclaw/normalization-core";
5+
import { parseStrictPositiveInteger } from "@openclaw/normalization-core/number-coercion";
56
import { isRecord } from "@openclaw/normalization-core/record-coerce";
67
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
78
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
@@ -1253,15 +1254,14 @@ export function registerExecApprovalsCli(program: Command) {
12531254
.option("--limit <n>", "Maximum rows to return (default 200)")
12541255
.action(async (opts: ExecApprovalsCliOpts & { limit?: string }) => {
12551256
try {
1256-
const limitRaw = opts.limit === undefined ? undefined : Number.parseInt(opts.limit, 10);
1257-
const limit =
1258-
limitRaw !== undefined && Number.isInteger(limitRaw) && limitRaw >= 1
1259-
? limitRaw
1260-
: undefined;
1257+
const limit = parseStrictPositiveInteger(opts.limit);
1258+
if (opts.limit !== undefined && limit === undefined) {
1259+
exitWithError("--limit must be a positive integer.");
1260+
}
12611261
const result = (await callGatewayFromCli(
12621262
"exec.approval.grants.list",
12631263
opts,
1264-
limit ? { limit } : {},
1264+
limit !== undefined ? { limit } : {},
12651265
)) as { grants: StandingGrantCliEntry[] }; // SAFETY: matches ExecApprovalGrantsListResultSchema.
12661266
if (opts.json) {
12671267
defaultRuntime.writeJson(result, 0);

0 commit comments

Comments
 (0)