Files
notarius/internal/modules/dnd/extract/spells/prompt_assets_test.go

64 lines
2.4 KiB
Go

package spells
import (
"context"
"reflect"
"strings"
"testing"
"go.maximumdirect.net/promptkit"
)
func TestSpellPromptPairSharesNativeContractAndDefaultProfile(t *testing.T) {
client := &fakeSpellsLLMClient{}
engine := newSpellEngine(t, client)
var initial promptkit.PreparedRun
for _, id := range []string{PromptID, CorrectionPromptID} {
inputs := map[string]promptkit.ArtifactRef{"guidance": promptkit.Inline("Fix the rejected cast.")}
if id == PromptID {
inputs = map[string]promptkit.ArtifactRef{
"transcript": promptkit.Inline(`{"sentinel":"spell-transcript-sentinel"}`),
"spell_catalog": promptkit.Inline(`{"sentinel":"spell-catalog-sentinel"}`),
"npc_registry": promptkit.Inline(`{"sentinel":"spell-npcs-sentinel"}`),
"players": promptkit.Inline(" "), "party": promptkit.Inline(" "), "glossary": promptkit.Inline(" "),
}
}
handle, err := engine.PrepareExecution(context.Background(), promptkit.RunRequest{PromptID: id, APIKey: "test-only", Inputs: inputs})
if err != nil {
t.Fatal(err)
}
prepared := handle.Details()
handle.Discard()
if prepared.SelectedProfileID != "notarius/dnd-extraction" {
t.Fatalf("unexpected default profile %q", prepared.SelectedProfileID)
}
if prepared.StructuredOutput == nil || prepared.OutputContract.SchemaPath != "dnd/spells/schemas/dnd_spells_llm.v1.json" {
t.Fatal("missing native spell response schema")
}
if id == PromptID {
initial = prepared
for _, sentinel := range []string{"spell-transcript-sentinel", "spell-catalog-sentinel", "spell-npcs-sentinel"} {
var count int
for _, message := range prepared.Messages {
count += strings.Count(message.Content, sentinel)
}
if count != 1 {
t.Fatalf("input %q rendered %d times", sentinel, count)
}
}
} else {
if !reflect.DeepEqual(initial.OutputContract, prepared.OutputContract) || len(prepared.Messages) != 1 || prepared.Messages[0].Role != "user" || !strings.Contains(prepared.Messages[0].Content, "Fix the rejected cast.") {
t.Fatal("correction must supply only findings and a replacement assignment with the same contract")
}
for _, sentinel := range []string{"spell-transcript-sentinel", "spell-catalog-sentinel", "spell-npcs-sentinel"} {
if strings.Contains(prepared.Messages[0].Content, sentinel) {
t.Fatalf("correction repeated input %q", sentinel)
}
}
}
}
if len(client.requests) != 0 {
t.Fatal("preparation invoked generation")
}
}