feat: evolution track seed data and tests (WP-03) (#68) #83

Merged
cal merged 1 commits from ai/paper-dynasty-database#68 into next-release 2026-03-16 16:12:20 +00:00
Collaborator

Closes #68

Summary

Creates the three universal evolution tracks as a locked seed data fixture.

  • app/seed/evolution_tracks.json — locked JSON with 3 track rows (Batter, Starting Pitcher, Relief Pitcher)
  • app/seed/evolution_tracks.pyload_tracks() + seed(model_class=None) using get_or_create; lazy-imports EvolutionTrack from db_engine (WP-01 dependency)
  • tests/test_evolution_seed.py — 5 unit tests (JSON fixture only, no DB) + 1 integration test (in-memory SQLite stub model)
  • tests/__init__.py — package marker

Test results

6 passed in 0.04s

All tests from the issue checklist covered:

  • 3 tracks in seed data ✓
  • card_types exactly {batter, sp, rp} ✓
  • all thresholds positive and ascending ✓
  • all tracks have non-empty formula ✓
  • tier thresholds match locked values ✓
  • idempotent seed (get_or_create) ✓

Notes

The integration test defines a minimal EvolutionTrackStub Peewee model bound to in-memory SQLite so the test suite can run before WP-01 (EvolutionTrack model) is merged. Once WP-01 lands, seed() with no arguments will use app.db_engine.EvolutionTrack directly.

Closes #68 ## Summary Creates the three universal evolution tracks as a locked seed data fixture. - `app/seed/evolution_tracks.json` — locked JSON with 3 track rows (Batter, Starting Pitcher, Relief Pitcher) - `app/seed/evolution_tracks.py` — `load_tracks()` + `seed(model_class=None)` using `get_or_create`; lazy-imports `EvolutionTrack` from `db_engine` (WP-01 dependency) - `tests/test_evolution_seed.py` — 5 unit tests (JSON fixture only, no DB) + 1 integration test (in-memory SQLite stub model) - `tests/__init__.py` — package marker ## Test results ``` 6 passed in 0.04s ``` All tests from the issue checklist covered: - 3 tracks in seed data ✓ - card_types exactly {batter, sp, rp} ✓ - all thresholds positive and ascending ✓ - all tracks have non-empty formula ✓ - tier thresholds match locked values ✓ - idempotent seed (get_or_create) ✓ ## Notes The integration test defines a minimal `EvolutionTrackStub` Peewee model bound to in-memory SQLite so the test suite can run before WP-01 (EvolutionTrack model) is merged. Once WP-01 lands, `seed()` with no arguments will use `app.db_engine.EvolutionTrack` directly.
Claude added 1 commit 2026-03-12 22:35:31 +00:00
Closes #68

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude added the
ai-reviewing
label 2026-03-12 22:45:47 +00:00
Author
Collaborator

AI Code Review

Files Reviewed

  • app/seed/__init__.py (added — empty package marker)
  • app/seed/evolution_tracks.json (added)
  • app/seed/evolution_tracks.py (added)
  • tests/__init__.py (added — empty package marker)
  • tests/test_evolution_seed.py (added)

Findings

Correctness

  • Threshold values verified: all three tracks have t1 < t2 < t3 < t4, all positive. Batter (37/149/448/896), SP (10/40/120/240), RP (3/12/35/70). ✓
  • get_or_create(card_type=..., defaults=track) is correct. The defaults dict includes card_type (a duplicate of the lookup key) — Peewee ignores the duplicate in defaults during create and uses the kwarg value, so this is harmless. Works as intended.
  • Lazy import from app.db_engine import EvolutionTrack correctly defers the WP-01 dependency. Confirmed EvolutionTrack is not yet in db_engine.py, so seed() without model_class will fail until WP-01 merges — expected and documented.
  • Integration test idempotency check is correct: first call asserts all created=True, second call asserts all created=False, final row count is 3. ✓

Edge Cases

  • load_tracks() will raise FileNotFoundError / json.JSONDecodeError on fixture file issues — appropriate loud failure for a deployment error.
  • _test_db.connect(reuse_if_open=True) + drop_tables after each test correctly isolates tests while keeping the in-memory connection alive across the suite.

Security

  • No issues. All data sourced from a locked JSON fixture (no user input). No credential exposure. Peewee ORM handles parameterization. Formula strings are stored as data, not evaluated here.

Style & Conventions

  • Test docstrings follow CLAUDE.md convention (explain "what" and "why"). ✓
  • # noqa: PLC0415 on the mid-function import is correct and appropriate.
  • No scope creep — 5 new files, zero modifications to existing files.

Suggestions

  • autouse=True applies DB fixture to all 6 tests: The 5 pure JSON unit tests don't touch the database, but they still get _db's connect/create/drop cycle on every run. Not a bug, but adds minor overhead. Consider scoping the DB fixture to the integration test only (e.g., apply the fixture directly on test_seed_is_idempotent instead of autouse=True). Low priority.
  • Redundant card_type in defaults: defaults=track passes card_type both as the lookup key and inside the defaults dict. Functionally harmless, but defaults={k: v for k, v in track.items() if k != "card_type"} would be semantically cleaner. Low priority.

Verdict: APPROVED

Clean, focused implementation. Scope exactly matches the PR description. All 6 test cases cover the issue checklist. No correctness bugs, no security issues. Dependency on WP-01 is correctly deferred with a lazy import and well-documented stub for the integration test.


Automated review by Claude PR Reviewer (posted as comment — Gitea self-review restriction)

## AI Code Review ### Files Reviewed - `app/seed/__init__.py` (added — empty package marker) - `app/seed/evolution_tracks.json` (added) - `app/seed/evolution_tracks.py` (added) - `tests/__init__.py` (added — empty package marker) - `tests/test_evolution_seed.py` (added) ### Findings #### Correctness - Threshold values verified: all three tracks have `t1 < t2 < t3 < t4`, all positive. Batter (37/149/448/896), SP (10/40/120/240), RP (3/12/35/70). ✓ - `get_or_create(card_type=..., defaults=track)` is correct. The `defaults` dict includes `card_type` (a duplicate of the lookup key) — Peewee ignores the duplicate in `defaults` during create and uses the kwarg value, so this is harmless. Works as intended. - Lazy import `from app.db_engine import EvolutionTrack` correctly defers the WP-01 dependency. Confirmed `EvolutionTrack` is not yet in `db_engine.py`, so `seed()` without `model_class` will fail until WP-01 merges — expected and documented. - Integration test idempotency check is correct: first call asserts all `created=True`, second call asserts all `created=False`, final row count is 3. ✓ #### Edge Cases - `load_tracks()` will raise `FileNotFoundError` / `json.JSONDecodeError` on fixture file issues — appropriate loud failure for a deployment error. - `_test_db.connect(reuse_if_open=True)` + `drop_tables` after each test correctly isolates tests while keeping the in-memory connection alive across the suite. #### Security - No issues. All data sourced from a locked JSON fixture (no user input). No credential exposure. Peewee ORM handles parameterization. Formula strings are stored as data, not evaluated here. #### Style & Conventions - Test docstrings follow CLAUDE.md convention (explain "what" and "why"). ✓ - `# noqa: PLC0415` on the mid-function import is correct and appropriate. - No scope creep — 5 new files, zero modifications to existing files. #### Suggestions - **`autouse=True` applies DB fixture to all 6 tests**: The 5 pure JSON unit tests don't touch the database, but they still get `_db`'s connect/create/drop cycle on every run. Not a bug, but adds minor overhead. Consider scoping the DB fixture to the integration test only (e.g., apply the fixture directly on `test_seed_is_idempotent` instead of `autouse=True`). Low priority. - **Redundant `card_type` in `defaults`**: `defaults=track` passes `card_type` both as the lookup key and inside the defaults dict. Functionally harmless, but `defaults={k: v for k, v in track.items() if k != "card_type"}` would be semantically cleaner. Low priority. ### Verdict: APPROVED Clean, focused implementation. Scope exactly matches the PR description. All 6 test cases cover the issue checklist. No correctness bugs, no security issues. Dependency on WP-01 is correctly deferred with a lazy import and well-documented stub for the integration test. --- *Automated review by Claude PR Reviewer (posted as comment — Gitea self-review restriction)*
Claude added
ai-reviewed
and removed
ai-reviewing
labels 2026-03-12 22:48:32 +00:00
cal merged commit 223743d89f into next-release 2026-03-16 16:12:20 +00:00
cal deleted branch ai/paper-dynasty-database#68 2026-03-16 16:12:20 +00:00
Sign in to join this conversation.
No description provided.