Consolidate D&D prompt ordering tests

This commit is contained in:
2026-07-27 20:14:57 +00:00
parent c0ec068f53
commit d1eaec4dad
9 changed files with 218 additions and 312 deletions

View File

@@ -50,10 +50,10 @@ func TestScriptoriumPromptPreparesRequiredInputs(t *testing.T) {
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "combat-test-profile",
Inputs: map[string]scriptorium.ArtifactRef{
"transcript": scriptorium.InlineWithURI("file:///session.json", transcript),
"players": scriptorium.Inline("Dana: Mira"),
"party": scriptorium.Inline("Mira: ranger"),
"glossary": scriptorium.Inline("Greencloak: title"),
"npcs": scriptorium.Inline(`{"npcs":[]}`),
"players": scriptorium.Inline(" "),
"party": scriptorium.Inline(" "),
"glossary": scriptorium.Inline(" "),
"npcs": scriptorium.Inline(" "),
},
})
if err != nil {
@@ -62,48 +62,4 @@ func TestScriptoriumPromptPreparesRequiredInputs(t *testing.T) {
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_combat_turns_llm.v1.json" {
t.Fatalf("prepared prompt = %#v, want combat prompt identity and schema", prepared)
}
for index, want := range []struct {
role string
cached bool
marker string
}{
{role: "system", marker: "Dungeons & Dragons gameplay transcripts"},
{role: "user", marker: "Transcript units are the only evidence"},
{role: "user", cached: true, marker: "most specific supported in-world"},
{role: "user", cached: true},
{role: "user", cached: true},
{role: "user", marker: "combat-turn artifacts"},
{role: "user", cached: true, marker: "turn_kind"},
{role: "user"},
} {
if index >= len(prepared.Messages) {
t.Fatalf("prepared prompt has %d messages, want at least %d", len(prepared.Messages), index+1)
}
message := prepared.Messages[index]
if message.Role != want.role {
t.Errorf("message %d role = %q, want %q", index, message.Role, want.role)
}
if want.cached {
if message.CacheControl == nil || message.CacheControl.Type != scriptorium.CacheControlEphemeral {
t.Errorf("message %d cache control = %#v, want ephemeral", index, message.CacheControl)
}
} else if message.CacheControl != nil {
t.Errorf("message %d cache control = %#v, want nil", index, message.CacheControl)
}
if want.marker != "" && !strings.Contains(message.Content, want.marker) {
t.Errorf("message %d content does not contain purpose marker %q", index, want.marker)
}
}
if len(prepared.Messages) != 8 {
t.Fatalf("prepared prompt has %d messages, want 8", len(prepared.Messages))
}
if references := prepared.Messages[3].Content; !strings.Contains(references, "Dana: Mira") || !strings.Contains(references, "Mira: ranger") || !strings.Contains(references, "Greencloak: title") {
t.Fatalf("campaign references message = %q, want rendered reference inputs", references)
}
if registry := prepared.Messages[4].Content; !strings.Contains(registry, `{"npcs":[]}`) {
t.Fatalf("NPC registry message = %q, want registry input", registry)
}
if final := prepared.Messages[7].Content; !strings.Contains(final, transcript) {
t.Fatalf("final message = %q, want transcript", final)
}
}