fix: add 'auto' to RuleMode type to prevent undefined display values

The 'auto' display rule value was added to config schemas but not to the
RuleMode type definition, causing evaluateRule to return undefined when
encountering 'auto' values that weren't properly resolved.

Changes:
- Add 'auto' to RuleMode type definition
- Add 'auto' case in evaluateRule that logs error and defaults to 'always'
- Prevents 'undefined' from reaching Typst generator

This is a defensive fix - 'auto' should be resolved in validation.ts
before reaching the display rule evaluator, but this prevents crashes
if resolution fails for any reason.

🤖 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-18 07:24:04 -06:00
parent b62db5a323
commit a8636ca6a2
1 changed files with 9 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import type { ProblemMeta, SubtractionProblemMeta } from './problemAnalysis'
export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta
export type RuleMode =
| 'auto' // Defer to mastery progression (should be resolved before rendering)
| 'always' // Always show this display option
| 'never' // Never show this display option
| 'whenRegrouping' // Show when problem requires any regrouping
@ -39,6 +40,14 @@ export interface ResolvedDisplayOptions {
*/
export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean {
switch (mode) {
case 'auto':
// 'auto' should have been resolved to a concrete value in validation
// If it reaches here, something went wrong - default to 'always' to avoid breaking
console.error(
'[evaluateRule] BUG: "auto" mode should have been resolved before rendering. Defaulting to "always".'
)
return true
case 'always':
return true