2026-07-23 13:59:02 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
2026-07-26 01:41:35 +00:00
|
|
|
"reflect"
|
2026-07-23 13:59:02 +00:00
|
|
|
"sync"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
2026-08-05 19:00:55 +00:00
|
|
|
occurrencecodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/npcoccurrences"
|
2026-08-05 18:38:22 +00:00
|
|
|
npccodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/npcregistry"
|
2026-07-26 01:41:35 +00:00
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/npcs/identity"
|
2026-11-22 04:45:39 +00:00
|
|
|
"go.maximumdirect.net/promptkit"
|
2026-07-23 13:59:02 +00:00
|
|
|
)
|
|
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
func TestNPCOccurrencePipelineUsesAcceptedRegistryAndCurrentEvidence(t *testing.T) {
|
2026-07-23 13:59:02 +00:00
|
|
|
registries := productionNPCRegistries(t)
|
2026-08-05 19:00:55 +00:00
|
|
|
resolved := resolveNPCOccurrencePipeline(t, registries)
|
|
|
|
|
client := &npcOccurrenceLLMClient{}
|
2026-07-23 13:59:02 +00:00
|
|
|
|
|
|
|
|
output, err := runPreparedPipeline(t, registries, resolved, client, pipeline.RunInput{RawInput: readNPCFixture(t)})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Run() error = %v", err)
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
if len(output.OutputFiles) != 2 {
|
|
|
|
|
t.Fatalf("output files = %#v, want registry and occurrences", output.OutputFiles)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
request := client.requestFor(t, "occurrences")
|
2026-08-08 14:37:54 +00:00
|
|
|
wantRegistry := `{"npcs":[{"name":"Mira Thorn"},{"name":"Hooded Guard"}]}`
|
2026-11-22 04:45:39 +00:00
|
|
|
registryInput, err := nativeJSONInput(request, "npcs")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
if string(registryInput) != wantRegistry {
|
|
|
|
|
t.Fatalf("occurrence registry = %s, want names-only projection %s", registryInput, wantRegistry)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
serialized := publishedLane(t, output, "occurrences")
|
|
|
|
|
occurrences, err := occurrencecodec.New().Decode(serialized.Bytes)
|
2026-07-23 13:59:02 +00:00
|
|
|
if err != nil {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatalf("Decode(occurrence output) error = %v", err)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-08-05 19:00:55 +00:00
|
|
|
if len(occurrences.Occurrences) != 2 {
|
|
|
|
|
t.Fatalf("occurrences = %#v, want two occurrences", occurrences)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-08-05 19:00:55 +00:00
|
|
|
first, second := occurrences.Occurrences[0], occurrences.Occurrences[1]
|
2026-07-23 13:59:02 +00:00
|
|
|
if first.Name != "Mira Thorn" || string(first.Kind) != "dialogue" || second.Name != "Hooded Guard" || string(second.Kind) != "noncombat_presence" {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatalf("occurrences = %#v, want canonical names, kinds, and source chronology", occurrences)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-08-08 14:37:54 +00:00
|
|
|
if first.NPCID != identity.DeriveID("Mira Thorn") || second.NPCID != identity.DeriveID("Hooded Guard") {
|
|
|
|
|
t.Fatalf("occurrences = %#v, want durable registry IDs", occurrences)
|
|
|
|
|
}
|
2026-08-05 19:00:55 +00:00
|
|
|
assertOccurrenceEvidence(t, first.SourceRefs)
|
|
|
|
|
assertOccurrenceEvidence(t, second.SourceRefs)
|
2026-07-23 13:59:02 +00:00
|
|
|
if first.SourceRefs[0].StartUnitID >= second.SourceRefs[0].StartUnitID {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatalf("occurrence chronology = %#v, want source order", occurrences.Occurrences)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var durable map[string]json.RawMessage
|
2026-11-22 04:45:39 +00:00
|
|
|
if err := json.Unmarshal(serialized.Bytes, &durable); err != nil {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatalf("unmarshal durable occurrence payload: %v", err)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-08-05 18:55:58 +00:00
|
|
|
if len(durable) != 1 || durable["occurrences"] == nil {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatalf("durable occurrence payload = %#v, want only occurrences", durable)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-26 01:41:35 +00:00
|
|
|
func TestSemanticNPCNormalizationCrossesOrderedRegistryHandoff(t *testing.T) {
|
|
|
|
|
registries := productionNPCRegistries(t)
|
2026-08-05 19:00:55 +00:00
|
|
|
cfg := loadNPCOccurrencePipelineConfig(t)
|
|
|
|
|
profile := cfg.Pipelines["dnd-npc-occurrences-fixture"]
|
2026-07-26 01:41:35 +00:00
|
|
|
profile.Chunk = pipeline.ModuleBinding{Module: "generic", Options: map[string]any{"max_units": 1}}
|
2026-08-05 19:00:55 +00:00
|
|
|
cfg.Pipelines["dnd-npc-occurrences-fixture"] = profile
|
|
|
|
|
effective, err := cfg.Resolve(config.ResolveInput{PipelineID: "dnd-npc-occurrences-fixture", Catalog: moduleCatalog(registries)})
|
2026-07-26 01:41:35 +00:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
resolved, warnings, err := pipeline.MaterializeReferences(effective.ResolvedPipeline, moduleCatalog(registries), pipeline.ReferenceMaterializationOptions{})
|
|
|
|
|
if err != nil || len(warnings) != 0 {
|
|
|
|
|
t.Fatalf("MaterializeReferences() error = %v warnings = %#v", err, warnings)
|
|
|
|
|
}
|
2026-08-05 19:00:55 +00:00
|
|
|
client := &semanticNPCOccurrenceClient{}
|
2026-07-26 01:41:35 +00:00
|
|
|
raw := []byte(`{"metadata":{"id":"semantic-session","title":"Semantic NPC session"},"segments":[{"id":1,"start":0,"end":1,"speaker":"DM","text":"Mira Thorn enters."},{"id":2,"start":1,"end":2,"speaker":"DM","text":"Mira Thorn, the Greencloak, waves."}]}`)
|
|
|
|
|
output, err := runPreparedPipeline(t, registries, resolved, client, pipeline.RunInput{RawInput: raw})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Run() error = %v", err)
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
if client.requestCount("npcs") != 2 || client.requestCount("duplicate_groups") != 1 {
|
2026-07-26 01:41:35 +00:00
|
|
|
t.Fatalf("prompt requests = %#v, want two extraction calls and one document normalization call", client.requests)
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
npcOutput := publishedLane(t, output, "npc_registry")
|
|
|
|
|
npcsValue, err := npccodec.New().Decode(npcOutput.Bytes)
|
2026-07-26 01:41:35 +00:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
if len(npcsValue.NPCs) != 1 || npcsValue.NPCs[0].Name != "Mira Thorn" || npcsValue.NPCs[0].ID != identity.DeriveID("Mira Thorn") {
|
2026-07-26 01:41:35 +00:00
|
|
|
t.Fatalf("NPC output = %#v / %#v, want canonical ordered producer artifact", npcOutput, npcsValue)
|
|
|
|
|
}
|
|
|
|
|
if refs := npcsValue.NPCs[0].SourceRefs; !reflect.DeepEqual(refs, []source.SourceRef{{SourceID: "semantic-session", StartUnitID: 1, EndUnitID: 1}, {SourceID: "semantic-session", StartUnitID: 2, EndUnitID: 2}}) {
|
|
|
|
|
t.Fatalf("NPC evidence = %#v, want original extraction evidence union", refs)
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
registryRequest := client.requestFor(t, "occurrences")
|
|
|
|
|
registryInput, err := nativeJSONInput(registryRequest, "npcs")
|
|
|
|
|
if err != nil || string(registryInput) != `{"npcs":[{"name":"Mira Thorn"}]}` {
|
|
|
|
|
t.Fatalf("downstream registry = %s, error=%v", registryInput, err)
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
occurrences, err := occurrencecodec.New().Decode(publishedLane(t, output, "occurrences").Bytes)
|
|
|
|
|
if err != nil || len(occurrences.Occurrences) != 2 {
|
|
|
|
|
t.Fatalf("downstream occurrences=%#v error=%v, want both chunks", occurrences, err)
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
for index, occurrence := range occurrences.Occurrences {
|
|
|
|
|
wantRef := source.SourceRef{SourceID: "semantic-session", StartUnitID: index + 1, EndUnitID: index + 1}
|
|
|
|
|
if occurrence.Name != "Mira Thorn" || occurrence.NPCID != npcsValue.NPCs[0].ID || !reflect.DeepEqual(occurrence.SourceRefs, []source.SourceRef{wantRef}) {
|
|
|
|
|
t.Fatalf("occurrence=%#v, want canonical identity and current chunk evidence %#v", occurrence, wantRef)
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
func TestNPCOccurrencePipelineSkipsConsumerWhenNPCProducerIsRejected(t *testing.T) {
|
2026-07-23 13:59:02 +00:00
|
|
|
registries := productionNPCRegistries(t)
|
2026-08-05 19:00:55 +00:00
|
|
|
resolved := resolveNPCOccurrencePipeline(t, registries)
|
|
|
|
|
client := &npcOccurrenceLLMClient{rejectNPCs: true}
|
2026-11-22 04:45:39 +00:00
|
|
|
resolved.Steps[0].ArtifactLanes[0].ExtractControls.MaxAdditionalTurns = 0
|
2026-07-23 13:59:02 +00:00
|
|
|
|
|
|
|
|
output, err := runPreparedPipeline(t, registries, resolved, client, pipeline.RunInput{RawInput: readNPCFixture(t)})
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatalf("Run() output = %#v, want missing generated NPC producer error", output)
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
if client.requestCount("npcs") != 1 {
|
|
|
|
|
t.Fatalf("NPC requests = %d, want rejected producer", client.requestCount("npcs"))
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
if client.requestCount("occurrences") != 0 {
|
|
|
|
|
t.Fatalf("occurrence requests = %d, want none after rejected producer", client.requestCount("occurrences"))
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
func resolveNPCOccurrencePipeline(t *testing.T, registries pipeline.Registries) pipeline.ResolvedPipeline {
|
2026-07-23 13:59:02 +00:00
|
|
|
t.Helper()
|
2026-08-05 19:00:55 +00:00
|
|
|
configValue := loadNPCOccurrencePipelineConfig(t)
|
|
|
|
|
effective, err := configValue.Resolve(config.ResolveInput{PipelineID: "dnd-npc-occurrences-fixture", Catalog: moduleCatalog(registries)})
|
2026-07-23 13:59:02 +00:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Resolve() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
resolved, warnings, err := pipeline.MaterializeReferences(effective.ResolvedPipeline, moduleCatalog(registries), pipeline.ReferenceMaterializationOptions{})
|
|
|
|
|
if err != nil || len(warnings) != 0 {
|
|
|
|
|
t.Fatalf("MaterializeReferences() error = %v warnings = %#v", err, warnings)
|
|
|
|
|
}
|
|
|
|
|
return resolved
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
func loadNPCOccurrencePipelineConfig(t *testing.T) config.Config {
|
2026-07-23 13:59:02 +00:00
|
|
|
t.Helper()
|
2026-09-13 17:23:00 +00:00
|
|
|
return loadIntegrationConfig(t, "testdata/dnd_npc_occurrences_pipeline.yml")
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
func assertOccurrenceEvidence(t *testing.T, references []source.SourceRef) {
|
2026-07-23 13:59:02 +00:00
|
|
|
t.Helper()
|
|
|
|
|
if len(references) == 0 {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatal("occurrence has no current-source evidence")
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
for _, reference := range references {
|
|
|
|
|
if reference.SourceID != "npc-session" {
|
2026-08-05 19:00:55 +00:00
|
|
|
t.Fatalf("occurrence evidence = %#v, want current source only", reference)
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
type npcOccurrenceLLMClient struct {
|
2026-07-23 13:59:02 +00:00
|
|
|
mu sync.Mutex
|
2026-11-22 04:45:39 +00:00
|
|
|
requests []promptkit.GenerateRequest
|
2026-07-23 13:59:02 +00:00
|
|
|
rejectNPCs bool
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
func (client *npcOccurrenceLLMClient) Generate(ctx context.Context, request promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
2026-07-23 13:59:02 +00:00
|
|
|
if err := ctx.Err(); err != nil {
|
2026-11-22 04:45:39 +00:00
|
|
|
return nil, err
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
client.mu.Lock()
|
2026-11-22 04:45:39 +00:00
|
|
|
client.requests = append(client.requests, request)
|
2026-07-23 13:59:02 +00:00
|
|
|
client.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
var payload any
|
2026-11-22 04:45:39 +00:00
|
|
|
switch {
|
|
|
|
|
case nativeSchemaHasProperty(request, "npcs"):
|
2026-07-23 13:59:02 +00:00
|
|
|
if client.rejectNPCs {
|
|
|
|
|
payload = map[string]any{"npcs": []any{map[string]any{
|
|
|
|
|
"name": "", "source_refs": []any{map[string]int{"start_unit_id": 1, "end_unit_id": 1}},
|
|
|
|
|
}}}
|
|
|
|
|
} else {
|
|
|
|
|
payload = map[string]any{"npcs": []any{
|
|
|
|
|
map[string]any{"name": "Mira Thorn", "source_refs": []any{map[string]int{"start_unit_id": 1, "end_unit_id": 1}}},
|
|
|
|
|
map[string]any{"name": "Hooded Guard", "source_refs": []any{map[string]int{"start_unit_id": 3, "end_unit_id": 3}}},
|
|
|
|
|
}}
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
case nativeSchemaHasProperty(request, "duplicate_groups"):
|
2026-07-26 01:41:35 +00:00
|
|
|
payload = map[string]any{"duplicate_groups": []any{}}
|
2026-11-22 04:45:39 +00:00
|
|
|
case nativeSchemaHasProperty(request, "occurrences"):
|
2026-08-05 18:55:58 +00:00
|
|
|
payload = map[string]any{"occurrences": []any{
|
2026-11-22 04:45:39 +00:00
|
|
|
map[string]any{"name": "Hooded Guard", "kind": "noncombat_presence", "source_refs": []any{map[string]int{"start_unit_id": 3, "end_unit_id": 3}}},
|
|
|
|
|
map[string]any{"name": "Mira Thorn", "kind": "dialogue", "source_refs": []any{map[string]int{"start_unit_id": 2, "end_unit_id": 2}}},
|
2026-07-23 13:59:02 +00:00
|
|
|
}}
|
|
|
|
|
default:
|
2026-11-22 04:45:39 +00:00
|
|
|
return nil, fmt.Errorf("unexpected native occurrence response contract")
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
content, err := json.Marshal(payload)
|
|
|
|
|
if err != nil {
|
2026-11-22 04:45:39 +00:00
|
|
|
return nil, err
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
return &promptkit.GenerateResponse{Content: string(content)}, nil
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
func (client *npcOccurrenceLLMClient) requestFor(t *testing.T, property string) promptkit.GenerateRequest {
|
2026-07-23 13:59:02 +00:00
|
|
|
t.Helper()
|
|
|
|
|
client.mu.Lock()
|
|
|
|
|
defer client.mu.Unlock()
|
|
|
|
|
for _, request := range client.requests {
|
2026-11-22 04:45:39 +00:00
|
|
|
if nativeSchemaHasProperty(request, property) {
|
2026-07-23 13:59:02 +00:00
|
|
|
return request
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
t.Fatalf("requests = %#v, missing prompt %q", client.requests, property)
|
|
|
|
|
return promptkit.GenerateRequest{}
|
2026-07-23 13:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
func (client *npcOccurrenceLLMClient) requestCount(property string) int {
|
2026-07-23 13:59:02 +00:00
|
|
|
client.mu.Lock()
|
|
|
|
|
defer client.mu.Unlock()
|
|
|
|
|
count := 0
|
|
|
|
|
for _, request := range client.requests {
|
2026-11-22 04:45:39 +00:00
|
|
|
if nativeSchemaHasProperty(request, property) {
|
2026-07-23 13:59:02 +00:00
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
var _ promptkit.LLMClient = (*npcOccurrenceLLMClient)(nil)
|
2026-07-26 01:41:35 +00:00
|
|
|
|
2026-08-05 19:00:55 +00:00
|
|
|
type semanticNPCOccurrenceClient struct {
|
2026-11-22 04:45:39 +00:00
|
|
|
mu sync.Mutex
|
|
|
|
|
requests []promptkit.GenerateRequest
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
func (client *semanticNPCOccurrenceClient) Generate(ctx context.Context, request promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
|
|
|
|
client.mu.Lock()
|
|
|
|
|
defer client.mu.Unlock()
|
|
|
|
|
if err := ctx.Err(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
client.requests = append(client.requests, request)
|
2026-07-26 01:41:35 +00:00
|
|
|
var payload any
|
2026-11-22 04:45:39 +00:00
|
|
|
var unitID int
|
|
|
|
|
if nativeSchemaHasProperty(request, "npcs") || nativeSchemaHasProperty(request, "occurrences") {
|
|
|
|
|
content, err := nativeJSONInput(request, "units")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
var document struct {
|
|
|
|
|
Units []struct {
|
|
|
|
|
ID int `json:"id"`
|
|
|
|
|
} `json:"units"`
|
|
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(content, &document); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if len(document.Units) != 1 || document.Units[0].ID <= 0 {
|
|
|
|
|
return nil, fmt.Errorf("semantic fixture requires one source-addressed unit: %s", content)
|
|
|
|
|
}
|
|
|
|
|
unitID = document.Units[0].ID
|
|
|
|
|
}
|
|
|
|
|
switch {
|
|
|
|
|
case nativeSchemaHasProperty(request, "npcs"):
|
2026-07-26 01:41:35 +00:00
|
|
|
name := "Mira Thorn"
|
2026-11-22 04:45:39 +00:00
|
|
|
if unitID == 2 {
|
2026-07-26 01:41:35 +00:00
|
|
|
name = "Mira Thorn, the Greencloak"
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
payload = map[string]any{"npcs": []any{map[string]any{"name": name, "source_refs": []any{map[string]int{"start_unit_id": unitID, "end_unit_id": unitID}}}}}
|
|
|
|
|
case nativeSchemaHasProperty(request, "duplicate_groups"):
|
2026-08-29 03:16:24 +00:00
|
|
|
content := []byte(`{"duplicate_groups":[{"candidate_numbers":[1,2],"canonical_candidate_number":1}]}`)
|
2026-11-22 04:45:39 +00:00
|
|
|
return &promptkit.GenerateResponse{Content: string(content)}, nil
|
|
|
|
|
case nativeSchemaHasProperty(request, "occurrences"):
|
|
|
|
|
payload = map[string]any{"occurrences": []any{map[string]any{"name": "Mira Thorn", "kind": "dialogue", "source_refs": []any{map[string]int{"start_unit_id": unitID, "end_unit_id": unitID}}}}}
|
2026-07-26 01:41:35 +00:00
|
|
|
default:
|
2026-11-22 04:45:39 +00:00
|
|
|
return nil, fmt.Errorf("unexpected native occurrence response contract")
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
|
|
|
|
content, err := json.Marshal(payload)
|
|
|
|
|
if err != nil {
|
2026-11-22 04:45:39 +00:00
|
|
|
return nil, err
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
return &promptkit.GenerateResponse{Content: string(content)}, nil
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
func (client *semanticNPCOccurrenceClient) requestCount(property string) int {
|
2026-07-26 01:41:35 +00:00
|
|
|
count := 0
|
|
|
|
|
for _, request := range client.requests {
|
2026-11-22 04:45:39 +00:00
|
|
|
if nativeSchemaHasProperty(request, property) {
|
2026-07-26 01:41:35 +00:00
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
func (client *semanticNPCOccurrenceClient) requestFor(t *testing.T, property string) promptkit.GenerateRequest {
|
2026-07-26 01:41:35 +00:00
|
|
|
t.Helper()
|
|
|
|
|
for _, request := range client.requests {
|
2026-11-22 04:45:39 +00:00
|
|
|
if nativeSchemaHasProperty(request, property) {
|
2026-07-26 01:41:35 +00:00
|
|
|
return request
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-22 04:45:39 +00:00
|
|
|
t.Fatalf("requests = %#v, missing %q", client.requests, property)
|
|
|
|
|
return promptkit.GenerateRequest{}
|
2026-07-26 01:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-22 04:45:39 +00:00
|
|
|
var _ promptkit.LLMClient = (*semanticNPCOccurrenceClient)(nil)
|