Prepare combat-gated extraction without module-owned execution
This commit is contained in:
@@ -33,7 +33,7 @@ func TestExtractMapsAndOrdersCombatTurnsBySourcePosition(t *testing.T) {
|
||||
},
|
||||
}}}
|
||||
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), extractionRequest(t))
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), extractionRequest(t))
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func TestExtractPreservesInvalidCandidatesForValidators(t *testing.T) {
|
||||
SourceRefs: []combatSourceRefResponse{{StartUnitID: 99, EndUnitID: 0}},
|
||||
},
|
||||
}}}
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), extractionRequest(t))
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), extractionRequest(t))
|
||||
if err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil for candidate values", err)
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func TestExtractUsesDocumentOrderForReferencesAndTurns(t *testing.T) {
|
||||
req.Chunk.Ref = source.SourceRef{SourceID: req.Source.ID, StartUnitID: 10, EndUnitID: 30}
|
||||
req.References = sceneReferences(t, req.Chunk, dnd.SceneKindCombat)
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func TestExtractPassesReferencesAndNPCGroundingWithoutUsingItAsEvidence(t *testi
|
||||
references.Slots[name] = slot
|
||||
}
|
||||
req.References = references
|
||||
if _, err := newExtractor(t, client, references).Extract(context.Background(), req); err != nil {
|
||||
if _, err := runExtraction(context.Background(), newExtractor(t, client, references), req); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestExtractPassesReferencesAndNPCGroundingWithoutUsingItAsEvidence(t *testi
|
||||
func TestExtractUnboundRegistryUsesExactEmptyPromptAndOmitsIdentity(t *testing.T) {
|
||||
client := &fakeCombatTurnsLLMClient{response: extractionResponse{CombatTurns: []combatTurnResponse{}}}
|
||||
extractor := newExtractor(t, client)
|
||||
if _, err := extractor.Extract(context.Background(), extractionRequest(t)); err != nil {
|
||||
if _, err := runExtraction(context.Background(), extractor, extractionRequest(t)); err != nil {
|
||||
t.Fatalf("Extract() error = %v, want nil", err)
|
||||
}
|
||||
if input := renderedInput(t, client.requests[0], NPCRegistryReferenceSlot); string(input) != `{"npcs":[]}` {
|
||||
@@ -177,7 +177,7 @@ func TestExtractorResolvesOperationNPCOverrideWithoutSingletonMetadata(t *testin
|
||||
Slot: contracts.ReferenceSlot{Name: NPCRegistryReferenceSlot},
|
||||
Items: []contracts.ReferenceItem{{SlotName: NPCRegistryReferenceSlot, MediaType: npccodec.MediaType, Content: append([]byte(nil), content...), Origin: contracts.ReferenceOrigin{Type: "generated"}}},
|
||||
}
|
||||
if _, err := extractor.Extract(context.Background(), request); err != nil {
|
||||
if _, err := runExtraction(context.Background(), extractor, request); err != nil {
|
||||
t.Fatalf("Extract() error = %v", err)
|
||||
}
|
||||
if input := renderedInput(t, client.requests[0], NPCRegistryReferenceSlot); string(input) != `{"npcs":[{"name":"Mira Thorn"}]}` {
|
||||
@@ -268,7 +268,7 @@ func TestExtractAppliesSceneEligibilityBeforePromptConstruction(t *testing.T) {
|
||||
req.References = sceneListReferences(t, test.scenes...)
|
||||
}
|
||||
|
||||
result, err := newExtractor(t, client).Extract(context.Background(), req)
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client), req)
|
||||
if test.wantError != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), test.wantError) {
|
||||
t.Fatalf("Extract() error = %v, want %q", err, test.wantError)
|
||||
@@ -301,7 +301,7 @@ func TestNewRejectsMalformedNPCRegistryBeforeLLMCallWithoutContent(t *testing.T)
|
||||
Items: []contracts.ReferenceItem{{SlotName: NPCRegistryReferenceSlot, MediaType: "application/json", Content: []byte(`{"secret":"private transcript detail"}`)}},
|
||||
},
|
||||
}}
|
||||
_, err := New(newExtractor(t, client).engine, Options{}, references)
|
||||
_, err := New(Options{}, references)
|
||||
if err == nil || !strings.Contains(err.Error(), "prepare NPC registry") || strings.Contains(err.Error(), "private transcript detail") {
|
||||
t.Fatalf("New() error = %v, want bounded content-free registry failure", err)
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func TestNewRejectsInvalidSceneReferenceBeforeLLMCallWithoutContent(t *testing.T
|
||||
Items: []contracts.ReferenceItem{{SlotName: SceneDescriptionReferenceSlot, MediaType: scenecodec.MediaType, Content: []byte(`{"scenes":[]}`)}},
|
||||
},
|
||||
}}
|
||||
_, err := New(newExtractor(t, client).engine, Options{}, references)
|
||||
_, err := New(Options{}, references)
|
||||
if err == nil || !strings.Contains(err.Error(), "prepare scene eligibility") || strings.Contains(err.Error(), `{"scenes":[]}`) {
|
||||
t.Fatalf("New() error = %v, want bounded content-free scene failure", err)
|
||||
}
|
||||
@@ -330,28 +330,27 @@ func TestNewRejectsInvalidSceneReferenceBeforeLLMCallWithoutContent(t *testing.T
|
||||
func TestExtractRejectsInvalidRequestsAndWrapsProviderFailures(t *testing.T) {
|
||||
validReq := extractionRequest(t)
|
||||
validExtractor := newExtractor(t, &fakeCombatTurnsLLMClient{response: extractionResponse{CombatTurns: []combatTurnResponse{}}})
|
||||
var nilExtractor *Extractor
|
||||
var nilExtractor *extractionFixture
|
||||
tests := []struct {
|
||||
name string
|
||||
extractor *Extractor
|
||||
extractor *extractionFixture
|
||||
ctx context.Context
|
||||
req contracts.TypedExtractionRequest[dnd.CombatTurnList]
|
||||
want string
|
||||
}{
|
||||
{name: "nil extractor", extractor: nilExtractor, ctx: context.Background(), req: validReq, want: "extractor"},
|
||||
{name: "nil LLM client", 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 combat turns") || !strings.Contains(err.Error(), test.want) {
|
||||
t.Fatalf("Extract() error = %v, want %q context", err, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
_, err := newExtractor(t, &fakeCombatTurnsLLMClient{err: errors.New("provider unavailable")}).Extract(context.Background(), extractionRequest(t))
|
||||
if err == nil || !strings.Contains(err.Error(), "dnd combat turns") || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
_, err := runExtraction(context.Background(), newExtractor(t, &fakeCombatTurnsLLMClient{err: errors.New("provider unavailable")}), extractionRequest(t))
|
||||
if err == nil || !strings.Contains(err.Error(), "provider unavailable") {
|
||||
t.Fatalf("provider error = %v, want contextual wrapped error", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user