diff --git a/docs/package-rollouts.md b/docs/package-rollouts.md index d80329d..f4d6956 100644 --- a/docs/package-rollouts.md +++ b/docs/package-rollouts.md @@ -22,7 +22,9 @@ deployment restarts the observation period. Each consumer must still pass all of Known first-party packages without a designated canary wait for configuration; they do not silently promote. Lock-only pnpm root dependency changes are checked, including pinned Git artifacts; npm lockfile v2/v3 direct dependencies are also -supported. Unsupported lock formats, unavailable API evidence and checker errors +supported. A pull request's change is measured from its merge base, so a branch +that forked before the base moved a dependency is not read as reverting it. +Unsupported lock formats, unavailable API evidence and checker errors hold automatic merging. Changed shared artifacts in nested pnpm importers hold automatic promotion until workspace-specific canary evidence is supported. Standalone nested dependency manifest changes and nested lockfile updates with shared dependencies likewise hold automatic promotion. The gate does not diff --git a/scripts/ci/package-rollout-cli.test.mjs b/scripts/ci/package-rollout-cli.test.mjs index 19bc74d..e60bca1 100644 --- a/scripts/ci/package-rollout-cli.test.mjs +++ b/scripts/ci/package-rollout-cli.test.mjs @@ -35,6 +35,7 @@ const manifest = v => JSON.stringify({name:'fixture-app',dependencies:{'@bitbaum let result; if (verb !== 'api') throw Error('unexpected CLI invocation'); if (path === 'repos/bitbaum/example/pulls/1') result={base:{sha:'a'.repeat(40)},head:{sha:'b'.repeat(40)}}; +else if (path.startsWith('repos/bitbaum/example/compare/'+'a'.repeat(40)+'...'+'b'.repeat(40))) result={merge_base_commit:{sha:'a'.repeat(40)}}; else if (path.includes('/pulls/1/files?')) result=[{filename:(project==='.'?'':project+'/')+'package.json'},{filename:(project==='.'?'':project+'/')+'pnpm-lock.yaml'}]; else if (path === 'repos/bitbaum/biaslens') result={default_branch:'main'}; else if (path === 'repos/bitbaum/biaslens/commits/main') result={sha:tip}; @@ -133,6 +134,7 @@ const encode = value => ({content:Buffer.from(value).toString('base64')}); let result; if(verb!=='api') throw Error('unexpected CLI invocation'); if(path==='repos/bitbaum/loki/pulls/1') result={base:{sha:base},head:{sha:head}}; +else if(path.startsWith('repos/bitbaum/loki/compare/'+base+'...'+head)) result={merge_base_commit:{sha:base}}; else if(path.includes('/pulls/1/files?')) result=[{filename:'scripts/site-template/package.json'},{filename:'scripts/site-template/pnpm-lock.yaml'}]; else if(path==='repos/bitbaum/kivvi') result={default_branch:'main'}; else if(path==='repos/bitbaum/kivvi/commits/main') result={sha:tip}; @@ -182,3 +184,47 @@ console.log(JSON.stringify(result)); rmSync(dir, { recursive: true, force: true }); } }); + +// bitbaum/diplodoctor#59 (2026-10-31): a branch forked before the base moved +// @bitbaum/chatkit 0.21.2 -> 0.21.3 never touched a manifest, yet measuring it +// from `pr.base.sha` read as a downgrade to 0.21.2, which no canary would ever +// run again. The sweep holds before it refreshes a behind branch, so the PR +// could never clear. The PR's change is measured from its merge base. +test("a stale branch that does not touch the lockfile is not read as a downgrade", () => { + const dir = mkdtempSync(join(tmpdir(), "rollout-stale-cli-")); + const fork = "e".repeat(40); + try { + writeFileSync( + join(dir, "gh"), + `#!${process.execPath} +const [verb, path] = process.argv.slice(2); +const base='a'.repeat(40), head='b'.repeat(40), fork=${JSON.stringify(fork)}; +const lock = v => "lockfileVersion: '9.0'\\nimporters:\\n .:\\n dependencies:\\n '@bitbaum/chatkit':\\n specifier: ^"+v+"\\n version: "+v+"\\n"; +const manifest = v => JSON.stringify({name:'fixture-app',dependencies:{'@bitbaum/chatkit':'^'+v}}); +let result; +if (verb !== 'api') throw Error('unexpected CLI invocation'); +if (path === 'repos/bitbaum/example/pulls/1') result={base:{sha:base},head:{sha:head}}; +else if (path.startsWith('repos/bitbaum/example/compare/'+base+'...'+head)) result={merge_base_commit:{sha:fork}}; +else if (path.includes('/pulls/1/files?')) result=[{filename:'lib/auth/recovery.test.ts'}]; +else if (path.includes('/contents/')) { + const [file,ref]=/^repos\\/bitbaum\\/example\\/contents\\/(.+)\\?ref=(.+)$/.exec(path).slice(1); + const v = ref===base ? '0.21.3' : '0.21.2'; + const content = file==='package.json'?manifest(v):file==='pnpm-lock.yaml'?lock(v):null; + if (content!==null) result={content:Buffer.from(content).toString('base64')}; +} +if(result===undefined){console.error('404');process.exit(1)} +console.log(JSON.stringify(result)); +`, + { mode: 0o755 }, + ); + const run = spawnSync( + process.execPath, + [new URL("./package-rollout-gate.mjs", import.meta.url).pathname, "bitbaum/example", "1"], + { encoding: "utf8", env: { ...process.env, PATH: dir + ":" + process.env.PATH } }, + ); + assert.equal(run.status, 0, run.stdout + run.stderr); + assert.doesNotMatch(run.stdout, /chatkit@0\.21\.2/); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); diff --git a/scripts/ci/package-rollout-gate.mjs b/scripts/ci/package-rollout-gate.mjs index ceb1e42..ca854c2 100644 --- a/scripts/ci/package-rollout-gate.mjs +++ b/scripts/ci/package-rollout-gate.mjs @@ -523,9 +523,33 @@ export async function canaryDeploymentEvidence({ }; } +/** + * The commit the pull request's own change is measured from. `pr.base.sha` is + * the base branch as GitHub last recorded it, not where the branch forked: a + * branch that predates a dependency bump on the base would read as reverting + * it, and the gate would hold a PR that never touches a manifest. The merge + * base is the parent of exactly the diff a squash merge lands. + */ +export function pullRequestBaseline(pr, readCompare) { + const compare = readCompare(pr.base.sha, pr.head.sha); + const sha = compare?.merge_base_commit?.sha; + if (!/^[0-9a-f]{40}$/.test(sha ?? "")) + throw new Error("merge base of the pull request is unavailable"); + return sha; +} + async function main() { const [repo, number] = process.argv.slice(2); - const pr = api(`repos/${repo}/pulls/${number}`); + const pullRequest = api(`repos/${repo}/pulls/${number}`); + const pr = { + ...pullRequest, + base: { + ...pullRequest.base, + sha: pullRequestBaseline(pullRequest, (base, head) => + api(`repos/${repo}/compare/${base}...${head}?per_page=1`), + ), + }, + }; // Avoid requiring a Node lockfile from repositories with no root Node manifest. const manifest = content(repo, "package.json", pr.head.sha); // Package repositories publish artifacts; their downstream application consumers diff --git a/scripts/ci/package-rollout-gate.test.mjs b/scripts/ci/package-rollout-gate.test.mjs index 7375a78..6f3128e 100644 --- a/scripts/ci/package-rollout-gate.test.mjs +++ b/scripts/ci/package-rollout-gate.test.mjs @@ -592,3 +592,19 @@ test("multiple named jobs reuse the exact run and reject a missing guard", () => [], ); }); + +test("the pull request baseline is its merge base, and an unreadable one holds", async () => { + const { pullRequestBaseline } = await import("./package-rollout-gate.mjs"); + const pr = { base: { sha: "a".repeat(40) }, head: { sha: "b".repeat(40) } }; + const seen = []; + assert.equal( + pullRequestBaseline(pr, (base, head) => { + seen.push([base, head]); + return { merge_base_commit: { sha: "e".repeat(40) } }; + }), + "e".repeat(40), + ); + assert.deepEqual(seen, [["a".repeat(40), "b".repeat(40)]]); + for (const reply of [undefined, {}, { merge_base_commit: { sha: "main" } }]) + assert.throws(() => pullRequestBaseline(pr, () => reply), /merge base/); +});