fix(report): require ownership markdown path

This commit is contained in:
Vincent Koc
2026-06-06 22:18:03 +02:00
parent c2af0475fe
commit bedb3e61c6
2 changed files with 31 additions and 2 deletions

View File

@@ -397,7 +397,15 @@ function printTextReport(report) {
process.stdout.write(renderTextReport(report));
}
function parseArgs(argv) {
function readArtifactPath(argv, index, optionName) {
const value = argv[index + 1];
if (value === undefined || value === "" || value.startsWith("--")) {
throw new Error(`${optionName} requires a value`);
}
return value;
}
export function parseArgs(argv) {
const options = {
asJson: false,
check: false,
@@ -421,7 +429,8 @@ function parseArgs(argv) {
continue;
}
if (arg === "--markdown") {
options.markdownPath = argv[++index];
options.markdownPath = readArtifactPath(argv, index, arg);
index += 1;
continue;
}
throw new Error(`Unsupported argument: ${arg}`);

View File

@@ -7,6 +7,7 @@ import {
collectDependencyOwnershipSurfaceCheckErrors,
collectDependencyOwnershipSurfaceReport,
packageNameFromLockKey,
parseArgs,
renderDependencyOwnershipSurfaceMarkdownReport,
} from "../../scripts/dependency-ownership-surface-report.mjs";
@@ -37,6 +38,25 @@ describe("packageNameFromLockKey", () => {
});
});
describe("parseArgs", () => {
it("rejects missing markdown artifact paths", () => {
expect(() => parseArgs(["--markdown"])).toThrow("--markdown requires a value");
expect(() => parseArgs(["--markdown", "--json"])).toThrow("--markdown requires a value");
expect(() => parseArgs(["--markdown", ""])).toThrow("--markdown requires a value");
});
it("keeps json as a boolean or optional artifact path", () => {
expect(parseArgs(["--json"])).toMatchObject({
asJson: true,
jsonPath: null,
});
expect(parseArgs(["--json", "report.json"])).toMatchObject({
asJson: true,
jsonPath: "report.json",
});
});
});
describe("collectDependencyOwnershipSurfaceReport", () => {
it("reports root dependency reachability, install-surface packages, and ownership metadata gaps", () => {
const repoRoot = makeTempRepo();