Skip to content

feat: add mocked-HTTP coverage for contributor_label_guard I/O - #633

Merged
anilmurty merged 3 commits into
Metabuilder-Labs:mainfrom
syf2211:test/contributor-label-guard-http-mocks
Aug 13, 2026
Merged

anilmurty merged 3 commits into
Metabuilder-Labs:mainfrom
syf2211:test/contributor-label-guard-http-mocks

Conversation

@syf2211

@syf2211 syf2211 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

  • Extend tests/unit/test_contributor_label_guard.py with mocked urllib.request.urlopen coverage for _api_request, fetch_issue, and fetch_issue_timeline
  • Add handler-level tests for _handle_claim / _handle_release that assert distinguishable stdout/stderr log lines on success, no-op, and warn paths
  • Cover 200, 401, 403, 404, 429, non-JSON error bodies, timeline pagination, and issue payloads missing expected keys
  • No production code changes — fail-safe behavior is unchanged

Tests

python3 -m pytest tests/unit/test_contributor_label_guard.py -v
python3 -m ruff check tests/unit/test_contributor_label_guard.py

Result: 45 passed, ruff clean.

Notes

  • Handler tests stub fetch_issue / remove_label / add_labels for log-contract coverage; the lower-level urlopen mocks cover the actual HTTP transport.
  • Reviewed with composer-2.5: APPROVE.

Fixes #608

cc @anilmurty for review

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.
@syf2211
syf2211 requested a review from anilmurty as a code owner July 28, 2026 00:04
@greptile-apps

greptile-apps Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR strengthens fail-safe handling and expands mocked HTTP coverage for the contributor label guard.

  • Prevents claim and release handlers from processing issue payloads returned with non-200 statuses.
  • Tests actual JSON error payloads for authentication and rate-limit responses.
  • Adds transport, pagination, malformed-response, handler logging, and label-operation coverage.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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 anilmurty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@anilmurty

Copy link
Copy Markdown
Contributor

@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.
@syf2211

syf2211 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review — pushed 5ec8d5b addressing the auth-failure gap:

  1. Realistic 403 payload — test_handle_claim_auth_failure now injects (403, {"message": "Forbidden"}) instead of (403, None).
  2. Handler fix — _handle_claim and _handle_release now branch on status != 200 before checking issue.state, so a 403 logs no-op: issue #N API error (status 403) instead of the misleading "already closed" message.

python3 -m pytest tests/unit/test_contributor_label_guard.py -v --noconftest — 45/45 pass.

@syf2211

syf2211 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

@syf2211

syf2211 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

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.

@anilmurty anilmurty changed the title test: add mocked-HTTP coverage for contributor_label_guard I/O feat: add mocked-HTTP coverage for contributor_label_guard I/O Aug 13, 2026
@anilmurty
anilmurty merged commit bfcf584 into Metabuilder-Labs:main Aug 13, 2026
6 checks passed
@anilmurty

Copy link
Copy Markdown
Contributor

thanks @syf2211 - appreciate the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

contributor_label_guard's network paths have no mocked-HTTP test coverage

2 participants