fix: allow ANSWER_TIMER-only question type definitions

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-06-19 03:55:37 -07:00
parent ef5858851a
commit c5347f5b6f
2 changed files with 15 additions and 37 deletions

View File

@ -90,11 +90,6 @@ var (
ResponseSequenceOrder, ResponseSequenceOrder,
} }
responseSet map[string]struct{} responseSet map[string]struct{}
// responseKindsAuxiliary are allowed but cannot be the only selected answer kinds.
responseKindsAuxiliary = map[string]struct{}{
string(ResponseAnswerTimer): {},
}
) )
func init() { func init() {
@ -194,10 +189,6 @@ func ValidateDynamicQuestionTypeDefinition(stimulusKinds, responseKinds []string
errs = append(errs, "response: at most one ANSWER_TIMER is allowed") errs = append(errs, "response: at most one ANSWER_TIMER is allowed")
} }
if len(response) > 0 && onlyAuxiliaryResponseKinds(response) {
errs = append(errs, "response: at least one non-timer answer component is required (ANSWER_TIMER alone is not sufficient)")
}
if len(errs) == 0 { if len(errs) == 0 {
return nil return nil
} }
@ -398,11 +389,7 @@ func ResolveRuntimeQuestionTypeFromDefinition(key string, responseKinds []string
return "DYNAMIC" return "DYNAMIC"
} }
hasNonAuxiliary := false
for _, kind := range response { for _, kind := range response {
if _, aux := responseKindsAuxiliary[kind]; !aux {
hasNonAuxiliary = true
}
switch kind { switch kind {
case string(ResponseAudioResponse): case string(ResponseAudioResponse):
return "AUDIO" return "AUDIO"
@ -418,12 +405,8 @@ func ResolveRuntimeQuestionTypeFromDefinition(key string, responseKinds []string
} }
} }
// Builder-native response kinds should still be persistable/executable as DYNAMIC. // Builder-native and auxiliary-only response kinds (e.g. ANSWER_TIMER) persist as DYNAMIC.
if hasNonAuxiliary { return "DYNAMIC"
return "DYNAMIC"
}
return ""
} }
// LegacyRuntimeTypesForDefinitionLookup returns legacy questions.question_type values that should // LegacyRuntimeTypesForDefinitionLookup returns legacy questions.question_type values that should
@ -602,18 +585,6 @@ func findDuplicates(kinds []string) []string {
return dups return dups
} }
func onlyAuxiliaryResponseKinds(response []string) bool {
if len(response) == 0 {
return false
}
for _, k := range response {
if _, aux := responseKindsAuxiliary[k]; !aux {
return false
}
}
return true
}
// stimulusTextKindsForQuestionText are checked in order when deriving question_text from dynamic_payload. // stimulusTextKindsForQuestionText are checked in order when deriving question_text from dynamic_payload.
var stimulusTextKindsForQuestionText = []string{ var stimulusTextKindsForQuestionText = []string{
string(StimulusQuestionText), string(StimulusQuestionText),

View File

@ -81,8 +81,8 @@ func TestValidateDynamicQuestionTypeDefinition_timerOnlyResponse(t *testing.T) {
[]string{"TEXT_PASSAGE"}, []string{"TEXT_PASSAGE"},
[]string{"ANSWER_TIMER"}, []string{"ANSWER_TIMER"},
) )
if err == nil || !strings.Contains(err.Error(), "ANSWER_TIMER alone") { if err != nil {
t.Fatalf("expected auxiliary-only error, got %v", err) t.Fatalf("expected timer-only response definition to be valid, got %v", err)
} }
} }
@ -124,10 +124,17 @@ func TestResolveRuntimeQuestionTypeFromDefinition_builderNativeKinds(t *testing.
} }
} }
func TestValidatePersistableQuestionTypeDefinition_unmappable(t *testing.T) { func TestValidatePersistableQuestionTypeDefinition_timerOnly(t *testing.T) {
err := ValidatePersistableQuestionTypeDefinition("custom", []string{"ANSWER_TIMER"}) err := ValidatePersistableQuestionTypeDefinition("timed_only", []string{"ANSWER_TIMER"})
if err == nil || !strings.Contains(err.Error(), "unable to map definition") { if err != nil {
t.Fatalf("expected unmappable definition error, got %v", err) t.Fatalf("expected timer-only definition to be persistable, got %v", err)
}
}
func TestResolveRuntimeQuestionTypeFromDefinition_timerOnly(t *testing.T) {
got := ResolveRuntimeQuestionTypeFromDefinition("timed_only", []string{"ANSWER_TIMER"})
if got != "DYNAMIC" {
t.Fatalf("expected DYNAMIC for timer-only definition, got %q", got)
} }
} }