feat: allow empty stimulus and response on question type definitions
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8b6c6ea17f
commit
ef5858851a
|
|
@ -139,21 +139,14 @@ func IsValidResponseComponentKind(s string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateDynamicQuestionTypeDefinition checks stimulus and response component selections for a
|
// ValidateDynamicQuestionTypeDefinition checks stimulus and response component selections for a
|
||||||
// temporary dynamic question-type definition. Empty or duplicate entries, unknown kinds, and
|
// dynamic question-type definition. Both sides may be empty (shell definitions). Unknown kinds,
|
||||||
// disallowed combinations return a non-nil error.
|
// duplicates, and disallowed combinations return a non-nil error.
|
||||||
func ValidateDynamicQuestionTypeDefinition(stimulusKinds, responseKinds []string) error {
|
func ValidateDynamicQuestionTypeDefinition(stimulusKinds, responseKinds []string) error {
|
||||||
var errs []string
|
var errs []string
|
||||||
|
|
||||||
stimulus := normalizeKindList(stimulusKinds)
|
stimulus := normalizeKindList(stimulusKinds)
|
||||||
response := normalizeKindList(responseKinds)
|
response := normalizeKindList(responseKinds)
|
||||||
|
|
||||||
if len(stimulus) == 0 {
|
|
||||||
errs = append(errs, "at least one stimulus (question input) component is required")
|
|
||||||
}
|
|
||||||
if len(response) == 0 {
|
|
||||||
errs = append(errs, "at least one response component is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, k := range stimulus {
|
for i, k := range stimulus {
|
||||||
if k == "" {
|
if k == "" {
|
||||||
errs = append(errs, fmt.Sprintf("stimulus [%d]: empty component kind", i))
|
errs = append(errs, fmt.Sprintf("stimulus [%d]: empty component kind", i))
|
||||||
|
|
@ -400,8 +393,13 @@ func ResolveRuntimeQuestionTypeFromDefinition(key string, responseKinds []string
|
||||||
return "TRUE_FALSE"
|
return "TRUE_FALSE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response := normalizeKindList(responseKinds)
|
||||||
|
if len(response) == 0 {
|
||||||
|
return "DYNAMIC"
|
||||||
|
}
|
||||||
|
|
||||||
hasNonAuxiliary := false
|
hasNonAuxiliary := false
|
||||||
for _, kind := range normalizeKindList(responseKinds) {
|
for _, kind := range response {
|
||||||
if _, aux := responseKindsAuxiliary[kind]; !aux {
|
if _, aux := responseKindsAuxiliary[kind]; !aux {
|
||||||
hasNonAuxiliary = true
|
hasNonAuxiliary = true
|
||||||
}
|
}
|
||||||
|
|
@ -495,12 +493,6 @@ func ValidateDefinitionSchemas(stimulusSchema, responseSchema []DynamicElementDe
|
||||||
|
|
||||||
func ValidateDynamicPayloadAgainstDefinition(payload DynamicQuestionPayload, def QuestionTypeDefinition) error {
|
func ValidateDynamicPayloadAgainstDefinition(payload DynamicQuestionPayload, def QuestionTypeDefinition) error {
|
||||||
var errs []string
|
var errs []string
|
||||||
if len(payload.Stimulus) == 0 {
|
|
||||||
errs = append(errs, "dynamic_payload.stimulus must contain at least one element")
|
|
||||||
}
|
|
||||||
if len(payload.Response) == 0 {
|
|
||||||
errs = append(errs, "dynamic_payload.response must contain at least one element")
|
|
||||||
}
|
|
||||||
|
|
||||||
allowedStimulus := make(map[string]struct{})
|
allowedStimulus := make(map[string]struct{})
|
||||||
allowedResponse := make(map[string]struct{})
|
allowedResponse := make(map[string]struct{})
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,20 @@ func TestValidateDynamicQuestionTypeDefinition_unknownStimulus(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateDynamicQuestionTypeDefinition_emptyResponse(t *testing.T) {
|
func TestValidateDynamicQuestionTypeDefinition_emptyShell(t *testing.T) {
|
||||||
|
err := ValidateDynamicQuestionTypeDefinition(nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected empty shell definition to be valid, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateDynamicQuestionTypeDefinition_stimulusOnly(t *testing.T) {
|
||||||
err := ValidateDynamicQuestionTypeDefinition(
|
err := ValidateDynamicQuestionTypeDefinition(
|
||||||
[]string{"INSTRUCTION"},
|
[]string{"INSTRUCTION"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
if err == nil || !strings.Contains(err.Error(), "at least one response") {
|
if err != nil {
|
||||||
t.Fatalf("expected empty response error, got %v", err)
|
t.Fatalf("expected stimulus-only definition to be valid, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,6 +131,28 @@ func TestValidatePersistableQuestionTypeDefinition_unmappable(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidatePersistableQuestionTypeDefinition_emptyShell(t *testing.T) {
|
||||||
|
err := ValidatePersistableQuestionTypeDefinition("custom_shell", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected empty shell definition to be persistable, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveRuntimeQuestionTypeFromDefinition_emptyShell(t *testing.T) {
|
||||||
|
got := ResolveRuntimeQuestionTypeFromDefinition("custom_shell", nil)
|
||||||
|
if got != "DYNAMIC" {
|
||||||
|
t.Fatalf("expected DYNAMIC for empty shell, got %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateDynamicPayloadAgainstDefinition_emptyShell(t *testing.T) {
|
||||||
|
def := QuestionTypeDefinition{}
|
||||||
|
payload := DynamicQuestionPayload{}
|
||||||
|
if err := ValidateDynamicPayloadAgainstDefinition(payload, def); err != nil {
|
||||||
|
t.Fatalf("expected empty payload against empty shell definition, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestValidateDefinitionSchemas_valid(t *testing.T) {
|
func TestValidateDefinitionSchemas_valid(t *testing.T) {
|
||||||
err := ValidateDefinitionSchemas(
|
err := ValidateDefinitionSchemas(
|
||||||
[]DynamicElementDefinition{
|
[]DynamicElementDefinition{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user