2026-07-23 20:09:59 +00:00
package scenedescriptions
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
2026-07-28 16:31:36 +00:00
"gitea.maximumdirect.net/eric/promptkit"
2026-07-23 20:09:59 +00:00
)
2026-07-27 20:14:57 +00:00
func TestRegisterPromptAssetsPreparesSceneDescriptionPrompt ( t * testing . T ) {
2026-07-23 20:09:59 +00:00
registry := llm . NewAssetRegistry ( )
if err := RegisterPromptAssets ( registry ) ; err != nil {
t . Fatalf ( "RegisterPromptAssets() error = %v, want nil" , err )
}
2026-07-28 16:31:36 +00:00
options , err := registry . PromptKitOptions ( )
2026-07-23 20:09:59 +00:00
if err != nil {
2026-07-28 16:31:36 +00:00
t . Fatalf ( "PromptKitOptions() error = %v, want nil" , err )
2026-07-23 20:09:59 +00:00
}
2026-07-28 16:31:36 +00:00
options = append ( options , promptkit . WithProfiles ( promptkit . OpenAICompatibleProfile ( promptkit . OpenAICompatibleProfileConfig {
2026-07-23 20:09:59 +00:00
ID : "scene-description-test-profile" , Endpoint : "http://127.0.0.1:1/v1" , Model : "scene-description-test-model" ,
} ) ) )
2026-07-28 16:31:36 +00:00
engine , err := promptkit . NewEngine ( promptkit . Config { Timeout : time . Second } , options ... )
2026-07-23 20:09:59 +00:00
if err != nil {
t . Fatalf ( "NewEngine() error = %v, want nil" , err )
}
2026-07-28 16:31:36 +00:00
prepared , err := engine . Prepare ( context . Background ( ) , promptkit . RunRequest {
2026-07-23 20:09:59 +00:00
PromptID : PromptID , PromptVersion : SchemaVersion , ProfileID : "scene-description-test-profile" ,
2026-07-28 16:31:36 +00:00
Inputs : map [ string ] promptkit . ArtifactRef {
2026-08-05 14:42:54 +00:00
"transcript" : promptkit . InlineWithURI ( "file:///session.json" , ` { "sentinel":"scene-description-transcript"} ` ) ,
"players" : promptkit . Inline ( "scene-description-player" ) ,
2026-07-28 16:31:36 +00:00
"party" : promptkit . Inline ( " " ) ,
"glossary" : promptkit . Inline ( " " ) ,
2026-07-23 20:09:59 +00:00
} ,
} )
if err != nil {
t . Fatalf ( "Prepare() error = %v, want nil" , err )
}
if prepared . PromptID != PromptID || prepared . OutputContract . SchemaPath != "dnd_scene_descriptions_llm.v1.json" {
t . Fatalf ( "prepared prompt = %#v, want scene-description prompt identity and schema wiring" , prepared )
}
2026-08-28 00:13:44 +00:00
const combatPolicySentinel = "substantive active combat materially organizes the"
transcriptIndex := - 1
policyIndex := - 1
instructionsIndex := len ( prepared . Messages ) - 1
policyOccurrences := 0
for index , message := range prepared . Messages {
if strings . Contains ( message . Content , "scene-description-transcript" ) {
transcriptIndex = index
}
if count := strings . Count ( message . Content , combatPolicySentinel ) ; count > 0 {
policyIndex = index
policyOccurrences += count
}
}
if policyOccurrences != 1 || policyIndex <= transcriptIndex || policyIndex >= instructionsIndex {
t . Fatalf ( "combat policy appeared %d times at message %d; want once after transcript message %d and before instructions message %d" , policyOccurrences , policyIndex , transcriptIndex , instructionsIndex )
}
2026-07-23 20:09:59 +00:00
}
func TestPromptMetadataAndDiagnosticsDoNotContainRawAssets ( t * testing . T ) {
2026-07-28 16:42:41 +00:00
hash , err := promptAssetMetadata ( )
2026-07-23 20:09:59 +00:00
if err != nil || ! strings . HasPrefix ( hash , "sha256:" ) {
2026-07-28 16:42:41 +00:00
t . Fatalf ( "promptAssetMetadata() = %q, %v; want hash" , hash , err )
2026-07-23 20:09:59 +00:00
}
payload , err := json . Marshal ( newExtractor ( t , & fakeSceneDescriptionsLLMClient { } ) . ManifestMetadata ( ) )
if err != nil {
t . Fatal ( err )
}
2026-07-27 20:14:57 +00:00
for _ , forbidden := range [ ] string { "common-dnd-system" , "dnd_scene_descriptions_llm.v1.json" } {
2026-07-23 20:09:59 +00:00
if strings . Contains ( string ( payload ) , forbidden ) {
t . Fatalf ( "metadata leaked raw prompt/schema content %q: %s" , forbidden , payload )
}
}
}