Migrate registry extraction to native correction and explicit empty fallbacks
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/promptkit"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
@@ -28,7 +30,10 @@ func TestExtractReturnsCanonicalNPCRegistryFromPrivateResponse(t *testing.T) {
|
||||
},
|
||||
}}}
|
||||
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), extractionRequest())
|
||||
callRequest := extractionRequest()
|
||||
var prepared promptkit.PreparedRun
|
||||
callRequest.Operation.Execution.OnPrepared = func(_ context.Context, value promptkit.PreparedRun) { prepared = value }
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), callRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -43,13 +48,11 @@ func TestExtractReturnsCanonicalNPCRegistryFromPrivateResponse(t *testing.T) {
|
||||
t.Fatalf("LLM calls = %d, want 1", len(client.requests))
|
||||
}
|
||||
request := client.requests[0]
|
||||
if request.StageName != Key || request.PromptID != PromptID || request.PromptVersion != SchemaVersion || request.ProfileID != "profile-npcs" || request.SessionID != "session-123" {
|
||||
t.Fatalf("LLM request identity = %#v", request)
|
||||
}
|
||||
transcript := request.Inputs["transcript"]
|
||||
if transcript.Name != "transcript" || transcript.MediaType != "application/json" || transcript.Digest != "sha256:chunk" || transcript.OriginURI != "file:///session-alpha.json" || string(transcript.Content) != string(extractionRequest().Chunk.Content) {
|
||||
t.Fatalf("transcript input = %#v, want chunk-scoped material", transcript)
|
||||
if prepared.PromptID != PromptID || prepared.SelectedProfileID != "profile-npcs" || request.Prompt.SessionID != "session-123" {
|
||||
t.Fatal("native registry routing lost")
|
||||
}
|
||||
messageContaining(t, request, string(callRequest.Chunk.Content))
|
||||
|
||||
}
|
||||
|
||||
func TestExtractOrdersNPCsBySourcePositionRatherThanUnitID(t *testing.T) {
|
||||
@@ -132,13 +135,15 @@ func TestExtractPassesCampaignReferencesAsPromptInputs(t *testing.T) {
|
||||
if _, err := newExtractor(t, client).Extract(context.Background(), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
inputs := client.requests[0].Inputs
|
||||
if string(inputs["players"].Content) != "Dana: Mira" || string(inputs["party"].Content) != "Mira: ranger" || string(inputs["glossary"].Content) != "Greencloak: local title" {
|
||||
t.Fatalf("reference inputs = %#v", inputs)
|
||||
request := client.requests[0]
|
||||
references := messageContaining(t, request, "Dana: Mira").Content
|
||||
if !strings.Contains(references, "Mira: ranger") || !strings.Contains(references, "Greencloak: local title") {
|
||||
t.Fatal("campaign references missing")
|
||||
}
|
||||
if strings.Contains(string(inputs["transcript"].Content), "local title") {
|
||||
t.Fatal("transcript input contains reference content")
|
||||
if strings.Contains(messageContaining(t, request, string(req.Chunk.Content)).Content, "local title") {
|
||||
t.Fatal("references became source evidence")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExtractPreservesMalformedCandidatesForValidators(t *testing.T) {
|
||||
@@ -173,38 +178,6 @@ func TestExtractMapsRawSemanticCandidatesWithoutRepair(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractForwardsCorrectionAndOwnsModelCandidate(t *testing.T) {
|
||||
rawResponse := []byte(`{"npcs":[{"name":"Mira Thorn","source_refs":[{"start_unit_id":1,"end_unit_id":1}]}]}`)
|
||||
client := &fakeNPCsLLMClient{content: append([]byte(nil), rawResponse...)}
|
||||
correction, err := contracts.NewSemanticCorrection([]byte(`{"npcs":[]}`), "Retain the transcript-grounded NPC.")
|
||||
if err != nil {
|
||||
t.Fatalf("NewSemanticCorrection() error = %v", err)
|
||||
}
|
||||
request := extractionRequest()
|
||||
request.Correction = correction
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), request)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
if len(client.requests) != 1 || client.requests[0].Correction == nil ||
|
||||
string(client.requests[0].Correction.AssistantResponse) != `{"npcs":[]}` ||
|
||||
client.requests[0].Correction.UserGuidance != "Retain the transcript-grounded NPC." {
|
||||
t.Fatalf("structured request correction = %#v, want forwarded correction", client.requests)
|
||||
}
|
||||
correction.AssistantResponse[0] = '['
|
||||
if got := string(client.requests[0].Correction.AssistantResponse); got != `{"npcs":[]}` {
|
||||
t.Fatalf("captured correction changed after caller mutation: %q", got)
|
||||
}
|
||||
if result.ModelCandidate == nil || result.ModelCandidate.Protocol != contracts.CorrectionProtocolSingleResponseV1 ||
|
||||
string(result.ModelCandidate.Response) != string(rawResponse) {
|
||||
t.Fatalf("model candidate = %#v, want exact validated response", result.ModelCandidate)
|
||||
}
|
||||
client.content[0] = '['
|
||||
if got := string(result.ModelCandidate.Response); got != string(rawResponse) {
|
||||
t.Fatalf("model candidate changed after provider buffer mutation: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractRetainsLocalErrorContextAndProviderFailures(t *testing.T) {
|
||||
request := extractionRequest()
|
||||
extractor := newExtractor(t, &fakeNPCsLLMClient{response: extractionResponse{NPCs: []npcResponse{}}})
|
||||
@@ -212,11 +185,11 @@ func TestExtractRetainsLocalErrorContextAndProviderFailures(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
extractor *Extractor
|
||||
req contracts.TypedExtractionRequest
|
||||
req contracts.TypedExtractionRequest[dnd.NPCRegistry]
|
||||
want string
|
||||
}{
|
||||
{name: "nil extractor", extractor: nilExtractor, req: request, want: "extractor"},
|
||||
{name: "nil LLM client", extractor: &Extractor{}, req: request, want: "LLM client"},
|
||||
{name: "nil native engine", extractor: &Extractor{}, req: request, want: "native engine"},
|
||||
{name: "wrapped preflight failure", extractor: extractor, req: mismatchedSourceInputRequest(request), want: "must match chunk"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user