Prepare shared context for all D&D extractors

This commit is contained in:
2026-11-29 18:13:45 +00:00
parent e0554209f0
commit 03e4c0d64d
22 changed files with 189 additions and 176 deletions

View File

@@ -12,7 +12,6 @@ import (
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
spellcatalog "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/spells/catalog"
"go.maximumdirect.net/promptkit"
)
@@ -177,33 +176,21 @@ func TestExtractPassesReferencesAsPromptInputs(t *testing.T) {
req := extractionRequest()
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
"players": {Slot: contracts.ReferenceSlot{Name: "players"}, Items: []contracts.ReferenceItem{{SlotName: "players", Content: []byte("Alice: Aria Brightmantle")}}},
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", Content: []byte("Aria Brightmantle: party cleric")}}},
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Brightmantle: local temple name")}}},
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.rpg.party.v1","characters":{"a":{"character":{"name":"Aria Brightmantle","classes":[{"name":"cleric"}]},"player":{"name":"Alice"}}}}`)}}},
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", MediaType: "application/json", Content: []byte(`{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"b","name":"Brightmantle","category":"place","description":"local temple name"}]}}}`)}}},
}}
if _, err := runExtraction(context.Background(), newExtractor(t, client), req); err != nil {
if _, err := runExtraction(context.Background(), newExtractor(t, client, req.References), req); err != nil {
t.Fatalf("Extract() error = %v, want nil", err)
}
text := promptText(client.requests[0])
for _, content := range []string{"Alice: Aria Brightmantle", "Aria Brightmantle: party cleric", "Brightmantle: local temple name", string(req.Chunk.Content)} {
for _, content := range []string{"Alice: Aria Brightmantle", "cleric", "local temple name", string(req.Chunk.Content)} {
if !strings.Contains(text, content) {
t.Fatalf("missing fixed input %q", content)
}
}
}
func TestPromptInputsMapLegacyRosterReferenceToParty(t *testing.T) {
inputs := shared.PromptInputs(spellSourceInput(), contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
"roster": {Slot: contracts.ReferenceSlot{Name: "roster"}, Items: []contracts.ReferenceItem{{SlotName: "roster", Content: []byte("Legacy roster text")}}},
}})
if got := string(inputs["party"].Content); got != "Legacy roster text" {
t.Fatalf("party input = %q, want legacy roster content", got)
}
if _, ok := inputs["roster"]; ok {
t.Fatal("roster prompt input was present; want only party input")
}
}
func TestExtractPreservesValidEmptyCollection(t *testing.T) {
result, err := runExtraction(context.Background(), newExtractor(t, &fakeSpellsLLMClient{content: []byte(`{"spell_casts":[]}`)}), extractionRequest())
if err != nil || result.Value.SpellCasts == nil || len(result.Value.SpellCasts) != 0 {