fix(compat): extract hostname from brand_manifest URLs with paths#679
Conversation
strip_url_scheme only stripped the scheme prefix; for URLs like "https://acme.com/.well-known/brand.json" it produced "acme.com/.well-known/brand.json", which fails BrandReference.domain's regex and surfaces as a confusing INVALID_REQUEST[brand.domain] error. Adds extract_brand_domain() to _url.py — uses urlparse().hostname to isolate the hostname, falling back to strip_url_scheme for bare-domain inputs (no scheme). Both adapter call sites (get_products.adapt_request and _media_buy_helpers.adapt_brand_manifest_to_brand) now use the new helper. Regression tests cover the exact URL-with-path case from #677 and URL-with-port. Fixes #677 https://claude.ai/code/session_01YX14H75zYWQ1BYuopyUL34
|
Promoting out of draft — CI green across 3.10–3.13, both expert reviews approved, regression tests in place for both Follow-up nits (not blocking this PR):
Tracking both as ideas; happy to file follow-up issues if useful. |
|
Thanks for the promotion and the CI confirmation. Both nits are worth tracking — please do file follow-up issues for them. Brief suggested scopes:
Neither is blocking; filing them now gives the next triage sweep a handle to act on them. Triaged by Claude Code. Generated by Claude Code |
Expert review summarycode-reviewer: approved — no blockers. Confirmed ad-tech-protocol-expert: approved — confirmed the v2.5→v3 mapping is the only one v3's
CI: 16/16 green. Merging. |
Closes #677
Summary
strip_url_schemeonly strips the scheme prefix and trailing slash — for a v2.5brand_manifestURL like"https://acme.com/.well-known/brand.json"it returned"acme.com/.well-known/brand.json", which failsBrandReference.domain's hostname-only regex and surfaced as a confusingINVALID_REQUEST[brand.domain]error. The v2.5 spec documentsbrand_manifestas a URL to a JSON file, so a path is the expected input shape.This PR adds
extract_brand_domain()to_url.pyusingurlparse().hostname, which correctly strips both path and port. A bare-domain fallback viastrip_url_schemehandles callers that pass a schemeless string. Both adapter call sites —get_products.adapt_requestand_media_buy_helpers.adapt_brand_manifest_to_brand(used bycreate_media_buy) — are updated.update_media_buyis not affected (it carries nobrand_manifest).What was tested
pytest tests/test_legacy_adapter_v2_5_get_products.py tests/test_legacy_adapter_v2_5_media_buy.py tests/test_dispatcher_shape_detection.py -v— 54 passedruff check src/adcp/compat/— no issuesmypy src/adcp/compat/— no issues in 12 source filesNits surfaced by pre-PR review (not fixed in this PR)
"acme.com/.well-known/brand.json") falls through tostrip_url_schemeand produces an invalid domain — pre-existing gap, not introduced here; v2.5 spec definesbrand_manifestas a full URL so this input shape is malformedstrip_url_schemeretains a public name despite now being an internal fallback insideextract_brand_domain; consider renaming to_strip_url_schemein a follow-upurlparseand will still failBrandReference.domain's regex; documented inextract_brand_domain's docstring, callers must validate if IPv6 is possible (v2.5 spec makes this unrealistic forbrand_manifest)Pre-PR review
strip_url_schemenaming and IPv6 noted aboveSession: https://claude.ai/code/session_01YX14H75zYWQ1BYuopyUL34
Generated by Claude Code