|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Real-behavior proof for the repository-slug case-sensitivity fix. |
| 4 | + * |
| 5 | + * Three claims, all against the built dist/: |
| 6 | + * |
| 7 | + * 1. RESOLVES - automergeOutcomeReviewedShaFromResult() returns the reviewed |
| 8 | + * head when canonical_pr names the same repository with |
| 9 | + * different casing. Pre-fix it returned null. |
| 10 | + * 2. BOUNDED - a genuinely different repository is still rejected, so the |
| 11 | + * fix cannot widen into cross-repository head borrowing. This |
| 12 | + * must hold both before and after. |
| 13 | + * 3. CONSISTENT- every module that compares a parsed repository slug now uses |
| 14 | + * the shared comparator, so no equivalent site is left behind. |
| 15 | + * |
| 16 | + * Claim 1 compares against a pre-fix build when one is supplied as argv[2]; |
| 17 | + * without it, the before/after contrast is reported SKIPPED rather than assumed. |
| 18 | + * |
| 19 | + * Usage: node docs/proof/automerge-repo-case-sensitivity/run-proof.mjs [preFixDistRepairDir] |
| 20 | + */ |
| 21 | +import fs from "node:fs"; |
| 22 | +import path from "node:path"; |
| 23 | +import { fileURLToPath } from "node:url"; |
| 24 | + |
| 25 | +const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", ".."); |
| 26 | +const distRepair = path.join(repoRoot, "dist", "repair"); |
| 27 | +const distOutcome = path.join(distRepair, "automerge-outcome.js"); |
| 28 | + |
| 29 | +if (!fs.existsSync(distOutcome)) { |
| 30 | + console.error(`missing build artifact: ${distOutcome}\nrun: pnpm run build:repair`); |
| 31 | + process.exit(2); |
| 32 | +} |
| 33 | + |
| 34 | +const { automergeOutcomeReviewedShaFromResult } = await import(`file://${distOutcome}`); |
| 35 | +const { sameRepoSlug } = await import(`file://${path.join(distRepair, "github-ref.js")}`); |
| 36 | + |
| 37 | +const HEAD = "92dca8fde03aee8da56a84a011fa387b9c1640fe"; |
| 38 | +const REPO = "openclaw/openclaw"; |
| 39 | +const TARGET = 83707; |
| 40 | +const failures = []; |
| 41 | +const check = (label, ok, detail) => { |
| 42 | + console.log(` ${ok ? "PASS" : "FAIL"} ${label}`); |
| 43 | + if (!ok) { |
| 44 | + if (detail) console.log(` ${detail}`); |
| 45 | + failures.push(label); |
| 46 | + } |
| 47 | +}; |
| 48 | + |
| 49 | +const resolve = (impl, canonicalPr) => |
| 50 | + impl({ |
| 51 | + repo: REPO, |
| 52 | + target: TARGET, |
| 53 | + result: { repo: REPO, canonical_pr: canonicalPr, fix_artifact: null }, |
| 54 | + targetView: { headRefOid: HEAD }, |
| 55 | + }); |
| 56 | + |
| 57 | +/* -- Claim 1: case-differing slug resolves ------------------------------- */ |
| 58 | + |
| 59 | +console.log("== Claim 1: a slug differing only by case resolves the reviewed head ==\n"); |
| 60 | +const CASE_VARIANTS = [ |
| 61 | + `https://github.com/OpenClaw/OpenClaw/pull/${TARGET}`, |
| 62 | + `https://github.com/openclaw/OPENCLAW/pull/${TARGET}`, |
| 63 | + `https://GitHub.com/OpenClaw/openclaw/pull/${TARGET}`, |
| 64 | +]; |
| 65 | +check( |
| 66 | + "control: exact-case canonical_pr resolves", |
| 67 | + resolve(automergeOutcomeReviewedShaFromResult, `https://github.com/${REPO}/pull/${TARGET}`) === HEAD, |
| 68 | +); |
| 69 | +for (const url of CASE_VARIANTS) { |
| 70 | + check(`resolves ${url}`, resolve(automergeOutcomeReviewedShaFromResult, url) === HEAD); |
| 71 | +} |
| 72 | + |
| 73 | +/* -- Claim 2: cross-repository borrowing still rejected ------------------ */ |
| 74 | + |
| 75 | +console.log("\n== Claim 2: a different repository is still rejected ==\n"); |
| 76 | +for (const url of [ |
| 77 | + `https://github.com/openclaw/other-repo/pull/${TARGET}`, |
| 78 | + `https://github.com/OtherOwner/OpenClaw/pull/${TARGET}`, |
| 79 | + `https://github.com/openclaw/openclaw-state/pull/${TARGET}`, |
| 80 | +]) { |
| 81 | + check(`rejects ${url}`, resolve(automergeOutcomeReviewedShaFromResult, url) === null); |
| 82 | +} |
| 83 | +check( |
| 84 | + "an absent slug never satisfies a repository guard", |
| 85 | + sameRepoSlug(undefined, undefined) === false && sameRepoSlug("", "") === false, |
| 86 | +); |
| 87 | + |
| 88 | +/* -- Claim 3: no equivalent comparison site left behind ------------------ */ |
| 89 | + |
| 90 | +console.log("\n== Claim 3: every parsed-slug comparison uses the shared comparator ==\n"); |
| 91 | +const CONSUMERS = [ |
| 92 | + "automerge-outcome.js", |
| 93 | + "execute-fix-github.js", |
| 94 | + "execute-fix-artifact.js", |
| 95 | + "post-flight.js", |
| 96 | + "source-pr-checkout.js", |
| 97 | + "target-validation.js", |
| 98 | +]; |
| 99 | +// A parsed slug compared with === / !== instead of sameRepoSlug is the defect. |
| 100 | +const LEFTOVER = /(?:parsed|canonicalPr|sourcePr)(?:\?)?\.repo\s*(?:===|!==)/; |
| 101 | +for (const file of CONSUMERS) { |
| 102 | + const full = path.join(distRepair, file); |
| 103 | + if (!fs.existsSync(full)) { |
| 104 | + check(`${file} present`, false, "build artifact missing"); |
| 105 | + continue; |
| 106 | + } |
| 107 | + const src = fs.readFileSync(full, "utf8"); |
| 108 | + const leftover = src.match(new RegExp(LEFTOVER.source, "g")) ?? []; |
| 109 | + check( |
| 110 | + `${file}: no case-sensitive parsed-slug comparison`, |
| 111 | + leftover.length === 0, |
| 112 | + leftover.length ? `found: ${leftover.join(", ")}` : undefined, |
| 113 | + ); |
| 114 | +} |
| 115 | + |
| 116 | +/* -- Before/after contrast ------------------------------------------------ */ |
| 117 | + |
| 118 | +console.log("\n== Before/after against a pre-fix build ==\n"); |
| 119 | +const preFixDir = process.argv[2]; |
| 120 | +if (!preFixDir) { |
| 121 | + console.log(" SKIPPED no pre-fix build supplied (argv[2]); contrast not measured"); |
| 122 | + failures.push("before/after not measured"); |
| 123 | +} else { |
| 124 | + const preOutcome = path.join(path.resolve(preFixDir), "automerge-outcome.js"); |
| 125 | + if (!fs.existsSync(preOutcome)) { |
| 126 | + check("pre-fix build present", false, preOutcome); |
| 127 | + } else { |
| 128 | + const pre = await import(`file://${preOutcome}`); |
| 129 | + const url = CASE_VARIANTS[0]; |
| 130 | + const before = resolve(pre.automergeOutcomeReviewedShaFromResult, url); |
| 131 | + const after = resolve(automergeOutcomeReviewedShaFromResult, url); |
| 132 | + console.log(` ${url}`); |
| 133 | + console.log(` pre-fix : ${before === null ? "null (reviewed SHA dropped)" : before}`); |
| 134 | + console.log(` post-fix: ${after}`); |
| 135 | + check("pre-fix dropped the reviewed SHA", before === null); |
| 136 | + check("post-fix resolves the reviewed SHA", after === HEAD); |
| 137 | + // The bounded claim must hold in BOTH builds. |
| 138 | + const crossRepo = `https://github.com/openclaw/other-repo/pull/${TARGET}`; |
| 139 | + check( |
| 140 | + "cross-repository rejection unchanged by the fix", |
| 141 | + resolve(pre.automergeOutcomeReviewedShaFromResult, crossRepo) === null && |
| 142 | + resolve(automergeOutcomeReviewedShaFromResult, crossRepo) === null, |
| 143 | + ); |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +console.log(`\nRESULT: ${failures.length === 0 ? "PASS" : "FAIL"}`); |
| 148 | +if (failures.length) console.log(` failed: ${failures.join(", ")}`); |
| 149 | +process.exit(failures.length === 0 ? 0 : 1); |
0 commit comments