diff --git a/scripts/check-changelog-semver.mjs b/scripts/check-changelog-semver.mjs index a6c1e6c0..93a9d53e 100644 --- a/scripts/check-changelog-semver.mjs +++ b/scripts/check-changelog-semver.mjs @@ -11,7 +11,7 @@ import { execFileSync, spawnSync } from "node:child_process"; import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; -import { basename, dirname, join } from "node:path"; +import { basename, dirname, join, resolve } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; // The exact heading spelling the policy mandates for a breaking-change @@ -342,7 +342,8 @@ const UNMEASURED_NOTICE = function main() { const args = parseArgs(process.argv.slice(2)); const { package: packageName, changelog, version, "tag-prefix": tagPrefix, cwd = process.cwd() } = args; - const built = args["api-built"] ?? []; + // The tool runs from scripts/api-gate, so a path given relative to this process is made absolute first. + const built = (args["api-built"] ?? []).map((path) => resolve(path)); if (!packageName || !changelog || !version || !tagPrefix || (built.length > 0) !== Boolean(args["api-baseline-path"])) { console.error( "usage: check-changelog-semver.mjs --package --changelog --version --tag-prefix [--cwd ] [--first-release]\n" + @@ -390,7 +391,7 @@ function main() { previousVersion, baselinePath: args["api-baseline-path"], built, - refs: args["api-refs"] ?? [], + refs: (args["api-refs"] ?? []).map((path) => resolve(path)), declaredNew: args["api-new"] ?? [], cwd, }); diff --git a/scripts/check-changelog-semver.test.mjs b/scripts/check-changelog-semver.test.mjs index 68cf1290..2c6da50e 100644 --- a/scripts/check-changelog-semver.test.mjs +++ b/scripts/check-changelog-semver.test.mjs @@ -820,3 +820,18 @@ test("refusals never repeat what the inputs contain", () => { rmSync(scratch, { recursive: true, force: true }); } }); + +test("measured: built and reference paths given relative to the process are read from there", () => { + withReleasedBaseline({ baseline: { "GameCult.Widget.dll": oldWidget() } }, (dir) => { + const scratch = mkdtempSync(join(tmpdir(), "cultlib-semver-relative-")); + try { + mkdirSync(join(scratch, "refs")); + copyFileSync(trimmedWidget(), join(scratch, "GameCult.Widget.dll")); + const args = measuredArgs(dir, "1.1.0", ["GameCult.Widget.dll"], { refs: ["refs"] }); + // The tool is started elsewhere, so an unresolved relative path would not be found. + assert.match(runCheckerExpectFailure(dir, args, { processCwd: scratch }), /Gone/); + } finally { + rmSync(scratch, { recursive: true, force: true }); + } + }); +});