Skip to content

Split the entrypoint app and its deployment asset tests under the file-length limit - #946

Merged
anth-volk merged 1 commit into
mainfrom
file-length-split-entry-app
Oct 27, 2026
Merged

anth-volk merged 1 commit into
mainfrom
file-length-split-entry-app

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #945

Same-Repository Draft PR Check

  • This PR is a draft.
  • This PR is from a branch in PolicyEngine/policyengine-sim-api, not a personal fork.

Summary

Eighth of nine stacked PRs; it builds on #942. It splits the entrypoint's app.py and 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 # noqa comment is kept.

src/policyengine_simulation_entry/app.py (925 lines)

Module Lines Holds
entry_runtime.py 400 the response constants, ComparisonBackend, the backend call and telemetry helpers, and EntryRuntime, which calls the backends and dispatches comparisons
app.py 583 the request-context middleware, every route, create_app, app, and re-exports of the moved public names
  • Why the routes stay in app.py (583 lines, above the 400 the split aims for): their request annotations (SimulationRequest, UUID, AuthorizationDependency) come from imports that app.py also uses at runtime. Ruff doesn't recognise the routes' @app.post decorators, because app is a function parameter, so in a module of their own it reads those imports as typing-only and asks to move them under TYPE_CHECKING, which would stop FastAPI resolving the annotations. Keeping the routes in app.py keeps both behaviours as they are, with no suppression or settings change.
  • Logging: entry_runtime.py names the policyengine_simulation_entry.app logger explicitly, so its records keep the logger name the tests check; this is the one statement that isn't verbatim. It is a logging.getLogger call in each module, not an import, so ruff still recognises the logger and the TRY400 suppressions on its calls stay in force.
  • policyengine_simulation_entry.app:app, which the Dockerfile runs, and create_app are unchanged, and the entrypoint's OpenAPI tests pass unchanged.

Renames

Private names app.py now imports from entry_runtime.py are public: _EntryRuntime to EntryRuntime, _BackendCall to BackendCall, _model_json to model_json, _request_identifiers to request_identifiers, _route_template to route_template (the last three with a new one-line docstring), and _set_observability_header to set_observability_header.

Tests: tests/test_deployment_assets.py (2,251 lines)

File Lines
test_deployment_assets_support.py (shared paths, shell and smoke fakes, GitHub expression reader; no tests) 411
test_deployment_assets.py 269
test_deployment_assets_cloud_run.py 280
test_deployment_assets_promotion.py 269
test_deployment_assets_release_gates.py 302
test_deployment_assets_routing.py 384
test_deployment_assets_traffic.py 197
test_deployment_assets_identity_smoke.py 303
  • 126 tests before and after, with the same names. The shared helpers are public: _run_bash, _write_fake_smoke_curl, _smoke_test_env, _job_section, _sentinel_check_step, _routing_context, _run_identity_smoke and _workflow_jobs drop their underscore, and _gh_eval is evaluate_github_expression.
  • The support module's name matches 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.
  • Rules registry: every one of these tests was referenced by a rule's pytest nodes or listed in discovery.ignore_tests. rules/registry.toml now names each by its new file (63 references), and the guard-test discovery pattern is tests/test_deployment_assets*.py, so every test in the new files must still be registered or ignored. No rule, status or scope changes otherwise.
  • Patch targets: test_comparison_dispatch_timeout_cannot_change_production_response patches STAGE12_MODAL_SUBMISSION_TIMEOUT_SECONDS in entry_runtime, where EntryRuntime reads it for the comparison dispatch; test_temporary_stage12_submission_has_a_hard_acknowledgement_timeout still patches it in app, where the Stage 12 submission route reads it; Stage12ComparisonBackend is still patched in app, where create_app reads it.

Environment variables

No change: the moved code reads no environment variable, and no workflow, image or deployment file changes.

Testing

  • Entrypoint, full suite: 742 passed.
  • Pyright for the entrypoint: no errors.
  • Ruff 0.15.22 format and lint: clean.
  • python -m unittest discover -s scripts/rules/tests -t .: passed.
  • python scripts/run_quality_guards.py and python -m scripts.rules guard --base-ref origin/file-length-split-simulation-runtime: passed; python -m scripts.rules render leaves no diff.

Only the lowest PR in the stack runs full CI, so this PR's CI complete check fails by design until the PRs below it merge.

🤖 Generated with Claude Code

@anth-volk
anth-volk added this pull request to stack #928 October 27, 2026 14:12
@anth-volk
anth-volk force-pushed the file-length-split-entry-app branch 5 times, most recently from f0c4496 to b749e1e Compare October 27, 2026 17:00
Base automatically changed from file-length-split-simulation-runtime to main October 27, 2026 17:11
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
anth-volk force-pushed the file-length-split-entry-app branch from b749e1e to 6b0dc54 Compare October 27, 2026 17:11
@anth-volk
anth-volk marked this pull request as ready for review October 27, 2026 17:23
@anth-volk
anth-volk requested a review from a team as a code owner October 27, 2026 17:23
@anth-volk
anth-volk merged commit 3968581 into main Oct 27, 2026
22 checks passed
@anth-volk
anth-volk deleted the file-length-split-entry-app branch October 27, 2026 17:23
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.

Split the entrypoint app and its deployment asset tests under the file-length limit

1 participant