Skip to content

Tests: boot the real app once for the route-table checks - #251

Open
cody-the-code-bot wants to merge 1 commit into
mainfrom
quality/tests-shared-route-table
Open

cody-the-code-bot wants to merge 1 commit into
mainfrom
quality/tests-shared-route-table

Conversation

@cody-the-code-bot

Copy link
Copy Markdown
Collaborator

What I found

Six test files each start a fresh Python subprocess that imports quest, dumps the real app's route table as JSON, and then assert on it. (A subprocess is needed because importing quest loads every plugin into process-global registries, which would pollute the other tests.) Each file carried its own copy of the script and the subprocess.run boilerplate:

  • tests/test_spa_docs_routes.py (module fixture route_table)
  • tests/test_spa_tables_routes.py (module fixture route_table, same body)
  • tests/test_autoproject_access.py (module fixture route_table, same body)
  • tests/test_sandbox_api.py (inline in test_main_app_serves_the_same_roster)
  • tests/test_connections_routes.py (inline in test_quest_app_mounts_connection_routes)
  • plugins/telegram/tests/test_telegram_tools.py (inline in test_main_app_has_no_telegram_api_routes)

So a serial test run boots the whole app six times to read the same table, and the three fixtures are copies of each other.

What this PR does

Adds tests/route_table_support.py with one session-scoped fixture, quest_route_table, that boots the app once per test process and returns the table as data (routes, paths in registration order, and the API-docs URLs that the docs test needs). tests/conftest.py exposes it to the core suite and plugins/telegram/tests/conftest.py imports it, the same way plugin suites already take isolated_db from tests.db_support. The six files now ask for the fixture and keep their assertions.

No test is added or removed, and every assertion is kept. Net for the test files: 44 lines added, 196 removed, plus the 63-line support module. docs/setup/development-workflows.md lists the new file under Key Files, and two comments that named tests/test_spa_docs_routes.py as the place to look for the subprocess pattern now name the support module.

Two details worth a reviewer's eye:

  • tests/test_sandbox_api.py used to read quest.app.routes directly; it now gets the table through chat.route_table.iter_app_routes like the other five. That walker also sees routes inside included routers, so it can only see more routes than before, and the test only checks that the expected sandbox routes are present.
  • The Telegram test used to filter and sort the paths inside the subprocess; it now does the same filtering on the shared paths list in the test body. The expected list is unchanged.

Time saved

One app boot is about 1.6 s on this machine when run serially (2.5 to 3 s under a loaded -n auto run). A serial run of the six files now boots the app once instead of six times, so roughly 8 s less. Under pytest -n auto the saving is smaller and varies, because each xdist worker is its own process and boots the app once if it gets any of these tests.

How I verified it

  • The six files plus tests/test_security_headers.py, tests/test_impersonation_guard.py and tests/test_docs.py: 171 passed, with a single route-table boot showing in --durations.
  • Full suite, uv run pytest -n auto: 15155 passed, with the five tests/test_encryption.py::TestMaskedPrompt tests deselected. Those five have an unrelated intermittent hang on main that stalled my first two full runs of this branch; PR Fix the masked-prompt pty test hang; fail stuck tests by name instead of stalling CI #250 fixes it.

Left alone

  • tests/test_impersonation_guard.py and tests/test_security_headers.py also boot quest in a subprocess, but they do different work there (walking route dependencies, issuing a real request), so they keep their own scripts.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Feg3tCK32dcjnGBBuGS75b

Six test files each ran their own subprocess importing quest to dump the
route table. Share one session fixture, quest_route_table, from
tests/route_table_support.py.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Feg3tCK32dcjnGBBuGS75b
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.

1 participant