Skip to content

Split the Stage 12 runtime tests under the file-length limit - #936

Merged
anth-volk merged 1 commit into
mainfrom
file-length-split-stage12-runtime-tests
Oct 27, 2026
Merged

anth-volk merged 1 commit into
mainfrom
file-length-split-stage12-runtime-tests

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #935

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

Fifth of nine stacked PRs; it builds on #933. It splits the executor's tests/test_stage12_runtime.py (4,709 lines) into test files under the 1,500-line limit for tests, without changing any test or any source file, and removes it from the file-length baseline (count 8 to 7).

A script compared every top-level statement of the old file with the new files: all 168 appear exactly once and unchanged apart from the helper renames, in their original order.

File Lines Holds
stage12_runtime_support.py 369 IDs, input and record builders, the coordinate_report wrapper, recording runtimes, failure-summary checks, the dataset-load harness
stage12_fake_stores.py 207 FakeStore, FakeArtifacts and the simulation frames they hold
stage12_child_call_support.py 411 fake child calls and invokers, and the cancellation and log checks
test_stage12_runtime.py 309 how a simulation loads its dataset and region
test_stage12_dataset_provenance.py 335 the dataset a calculation loads, and the provenance it checks
test_stage12_single_worker.py 233 the single worker's successful and refused runs
test_stage12_single_worker_failures.py 337 how the single worker records and reports failures
test_stage12_aggregate_reports.py 454 the aggregate report
test_stage12_coordinator.py 414 starting, aggregating and comparing
test_stage12_coordinator_failures.py 529 a failing child or artifact
test_stage12_coordinator_failure_records.py 403 failure records, dispatch failures, reuse and timeouts
test_stage12_runtime_store_retries.py 135 retrying refused database connections
test_stage12_child_cancellation.py 412 cancelling unfinished children
test_stage12_child_state_errors.py 401 child state errors never replace the recorded failure
test_stage12_wait_window.py 152 the shared wait window

Renames

The helpers the files share are now public, under names no test already uses for a local variable or parameter (a script checked): _spm_calculation_provenance to spm_calculation_provenance, _bundle to bundle_provenance, _simulation to simulation_execution_input, _output_plan to shared_output_plan, _planned_simulation to planned_simulation, _report to report_execution_input, _aggregate_payload to aggregate_payload, _context to invocation_context, _parent to parent_record, _child to child_record, _automatic_parent to automatic_parent_record, _frames to simulation_frames, _connection_limit_error to connection_limit_error, _correlation_id to summary_correlation_id, _failure_cause to summary_failure_cause, _stage12_load to run_until_dataset_loaded, _simulation_id to role_simulation_id, _report_with_segmentation to report_with_segmentation, _coordinate_with to coordinate_with, _assert_cancelled to assert_cancelled, _assert_original_coordinator_failure to assert_original_coordinator_failure, _coordination_log to coordination_log_record, _assert_log_identifies_child to assert_log_identifies_child. Fakes whose unused parameters were named _simulation or _report keep those parameter names.

Seven other test modules imported these helpers from test_stage12_runtime.py (test_stage12_cache_runtime.py, test_stage12_coordination.py, test_stage12_qualification.py, test_stage12_segment_calculation.py, test_stage12_segment_fanout.py, test_stage12_segmentation_foundation.py, test_stage12_simulation_worker.py). They now import them from the support modules under the new names, and test_stage12_coordination.py imports coordinate_report_impl from policyengine_simulation_executor.stage12_runtime directly.

Tests

  • 1,895 tests are collected before and after. Every test keeps its name and body apart from the renamed helpers, with one visible difference: pytest names two parametrized cases of test_installed_bundle_accepts_the_dataset_a_region_loads after the helper passed as their parameter, so [us-_bundle] and [state/ut-_bundle] are now [us-bundle_provenance] and [state/ut-bundle_provenance].
  • No patch changes: the tests patch the same source modules as before.

Environment variables

None: only test files change.

Testing

  • Executor, full suite: 1,873 passed, 22 skipped, as before; the Stage 12 tests (562) were run again on the final layout.
  • Ruff 0.15.22 format and lint: clean, including ruff format --check on the executor's tests.
  • python scripts/run_quality_guards.py and python -m scripts.rules guard --base-ref origin/file-length-split-stage12-coordination: passed; python -m scripts.rules render leaves no diff.
  • Pyright doesn't check test files (each package's include is src), and no source changes.

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 13:20
@anth-volk
anth-volk force-pushed the file-length-split-stage12-runtime-tests branch from b72ac3f to 9ff580d Compare October 27, 2026 13:45
@anth-volk
anth-volk force-pushed the file-length-split-stage12-runtime-tests branch 3 times, most recently from 751a192 to c15dab7 Compare October 27, 2026 16:17
Base automatically changed from file-length-split-stage12-coordination to main October 27, 2026 16:30
tests/test_stage12_runtime.py (4,709 lines) was over the file-length
limit for test code. Its tests move, unchanged, into thirteen files by
behaviour:

- test_stage12_runtime.py: loading a simulation's dataset and region
- test_stage12_dataset_provenance.py: the dataset a calculation loads
- test_stage12_single_worker.py, test_stage12_single_worker_failures.py
- test_stage12_aggregate_reports.py
- test_stage12_coordinator.py, test_stage12_coordinator_failures.py,
  test_stage12_coordinator_failure_records.py
- test_stage12_runtime_store_retries.py
- test_stage12_child_cancellation.py, test_stage12_child_state_errors.py
- test_stage12_wait_window.py

The helpers several files use move to three support modules:
stage12_runtime_support.py (inputs, records, runtimes and failure
checks), stage12_fake_stores.py (the in-memory stores) and
stage12_child_call_support.py (fake child calls and invokers). Their
private names are now public, under names that no test uses for a local
variable: for example _report is report_execution_input, _simulation is
simulation_execution_input, _context is invocation_context and _parent
is parent_record. The seven other Stage 12 test modules that imported
them from test_stage12_runtime.py now import them from the support
modules, and coordinate_report_impl from the package itself.

All 1,895 tests keep their names and bodies, apart from the renamed
helpers. Pytest names two parametrized cases of
test_installed_bundle_accepts_the_dataset_a_region_loads after the bundle
helper, so they are now [us-bundle_provenance] and
[state/ut-bundle_provenance].

The file-length baseline drops the file (count 8 to 7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk force-pushed the file-length-split-stage12-runtime-tests branch from c15dab7 to 587c559 Compare October 27, 2026 16:30
@anth-volk
anth-volk marked this pull request as ready for review October 27, 2026 16:52
@anth-volk
anth-volk requested a review from a team as a code owner October 27, 2026 16:52
@anth-volk
anth-volk merged commit 488a681 into main Oct 27, 2026
22 checks passed
@anth-volk
anth-volk deleted the file-length-split-stage12-runtime-tests branch October 27, 2026 16:52
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 Stage 12 runtime tests under the file-length limit

1 participant