feat(testing): add make_request_context + build_asgi_app platform test helpers#532
Closed
feat(testing): add make_request_context + build_asgi_app platform test helpers#532
Conversation
…t helpers Closes #516 Adopters writing DecisioningPlatform unit tests previously had to guess which RequestContext factory defaults are safe and wire create_adcp_server_from_platform → create_mcp_server → streamable_http_app themselves. The new helpers make the test seam official and one-line. - `adcp.testing.make_request_context(account_id=..., **overrides)`: builds a RequestContext with sane defaults; sets `caller_identity` to the resolved account id to mirror production dispatch behavior. - `adcp.testing.build_asgi_app(platform, name=...)`: returns `mcp.streamable_http_app()` with test-appropriate defaults (`auto_emit_completion_webhooks=False` to skip the F12 webhook boot gate, `thread_pool_size=1` to cap executor churn, `enable_dns_rebinding_protection=False` so httpx.ASGITransport test clients pass arbitrary Host headers). Both are exported from `adcp.testing.__init__`. https://claude.ai/code/session_01PAKukKa2z53LwJAFoH2MuL
…ing in build_asgi_app docstring - caller_identity: doc now says "test simplicity" default (not "mirrors production"); production uses composite opaque key <store>:<account_id> - test assertions changed from == "test-account" / == "acme-corp" to `is not None` so adopters are not taught to parse the opaque field - build_asgi_app docstring adds .. warning:: block explaining asyncio.run() constraint and rewrites example as sync test + asyncio.run(_run()) pattern - removed duplicate test_build_asgi_app_default_name_from_class https://claude.ai/code/session_01PAKukKa2z53LwJAFoH2MuL
Contributor
Author
Contributor
Author
|
Noted — superseded by #535 (merged) and #554 extending from there. No further action on this PR. Triaged by Claude Code. Session: https://claude.ai/code/${CLAUDE_CODE_REMOTE_SESSION_ID} Generated by Claude Code |
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.
Summary
Closes #516.
Adds two server-side test seams to
adcp.testingso adopters writingDecisioningPlatformhandler tests have official, one-liner entry points with safe defaults:make_request_context(account=..., account_id=..., **overrides)— constructs aRequestContextwith all framework-owned stubs wired in (state,resolve).caller_identitydefaults to the resolved account'sidfor test simplicity (the production dispatch path sets a composite opaque key; tests should not assert on the exact value).build_asgi_app(platform, *, name=None) → ASGIApp— builds a runnable ASGI callable from aDecisioningPlatformwith test-appropriate defaults:auto_emit_completion_webhooks=False(skips F12 webhook-sender gate),thread_pool_size=1(reduces OS-thread churn),enable_dns_rebinding_protection=False(allowshttpx.ASGITransporttest clients). Synchronous — must be called outside a running event loop; the boot-time capabilities validator usesasyncio.run()internally.Both helpers are exported from
adcp.testing.__all__and documented with usage examples and constraints.Files changed
src/adcp/testing/platform_helpers.py— new module with both helpers and full docstringssrc/adcp/testing/__init__.py— re-exportsmake_request_context,build_asgi_apptests/test_testing_platform_helpers.py— 12 unit tests covering default/custom account, overrides, callable check, and MCP initialize smoke testTest plan
pytest tests/test_testing_platform_helpers.py -v— all 12 passpytest tests/ -v— no regressions in full suitemypy src/adcp/— cleanruff check src/— cleanhttps://claude.ai/code/session_01PAKukKa2z53LwJAFoH2MuL
Generated by Claude Code