Enable correction-aware foundational D&D producers

This commit is contained in:
2026-08-26 23:55:23 +00:00
parent 1a7b20c766
commit 759d32403f
16 changed files with 168 additions and 68 deletions

View File

@@ -173,6 +173,38 @@ 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{}}})