refactor: type game availability state

Game::availability used string labels that were carried through persisted
library data, protocol summaries, and the Tauri-facing game payload. That
allowed invalid states to exist and required legacy summary conversion code to
defensively map strings back into protocol availability values.

Move Availability to lanspread-db and re-export it from lanspread-proto so the
persisted Game type and wire GameSummary type share one serde enum. The JSON
spelling stays Ready, Downloading, or LocalOnly, so the serialized shape does
not change for current library indexes or peer payloads.

Add typed helpers for sentinel-derived download state. Game::set_downloaded
keeps downloaded and Ready/LocalOnly in lockstep and intentionally collapses
non-ready local state, including Downloading, back to LocalOnly. That matches
the current local-summary contract where active operations are suppressed
instead of advertised as Downloading. Game::normalized_availability keeps the
legacy Game-to-summary path from publishing an inconsistent Ready value when
downloaded is false.

Update the follow-up status note so typed availability is no longer listed as
open work.

Test Plan:
- just fmt
- just test
- just clippy
- just build

Refs: none
This commit is contained in:
2026-05-16 11:49:01 +02:00
parent fdad162240
commit be196f9e4b
8 changed files with 128 additions and 93 deletions
+3 -4
View File
@@ -37,15 +37,14 @@ The OperationGuard ordering fix in `handlers.rs` is the structurally most import
missing-sentinel, and local-path cases.
- TempDir test helper: peer tests now share `test_support::TempDir` instead of
carrying per-module copies.
- Typed availability: `lanspread-db::Game::availability` now uses the shared
serde enum, with `lanspread-proto` re-exporting it for wire summaries. The
JSON spelling stays `"Ready" | "Downloading" | "LocalOnly"`.
## Still open
### Code hygiene
#### 9. `availability` field is `String`, not a typed enum
`lanspread-db::Game::availability: String` with `AVAILABILITY_*` consts works but allows invalid values. `remote_peer::summary_from_game` already has a defensive fallback for unknown strings. A typed enum + serde would be tighter, but is a wire-format change — coordinate if/when other peers are upgraded.
#### 10. `save_library_index` non-atomic
`local_games.rs:141-148` writes without temp+rename. Corrupt index → next scan rebuilds, so blast radius is small. Match the intent-log atomic pattern if touching that module.