Exercise shared campaign and consumer workflows

This commit is contained in:
2026-11-30 02:29:50 +00:00
parent b5b4672920
commit 706c1bb7ad
26 changed files with 417 additions and 489 deletions

View File

@@ -81,18 +81,19 @@ func TestReferenceCatalogCompatibility(t *testing.T) {
return path
}
pipeline := write("pipeline.yml", fmt.Sprintf("config:\n imports:\n - path: catalog/catalog.yml\nworkspace: {root: %q}\nwhisperx: {transcribe_url: 'https://example.invalid/transcribe'}\n", workspace))
campaign := write("campaign.yml", `campaign_id: sample-campaign
inputs:
speakers_file: speakers.yml
autocorrect_file: autocorrect.yml
party_file: party.yml
glossary_file: campaign-glossary.yml
setting: lantern_coast_sample
system: sample_magic
glossary:
entries: [{id: watch, name: Silver Watch, category: organization}]
campaign := write("campaign.yml", `schema_version: maximumdirect.rpg.campaign.v1
id: sample-campaign
setting: lantern_coast_sample
system: sample_magic
references: {party: party.yml}
narratio:
inputs:
speakers_file: speakers.yml
glossary_file: campaign-glossary.yml
glossary:
entries: [{id: watch, name: Silver Watch, category: organization}]
`)
write("campaign-glossary.yml", "campaign:\n instruction: Preserve campaign names.\n entries: [{id: watch, name: Old Watch, category: organization}, {id: inn, name: Lantern Inn, category: place}]\n")
write("campaign-glossary.yml", "schema_version: maximumdirect.glossary.v1\ncollections:\n campaign:\n instruction: Preserve campaign names.\n entries: [{id: watch, name: Old Watch, category: organization}, {id: inn, name: Lantern Inn, category: place}]\n")
write("speakers.yml", "alice: alice.flac\n")
write("autocorrect.yml", "[]\n")
write("party.yml", "schema_version: maximumdirect.rpg.party.v1\ncharacters:\n alice:\n player: {name: Player}\n character: {name: Alice, classes: [{name: wizard}]}\n")
@@ -160,6 +161,7 @@ inputs:
func TestAuditaBinaryCompatibility(t *testing.T) {
binary := externalPath(t, "NARRATIO_TEST_AUDITA_BINARY")
var negative atomic.Bool
var processing atomic.Bool
var calls atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
@@ -173,6 +175,9 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
}
calls.Add(1)
content := `{"status":"ok"}`
if processing.Load() {
content = `{"corrections":[]}`
}
if negative.Load() && request.Model == "review-model" {
content = `{"bad":true}`
}
@@ -180,11 +185,11 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
}))
defer server.Close()
cfg := testConfig(t)
mustWriteTestFile(t, *cfg.Session.Inputs.GlossaryFile, "campaign:\n instruction: Preserve campaign names.\n entries: [{id: watch, name: Silver Watch, category: organization, aliases: null}]\n")
mustWriteTestFile(t, *cfg.Session.Inputs.GlossaryFile, "schema_version: maximumdirect.glossary.v1\ncollections:\n campaign:\n instruction: Preserve campaign names.\n entries: [{id: watch, name: Silver Watch, category: organization, aliases: null}]\n")
settingPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "setting.yml")
spellsPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "spells.yml")
mustWriteTestFile(t, settingPath, "setting: {instruction: Preserve place names., entries: [{id: harbor, name: Harbor, category: place}]}\n")
mustWriteTestFile(t, spellsPath, "spells: {instruction: Preserve spell names., entries: [{id: glow, name: Glow, category: spell}]}\n")
mustWriteTestFile(t, settingPath, "schema_version: maximumdirect.glossary.v1\ncollections:\n setting: {instruction: Preserve place names., entries: [{id: harbor, name: Harbor, category: place}]}\n")
mustWriteTestFile(t, spellsPath, "schema_version: maximumdirect.glossary.v1\ncollections:\n spells: {instruction: Preserve spell names., entries: [{id: glow, name: Glow, category: spell}]}\n")
cfg.Pipeline.ReferenceCatalog = config.ReferenceCatalogConfig{Settings: map[string]string{"coast": settingPath}, Systems: map[string]string{"magic": spellsPath}}
cfg.Session.Inputs.Setting = new("coast")
cfg.Session.Inputs.System = new("magic")
@@ -230,13 +235,13 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
t.Fatalf("missing %s: %s", name, output)
}
}
for name, instruction := range map[string]string{"campaign": "Preserve campaign names.", "setting": "Preserve place names.", "spells": "Preserve spell names."} {
for name, instruction := range map[string]string{"campaign": "", "setting": "", "spells": "Audita default."} {
collection := inspected.Collections[name]
if collection.Instruction == nil || *collection.Instruction != instruction || len(collection.Entries) != 1 {
t.Fatalf("%s: %+v", name, collection)
t.Fatalf("%s: unexpected effective instruction or entries: %+v", name, collection)
}
}
runner, err := audita.NewSubprocessRunner(audita.SubprocessRunnerConfig{Binary: binary, ConfigPath: configPath, Timeout: 30 * time.Second})
runner, err := audita.NewSubprocessRunner(audita.SubprocessRunnerConfig{Binary: binary, ConfigPath: configPath, OutputSchema: "audita-v1", Timeout: 30 * time.Second})
if err != nil {
t.Fatal(err)
}
@@ -244,6 +249,18 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
if err != nil || result.ExitCode != 0 || calls.Load() != 2 {
t.Fatalf("preflight: %+v %v calls=%d", result, err, calls.Load())
}
transcript := filepath.Join(dir, "input.json")
mustWriteTestFile(t, transcript, `{"segments":[{"id":1,"speaker":"Player","start":0,"end":1,"text":"Hello world."}]}`)
req.MergedTranscriptPath = transcript
processing.Store(true)
processed, err := runner.Run(context.Background(), req)
if err != nil || processed.ExitCode != 0 {
t.Fatalf("processing: %+v %v", processed, err)
}
if data, err := os.ReadFile(req.OutputProcessedPath); err != nil || !bytes.Contains(data, []byte("Hello world")) {
t.Fatalf("processed transcript: %s %v", data, err)
}
processing.Store(false)
negative.Store(true)
calls.Store(0)
result, err = runner.Preflight(context.Background(), req)