fix(tooling): reject malformed topology limits

This commit is contained in:
Vincent Koc
2026-06-02 22:19:10 +02:00
parent 0188c541de
commit ac8338bb02
2 changed files with 11 additions and 1 deletions

View File

@@ -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<TopologyReportName>([
"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);

View File

@@ -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(