59 lines
2.1 KiB
Go
59 lines
2.1 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(`{"units":[1,2]}`),
|
|
"spell_catalog": promptkit.Inline(`{"spells":[]}`),
|
|
"npc_registry": promptkit.Inline(`{"npcs":[]}`),
|
|
"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
|
|
var system string
|
|
for _, message := range prepared.Messages {
|
|
if message.Role == "system" {
|
|
system += message.Content
|
|
}
|
|
}
|
|
if !strings.Contains(system, "canonical spelling exactly") || !strings.Contains(system, "in-world caster") {
|
|
t.Fatal("enduring spell constraints missing from initial system context")
|
|
}
|
|
} 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")
|
|
}
|
|
}
|
|
}
|
|
if len(client.requests) != 0 {
|
|
t.Fatal("preparation invoked generation")
|
|
}
|
|
}
|