package combat_semantics import ( "strings" "testing" "gitea.maximumdirect.net/eric/notarius/internal/framework/contracts" "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd" ) func TestValidatorInterpretsCombatSemanticsResponses(t *testing.T) { for _, test := range []struct { name string kind dnd.SceneKind response classificationResponse approved bool reasonCode string guidance string correction string wantError string }{ {name: "approve non-combat", kind: dnd.SceneKindNarrative, response: classificationResponse{Classification: "non_combat", Explanation: "No active encounter occurs."}, approved: true}, {name: "approve combat", kind: dnd.SceneKindCombat, response: classificationResponse{Classification: "combat", Explanation: "Initiative and attacks organize the chunk."}, approved: true}, {name: "add combat", kind: dnd.SceneKindNarrative, response: classificationResponse{Classification: "combat", Explanation: "The combatants exchange attacks and damage."}, reasonCode: ReasonCodeActiveCombatNotClassified, guidance: "Return kind: combat"}, {name: "remove combat", kind: dnd.SceneKindCombat, response: classificationResponse{Classification: "non_combat", Explanation: "The group only plans for a possible fight."}, reasonCode: ReasonCodeCombatClassificationUnsupported, guidance: "narrative, recap, or meta"}, {name: "unknown classification", kind: dnd.SceneKindNarrative, response: classificationResponse{Classification: "uncertain", Explanation: "The group only plans."}, wantError: "unsupported"}, {name: "blank explanation", kind: dnd.SceneKindNarrative, response: classificationResponse{Classification: "non_combat", Explanation: " "}, wantError: "blank"}, {name: "trim explanation", kind: dnd.SceneKindNarrative, response: classificationResponse{Classification: "combat", Explanation: " The combatants exchange attacks.\n"}, reasonCode: ReasonCodeActiveCombatNotClassified, correction: "Return kind: combat for this scene. The combatants exchange attacks."}, {name: "oversized explanation", kind: dnd.SceneKindNarrative, response: classificationResponse{Classification: "non_combat", Explanation: strings.Repeat("界", 513)}, wantError: "exceeds"}, } { t.Run(test.name, func(t *testing.T) { result, err := interpretResponse(test.response, test.kind) if test.wantError != "" { if err == nil || !strings.Contains(err.Error(), test.wantError) { t.Fatalf("Validate() error = %v, want %q", err, test.wantError) } return } if err != nil || result.Approved != test.approved || result.ReasonCode != test.reasonCode || !strings.Contains(result.CorrectionGuidance, test.guidance) { t.Fatalf("Validate() = %#v, %v", result, err) } if test.correction != "" && result.CorrectionGuidance != test.correction { t.Fatalf("CorrectionGuidance = %q, want %q", result.CorrectionGuidance, test.correction) } if !result.Approved && strings.Contains(result.CorrectionGuidance, result.ReasonCode) { t.Fatalf("correction guidance leaked opaque application detail: %q", result.CorrectionGuidance) } if err := contracts.ValidateValidationResult(result); err != nil { t.Fatalf("ValidateValidationResult(%#v) = %v", result, err) } }) } }