package locations import ( "context" "slices" "strings" "testing" "time" "gitea.maximumdirect.net/eric/notarius/internal/framework/llm" "gitea.maximumdirect.net/eric/promptkit" ) func TestRegisterPromptAssetsPreparesLocationPrompt(t *testing.T) { for _, name := range []string{"common-dnd-system.md", "common-dnd-identity.md", "common-dnd-references.md", "common-dnd-transcript-chunk.md", "common-dnd-extraction-evidence.md"} { if !slices.Contains(promptAssetManifest.SharedFiles, name) { t.Fatalf("shared prompt assets = %#v, missing %q", promptAssetManifest.SharedFiles, name) } } registry := llm.NewAssetRegistry() if err := RegisterPromptAssets(registry); err != nil { t.Fatalf("RegisterPromptAssets() error = %v", err) } options, err := registry.PromptKitOptions() if err != nil { t.Fatalf("PromptKitOptions() error = %v", err) } options = append(options, promptkit.WithProfiles(promptkit.OpenAICompatibleProfile(promptkit.OpenAICompatibleProfileConfig{ID: "location-test-profile", Endpoint: "http://127.0.0.1:1/v1", Model: "location-test-model"}))) engine, err := promptkit.NewEngine(promptkit.Config{Timeout: time.Second}, options...) if err != nil { t.Fatalf("NewEngine() error = %v", err) } prepared, err := engine.Prepare(context.Background(), promptkit.RunRequest{PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "location-test-profile", Inputs: map[string]promptkit.ArtifactRef{ "transcript": promptkit.Inline(`{"units":[{"sentinel":"location-transcript"}]}`), "players": promptkit.Inline("location-player"), "party": promptkit.Inline(" "), "glossary": promptkit.Inline(" "), }}) if err != nil { t.Fatalf("Prepare() error = %v", err) } if prepared.OutputContract.SchemaPath != "dnd_locations_llm.v1.json" { t.Fatalf("output contract = %#v", prepared.OutputContract) } if len(prepared.Messages) < 5 { t.Fatalf("prepared messages = %#v, want shared policy, references, transcript, and instructions", prepared.Messages) } referenceIndex := -1 transcriptIndex := -1 for index, message := range prepared.Messages { if strings.Contains(message.Content, "location-player") { referenceIndex = index } if strings.Contains(message.Content, "location-transcript") { transcriptIndex = index } } instructionsIndex := len(prepared.Messages) - 1 if referenceIndex < 0 || transcriptIndex <= referenceIndex || transcriptIndex >= instructionsIndex { t.Fatalf("message order = references %d, transcript %d, instructions %d; want that order", referenceIndex, transcriptIndex, instructionsIndex) } for _, index := range []int{referenceIndex, transcriptIndex, instructionsIndex} { if prepared.Messages[index].CacheControl == nil || prepared.Messages[index].CacheControl.Type != promptkit.CacheControlEphemeral { t.Fatalf("message %d cache control = %#v, want ephemeral", index, prepared.Messages[index].CacheControl) } } for index, message := range prepared.Messages { if index != referenceIndex && strings.Contains(message.Content, "location-player") { t.Errorf("message %d unexpectedly rendered campaign-reference input", index) } if index != transcriptIndex && strings.Contains(message.Content, "location-transcript") { t.Errorf("message %d unexpectedly rendered transcript input", index) } } }