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

@@ -28,33 +28,6 @@ func TestRegisterPromptAssetsAndPrepareEnemyEventPrompt(t *testing.T) {
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_enemy_events_llm.v1.json" || prepared.SelectedProfileID != "dnd-extraction" {
t.Fatalf("prepared prompt = %#v", prepared)
}
referenceIndex := renderedMessageIndex(t, prepared.Messages, "enemy-player")
transcriptIndex := renderedMessageIndex(t, prepared.Messages, "enemy-transcript")
if transcriptIndex <= referenceIndex {
t.Fatalf("transcript message index = %d, want after references index %d", transcriptIndex, referenceIndex)
}
groundingIndices := make([]int, 0, 3)
for _, sentinel := range []string{"enemy-npc", "enemy-turn", "enemy-opponent"} {
if index := renderedMessageIndex(t, prepared.Messages, sentinel); index <= transcriptIndex {
t.Fatalf("message containing %q has index %d, want after transcript index %d", sentinel, index, transcriptIndex)
} else {
groundingIndices = append(groundingIndices, index)
}
}
instructionIndex := len(prepared.Messages) - 1
for _, index := range groundingIndices {
if instructionIndex <= index {
t.Fatalf("instruction index = %d, want after grounding index %d", instructionIndex, index)
}
}
if instructionIndex != len(prepared.Messages)-1 {
t.Fatalf("instruction message index = %d, want final message", instructionIndex)
}
for _, index := range []int{referenceIndex, transcriptIndex, instructionIndex} {
if cache := prepared.Messages[index].CacheControl; cache == nil || cache.Type != promptkit.CacheControlEphemeral {
t.Fatalf("message %d cache control = %#v, want ephemeral", index, cache)
}
}
}
func TestEnemyEventPromptRequiresGroundingInputs(t *testing.T) {
@@ -115,20 +88,3 @@ func enemyEventPromptInputs() map[string]promptkit.ArtifactRef {
"npc_interactions": promptkit.Inline(`{"npc_interactions":[{"name":"enemy-opponent","kind":"combat_opponent"}]}`),
}
}
func renderedMessageIndex(t *testing.T, messages []promptkit.RenderedMessage, sentinel string) int {
t.Helper()
index := -1
occurrences := 0
for messageIndex, message := range messages {
count := strings.Count(message.Content, sentinel)
if count > 0 {
index = messageIndex
occurrences += count
}
}
if occurrences != 1 {
t.Fatalf("message sentinel %q rendered %d times, want exactly once", sentinel, occurrences)
}
return index
}