Tighten D&D prompt contracts and tests

This commit is contained in:
2026-08-05 17:38:51 +00:00
parent 4093ff2e8b
commit 299c110267
15 changed files with 78 additions and 331 deletions

View File

@@ -21,35 +21,6 @@ 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)
}
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) {