Migrate ordered NPC and location handoff tests to native execution

This commit is contained in:
2026-11-22 04:45:39 +00:00
parent 0ad73ff575
commit 562dfad5cd
9 changed files with 191 additions and 202 deletions

View File

@@ -10,15 +10,11 @@ import (
"testing"
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/evidencecontext"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
locationoccurrencecodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/locationoccurrences"
locationcodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/locationregistry"
locationoccurrences "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/extract/locationoccurrences"
locations "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/extract/locationregistry"
locationnormalize "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/normalize/locationregistry"
"go.maximumdirect.net/promptkit"
)
func TestLocationRegistryHandoffProducesOccurrencesAndEvidence(t *testing.T) {
@@ -29,15 +25,12 @@ func TestLocationRegistryHandoffProducesOccurrencesAndEvidence(t *testing.T) {
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if len(output.Rejected) != 0 || len(output.NormalizeOutputs) != 2 {
t.Fatalf("run outputs = %#v rejected = %#v, want accepted registry and occurrences", output.NormalizeOutputs, output.Rejected)
if len(output.OutputFiles) != 3 {
t.Fatalf("files=%#v, want two lanes and evidence", output.OutputFiles)
}
registryOutput := normalizedLane(t, output, "locations")
if registryOutput.Artifact.Kind != dnd.LocationRegistryKind || registryOutput.Artifact.Schema.ID != locationcodec.SchemaID {
t.Fatalf("registry envelope = %#v, want durable location artifact", registryOutput)
}
registry, err := locationcodec.New().Decode(registryOutput.Artifact.Content)
registryOutput := publishedLane(t, output, "locations")
registry, err := locationcodec.New().Decode(registryOutput.Bytes)
if err != nil {
t.Fatalf("Decode(registry) error = %v", err)
}
@@ -45,11 +38,8 @@ func TestLocationRegistryHandoffProducesOccurrencesAndEvidence(t *testing.T) {
t.Fatalf("registry = %#v, want same-name locations distinguished by source-derived IDs", registry)
}
occurrenceOutput := normalizedLane(t, output, "occurrences")
if occurrenceOutput.Artifact.Kind != dnd.LocationOccurrenceListKind || occurrenceOutput.Artifact.Schema.ID != locationoccurrencecodec.SchemaID {
t.Fatalf("occurrence envelope = %#v, want durable occurrence artifact", occurrenceOutput)
}
occurrences, err := locationoccurrencecodec.New().Decode(occurrenceOutput.Artifact.Content)
occurrenceOutput := publishedLane(t, output, "occurrences")
occurrences, err := locationoccurrencecodec.New().Decode(occurrenceOutput.Bytes)
if err != nil {
t.Fatalf("Decode(occurrences) error = %v", err)
}
@@ -62,11 +52,16 @@ func TestLocationRegistryHandoffProducesOccurrencesAndEvidence(t *testing.T) {
}
}
request := client.requestFor(t, locationoccurrences.PromptID)
registryInput := request.Inputs["location_registry"]
if registryInput.MediaType != locationcodec.MediaType || strings.Contains(string(registryInput.Content), "source_refs") || strings.Contains(string(registryInput.Content), registry.Locations[0].ID) || strings.Contains(string(registryInput.Content), registry.Locations[1].ID) || !strings.Contains(string(registryInput.Content), "registry_refs") {
t.Fatalf("occurrence registry input = %#v, want contextual selector projection", registryInput)
request := client.requestFor(t, "occurrences")
registryInput, err := nativeJSONInput(request, "locations")
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(registryInput), "source_refs") || strings.Contains(string(registryInput), registry.Locations[0].ID) || strings.Contains(string(registryInput), registry.Locations[1].ID) || !strings.Contains(string(registryInput), "registry_refs") {
t.Fatalf("registry input=%s, want contextual source-free selectors", registryInput)
}
contextArtifact := outputFileContent(t, output.OutputFiles, "evidence-context.json")
evidence, err := evidencecontext.New().Decode(contextArtifact)
if err != nil {
@@ -92,8 +87,8 @@ func TestLocationOccurrenceConsumerDoesNotRunAfterRejectedRegistry(t *testing.T)
if err == nil {
t.Fatal("Run() error = nil, want missing accepted location registry")
}
if client.requestCount(locationoccurrences.PromptID) != 0 {
t.Fatalf("occurrence requests = %d, want none after rejected registry", client.requestCount(locationoccurrences.PromptID))
if client.requestCount("occurrences") != 0 {
t.Fatalf("occurrence requests = %d, want none after rejected registry", client.requestCount("occurrences"))
}
}
@@ -106,24 +101,6 @@ func TestLocationOccurrenceConfigurationRequiresEarlierRegistry(t *testing.T) {
}
}
func TestLocationOccurrenceCheckpointTracksGeneratedRegistry(t *testing.T) {
registries := productionNPCRegistries(t)
checkpoint := newGeneratedReferenceCheckpointLoader()
_, err := runPreparedPipeline(t, registries, resolveLocationPipeline(t, registries), &locationHandoffLLMClient{}, pipeline.RunInput{
RawInput: readNPCFixture(t),
Checkpoint: checkpoint,
})
if err != nil {
t.Fatalf("Run() error = %v", err)
}
for _, dependency := range checkpoint.extractDependencies("occurrences") {
if dependency.Name == "generated-reference:location_registry:0" && strings.HasPrefix(dependency.Value, "sha256:") {
return
}
}
t.Fatalf("occurrence checkpoint dependencies = %#v, want generated location registry fingerprint", checkpoint.extractDependencies("occurrences"))
}
func resolveLocationPipeline(t *testing.T, registries pipeline.Registries) pipeline.ResolvedPipeline {
t.Helper()
cfg := loadIntegrationConfigText(t, locationPipelineConfig)
@@ -138,11 +115,7 @@ func resolveLocationPipeline(t *testing.T, registries pipeline.Registries) pipel
return resolved
}
const locationPipelineConfig = `version: 5
cache:
chunk_plans:
mode: bypass
checkpoints: {}
const locationPipelineConfig = `version: 6
pipelines:
dnd-locations-fixture:
input:
@@ -175,28 +148,28 @@ pipelines:
type locationHandoffLLMClient struct {
mu sync.Mutex
requests []contracts.StructuredCompletionRequest
requests []promptkit.GenerateRequest
rejectRegistry bool
}
func (client *locationHandoffLLMClient) CompleteStructured(ctx context.Context, request contracts.StructuredCompletionRequest, output any) (contracts.StructuredCompletionResponse, error) {
func (client *locationHandoffLLMClient) Generate(ctx context.Context, request promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
if err := ctx.Err(); err != nil {
return contracts.StructuredCompletionResponse{}, err
return nil, err
}
client.mu.Lock()
client.requests = append(client.requests, cloneStructuredCompletionRequest(request))
client.requests = append(client.requests, request)
client.mu.Unlock()
var payload any
switch request.PromptID {
case locations.PromptID:
switch {
case nativeSchemaHasProperty(request, "locations"):
name := "Moon Gate"
if client.rejectRegistry {
name = ""
}
payload = map[string]any{"locations": []any{map[string]any{"name": name, "source_refs": []any{map[string]int{"start_unit_id": 1, "end_unit_id": 1}}}, map[string]any{"name": name, "source_refs": []any{map[string]int{"start_unit_id": 3, "end_unit_id": 3}}}}}
case locationnormalize.PromptID:
case nativeSchemaHasProperty(request, "duplicate_groups"):
payload = map[string]any{"duplicate_groups": []any{}}
case locationoccurrences.PromptID:
case nativeSchemaHasProperty(request, "occurrences"):
var projection struct {
Locations []struct {
Name string `json:"name"`
@@ -206,48 +179,49 @@ func (client *locationHandoffLLMClient) CompleteStructured(ctx context.Context,
} `json:"registry_refs"`
} `json:"locations"`
}
if err := json.Unmarshal(request.Inputs["location_registry"].Content, &projection); err != nil {
return contracts.StructuredCompletionResponse{}, fmt.Errorf("decode location registry: %w", err)
content, err := nativeJSONInput(request, "locations")
if err != nil {
return nil, err
}
if err := json.Unmarshal(content, &projection); err != nil {
return nil, fmt.Errorf("decode location registry: %w", err)
}
if len(projection.Locations) != 2 {
return contracts.StructuredCompletionResponse{}, fmt.Errorf("generated location registry has %d locations, want 2", len(projection.Locations))
return nil, fmt.Errorf("generated location registry has %d locations, want 2", len(projection.Locations))
}
payload = map[string]any{"occurrences": []any{map[string]any{"name": projection.Locations[0].Name, "registry_refs": projection.Locations[0].RegistryRefs, "kind": "visited", "source_refs": []any{map[string]int{"start_unit_id": 1, "end_unit_id": 1}}}, map[string]any{"name": projection.Locations[1].Name, "registry_refs": projection.Locations[1].RegistryRefs, "kind": "mentioned", "source_refs": []any{map[string]int{"start_unit_id": 3, "end_unit_id": 3}}}}}
default:
return contracts.StructuredCompletionResponse{}, fmt.Errorf("unexpected prompt %q", request.PromptID)
return nil, fmt.Errorf("unexpected native location output contract")
}
content, err := json.Marshal(payload)
if err != nil {
return contracts.StructuredCompletionResponse{}, err
return nil, err
}
if err := json.Unmarshal(content, output); err != nil {
return contracts.StructuredCompletionResponse{}, err
}
return contracts.StructuredCompletionResponse{Content: content, Provider: "test", Model: "location-handoff"}, nil
return &promptkit.GenerateResponse{Content: string(content)}, nil
}
func (client *locationHandoffLLMClient) requestFor(t *testing.T, promptID string) contracts.StructuredCompletionRequest {
func (client *locationHandoffLLMClient) requestFor(t *testing.T, property string) promptkit.GenerateRequest {
t.Helper()
client.mu.Lock()
defer client.mu.Unlock()
for _, request := range client.requests {
if request.PromptID == promptID {
if nativeSchemaHasProperty(request, property) {
return request
}
}
t.Fatalf("requests = %#v, missing %q", client.requests, promptID)
return contracts.StructuredCompletionRequest{}
t.Fatalf("requests = %#v, missing %q", client.requests, property)
return promptkit.GenerateRequest{}
}
func (client *locationHandoffLLMClient) requestCount(promptID string) int {
func (client *locationHandoffLLMClient) requestCount(property string) int {
client.mu.Lock()
defer client.mu.Unlock()
count := 0
for _, request := range client.requests {
if request.PromptID == promptID {
if nativeSchemaHasProperty(request, property) {
count++
}
}
return count
}
var _ contracts.StructuredLLMClient = (*locationHandoffLLMClient)(nil)
var _ promptkit.LLMClient = (*locationHandoffLLMClient)(nil)