fix: add seed and prngAlgorithm fields to all Zod schema versions (V1-V4)

**Problem**: Seeds were being saved to the database but lost when loading
because Zod schemas didn't include seed/prngAlgorithm fields. Zod strips
unknown fields during parsing, so even though extractConfigFields() included
the seed and the database had the seed, parseAdditionConfig() was removing it.

**Root Cause**: The migration from summary showed seed was being extracted and
saved, but server logs showed `hasSavedSeed: false, savedSeed: undefined`.
Database query confirmed seed WAS in the JSON (seed: 1977890241), but
migrateAdditionConfig() → additionConfigSchema.safeParse() was stripping it.

**Fix**: Added seed and prngAlgorithm as optional fields to ALL schema versions:
- V1: Added to additionConfigV1Schema
- V2: Added to additionConfigV2Schema
- V3: Added to additionConfigV3BaseSchema (inherited by Smart/Manual modes)
- V4: Added to additionConfigV4BaseSchema (inherited by Smart/Manual/Mastery modes)

**Impact**: Seeds will now persist correctly through the full save/load cycle.
Users can reload the page and see the exact same problems.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Thomas Hallock 2025-11-11 20:31:53 -06:00
parent 0f3ec369bf
commit 1782f427f1
1 changed files with 16 additions and 0 deletions

View File

@ -50,6 +50,10 @@ export const additionConfigV1Schema = z.object({
.int()
.min(WORKSHEET_LIMITS.FONT_SIZE.MIN)
.max(WORKSHEET_LIMITS.FONT_SIZE.MAX),
// Problem reproducibility (CRITICAL for sharing worksheets)
seed: z.number().int().min(0).optional(),
prngAlgorithm: z.string().optional(),
})
export type AdditionConfigV1 = z.infer<typeof additionConfigV1Schema>
@ -139,6 +143,10 @@ export const additionConfigV2Schema = z.object({
.min(WORKSHEET_LIMITS.FONT_SIZE.MIN)
.max(WORKSHEET_LIMITS.FONT_SIZE.MAX),
showTenFramesForAll: z.boolean(),
// Problem reproducibility (CRITICAL for sharing worksheets)
seed: z.number().int().min(0).optional(),
prngAlgorithm: z.string().optional(),
})
export type AdditionConfigV2 = z.infer<typeof additionConfigV2Schema>
@ -168,6 +176,10 @@ const additionConfigV3BaseSchema = z.object({
pAnyStart: z.number().min(0).max(1),
pAllStart: z.number().min(0).max(1),
interpolate: z.boolean(),
// Problem reproducibility (CRITICAL for sharing worksheets)
seed: z.number().int().min(0).optional(),
prngAlgorithm: z.string().optional(),
})
// Smart Difficulty Mode
@ -314,6 +326,10 @@ const additionConfigV4BaseSchema = z.object({
pAnyStart: z.number().min(0).max(1),
pAllStart: z.number().min(0).max(1),
interpolate: z.boolean(),
// Problem reproducibility (CRITICAL for sharing worksheets)
seed: z.number().int().min(0).optional(),
prngAlgorithm: z.string().optional(),
})
// Smart Difficulty Mode for V4