Harden D&D scene description extraction

This commit is contained in:
2026-07-23 23:03:37 +00:00
parent 9614eb540d
commit e1c2f3c202
8 changed files with 118 additions and 763 deletions

View File

@@ -65,6 +65,24 @@ func TestNormalizeRejectsInvalidCandidatesAndConflicts(t *testing.T) {
}
}
func TestNormalizeUsesDocumentOrderRatherThanNumericUnitID(t *testing.T) {
doc := &source.SourceDocument{ID: "session", Units: []source.SourceUnit{
{ID: 20, Text: "The party arrives."},
{ID: 10, Text: "The party departs."},
}}
input := dnd.SceneDescriptionList{Scenes: []dnd.SceneDescription{
scene("later", 10, 10, dnd.SceneKindNarrative, "Departure", "The party departs."),
scene("first", 20, 20, 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 got, want := []string{result.Value.Scenes[0].ID, result.Value.Scenes[1].ID}, []string{"first", "later"}; !reflect.DeepEqual(got, want) {
t.Fatalf("scene order = %#v, want %#v", got, want)
}
}
func TestNormalizerContractAndCancellation(t *testing.T) {
if _, err := DecodeOptions(nil); err != nil {
t.Fatalf("DecodeOptions(nil) error = %v", err)