Files

56 lines
2.0 KiB
Go
Raw Permalink Normal View History

package npcregistry
2026-07-21 02:24:26 +00:00
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
"gitea.maximumdirect.net/eric/notarius/internal/testsupport/promptkitfixture"
"gitea.maximumdirect.net/eric/promptkit"
2026-07-21 02:24:26 +00:00
)
func TestRegisterPromptAssetsAndPrepareNPCPrompt(t *testing.T) {
registry := llm.NewAssetRegistry()
if err := RegisterPromptAssets(registry); err != nil {
t.Fatalf("RegisterPromptAssets() error = %v, want nil", err)
}
engine := promptkitfixture.NewEngine(t, registry, promptkit.Config{Timeout: time.Second}, map[string]promptkit.ProfileConfig{
"npc-test-profile": promptkitfixture.Profile("http://127.0.0.1:1/v1", "npc-test-model"),
})
prepared, err := engine.Prepare(context.Background(), promptkit.RunRequest{
2026-07-21 02:24:26 +00:00
PromptID: PromptID, PromptVersion: SchemaVersion, ProfileID: "npc-test-profile",
Inputs: map[string]promptkit.ArtifactRef{
"transcript": promptkit.InlineWithURI("file:///session.json", `{"units":[{"sentinel":"npc-transcript"}]}`),
"players": promptkit.Inline("npc-player"),
"party": promptkit.Inline(" "),
"glossary": promptkit.Inline(" "),
2026-07-21 02:24:26 +00:00
},
})
if err != nil {
t.Fatalf("Prepare() error = %v, want nil", err)
}
if prepared.PromptID != PromptID || prepared.OutputContract.SchemaPath != "dnd_npc_registry_llm.v1.json" {
2026-07-21 02:24:26 +00:00
t.Fatalf("prepared prompt = %#v, want NPC prompt identity and wiring", prepared)
}
}
func TestPromptMetadataAndDiagnosticsDoNotContainRawAssets(t *testing.T) {
hash, err := promptAssetMetadata()
2026-07-21 02:24:26 +00:00
if err != nil || !strings.HasPrefix(hash, "sha256:") {
t.Fatalf("promptAssetMetadata() = %q, %v; want hash", hash, err)
2026-07-21 02:24:26 +00:00
}
metadata := newExtractor(t, &fakeNPCsLLMClient{}).ManifestMetadata()
payload, err := json.Marshal(metadata)
if err != nil {
t.Fatal(err)
}
for _, forbidden := range []string{"common-dnd-system", "dnd_npc_registry_llm.v1.json"} {
2026-07-21 02:24:26 +00:00
if strings.Contains(string(payload), forbidden) {
t.Fatalf("metadata leaked raw prompt/schema content %q: %s", forbidden, payload)
}
}
}