62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
package scenedescriptions
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
|
"gitea.maximumdirect.net/eric/scriptorium"
|
|
)
|
|
|
|
func TestRegisterPromptAssetsPreparesSceneDescriptionPrompt(t *testing.T) {
|
|
registry := llm.NewAssetRegistry()
|
|
if err := RegisterPromptAssets(registry); err != nil {
|
|
t.Fatalf("RegisterPromptAssets() error = %v, want nil", err)
|
|
}
|
|
options, err := registry.ScriptoriumOptions()
|
|
if err != nil {
|
|
t.Fatalf("ScriptoriumOptions() error = %v, want nil", err)
|
|
}
|
|
options = append(options, scriptorium.WithProfiles(scriptorium.OpenAICompatibleProfile(scriptorium.OpenAICompatibleProfileConfig{
|
|
ID: "scene-description-test-profile", Endpoint: "http://127.0.0.1:1/v1", Model: "scene-description-test-model",
|
|
})))
|
|
engine, err := scriptorium.NewEngine(scriptorium.Config{Timeout: time.Second}, options...)
|
|
if err != nil {
|
|
t.Fatalf("NewEngine() error = %v, want nil", err)
|
|
}
|
|
prepared, err := engine.Prepare(context.Background(), scriptorium.RunRequest{
|
|
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "scene-description-test-profile",
|
|
Inputs: map[string]scriptorium.ArtifactRef{
|
|
"transcript": scriptorium.InlineWithURI("file:///session.json", `{"units":[1]}`),
|
|
"players": scriptorium.Inline(" "),
|
|
"party": scriptorium.Inline(" "),
|
|
"glossary": scriptorium.Inline(" "),
|
|
},
|
|
})
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestPromptMetadataAndDiagnosticsDoNotContainRawAssets(t *testing.T) {
|
|
hash, err := scriptoriumPromptMetadata()
|
|
if err != nil || !strings.HasPrefix(hash, "sha256:") {
|
|
t.Fatalf("scriptoriumPromptMetadata() = %q, %v; want hash", hash, err)
|
|
}
|
|
payload, err := json.Marshal(newExtractor(t, &fakeSceneDescriptionsLLMClient{}).ManifestMetadata())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, forbidden := range []string{"common-dnd-system", "dnd_scene_descriptions_llm.v1.json"} {
|
|
if strings.Contains(string(payload), forbidden) {
|
|
t.Fatalf("metadata leaked raw prompt/schema content %q: %s", forbidden, payload)
|
|
}
|
|
}
|
|
}
|