From 6d71e809b42533ed07f183dc7a224f2200818fd7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 19:38:30 +0000 Subject: [PATCH] fix(badges): accept the legacy K9 badge label when publishing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Publish the lane badges" fails on every push to main: governance-badge.js refuses to overwrite badges/k9.json on the governance-badges branch, because its label is "k9-deed L0–L2" (written by the earlier renderer), not "K9". rsr-template-repo a20fdb2 (#381) already fixed this in the template: the legacy label is accepted and replaced, and any other label is still refused. Both files were unchanged from template 48671ce here, so they now match rsr-template-repo main exactly. tests/workflows/governance_badge_test.sh: exit 1 with the old script and the new test, exit 0 with this change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoZwvZCfM387TZQ5kY --- scripts/governance-badge.js | 17 +++++++++++++- tests/workflows/governance_badge_test.js | 29 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/scripts/governance-badge.js b/scripts/governance-badge.js index 865aa885..06d40fc3 100644 --- a/scripts/governance-badge.js +++ b/scripts/governance-badge.js @@ -131,6 +131,15 @@ function renderBadge(label, state) { ); } +// LEGACY_LABELS - labels an earlier renderer wrote for a lane, per current label. +// A file on the badges branch carrying one of these (and otherwise a valid +// shield badge) is a known predecessor of this lane's badge, so it is +// migrated (replaced with the canonical badge) rather than refused as foreign. +// Any other label stays a refusal. The old K9 lane was labelled "k9-deed L0" + U+2013 + "L2". +const LEGACY_LABELS = Object.freeze({ + K9: Object.freeze(["k9-deed L0\u2013L2"]), +}); + // inspectBadge - is this text a shield-endpoint object? // // pairing: "strict" message must be one of STATE_TABLE's, with exactly the @@ -158,7 +167,13 @@ function inspectBadge(text, label, { pairing = "strict" } = {}) { if (badge.schemaVersion !== 1) { errors.push(`schemaVersion is ${JSON.stringify(badge.schemaVersion)}, expected 1`); } - if (label !== undefined && badge.label !== label) { + // Own properties only: a label such as "constructor" or "toString" is a valid + // label, and a bare lookup would return the inherited built-in, not an array. + const legacyLabels = label !== undefined && Object.prototype.hasOwnProperty.call(LEGACY_LABELS, label) + ? LEGACY_LABELS[label] + : []; + const legacy = pairing === "loose" && label !== undefined && legacyLabels.includes(badge.label); + if (label !== undefined && badge.label !== label && !legacy) { errors.push(`label is ${JSON.stringify(badge.label)}, expected ${JSON.stringify(label)}`); } if (typeof badge.message !== "string" || badge.message.length === 0) { diff --git a/tests/workflows/governance_badge_test.js b/tests/workflows/governance_badge_test.js index 5ea18330..c7faeafb 100644 --- a/tests/workflows/governance_badge_test.js +++ b/tests/workflows/governance_badge_test.js @@ -571,6 +571,7 @@ async function main() { ["missing final newline", SUCCESS_BADGE.trimEnd(), "success", SUCCESS_BADGE], ["legacy red skipped badge", '{"schemaVersion":1,"label":"K9","message":"skipped","color":"red"}\n', "skipped", SKIPPED_BADGE], ["legacy unrecognised message", '{"schemaVersion":1,"label":"K9","message":"pending","color":"blue"}\n', "success", SUCCESS_BADGE], + ["legacy K9 label (k9-deed L0\u2013L2), as published by the earlier renderer", '{"schemaVersion":1,"label":"k9-deed L0\u2013L2","message":"passing","color":"brightgreen"}\n', "success", SUCCESS_BADGE], ]) { await testWithApi(`existing ${name} is updated to canonical bytes`, { branchExists: true, fileBytes: bytes, @@ -772,6 +773,9 @@ async function main() { ["JSON array", "[]\n"], ["missing schemaVersion", '{"label":"K9","message":"failure","color":"red"}\n'], ["null message", '{"schemaVersion":1,"label":"K9","message":null,"color":"red"}\n'], + ["a foreign label that is not a K9 predecessor", '{"schemaVersion":1,"label":"coverage","message":"success","color":"brightgreen"}\n'], + ["the legacy K9 label with a missing message", '{"schemaVersion":1,"label":"k9-deed L0\u2013L2","color":"red"}\n'], + ["the legacy K9 label with the wrong schemaVersion", '{"schemaVersion":2,"label":"k9-deed L0\u2013L2","message":"passing","color":"brightgreen"}\n'], ...INVALID_BADGES, ]) { const api = createApi({ branchExists: true, fileBytes: text }); @@ -794,6 +798,31 @@ async function main() { await api.close(); } + // A label inherited from Object.prototype is still a valid label. With an + // existing foreign file the legacy lookup must fall back to "no legacy + // labels" and refuse cleanly, not throw a TypeError. + for (const inherited of ["constructor", "toString", "hasOwnProperty"]) { + const api = createApi({ branchExists: true, fileBytes: '{"schemaVersion":1,"label":"coverage","message":"success","color":"brightgreen"}\n' }); + const url = await api.listen(); + await test(`label "${inherited}" over an existing foreign file is refused, not a crash`, async () => { + const out = await runAsync([ + "publish", + "--label", inherited, + "--lane-result", "failure", + "--artifact", failureArtifact, + "--branch", BRANCH, + "--path", DEST, + "--repo", "example/template", + "--api-url", url, + ]); + equal(out.code, 1, `expected exit 1, got ${out.code}: ${out.stderr}`); + check(!/TypeError/.test(out.stderr), `must not crash with a TypeError: ${out.stderr}`); + check(/refused/i.test(out.stderr), `stderr must say refused: ${out.stderr}`); + equal(api.writes().length, 0, "a foreign file must not be overwritten"); + }); + await api.close(); + } + // ---------------------------------------------------------------- 7 section("7. Missing is not the same as broken");