Skip to content

test: add tests for example apps - #65

Merged
JacobCoffee merged 7 commits into
mainfrom
test/example-apps
Oct 11, 2026
Merged

JacobCoffee merged 7 commits into
mainfrom
test/example-apps

Conversation

@JacobCoffee

Copy link
Copy Markdown
Owner

Summary

  • Adds tests/examples/ with 95 tests 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 eight standalone panel demo scripts (cache, templates, settings, profiling, memory, flamegraph, async_profiler, alerts).
  • Each example is exercised through its own framework's real test client against documented routes (status codes, content types, toolbar HTML injection, static assets) and the specific panel data it's built to demonstrate (SQL N+1 detection, GraphQL resolver/N+1 tracking, websocket connection stats, async profiler task stats, settings redaction, etc.).
  • Adds a shared tests/examples/conftest.py import_example fixture that imports each example module fresh per test and evicts it afterwards, since several examples build module-level toolbar/app singletons (and some write real files like ./example.db or .debug_toolbar_storage.json) at import time.
  • Fixes a genuine bug found while testing litestar_advanced_alchemy: DELETE /api/users/{id} 500'd for any user with posts because the User.posts relationship had no cascade, and Post.author_id is non-nullable.
  • Adds .github/workflows/examples-latest.yml ("Examples (latest dependencies)"), which runs tests/examples against uv sync --all-extras --upgrade on Python 3.10 and 3.15, on a weekly schedule / workflow_dispatch / PRs touching examples/. Not part of the CI Success aggregator.
  • Adds make test-examples.

Verification

  • make ci passes (755 passed, 13 skipped).
  • tests/examples passes standalone (95 passed, ~20s) and interleaved with the rest of the suite with no cross-test interference.
  • Confirmed a test actually catches breakage: temporarily set enabled=False on litestar_basic's toolbar config and observed 10/12 of its tests fail (toolbar markup missing, static assets 404, history/detail endpoints 404); reverted cleanly.
  • Ran the new workflow's upgrade path locally in a throwaway copy (uv sync --all-extras --upgrade): litestar 2.24.0, starlette 1.7.0, fastapi 0.143.0, advanced-alchemy 1.11.0, sqlalchemy 2.1.4, strawberry-graphql 0.333.0, mcp 2.3.0. This genuinely caught a real regression: mcp>=2.0 renamed FastMCP to MCPServer, which breaks debug_toolbar.mcp.server's import and fails the 2 MCP tool-registry tests. That's a library-level incompatibility in src/debug_toolbar/mcp/server.py (not an example bug), out of scope for this examples-only PR, but it's exactly the kind of regression this new workflow is meant to surface going forward — flagging for a follow-up fix (e.g. pin mcp<2 or support both APIs).

Notes

Copilot AI balanced review requested due to automatic review settings October 11, 2026 00:52

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 00:59

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:21

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.

…ample

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.
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.
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.
…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.
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.
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.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 01:48

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 01:48
Copilot AI balanced review requested due to automatic review settings October 11, 2026 01:50

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 1560656 into main Oct 11, 2026
24 checks passed
@JacobCoffee
JacobCoffee deleted the test/example-apps branch October 11, 2026 01:55
@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