fix(codex): centralize session limit parsing

This commit is contained in:
Peter Steinberger
2026-05-29 06:37:59 -04:00
parent 9996cad49a
commit 1042dce454
2 changed files with 23 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import crypto from "node:crypto";
import { resolveAgentDir, resolveSessionAgentIds } from "openclaw/plugin-sdk/agent-runtime";
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
import type { PluginCommandContext, PluginCommandResult } from "openclaw/plugin-sdk/plugin-entry";
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
import { CODEX_CONTROL_METHODS, type CodexControlMethod } from "./app-server/capabilities.js";
@@ -1932,9 +1933,8 @@ function parseCodexCliSessionsArgs(args: string[]): ParsedCodexCliSessionsArgs {
}
if (arg === "--limit") {
const value = readRequiredOptionValue(args, index);
const parsedLimit =
value && /^\+?\d+$/.test(value.trim()) ? Number(value.trim()) : Number.NaN;
if (!Number.isSafeInteger(parsedLimit) || parsedLimit <= 0) {
const parsedLimit = parseStrictPositiveInteger(value);
if (parsedLimit === undefined) {
parsed.help = true;
continue;
}

View File

@@ -595,6 +595,26 @@ describe("codex command", () => {
});
});
it("normalizes signed decimal Codex CLI session limits before node dispatch", async () => {
const listCodexCliSessionsOnNode = vi.fn(async () => ({
node: { nodeId: "mb-m5", displayName: "mb-m5" },
result: {
codexHome: "/Users/mariano/.codex",
sessions: [],
},
}));
await handleCodexCommand(createContext("sessions --host mb-m5 --limit +05 bridge"), {
deps: createDeps({ listCodexCliSessionsOnNode }),
});
expect(listCodexCliSessionsOnNode).toHaveBeenCalledWith({
requestedNode: "mb-m5",
filter: "bridge",
limit: 5,
});
});
it("rejects partial Codex CLI session limits before node dispatch", async () => {
const listCodexCliSessionsOnNode = vi.fn();