Update examples and tests for shared glossaries
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -13,6 +14,55 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestGlossaryAuthoringExamplesResolve(t *testing.T) {
|
||||
examples, err := filepath.Abs(filepath.Join("..", "..", "examples"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name, fragment, selectors, campaign, setting, spells string
|
||||
}{
|
||||
{name: "inline", fragment: "inline-only.yml", campaign: "Silver Watch", setting: "entries: []", spells: "entries: []"},
|
||||
{name: "file", fragment: "file-only.yml", campaign: "Lantern Watch", setting: "entries: []", spells: "entries: []"},
|
||||
{name: "combined with catalog", fragment: "combined.yml", selectors: " setting: lantern_coast\n system: sample_magic\n", campaign: "Silver Watch", setting: "North Harbor", spells: "Lantern Glow"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
fragment := filepath.Join("glossary-authoring", tc.fragment)
|
||||
for _, name := range []string{fragment, "glossary.yml"} {
|
||||
data, err := os.ReadFile(filepath.Join(examples, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writePipelineFixture(t, dir, name, string(data))
|
||||
}
|
||||
campaign := writePipelineFixture(t, dir, "campaign.yml", fmt.Sprintf(`config:
|
||||
imports:
|
||||
- path: %q
|
||||
campaign_id: sample-campaign
|
||||
inputs:
|
||||
speakers_file: %q
|
||||
autocorrect_file: %q
|
||||
party_file: %q
|
||||
%s`, fragment, filepath.Join(examples, "campaigns", "sample-campaign", "speakers.yml"), filepath.Join(examples, "campaigns", "sample-campaign", "autocorrect.yml"), filepath.Join(examples, "campaigns", "sample-campaign", "party.yml"), tc.selectors))
|
||||
session := writePipelineFixture(t, dir, "session.yml", "session_id: session\ninputs: {audio_dir: audio}\n")
|
||||
cfg, err := LoadWithSessionOptions(filepath.Join(examples, "pipeline.catalog.yml"), campaign, session, SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
docs, err := ResolveGlossaries(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for role, want := range map[string]string{"campaign": tc.campaign, "setting": tc.setting, "spells": tc.spells} {
|
||||
if !strings.Contains(string(docs[role]), want) {
|
||||
t.Fatalf("%s = %s; want %q", role, docs[role], want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepresentativeLoadDefaultsAndValidation(t *testing.T) {
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, `whisperx:
|
||||
transcribe_url: https://transcription.example.com/transcribe
|
||||
@@ -261,6 +311,7 @@ func TestExamplesLoadAndValidate(t *testing.T) {
|
||||
t.Setenv("NOTARIUS_LLM_API_KEY", "synthetic-example-notarius-key")
|
||||
examplesDir := filepath.Join("..", "..", "examples")
|
||||
if got, want := maintainedPipelineRoots(t, examplesDir), []string{
|
||||
"pipeline.catalog.yml",
|
||||
"pipeline.extraction-subset.yml",
|
||||
"pipeline.full.annotated.yml",
|
||||
"pipeline.minimal.yml",
|
||||
@@ -274,6 +325,7 @@ func TestExamplesLoadAndValidate(t *testing.T) {
|
||||
pipelineFile string
|
||||
sessionFile string
|
||||
}{
|
||||
{name: "catalog pipeline with local audio session", pipelineFile: "pipeline.catalog.yml", sessionFile: "session.local-audio.yml"},
|
||||
{
|
||||
name: "minimal pipeline with local audio session",
|
||||
pipelineFile: "pipeline.minimal.yml",
|
||||
|
||||
@@ -359,7 +359,7 @@ func TestNotariusReferenceValidationAndNormalization(t *testing.T) {
|
||||
cfg.References = map[string]string{
|
||||
" party ": " narratio.input.party ",
|
||||
" chunk . players ": "narratio.input.players",
|
||||
" npc-registry . extract . glossary ": "narratio.input.glossary",
|
||||
" npc-registry . extract . glossary ": "narratio.input.glossary.campaign",
|
||||
"spells": "narratio.input.spell_catalog",
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ func TestNotariusReferenceValidationAndNormalization(t *testing.T) {
|
||||
want := map[string]string{
|
||||
"party": "narratio.input.party",
|
||||
"chunk.players": "narratio.input.players",
|
||||
"npc-registry.extract.glossary": "narratio.input.glossary",
|
||||
"npc-registry.extract.glossary": "narratio.input.glossary.campaign",
|
||||
"spells": "narratio.input.spell_catalog",
|
||||
}
|
||||
if len(cfg.References) != len(want) {
|
||||
|
||||
@@ -247,7 +247,7 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
||||
source: narratio.input.party
|
||||
required: true
|
||||
glossary:
|
||||
source: narratio.input.glossary
|
||||
source: narratio.input.glossary.campaign
|
||||
required: false
|
||||
`,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user