Skip to content

Comments

Add infra for SGF/GIB snapshot tests#131

Merged
ale64bit merged 1 commit intoale64bit:mainfrom
benjaminpjones:gamerecord-snapshot-tests
Dec 31, 2025
Merged

Add infra for SGF/GIB snapshot tests#131
ale64bit merged 1 commit intoale64bit:mainfrom
benjaminpjones:gamerecord-snapshot-tests

Conversation

@benjaminpjones
Copy link
Contributor

There's some relevant discussion on #112 and #101, but I think there would be some benefit to snapshot tests for the file parsers. These scripts make it simple to add a file from one of the servers and commit its GameRecord representation.

This PR adds:

  • generate_snapshots.dart: used when adding new snapshots or updating the behavior of the parsers
  • game_record_snapshot_test.dart: snapshot tests that parse the files and compare to existing snapshots
  • Sample files from the 3 supported servers
  • Snapshots for those files

The README has more detail on what's here and how to re-generate snapshot tests.

@ernestasromeika
Copy link

Looks nice. I like the idea of utility tool to generate a snapshot of sgf file in a less troublesome and more readable format like json, and then comparing the parsed moves from sgf to it, but... if we regenerate those snapshots and they both (snapshot generator and tests) use the same GameRecord.fromSgf then it won't detect issues with move integrity, i.e. if GameRecord.fromSgf has an issue for missing first move then the json snapshot won't contain the first move either. So snapshots have to be manually checked (once) anyway.

I'm assuming this util doesn't run and regenerate snapshots on a build/test/run commands? only on "run test/game_record_snapshot_tests/generate_snapshots.dart"? I'm still pretty new to dart/flutter 🙂

@benjaminpjones
Copy link
Contributor Author

if we regenerate those snapshots and they both (snapshot generator and tests) use the same GameRecord.fromSgf then it won't detect issues with move integrity, i.e. if GameRecord.fromSgf has an issue for missing first move then the json snapshot won't contain the first move either. So snapshots have to be manually checked (once) anyway.

Right, the expectation is that fromSgf is working as-expected when the snapshots are generated. Though one doesn't necessarily need to inspect the snapshot files directly. I'm approaching it like:

  1. Inspect game record in the app
  2. Verify it matches my expectations
  3. Commit the output by saving the SGF in the fixtures dir and re-generating the snapshots

IMO snapshot tests are useful as a gut check to ensure something doesn't change unexpectedly. They aren't as good figuring out your impl meets functional requirements in the first place (traditional unit tests and manual testing are a better tool)

I'm assuming this util doesn't run and regenerate snapshots on a build/test/run commands? only on "run test/game_record_snapshot_tests/generate_snapshots.dart"?

Correct. flutter test will compare output to existing snapshots and notify you of mismatches, but it won't actually update the snapshots.

@ale64bit ale64bit merged commit 524f095 into ale64bit:main Dec 31, 2025
2 checks passed
@benjaminpjones benjaminpjones deleted the gamerecord-snapshot-tests branch December 31, 2025 14:34
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.

3 participants