Consolidate spell and combat turn instructions

This commit is contained in:
2026-08-05 14:52:26 +00:00
parent 856b26b718
commit 16d1b29b14
10 changed files with 106 additions and 60 deletions

View File

@@ -12,8 +12,8 @@ import (
)
func TestPromptAssetsPrepareSpellPrompt(t *testing.T) {
transcript := []byte(`{"id":"session-1","segments":[{"id":"u1","text":"Mira casts shield."}]}`)
prepared := prepareSpellsPrompt(t, transcript, "Dana: Mira", "Mira: wizard", "Shield: abjuration")
transcript := []byte(`{"id":"session-1","segments":[{"id":"u1","text":"spell-transcript"}]}`)
prepared := prepareSpellsPrompt(t, transcript, "spell-player", "Mira: wizard", "Shield: abjuration")
if prepared.PromptID != PromptID {
t.Fatalf("prompt id = %q, want %q", prepared.PromptID, PromptID)
@@ -21,6 +21,38 @@ func TestPromptAssetsPrepareSpellPrompt(t *testing.T) {
if prepared.OutputContract.SchemaPath != "dnd_spells_llm.v1.json" {
t.Fatalf("schema path = %q, want LLM-only schema", prepared.OutputContract.SchemaPath)
}
if len(prepared.Messages) < 7 {
t.Fatalf("prepared messages = %#v, want shared context, grounded inputs, and instructions", prepared.Messages)
}
indices := map[string]int{
"spell-player": -1,
"spell-transcript": -1,
"spell-npc-sentinel": -1,
"spell-catalog-sentinel": -1,
}
for index, message := range prepared.Messages {
for sentinel := range indices {
if strings.Contains(message.Content, sentinel) {
indices[sentinel] = index
}
}
}
instructionsIndex := len(prepared.Messages) - 1
if indices["spell-player"] < 0 || indices["spell-transcript"] <= indices["spell-player"] || indices["spell-npc-sentinel"] <= indices["spell-transcript"] || indices["spell-catalog-sentinel"] <= indices["spell-npc-sentinel"] || instructionsIndex <= indices["spell-catalog-sentinel"] {
t.Fatalf("message order = %#v with instructions at %d, want references, transcript, NPCs, catalog, instructions", indices, instructionsIndex)
}
for _, index := range []int{indices["spell-player"], indices["spell-transcript"], instructionsIndex} {
if cache := prepared.Messages[index].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
t.Fatalf("message %d cache control = %#v, want ephemeral", index, cache)
}
}
for sentinel, index := range indices {
for messageIndex, message := range prepared.Messages {
if messageIndex != index && strings.Contains(message.Content, sentinel) {
t.Errorf("message %d unexpectedly rendered %q", messageIndex, sentinel)
}
}
}
}
func TestPromptAssetsPrepareWithMissingOptionalReferences(t *testing.T) {
@@ -107,8 +139,8 @@ func prepareSpellsPrompt(t *testing.T, transcript []byte, players string, party
ProfileID: "spell-test-profile",
Inputs: map[string]promptkit.ArtifactRef{
"transcript": promptkit.InlineWithURI("file:///session.json", string(transcript)),
"spell_catalog": promptkit.Inline(`{"spell_names":["Cure Wounds"]}`),
"npcs": promptkit.Inline(`{"npcs":[]}`),
"spell_catalog": promptkit.Inline(`{"spell_names":["spell-catalog-sentinel"]}`),
"npcs": promptkit.Inline(`{"npcs":[{"name":"spell-npc-sentinel"}]}`),
"players": promptkit.Inline(players),
"party": promptkit.Inline(party),
"glossary": promptkit.Inline(glossary),