Skip to content

Cover the voyage stats in the Stats persistence tests - #223

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/stats-voyage-persistence-tests
Oct 12, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/stats-voyage-persistence-tests

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle targeting Stats and StatsJsonReaderWriter. Only test files are changed; no production code is touched.

  • The nine voyage/adventure lifetime totals (totalHaulingContracts, totalTransportRuns, totalRaids, totalPlunder, totalMoneyFromVoyages, crewLostToPiracy, boatsOwned, totalVoyagesCaptained, totalVoyagesFoundered) were written and read by src/stats/statsJsonReaderWriter.py but were not mentioned by any test. A round-trip test (distinct per-field values, float money values, schema-validated) and a legacy-save test (fields deleted → load as 0, other fields kept) are added.
  • Two drift guards are added: createJsonFromStats must write exactly the attributes of Stats() and exactly the properties of schemas/stats.json, and createStatsFromJson({}) must reproduce every Stats() default (the existing missing-fields test only checked the seven core fields).
  • tests/stats/test_stats.py previously asserted 10 of the 29 defaults; the remaining 19 are now asserted, plus a check that the earnedMilestones/unlockedFeatures lists are not shared between instances.

No tracking issue — the gap was found during triage (no issues were open at triage time, so no issues were deferred).

Test plan

  • python3 -m compileall -q src
  • Full suite with dummy SDL drivers (run in-process via pytest.main): 985 passed, 1 failed. The single failure, tests/test_saveFileManager.py::test_migrate_old_save_files_skips_a_slot_holding_any_file, reproduces identically on unchanged main in this environment and is caused by the locally installed editable tak differing from the requirements.txt pin; CI on main passes it.
  • CI Run Unit Tests green on the PR head

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

The nine voyage/adventure lifetime totals were written and read by
StatsJsonReaderWriter but never exercised by a test. Add a round trip
and a legacy-save default test for them, plus guards that the writer,
the schema and Stats() agree on the full field set and that an empty
save falls back to every default. Complete the Stats() defaults test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (diff: 2 test files, +127 lines, no production code):

  • Scope: PASS — only tests/stats/test_stats.py and tests/stats/test_statsJsonReaderWriter.py are modified; both are the mirrors of the Stats/StatsJsonReaderWriter target named in the PR.
  • Tests-new: PASS — no new public functions are introduced; six new tests are added.
  • Tests-fix: N/A — this is a characterization-only cycle with no bug fix; every new assertion matches current behavior (green locally and in CI).
  • Sibling structure: PASS — new tests follow the # prepare / # call / # check layout and reuse the existing createStats / createStatsJsonReaderWriter / getStatsSchema helpers; the legacy-save test mirrors test_save_without_exportStats_loads_with_zeroes.
  • Sibling renames: N/A — nothing renamed.
  • Docs: PASS — no behavior changed, so README, schemas/stats.json, and PLANNING.md need no update.
  • Issue resolution: N/A — no Closes #N; this is a triage-found gap, as stated in the PR body.
  • CI: PASS — Run Unit Tests green on the head, log reports 986 passed (980 on main + 6 new).
  • Schema-sync: PASS — no persisted field changed; the new test_createJsonFromStats_writesEveryStatsField now enforces writer == Stats() == schema properties.
  • Money-format: N/A — no display code touched.
  • Deterministic-tests: PASS — no randomness is involved in any new test.
  • Headless-pygame: N/A — no pygame code paths.
  • camelCase: PASS — new locals (readerWriter, voyageFields, legacyJson) are camelCase.

Judgment call flagged for a human reader:

  • tests/stats/test_statsJsonReaderWriter.py — test_createJsonFromStats_writesEveryStatsField asserts exact set equality with schemas/stats.json properties. That is deliberately strict: a schema property kept for a retired field (with no matching Stats attribute) would fail it. No such property exists today; if one is ever wanted, the assertion can be relaxed to a subset check.

Out-of-diff note: locally (not in CI), tests/test_saveFileManager.py::test_migrate_old_save_files_skips_a_slot_holding_any_file fails identically on unchanged main. The cause is the local editable tak differing from the requirements.txt pin; no signal for this diff.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 339cc08 into main Oct 12, 2026
1 check passed
@dmccoystephenson
dmccoystephenson deleted the feature/stats-voyage-persistence-tests branch October 12, 2026 07:40
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