Prepare NPC item and location registry extraction in core
This commit is contained in:
@@ -18,7 +18,7 @@ func TestExtractMapsLocationsWithOwnedEvidenceAndDeterministicOrder(t *testing.T
|
||||
{Name: "The Tavern", SourceRefs: responseSourceRefs(3, 2)},
|
||||
{Name: "Old Mill", SourceRefs: []locationSourceRefResponse{{StartUnitID: 2, EndUnitID: 2}, {StartUnitID: 1, EndUnitID: 1}, {StartUnitID: 1, EndUnitID: 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)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func TestExtractRetainsSameNameLocationsAtDifferentAnchors(t *testing.T) {
|
||||
{Name: "the tavern", SourceRefs: responseSourceRefs(1, 1)},
|
||||
{Name: "the tavern", SourceRefs: responseSourceRefs(3, 3)},
|
||||
}}}
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), extractionRequest())
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), extractionRequest())
|
||||
if err != nil || len(result.Value.Locations) != 2 {
|
||||
t.Fatalf("Extract() = %#v, %v; want both same-name candidates", result, err)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func TestExtractRetainsSameNameLocationsAtDifferentAnchors(t *testing.T) {
|
||||
|
||||
func TestExtractPreservesInvalidCandidatesForValidators(t *testing.T) {
|
||||
client := &fakeLocationsLLMClient{content: []byte(`{"locations":[{"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)
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func TestExtractPassesReferencesWithoutTreatingThemAsEvidence(t *testing.T) {
|
||||
req.References = contracts.ReferenceSet{Slots: map[string]contracts.ResolvedReferenceSlot{
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Old Mill: abandoned granary")}}},
|
||||
}}
|
||||
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", err)
|
||||
}
|
||||
messageContaining(t, client.requests[0], "Old Mill: abandoned granary")
|
||||
@@ -88,7 +88,7 @@ func TestExtractDoesNotMutateRequestMaterials(t *testing.T) {
|
||||
beforeUnits := append([]source.SourceUnit(nil), req.Source.Units...)
|
||||
beforeChunkUnits := append([]source.SourceUnit(nil), req.Chunk.Units...)
|
||||
beforeContent := append([]byte(nil), req.Chunk.Content...)
|
||||
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", err)
|
||||
}
|
||||
if !reflect.DeepEqual(req.Source.Units, beforeUnits) || !reflect.DeepEqual(req.Chunk.Units, beforeChunkUnits) || !reflect.DeepEqual(req.Chunk.Content, beforeContent) {
|
||||
@@ -97,30 +97,29 @@ func TestExtractDoesNotMutateRequestMaterials(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractHandlesEmptyOutputAndLocalFailures(t *testing.T) {
|
||||
empty, err := newExtractor(t, &fakeLocationsLLMClient{response: extractionResponse{Locations: []locationResponse{}}}).Extract(context.Background(), extractionRequest())
|
||||
empty, err := runExtraction(context.Background(), newExtractor(t, &fakeLocationsLLMClient{response: extractionResponse{Locations: []locationResponse{}}}), extractionRequest())
|
||||
if err != nil || empty.Value.Locations == nil || len(empty.Value.Locations) != 0 {
|
||||
t.Fatalf("empty Extract() = %#v, %v; want empty list", empty, err)
|
||||
}
|
||||
request := extractionRequest()
|
||||
var nilExtractor *Extractor
|
||||
var nilExtractor *extractionFixture
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
extractor *Extractor
|
||||
extractor *extractionFixture
|
||||
req contracts.TypedExtractionRequest[dnd.LocationRegistry]
|
||||
want string
|
||||
}{
|
||||
{name: "nil extractor", extractor: nilExtractor, req: request, want: "extractor"},
|
||||
{name: "nil client", extractor: &Extractor{}, req: request, want: "native engine"},
|
||||
{name: "preflight", extractor: newExtractor(t, &fakeLocationsLLMClient{}), 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 location registry") || !strings.Contains(err.Error(), test.want) {
|
||||
if _, err := runExtraction(context.Background(), test.extractor, test.req); err == nil || !strings.Contains(err.Error(), "dnd location registry") || !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("Extract() error = %v, want local context", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
_, err = newExtractor(t, &fakeLocationsLLMClient{err: errors.New("provider unavailable")}).Extract(context.Background(), request)
|
||||
if err == nil || !strings.Contains(err.Error(), "dnd location registry") || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
_, err = runExtraction(context.Background(), newExtractor(t, &fakeLocationsLLMClient{err: errors.New("provider unavailable")}), request)
|
||||
if err == nil || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
t.Fatalf("provider error = %v, want contextual provider error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user