Adopt shared campaign and session configuration
This commit is contained in:
@@ -7,8 +7,9 @@ User-visible fields, defaults, discovery, and selection belong in the
|
|||||||
|
|
||||||
## Typed Configuration Handoff
|
## Typed Configuration Handoff
|
||||||
|
|
||||||
Pipeline, campaign, session, and party loaders retain their actual typed
|
Pipeline, campaign, session, and party loaders retain their actual
|
||||||
ConfigKit results. ConfigKit owns imports, overlay composition, inheritance,
|
ConfigKit results. Campaign and party inputs retain shared extensions, while
|
||||||
|
Narratio's operational settings use strict typed bindings. ConfigKit owns imports, overlay composition, inheritance,
|
||||||
presence, typed secrets, and native source/history evidence. Narratio's
|
presence, typed secrets, and native source/history evidence. Narratio's
|
||||||
supported definition callbacks complete configuration-owned defaults,
|
supported definition callbacks complete configuration-owned defaults,
|
||||||
normalization, resource resolution, and validation before handoff. Consumers
|
normalization, resource resolution, and validation before handoff. Consumers
|
||||||
@@ -73,9 +74,9 @@ entry imports use the source file's native relative context.
|
|||||||
## Canonical Party And Derived Catalog
|
## Canonical Party And Derived Catalog
|
||||||
|
|
||||||
File-backed party loading supports imports; contextless `ParseParty` accepts
|
File-backed party loading supports imports; contextless `ParseParty` accepts
|
||||||
bytes. The definition checks the main version and effective roster. Native
|
bytes. The completed native mapping is validated against the shared contract and
|
||||||
source coordinates establish roster order, favoring each child's declaration.
|
Narratio's roster requirements. Character IDs determine projection order. The
|
||||||
A deterministic renderer materializes canonical party YAML. The selected roster
|
native result supplies standalone canonical party YAML. The selected roster
|
||||||
supplies both the players projection and concrete family members, including when
|
supplies both the players projection and concrete family members, including when
|
||||||
an explicit party file replaces the campaign default.
|
an explicit party file replaces the campaign default.
|
||||||
|
|
||||||
|
|||||||
@@ -213,6 +213,14 @@ artifacts. Family keys, dependencies, and repeated player names still work.
|
|||||||
|
|
||||||
## Stage 5 — Replace campaign and session configuration shapes
|
## Stage 5 — Replace campaign and session configuration shapes
|
||||||
|
|
||||||
|
**Complete.** Commit: `Adopt shared campaign and session configuration`.
|
||||||
|
Verification: focused shared-campaign, session-default, imported-origin,
|
||||||
|
snapshot, party, family, and template-path tests passed with Go 1.27.4;
|
||||||
|
`go test ./... -run '^$'` compiled all packages. A broader configuration and
|
||||||
|
application test run still contains many retired campaign/session fixtures and
|
||||||
|
the old prepared-autocorrection and spell-input consumers; acquisition,
|
||||||
|
preparation, and fixture reconciliation belong to Stages 6, 8, 21, and 22.
|
||||||
|
|
||||||
**Read:** roadmap “Campaign and session field layout” and “Shared acquisition”;
|
**Read:** roadmap “Campaign and session field layout” and “Shared acquisition”;
|
||||||
[Configuration Internals](../internal/configuration.md). Entry points:
|
[Configuration Internals](../internal/configuration.md). Entry points:
|
||||||
`config.go`, `document_configkit.go`, validation, resource resolution, and renderers.
|
`config.go`, `document_configkit.go`, validation, resource resolution, and renderers.
|
||||||
|
|||||||
@@ -449,12 +449,14 @@ notification:
|
|||||||
inputs:
|
inputs:
|
||||||
audio_dir: ./audio
|
audio_dir: ./audio
|
||||||
`
|
`
|
||||||
campaignYAML := `campaign_id: sample-campaign
|
campaignYAML := `schema_version: maximumdirect.rpg.campaign.v1
|
||||||
inputs:
|
id: sample-campaign
|
||||||
speakers_file: ./speakers.yml
|
references:
|
||||||
autocorrect_file: ./autocorrect.yml
|
party: ./party.yml
|
||||||
glossary_file: ./glossary.yml
|
narratio:
|
||||||
party_file: ./party.yml
|
inputs:
|
||||||
|
speakers_file: ./speakers.yml
|
||||||
|
glossary_file: ./glossary.yml
|
||||||
`
|
`
|
||||||
|
|
||||||
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
|
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func configurationCommand(deps commandDependencies) commandkit.Command {
|
|||||||
return cfg.ConfigKitResult(), nil
|
return cfg.ConfigKitResult(), nil
|
||||||
})
|
})
|
||||||
app.Features.Overrides = true
|
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)
|
acquired := state.acquisition(selection, input)
|
||||||
cfg, err := acquired.Campaign(ctx)
|
cfg, err := acquired.Campaign(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -607,7 +607,7 @@ func artifactFamilyPipelineYAML(families string) string {
|
|||||||
func writeArtifactFamilyConfig(t *testing.T, dir, pipeline string) (string, string, string) {
|
func writeArtifactFamilyConfig(t *testing.T, dir, pipeline string) (string, string, string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
pipelinePath := writePartyResolutionFile(t, filepath.Join(dir, "pipeline.yml"), pipeline)
|
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")
|
sessionPath := writePartyResolutionFile(t, filepath.Join(dir, "session.yml"), "session_id: session\ncampaign: campaign\ninputs:\n audio_dir: audio\n")
|
||||||
return pipelinePath, campaignPath, sessionPath
|
return pipelinePath, campaignPath, sessionPath
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,8 +94,9 @@ func ArtifactFamilyIdentity(catalog *ArtifactCatalog, key string) (family, chara
|
|||||||
|
|
||||||
// CampaignsConfig configures the local campaign registry.
|
// CampaignsConfig configures the local campaign registry.
|
||||||
type CampaignsConfig struct {
|
type CampaignsConfig struct {
|
||||||
Root string `yaml:"root" json:"root"`
|
Root string `yaml:"root" json:"root"`
|
||||||
DefaultCampaignID string `yaml:"default_campaign_id" json:"default_campaign_id"`
|
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.
|
// CampaignConfig contains stable campaign-level identity and input defaults.
|
||||||
@@ -106,16 +107,47 @@ type CampaignConfig struct {
|
|||||||
resolution *documentResolution
|
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.
|
// CampaignInputsConfig contains stable campaign-level input file references.
|
||||||
type CampaignInputsConfig struct {
|
type CampaignInputsConfig struct {
|
||||||
Setting *string `yaml:"setting" json:"setting"`
|
Setting *string `yaml:"setting" json:"setting"`
|
||||||
System *string `yaml:"system" json:"system"`
|
System *string `yaml:"system" json:"system"`
|
||||||
Glossary map[string]any `yaml:"glossary" json:"glossary"`
|
Glossary map[string]any `yaml:"glossary" json:"glossary"`
|
||||||
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
||||||
AutocorrectFile string `yaml:"autocorrect_file" json:"autocorrect_file"`
|
AutocorrectFile string `yaml:"autocorrect_file" json:"autocorrect_file"`
|
||||||
GlossaryFile *string `yaml:"glossary_file" json:"glossary_file"`
|
GlossaryFile *string `yaml:"glossary_file" json:"glossary_file"`
|
||||||
PartyFile string `yaml:"party_file" json:"party_file"`
|
PartyFile string `yaml:"party_file" json:"party_file"`
|
||||||
SpellCatalogFile string `yaml:"spell_catalog_file" json:"spell_catalog_file"`
|
SpellCatalogFile string `yaml:"spell_catalog_file" json:"spell_catalog_file"`
|
||||||
|
Autocorrect []AutocorrectionRule `yaml:"autocorrect" json:"autocorrect"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionConfig contains per-session inputs and metadata.
|
// SessionConfig contains per-session inputs and metadata.
|
||||||
@@ -389,9 +421,10 @@ type SessionInputsConfig struct {
|
|||||||
AudioFiles []string `yaml:"audio_files" json:"audio_files"`
|
AudioFiles []string `yaml:"audio_files" json:"audio_files"`
|
||||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3" json:"audio_s3"`
|
AudioS3 *SessionAudioS3Input `yaml:"audio_s3" json:"audio_s3"`
|
||||||
SpeakersFile string `yaml:"speakers_file" json:"speakers_file"`
|
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"`
|
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.
|
// SessionAudioS3Input configures S3 session-audio input discovery.
|
||||||
|
|||||||
@@ -7,20 +7,21 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/domaininput"
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxConfigDocumentBytes int64 = 8 << 20
|
const maxConfigDocumentBytes int64 = 8 << 20
|
||||||
|
|
||||||
type documentResolution struct {
|
type documentResolution struct {
|
||||||
campaign *configkit.Result[CampaignConfig]
|
campaign *configkit.Result[CampaignDocument]
|
||||||
session *configkit.Result[SessionConfig]
|
session *configkit.Result[SessionConfig]
|
||||||
sources map[string]string
|
sources map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigKitResult returns the campaign's actual completed native load result.
|
// ConfigKitResult returns the campaign's actual completed native load result.
|
||||||
// Constructed campaign values have no 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 {
|
if cfg == nil || cfg.resolution == nil {
|
||||||
return 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")
|
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] {
|
func campaignDefinition(invocationDir string, sources map[string]string, expected string) configkit.Definition[CampaignDocument] {
|
||||||
return configkit.Definition[CampaignConfig]{Resolve: func(cfg *CampaignConfig, resolution *configkit.Resolution) error {
|
presence := make(map[string]configkit.FieldInfo)
|
||||||
documentResource(resolution, configkit.Keys("session_template_file"), &cfg.SessionTemplateFile, invocationDir, sources)
|
return configkit.Definition[CampaignDocument]{Resolve: func(cfg *CampaignDocument, resolution *configkit.Resolution) error {
|
||||||
inputs := configkit.Keys("inputs")
|
narratio := configkit.Keys("narratio")
|
||||||
for _, field := range []struct {
|
documentResource(resolution, narratio.Key("session_template_file"), &cfg.Narratio.SessionTemplateFile, invocationDir, sources)
|
||||||
name string
|
inputs := narratio.Key("inputs")
|
||||||
value *string
|
documentResource(resolution, inputs.Key("speakers_file"), &cfg.Narratio.Inputs.SpeakersFile, invocationDir, sources)
|
||||||
}{
|
documentOptionalResource(resolution, inputs.Key("glossary_file"), &cfg.Narratio.Inputs.GlossaryFile, invocationDir, sources)
|
||||||
{"speakers_file", &cfg.Inputs.SpeakersFile}, {"autocorrect_file", &cfg.Inputs.AutocorrectFile},
|
if party, ok := cfg.References["party"].(string); ok {
|
||||||
{"party_file", &cfg.Inputs.PartyFile},
|
documentResource(resolution, configkit.Keys("references", "party"), &party, invocationDir, sources)
|
||||||
{"spell_catalog_file", &cfg.Inputs.SpellCatalogFile},
|
cfg.References["party"] = party
|
||||||
} {
|
|
||||||
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
|
||||||
}
|
}
|
||||||
if cfg.Inputs.GlossaryFile != nil {
|
for _, name := range []string{"schema_version", "id", "name", "description", "setting", "system", "references"} {
|
||||||
documentOptionalResource(resolution, inputs.Key("glossary_file"), &cfg.Inputs.GlossaryFile, invocationDir, sources)
|
if info, ok := resolution.EntryInfo(configkit.Keys(name)); ok {
|
||||||
|
presence[name] = info
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, Validate: func(cfg *CampaignConfig, v *configkit.Validation) {
|
}, Validate: func(cfg *CampaignDocument, v *configkit.Validation) {
|
||||||
validateCampaignConfigKit(cfg, v)
|
shared := make(map[string]any, len(cfg.Extensions)+7)
|
||||||
validateIdentity(v, "campaign_id", expected, CampaignID(cfg))
|
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
|
value *string
|
||||||
}{
|
}{
|
||||||
{"audio_dir", &cfg.Inputs.AudioDir}, {"speakers_file", &cfg.Inputs.SpeakersFile},
|
{"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)
|
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
||||||
}
|
}
|
||||||
@@ -165,8 +193,6 @@ func applyCampaignSessionDefaults(cfg *SessionConfig, resolution *configkit.Reso
|
|||||||
target *string
|
target *string
|
||||||
}{
|
}{
|
||||||
{"speakers_file", campaign.Inputs.SpeakersFile, &cfg.Inputs.SpeakersFile},
|
{"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 != "" {
|
if field.value != "" {
|
||||||
configkit.Default(resolution, configkit.Keys("inputs", field.name), field.target, field.value, reason)
|
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 {
|
if campaign.Inputs.Glossary != nil {
|
||||||
configkit.Default(resolution, configkit.Keys("inputs", "glossary"), &cfg.Inputs.Glossary, campaign.Inputs.Glossary, reason)
|
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.
|
// LoadCampaignWithIdentity validates an optional asserted identity within the native load.
|
||||||
@@ -197,15 +226,33 @@ func LoadCampaignWithIdentity(path, expected string) (*CampaignConfig, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sources := make(map[string]string)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("load campaign config: %w", err)
|
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}
|
cfg.resolution = &documentResolution{campaign: result, sources: sources}
|
||||||
return cfg, nil
|
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) {
|
func loadSessionSource(source configkit.Source, label string, opts SessionLoadOptions, imports bool) (*SessionConfig, string, error) {
|
||||||
return loadSessionSourceWithFilesystem(source, label, opts, imports, nil)
|
return loadSessionSourceWithFilesystem(source, label, opts, imports, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,13 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
"gopkg.in/yaml.v3"
|
"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.
|
// RenderCampaignDocument serializes the loaded effective campaign document.
|
||||||
func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
@@ -27,13 +20,34 @@ func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
|||||||
if doc == nil {
|
if doc == nil {
|
||||||
return nil, fmt.Errorf("campaign document is required")
|
return nil, fmt.Errorf("campaign document is required")
|
||||||
}
|
}
|
||||||
value := struct {
|
if result := doc.ConfigKitResult(); result != nil {
|
||||||
CampaignID string `yaml:"campaign_id"`
|
var output bytes.Buffer
|
||||||
SessionTemplateFile string `yaml:"session_template_file,omitempty"`
|
if err := result.WriteEffective(&output); err != nil {
|
||||||
Inputs renderedCampaignInputs `yaml:"inputs"`
|
return nil, err
|
||||||
}{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),
|
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)
|
return yaml.Marshal(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,17 +81,24 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
|||||||
return &value
|
return &value
|
||||||
}
|
}
|
||||||
inputs := struct {
|
inputs := struct {
|
||||||
AudioDir string `yaml:"audio_dir,omitempty"`
|
AudioDir string `yaml:"audio_dir,omitempty"`
|
||||||
AudioFiles []string `yaml:"audio_files,omitempty"`
|
AudioFiles []string `yaml:"audio_files,omitempty"`
|
||||||
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
||||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||||
AutocorrectFile *string `yaml:"autocorrect_file,omitempty"`
|
Extra map[string]any `yaml:",inline"`
|
||||||
SpellCatalogFile *string `yaml:"spell_catalog_file,omitempty"`
|
|
||||||
Extra map[string]any `yaml:",inline"`
|
|
||||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||||
inputValue("autocorrect_file", doc.Inputs.AutocorrectFile),
|
glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, true)}
|
||||||
inputValue("spell_catalog_file", doc.Inputs.SpellCatalogFile), 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 {
|
value := struct {
|
||||||
SessionID string `yaml:"session_id"`
|
SessionID string `yaml:"session_id"`
|
||||||
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
||||||
@@ -89,13 +110,6 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
|||||||
return yaml.Marshal(value)
|
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 {
|
func glossaryFields(hasResult bool, metadata configkit.Metadata, setting, system, file *string, glossary map[string]any, authoredOnly bool) map[string]any {
|
||||||
result := map[string]any{}
|
result := map[string]any{}
|
||||||
for _, field := range []struct {
|
for _, field := range []struct {
|
||||||
|
|||||||
@@ -320,8 +320,15 @@ func deriveStableInputs(campaignCfg *CampaignConfig, sessionCfg *SessionConfig,
|
|||||||
reference.Source = "campaign_config"
|
reference.Source = "campaign_config"
|
||||||
metadata = campaignCfg.resolution
|
metadata = campaignCfg.resolution
|
||||||
}
|
}
|
||||||
if metadata != nil && metadata.sources["/inputs/"+field.name] != "" {
|
originPath := "/inputs/" + field.name
|
||||||
reference.ConfigPath = metadata.sources["/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
|
*field.target = reference
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,19 +72,20 @@ scriptorium:
|
|||||||
|
|
||||||
func TestNativeCampaignResultValidatesConfigurationWithoutReadingResources(t *testing.T) {
|
func TestNativeCampaignResultValidatesConfigurationWithoutReadingResources(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
root := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: settings/defaults.yml\ncampaign_id: sample\n")
|
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", `inputs:
|
writePipelineFixture(t, dir, "settings/defaults.yml", `references:
|
||||||
speakers_file: speakers.yml
|
party: party.yml
|
||||||
autocorrect_file: autocorrect.yml
|
narratio:
|
||||||
glossary_file: glossary.yml
|
inputs:
|
||||||
party_file: party.yml
|
speakers_file: speakers.yml
|
||||||
|
glossary_file: glossary.yml
|
||||||
`)
|
`)
|
||||||
cfg, err := LoadCampaign(root)
|
cfg, err := LoadCampaign(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
result := cfg.ConfigKitResult()
|
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")
|
t.Fatal("campaign did not retain its original load and imported source")
|
||||||
}
|
}
|
||||||
if cfg.Inputs.PartyFile != filepath.Join(dir, "settings", "party.yml") {
|
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 {
|
if err := result.WriteEffective(&output); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var shown CampaignConfig
|
var shown CampaignDocument
|
||||||
if err := yaml.Unmarshal(output.Bytes(), &shown); err != nil {
|
if err := yaml.Unmarshal(output.Bytes(), &shown); err != nil {
|
||||||
t.Fatal(err)
|
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")
|
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)
|
_, err = LoadCampaign(invalid)
|
||||||
var loadError *configkit.LoadError
|
var loadError *configkit.LoadError
|
||||||
if !errors.As(err, &loadError) {
|
if !errors.As(err, &loadError) {
|
||||||
t.Fatalf("campaign validation lost its native error: %v", err)
|
t.Fatalf("campaign validation lost its native error: %v", err)
|
||||||
}
|
}
|
||||||
findings := loadError.Diagnostics()
|
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)
|
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")
|
return ResolvedInputFile{}, fmt.Errorf("campaign config is required")
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(campaign.Inputs.PartyFile) == "" {
|
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
|
sourcePath := campaignPath
|
||||||
if campaign.resolution != nil && campaign.resolution.sources["/inputs/party_file"] != "" {
|
if campaign.resolution != nil && campaign.resolution.sources["/references/party"] != "" {
|
||||||
sourcePath = campaign.resolution.sources["/inputs/party_file"]
|
sourcePath = campaign.resolution.sources["/references/party"]
|
||||||
}
|
}
|
||||||
return ResolvedInputFile{
|
return ResolvedInputFile{
|
||||||
Path: campaign.Inputs.PartyFile,
|
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("workspace", "root"), &cfg.Workspace.Root, invocationDir)
|
||||||
resolveHostResource(resolution, configkit.Keys("campaigns", "root"), &cfg.Campaigns.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("spool", "root"), &cfg.Spool.Root, invocationDir)
|
||||||
resolveHostResource(resolution, configkit.Keys("cache", "root"), &cfg.Cache.Root, invocationDir)
|
resolveHostResource(resolution, configkit.Keys("cache", "root"), &cfg.Cache.Root, invocationDir)
|
||||||
resolveHostResource(resolution, configkit.Keys("audita", "config_path"), &cfg.Audita.ConfigPath, 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) {
|
func TestInheritedNotariusPathsFollowSupplyingSource(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
pipelinePath := writePipelineFixture(t, dir, "pipeline.yml", `config:
|
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
|
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) {
|
func campaignConfigurationError(cfg *CampaignConfig) (configkit.Path, error) {
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
return configkit.Keys(), fmt.Errorf("campaign config is required")
|
return configkit.Keys(), fmt.Errorf("campaign config is required")
|
||||||
}
|
}
|
||||||
if CampaignID(cfg) == "" {
|
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 {
|
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) == "" {
|
if strings.TrimSpace(cfg.Inputs.SpeakersFile) == "" {
|
||||||
return configkit.Keys("inputs", "speakers_file"), fmt.Errorf("campaign.inputs.speakers_file is required")
|
return configkit.Keys("narratio", "inputs", "speakers_file"), fmt.Errorf("campaign.narratio.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")
|
|
||||||
}
|
}
|
||||||
if strings.TrimSpace(cfg.Inputs.PartyFile) == "" {
|
if strings.TrimSpace(cfg.Inputs.PartyFile) == "" {
|
||||||
return configkit.Keys("inputs", "party_file"), fmt.Errorf("campaign.inputs.party_file is required")
|
return configkit.Keys("references", "party"), fmt.Errorf("campaign.references.party 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(), nil
|
return configkit.Keys(), nil
|
||||||
}
|
}
|
||||||
@@ -83,12 +70,6 @@ func sessionConfigurationError(cfg *SessionConfig) (configkit.Path, error) {
|
|||||||
if strings.TrimSpace(cfg.Inputs.SpeakersFile) == "" {
|
if strings.TrimSpace(cfg.Inputs.SpeakersFile) == "" {
|
||||||
return configkit.Keys("inputs", "speakers_file"), fmt.Errorf("session.inputs.speakers_file is required")
|
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) != ""
|
hasAudioDir := strings.TrimSpace(cfg.Inputs.AudioDir) != ""
|
||||||
hasAudioFiles := len(cfg.Inputs.AudioFiles) > 0
|
hasAudioFiles := len(cfg.Inputs.AudioFiles) > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user