Implement NPC extraction follow-up fixes

This commit is contained in:
2026-07-20 23:10:25 -05:00
parent 20cfbfd311
commit c6f330eb06
13 changed files with 133 additions and 757 deletions

View File

@@ -56,6 +56,38 @@ func TestExtractReturnsCanonicalNPCListFromPrivateResponse(t *testing.T) {
}
}
func TestExtractOrdersNPCsBySourcePositionRatherThanUnitID(t *testing.T) {
client := &fakeNPCsLLMClient{response: extractionResponse{NPCs: []npcResponse{
{
Name: "Later NPC", Aliases: []string{}, Description: "Appears later.", Relationships: []npcRelationshipResponse{},
SourceRefs: responseSourceRefs(10, 10),
},
{
Name: "Earlier NPC", Aliases: []string{}, Description: "Appears first.", Relationships: []npcRelationshipResponse{},
SourceRefs: []npcSourceRefResponse{
{StartUnitID: sharedUnitRef(50), EndUnitID: sharedUnitRef(50)},
{StartUnitID: sharedUnitRef(100), EndUnitID: sharedUnitRef(100)},
},
},
}}}
req := extractionRequest()
req.Source.Units = []source.SourceUnit{
{ID: 100, Kind: "transcript_segment", Text: "Earlier NPC appears."},
{ID: 10, Kind: "transcript_segment", Text: "Later NPC appears."},
{ID: 50, Kind: "transcript_segment", Text: "Earlier NPC appears again."},
}
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)
if err != nil {
t.Fatalf("Extract() error = %v, want nil", err)
}
if len(result.Value.NPCs) != 2 || result.Value.NPCs[0].Name != "Earlier NPC" || result.Value.NPCs[1].Name != "Later NPC" {
t.Fatalf("NPC order = %#v, want source-document order", result.Value.NPCs)
}
}
func TestExtractPassesCampaignReferencesAsPromptInputs(t *testing.T) {
client := &fakeNPCsLLMClient{response: extractionResponse{NPCs: []npcResponse{}}}
req := extractionRequest()