Repository navigation
Split the entrypoint app and its deployment asset tests under the file-length limit - #946
Merged
Merged
Conversation
2 tasks done
anth-volk
force-pushed
the
file-length-split-entry-app
branch
5 times, most recently
from
October 27, 2026 17:00
f0c4496 to
b749e1e
Compare
The entrypoint's app.py (925 lines) and tests/test_deployment_assets.py (2,251 lines) were over the file-length limits. The code moves unchanged. The backend calls, response telemetry and comparison dispatch move to entry_runtime.py: the response constants, the ComparisonBackend protocol, the backend call helpers and the runtime class, EntryRuntime. app.py keeps the routes and create_app (583 lines) and re-exports the public names. The routes stay there because their request annotations come from imports that app.py also uses at runtime; in a module of their own, ruff would read those imports as typing-only, and moving them under TYPE_CHECKING would stop FastAPI resolving the annotations. entry_runtime.py logs under the policyengine_simulation_entry.app logger, named explicitly, so its records keep their logger name. Private names app.py now imports are public: _EntryRuntime, _BackendCall, _model_json, _request_identifiers and _route_template (the last three with a new docstring), and _set_observability_header. The deployment tests move to seven files named test_deployment_assets*.py, with the shared paths, shell and smoke fakes and the GitHub expression reader in test_deployment_assets_support.py, whose helpers are now public. Its name keeps it among the files the CI-script guard searches for script names. All 126 tests keep their names and bodies. rules/registry.toml names each moved test by its new file, in its rule's nodes or in discovery.ignore_tests, and its guard-test discovery covers tests/test_deployment_assets*.py, so every test in these files must still be registered or ignored. The comparison dispatch timeout test patches STAGE12_MODAL_SUBMISSION_TIMEOUT_SECONDS in entry_runtime.py, where the dispatch reads it; the temporary Stage 12 submission test still patches it in app.py, where that route reads it. The file-length baseline drops both files (count 2 to 0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
file-length-split-entry-app
branch
from
October 27, 2026 17:11
b749e1e to
6b0dc54
Compare
anth-volk
marked this pull request as ready for review
October 27, 2026 17:23
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.
Fixes #945
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Summary
Eighth of nine stacked PRs; it builds on #942. It splits the entrypoint's
app.pyand its deployment asset tests without changing behaviour, and removes the last two files from the file-length baseline (count 2 to 0). Scripts compared every top-level statement of each old file with the new files: all appear exactly once and unchanged apart from the renames below and one logger line, in their original order, and every# noqacomment is kept.src/policyengine_simulation_entry/app.py(925 lines)entry_runtime.pyComparisonBackend, the backend call and telemetry helpers, andEntryRuntime, which calls the backends and dispatches comparisonsapp.pycreate_app,app, and re-exports of the moved public namesapp.py(583 lines, above the 400 the split aims for): their request annotations (SimulationRequest,UUID,AuthorizationDependency) come from imports thatapp.pyalso uses at runtime. Ruff doesn't recognise the routes'@app.postdecorators, becauseappis a function parameter, so in a module of their own it reads those imports as typing-only and asks to move them underTYPE_CHECKING, which would stop FastAPI resolving the annotations. Keeping the routes inapp.pykeeps both behaviours as they are, with no suppression or settings change.entry_runtime.pynames thepolicyengine_simulation_entry.applogger explicitly, so its records keep the logger name the tests check; this is the one statement that isn't verbatim. It is alogging.getLoggercall in each module, not an import, so ruff still recognises the logger and theTRY400suppressions on its calls stay in force.policyengine_simulation_entry.app:app, which the Dockerfile runs, andcreate_appare unchanged, and the entrypoint's OpenAPI tests pass unchanged.Renames
Private names
app.pynow imports fromentry_runtime.pyare public:_EntryRuntimetoEntryRuntime,_BackendCalltoBackendCall,_model_jsontomodel_json,_request_identifierstorequest_identifiers,_route_templatetoroute_template(the last three with a new one-line docstring), and_set_observability_headertoset_observability_header.Tests:
tests/test_deployment_assets.py(2,251 lines)test_deployment_assets_support.py(shared paths, shell and smoke fakes, GitHub expression reader; no tests)test_deployment_assets.pytest_deployment_assets_cloud_run.pytest_deployment_assets_promotion.pytest_deployment_assets_release_gates.pytest_deployment_assets_routing.pytest_deployment_assets_traffic.pytest_deployment_assets_identity_smoke.py_run_bash,_write_fake_smoke_curl,_smoke_test_env,_job_section,_sentinel_check_step,_routing_context,_run_identity_smokeand_workflow_jobsdrop their underscore, and_gh_evalisevaluate_github_expression.test_*.py, so the CI-script guard (sim.ci.workflow-scripts-tested), which looks for each workflow script's name in test files, still finds the scripts named by its path constants.nodesor listed indiscovery.ignore_tests.rules/registry.tomlnow names each by its new file (63 references), and the guard-test discovery pattern istests/test_deployment_assets*.py, so every test in the new files must still be registered or ignored. No rule, status or scope changes otherwise.test_comparison_dispatch_timeout_cannot_change_production_responsepatchesSTAGE12_MODAL_SUBMISSION_TIMEOUT_SECONDSinentry_runtime, whereEntryRuntimereads it for the comparison dispatch;test_temporary_stage12_submission_has_a_hard_acknowledgement_timeoutstill patches it inapp, where the Stage 12 submission route reads it;Stage12ComparisonBackendis still patched inapp, wherecreate_appreads it.Environment variables
No change: the moved code reads no environment variable, and no workflow, image or deployment file changes.
Testing
python -m unittest discover -s scripts/rules/tests -t .: passed.python scripts/run_quality_guards.pyandpython -m scripts.rules guard --base-ref origin/file-length-split-simulation-runtime: passed;python -m scripts.rules renderleaves no diff.Only the lowest PR in the stack runs full CI, so this PR's
CI completecheck fails by design until the PRs below it merge.🤖 Generated with Claude Code