Protect D&D citation prompt ordering
This commit is contained in:
@@ -42,17 +42,41 @@ func TestRegisterPromptAssetsAndPrepareNPCPrompt(t *testing.T) {
|
||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npcs_llm.v1.json" {
|
||||
t.Fatalf("prepared prompt = %#v, want NPC prompt identity and wiring", prepared)
|
||||
}
|
||||
for _, want := range []string{`{"units":[1]}`, "Dana: Mira", "Mira: ranger", "Greencloak: title"} {
|
||||
found := false
|
||||
for _, message := range prepared.Messages {
|
||||
if strings.Contains(message.Content, want) {
|
||||
found = true
|
||||
break
|
||||
for index, want := range []struct {
|
||||
role string
|
||||
cached bool
|
||||
}{
|
||||
{role: "system"},
|
||||
{role: "user"},
|
||||
{role: "user", cached: true},
|
||||
{role: "user", cached: true},
|
||||
{role: "user"},
|
||||
{role: "user", cached: true},
|
||||
{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 !found {
|
||||
t.Fatalf("prepared prompt did not render required input %q", want)
|
||||
}
|
||||
}
|
||||
if len(prepared.Messages) != 7 {
|
||||
t.Fatalf("prepared prompt has %d messages, want 7", 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 transcript := prepared.Messages[6].Content; !strings.Contains(transcript, `{"units":[1]}`) {
|
||||
t.Fatalf("final message = %q, want transcript", transcript)
|
||||
}
|
||||
transcriptMessages := 0
|
||||
for _, message := range prepared.Messages {
|
||||
|
||||
Reference in New Issue
Block a user