Skip to content

fix(examples): show the debug toolbar in the asgi_basic example - #61

Merged
JacobCoffee merged 3 commits into
mainfrom
fix/asgi-basic-html-page
Oct 11, 2026
Merged

JacobCoffee merged 3 commits into
mainfrom
fix/asgi-basic-html-page

Conversation

@JacobCoffee

Copy link
Copy Markdown
Owner

The asgi_basic example's hand-rolled ASGI middleware never buffered HTML response bodies, so the toolbar was never injected into the page \u2014 visiting the example in a browser never showed it, even on the existing HTML routes (/, /about).

What changed

  • The middleware now buffers HTML bodies and injects the rendered toolbar bar before </body>, mirroring the pattern used in examples/starlette_basic.
  • Added /_debug_toolbar/static/toolbar.css and toolbar.js routes serving the real toolbar assets (previously missing, so even if injected the toolbar would have been unstyled/non-interactive).
  • Renamed the request-history JSON endpoints to /_debug_toolbar/api/requests and /_debug_toolbar/api/requests/{id} to match the paths the toolbar's own JS calls when a panel is clicked.
  • JSON routes (/api/data) are untouched.

Verification

  • Confirmed the bug on current main: curl'd the index page before the change and the response had no toolbar markup at all.
  • After the fix, ran the example and checked with a headless browser: the toolbar bar renders on / and /about, clicking a panel button (e.g. Request) fetches and displays real request data, /api/data still returns unchanged JSON, and there are no console errors.
  • make ci passes (lint, type-check, 658 tests, docs build).

No example smoke tests exist in tests/ to extend; this repo has no test harness for the example apps.

The asgi_basic example's hand-rolled middleware never buffered HTML
response bodies, so the toolbar HTML was never injected and the toolbar
never appeared in the browser even though it has HTML routes. The
debug toolbar API handler also served static assets and request data
under paths the toolbar's own JS/CSS never requests.

Buffer HTML responses in the middleware, inject the rendered toolbar
before </body> (mirroring the starlette example), and serve
toolbar.css/toolbar.js plus matching /_debug_toolbar/api/requests(/{id})
routes so the toolbar bar renders and its panels open with real data.
JSON routes are unaffected.

Verified with a headless browser against the example on port 8984:
toolbar bar renders on / and /about, clicking a panel button loads
request data, /api/data JSON response is unchanged, no console errors.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 00:28

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@JacobCoffee
JacobCoffee enabled auto-merge (squash) October 11, 2026 00:34
Copilot AI balanced review requested due to automatic review settings October 11, 2026 00:36

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 01:10

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@JacobCoffee
JacobCoffee merged commit af3c25f into main Oct 11, 2026
22 checks passed
@JacobCoffee
JacobCoffee deleted the fix/asgi-basic-html-page branch October 11, 2026 01:18
JacobCoffee added a commit that referenced this pull request Oct 11, 2026
PR #61 made the asgi_basic example inject the toolbar markup into HTML
responses, serve /_debug_toolbar/static/{toolbar.css,toolbar.js}, and
move its JSON endpoints to /_debug_toolbar/api/requests(/<id>). Flip
the tests that previously asserted the pre-fix absence of these
behaviors to assert the real, now-fixed behavior instead.
JacobCoffee added a commit that referenced this pull request Oct 11, 2026
PR #61 made the asgi_basic example inject the toolbar markup into HTML
responses, serve /_debug_toolbar/static/{toolbar.css,toolbar.js}, and
move its JSON endpoints to /_debug_toolbar/api/requests(/<id>). Flip
the tests that previously asserted the pre-fix absence of these
behaviors to assert the real, now-fixed behavior instead.
JacobCoffee added a commit that referenced this pull request Oct 11, 2026
* fix: cascade-delete posts when deleting a user in advanced-alchemy example

DELETE /api/users/{id} raised a 500 IntegrityError for any user with
posts, since the default relationship behaviour nulls out the foreign
key instead of deleting dependents, and Post.author_id is non-nullable.
Found while writing tests for the example app.

* test: add full test coverage for example apps

Add tests/examples/ covering every app under examples/: asgi_basic,
litestar_basic, litestar_advanced_alchemy, starlette_basic,
fastapi_basic, websocket_panel_example, graphql_panel_example,
mcp_server_example, and the standalone panel demo scripts (cache,
templates, settings, profiling, memory, flamegraph, async_profiler,
alerts).

Each app is exercised through its own framework's real test client:
documented routes are checked for status/content-type, toolbar HTML
injection and static assets, and the per-request panel data the
example is built to demonstrate (SQL N+1 detection, GraphQL resolver
tracking, websocket connection stats, async profiler stats, and so
on).

A shared tests/examples/conftest.py fixture (import_example) imports
each example fresh per test and evicts it afterwards, since several
examples build module-level toolbar/app singletons at import time.

Add make test-examples to run just this suite.

* ci: add weekly workflow to test examples against latest dependencies

Runs tests/examples against uv sync --all-extras --upgrade (ignoring
the lockfile pins) on the oldest and newest supported Python versions,
on a weekly schedule, workflow_dispatch, and PRs touching examples/ or
tests/examples/. Prints resolved versions of the key frameworks for
debugging. Not part of the required CI Success aggregator.

Confirmed this actually catches regressions: with mcp upgraded past
2.0, debug_toolbar.mcp.server fails to import because mcp 2.x renamed
FastMCP to MCPServer, which this workflow surfaces as a test failure
in tests/examples/test_mcp_server_example.py.

* test: exercise the real example scripts instead of replicating panel logic

The standalone panel demo tests previously had a second test per
script that reconstructed the same DebugToolbar/Panel/Config objects
the script's main() builds, independent of the script itself. That
let a broken script (e.g. a renamed import, wrong panel class, wrong
config key) pass the test suite as long as the underlying panel class
still worked when built directly.

Replace those with a single test per script that imports the module
and calls its real main() (or free functions, for cache_panel_demo),
capturing real printed output and asserting on specific computed
values (counts, ratios, byte totals, timings, redacted fields) that
would change if the panel actually broke.

Also widen examples-latest.yml's pull_request trigger to include
src/** and pyproject.toml, since a library change (not just an
examples/tests change) can break examples against upgraded
dependencies.

* test: rebase asgi_basic tests onto the merged PR #61 fix

PR #61 made the asgi_basic example inject the toolbar markup into HTML
responses, serve /_debug_toolbar/static/{toolbar.css,toolbar.js}, and
move its JSON endpoints to /_debug_toolbar/api/requests(/<id>). Flip
the tests that previously asserted the pre-fix absence of these
behaviors to assert the real, now-fixed behavior instead.

* test: assert real behavior now fixed by PR #64 and #67

PR #64 made the FastAPI dependency injection panel actually populate
resolved_dependencies for nested Depends() trees; assert on the real
dependency names (get_db, get_current_user, get_token) and counts
instead of only checking the panel key exists.

PR #67 made the async profiler's taskfactory backend report the real
caller-supplied task name (previously always 'Task-N') and made
blocking call detection actually fire (previously silent, since
asyncio logs slow callbacks via the asyncio logger rather than
call_exception_handler). Assert on the real task names and a real
detected blocking call instead of working around both bugs.

* test: drop comparison of shortened task ids in async profiler example test
@JacobCoffee JacobCoffee mentioned this pull request Oct 11, 2026
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.

2 participants