Trim defensive internal invariant checks#92
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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#87made 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 -quv 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.pyuv run ty check backend tests/test_scoring.py tests/test_climate_repository.py tests/test_score_service.py tests/test_heatmap.pyCloses #91