Prepare NPC item and location registry extraction in core
This commit is contained in:
@@ -33,7 +33,7 @@ func TestExtractReturnsCanonicalNPCRegistryFromPrivateResponse(t *testing.T) {
|
||||
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)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), callRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func TestExtractOrdersNPCsBySourcePositionRatherThanUnitID(t *testing.T) {
|
||||
req.Chunk.Units = append([]source.SourceUnit(nil), req.Source.Units...)
|
||||
req.Chunk.Ref = source.SourceRef{SourceID: req.Source.ID, StartUnitID: 100, EndUnitID: 50}
|
||||
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), req)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), req)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func TestExtractUsesDocumentOrderForNPCReferencesAndStableTies(t *testing.T) {
|
||||
req.Chunk.Units = append([]source.SourceUnit(nil), req.Source.Units...)
|
||||
req.Chunk.Ref = source.SourceRef{SourceID: req.Source.ID, StartUnitID: 30, EndUnitID: 10}
|
||||
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), req)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), req)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v", err)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func TestExtractPassesCampaignReferencesAsPromptInputs(t *testing.T) {
|
||||
"party": {Slot: contracts.ReferenceSlot{Name: "party"}, Items: []contracts.ReferenceItem{{SlotName: "party", Content: []byte("Mira: ranger")}}},
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Greencloak: local title")}}},
|
||||
}}
|
||||
if _, err := newExtractor(t, client).Extract(context.Background(), req); err != nil {
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
request := client.requests[0]
|
||||
@@ -151,7 +151,7 @@ func TestExtractPreservesMalformedCandidatesForValidators(t *testing.T) {
|
||||
Name: "",
|
||||
SourceRefs: []npcSourceRefResponse{{StartUnitID: 99, EndUnitID: 0}},
|
||||
}}}}
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), extractionRequest())
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), extractionRequest())
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func TestExtractPreservesMalformedCandidatesForValidators(t *testing.T) {
|
||||
|
||||
func TestExtractMapsRawSemanticCandidatesWithoutRepair(t *testing.T) {
|
||||
client := &fakeNPCsLLMClient{content: []byte(`{"npcs":[{"name":"","source_refs":[{"start_unit_id":0,"end_unit_id":-1}]}]}`)}
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), extractionRequest())
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), extractionRequest())
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -181,25 +181,24 @@ func TestExtractMapsRawSemanticCandidatesWithoutRepair(t *testing.T) {
|
||||
func TestExtractRetainsLocalErrorContextAndProviderFailures(t *testing.T) {
|
||||
request := extractionRequest()
|
||||
extractor := newExtractor(t, &fakeNPCsLLMClient{response: extractionResponse{NPCs: []npcResponse{}}})
|
||||
var nilExtractor *Extractor
|
||||
var nilExtractor *extractionFixture
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
extractor *Extractor
|
||||
extractor *extractionFixture
|
||||
req contracts.TypedExtractionRequest[dnd.NPCRegistry]
|
||||
want string
|
||||
}{
|
||||
{name: "nil extractor", extractor: nilExtractor, req: request, want: "extractor"},
|
||||
{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) {
|
||||
if _, err := test.extractor.Extract(context.Background(), test.req); err == nil || !strings.Contains(err.Error(), "dnd npc registry") || !strings.Contains(err.Error(), test.want) {
|
||||
if _, err := runExtraction(context.Background(), test.extractor, test.req); err == nil || !strings.Contains(err.Error(), "dnd npc registry") || !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("Extract() error = %v, want contextual local error", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
_, err := newExtractor(t, &fakeNPCsLLMClient{err: errors.New("provider unavailable")}).Extract(context.Background(), request)
|
||||
if err == nil || !strings.Contains(err.Error(), "dnd npc registry") || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
_, err := runExtraction(context.Background(), newExtractor(t, &fakeNPCsLLMClient{err: errors.New("provider unavailable")}), request)
|
||||
if err == nil || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
t.Fatalf("provider Extract() error = %v, want contextual provider error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user