Repository navigation
Tests: boot the real app once for the route-table checks - #251
Open
cody-the-code-bot wants to merge 1 commit into
Open
cody-the-code-bot wants to merge 1 commit into
cody-the-code-bot wants to merge 1 commit into
Conversation
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
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.
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 importingquestloads every plugin into process-global registries, which would pollute the other tests.) Each file carried its own copy of the script and thesubprocess.runboilerplate:tests/test_spa_docs_routes.py(module fixtureroute_table)tests/test_spa_tables_routes.py(module fixtureroute_table, same body)tests/test_autoproject_access.py(module fixtureroute_table, same body)tests/test_sandbox_api.py(inline intest_main_app_serves_the_same_roster)tests/test_connections_routes.py(inline intest_quest_app_mounts_connection_routes)plugins/telegram/tests/test_telegram_tools.py(inline intest_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.pywith one session-scoped fixture,quest_route_table, that boots the app once per test process and returns the table as data (routes,pathsin registration order, and the API-docs URLs that the docs test needs).tests/conftest.pyexposes it to the core suite andplugins/telegram/tests/conftest.pyimports it, the same way plugin suites already takeisolated_dbfromtests.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.mdlists the new file under Key Files, and two comments that namedtests/test_spa_docs_routes.pyas the place to look for the subprocess pattern now name the support module.Two details worth a reviewer's eye:
tests/test_sandbox_api.pyused to readquest.app.routesdirectly; it now gets the table throughchat.route_table.iter_app_routeslike 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.pathslist 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 autorun). A serial run of the six files now boots the app once instead of six times, so roughly 8 s less. Underpytest -n autothe 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
tests/test_security_headers.py,tests/test_impersonation_guard.pyandtests/test_docs.py: 171 passed, with a single route-table boot showing in--durations.uv run pytest -n auto: 15155 passed, with the fivetests/test_encryption.py::TestMaskedPrompttests deselected. Those five have an unrelated intermittent hang onmainthat 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.pyandtests/test_security_headers.pyalso bootquestin 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