Exercise shared campaign and consumer workflows
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -430,3 +431,104 @@ func loadAssembledManifest(t *testing.T, cfg *config.Config) *manifest.Manifest
|
||||
func manifestPathForConfig(workspaceRoot string) string {
|
||||
return artifacts.SessionManifestPathForCampaign(workspaceRoot, "sample-campaign", "2026-05-03")
|
||||
}
|
||||
|
||||
func TestThreeDocumentCampaignOnboarding(t *testing.T) {
|
||||
for _, inline := range []bool{false, true} {
|
||||
name := "defaults"
|
||||
if inline {
|
||||
name = "inline"
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
campaignDir := filepath.Join(root, "campaign")
|
||||
example, err := filepath.Abs(filepath.Join("..", "..", "examples", "campaigns", "lantern-coast"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range []string{"campaign.yml", "party.yml", "speakers.yml"} {
|
||||
data, err := os.ReadFile(filepath.Join(example, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if name == "campaign.yml" && !inline {
|
||||
data = []byte(strings.Split(string(data), " glossary:")[0])
|
||||
}
|
||||
mustWriteTestFile(t, filepath.Join(campaignDir, name), string(data))
|
||||
}
|
||||
entries, err := os.ReadDir(campaignDir)
|
||||
if err != nil || len(entries) != 3 {
|
||||
t.Fatalf("campaign documents = %v, %v", entries, err)
|
||||
}
|
||||
catalog, err := filepath.Abs(filepath.Join("..", "..", "examples", "reference-catalog", "catalog.yml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
copyCatalog(t, filepath.Dir(catalog), filepath.Join(root, "catalog"))
|
||||
catalog = "catalog/catalog.yml"
|
||||
workspace := filepath.Join(root, "workspace")
|
||||
pipeline := filepath.Join(root, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipeline, fmt.Sprintf("config:\n imports: [{path: %q}]\nworkspace: {root: %q}\nwhisperx: {transcribe_url: 'https://example.invalid/transcribe'}\n", catalog, workspace))
|
||||
audio := filepath.Join(root, "audio")
|
||||
mustWriteTestFile(t, filepath.Join(audio, "Rowan_recording.flac"), "synthetic audio")
|
||||
session := filepath.Join(root, "session.yml")
|
||||
campaign := filepath.Join(campaignDir, "campaign.yml")
|
||||
var out, diagnostics bytes.Buffer
|
||||
if code := executeForTest([]string{"session", "init", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--output", session, "--audio-dir", audio}, &out, &diagnostics); code != 0 {
|
||||
t.Fatalf("session init: %s", diagnostics.String())
|
||||
}
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prepare, err := stage.Select("prepare")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := executeStages(context.Background(), cfg, []stage.Stage{prepare}, RunOptions{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(workspace).SessionPathsFor("lantern-coast", "2026-05-03")
|
||||
for role, want := range map[string]string{"setting": "Harbor Crossing", "spells": "Tide Step", "party": "Mira"} {
|
||||
data, err := os.ReadFile(filepath.Join(paths.InputsDir, "glossaries", role+".yml"))
|
||||
if err != nil || !strings.Contains(string(data), want) {
|
||||
t.Fatalf("%s glossary: %s %v", role, data, err)
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(paths.InputsDir, "glossaries", "campaign.yml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(data), "Glass Harbor") != inline {
|
||||
t.Fatalf("inline glossary = %s", data)
|
||||
}
|
||||
m, err := (&manifest.LocalStore{}).Load(context.Background(), paths.ManifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
base := filepath.Join(paths.TranscriptsDir, "base.json")
|
||||
mustWriteTestFile(t, base, `{"segments":[]}`)
|
||||
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, base)
|
||||
m.RunID = "20260519T010203Z-a1b2c3d4"
|
||||
fake := &audita.FakeRunner{Err: fmt.Errorf("controlled consumer failure")}
|
||||
env := &stage.Env{Config: cfg, ArtifactStore: artifacts.NewLocalStore(workspace), Audita: fake}
|
||||
polish, err := stage.Select("polish")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := polish.Run(context.Background(), env, m); err == nil {
|
||||
t.Fatal("controlled consumer failure was ignored")
|
||||
}
|
||||
fake.Err = nil
|
||||
if _, err := polish.Run(context.Background(), env, m); err != nil {
|
||||
t.Fatalf("consumer retry: %v", err)
|
||||
}
|
||||
if len(fake.Requests) != 2 || len(fake.Requests[1].GlossaryFiles) != 4 {
|
||||
t.Fatalf("consumer inputs: %+v", fake.Requests)
|
||||
}
|
||||
again, err := executeStages(context.Background(), cfg, []stage.Stage{prepare}, RunOptions{})
|
||||
if err != nil || len(again.Skipped) != 1 {
|
||||
t.Fatalf("prepared input reuse: %+v %v", again, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user