Route spell extraction through core preparation with remaining extractors pending
This commit is contained in:
@@ -30,7 +30,7 @@ func TestExtractReturnsCanonicalSpellListFromPrivateResponse(t *testing.T) {
|
||||
req.Operation.Execution.OnPrepared = func(_ context.Context, value promptkit.PreparedRun) { prepared = value }
|
||||
|
||||
extractor := newExtractor(t, client)
|
||||
result, err := extractor.Extract(context.Background(), req)
|
||||
result, err := runExtraction(context.Background(), extractor, req)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func TestExtractReturnsCanonicalSpellListFromPrivateResponse(t *testing.T) {
|
||||
func TestExtractPromptProjectsCanonicalNamesAndAliasesWithoutMetadata(t *testing.T) {
|
||||
client := &fakeSpellsLLMClient{response: extractionResponse{SpellCasts: []spellCastResponse{}}}
|
||||
extractor := newExtractor(t, client, overlaySpellCatalogReference())
|
||||
if _, err := extractor.Extract(context.Background(), extractionRequest()); err != nil {
|
||||
if _, err := runExtraction(context.Background(), extractor, extractionRequest()); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
input := extractor.catalogPromptInput
|
||||
@@ -126,7 +126,7 @@ func TestExtractUsesAliasRecognitionToRequestCanonicalSpellNames(t *testing.T) {
|
||||
request.Chunk.Content = []byte(`{"segments":[{"id":1,"text":"Aria invokes Emberfall Aegis."}]}`)
|
||||
request.SourceInput = spellChunkInput(request.Chunk)
|
||||
|
||||
result, err := newExtractor(t, client, overlaySpellCatalogReference()).Extract(context.Background(), request)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client, overlaySpellCatalogReference()), request)
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -145,10 +145,10 @@ func TestExtractAliasOnlyCatalogChangesPromptMaterial(t *testing.T) {
|
||||
aliasClient := &fakeSpellsLLMClient{response: extractionResponse{SpellCasts: []spellCastResponse{}}}
|
||||
baseExtractor := newExtractor(t, baseClient)
|
||||
aliasExtractor := newExtractor(t, aliasClient, aliasReference)
|
||||
if _, err := baseExtractor.Extract(context.Background(), extractionRequest()); err != nil {
|
||||
if _, err := runExtraction(context.Background(), baseExtractor, extractionRequest()); err != nil {
|
||||
t.Fatalf("base Extract() error = %v", err)
|
||||
}
|
||||
if _, err := aliasExtractor.Extract(context.Background(), extractionRequest()); err != nil {
|
||||
if _, err := runExtraction(context.Background(), aliasExtractor, extractionRequest()); err != nil {
|
||||
t.Fatalf("alias Extract() error = %v", err)
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func TestExtractAliasOnlyCatalogChangesPromptMaterial(t *testing.T) {
|
||||
|
||||
func TestNewRejectsMalformedCatalogBeforeLLMCall(t *testing.T) {
|
||||
client := &fakeSpellsLLMClient{}
|
||||
_, err := New(newSpellEngine(t, client), Options{}, spellCatalogReference(`{"schema_version":"notarius.dnd.spell-catalog-overlay.v2","catalogs":[]}`))
|
||||
_, err := New(Options{}, spellCatalogReference(`{"schema_version":"notarius.dnd.spell-catalog-overlay.v2","catalogs":[]}`))
|
||||
if err == nil || !strings.Contains(err.Error(), "resolve effective spell catalog") {
|
||||
t.Fatalf("New() error = %v, want effective catalog error", err)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func TestExtractPassesReferencesAsPromptInputs(t *testing.T) {
|
||||
"glossary": {Slot: contracts.ReferenceSlot{Name: "glossary"}, Items: []contracts.ReferenceItem{{SlotName: "glossary", Content: []byte("Brightmantle: local temple name")}}},
|
||||
}}
|
||||
|
||||
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)
|
||||
}
|
||||
text := promptText(client.requests[0])
|
||||
@@ -203,7 +203,7 @@ func TestPromptInputsMapLegacyRosterReferenceToParty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractPreservesValidEmptyCollection(t *testing.T) {
|
||||
result, err := newExtractor(t, &fakeSpellsLLMClient{content: []byte(`{"spell_casts":[]}`)}).Extract(context.Background(), extractionRequest())
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, &fakeSpellsLLMClient{content: []byte(`{"spell_casts":[]}`)}), extractionRequest())
|
||||
if err != nil || result.Value.SpellCasts == nil || len(result.Value.SpellCasts) != 0 {
|
||||
t.Fatalf("empty collection: %#v %v", result, err)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func TestExtractDoesNotAssessNativeStructuralFailure(t *testing.T) {
|
||||
assessed++
|
||||
return contracts.CandidateAssessment{}, nil
|
||||
}
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), request)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), request)
|
||||
if assessed != 0 {
|
||||
t.Fatal("structurally invalid native result reached typed validation")
|
||||
}
|
||||
@@ -237,8 +237,8 @@ func TestExtractDoesNotAssessNativeStructuralFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExtractWrapsLLMClientError(t *testing.T) {
|
||||
_, err := newExtractor(t, &fakeSpellsLLMClient{err: errors.New("provider unavailable")}).Extract(context.Background(), extractionRequest())
|
||||
if err == nil || !strings.Contains(err.Error(), "dnd spells") || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
_, err := runExtraction(context.Background(), newExtractor(t, &fakeSpellsLLMClient{err: errors.New("provider unavailable")}), extractionRequest())
|
||||
if err == nil || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
t.Fatalf("Extract() error = %v, want wrapped provider error", err)
|
||||
}
|
||||
}
|
||||
@@ -246,21 +246,20 @@ func TestExtractWrapsLLMClientError(t *testing.T) {
|
||||
func TestExtractRejectsInvalidRequests(t *testing.T) {
|
||||
validReq := extractionRequest()
|
||||
validExtractor := newExtractor(t, &fakeSpellsLLMClient{response: extractionResponse{SpellCasts: []spellCastResponse{}}})
|
||||
var nilExtractor *Extractor
|
||||
nilExtractor := &extractionFixture{engine: newSpellEngine(t, &fakeSpellsLLMClient{})}
|
||||
tests := []struct {
|
||||
name string
|
||||
extractor *Extractor
|
||||
extractor *extractionFixture
|
||||
ctx context.Context
|
||||
req contracts.TypedExtractionRequest[dnd.SpellList]
|
||||
want string
|
||||
}{
|
||||
{name: "nil extractor", extractor: nilExtractor, ctx: context.Background(), req: validReq, want: "extractor"},
|
||||
{name: "nil native engine", extractor: &Extractor{}, ctx: context.Background(), req: validReq, want: "native engine"},
|
||||
{name: "wrapped preflight failure", extractor: validExtractor, ctx: context.Background(), req: mismatchedSourceInputRequest(validReq), want: "must match chunk"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, err := test.extractor.Extract(test.ctx, test.req)
|
||||
_, err := runExtraction(test.ctx, test.extractor, test.req)
|
||||
if err == nil || !strings.Contains(err.Error(), "dnd spells") || !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("Extract() error = %v, want %q context", err, test.want)
|
||||
}
|
||||
@@ -274,7 +273,7 @@ func TestExtractOrdersAndDeduplicatesEvidence(t *testing.T) {
|
||||
{Caster: "Aria", Spell: "Cure Wounds", SourceRefs: []spellSourceRefResponse{{StartUnitID: 1, EndUnitID: 2}, {StartUnitID: 1, EndUnitID: 2}}},
|
||||
{Caster: "Narrator", Spell: "Unknown", SourceRefs: []spellSourceRefResponse{}},
|
||||
}}}
|
||||
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)
|
||||
}
|
||||
@@ -302,7 +301,7 @@ func TestExtractUsesDocumentOrderForReferencesAndSpellCasts(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)
|
||||
}
|
||||
@@ -328,7 +327,7 @@ func TestExtractPreservesStableSpellOrderForEqualEvidence(t *testing.T) {
|
||||
{Caster: "First", Spell: "Cure Wounds", SourceRefs: responseSourceRefs(2, 2)},
|
||||
{Caster: "Second", Spell: "Fire Bolt", SourceRefs: responseSourceRefs(2, 2)},
|
||||
}}}
|
||||
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", err)
|
||||
}
|
||||
@@ -342,7 +341,7 @@ func TestExtractPreservesInvalidEvidenceForValidators(t *testing.T) {
|
||||
Caster: "Aria", Spell: "Cure Wounds",
|
||||
SourceRefs: []spellSourceRefResponse{{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)
|
||||
}
|
||||
@@ -354,7 +353,7 @@ func TestExtractPreservesInvalidEvidenceForValidators(t *testing.T) {
|
||||
|
||||
func TestExtractMapsRawSemanticCandidatesWithoutRepair(t *testing.T) {
|
||||
client := &fakeSpellsLLMClient{content: []byte(`{"spell_casts":[{"caster":"","spell":"Cure Wounds","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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user