Reconcile reuse and inspection with native extraction

This commit is contained in:
2026-11-30 02:20:09 +00:00
parent 52a5d483e3
commit b5b4672920
59 changed files with 515 additions and 2444 deletions

View File

@@ -35,9 +35,9 @@ notification:
}
}
func TestCampaignStrictDecodeAcceptsCampaignID(t *testing.T) {
func TestCampaignStrictDecodeAcceptsSharedID(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./party.yml}\nnarratio:\n inputs:\n speakers_file: ./speakers.yml\n glossary_file: ./glossary.yml\n",
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n",
)
@@ -60,14 +60,14 @@ func TestCampaignStrictDecodeRejectsLegacyCampaignField(t *testing.T) {
if err == nil {
t.Fatal("expected load error, got nil")
}
if !strings.Contains(configurationErrorText(err), "load campaign config") || !strings.Contains(configurationErrorText(err), "decode.unknown_field") {
t.Fatalf("error = %q, want campaign strict decode context", configurationErrorText(err))
if !strings.Contains(configurationErrorText(err), "load campaign config") || !strings.Contains(configurationErrorText(err), "retired campaign field") {
t.Fatalf("error = %q, want retired field context", configurationErrorText(err))
}
}
func TestCampaignStrictDecodeRejectsUnknownFields(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\nunknown: true\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./party.yml}\nnarratio:\n unknown: true\n inputs: {speakers_file: ./speakers.yml}\n",
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n",
)
@@ -82,7 +82,7 @@ func TestCampaignStrictDecodeRejectsUnknownFields(t *testing.T) {
func TestCampaignStrictDecodeAcceptsSessionTemplateFile(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\nsession_template_file: ./session.template.yml\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./party.yml}\nnarratio:\n session_template_file: ./session.template.yml\n inputs:\n speakers_file: ./speakers.yml\n glossary_file: ./glossary.yml\n",
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n",
)
@@ -97,7 +97,7 @@ func TestCampaignStrictDecodeAcceptsSessionTemplateFile(t *testing.T) {
func TestCampaignSessionMergeFillsStableInputs(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./campaign-speakers.yml\n autocorrect_file: ./campaign-autocorrect.yml\n glossary_file: ./campaign-glossary.yml\n party_file: ./campaign-party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./campaign-party.yml}\nnarratio:\n inputs:\n speakers_file: ./campaign-speakers.yml\n glossary_file: ./campaign-glossary.yml\n",
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n",
)
@@ -112,14 +112,13 @@ func TestCampaignSessionMergeFillsStableInputs(t *testing.T) {
t.Fatalf("session campaign = %q, want campaign config value", cfg.Session.Campaign)
}
assertResolvedStableInput(t, cfg.StableInputs.SpeakersFile, "./campaign-speakers.yml", campaignPath, "campaign_config")
assertResolvedStableInput(t, cfg.StableInputs.AutocorrectFile, "./campaign-autocorrect.yml", campaignPath, "campaign_config")
assertResolvedStableInput(t, cfg.StableInputs.GlossaryFile, "./campaign-glossary.yml", campaignPath, "campaign_config")
assertResolvedStableInput(t, cfg.StableInputs.PartyFile, "./campaign-party.yml", campaignPath, "campaign_config")
}
func TestCampaignSessionMergeSessionOverridesStableInputs(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./campaign-speakers.yml\n autocorrect_file: ./campaign-autocorrect.yml\n glossary_file: ./campaign-glossary.yml\n party_file: ./campaign-party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./campaign-party.yml}\nnarratio:\n inputs:\n speakers_file: ./campaign-speakers.yml\n glossary_file: ./campaign-glossary.yml\n",
"session_id: 2026-05-03\ncampaign: sample-campaign\ninputs:\n audio_dir: ./audio\n speakers_file: ./session-speakers.yml\n",
)
@@ -131,82 +130,13 @@ func TestCampaignSessionMergeSessionOverridesStableInputs(t *testing.T) {
t.Fatalf("Validate() error = %v", err)
}
assertResolvedStableInput(t, cfg.StableInputs.SpeakersFile, "./session-speakers.yml", sessionPath, "session_config")
assertResolvedStableInput(t, cfg.StableInputs.AutocorrectFile, "./campaign-autocorrect.yml", campaignPath, "campaign_config")
assertResolvedStableInput(t, cfg.StableInputs.GlossaryFile, "./campaign-glossary.yml", campaignPath, "campaign_config")
assertResolvedStableInput(t, cfg.StableInputs.PartyFile, "./campaign-party.yml", campaignPath, "campaign_config")
}
func TestCampaignSessionMergeSpellCatalog(t *testing.T) {
tests := []struct {
name string
campaignValue string
sessionValue string
wantPath string
wantSource string
}{
{name: "omitted", wantPath: "", wantSource: "campaign_config"},
{name: "campaign inherited", campaignValue: "./campaign-spells.json", wantPath: "./campaign-spells.json", wantSource: "campaign_config"},
{name: "session override", campaignValue: "./campaign-spells.json", sessionValue: "./session-spells.json", wantPath: "./session-spells.json", wantSource: "session_config"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
campaignSpell := ""
if tt.campaignValue != "" {
campaignSpell = " spell_catalog_file: " + tt.campaignValue + "\n"
}
sessionSpell := ""
if tt.sessionValue != "" {
sessionSpell = " spell_catalog_file: " + tt.sessionValue + "\n"
}
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n"+campaignSpell,
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n"+sessionSpell,
)
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
if err != nil {
t.Fatalf("LoadWithSessionOptions() error = %v", err)
}
wantConfigPath := campaignPath
if tt.wantSource == "session_config" {
wantConfigPath = sessionPath
}
assertResolvedStableInput(t, cfg.StableInputs.SpellCatalogFile, tt.wantPath, wantConfigPath, tt.wantSource)
if cfg.Session.Inputs.SpellCatalogFile != cfg.StableInputs.SpellCatalogFile.Path {
t.Fatalf("session spell_catalog_file = %q, want %q", cfg.Session.Inputs.SpellCatalogFile, cfg.StableInputs.SpellCatalogFile.Path)
}
})
}
}
func TestCampaignSessionMergeRejectsWhitespaceSpellCatalog(t *testing.T) {
tests := []struct {
name string
campaignLine string
sessionLine string
wantErr string
}{
{name: "campaign", campaignLine: " spell_catalog_file: ' '\n", wantErr: "campaign.inputs.spell_catalog_file"},
{name: "session", sessionLine: " spell_catalog_file: ' '\n", wantErr: "session.inputs.spell_catalog_file"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n"+tt.campaignLine,
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n"+tt.sessionLine,
)
_, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
if err == nil || !strings.Contains(configurationErrorText(err), tt.wantErr) {
t.Fatalf("LoadWithSessionOptions() error = %v, want containing %q", err, tt.wantErr)
}
})
}
}
func TestCampaignWithCanonicalPartyDoesNotRequirePlayersInput(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./party.yml}\nnarratio:\n inputs:\n speakers_file: ./speakers.yml\n glossary_file: ./glossary.yml\n",
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n",
)
@@ -217,7 +147,7 @@ func TestCampaignWithCanonicalPartyDoesNotRequirePlayersInput(t *testing.T) {
func TestCampaignSessionMismatchFails(t *testing.T) {
pipelinePath, campaignPath, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./party.yml}\nnarratio:\n inputs:\n speakers_file: ./speakers.yml\n glossary_file: ./glossary.yml\n",
"session_id: 2026-05-03\ncampaign: other-campaign\ninputs:\n audio_dir: ./audio\n",
)
@@ -232,7 +162,7 @@ func TestCampaignSessionMismatchFails(t *testing.T) {
func TestLoadMissingCampaignFileFails(t *testing.T) {
pipelinePath, _, sessionPath := writeCampaignConfigTestFiles(t,
"campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n",
"schema_version: maximumdirect.rpg.campaign.v1\nid: sample-campaign\nreferences: {party: ./party.yml}\nnarratio:\n inputs:\n speakers_file: ./speakers.yml\n glossary_file: ./glossary.yml\n",
"session_id: 2026-05-03\ninputs:\n audio_dir: ./audio\n",
)
missingCampaignPath := filepath.Join(filepath.Dir(sessionPath), "missing-campaign.yml")