Skip to content

Split the report output service under the file-length limit - #4066

Merged
anth-volk merged 1 commit into
masterfrom
file-length-split-report-output
Oct 27, 2026
Merged

anth-volk merged 1 commit into
masterfrom
file-length-split-report-output

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #4065

This fixes the failing file-length check on master, which fails the "Quality guards" job on every open pull request. #4044 grew report_output_service.py from 792 to 805 lines, and #4054 then added the 800-line api.quality.file-length rule on a CI run from before #4044 merged: the branch rules don't require pull requests to be up to date with master, so neither CI run saw both changes. This pull request is based on master and is not part of stack #4057. It doesn't add the file to the rule's baseline.

What moves where

Module Lines Holds
services/report_output_service.py 805 → 443 The SPM output checks, InvalidReportOutputIdError, ReportOutputView, ReportCreateResult, and ReportOutputService: its constructor and sessions, finding, creating and resolving report outputs, create_or_reuse_report_output, resolve_report_output, update_report_output
services/report_output_runs.py (new) 379 ReportOutputRunHistoryMixin: the 15 methods that keep a report's run history, report spec and version manifest in step with the report (_ensure_report_output_dual_write_state and its helpers), and format_run_timestamp

ReportOutputService now inherits ReportOutputRunHistoryMixin. No method name is defined in both, so every method resolves to the same code, including ReportOutputService.format_run_timestamp, which the routes call. Every public name the module defined is still defined there.

No names were renamed. No patch target changes: no test patches a name in report_output_service; the tests patch the route's service instance (report_output_routes.report_output_service) or methods on a service object, which resolve as before. To check, a pytest plugin recorded every patch and monkeypatch.setattr in each test, the function that made it, and the calls its fake received, before and after, over the report-output service, route, contract and boundary tests: outcomes and call counts are identical for all 518 tests.

Not a pure move

The two boundary tests that read report_output_service.py by path now also read the new module:

  • tests/unit/services/test_orchestration_service_database_boundaries.py::test_orchestration_services_do_not_access_database_connections (api.services.no-direct-queries): report_output_runs.py is added to its module_name parameters; the test body is unchanged.
  • tests/unit/data/test_runtime_sql_boundaries.py::test_report_orchestration_uses_sessions_and_models_not_raw_sql is unchanged; a new test, test_report_run_history_uses_sessions_and_models_not_raw_sql, makes the same assertions on report_output_runs.py and is registered on the same rule, api.data.runtime-sql-confined.

Testing

  • An AST comparison of the original and new modules: all 35 classes, functions and methods are present once and identical.
  • pytest over the report-output service, route, contract and boundary tests (tests/unit/services/test_report_output_service.py, test_report_service_owned_sessions.py, test_service_owned_session_architecture.py, tests/unit/test_simulation_and_report_routes.py, tests/unit/v2/test_report_v1_runtime_selection.py, tests/unit/routes, tests/contract/test_v1_route_contracts.py, and both boundary test files): 518 passed on master, 520 on this branch (the new test and the new parameter).
  • python scripts/run_quality_guards.py: all guards pass, including file-length, which fails on master.
  • The same guards on this branch merged with the head of Split the economy service and its tests under the file-length limit #4056 (origin/file-length-economy-service): all pass, and the registry merges without conflicts.
  • python -m scripts.rules guard --base-ref origin/master: pass; python -m scripts.rules render: no changes; python -m unittest discover -s scripts/rules/tests -t .: 142 pass.
  • ruff format --check ., ruff check .: pass.
  • uv lock --check: pass.
  • # noqa comments: 94 before and after; type: ignore/pyright: ignore: 9 before and after.

Environment variables

None changed. No workflow, image or deployment file changed, and the moved code reads no environment variable.

🤖 Generated with Claude Code

report_output_service.py grew to 805 lines on master, one over the
api.quality.file-length limit, so the file-length check fails there. Its
run-history methods, which keep each report's run records, spec and
version manifest in step with the report, move unchanged to a
ReportOutputRunHistoryMixin in report_output_runs.py.
ReportOutputService inherits them, so every method resolves to the same
code, and the module's public names are unchanged.

The runtime SQL and orchestration boundary tests now also read the new
module, as they read report_output_service.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.32298% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.82%. Comparing base (e5de69e) to head (e6c3eab).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
policyengine_api/services/report_output_runs.py 67.92% 31 Missing and 20 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4066       +/-   ##
===========================================
+ Coverage   50.94%   87.82%   +36.88%     
===========================================
  Files         242      259       +17     
  Lines       14531    15961     +1430     
  Branches     2335     2622      +287     
===========================================
+ Hits         7403    14018     +6615     
+ Misses       6505     1278     -5227     
- Partials      623      665       +42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anth-volk
anth-volk marked this pull request as ready for review October 27, 2026 14:46
@anth-volk
anth-volk requested a review from a team as a code owner October 27, 2026 14:46
@anth-volk
anth-volk merged commit c8e3328 into master Oct 27, 2026
15 checks passed
@anth-volk
anth-volk deleted the file-length-split-report-output branch October 27, 2026 14:47

This branch was previously deployed

1 inactive deployment
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 report output service under the file-length limit

1 participant