Consolidate D&D prompt ordering tests
This commit is contained in:
@@ -3,7 +3,6 @@ package itemevents
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/scriptorium"
|
||||
)
|
||||
|
||||
func TestPromptAssetsUseSharedSequenceAndTranscriptLast(t *testing.T) {
|
||||
func TestPromptAssetsPrepareItemEventPrompt(t *testing.T) {
|
||||
registry := llm.NewAssetRegistry()
|
||||
if err := RegisterPromptAssets(registry); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -33,9 +32,9 @@ func TestPromptAssetsUseSharedSequenceAndTranscriptLast(t *testing.T) {
|
||||
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "item-events-test-profile",
|
||||
Inputs: map[string]scriptorium.ArtifactRef{
|
||||
"transcript": scriptorium.InlineWithURI("file:///session.json", `{"segments":[1]}`),
|
||||
"players": scriptorium.Inline("Dana: Aria"),
|
||||
"party": scriptorium.Inline("Aria: ranger"),
|
||||
"glossary": scriptorium.Inline("Moonblade: heirloom"),
|
||||
"players": scriptorium.Inline(" "),
|
||||
"party": scriptorium.Inline(" "),
|
||||
"glossary": scriptorium.Inline(" "),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -44,34 +43,6 @@ func TestPromptAssetsUseSharedSequenceAndTranscriptLast(t *testing.T) {
|
||||
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_item_events_llm.v1.json" {
|
||||
t.Fatalf("prepared prompt = %#v", prepared)
|
||||
}
|
||||
want := []struct {
|
||||
role string
|
||||
cached bool
|
||||
marker string
|
||||
}{
|
||||
{"system", false, "Dungeons & Dragons gameplay transcripts"},
|
||||
{"user", false, "Transcript units are the only evidence"},
|
||||
{"user", true, "most specific supported in-world"},
|
||||
{"user", true, "Dana: Aria"},
|
||||
{"user", false, "item and currency events"},
|
||||
{"user", true, "Ordinary non-depleting use"},
|
||||
{"user", false, `{"segments":[1]}`},
|
||||
}
|
||||
if len(prepared.Messages) != len(want) {
|
||||
t.Fatalf("prompt messages = %d, want %d", len(prepared.Messages), len(want))
|
||||
}
|
||||
for index, expected := range want {
|
||||
message := prepared.Messages[index]
|
||||
if message.Role != expected.role || !strings.Contains(message.Content, expected.marker) {
|
||||
t.Fatalf("message %d = %#v", index, message)
|
||||
}
|
||||
if (message.CacheControl != nil) != expected.cached {
|
||||
t.Fatalf("message %d cache control = %#v", index, message.CacheControl)
|
||||
}
|
||||
}
|
||||
if strings.Contains(prepared.Messages[len(prepared.Messages)-1].Content, "Moonblade: heirloom") {
|
||||
t.Fatal("transcript message contains optional reference content")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptAssetsDoNotLeakIntoMetadata(t *testing.T) {
|
||||
@@ -84,7 +55,7 @@ func TestPromptAssetsDoNotLeakIntoMetadata(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, forbidden := range []string{"meaningful Dungeons", "common-dnd-system", "start_segment", "dnd_item_events_llm.v1.json"} {
|
||||
for _, forbidden := range []string{"common-dnd-system", "dnd_item_events_llm.v1.json"} {
|
||||
if strings.Contains(string(payload), forbidden) {
|
||||
t.Fatalf("metadata leaked raw asset content %q: %s", forbidden, payload)
|
||||
}
|
||||
@@ -102,13 +73,4 @@ func TestPromptManifestReusesOnlySharedAssets(t *testing.T) {
|
||||
if !reflect.DeepEqual(promptAssetManifest.SharedFiles, want) {
|
||||
t.Fatalf("shared assets = %#v, want %#v", promptAssetManifest.SharedFiles, want)
|
||||
}
|
||||
for _, path := range []string{"assets/prompts/task.md", "assets/prompts/instructions.md"} {
|
||||
content, err := fs.ReadFile(embeddedAssets, path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(content), "Transcript units are the only evidence") || strings.Contains(string(content), "Dungeons & Dragons gameplay transcripts") {
|
||||
t.Fatalf("module asset %q copied shared prompt text", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user