Complete native session acquisition and initialization

This commit is contained in:
2026-11-30 00:19:42 +00:00
parent d5e6d44fa7
commit c70de21a7b
12 changed files with 203 additions and 56 deletions

View File

@@ -111,11 +111,6 @@ type CampaignConfig struct {
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"`
}

View File

@@ -77,20 +77,16 @@ func documentOptionalResource(resolution *configkit.Resolution, path configkit.P
}
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
}
for _, name := range []string{"schema_version", "id", "name", "description", "setting", "system", "references"} {
if info, ok := resolution.EntryInfo(configkit.Keys(name)); ok {
presence[name] = info
if references, ok := cfg.Extensions["references"].(map[string]any); ok {
if party, ok := references["party"].(string); ok {
documentResource(resolution, configkit.Keys("references", "party"), &party, invocationDir, sources)
references["party"] = party
}
}
return nil
@@ -99,21 +95,8 @@ func campaignDefinition(invocationDir string, sources map[string]string, expecte
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
}
}
}
shared["schema_version"] = cfg.SchemaVersion
shared["id"] = cfg.ID
if err := domaininput.ValidateCampaign(shared); err != nil {
v.Error(configkit.Keys(), err.Error())
}
@@ -241,14 +224,16 @@ func campaignDomain(doc CampaignDocument) *CampaignConfig {
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 {
if value, ok := doc.Extensions["setting"].(string); ok {
cfg.Inputs.Setting = &value
}
if value, ok := doc.System.(string); ok {
if value, ok := doc.Extensions["system"].(string); ok {
cfg.Inputs.System = &value
}
if value, ok := doc.References["party"].(string); ok {
cfg.Inputs.PartyFile = value
if references, ok := doc.Extensions["references"].(map[string]any); ok {
if value, ok := references["party"].(string); ok {
cfg.Inputs.PartyFile = value
}
}
return cfg
}

View File

@@ -75,6 +75,10 @@ narratio:
if !bytes.Contains(output, []byte("extension:")) {
t.Fatalf("extension lost: %s", output)
}
snapshot := writePipelineFixture(t, dir, "campaign-snapshot.yml", string(output))
if _, err := LoadCampaign(snapshot); err != nil {
t.Fatalf("standalone campaign snapshot is invalid: %v\n%s", err, output)
}
}
func TestSharedCampaignLoadsWithRosterWithoutArtifactFamilies(t *testing.T) {