Skip to content

Small follow-ups from v4 audit#312

Open
MaxGhenis wants to merge 1 commit intomainfrom
small-follow-ups
Open

Small follow-ups from v4 audit#312
MaxGhenis wants to merge 1 commit intomainfrom
small-follow-ups

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

Three small quality-of-life items the v4 audit flagged:

1. Simulation.save() unhelpful error

Before: AttributeError: 'NoneType' object has no attribute 'save'
After: ValueError: Simulation.save() called with no output_dataset. Run simulation.run() or simulation.ensure() first so there is something to persist.

One-line fix in common/model_version.py.

2. scripts/check_data_staleness.py

~60 lines of Python. Prints one verdict line per country comparing the bundled release manifest's model_package.version against the installed country package. Exits non-zero when any country is stale so CI can gate on it. No network access; reads both sides locally via importlib.metadata + the bundled JSON.

Example output:

us: ok (policyengine-us 1.653.3 matches bundle pin)
uk: STALE (policyengine-uk installed=2.88.9, bundle pin=2.88.0; consider a release-bundle refresh)

Targeted fix for the "is our data stale?" pain flagged in #311. Doesn't require the larger storage-substrate design to ship.

3. Clarified load() docstring

The old docstring claimed save() + load() round-trip created_at / updated_at. They don't — save() doesn't persist them; load() reads filesystem ctime / mtime instead. Docstring now says so.

Tests

tests/test_small_follow_ups.py — 3 tests:

  • save() raises ValueError with "no output_dataset" in the message
  • check_data_staleness script emits one line per country
  • Direct check_country() test against a tmp manifest with a drifted pin

430/430 existing tests still pass.

🤖 Generated with Claude Code

Three things the audit flagged as small quality-of-life:

1. Simulation.save() raises a helpful ValueError when
   output_dataset is None rather than the raw AttributeError from
   None.save(). Names the missing step (run()/ensure()).

2. scripts/check_data_staleness.py — a ~60 line script that prints
   a one-line verdict per country comparing the bundled release
   manifest's model_package.version against the installed country
   package. Exits non-zero when any country is stale so CI can
   gate on it. No network access; reads both sides locally.

3. Clarified the load() docstring — the "created_at/updated_at
   round-trip" claim was misleading; these are filesystem
   ctime/mtime approximations because save() doesn't persist them.

Regression tests in tests/test_small_follow_ups.py:
- save() raises ValueError with "no output_dataset" in the
  message when output_dataset is None
- check_data_staleness script runs and emits one verdict line per
  configured country
- direct test of check_country() against a tmp manifest with a
  drifted pin, so we don't have to reinstall a country package
  to exercise the drift path

All 430 existing tests still pass.
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