Skip to content

Trim defensive internal invariant checks#92

Merged
adrunkhuman merged 3 commits into
masterfrom
issue-91-audit-internal-invariants
Apr 24, 2026
Merged

Trim defensive internal invariant checks#92
adrunkhuman merged 3 commits into
masterfrom
issue-91-audit-internal-invariants

Conversation

@adrunkhuman
Copy link
Copy Markdown
Owner

@adrunkhuman adrunkhuman commented Apr 23, 2026

Summary

  • remove low-value defensive checks from internal scoring and city-ranking runtime objects that are constructed only by our own code
  • drop tests that intentionally corrupt those internal objects only to assert a specific validation exception
  • remove stub-repository fixture tests that only proved returned objects had expected Python classes
  • keep real validation at trust boundaries such as HTTP input, DuckDB reads, build-time database validation, and environment parsing

Why

This started from #91, but the useful cleanup is not an exception-class swap. The problem was that some tests and constructors treated programmer-controlled runtime objects as if they were hostile input. That added noise, froze implementation details, and made internal corruption paths look like supported behavior.

The cache/vectorization work in #39, #65, and #87 made these internal models more alignment-sensitive, so defensive guards were understandable while those paths stabilized. At this point the construction sites are narrow enough that normal NumPy/Python failures are sufficient if our own code corrupts an object. Boundary validation remains intact where malformed external data can actually enter.

I also did a broader pass for the same pattern. The remaining obvious brittle area is tests/test_app_shell.py, which over-specifies rendered markup and static script details. That is real, but it is a separate frontend contract-test cleanup rather than part of this internal runtime object audit.

Testing

  • uv run pytest tests/test_scoring.py tests/test_climate_repository.py tests/test_score_service.py tests/test_heatmap.py -q
  • uv run ruff check backend/scoring.py backend/cities.py backend/heatmap.py backend/climate_repository.py tests/test_scoring.py tests/test_climate_repository.py tests/test_score_service.py tests/test_heatmap.py
  • uv run ty check backend tests/test_scoring.py tests/test_climate_repository.py tests/test_score_service.py tests/test_heatmap.py

Closes #91

@adrunkhuman adrunkhuman changed the title Audit internal invariant failures in runtime models Trim defensive internal invariant checks Apr 24, 2026
@adrunkhuman adrunkhuman merged commit 0d0a6f4 into master Apr 24, 2026
1 check passed
@adrunkhuman adrunkhuman deleted the issue-91-audit-internal-invariants branch April 24, 2026 13:22
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.

Audit internal invariant checks and fallback paths

1 participant