Bound D&D normalization diagnostics

This commit is contained in:
2026-08-09 02:22:23 +00:00
parent a705ba74a1
commit 2a75f40871
8 changed files with 218 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ package scenedescriptions
import (
"context"
"fmt"
"reflect"
"strings"
"testing"
@@ -10,6 +11,7 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
)
func TestNormalizeTrimsOrdersDeduplicatesAndOwnsOutput(t *testing.T) {
@@ -33,6 +35,15 @@ func TestNormalizeTrimsOrdersDeduplicatesAndOwnsOutput(t *testing.T) {
if !reflect.DeepEqual(result.Value.Scenes, want) {
t.Fatalf("scenes = %#v, want %#v", result.Value.Scenes, want)
}
if got := result.Warnings; len(got) != 7 || !reflect.DeepEqual(
[]string{got[0].ReasonCode, got[1].ReasonCode, got[2].ReasonCode, got[3].ReasonCode, got[4].ReasonCode, got[5].ReasonCode, got[6].ReasonCode},
[]string{ReasonCodeProseNormalized, ReasonCodeProseNormalized, ReasonCodeProseNormalized, ReasonCodeProseNormalized, ReasonCodeOrderNormalized, ReasonCodeOrderNormalized, ReasonCodeDuplicateCollapsed},
) || !reflect.DeepEqual(
[]string{got[0].Scope, got[1].Scope, got[2].Scope, got[3].Scope, got[4].Scope, got[5].Scope, got[6].Scope},
[]string{"scenes[0]", "scenes[1]", "scenes[2]", "scenes[3]", "scenes[2]", "scenes[0]", "scenes[3]"},
) {
t.Fatalf("warnings = %#v, want prose, order, then duplicate mutation diagnostics", got)
}
if !reflect.DeepEqual(input, before) {
t.Fatalf("Normalize() mutated input: %#v", input)
}
@@ -40,6 +51,41 @@ func TestNormalizeTrimsOrdersDeduplicatesAndOwnsOutput(t *testing.T) {
if input.Scenes[0].Title == "changed" {
t.Fatal("normalized output aliases input storage")
}
second, err := New(Options{}).Normalize(context.Background(), normalizeRequest(dnd.SceneDescriptionList{Scenes: want}, doc))
if err != nil {
t.Fatalf("second Normalize() error = %v", err)
}
if !reflect.DeepEqual(second.Value.Scenes, want) || len(second.Warnings) != 0 {
t.Fatalf("second normalization = %#v, want unchanged value without warnings", second)
}
}
func TestNormalizeLimitsCombinedSceneMutationWarnings(t *testing.T) {
count := diagnostics.MaxWarnings - 8
doc := &source.SourceDocument{ID: "session", Units: make([]source.SourceUnit, count)}
input := dnd.SceneDescriptionList{Scenes: make([]dnd.SceneDescription, count)}
for index := range input.Scenes {
unitID := count - index
doc.Units[index] = source.SourceUnit{ID: index + 1}
input.Scenes[index] = scene(fmt.Sprintf("scene-%02d", unitID), unitID, unitID, dnd.SceneKindNarrative, " Arrival ", " The party arrives. ")
}
result, err := New(Options{}).Normalize(context.Background(), normalizeRequest(input, doc))
if err != nil {
t.Fatalf("Normalize() error = %v", err)
}
if len(result.Value.Scenes) != count || result.Value.Scenes[0].SourceRef.StartUnitID != 1 {
t.Fatalf("normalized scenes = %#v, want unchanged canonical values", result.Value.Scenes)
}
if len(result.Warnings) != diagnostics.MaxWarnings {
t.Fatalf("warning count = %d, want %d", len(result.Warnings), diagnostics.MaxWarnings)
}
if first := result.Warnings[0]; first.Scope != "scenes[0]" || first.ReasonCode != ReasonCodeProseNormalized {
t.Fatalf("first warning = %#v, want first prose warning", first)
}
summary := result.Warnings[len(result.Warnings)-1]
if summary.Scope != "scenes" || summary.ReasonCode != ReasonCodeNormalizationWarningsOmitted || summary.Message != "5 additional warning(s) omitted" {
t.Fatalf("warning summary = %#v", summary)
}
}
func TestNormalizeRejectsInvalidCandidatesAndConflicts(t *testing.T) {