Skip to content

Conversation

@offendingcommit
Copy link
Owner

Summary

This PR completes the implementation of server-side state persistence for the Bingo application, replacing the unreliable client-side app.storage.general with a robust StateManager that persists to game_state.json.

This fixes #13 - App restarts lose game state.

Background

The app was previously using NiceGUI's app.storage.general which is just a wrapper around browser localStorage. This caused several issues:

  • State was lost on server restarts
  • Each browser had its own separate state
  • No persistence across hot reloads during development
  • Race conditions with concurrent users

Solution Implemented

1. StateManager Pattern (src/core/state_manager.py)

  • Server-side file persistence to game_state.json
  • Atomic file writes using temp file + rename pattern
  • Thread-safe with asyncio locks
  • Debounced saves (100ms) for performance
  • Graceful corruption recovery
  • 96% test coverage

2. Enhanced Testing Infrastructure

  • Added 79 new unit tests across 4 test suites
  • Implemented pytest markers for test categorization
  • Created progressive test targets (unit → integration → e2e)
  • Optimized CI pipeline from 2+ minutes to ~7 seconds

3. CI/CD Improvements

  • Excluded slow/flaky tests from CI while keeping them for local runs
  • Added proper test markers (@pytest.mark.unit, @pytest.mark.slow, etc.)
  • Fixed import sorting issues with isort
  • Enhanced Makefile with multiple test targets

Changes Overview

  • 6,824 additions, 269 deletions across 49 files
  • Core implementation in src/core/state_manager.py
  • Updated app.py and game_logic.py to use StateManager
  • Comprehensive test suites for all components
  • Documentation updates in CLAUDE.md
  • Added game_state.json to .gitignore

Test Results

✅ 165 total tests
✅ 139 reliable tests run in CI (~7 seconds)
✅ 96% coverage for StateManager
✅ All unit tests pass in <100ms each

Key Features

  1. Backward Compatibility: Existing game logic continues to work
  2. Hot Reload Support: State persists across development reloads
  3. Concurrent Access: Thread-safe operations with proper locking
  4. Error Recovery: Handles corrupted/missing state files gracefully
  5. Performance: Debounced saves prevent excessive I/O

Breaking Changes

None - the implementation maintains full backward compatibility.

Checklist

  • Tests pass locally
  • Code follows project style guidelines (black, isort)
  • Documentation updated
  • No breaking changes
  • CI pipeline optimized

- Add game_state.json to gitignore for state persistence
- Update CLAUDE.md with memory management protocols
- Fix hot reload integration test indentation error
@offendingcommit offendingcommit merged commit c331f20 into main Jun 26, 2025
5 checks passed
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.

Fix: App restarts lose game state

2 participants