Prepare shared context for all D&D extractors
This commit is contained in:
@@ -262,20 +262,20 @@ func loadGroundedPipelineConfig(t *testing.T) config.Config {
|
||||
func configureGroundedCampaignReferences(t *testing.T, cfg *config.Config) map[string]string {
|
||||
t.Helper()
|
||||
values := map[string]string{
|
||||
"party": "Mira Thorn: ally\n",
|
||||
"glossary": "Greencloak: Mira Thorn's title\n",
|
||||
"party": `{"schema_version":"maximumdirect.rpg.party.v1","characters":{"m":{"character":{"name":"Mira Thorn","aliases":["Ally"]}}}}`,
|
||||
"glossary": `{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"g","name":"Greencloak","category":"title","description":"Mira Thorn's title"}]}}}`,
|
||||
}
|
||||
profile := cfg.Pipelines["dnd-npc-grounded"]
|
||||
profile.References = make(map[string]pipeline.ReferenceSource, len(values))
|
||||
for name, content := range values {
|
||||
path := filepath.Join(t.TempDir(), name+".txt")
|
||||
path := filepath.Join(t.TempDir(), name+".json")
|
||||
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
|
||||
t.Fatalf("write %s reference: %v", name, err)
|
||||
}
|
||||
profile.References[name] = pipeline.ExternalReference(path)
|
||||
}
|
||||
cfg.Pipelines["dnd-npc-grounded"] = profile
|
||||
return values
|
||||
return map[string]string{"party": "Ally", "glossary": "Greencloak"}
|
||||
}
|
||||
|
||||
func runGroundedPipeline(t *testing.T, configValue config.Config, registries pipeline.Registries, client *groundedDNDLLMClient) pipeline.RunOutput {
|
||||
|
||||
@@ -93,8 +93,8 @@ func TestRunnerPassesPartyAndGlossaryReferencesToDNDSpellsPrompt(t *testing.T) {
|
||||
raw := readDNDSpellsFixture(t)
|
||||
resolved := resolveDNDSpellsPipeline(t)
|
||||
resolved.ResolvedPipeline.Steps[0].ArtifactLanes[0].ExtractReferences.ReferenceSet = dndSpellsReferenceSet(
|
||||
"Aria: party cleric\nBorin: fighter",
|
||||
"Fire Bolt: evocation cantrip",
|
||||
`{"schema_version":"maximumdirect.rpg.party.v1","characters":{"a":{"character":{"name":"Aria","classes":[{"name":"cleric"}]},"player":{"name":"Alice"}},"b":{"character":{"name":"Borin","classes":[{"name":"fighter"}]}}}}`,
|
||||
`{"schema_version":"maximumdirect.glossary.v1","collections":{"campaign":{"entries":[{"id":"f","name":"Fire Bolt","category":"spell","description":"evocation cantrip"}]}}}`,
|
||||
)
|
||||
llmClient := &fakeSpellsLLMClient{
|
||||
response: extractionResponse{
|
||||
@@ -122,7 +122,7 @@ func TestRunnerPassesPartyAndGlossaryReferencesToDNDSpellsPrompt(t *testing.T) {
|
||||
t.Fatalf("LLM calls = %d, want 1", len(llmClient.requests))
|
||||
}
|
||||
request := llmClient.requests[0]
|
||||
for _, value := range []string{"Aria: party cleric\nBorin: fighter", "Fire Bolt: evocation cantrip"} {
|
||||
for _, value := range []string{"cleric", "fighter", "Alice", "evocation cantrip"} {
|
||||
if !strings.Contains(nativePromptText(request), value) {
|
||||
t.Fatalf("rendered prompt omitted %q", value)
|
||||
}
|
||||
@@ -197,10 +197,10 @@ func dndSpellsReferenceSet(party string, glossary string) contracts.ReferenceSet
|
||||
Items: []contracts.ReferenceItem{
|
||||
{
|
||||
SlotName: "party",
|
||||
MediaType: "text/plain; charset=utf-8",
|
||||
MediaType: "application/json",
|
||||
Content: []byte(party),
|
||||
Digest: "sha256:party",
|
||||
Origin: contracts.ReferenceOrigin{Type: "file", URI: "file:///tmp/party.txt"},
|
||||
Origin: contracts.ReferenceOrigin{Type: "file", URI: "file:///tmp/party.json"},
|
||||
SizeBytes: int64(len(party)),
|
||||
BindingSource: contracts.ReferenceBindingSourceConfig,
|
||||
},
|
||||
@@ -213,10 +213,10 @@ func dndSpellsReferenceSet(party string, glossary string) contracts.ReferenceSet
|
||||
Items: []contracts.ReferenceItem{
|
||||
{
|
||||
SlotName: "glossary",
|
||||
MediaType: "text/plain; charset=utf-8",
|
||||
MediaType: "application/json",
|
||||
Content: []byte(glossary),
|
||||
Digest: "sha256:glossary",
|
||||
Origin: contracts.ReferenceOrigin{Type: "file", URI: "file:///tmp/glossary.txt"},
|
||||
Origin: contracts.ReferenceOrigin{Type: "file", URI: "file:///tmp/glossary.json"},
|
||||
SizeBytes: int64(len(glossary)),
|
||||
BindingSource: contracts.ReferenceBindingSourceConfig,
|
||||
},
|
||||
|
||||
@@ -103,8 +103,8 @@ func TestNativeSpellPipelineAssessesEveryCandidateOnce(t *testing.T) {
|
||||
bindings = append(bindings, pipeline.Binding(validator.Name()))
|
||||
names = append(names, validator.Name())
|
||||
}
|
||||
partyFile := filepath.Join(t.TempDir(), "party.txt")
|
||||
check(os.WriteFile(partyFile, []byte("party-grounding-sentinel: Aria"), 0600))
|
||||
partyFile := filepath.Join(t.TempDir(), "party.json")
|
||||
check(os.WriteFile(partyFile, []byte(`{"schema_version":"maximumdirect.rpg.party.v1","characters":{"a":{"character":{"name":"Aria","aliases":["party-grounding-sentinel"]}}}}`), 0600))
|
||||
turns := 2
|
||||
profile := pipeline.PipelineProfile{
|
||||
ID: "native-spells", Input: pipeline.Binding(transcript.Key),
|
||||
|
||||
Reference in New Issue
Block a user