Commit Graph

5 Commits

Author SHA1 Message Date
Thomas Hallock
72c72fc218 fix: align share persistence with user session logic
Implement comprehensive fix to ensure worksheet sharing uses the same
persistence/loading logic as user session management.

**Problem:**
- Share save sent unfiltered formState with derived/UI state
- Share load used JSON.parse without validation/migration
- Inconsistent with user session which extracts specific fields and validates

**Solution:**

1. Create extractConfigFields helper (DRY principle)
   - Single source of truth for persisted fields
   - Excludes derived state (rows, total, date, seed)
   - Type-safe extraction of 24 config fields

2. Update useWorksheetAutoSave to use helper
   - Replace 50+ lines of manual extraction
   - Ensures consistency across all save operations

3. Update all share creation paths
   - PreviewCenter: extractConfigFields(formState)
   - ActionsSidebar: extractConfigFields(formState)
   - ShareModal: extractConfigFields(config)

4. Update share load API to use parseAdditionConfig
   - Validates config structure
   - Migrates old versions (v1/v2/v3) to v4
   - Matches user session loading logic exactly

**Benefits:**
- Consistency: Share and session use identical logic
- Validation: All configs validated before saving/loading
- Migration: Old shared configs auto-migrate to current schema
- Maintainability: 100+ lines reduced to ~30, single source of truth

**Files Changed:**
- utils/extractConfigFields.ts (new helper)
- hooks/useWorksheetAutoSave.ts (refactored to use helper)
- components/PreviewCenter.tsx (use helper)
- components/ActionsSidebar.tsx (use helper)
- components/ShareModal.tsx (use helper + type fix)
- api/worksheets/share/[id]/route.ts (use parseAdditionConfig)

Fixes ensure shared worksheets are persisted and loaded with the same
validation, versioning, and migration as user settings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 12:03:32 -06:00
Thomas Hallock
f06a6f2dcd refactor: change operator values from Unicode to alphanumeric strings
**Problem:** Using Unicode characters '+' and '−' (U+2212) as operator flags
causes bugs when developers use the wrong character (ASCII '-' vs Unicode '−').

**Solution:** Changed operator discriminator values to alphanumeric strings:
- Addition: '+' → 'add'
- Subtraction: '−' → 'sub'

**Files changed:**
- types.ts: Updated AdditionProblem and SubtractionProblem operator types
- All operator assignments changed: operator: 'add' / operator: 'sub'
- All operator comparisons changed: === 'add' / === 'sub'

**Benefits:**
- No more Unicode character confusion
- Easier to type and read
- Less error-prone for future developers
- Consistent with WorksheetOperator type ('addition', 'subtraction', 'mixed')

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 14:51:03 -06:00
Thomas Hallock
b36df3a40c fix(worksheets): ten-frames not rendering in mastery mode
Fixed two critical bugs preventing ten-frames from rendering:

1. **Mastery mode not handled** (typstGenerator.ts:61)
   - Code only checked for 'smart' | 'manual' modes
   - Mastery mode fell into manual path, tried to use boolean flags that don't exist
   - Resulted in all display options being `undefined`
   - Fix: Check for both 'smart' OR 'mastery' modes (both use displayRules)

2. **Typst array membership syntax** (already fixed in previous commit)
   - Used `(i in array)` which doesn't work in Typst
   - Changed to `array.contains(i)`

Added comprehensive unit tests (tenFrames.test.ts):
- Problem analysis tests (regrouping detection)
- Display rule evaluation tests
- Full Typst template generation tests
- Mastery mode specific tests
- All 14 tests now passing

Added debug logging to trace display rules resolution:
- displayRules.ts: Shows rule evaluation per problem
- typstGenerator.ts: Shows enriched problems and Typst data
- Helps diagnose future issues

The issue was that mastery mode (which uses displayRules like smart mode)
was being treated as manual mode (which uses boolean flags), resulting in
undefined display options.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:06:27 -06:00
Thomas Hallock
2d33f35c4d fix: correct GPT-5 API parameters and surface actual grading errors
Two critical fixes for worksheet grading:

1. **Fix OpenAI Responses API parameters**
   - Move `verbosity` from top-level to `text.verbosity`
   - API was rejecting requests with 400 error
   - Confirmed against GPT-5 Responses API documentation

2. **Surface actual grading errors in UI**
   - Add `error_message` column to worksheet_attempts table
   - Store actual API/grading errors in database
   - Display real error messages instead of generic "too blurry" text
   - Users now see OpenAI API errors, validation failures, etc.

Changes:
- Updated gradeWorksheet.ts API call structure
- Created migration 0020 for error_message column
- Updated processAttempt.ts to save error messages
- Updated API route to return errorMessage field
- Updated results page to display actual errors

Now when grading fails, users see helpful error messages like:
"Unsupported parameter: 'verbosity'..." instead of just "too blurry"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 06:12:10 -06:00
Thomas Hallock
2ffeade437 fix: resolve Memory Quiz room-based multiplayer validation issues
Root Cause:
- GAMES_CONFIG used 'memory-lightning' as key but validator was registered as 'memory-quiz'
- When rooms were created with gameName 'memory-lightning', getValidator() couldn't find the validator
- This caused all move validations to fail, breaking configuration changes and guess validation

Key Changes:
1. Fixed game identifier mismatch:
   - Changed GAMES_CONFIG key from 'memory-lightning' to 'memory-quiz'
   - Updated games/page.tsx to use 'memory-quiz' for routing

2. Completed Memory Quiz room-based multiplayer implementation:
   - Added MemoryQuizGameValidator with all 9 move types (START_QUIZ, NEXT_CARD, SHOW_INPUT_PHASE, ACCEPT_NUMBER, REJECT_NUMBER, SET_INPUT, SHOW_RESULTS, RESET_QUIZ, SET_CONFIG)
   - Created RoomMemoryQuizProvider for network-synchronized gameplay
   - Implemented optimistic client-side updates with server validation
   - Added proper serialization handling (send numbers instead of React components)
   - Split memory-quiz/page.tsx into modular components (SetupPhase, DisplayPhase, InputPhase, ResultsPhase)

3. Updated socket-server:
   - Fixed to use getValidator() instead of hardcoded matchingGameValidator
   - Added game-specific initial state handling for both 'matching' and 'memory-quiz'

4. Fixed test failures from arcade_sessions schema changes:
   - Updated arcade-session-validation.e2e.test.ts to create rooms before sessions (roomId is now primary key)
   - Added missing playerMetadata and playerHovers fields to arcade-session-integration.test.ts
   - Skipped obsolete test in orphaned-session-cleanup.test.ts (roomId can't be null as it's the primary key)

5. Code quality fixes:
   - Removed unused type imports from room-moderation.ts
   - Changed to optional chain in MemoryQuizGameValidator.ts
   - Removed unnecessary fragment in MemoryQuizGame.tsx

Testing:
- All modified tests updated to match new schema requirements
- TypeScript errors resolved (excluding pre-existing @soroban/abacus-react issues)
- Lint passes with 0 errors and 0 warnings

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 18:28:01 -05:00