fix(cli): reject unsafe sessions tail counts (#99398)

* fix(cli): reject unsafe sessions tail counts

* fix(cli): reuse strict tail count parser
This commit is contained in:
qingminlong
2026-07-03 18:53:35 +08:00
committed by GitHub
parent 05de72c4cd
commit 3e2d373d43
2 changed files with 14 additions and 8 deletions
+12
View File
@@ -188,6 +188,18 @@ describe("sessionsTailCommand", () => {
expect(output).toContain("tool.result");
});
it("rejects tail counts that exceed JavaScript safe integer precision", async () => {
const runtime = makeRuntime();
await sessionsTailCommand({ store: storePath, sessionKey, tail: "9007199254740992" }, runtime);
expect(runtime.error).toHaveBeenCalledWith(
"--tail must be a non-negative integer, for example --tail 25.",
);
expect(runtime.exit).toHaveBeenCalledWith(1);
expect(runtime.log).not.toHaveBeenCalled();
});
it("uses a session trajectory pointer for relocated runtime files", async () => {
const runtime = makeRuntime();
const relocatedDir = path.join(tmpDir, "relocated-trajectories");
+2 -8
View File
@@ -14,6 +14,7 @@ import { listSessionEntries } from "../config/sessions/session-accessor.js";
import type { SessionEntry } from "../config/sessions/types.js";
import { resolveStoredSessionKeyForAgentStore } from "../gateway/session-store-key.js";
import { formatErrorMessage } from "../infra/errors.js";
import { parseStrictNonNegativeInteger } from "../infra/parse-finite-number.js";
import { resolveAgentIdFromSessionKey } from "../routing/session-key.js";
import type { RuntimeEnv } from "../runtime.js";
import {
@@ -90,14 +91,7 @@ function parseTailCount(value: string | number | undefined): number | null {
if (value === undefined) {
return DEFAULT_TAIL_COUNT;
}
if (typeof value === "number") {
return Number.isInteger(value) && value >= 0 ? value : null;
}
const trimmed = value.trim();
if (!/^\d+$/.test(trimmed)) {
return null;
}
return Number.parseInt(trimmed, 10);
return parseStrictNonNegativeInteger(value) ?? null;
}
function toOptionalString(value: unknown): string | undefined {