Repository navigation
fix(examples): show the debug toolbar in the asgi_basic example - #61
Merged
Merged
Conversation
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.
JacobCoffee
enabled auto-merge (squash)
October 11, 2026 00:34
This was referenced Oct 11, 2026
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
Merged
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.
The
asgi_basicexample'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
</body>, mirroring the pattern used inexamples/starlette_basic./_debug_toolbar/static/toolbar.cssandtoolbar.jsroutes serving the real toolbar assets (previously missing, so even if injected the toolbar would have been unstyled/non-interactive)./_debug_toolbar/api/requestsand/_debug_toolbar/api/requests/{id}to match the paths the toolbar's own JS calls when a panel is clicked./api/data) are untouched.Verification
main:curl'd the index page before the change and the response had no toolbar markup at all./and/about, clicking a panel button (e.g. Request) fetches and displays real request data,/api/datastill returns unchanged JSON, and there are no console errors.make cipasses (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.