From 66776948e9eab8600d9caa7b6a719f0aabfdd1da Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 13 Oct 2026 19:42:34 +0000 Subject: [PATCH] Let a 404 from compare mean "this branch does not vouch" in the intake scan reachable() lists the repository's branches and asks GitHub to compare each one with the submitted source commit. GitHub answers 404 "No common ancestor" for a branch with unrelated history, and 404 for a branch deleted between the listing and the compare. ancestor_of_branch() let that HTTPError escape, so one orphan branch listed before the vouching branch made the whole check reject with "HTTP Error 404: Not Found". That is what turned main#386 red once claude/recovery-01N-20261013 appeared. A 404 from that one compare request now returns False for that branch and the scan continues. Every other HTTP status still raises and rejects. No other request changes: branch listing, source, tree, blob and admission fetches keep their existing failure behaviour. A 404 alone is never reachability: if no branch vouches, the check still rejects with "not reachable from any branch". Three regressions in tests/test_public_intake.py: - an orphan branch answering 404 before a vouching branch is accepted (fails on the old checker with HTTP Error 404); - an orphan branch answering 404 with no vouching branch is rejected as not reachable (fails on the old checker); - 403, 500 and 502 from compare still reject (passes on both; it fails if the catch is widened to every HTTPError). The diff is byte-identical to the frozen patch at 31a28da, blob 8b758740, SHA-256 7cb9ee64a99d026a2c3b5d040e05a50d8fead89f9f80519fa6ed2274c5faf18a. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Cz7WZybv8znP64SpPj6sWY --- tests/test_public_intake.py | 32 ++++++++++++++++++++++++++++++++ tools/public_intake_check.py | 12 +++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/test_public_intake.py b/tests/test_public_intake.py index d22cdd10b..d531e2816 100644 --- a/tests/test_public_intake.py +++ b/tests/test_public_intake.py @@ -15,6 +15,7 @@ import unittest import zipfile import zlib +import urllib.error spec = importlib.util.spec_from_file_location('intake', Path(__file__).resolve().parents[1] / 'tools/public_intake_check.py') intake = importlib.util.module_from_spec(spec) @@ -448,6 +449,37 @@ def test_source_reachable_only_from_research_branch_accepted(self): self.assertIn(f'/repos/{REPO}/compare/{branch}...{"d" * 40}?per_page=1', self.api.calls) self.assertFalse(any('page=2' in c for c in self.api.calls)) # a short page ends the enumeration + def test_orphan_branch_404_does_not_vouch_and_scan_continues(self): + # An unrelated-history branch listed before the vouching branch: GitHub's compare answers + # 404 "No common ancestor". That branch does not vouch; the scan must reach the next branch. + raw = b'public numbers on a research branch\n' + orphan, branch = 'claude/recovery-orphan', 'claude/recovery-real' + self.manifest['sources'] = [{'repository': REPO, 'path': 'research/numbers.json', 'commit': 'd' * 40, 'sha256': sha(raw)}] + self.save() + self.install_source(REPO, 'd' * 40, 'research/numbers.json', raw, branches=('main', orphan, branch), reachable_from=(branch,)) + no_common = urllib.error.HTTPError('https://api.github.com', 404, 'Not Found', None, None) + self.api.routes[f'/repos/{REPO}/compare/{orphan}...{"d" * 40}?per_page=1'] = no_common + self.assertEqual(self.run_check()['verified_sources'], 1) + self.assertIn(f'/repos/{REPO}/compare/{branch}...{"d" * 40}?per_page=1', self.api.calls) + + def test_orphan_branch_404_alone_is_not_reachability(self): + # Negative control: a 404 is "does not vouch", never "vouches"; with no other branch the source is refused. + raw = b'public numbers on a research branch\n' + orphan = 'claude/recovery-orphan' + self.manifest['sources'] = [{'repository': REPO, 'path': 'research/numbers.json', 'commit': 'd' * 40, 'sha256': sha(raw)}] + self.save() + self.install_source(REPO, 'd' * 40, 'research/numbers.json', raw, branches=('main', orphan), reachable_from=()) + self.api.routes[f'/repos/{REPO}/compare/{orphan}...{"d" * 40}?per_page=1'] = urllib.error.HTTPError('u', 404, 'Not Found', None, None) + self.reject('not reachable from any branch') + + def test_compare_non_404_http_error_still_rejects(self): + # Negative control: only 404 means "this branch does not vouch"; a 403 or 500 is not evidence and rejects. + route = f'/repos/{MATH}/compare/main...{SOURCE}?per_page=1' + for code in (403, 500, 502): + with self.subTest(code=code): + self.api.routes[route] = urllib.error.HTTPError('u', code, 'error', None, None) + self.reject(f'HTTP Error {code}') + def test_reachable_default_branch_costs_one_compare_call(self): self.assertEqual(self.run_check()['verified_sources'], 1) self.assertEqual(self.reachability_calls(), [f'/repos/{MATH}/compare/main...{SOURCE}?per_page=1']) diff --git a/tools/public_intake_check.py b/tools/public_intake_check.py index edc64d9a7..0bdfe5063 100644 --- a/tools/public_intake_check.py +++ b/tools/public_intake_check.py @@ -15,6 +15,7 @@ from pathlib import Path, PurePosixPath import re import struct +import urllib.error import urllib.request import zlib @@ -202,7 +203,16 @@ def tree(api, repo, ref): def ancestor_of_branch(api, repo, branch, commit): if not (isinstance(branch, str) and BRANCH.fullmatch(branch) and '..' not in branch): return False # a name this route cannot carry safely never vouches for a source - data = api.get(f'/repos/{repo}/compare/{branch}...{commit}?per_page=1') + try: + data = api.get(f'/repos/{repo}/compare/{branch}...{commit}?per_page=1') + except urllib.error.HTTPError as error: + # GitHub answers 404 "No common ancestor" for a branch with unrelated history + # (an orphan branch), and 404 for a branch deleted between listing and compare. + # Either way that branch does not vouch; keep scanning. Any other status is + # not evidence either way and still rejects. + if error.code == 404: + return False + raise if not (isinstance(data, dict) and isinstance(data.get('merge_base_commit'), dict)): return False # any other shape is not evidence of reachability return (type(data.get('ahead_by')) is int and data['ahead_by'] == 0 and data.get('status') in ('behind', 'identical')