Protect D&D citation prompt ordering
This commit is contained in:
@@ -62,16 +62,44 @@ func TestScriptoriumPromptPreparesRequiredInputs(t *testing.T) {
|
|||||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_combat_turns_llm.v1.json" {
|
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)
|
t.Fatalf("prepared prompt = %#v, want combat prompt identity and schema", prepared)
|
||||||
}
|
}
|
||||||
for _, want := range []string{transcript, "Dana: Mira", "Mira: ranger", "Greencloak: title", `{"npcs":[]}`} {
|
for index, want := range []struct {
|
||||||
found := false
|
role string
|
||||||
for _, message := range prepared.Messages {
|
cached bool
|
||||||
if strings.Contains(message.Content, want) {
|
}{
|
||||||
found = true
|
{role: "system"},
|
||||||
break
|
{role: "user"},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{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 {
|
if len(prepared.Messages) != 8 {
|
||||||
t.Fatalf("prepared prompt did not render required input %q", want)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,22 +51,45 @@ func TestRegisterPromptAssetsAndPrepareInteractionPrompt(t *testing.T) {
|
|||||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npc_interactions_llm.v1.json" {
|
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npc_interactions_llm.v1.json" {
|
||||||
t.Fatalf("prepared prompt = %#v", prepared)
|
t.Fatalf("prepared prompt = %#v", prepared)
|
||||||
}
|
}
|
||||||
for _, want := range []string{
|
for index, want := range []struct {
|
||||||
"Mira Thorn", "mentioned", "combat_opponent", "Registry content is context, not event evidence", transcript,
|
role string
|
||||||
|
cached bool
|
||||||
|
}{
|
||||||
|
{role: "system"},
|
||||||
|
{role: "user"},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user"},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user"},
|
||||||
} {
|
} {
|
||||||
found := false
|
if index >= len(prepared.Messages) {
|
||||||
for _, message := range prepared.Messages {
|
t.Fatalf("prepared prompt has %d messages, want at least %d", len(prepared.Messages), index+1)
|
||||||
if strings.Contains(message.Content, want) {
|
}
|
||||||
found = true
|
message := prepared.Messages[index]
|
||||||
break
|
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 {
|
if len(prepared.Messages) != 8 {
|
||||||
t.Fatalf("prepared prompt did not include %q", want)
|
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 last := prepared.Messages[len(prepared.Messages)-1]; !strings.Contains(last.Content, transcript) {
|
if registry := prepared.Messages[4].Content; !strings.Contains(registry, `{"npcs":[{"name":"Mira Thorn"}]}`) {
|
||||||
t.Fatalf("last prompt message = %q, want transcript", last.Content)
|
t.Fatalf("NPC registry message = %q, want names-only registry input", registry)
|
||||||
|
}
|
||||||
|
if final := prepared.Messages[7].Content; !strings.Contains(final, transcript) {
|
||||||
|
t.Fatalf("final message = %q, want transcript", final)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,17 +42,41 @@ func TestRegisterPromptAssetsAndPrepareNPCPrompt(t *testing.T) {
|
|||||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npcs_llm.v1.json" {
|
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npcs_llm.v1.json" {
|
||||||
t.Fatalf("prepared prompt = %#v, want NPC prompt identity and wiring", prepared)
|
t.Fatalf("prepared prompt = %#v, want NPC prompt identity and wiring", prepared)
|
||||||
}
|
}
|
||||||
for _, want := range []string{`{"units":[1]}`, "Dana: Mira", "Mira: ranger", "Greencloak: title"} {
|
for index, want := range []struct {
|
||||||
found := false
|
role string
|
||||||
for _, message := range prepared.Messages {
|
cached bool
|
||||||
if strings.Contains(message.Content, want) {
|
}{
|
||||||
found = true
|
{role: "system"},
|
||||||
break
|
{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 {
|
if len(prepared.Messages) != 7 {
|
||||||
t.Fatalf("prepared prompt did not render required input %q", want)
|
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
|
transcriptMessages := 0
|
||||||
for _, message := range prepared.Messages {
|
for _, message := range prepared.Messages {
|
||||||
|
|||||||
@@ -21,24 +21,49 @@ func TestScriptoriumPromptPreparesTranscriptReferencesAndTaskMessages(t *testing
|
|||||||
if prepared.OutputContract.SchemaPath != "dnd_spells_llm.v1.json" {
|
if prepared.OutputContract.SchemaPath != "dnd_spells_llm.v1.json" {
|
||||||
t.Fatalf("schema path = %q, want LLM-only schema", prepared.OutputContract.SchemaPath)
|
t.Fatalf("schema path = %q, want LLM-only schema", prepared.OutputContract.SchemaPath)
|
||||||
}
|
}
|
||||||
for _, want := range []string{
|
for index, want := range []struct {
|
||||||
string(transcript),
|
role string
|
||||||
"Dana: Mira",
|
cached bool
|
||||||
"Mira: wizard",
|
}{
|
||||||
"Shield: abjuration",
|
{role: "system"},
|
||||||
`{"spell_names":["Cure Wounds"]}`,
|
{role: "user"},
|
||||||
`{"npcs":[]}`,
|
{role: "user", cached: true},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user"},
|
||||||
|
{role: "user"},
|
||||||
|
{role: "user", cached: true},
|
||||||
|
{role: "user"},
|
||||||
} {
|
} {
|
||||||
found := false
|
if index >= len(prepared.Messages) {
|
||||||
for _, message := range prepared.Messages {
|
t.Fatalf("prepared prompt has %d messages, want at least %d", len(prepared.Messages), index+1)
|
||||||
if strings.Contains(message.Content, want) {
|
}
|
||||||
found = true
|
message := prepared.Messages[index]
|
||||||
break
|
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 {
|
if len(prepared.Messages) != 9 {
|
||||||
t.Fatalf("prepared prompt did not render required input %q", want)
|
t.Fatalf("prepared prompt has %d messages, want 9", len(prepared.Messages))
|
||||||
}
|
}
|
||||||
|
if references := prepared.Messages[3].Content; !strings.Contains(references, "Dana: Mira") || !strings.Contains(references, "Mira: wizard") || !strings.Contains(references, "Shield: abjuration") {
|
||||||
|
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 catalog := prepared.Messages[5].Content; !strings.Contains(catalog, `{"spell_names":["Cure Wounds"]}`) {
|
||||||
|
t.Fatalf("spell catalog message = %q, want catalog input", catalog)
|
||||||
|
}
|
||||||
|
if final := prepared.Messages[8].Content; !strings.Contains(final, string(transcript)) {
|
||||||
|
t.Fatalf("final message = %q, want transcript", final)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user