Adopt shared campaign and session configuration
This commit is contained in:
@@ -449,12 +449,14 @@ notification:
|
||||
inputs:
|
||||
audio_dir: ./audio
|
||||
`
|
||||
campaignYAML := `campaign_id: sample-campaign
|
||||
inputs:
|
||||
speakers_file: ./speakers.yml
|
||||
autocorrect_file: ./autocorrect.yml
|
||||
glossary_file: ./glossary.yml
|
||||
party_file: ./party.yml
|
||||
campaignYAML := `schema_version: maximumdirect.rpg.campaign.v1
|
||||
id: sample-campaign
|
||||
references:
|
||||
party: ./party.yml
|
||||
narratio:
|
||||
inputs:
|
||||
speakers_file: ./speakers.yml
|
||||
glossary_file: ./glossary.yml
|
||||
`
|
||||
|
||||
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
|
||||
|
||||
@@ -30,7 +30,7 @@ func configurationCommand(deps commandDependencies) commandkit.Command {
|
||||
return cfg.ConfigKitResult(), nil
|
||||
})
|
||||
app.Features.Overrides = true
|
||||
campaign := ckconfig.FromConfigKit("campaign", "Campaign configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.CampaignConfig], error) {
|
||||
campaign := ckconfig.FromConfigKit("campaign", "Campaign configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.CampaignDocument], error) {
|
||||
acquired := state.acquisition(selection, input)
|
||||
cfg, err := acquired.Campaign(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -607,7 +607,7 @@ func artifactFamilyPipelineYAML(families string) string {
|
||||
func writeArtifactFamilyConfig(t *testing.T, dir, pipeline string) (string, string, string) {
|
||||
t.Helper()
|
||||
pipelinePath := writePartyResolutionFile(t, filepath.Join(dir, "pipeline.yml"), pipeline)
|
||||
campaignPath := writePartyResolutionFile(t, filepath.Join(dir, "campaign.yml"), "campaign_id: campaign\ninputs:\n speakers_file: speakers.yml\n autocorrect_file: autocorrect.yml\n glossary_file: glossary.yml\n party_file: party.yml\n")
|
||||
campaignPath := writePartyResolutionFile(t, filepath.Join(dir, "campaign.yml"), "schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: party.yml}\nnarratio:\n inputs: {speakers_file: speakers.yml, glossary_file: glossary.yml}\n")
|
||||
sessionPath := writePartyResolutionFile(t, filepath.Join(dir, "session.yml"), "session_id: session\ncampaign: campaign\ninputs:\n audio_dir: audio\n")
|
||||
return pipelinePath, campaignPath, sessionPath
|
||||
}
|
||||
|
||||
@@ -94,8 +94,9 @@ func ArtifactFamilyIdentity(catalog *ArtifactCatalog, key string) (family, chara
|
||||
|
||||
// CampaignsConfig configures the local campaign registry.
|
||||
type CampaignsConfig struct {
|
||||
Root string `yaml:"root" json:"root"`
|
||||
DefaultCampaignID string `yaml:"default_campaign_id" json:"default_campaign_id"`
|
||||
Root string `yaml:"root" json:"root"`
|
||||
DefaultCampaignID string `yaml:"default_campaign_id" json:"default_campaign_id"`
|
||||
SessionTemplateFile string `yaml:"session_template_file" json:"session_template_file"`
|
||||
}
|
||||
|
||||
// CampaignConfig contains stable campaign-level identity and input defaults.
|
||||
@@ -106,16 +107,47 @@ type CampaignConfig struct {
|
||||
resolution *documentResolution
|
||||
}
|
||||
|
||||
// CampaignDocument is the native shared campaign envelope and Narratio extension.
|
||||
type CampaignDocument struct {
|
||||
SchemaVersion string `yaml:"schema_version"`
|
||||
ID string `yaml:"id"`
|
||||
Name any `yaml:"name"`
|
||||
Description any `yaml:"description"`
|
||||
Setting any `yaml:"setting"`
|
||||
System any `yaml:"system"`
|
||||
References map[string]any `yaml:"references"`
|
||||
Narratio CampaignNarratio `yaml:"narratio"`
|
||||
Extensions map[string]any `yaml:",inline"`
|
||||
}
|
||||
|
||||
type CampaignNarratio struct {
|
||||
SessionTemplateFile string `yaml:"session_template_file"`
|
||||
Inputs CampaignNarratioInputs `yaml:"inputs"`
|
||||
}
|
||||
|
||||
type CampaignNarratioInputs struct {
|
||||
SpeakersFile string `yaml:"speakers_file"`
|
||||
GlossaryFile *string `yaml:"glossary_file"`
|
||||
Glossary map[string]any `yaml:"glossary"`
|
||||
Autocorrect []AutocorrectionRule `yaml:"autocorrect"`
|
||||
}
|
||||
|
||||
type AutocorrectionRule struct {
|
||||
Target string `yaml:"target" json:"target"`
|
||||
Match []string `yaml:"match" json:"match"`
|
||||
}
|
||||
|
||||
// CampaignInputsConfig contains stable campaign-level input file references.
|
||||
type CampaignInputsConfig struct {
|
||||
Setting *string `yaml:"setting" json:"setting"`
|
||||
System *string `yaml:"system" json:"system"`
|
||||
Glossary map[string]any `yaml:"glossary" json:"glossary"`
|
||||
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file" json:"autocorrect_file"`
|
||||
GlossaryFile *string `yaml:"glossary_file" json:"glossary_file"`
|
||||
PartyFile string `yaml:"party_file" json:"party_file"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file" json:"spell_catalog_file"`
|
||||
Setting *string `yaml:"setting" json:"setting"`
|
||||
System *string `yaml:"system" json:"system"`
|
||||
Glossary map[string]any `yaml:"glossary" json:"glossary"`
|
||||
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file" json:"autocorrect_file"`
|
||||
GlossaryFile *string `yaml:"glossary_file" json:"glossary_file"`
|
||||
PartyFile string `yaml:"party_file" json:"party_file"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file" json:"spell_catalog_file"`
|
||||
Autocorrect []AutocorrectionRule `yaml:"autocorrect" json:"autocorrect"`
|
||||
}
|
||||
|
||||
// SessionConfig contains per-session inputs and metadata.
|
||||
@@ -389,9 +421,10 @@ type SessionInputsConfig struct {
|
||||
AudioFiles []string `yaml:"audio_files" json:"audio_files"`
|
||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3" json:"audio_s3"`
|
||||
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file" json:"autocorrect_file"`
|
||||
AutocorrectFile string `yaml:"-" json:"-"`
|
||||
Autocorrect []AutocorrectionRule `yaml:"autocorrect" json:"autocorrect"`
|
||||
GlossaryFile *string `yaml:"glossary_file" json:"glossary_file"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file" json:"spell_catalog_file"`
|
||||
SpellCatalogFile string `yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
// SessionAudioS3Input configures S3 session-audio input discovery.
|
||||
|
||||
@@ -7,20 +7,21 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/domaininput"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
const maxConfigDocumentBytes int64 = 8 << 20
|
||||
|
||||
type documentResolution struct {
|
||||
campaign *configkit.Result[CampaignConfig]
|
||||
campaign *configkit.Result[CampaignDocument]
|
||||
session *configkit.Result[SessionConfig]
|
||||
sources map[string]string
|
||||
}
|
||||
|
||||
// ConfigKitResult returns the campaign's actual completed native load result.
|
||||
// Constructed campaign values have no result.
|
||||
func (cfg *CampaignConfig) ConfigKitResult() *configkit.Result[CampaignConfig] {
|
||||
func (cfg *CampaignConfig) ConfigKitResult() *configkit.Result[CampaignDocument] {
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -75,27 +76,56 @@ func documentOptionalResource(resolution *configkit.Resolution, path configkit.P
|
||||
configkit.Normalize(resolution, path, value, &resolved, "resolved relative resource from its source")
|
||||
}
|
||||
|
||||
func campaignDefinition(invocationDir string, sources map[string]string, expected string) configkit.Definition[CampaignConfig] {
|
||||
return configkit.Definition[CampaignConfig]{Resolve: func(cfg *CampaignConfig, resolution *configkit.Resolution) error {
|
||||
documentResource(resolution, configkit.Keys("session_template_file"), &cfg.SessionTemplateFile, invocationDir, sources)
|
||||
inputs := configkit.Keys("inputs")
|
||||
for _, field := range []struct {
|
||||
name string
|
||||
value *string
|
||||
}{
|
||||
{"speakers_file", &cfg.Inputs.SpeakersFile}, {"autocorrect_file", &cfg.Inputs.AutocorrectFile},
|
||||
{"party_file", &cfg.Inputs.PartyFile},
|
||||
{"spell_catalog_file", &cfg.Inputs.SpellCatalogFile},
|
||||
} {
|
||||
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
||||
func campaignDefinition(invocationDir string, sources map[string]string, expected string) configkit.Definition[CampaignDocument] {
|
||||
presence := make(map[string]configkit.FieldInfo)
|
||||
return configkit.Definition[CampaignDocument]{Resolve: func(cfg *CampaignDocument, resolution *configkit.Resolution) error {
|
||||
narratio := configkit.Keys("narratio")
|
||||
documentResource(resolution, narratio.Key("session_template_file"), &cfg.Narratio.SessionTemplateFile, invocationDir, sources)
|
||||
inputs := narratio.Key("inputs")
|
||||
documentResource(resolution, inputs.Key("speakers_file"), &cfg.Narratio.Inputs.SpeakersFile, invocationDir, sources)
|
||||
documentOptionalResource(resolution, inputs.Key("glossary_file"), &cfg.Narratio.Inputs.GlossaryFile, invocationDir, sources)
|
||||
if party, ok := cfg.References["party"].(string); ok {
|
||||
documentResource(resolution, configkit.Keys("references", "party"), &party, invocationDir, sources)
|
||||
cfg.References["party"] = party
|
||||
}
|
||||
if cfg.Inputs.GlossaryFile != nil {
|
||||
documentOptionalResource(resolution, inputs.Key("glossary_file"), &cfg.Inputs.GlossaryFile, invocationDir, sources)
|
||||
for _, name := range []string{"schema_version", "id", "name", "description", "setting", "system", "references"} {
|
||||
if info, ok := resolution.EntryInfo(configkit.Keys(name)); ok {
|
||||
presence[name] = info
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}, Validate: func(cfg *CampaignConfig, v *configkit.Validation) {
|
||||
validateCampaignConfigKit(cfg, v)
|
||||
validateIdentity(v, "campaign_id", expected, CampaignID(cfg))
|
||||
}, Validate: func(cfg *CampaignDocument, v *configkit.Validation) {
|
||||
shared := make(map[string]any, len(cfg.Extensions)+7)
|
||||
for key, value := range cfg.Extensions {
|
||||
shared[key] = value
|
||||
}
|
||||
for _, field := range []struct {
|
||||
name string
|
||||
value any
|
||||
}{
|
||||
{"schema_version", cfg.SchemaVersion}, {"id", cfg.ID}, {"name", cfg.Name}, {"description", cfg.Description},
|
||||
{"setting", cfg.Setting}, {"system", cfg.System}, {"references", cfg.References},
|
||||
} {
|
||||
if info, ok := presence[field.name]; ok && info.Explicit {
|
||||
if info.Null {
|
||||
shared[field.name] = nil
|
||||
} else {
|
||||
shared[field.name] = field.value
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := domaininput.ValidateCampaign(shared); err != nil {
|
||||
v.Error(configkit.Keys(), err.Error())
|
||||
}
|
||||
if path, err := campaignConfigurationError(campaignDomain(*cfg)); err != nil {
|
||||
v.Error(path, err.Error())
|
||||
}
|
||||
validateIdentity(v, "id", expected, strings.TrimSpace(cfg.ID))
|
||||
for _, retired := range []string{"campaign_id", "inputs", "session_template_file"} {
|
||||
if _, found := cfg.Extensions[retired]; found {
|
||||
v.Error(configkit.Keys(retired), "retired campaign field")
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -113,8 +143,6 @@ func sessionDefinition(invocationDir string, sources map[string]string, label st
|
||||
value *string
|
||||
}{
|
||||
{"audio_dir", &cfg.Inputs.AudioDir}, {"speakers_file", &cfg.Inputs.SpeakersFile},
|
||||
{"autocorrect_file", &cfg.Inputs.AutocorrectFile},
|
||||
{"spell_catalog_file", &cfg.Inputs.SpellCatalogFile},
|
||||
} {
|
||||
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
||||
}
|
||||
@@ -165,8 +193,6 @@ func applyCampaignSessionDefaults(cfg *SessionConfig, resolution *configkit.Reso
|
||||
target *string
|
||||
}{
|
||||
{"speakers_file", campaign.Inputs.SpeakersFile, &cfg.Inputs.SpeakersFile},
|
||||
{"autocorrect_file", campaign.Inputs.AutocorrectFile, &cfg.Inputs.AutocorrectFile},
|
||||
{"spell_catalog_file", campaign.Inputs.SpellCatalogFile, &cfg.Inputs.SpellCatalogFile},
|
||||
} {
|
||||
if field.value != "" {
|
||||
configkit.Default(resolution, configkit.Keys("inputs", field.name), field.target, field.value, reason)
|
||||
@@ -188,6 +214,9 @@ func applyCampaignSessionDefaults(cfg *SessionConfig, resolution *configkit.Reso
|
||||
if campaign.Inputs.Glossary != nil {
|
||||
configkit.Default(resolution, configkit.Keys("inputs", "glossary"), &cfg.Inputs.Glossary, campaign.Inputs.Glossary, reason)
|
||||
}
|
||||
if campaign.Inputs.Autocorrect != nil {
|
||||
configkit.Default(resolution, configkit.Keys("inputs", "autocorrect"), &cfg.Inputs.Autocorrect, campaign.Inputs.Autocorrect, reason)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCampaignWithIdentity validates an optional asserted identity within the native load.
|
||||
@@ -197,15 +226,33 @@ func LoadCampaignWithIdentity(path, expected string) (*CampaignConfig, error) {
|
||||
return nil, err
|
||||
}
|
||||
sources := make(map[string]string)
|
||||
result, err := configkit.Load(configkit.File(path), configkit.Options[CampaignConfig]{Imports: true, Definition: campaignDefinition(invocationDir, sources, expected)})
|
||||
result, err := configkit.Load(configkit.File(path), configkit.Options[CampaignDocument]{Imports: true, Definition: campaignDefinition(invocationDir, sources, expected)})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load campaign config: %w", err)
|
||||
}
|
||||
cfg := &result.Config
|
||||
doc := result.Config
|
||||
cfg := campaignDomain(doc)
|
||||
cfg.resolution = &documentResolution{campaign: result, sources: sources}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func campaignDomain(doc CampaignDocument) *CampaignConfig {
|
||||
cfg := &CampaignConfig{CampaignID: doc.ID, SessionTemplateFile: doc.Narratio.SessionTemplateFile, Inputs: CampaignInputsConfig{
|
||||
SpeakersFile: doc.Narratio.Inputs.SpeakersFile, GlossaryFile: doc.Narratio.Inputs.GlossaryFile,
|
||||
Glossary: doc.Narratio.Inputs.Glossary, Autocorrect: doc.Narratio.Inputs.Autocorrect,
|
||||
}}
|
||||
if value, ok := doc.Setting.(string); ok {
|
||||
cfg.Inputs.Setting = &value
|
||||
}
|
||||
if value, ok := doc.System.(string); ok {
|
||||
cfg.Inputs.System = &value
|
||||
}
|
||||
if value, ok := doc.References["party"].(string); ok {
|
||||
cfg.Inputs.PartyFile = value
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func loadSessionSource(source configkit.Source, label string, opts SessionLoadOptions, imports bool) (*SessionConfig, string, error) {
|
||||
return loadSessionSourceWithFilesystem(source, label, opts, imports, nil)
|
||||
}
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type renderedCampaignInputs struct {
|
||||
SpeakersFile string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile string `yaml:"autocorrect_file,omitempty"`
|
||||
PartyFile string `yaml:"party_file,omitempty"`
|
||||
SpellCatalogFile string `yaml:"spell_catalog_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
}
|
||||
|
||||
// RenderCampaignDocument serializes the loaded effective campaign document.
|
||||
func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
||||
if cfg == nil {
|
||||
@@ -27,13 +20,34 @@ func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
||||
if doc == nil {
|
||||
return nil, fmt.Errorf("campaign document is required")
|
||||
}
|
||||
value := struct {
|
||||
CampaignID string `yaml:"campaign_id"`
|
||||
SessionTemplateFile string `yaml:"session_template_file,omitempty"`
|
||||
Inputs renderedCampaignInputs `yaml:"inputs"`
|
||||
}{doc.CampaignID, doc.SessionTemplateFile, renderedCampaignInputs{
|
||||
doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.PartyFile, doc.Inputs.SpellCatalogFile, glossaryFields(doc.ConfigKitResult() != nil, campaignMetadata(doc), doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, false),
|
||||
}}
|
||||
if result := doc.ConfigKitResult(); result != nil {
|
||||
var output bytes.Buffer
|
||||
if err := result.WriteEffective(&output); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return output.Bytes(), nil
|
||||
}
|
||||
inputs := map[string]any{"speakers_file": doc.Inputs.SpeakersFile}
|
||||
if doc.Inputs.GlossaryFile != nil {
|
||||
inputs["glossary_file"] = *doc.Inputs.GlossaryFile
|
||||
}
|
||||
if doc.Inputs.Glossary != nil {
|
||||
inputs["glossary"] = doc.Inputs.Glossary
|
||||
}
|
||||
if doc.Inputs.Autocorrect != nil {
|
||||
inputs["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
narratio := map[string]any{"inputs": inputs}
|
||||
if doc.SessionTemplateFile != "" {
|
||||
narratio["session_template_file"] = doc.SessionTemplateFile
|
||||
}
|
||||
value := map[string]any{"schema_version": "maximumdirect.rpg.campaign.v1", "id": doc.CampaignID, "references": map[string]any{"party": doc.Inputs.PartyFile}, "narratio": narratio}
|
||||
if doc.Inputs.Setting != nil {
|
||||
value["setting"] = *doc.Inputs.Setting
|
||||
}
|
||||
if doc.Inputs.System != nil {
|
||||
value["system"] = *doc.Inputs.System
|
||||
}
|
||||
return yaml.Marshal(value)
|
||||
}
|
||||
|
||||
@@ -67,17 +81,24 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
return &value
|
||||
}
|
||||
inputs := struct {
|
||||
AudioDir string `yaml:"audio_dir,omitempty"`
|
||||
AudioFiles []string `yaml:"audio_files,omitempty"`
|
||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile *string `yaml:"autocorrect_file,omitempty"`
|
||||
SpellCatalogFile *string `yaml:"spell_catalog_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
AudioDir string `yaml:"audio_dir,omitempty"`
|
||||
AudioFiles []string `yaml:"audio_files,omitempty"`
|
||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||
inputValue("autocorrect_file", doc.Inputs.AutocorrectFile),
|
||||
inputValue("spell_catalog_file", doc.Inputs.SpellCatalogFile), glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, true)}
|
||||
glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, true)}
|
||||
autocorrectPath := configkit.Keys("inputs", "autocorrect")
|
||||
if result != nil && metadata.IsExplicit(autocorrectPath) {
|
||||
if info, ok := metadata.Lookup(autocorrectPath); ok && info.Null {
|
||||
inputs.Extra["autocorrect"] = nil
|
||||
} else {
|
||||
inputs.Extra["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
} else if result == nil && doc.Inputs.Autocorrect != nil {
|
||||
inputs.Extra["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
value := struct {
|
||||
SessionID string `yaml:"session_id"`
|
||||
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
||||
@@ -89,13 +110,6 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
return yaml.Marshal(value)
|
||||
}
|
||||
|
||||
func campaignMetadata(cfg *CampaignConfig) configkit.Metadata {
|
||||
if r := cfg.ConfigKitResult(); r != nil {
|
||||
return r.Metadata()
|
||||
}
|
||||
return configkit.Metadata{}
|
||||
}
|
||||
|
||||
func glossaryFields(hasResult bool, metadata configkit.Metadata, setting, system, file *string, glossary map[string]any, authoredOnly bool) map[string]any {
|
||||
result := map[string]any{}
|
||||
for _, field := range []struct {
|
||||
|
||||
@@ -320,8 +320,15 @@ func deriveStableInputs(campaignCfg *CampaignConfig, sessionCfg *SessionConfig,
|
||||
reference.Source = "campaign_config"
|
||||
metadata = campaignCfg.resolution
|
||||
}
|
||||
if metadata != nil && metadata.sources["/inputs/"+field.name] != "" {
|
||||
reference.ConfigPath = metadata.sources["/inputs/"+field.name]
|
||||
originPath := "/inputs/" + field.name
|
||||
if fromCampaign {
|
||||
originPath = "/narratio/inputs/" + field.name
|
||||
if field.campaignOnly {
|
||||
originPath = "/references/party"
|
||||
}
|
||||
}
|
||||
if metadata != nil && metadata.sources[originPath] != "" {
|
||||
reference.ConfigPath = metadata.sources[originPath]
|
||||
}
|
||||
*field.target = reference
|
||||
}
|
||||
|
||||
@@ -72,19 +72,20 @@ scriptorium:
|
||||
|
||||
func TestNativeCampaignResultValidatesConfigurationWithoutReadingResources(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: settings/defaults.yml\ncampaign_id: sample\n")
|
||||
writePipelineFixture(t, dir, "settings/defaults.yml", `inputs:
|
||||
speakers_file: speakers.yml
|
||||
autocorrect_file: autocorrect.yml
|
||||
glossary_file: glossary.yml
|
||||
party_file: party.yml
|
||||
root := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: settings/defaults.yml\nschema_version: maximumdirect.rpg.campaign.v1\nid: sample\n")
|
||||
writePipelineFixture(t, dir, "settings/defaults.yml", `references:
|
||||
party: party.yml
|
||||
narratio:
|
||||
inputs:
|
||||
speakers_file: speakers.yml
|
||||
glossary_file: glossary.yml
|
||||
`)
|
||||
cfg, err := LoadCampaign(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := cfg.ConfigKitResult()
|
||||
if result == nil || cfg != &result.Config || len(result.Sources()) != 2 {
|
||||
if result == nil || len(result.Sources()) != 2 {
|
||||
t.Fatal("campaign did not retain its original load and imported source")
|
||||
}
|
||||
if cfg.Inputs.PartyFile != filepath.Join(dir, "settings", "party.yml") {
|
||||
@@ -94,22 +95,22 @@ func TestNativeCampaignResultValidatesConfigurationWithoutReadingResources(t *te
|
||||
if err := result.WriteEffective(&output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var shown CampaignConfig
|
||||
var shown CampaignDocument
|
||||
if err := yaml.Unmarshal(output.Bytes(), &shown); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if shown.CampaignID != cfg.CampaignID || !reflect.DeepEqual(shown.Inputs, cfg.Inputs) {
|
||||
if shown.ID != cfg.CampaignID || shown.Narratio.Inputs.SpeakersFile != cfg.Inputs.SpeakersFile {
|
||||
t.Fatal("native show lost completed campaign values")
|
||||
}
|
||||
|
||||
invalid := writePipelineFixture(t, dir, "invalid.yml", "campaign_id: sample\n")
|
||||
invalid := writePipelineFixture(t, dir, "invalid.yml", "schema_version: maximumdirect.rpg.campaign.v1\nid: sample\n")
|
||||
_, err = LoadCampaign(invalid)
|
||||
var loadError *configkit.LoadError
|
||||
if !errors.As(err, &loadError) {
|
||||
t.Fatalf("campaign validation lost its native error: %v", err)
|
||||
}
|
||||
findings := loadError.Diagnostics()
|
||||
if len(findings) == 0 || findings[0].Code != configkit.CodeValidateError || findings[0].Path.String() != "/inputs/speakers_file" {
|
||||
if len(findings) == 0 || findings[0].Code != configkit.CodeValidateError || findings[0].Path.String() != "/narratio/inputs/speakers_file" {
|
||||
t.Fatalf("campaign validation findings = %+v", findings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ func campaignPartyInput(campaignPath string, campaign *CampaignConfig) (Resolved
|
||||
return ResolvedInputFile{}, fmt.Errorf("campaign config is required")
|
||||
}
|
||||
if strings.TrimSpace(campaign.Inputs.PartyFile) == "" {
|
||||
return ResolvedInputFile{}, fmt.Errorf("campaign.inputs.party_file is required")
|
||||
return ResolvedInputFile{}, fmt.Errorf("campaign.references.party is required")
|
||||
}
|
||||
sourcePath := campaignPath
|
||||
if campaign.resolution != nil && campaign.resolution.sources["/inputs/party_file"] != "" {
|
||||
sourcePath = campaign.resolution.sources["/inputs/party_file"]
|
||||
if campaign.resolution != nil && campaign.resolution.sources["/references/party"] != "" {
|
||||
sourcePath = campaign.resolution.sources["/references/party"]
|
||||
}
|
||||
return ResolvedInputFile{
|
||||
Path: campaign.Inputs.PartyFile,
|
||||
|
||||
@@ -139,6 +139,7 @@ func resolvePipelineConfig(cfg *PipelineConfig, resolution *configkit.Resolution
|
||||
}
|
||||
resolveHostResource(resolution, configkit.Keys("workspace", "root"), &cfg.Workspace.Root, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("campaigns", "root"), &cfg.Campaigns.Root, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("campaigns", "session_template_file"), &cfg.Campaigns.SessionTemplateFile, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("spool", "root"), &cfg.Spool.Root, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("cache", "root"), &cfg.Cache.Root, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("audita", "config_path"), &cfg.Audita.ConfigPath, invocationDir)
|
||||
|
||||
@@ -330,6 +330,19 @@ whisperx:
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstallationTemplatePathFollowsSupplyingSource(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipeline := writePipelineFixture(t, dir, "pipeline.yml", "config:\n imports:\n - path: profiles/campaigns.yml\nwhisperx:\n transcribe_url: https://transcription.example.test/transcribe\n")
|
||||
writePipelineFixture(t, dir, "profiles/campaigns.yml", "campaigns:\n session_template_file: templates/session.yml\n")
|
||||
cfg, err := LoadPipeline(pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := filepath.Join(dir, "profiles", "templates", "session.yml"); cfg.Campaigns.SessionTemplateFile != want {
|
||||
t.Fatalf("installation template = %q, want %q", cfg.Campaigns.SessionTemplateFile, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInheritedNotariusPathsFollowSupplyingSource(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipelinePath := writePipelineFixture(t, dir, "pipeline.yml", `config:
|
||||
|
||||
197
internal/config/shared_campaign_test.go
Normal file
197
internal/config/shared_campaign_test.go
Normal file
@@ -0,0 +1,197 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSharedCampaignAndSessionDefaults(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
campaignPath := writePipelineFixture(t, dir, "campaign.yml", `schema_version: maximumdirect.rpg.campaign.v1
|
||||
id: campaign
|
||||
setting: sample
|
||||
references: {party: party.yml}
|
||||
extension: {custom: true}
|
||||
narratio:
|
||||
inputs:
|
||||
speakers_file: speakers.yml
|
||||
glossary_file: glossary.yml
|
||||
glossary: {entries: [{id: one, name: One, category: place}]}
|
||||
autocorrect: [{target: One, match: [Won]}]
|
||||
`)
|
||||
campaign, err := LoadCampaignWithIdentity(campaignPath, "campaign")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if campaign.Inputs.PartyFile != filepath.Join(dir, "party.yml") {
|
||||
t.Fatalf("party path: %s", campaign.Inputs.PartyFile)
|
||||
}
|
||||
if _, err := LoadCampaignWithIdentity(campaignPath, "other"); err == nil {
|
||||
t.Fatal("expected identity error")
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name, inputs string
|
||||
rules int
|
||||
glossary bool
|
||||
}{
|
||||
{"inherit", "", 1, true},
|
||||
{"empty", " autocorrect: []\n glossary: null\n", 0, false},
|
||||
{"null", " autocorrect: null\n glossary: null\n", 0, false},
|
||||
{"empty mapping", " glossary: {}\n", 1, true},
|
||||
{"replace", " autocorrect: [{target: Two, match: [Too]}]\n glossary: {entries: []}\n", 1, true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
data := []byte("session_id: session\ninputs:\n audio_dir: audio\n" + tc.inputs)
|
||||
session, err := LoadSessionBytesWithOptions("session.yml", data, SessionLoadOptions{Campaign: campaign, CampaignPath: campaignPath})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(session.Inputs.Autocorrect) != tc.rules || (session.Inputs.Glossary != nil) != tc.glossary {
|
||||
t.Fatalf("inputs: %+v", session.Inputs)
|
||||
}
|
||||
if session.Inputs.GlossaryFile == nil || *session.Inputs.GlossaryFile != filepath.Join(dir, "glossary.yml") {
|
||||
t.Fatalf("file selection lost: %+v", session.Inputs.GlossaryFile)
|
||||
}
|
||||
output, err := RenderSessionDocument(&Config{Session: session, SessionDocument: session}, "session")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
again, err := LoadSessionBytesWithOptions("snapshot.yml", output, SessionLoadOptions{Campaign: campaign, CampaignPath: campaignPath})
|
||||
if err != nil {
|
||||
t.Fatalf("reload %s: %v", output, err)
|
||||
}
|
||||
if len(again.Inputs.Autocorrect) != tc.rules || (again.Inputs.Glossary != nil) != tc.glossary {
|
||||
t.Fatalf("snapshot: %s", output)
|
||||
}
|
||||
})
|
||||
}
|
||||
output, err := RenderCampaignDocument(&Config{Campaign: campaign})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Contains(output, []byte("extension:")) {
|
||||
t.Fatalf("extension lost: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedCampaignLoadsWithRosterWithoutArtifactFamilies(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipeline := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig)
|
||||
campaign := writePipelineFixture(t, dir, "campaign.yml", "schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: party.yml}\nnarratio:\n inputs: {speakers_file: speakers.yml}\n")
|
||||
party := writePipelineFixture(t, dir, "party.yml", canonicalPartyFixture)
|
||||
session := writePipelineFixture(t, dir, "session.yml", "session_id: session\ninputs: {audio_dir: audio}\n")
|
||||
cfg, err := LoadWithSessionOptions(pipeline, campaign, session, SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(cfg.Party.Canonical.Characters) == 0 {
|
||||
t.Fatal("missing selected roster")
|
||||
}
|
||||
if err := os.WriteFile(party, []byte("schema_version: maximumdirect.rpg.party.v1\ncharacters: {}\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := LoadWithSessionOptions(pipeline, campaign, session, SessionLoadOptions{}); err == nil {
|
||||
t.Fatal("invalid roster accepted without artifact families")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedCampaignExplicitRosterDoesNotChangeAuthoredReference(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := writePipelineFixture(t, dir, "campaign.yml", "schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: party.yml}\nnarratio:\n inputs: {speakers_file: speakers.yml}\n")
|
||||
selected := writePipelineFixture(t, dir, "selected.yml", canonicalPartyFixture)
|
||||
campaign, err := LoadCampaign(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
party, err := ResolveParty(path, campaign, &selected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if party.Source.Path != selected || campaign.Inputs.PartyFile != filepath.Join(dir, "party.yml") {
|
||||
t.Fatalf("selected = %+v, campaign = %+v", party.Source, campaign.Inputs)
|
||||
}
|
||||
var shown bytes.Buffer
|
||||
if err := campaign.ConfigKitResult().WriteEffective(&shown); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if bytes.Contains(shown.Bytes(), []byte(selected)) {
|
||||
t.Fatalf("override leaked into campaign: %s", shown.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedCampaignRejectsRetiredAndInvalidFields(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
base := "schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: party.yml}\nnarratio:\n inputs: {speakers_file: speakers.yml}\n"
|
||||
for name, body := range map[string]string{
|
||||
"retired root": base + "campaign_id: old\n",
|
||||
"retired inputs": base + "inputs: {}\n",
|
||||
"unknown operational": strings.Replace(base, "speakers_file: speakers.yml", "speakers_file: speakers.yml, unknown: true", 1),
|
||||
"null shared selector": base + "setting: null\n",
|
||||
"missing party": strings.Replace(base, "references: {party: party.yml}\n", "", 1),
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if _, err := LoadCampaign(writePipelineFixture(t, dir, name+".yml", body)); err == nil {
|
||||
t.Fatal("expected rejection")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionRejectsRetiredFieldsAndInvalidRequiredPaths(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := writePipelineFixture(t, dir, "campaign.yml", "schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: party.yml}\nnarratio:\n inputs: {speakers_file: speakers.yml}\n")
|
||||
campaign, err := LoadCampaign(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, extra := range map[string]string{
|
||||
"retired autocorrect": " autocorrect_file: old.yml\n",
|
||||
"retired spell catalog": " spell_catalog_file: old.yml\n",
|
||||
"unknown field": " unsupported: true\n",
|
||||
"empty required path": " speakers_file: ''\n",
|
||||
"null required path": " speakers_file: null\n",
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
data := []byte("session_id: session\ninputs:\n audio_dir: audio\n" + extra)
|
||||
if _, err := LoadSessionBytesWithOptions("session.yml", data, SessionLoadOptions{Campaign: campaign, CampaignPath: path}); err == nil {
|
||||
t.Fatal("expected rejection")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedCampaignAndSessionImportedOrigins(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
campaignPath := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: shared/campaign.yml\nschema_version: maximumdirect.rpg.campaign.v1\nid: campaign\n")
|
||||
fragment := writePipelineFixture(t, dir, "shared/campaign.yml", "references: {party: party.yml}\nnarratio:\n session_template_file: template.yml\n inputs: {speakers_file: speakers.yml, glossary_file: glossary.yml}\n")
|
||||
campaign, err := LoadCampaign(campaignPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if campaign.Inputs.PartyFile != filepath.Join(dir, "shared", "party.yml") || campaign.Inputs.SpeakersFile != filepath.Join(dir, "shared", "speakers.yml") || campaign.SessionTemplateFile != filepath.Join(dir, "shared", "template.yml") {
|
||||
t.Fatalf("campaign paths: %+v", campaign.Inputs)
|
||||
}
|
||||
sessionPath := writePipelineFixture(t, dir, "session.yml", "config:\n imports:\n - path: overrides/session.yml\nsession_id: session\n")
|
||||
sessionFragment := writePipelineFixture(t, dir, "overrides/session.yml", "inputs: {audio_dir: audio, speakers_file: speakers.yml}\n")
|
||||
session, err := LoadSessionWithOptions(sessionPath, SessionLoadOptions{Campaign: campaign, CampaignPath: campaignPath})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stable, err := deriveStableInputs(campaign, session, campaignPath, sessionPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stable.SpeakersFile.ConfigPath != sessionFragment || stable.GlossaryFile.ConfigPath != fragment || stable.PartyFile.ConfigPath != fragment {
|
||||
t.Fatalf("source origins: %+v", stable)
|
||||
}
|
||||
output, err := RenderSessionDocument(&Config{Session: session, SessionDocument: session}, "session")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := LoadSessionAuthoringBytes(filepath.Join(dir, "snapshot.yml"), output, SessionLoadOptions{Campaign: campaign, CampaignPath: campaignPath}); err != nil {
|
||||
t.Fatalf("file-context snapshot: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -15,34 +15,21 @@ func validateCampaign(cfg *CampaignConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func validateCampaignConfigKit(cfg *CampaignConfig, validation *configkit.Validation) {
|
||||
path, err := campaignConfigurationError(cfg)
|
||||
if err != nil {
|
||||
validation.Error(path, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func campaignConfigurationError(cfg *CampaignConfig) (configkit.Path, error) {
|
||||
if cfg == nil {
|
||||
return configkit.Keys(), fmt.Errorf("campaign config is required")
|
||||
}
|
||||
if CampaignID(cfg) == "" {
|
||||
return configkit.Keys("campaign_id"), fmt.Errorf("campaign.campaign_id is required")
|
||||
return configkit.Keys("id"), fmt.Errorf("campaign.id is required")
|
||||
}
|
||||
if err := pathsafe.ValidateOpaqueSegment(cfg.CampaignID); err != nil {
|
||||
return configkit.Keys("campaign_id"), fmt.Errorf("campaign.campaign_id: %w", err)
|
||||
return configkit.Keys("id"), fmt.Errorf("campaign.id: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.SpeakersFile) == "" {
|
||||
return configkit.Keys("inputs", "speakers_file"), fmt.Errorf("campaign.inputs.speakers_file is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.AutocorrectFile) == "" {
|
||||
return configkit.Keys("inputs", "autocorrect_file"), fmt.Errorf("campaign.inputs.autocorrect_file is required")
|
||||
return configkit.Keys("narratio", "inputs", "speakers_file"), fmt.Errorf("campaign.narratio.inputs.speakers_file is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.PartyFile) == "" {
|
||||
return configkit.Keys("inputs", "party_file"), fmt.Errorf("campaign.inputs.party_file is required")
|
||||
}
|
||||
if cfg.Inputs.SpellCatalogFile != "" && strings.TrimSpace(cfg.Inputs.SpellCatalogFile) == "" {
|
||||
return configkit.Keys("inputs", "spell_catalog_file"), fmt.Errorf("campaign.inputs.spell_catalog_file must be non-empty when provided")
|
||||
return configkit.Keys("references", "party"), fmt.Errorf("campaign.references.party is required")
|
||||
}
|
||||
return configkit.Keys(), nil
|
||||
}
|
||||
@@ -83,12 +70,6 @@ func sessionConfigurationError(cfg *SessionConfig) (configkit.Path, error) {
|
||||
if strings.TrimSpace(cfg.Inputs.SpeakersFile) == "" {
|
||||
return configkit.Keys("inputs", "speakers_file"), fmt.Errorf("session.inputs.speakers_file is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.AutocorrectFile) == "" {
|
||||
return configkit.Keys("inputs", "autocorrect_file"), fmt.Errorf("session.inputs.autocorrect_file is required")
|
||||
}
|
||||
if cfg.Inputs.SpellCatalogFile != "" && strings.TrimSpace(cfg.Inputs.SpellCatalogFile) == "" {
|
||||
return configkit.Keys("inputs", "spell_catalog_file"), fmt.Errorf("session.inputs.spell_catalog_file must be non-empty when provided")
|
||||
}
|
||||
|
||||
hasAudioDir := strings.TrimSpace(cfg.Inputs.AudioDir) != ""
|
||||
hasAudioFiles := len(cfg.Inputs.AudioFiles) > 0
|
||||
|
||||
Reference in New Issue
Block a user