Skip to content

Restore in-progress books#69

Merged
vitofico merged 12 commits into
mainfrom
restore-in-progress-books
May 30, 2026
Merged

Restore in-progress books#69
vitofico merged 12 commits into
mainfrom
restore-in-progress-books

Conversation

@vitofico

Copy link
Copy Markdown
Owner

Summary

Phase 0–1 of the refactoring study (docs/refactoring-study.md) — the safe, no-behavioral-change slice. The goal of this PR is to fix the one concrete crash bug, lay a test safety net over the previously-untested data-access layer, and land low-risk hygiene/dedup, without changing any runtime/IO/exit/logging contract. The riskier behavioral items are deliberately deferred (see below) because this was executed unattended and they need human sign-off.

Scope was reviewed by an external model (plan review) which recommended exactly this conservative partition for an unattended run.

What's in this PR

# Change Risk
0.1 Add pytest-cov (dev dep + [tool.coverage] + CI --cov reporting). No --cov-fail-under gate. none
0.2/0.3 tests/conftest.py + characterization tests pinning current APIClient behavior (URL handling, success path, and the existing error-swallowing/dummy-token behavior) none (tests only)
1.1 Bug fix: add params= kwarg to APIClient.get. API.get_device_data/get_weather_data already call client.get(path, params=...), which raised TypeError on every device-data/weather fetch. Covered by new regression tests. low
1.4 Replace 3 production asserts (measured.py, pipeline.py) with explicit raise guards — assert is stripped under python -O and violates the repo's own ast-grep rule. Behavior-equivalent under normal execution. low
1.5 Bump requests 2.31.0 → >=2.32.4 (CVE-2024-35195, CVE-2024-47081); drop redundant matplotlib/weasyprint from the dev group. low
1.7 Extract the byte-identical _quarter_label (duplicated in pipeline.py and bundle.py) into a single config.quarter_label. low

Verification

  • uv run pytest161 passed, 2 deselected (was 150; +11 new tests, no regressions).
  • uv run pre-commit run --all-files → ruff check, ruff format, and ast-grep all pass.
  • Coverage now reported in CI (was 0% on src/api; src/utils/data_joiner.py and timeseries_generator.py remain ~0–2% — see deferred work).

Deliberately deferred — needs human sign-off

These were identified and intentionally NOT done because they change runtime behavior in zero-coverage areas where production env/consumer assumptions can't be verified unattended. Each is documented in docs/refactoring-study.md:

  • 2.2 Honest IO — make authenticate()/get() raise instead of returning a dummy token / {"data": []}. ~20 consumers assume a dict and never catch; no mid-run degrade path exists today. The characterization tests in this PR pin the current behavior precisely so this change can be made safely as a reviewed follow-up.
  • 2.1 Config consolidation — collapsing config.py/dps_config.py switches DPS credentials from ''admin/password; committed Argo manifests don't inject API_USERNAME/API_PASSWORD, so DPS may currently run silently offline. Needs prod-env confirmation.
  • 2.5 Exit/error contract & 1.2 false-success exits — some empty-DataFrame returns are legitimately "no data", others mask failures; misclassifying breaks pvbq's relaxed-completeness handling and changes exit codes CI/Argo depend on.
  • 1.3 DPS type=bool flag — fix requires editing live Argo CronWorkflow manifests in lockstep.
  • 1.6 RUF013 + --unsafe-fixes — repo-wide implicit-Optional autofix is too much unreviewed annotation churn for an unattended run.
  • 1.8 / 1.9 / 2.3 / 2.4 — config/data-key dedup, logging rewiring, dead-code deletion (CatalogService, SiteReport, …), logging-bootstrap unification: each touches import-time timing, operational log/stdout contracts, or needs a repo-wide "is this really dead / imported-by-name?" audit.
  • Phase 3 (decomposing the 1700/1015/748-line functions): separate PRs once the safety net and seams are in place.

Reference

Full analysis, target architecture, and prioritized roadmap: docs/refactoring-study.md.

@vitofico
vitofico merged commit aaeda54 into main May 30, 2026
4 checks passed
@vitofico
vitofico deleted the restore-in-progress-books branch May 30, 2026 10:13
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.

1 participant