2026-08-04 00:18:16 +00:00
package locationoccurrences
import (
"context"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
"gitea.maximumdirect.net/eric/promptkit"
)
func TestRegisterPromptAssetsPreparesLocationOccurrencePrompt ( t * testing . T ) {
registry := llm . NewAssetRegistry ( )
if err := RegisterPromptAssets ( registry ) ; err != nil {
t . Fatal ( err )
}
options , err := registry . PromptKitOptions ( )
if err != nil {
t . Fatal ( err )
}
options = append ( options , promptkit . WithProfiles ( promptkit . OpenAICompatibleProfile ( promptkit . OpenAICompatibleProfileConfig {
ID : "location-occurrences-test" , Endpoint : "http://127.0.0.1:1/v1" , Model : "test" ,
} ) ) )
engine , err := promptkit . NewEngine ( promptkit . Config { Timeout : time . Second } , options ... )
if err != nil {
t . Fatal ( err )
}
prepared , err := engine . Prepare ( context . Background ( ) , promptkit . RunRequest {
PromptID : PromptID , PromptVersion : SchemaVersion , ProfileID : "location-occurrences-test" ,
Inputs : map [ string ] promptkit . ArtifactRef {
2026-08-05 14:55:40 +00:00
"transcript" : promptkit . Inline ( ` { "units":[ { "sentinel":"location-occurrence-transcript"}]} ` ) , "players" : promptkit . Inline ( "location-occurrence-player" ) , "party" : promptkit . Inline ( " " ) , "glossary" : promptkit . Inline ( " " ) ,
2026-08-08 14:56:43 +00:00
"location_registry" : promptkit . Inline ( ` { "locations":[ { "name":"location-occurrence-registry","registry_refs":[ { "start_unit_id":7,"end_unit_id":7}],"context":[ { "unit_id":7,"text":"registry context"}]}]} ` ) ,
2026-08-04 00:18:16 +00:00
} ,
} )
if err != nil {
t . Fatal ( err )
}
if prepared . PromptID != PromptID || prepared . OutputContract . SchemaPath != "dnd_location_occurrences_llm.v1.json" {
t . Fatalf ( "prepared prompt = %#v" , prepared )
}
var registryMessage string
2026-08-05 17:38:51 +00:00
for _ , message := range prepared . Messages {
2026-08-08 14:56:43 +00:00
if strings . Contains ( message . Content , "contextual location registry" ) {
2026-08-04 00:18:16 +00:00
registryMessage = message . Content
}
}
2026-08-08 14:56:43 +00:00
if ! strings . Contains ( registryMessage , "location-occurrence-registry" ) || ! strings . Contains ( registryMessage , ` "registry_refs":[ { "start_unit_id":7,"end_unit_id":7}] ` ) || strings . Contains ( registryMessage , "source_id" ) || strings . Contains ( registryMessage , "location:sha256" ) {
2026-08-04 00:18:16 +00:00
t . Fatalf ( "rendered prompt did not preserve source-free registry grounding: %s" , registryMessage )
}
2026-08-05 19:13:37 +00:00
content := make ( [ ] string , len ( prepared . Messages ) )
for index , message := range prepared . Messages {
content [ index ] = message . Content
}
rendered := strings . Join ( content , "\n" )
policy := strings . ReplaceAll ( rendered , "\n" , " " )
2026-08-08 14:56:43 +00:00
if ! strings . Contains ( policy , "context supports that coreference" ) || ! strings . Contains ( policy , "must not create a registry location" ) || ! strings . Contains ( policy , "provenance must never replace current-chunk evidence" ) || ! strings . Contains ( policy , "complete, ordered" ) {
2026-08-05 19:13:37 +00:00
t . Fatalf ( "rendered prompt = %q, want contextual coreference without registry-derived evidence" , rendered )
}
2026-08-04 00:18:16 +00:00
}