diff --git a/scripts/ts-topology.ts b/scripts/ts-topology.ts index c0b370c5a18..1b1811f7867 100644 --- a/scripts/ts-topology.ts +++ b/scripts/ts-topology.ts @@ -8,6 +8,7 @@ import { createPluginSdkScope, } from "./lib/ts-topology/scope.js"; import type { TopologyReportName, TopologyScope } from "./lib/ts-topology/types.js"; +import { parsePositiveInt } from "./lib/numeric-options.mjs"; const VALID_REPORTS = new Set([ "public-surface-usage", @@ -86,7 +87,7 @@ function parseArgs(argv: string[]): CliOptions { options.report = (value as TopologyReportName | undefined) ?? options.report; break; case "--limit": - options.limit = Math.max(1, Number.parseInt(value ?? "25", 10)); + options.limit = parsePositiveInt(value, "--limit"); break; case "--repo-root": options.repoRoot = path.resolve(value ?? options.repoRoot); diff --git a/test/scripts/ts-topology.test.ts b/test/scripts/ts-topology.test.ts index ee6321806ba..f7c04848da8 100644 --- a/test/scripts/ts-topology.test.ts +++ b/test/scripts/ts-topology.test.ts @@ -198,6 +198,15 @@ describe("ts-topology", () => { `); }); + it("rejects malformed CLI limits", async () => { + const captured = createCapturedIo(); + const exitCode = await main(["--limit=abc"], captured.io); + + expect(exitCode).toBe(1); + expect(captured.readStderr()).toContain("--limit must be a positive integer"); + expect(captured.readStdout()).toBe(""); + }); + it("throws a clear error for invalid text report names", () => { expect(() => renderTextReport(