@@ -59,7 +59,8 @@ const containsKeyInfo = (text: string, keyInfo: string): boolean => {
5959const validateAnswerConsistency = ( exercise : ExerciseContent ) : boolean => {
6060 const { correctAnswer, options, relevantText } = exercise ;
6161
62- if ( ! correctAnswer || ! options [ correctAnswer as keyof typeof options ] ) {
62+ // correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
63+ if ( ! options [ correctAnswer as keyof typeof options ] ) {
6364 return false ;
6465 }
6566
@@ -72,7 +73,7 @@ const validateAnswerConsistency = (exercise: ExerciseContent): boolean => {
7273const validateExplanationConsistency = ( exercise : ExerciseContent ) : boolean => {
7374 const { correctAnswer, allExplanations, options } = exercise ;
7475
75- if ( ! correctAnswer ) return false ;
76+ // correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
7677
7778 const correctAnswerText = options [ correctAnswer as keyof typeof options ] ;
7879 const correctExplanation = allExplanations [ correctAnswer as keyof typeof allExplanations ] ;
@@ -107,7 +108,8 @@ const validateQuestionAnswerCoherence = (exercise: ExerciseContent): boolean =>
107108const validateSemanticAnswerValidation = ( exercise : ExerciseContent ) : boolean => {
108109 const { correctAnswer, options, relevantText, paragraph } = exercise ;
109110
110- if ( ! correctAnswer || ! options [ correctAnswer as keyof typeof options ] ) {
111+ // correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
112+ if ( ! options [ correctAnswer as keyof typeof options ] ) {
111113 return false ;
112114 }
113115
@@ -136,8 +138,7 @@ export const validateQuestionQuality = (
136138 ) ,
137139 optionsLength : Object . values ( exercise . options ) . map ( ( opt ) => opt . length ) ,
138140 relevantTextLength : exercise . relevantText . length ,
139- hasCorrectAnswer :
140- ! ! exercise . correctAnswer && [ 'A' , 'B' , 'C' , 'D' ] . includes ( exercise . correctAnswer ) ,
141+ hasCorrectAnswer : [ 'A' , 'B' , 'C' , 'D' ] . includes ( exercise . correctAnswer ) ,
141142 allExplanationsPresent :
142143 Object . keys ( exercise . allExplanations ) . length === 4 &&
143144 Object . values ( exercise . allExplanations ) . every ( ( exp ) => exp . length > 0 ) ,
@@ -255,10 +256,8 @@ export const debugValidationFailure = (exercise: ExerciseContent, reason: string
255256 } ) ;
256257
257258 // Show what the correct answer should be based on the text
258- if (
259- exercise . correctAnswer &&
260- exercise . options [ exercise . correctAnswer as keyof typeof exercise . options ]
261- ) {
259+ // correctAnswer is guaranteed to be one of ['A', 'B', 'C', 'D'] by schema
260+ if ( exercise . options [ exercise . correctAnswer as keyof typeof exercise . options ] ) {
262261 const correctAnswerText =
263262 exercise . options [ exercise . correctAnswer as keyof typeof exercise . options ] ;
264263 console . error ( `[ValidationDebug] Correct answer text: "${ correctAnswerText } "` ) ;
0 commit comments