Skip to content

feat(testing): add make_request_context + build_asgi_app platform test helpers#532

Closed
bokelley wants to merge 2 commits intomainfrom
claude/issue-516-testing-make-request-context-build-asgi-app
Closed

feat(testing): add make_request_context + build_asgi_app platform test helpers#532
bokelley wants to merge 2 commits intomainfrom
claude/issue-516-testing-make-request-context-build-asgi-app

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

@bokelley bokelley commented May 4, 2026

Summary

Closes #516.

Adds two server-side test seams to adcp.testing so adopters writing DecisioningPlatform handler tests have official, one-liner entry points with safe defaults:

  • make_request_context(account=..., account_id=..., **overrides) — constructs a RequestContext with all framework-owned stubs wired in (state, resolve). caller_identity defaults to the resolved account's id for 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 a DecisioningPlatform with 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 (allows httpx.ASGITransport test clients). Synchronous — must be called outside a running event loop; the boot-time capabilities validator uses asyncio.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 docstrings
  • src/adcp/testing/__init__.py — re-exports make_request_context, build_asgi_app
  • tests/test_testing_platform_helpers.py — 12 unit tests covering default/custom account, overrides, callable check, and MCP initialize smoke test

Test plan

  • pytest tests/test_testing_platform_helpers.py -v — all 12 pass
  • pytest tests/ -v — no regressions in full suite
  • mypy src/adcp/ — clean
  • ruff check src/ — clean

https://claude.ai/code/session_01PAKukKa2z53LwJAFoH2MuL


Generated by Claude Code

claude added 2 commits May 4, 2026 01:16
…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
@bokelley
Copy link
Copy Markdown
Contributor Author

bokelley commented May 4, 2026

Superseded by #535 (feat(testing): make_request_context + build_asgi_app helpers), already merged to main. Note #554 still proceeds — it extends build_asgi_app with allowed_hosts and adds build_test_client.

@bokelley bokelley closed this May 4, 2026
@bokelley bokelley deleted the claude/issue-516-testing-make-request-context-build-asgi-app branch May 4, 2026 08:51
@bokelley
Copy link
Copy Markdown
Contributor Author

bokelley commented May 4, 2026

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

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.

testing: ship adcp.testing.make_request_context + build_asgi_app helpers

2 participants