Centralize D&D extraction request preparation

This commit is contained in:
2026-07-24 14:38:42 +00:00
parent 8e0b029f5f
commit e2cb0d901a
15 changed files with 144 additions and 185 deletions

View File

@@ -204,24 +204,21 @@ func TestExtractRejectsInvalidRequestsAndProviderFailures(t *testing.T) {
references := requiredRegistryReferences(t, "Mira Thorn")
valid := extractionRequest()
valid.References = references
canceled, cancel := context.WithCancel(context.Background())
cancel()
extractor := newExtractor(t, &fakeInteractionsLLMClient{}, references)
var nilExtractor *Extractor
for _, test := range []struct {
name string
ctx context.Context
req contracts.TypedExtractionRequest
want string
name string
extractor *Extractor
ctx context.Context
req contracts.TypedExtractionRequest
want string
}{
{"nil context", nil, valid, "context"},
{"canceled context", canceled, valid, "context"},
{"nil source", context.Background(), contracts.TypedExtractionRequest{Chunk: valid.Chunk, References: references}, "source"},
{"nil chunk", context.Background(), contracts.TypedExtractionRequest{Source: valid.Source, References: references}, "chunk"},
{"empty chunk", context.Background(), emptyChunkRequest(valid), "units"},
{"source input mismatch", context.Background(), mismatchedSourceInputRequest(valid), "must match chunk"},
{"nil extractor", nilExtractor, context.Background(), valid, "extractor"},
{"nil LLM client", &Extractor{}, context.Background(), valid, "LLM client"},
{"wrapped preflight failure", extractor, context.Background(), mismatchedSourceInputRequest(valid), "must match chunk"},
} {
t.Run(test.name, func(t *testing.T) {
if _, err := extractor.Extract(test.ctx, test.req); err == nil || !strings.Contains(err.Error(), test.want) {
if _, err := test.extractor.Extract(test.ctx, test.req); err == nil || !strings.Contains(err.Error(), test.want) {
t.Fatalf("Extract() error = %v, want %q", err, test.want)
}
})
@@ -361,11 +358,6 @@ func interactionKinds(value dnd.NPCInteractionList) []dnd.NPCInteractionKind {
return kinds
}
func emptyChunkRequest(req contracts.TypedExtractionRequest) contracts.TypedExtractionRequest {
req.Chunk = &source.Chunk{ID: req.Chunk.ID, SourceID: req.Chunk.SourceID, Index: req.Chunk.Index}
return req
}
func mismatchedSourceInputRequest(req contracts.TypedExtractionRequest) contracts.TypedExtractionRequest {
req.SourceInput = contracts.NewLLMInputMaterial("source", "application/json", []byte(`{"different":true}`), "sha256:other", "")
return req