Repository navigation
Conversation
Closes Metabuilder-Labs#608 Pin the fail-safe no-raise contract for GitHub API responses (200, 401, 403, 404, 429, non-JSON errors) and assert distinguishable log lines for claim/release success and failure paths.
|
| Filename | Overview |
|---|---|
| .github/scripts/contributor_label_guard.py | Adds explicit non-200 guards so valid-looking API error payloads cannot reach claim or release processing. |
| tests/unit/test_contributor_label_guard.py | Adds mocked HTTP and handler tests, including the actual parsed dictionary shape returned for JSON 403 responses. |
Reviews (3): Last reviewed commit: "Merge branch 'main' into test/contributo..." | Re-trigger Greptile
anilmurty
left a comment
There was a problem hiding this comment.
Thanks @syf2211 — the transport-level mocks are faithful and the timeline-pagination test is nicely load-bearing. One real gap left (matches Greptile's P2):
test_handle_claim_auth_failure... injects fetch_issue → (403, None). But GitHub returns a JSON body on a 403, and _api_request parses it to a dict — so the real handler gets (403, {"message": ...}), skips the 404 / not-a-dict branch, and falls through to log "no-op: issue #N is already closed" rather than the "not found (status 403)" your test asserts. So the test doesn't exercise the auth-failure path it names, and it hides that a 403 is logged indistinguishably from a genuine closed-issue no-op — which is exactly the log-distinguishability #608 asked to pin.
Ask: inject the realistic (403, {"message": ...}) shape. If that surfaces the misleading "already closed" log, that's a real diagnostic gap — either tighten the handler to branch on status >= 400 before the state check, or scope it to a follow-up (the guard shipped in #574, so a handler change may be beyond this test-only PR — your call). Ping me when updated.
|
@syf2211 - are you still planning to work this? |
Inject realistic (403, {"message": ...}) payloads in auth-failure tests.
Handle non-200 statuses before checking issue state so a 403 no longer
logs misleading 'already closed' messages.
Addresses maintainer feedback on Metabuilder-Labs#633.
|
Thanks for the review — pushed 5ec8d5b addressing the auth-failure gap:
|
|
Yes — this PR is still active and ready for re-review. The latest commit addresses the structured 403 payload concern from the previous review thread. Happy to make further changes if anything else comes up. |
|
Yes — still on it. The 403 structured-payload regression from 5ec8d5b is covered and unit tests pass (45/45). Let me know if you'd like anything else before merge. |
|
thanks @syf2211 - appreciate the contribution! |
Summary
Add mocked-HTTP unit tests for the GitHub API I/O layer in
.github/scripts/contributor_label_guard.py, covering the response classes that were deliberately left untested when the guard shipped in #574.Motivation
The contributor label guard is designed to fail-safe: HTTP errors must never crash the workflow. That behavior was correct at runtime but untested in CI, so regressions in the I/O layer would be silent. Issue #608 asks us to pin that contract with mocked HTTP tests.
Changes
tests/unit/test_contributor_label_guard.pywith mockedurllib.request.urlopencoverage for_api_request,fetch_issue, andfetch_issue_timeline_handle_claim/_handle_releasethat assert distinguishable stdout/stderr log lines on success, no-op, and warn pathsTests
Result: 45 passed, ruff clean.
Notes
fetch_issue/remove_label/add_labelsfor log-contract coverage; the lower-levelurlopenmocks cover the actual HTTP transport.Fixes #608
cc @anilmurty for review