Make enemy event prompt tests resilient to refactoring

This commit is contained in:
2026-08-03 22:57:17 +00:00
parent e15007fffb
commit a8a99c1037
2 changed files with 75 additions and 86 deletions

View File

@@ -39,12 +39,11 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
"glossary": promptkit.Inline(glossarySentinel),
}
cases := []struct {
name string
promptID string
promptVersion string
inputs map[string]promptkit.ArtifactRef
npcInput bool
spellCatalogInput bool
name string
promptID string
promptVersion string
inputs map[string]promptkit.ArtifactRef
inputSentinels []string
}{
{name: "npcs", promptID: npcextract.PromptID, promptVersion: npcextract.SchemaVersion, inputs: commonInputs},
{name: "item events", promptID: itemeventextract.PromptID, promptVersion: itemeventextract.SchemaVersion, inputs: commonInputs},
@@ -56,7 +55,7 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
inputs: withPromptInputs(commonInputs, map[string]promptkit.ArtifactRef{
"npcs": promptkit.Inline(`{"sentinel":"` + npcSentinel + `"}`),
}),
npcInput: true,
inputSentinels: []string{npcSentinel},
},
{
name: "enemy events",
@@ -67,7 +66,7 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
"combat_turns": promptkit.Inline(`{"sentinel":"combat-turns-sentinel"}`),
"npc_interactions": promptkit.Inline(`{"sentinel":"npc-interactions-sentinel"}`),
}),
npcInput: true,
inputSentinels: []string{npcSentinel, "combat-turns-sentinel", "npc-interactions-sentinel"},
},
{
name: "npc interactions",
@@ -76,7 +75,7 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
inputs: withPromptInputs(commonInputs, map[string]promptkit.ArtifactRef{
"npcs": promptkit.Inline(`{"sentinel":"` + npcSentinel + `"}`),
}),
npcInput: true,
inputSentinels: []string{npcSentinel},
},
{
name: "spells",
@@ -86,8 +85,7 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
"npcs": promptkit.Inline(`{"sentinel":"` + npcSentinel + `"}`),
"spell_catalog": promptkit.Inline(`{"sentinel":"` + catalogSentinel + `"}`),
}),
npcInput: true,
spellCatalogInput: true,
inputSentinels: []string{npcSentinel, catalogSentinel},
},
}
@@ -105,9 +103,6 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
}
transcriptIndex := renderedInputMessageIndex(t, prepared.Messages, transcriptSentinel)
prefix := prepared.Messages[:transcriptIndex+1]
if len(prefix) != 4 {
t.Fatalf("messages through transcript = %d, want 4", len(prefix))
}
if len(prepared.Messages) <= len(prefix) {
t.Fatalf("prepared prompt has %d messages, want lane-specific suffix after transcript", len(prepared.Messages))
}
@@ -116,11 +111,8 @@ func TestExtractionPromptsShareRenderedPrefix(t *testing.T) {
} else if !reflect.DeepEqual(prefix, sharedPrefix) {
t.Fatalf("rendered prefix = %#v, want %#v", prefix, sharedPrefix)
}
if testCase.npcInput {
assertRenderedInputAfter(t, prepared.Messages, npcSentinel, transcriptIndex)
}
if testCase.spellCatalogInput {
assertRenderedInputAfter(t, prepared.Messages, catalogSentinel, transcriptIndex)
for _, sentinel := range testCase.inputSentinels {
assertRenderedInputAfter(t, prepared.Messages, sentinel, transcriptIndex)
}
})
}