Skip to content

Commit 7a9d33b

Browse files
authored
fix: compare GitHub repository slugs case-insensitively (#1058)
* fix(src/repair): compare GitHub repository slugs case-insensitively * test(test/repair/automerge-outcome.test.ts): adding up some amazing tests for github repo slugs * docs(docs/proof/automerge-repo-case-sensitivity): adding up proof of github repo case insensitively
1 parent 83a5329 commit 7a9d33b

11 files changed

Lines changed: 471 additions & 26 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Repository-slug case-sensitivity proof contract
2+
3+
## Claim
4+
5+
A parsed GitHub repository slug is matched case-insensitively, so a
6+
`canonical_pr` (or `source_prs` entry) that names the target repository with
7+
different casing resolves normally. Before this change the comparison was
8+
byte-exact, so `https://github.com/OpenClaw/OpenClaw/pull/83707` did not match
9+
the configured `openclaw/openclaw` and the reviewed head SHA was dropped.
10+
11+
Matching stays bounded: a genuinely different repository is still rejected, so
12+
this cannot widen into cross-repository head borrowing.
13+
14+
## Exercised surface
15+
16+
`automergeOutcomeReviewedShaFromResult()` in `dist/repair/automerge-outcome.js`
17+
is the reported site and the one measured before/after.
18+
19+
The same defect existed at every site that compared a slug returned by
20+
`parsePullRequestUrl` / `parseIssueOrPullRef`. Those parsers match with the `i`
21+
flag and return the slug **verbatim**, so a case-differing slug never equalled a
22+
configured one. All of them now use the shared `sameRepoSlug` comparator:
23+
24+
- `automerge-outcome.ts`
25+
- `execute-fix-github.ts`
26+
- `execute-fix-artifact.ts`
27+
- `post-flight.ts`
28+
- `source-pr-checkout.ts`
29+
- `target-validation.ts`
30+
31+
Claim 3 below re-derives that list from the built output rather than trusting the
32+
diff, so a site added later without the comparator fails the proof.
33+
34+
## Controlled scenario and fixture
35+
36+
`run-proof.mjs` asserts three claims against the built `dist/`:
37+
38+
1. **Resolves** — `canonical_pr` in three casings (`OpenClaw/OpenClaw`,
39+
`openclaw/OPENCLAW`, and a mixed-case `GitHub.com` host) each return the
40+
reviewed head, alongside an exact-case control.
41+
2. **Bounded** — three genuinely different repositories are still rejected,
42+
including the near-miss `openclaw/openclaw-state`. An absent slug never
43+
satisfies a repository guard, so the comparator cannot degrade into
44+
"empty matches everything".
45+
3. **Consistent** — the built output of all six consumer modules is scanned for a
46+
parsed slug compared with `===`/`!==` instead of the shared comparator. Any
47+
match fails the proof.
48+
49+
The before/after contrast compiles the **pre-fix** `automerge-outcome.ts` and
50+
`github-ref.ts` from the base commit inside the lease (their runtime import
51+
closure is just those two files — `json-types` is type-only and erases). If that
52+
build is unavailable the proof reports SKIPPED and **fails**, rather than
53+
quietly asserting an unmeasured contrast.
54+
55+
## Expected observation
56+
57+
17 checks, all PASS, exit 0, plus the measured contrast:
58+
59+
```
60+
https://github.com/OpenClaw/OpenClaw/pull/83707
61+
pre-fix : null (reviewed SHA dropped)
62+
post-fix: 92dca8fde03aee8da56a84a011fa387b9c1640fe
63+
```
64+
65+
Cross-repository rejection is asserted in **both** builds, showing the fix
66+
changed only the case dimension.
67+
68+
## Artifact and command
69+
70+
```bash
71+
crabbox run \
72+
--provider local-container \
73+
--local-container-image node:24 \
74+
--no-hydrate \
75+
--timing-json \
76+
--artifact-glob '.artifacts/automerge-repo-case-proof/**' \
77+
--script docs/proof/automerge-repo-case-sensitivity/run-proof.sh
78+
```
79+
80+
The script runs `pnpm run build:node`, **not** `build:repair`: `test/helpers.ts`
81+
(used by `post-flight.test.ts`) imports `dist/clawsweeper.js` and
82+
`dist/review-activity-cursor.js` from the main build, so the repair lane alone
83+
leaves the focused suites unable to load. An earlier revision of this script made
84+
exactly that mistake and the lease failed on it.
85+
86+
Host-only quick check (supply a pre-fix build directory for the contrast):
87+
88+
```bash
89+
pnpm run build:node
90+
node docs/proof/automerge-repo-case-sensitivity/run-proof.mjs /path/to/pre-fix/dist/repair
91+
```
92+
93+
Focused tests:
94+
95+
```bash
96+
node --test test/repair/automerge-outcome.test.ts test/repair/execute-fix-github.test.ts \
97+
test/repair/post-flight.test.ts test/repair/source-pr-checkout.test.ts
98+
```
99+
100+
## Provenance
101+
102+
- provider: Crabbox `local-container` (Docker/OrbStack)
103+
- crabbox: `0.15.0`
104+
- image: `node:24` @ `sha256:934240a162082fd8b8a2f90cd5114446443f1eba1c5378f6687167ca405e6584`
105+
- container node: `v24.19.0` (satisfies `engines.node >= 24`)
106+
- lease: `cbx_fe1bec2bb1b0` (`amber-barnacle`)
107+
- run: `run_194358f6840f`
108+
- artifact: `.crabbox/runs/run_194358f6840f/run_194358f6840f-artifacts.tgz`
109+
(`proof-output.txt`, `focused-tests.txt`, `install.log`, `build.log`,
110+
`prefix-build.log`)
111+
- result: exit `0`; 17/17 proof checks PASS; focused suites `18/18`
112+
- privacy: synthetic fixtures and public repository slugs only. The proof makes no
113+
network call, contacts no GitHub API, and performs no queue, GitHub, or
114+
production mutation.
115+
116+
## Limits
117+
118+
Covers the repository-slug comparison only. It does not change URL parsing, the
119+
allowed host, item-number matching, or any other guard.
120+
121+
The change is **one-directional**: it can only turn a "different repository"
122+
verdict into "same repository" when the two slugs differ solely by case. It can
123+
never cause a previously-matching slug to stop matching. That bounds the risk of
124+
touching the low-coverage `execute-fix-artifact.ts` mechanically.
125+
126+
Claim 3 scans **built output** for the specific `parsed.repo === …` shape. A site
127+
that compares a parsed slug through a differently-named local variable would not
128+
be caught by that regex; the six modules listed were enumerated by hand from the
129+
`parsePullRequestUrl` / `parseIssueOrPullRef` call graph.
130+
131+
The proof exercises no live GitHub redirect. That `github.com` serves
132+
case-differing slugs is GitHub's documented behavior, relied on here rather than
133+
demonstrated.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
# Crabbox local-container proof for the repository-slug case-sensitivity fix.
3+
#
4+
# Runs inside a Node 24 Linux container on the synced current checkout. It builds
5+
# the repair lane, compiles the PRE-FIX repair modules from the merge base so the
6+
# before/after contrast is measured rather than asserted, then runs run-proof.mjs
7+
# and the focused suites.
8+
set -euo pipefail
9+
10+
ARTIFACT_DIR=".artifacts/automerge-repo-case-proof"
11+
mkdir -p "$ARTIFACT_DIR"
12+
BASE_REF="${REPO_CASE_PROOF_BASE:-0588bda9}"
13+
14+
echo "== environment =="
15+
uname -a
16+
node --version
17+
NODE_MAJOR="$(node -p 'process.versions.node.split(".")[0]')"
18+
if [ "$NODE_MAJOR" -lt 24 ]; then
19+
echo "FAIL: repository requires Node >= 24, got $(node --version)"
20+
exit 1
21+
fi
22+
echo "head: $(git rev-parse HEAD 2>/dev/null || echo 'unavailable')"
23+
echo "base: $BASE_REF"
24+
echo
25+
26+
echo "== build =="
27+
# The lease runs as the unprivileged `crabbox` user, so corepack cannot symlink
28+
# into /usr/local/bin. Install the pinned pnpm into a user-writable prefix.
29+
export PNPM_HOME="$HOME/.local/bin"
30+
mkdir -p "$PNPM_HOME"
31+
export PATH="$PNPM_HOME:$PATH"
32+
if ! command -v pnpm >/dev/null 2>&1; then
33+
corepack enable --install-directory "$PNPM_HOME" >/dev/null 2>&1 || true
34+
fi
35+
if ! command -v pnpm >/dev/null 2>&1; then
36+
npm install -g --prefix "$HOME/.local" [email protected] >"$ARTIFACT_DIR/pnpm-install.log" 2>&1 || true
37+
fi
38+
command -v pnpm >/dev/null 2>&1 || {
39+
echo "FAIL: pnpm unavailable in container"
40+
tail -20 "$ARTIFACT_DIR/pnpm-install.log" 2>/dev/null || true
41+
exit 1
42+
}
43+
echo "pnpm: $(pnpm --version)"
44+
pnpm install --frozen-lockfile >"$ARTIFACT_DIR/install.log" 2>&1 \
45+
|| { echo "FAIL: pnpm install"; tail -30 "$ARTIFACT_DIR/install.log"; exit 1; }
46+
# build:node, not build:repair: test/helpers.ts (used by post-flight.test.ts)
47+
# imports dist/clawsweeper.js and dist/review-activity-cursor.js from the MAIN
48+
# build, so the repair lane alone leaves the focused suites unable to load.
49+
pnpm run build:node >"$ARTIFACT_DIR/build.log" 2>&1 \
50+
|| { echo "FAIL: pnpm run build:node"; tail -30 "$ARTIFACT_DIR/build.log"; exit 1; }
51+
test -f dist/repair/automerge-outcome.js || { echo "FAIL: repair build artifact missing"; exit 1; }
52+
test -f dist/clawsweeper.js || { echo "FAIL: main build artifact missing"; exit 1; }
53+
echo "post-fix comparator: $(grep -c 'sameRepoSlug' dist/repair/automerge-outcome.js || true) sameRepoSlug references (expect >0)"
54+
echo
55+
56+
echo "== compile pre-fix modules from $BASE_REF =="
57+
# automerge-outcome.ts's runtime import closure is just github-ref.ts (json-types
58+
# is type-only and erases), so the two files compile standalone. That is far more
59+
# robust inside a lease than reconstructing the whole repair lane.
60+
PREFIX_DIR="$(mktemp -d)"
61+
mkdir -p "$PREFIX_DIR/src"
62+
git show "$BASE_REF:src/repair/automerge-outcome.ts" > "$PREFIX_DIR/src/automerge-outcome.ts"
63+
git show "$BASE_REF:src/repair/github-ref.ts" > "$PREFIX_DIR/src/github-ref.ts"
64+
git show "$BASE_REF:src/repair/json-types.ts" > "$PREFIX_DIR/src/json-types.ts"
65+
./node_modules/.bin/tsc "$PREFIX_DIR/src/automerge-outcome.ts" --ignoreConfig \
66+
--target es2022 --module esnext --moduleResolution bundler --outDir "$PREFIX_DIR/out" \
67+
>"$ARTIFACT_DIR/prefix-build.log" 2>&1 || true
68+
PREFIX_REPAIR="$PREFIX_DIR/out"
69+
if [ ! -f "$PREFIX_REPAIR/automerge-outcome.js" ]; then
70+
PREFIX_REPAIR=""
71+
echo "pre-fix build: unavailable (before/after contrast reports SKIPPED and FAILS)"
72+
tail -20 "$ARTIFACT_DIR/prefix-build.log" 2>/dev/null || true
73+
else
74+
echo "pre-fix comparator: $(grep -c 'sameRepoSlug' "$PREFIX_REPAIR/automerge-outcome.js" || true) sameRepoSlug references (expect 0)"
75+
fi
76+
echo
77+
78+
echo "== proof =="
79+
node docs/proof/automerge-repo-case-sensitivity/run-proof.mjs ${PREFIX_REPAIR:+"$PREFIX_REPAIR"} \
80+
| tee "$ARTIFACT_DIR/proof-output.txt"
81+
82+
echo
83+
echo "== focused regression suites =="
84+
node --test \
85+
test/repair/automerge-outcome.test.ts \
86+
test/repair/execute-fix-github.test.ts \
87+
test/repair/post-flight.test.ts \
88+
test/repair/source-pr-checkout.test.ts 2>&1 | tail -8 | tee "$ARTIFACT_DIR/focused-tests.txt"
89+
90+
rm -rf "$PREFIX_DIR"
91+
echo
92+
echo "artifacts written to $ARTIFACT_DIR"

‎src/repair/automerge-outcome.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { JsonValue, LooseRecord } from "./json-types.js";
2-
import { parsePullRequestUrl } from "./github-ref.js";
2+
import { parsePullRequestUrl, sameRepoSlug } from "./github-ref.js";
33

44
export function automergeOutcomeReviewedShaFromResult({
55
result,
@@ -21,7 +21,7 @@ export function automergeOutcomeReviewedShaFromResult({
2121
if (direct) return direct;
2222

2323
const canonicalPr = parsePullRequestUrl(result.canonical_pr);
24-
if (!canonicalPr || canonicalPr.repo !== String(repo)) return null;
24+
if (!canonicalPr || !sameRepoSlug(canonicalPr.repo, repo)) return null;
2525
if (target !== undefined && Number(canonicalPr.number) !== Number(target)) return null;
2626

2727
return (

0 commit comments

Comments
 (0)