From 787c5348e3383df9f00eb819ac8c4bce6fa48322 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 17 Nov 2026 14:12:09 +0000 Subject: [PATCH] fix: report private/unreadable repos as excluded, not unavailable The Pages workflow collects with github.token, scoped to PyAutoEars, so the metadata read for a private repo answers 404 and was reported as a generic "unavailable" read failure. GitHub.get now raises NotFound (a ReadError) on gh's "HTTP 404", and collect() reports that metadata read as "excluded" with a "not visible publicly (private or missing)" gap. Rate limits, 5xx and timeouts stay "unavailable". Closes #33 Co-Authored-By: Claude Opus 5.5 --- REFERENCE.md | 2 ++ ears/collect.py | 14 ++++++++++++++ tests/test_ears.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index c1f54d7..1f4aad0 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -38,6 +38,8 @@ Each source receipt names the repo, UTC check time, verified-public flag, status (complete/partial/unavailable/excluded) and bounded gap descriptions. Only a successful repository metadata response with `private: false` permits collection. Failed metadata reads and private repositories publish no rows. +A metadata read that answers 404 (a source the collector cannot see: private +to its token, or missing) is `excluded`, not `unavailable`. URLs are constructed from validated identities, never accepted from source text. Snapshot inputs are trusted local evidence envelopes, not proof of API authenticity; validate their source before using them for public publication. diff --git a/ears/collect.py b/ears/collect.py index 3a11c71..5bd49bf 100644 --- a/ears/collect.py +++ b/ears/collect.py @@ -86,6 +86,10 @@ class ReadError(Exception): """Bounded public description, never an API payload or secret.""" +class NotFound(ReadError): + """The source answered 404: private to this token, renamed or missing.""" + + class GitHub: def __init__(self, binary="gh"): self.binary = binary @@ -99,6 +103,10 @@ def get(self, endpoint): except (OSError, subprocess.TimeoutExpired): raise ReadError("GitHub client unavailable or timed out") from None if r.returncode: + # gh reports "HTTP 404" on stderr; GitHub answers 404, not 403, for + # a private repository the token cannot see. + if "HTTP 404" in (r.stderr or ""): + raise NotFound("source not found or not visible publicly") raise ReadError("GitHub read failed (permissions, rate limit or endpoint)") try: return json.loads(r.stdout) @@ -504,6 +512,12 @@ def collect(api, repo_homes, config, pending=None): receipt["status"] = "excluded" receipt["gaps"] = ["source is not verified public"] continue + except NotFound: + # Private to the collector's token (or missing): not public, so + # excluded rather than a collection failure. + receipt["status"] = "excluded" + receipt["gaps"] = ["source is not visible publicly (private or missing)"] + continue except ReadError as exc: receipt["gaps"] = [str(exc)] continue diff --git a/tests/test_ears.py b/tests/test_ears.py index 1bc7f5e..9269e94 100644 --- a/tests/test_ears.py +++ b/tests/test_ears.py @@ -97,6 +97,21 @@ def test_public_only_and_failed_metadata_never_leak_titles(): assert {r["status"] for r in s["receipts"]} == {"complete", "excluded", "unavailable"} +def test_invisible_source_is_excluded_but_other_failures_stay_unavailable(): + api = API({"repos/hidden/lib": collect.NotFound("source not found or not visible publicly"), + "repos/limited/lib": collect.ReadError("GitHub read failed (permissions, rate limit or endpoint)"), + listing("hidden/lib"): [thread(title="HIDDEN TITLE")]}) + s = collect.collect(api, ["hidden/lib", "limited/lib"], CONFIG) + receipts = {r["repo"]: r for r in s["receipts"]} + hidden, limited = receipts["hidden/lib"], receipts["limited/lib"] + assert hidden["status"] == "excluded" and hidden["public_verified"] is False + assert hidden["gaps"] == ["source is not visible publicly (private or missing)"] + assert limited["status"] == "unavailable" and limited["public_verified"] is False + assert not any(c.startswith(("repos/hidden/lib/", "repos/limited/lib/")) for c in api.calls) + assert "HIDDEN TITLE" not in json.dumps(s) + collect.validate(s) + + def test_pagination_and_oldest_conversation_beyond_thirty(): api = API({listing(): [thread(n) for n in range(1, 101)], listing(page=2): [thread(101, created_at="2020-01-01T00:00:00Z")]}) @@ -236,6 +251,23 @@ def run(args, **kw): collect.GitHub().get("https://example.invalid/upload") +@pytest.mark.parametrize("stderr, error", [ + ("gh: Not Found (HTTP 404)\n", collect.NotFound), + ("gh: API rate limit exceeded (HTTP 403)\n", collect.ReadError), + ("gh: Server Error (HTTP 502)\n", collect.ReadError), + (None, collect.ReadError), +]) +def test_gh_adapter_classifies_not_found(monkeypatch, stderr, error): + payload = '{"message": "SECRET PAYLOAD"}' + def run(args, **kw): + return type("Result", (), {"returncode": 1, "stdout": payload, "stderr": stderr})() + monkeypatch.setattr(collect.subprocess, "run", run) + with pytest.raises(collect.ReadError) as caught: + collect.GitHub().get("repos/example/lib") + assert type(caught.value) is error + assert "SECRET" not in str(caught.value) + + def test_bot_pr_requested_review_is_not_lost(): pr = thread(login="bot[bot]", pull_request={"url": "unused"}) pr["user"]["type"] = "Bot"