fix(adagents): raise AdagentsAccessBlockedError on 403 + cf-mitigated: challenge#837
Draft
bokelley wants to merge 2 commits into
Draft
fix(adagents): raise AdagentsAccessBlockedError on 403 + cf-mitigated: challenge#837bokelley wants to merge 2 commits into
bokelley wants to merge 2 commits into
Conversation
…: challenge When _fetch_adagents_url receives HTTP 403 with cf-mitigated: challenge, raise AdagentsAccessBlockedError (AdagentsValidationError subclass) so callers can distinguish Cloudflare bot-management blocks from other errors. Existing except AdagentsValidationError handlers catch it automatically. Closes #801
- Add parametrized test for capitalized cf-mitigated: Challenge (Cloudflare's actual casing) - Add .strip() to header comparison for OWS robustness - Document AdagentsAccessBlockedError in fetch_adagents Raises section - Add explanatory comments at sites that intentionally swallow the subclass
| err = AdagentsAccessBlockedError("cafemedia.com") | ||
| assert isinstance(err, AdagentsValidationError) | ||
| assert "cf-mitigated: challenge" in str(err) | ||
| assert "cafemedia.com" in str(err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #801.
When
_fetch_adagents_urlreceives HTTP 403 withcf-mitigated: challenge, it now raisesAdagentsAccessBlockedError(anAdagentsValidationErrorsubclass) instead of the genericAdagentsValidationError. This makes the Cloudflare bot-challenge case distinguishable in application code without breaking existingexcept AdagentsValidationErrorhandlers.Changes
src/adcp/exceptions.py— newAdagentsAccessBlockedError(AdagentsValidationError)withpublisher_domainattribute and actionable suggestion textsrc/adcp/adagents.py— 403 +cf-mitigated: challengeguard inserted in_fetch_adagents_urlbetween the 404 and generic non-200 checks;fetch_adagentsdocstringRaisessection updated; explanatory comments added at swallow sitessrc/adcp/__init__.py—AdagentsAccessBlockedErroradded to exports and__all__tests/test_adagents.py— four new tests: CF-mitigated 403 raises the subclass (parametrized forchallenge/Challengecasing), plain 403 does not, subclass is catchable asAdagentsValidationErrortests/fixtures/public_api_snapshot.json—AdagentsAccessBlockedErroradded alphabeticallyDesign notes
AdagentsValidationError(notADCPErrordirectly) — existingexcept AdagentsValidationErrorcall sites catch it automatically; no call-site patches requiredcf-mitigated: challengeheader present (case-insensitive, OWS-stripped); plain 403s still raise the generic errorAdagentsAccessBlockedErroris intentionally swallowed in_try_managerdomain_fallbackandfetch_agent_authorizations(treated as authorization-unavailable, same as a missing file); comments added to each sitevalidate_adagents_domainsurfaces the error viastr(e)inAdAgentsValidationResult.errors— the actionable message reaches callersWhat was tested
pytest tests/test_adagents.py -v— 192 passedpytest tests/(excluding pre-existing TLS network test) — 5021 passed, 35 skippedmypy src/adcp/adagents.py src/adcp/exceptions.py src/adcp/__init__.py— no issuesruff check— no issuesPre-PR review
Challenge-casing test) fixed; intentional-swallow sites commentedpublisher_domainattribute is a DX improvementKnown nit (not fixed in this PR):
AdagentsNotFoundErrorandAdagentsTimeoutErrordo not storepublisher_domainas an instance attribute;AdagentsAccessBlockedErrordoes. Backfilling those siblings is a separate, additive change.Session: https://claude.ai/code/cse_01HBuAdZK8P2nCiEGqAeJ2wj
Generated by Claude Code