fix: allow ANSWER_TIMER-only question type definitions
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ef5858851a
commit
c5347f5b6f
|
|
@ -90,11 +90,6 @@ var (
|
|||
ResponseSequenceOrder,
|
||||
}
|
||||
responseSet map[string]struct{}
|
||||
|
||||
// responseKindsAuxiliary are allowed but cannot be the only selected answer kinds.
|
||||
responseKindsAuxiliary = map[string]struct{}{
|
||||
string(ResponseAnswerTimer): {},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -194,10 +189,6 @@ func ValidateDynamicQuestionTypeDefinition(stimulusKinds, responseKinds []string
|
|||
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 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -398,11 +389,7 @@ func ResolveRuntimeQuestionTypeFromDefinition(key string, responseKinds []string
|
|||
return "DYNAMIC"
|
||||
}
|
||||
|
||||
hasNonAuxiliary := false
|
||||
for _, kind := range response {
|
||||
if _, aux := responseKindsAuxiliary[kind]; !aux {
|
||||
hasNonAuxiliary = true
|
||||
}
|
||||
switch kind {
|
||||
case string(ResponseAudioResponse):
|
||||
return "AUDIO"
|
||||
|
|
@ -418,12 +405,8 @@ func ResolveRuntimeQuestionTypeFromDefinition(key string, responseKinds []string
|
|||
}
|
||||
}
|
||||
|
||||
// Builder-native response kinds should still be persistable/executable as DYNAMIC.
|
||||
if hasNonAuxiliary {
|
||||
return "DYNAMIC"
|
||||
}
|
||||
|
||||
return ""
|
||||
// Builder-native and auxiliary-only response kinds (e.g. ANSWER_TIMER) persist as DYNAMIC.
|
||||
return "DYNAMIC"
|
||||
}
|
||||
|
||||
// LegacyRuntimeTypesForDefinitionLookup returns legacy questions.question_type values that should
|
||||
|
|
@ -602,18 +585,6 @@ func findDuplicates(kinds []string) []string {
|
|||
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.
|
||||
var stimulusTextKindsForQuestionText = []string{
|
||||
string(StimulusQuestionText),
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ func TestValidateDynamicQuestionTypeDefinition_timerOnlyResponse(t *testing.T) {
|
|||
[]string{"TEXT_PASSAGE"},
|
||||
[]string{"ANSWER_TIMER"},
|
||||
)
|
||||
if err == nil || !strings.Contains(err.Error(), "ANSWER_TIMER alone") {
|
||||
t.Fatalf("expected auxiliary-only error, got %v", err)
|
||||
if err != nil {
|
||||
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) {
|
||||
err := ValidatePersistableQuestionTypeDefinition("custom", []string{"ANSWER_TIMER"})
|
||||
if err == nil || !strings.Contains(err.Error(), "unable to map definition") {
|
||||
t.Fatalf("expected unmappable definition error, got %v", err)
|
||||
func TestValidatePersistableQuestionTypeDefinition_timerOnly(t *testing.T) {
|
||||
err := ValidatePersistableQuestionTypeDefinition("timed_only", []string{"ANSWER_TIMER"})
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user