Complete native session acquisition and initialization
This commit is contained in:
@@ -220,6 +220,8 @@ snapshot, party, family, and template-path tests passed with Go 1.27.4;
|
|||||||
application test run still contains many retired campaign/session fixtures and
|
application test run still contains many retired campaign/session fixtures and
|
||||||
the old prepared-autocorrection and spell-input consumers; acquisition,
|
the old prepared-autocorrection and spell-input consumers; acquisition,
|
||||||
preparation, and fixture reconciliation belong to Stages 6, 8, 21, and 22.
|
preparation, and fixture reconciliation belong to Stages 6, 8, 21, and 22.
|
||||||
|
The shared optional-field binding and snapshot round trip were corrected in the
|
||||||
|
following session-acquisition commit after inspection exposed null expansion.
|
||||||
|
|
||||||
**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:
|
||||||
@@ -251,6 +253,12 @@ unknown operational fields. Exercise file and contextless session snapshots.
|
|||||||
|
|
||||||
## Stage 6 — Complete native acquisition, inspection, and session initialization
|
## Stage 6 — Complete native acquisition, inspection, and session initialization
|
||||||
|
|
||||||
|
**Complete.** Commit: `Complete native session acquisition and initialization`.
|
||||||
|
Verification: focused application tests for acquisition, independent native
|
||||||
|
inspection, party selection, remote authored-document preference, three-document
|
||||||
|
initialization, both template overrides, invalid templates, and template-relative
|
||||||
|
imports passed with Go 1.27.4. Focused shared-configuration tests also passed.
|
||||||
|
|
||||||
**Read:** roadmap “Author once” and “Worked campaign bundle”; native acquisition
|
**Read:** roadmap “Author once” and “Worked campaign bundle”; native acquisition
|
||||||
and inspection sections of Configuration Internals. Entry points:
|
and inspection sections of Configuration Internals. Entry points:
|
||||||
`configuration_acquisition.go`, `configuration_commands.go`, campaign selection,
|
`configuration_acquisition.go`, `configuration_commands.go`, campaign selection,
|
||||||
|
|||||||
@@ -495,12 +495,13 @@ func materializePrepareResumeFixture(t *testing.T, pipelinePath, campaignPath, s
|
|||||||
func writeAppTestCampaignConfig(t *testing.T, dir string) string {
|
func writeAppTestCampaignConfig(t *testing.T, dir string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
campaignPath := filepath.Join(dir, "campaign.yml")
|
campaignPath := filepath.Join(dir, "campaign.yml")
|
||||||
campaignYAML := `campaign_id: sample-campaign
|
campaignYAML := `schema_version: maximumdirect.rpg.campaign.v1
|
||||||
inputs:
|
id: sample-campaign
|
||||||
speakers_file: ./speakers.yml
|
references: {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
|
||||||
`
|
`
|
||||||
if err := os.WriteFile(campaignPath, []byte(campaignYAML), 0o644); err != nil {
|
if err := os.WriteFile(campaignPath, []byte(campaignYAML), 0o644); err != nil {
|
||||||
t.Fatalf("write campaign.yml: %v", err)
|
t.Fatalf("write campaign.yml: %v", err)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestConfigurationCommandsInspectActualDocuments(t *testing.T) {
|
|||||||
selectors []string
|
selectors []string
|
||||||
}{
|
}{
|
||||||
{"app", "workspace", []string{"--config", pipeline}},
|
{"app", "workspace", []string{"--config", pipeline}},
|
||||||
{"campaign", "campaign_id", []string{"--campaign-file", campaign}},
|
{"campaign", "id", []string{"--campaign-file", campaign}},
|
||||||
{"session", "session_id", []string{"--campaign-file", campaign, "--session-file", session}},
|
{"session", "session_id", []string{"--campaign-file", campaign, "--session-file", session}},
|
||||||
{"party", "characters", []string{"--party-file", party.Source.Path}},
|
{"party", "characters", []string{"--party-file", party.Source.Path}},
|
||||||
} {
|
} {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func TestConfigurationComparisonSeparatesCampaignSessionAndRoster(t *testing.T)
|
|||||||
scope, path string
|
scope, path string
|
||||||
selectors []string
|
selectors []string
|
||||||
}{
|
}{
|
||||||
{"campaign", "/campaign_id", []string{"--campaign-file", leftCampaign, "--against-campaign-file", rightCampaign}},
|
{"campaign", "/id", []string{"--campaign-file", leftCampaign, "--against-campaign-file", rightCampaign}},
|
||||||
{"session", "/title", []string{"--campaign-file", leftCampaign, "--session", "2026-05-03", "--session-file", leftSession, "--against-campaign-file", rightCampaign, "--against-session", "2026-05-03", "--against-session-file", rightSession}},
|
{"session", "/title", []string{"--campaign-file", leftCampaign, "--session", "2026-05-03", "--session-file", leftSession, "--against-campaign-file", rightCampaign, "--against-session", "2026-05-03", "--against-session-file", rightSession}},
|
||||||
{"party", "/characters", []string{"--party-file", leftParty.Source.Path, "--against-campaign-file", rightCampaign}},
|
{"party", "/characters", []string{"--party-file", leftParty.Source.Path, "--against-campaign-file", rightCampaign}},
|
||||||
{"party", "/characters", []string{"--party-file", leftParty.Source.Path, "--against-party-file", party.Source.Path}},
|
{"party", "/characters", []string{"--party-file", leftParty.Source.Path, "--against-party-file", party.Source.Path}},
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ func TestExecuteSessionInitUsesImportedTemplateLocation(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
mustWriteTestFile(t, filepath.Join(dir, "fragments", "template-settings.yml"), "session_template_file: templates/session.yml\n")
|
mustWriteTestFile(t, filepath.Join(dir, "fragments", "template-settings.yml"), "narratio:\n session_template_file: templates/session.yml\n")
|
||||||
mustWriteTestFile(t, filepath.Join(dir, "fragments", "templates", "session.yml"), "session_id: '{{ session_id }}'\ninputs:\n audio_s3: {prefix: audio/}\n")
|
mustWriteTestFile(t, filepath.Join(dir, "fragments", "templates", "session.yml"), "session_id: '{{ session_id }}'\ninputs:\n audio_s3: {prefix: audio/}\n")
|
||||||
if err := os.WriteFile(campaign, append([]byte("config:\n imports:\n - path: fragments/template-settings.yml\n"), original...), 0o644); err != nil {
|
if err := os.WriteFile(campaign, append([]byte("config:\n imports:\n - path: fragments/template-settings.yml\n"), original...), 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -818,7 +818,7 @@ func addSessionTemplateToCampaign(t *testing.T, campaignPath, templateFile strin
|
|||||||
if strings.Contains(string(data), "session_template_file:") {
|
if strings.Contains(string(data), "session_template_file:") {
|
||||||
t.Fatalf("campaign config already has session_template_file: %q", string(data))
|
t.Fatalf("campaign config already has session_template_file: %q", string(data))
|
||||||
}
|
}
|
||||||
updated := "session_template_file: " + templateFile + "\n" + string(data)
|
updated := strings.Replace(string(data), "narratio:\n", "narratio:\n session_template_file: "+templateFile+"\n", 1)
|
||||||
if err := os.WriteFile(campaignPath, []byte(updated), 0o644); err != nil {
|
if err := os.WriteFile(campaignPath, []byte(updated), 0o644); err != nil {
|
||||||
t.Fatalf("write campaign config: %v", err)
|
t.Fatalf("write campaign config: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ inputs:
|
|||||||
if err := os.WriteFile(templatePath, []byte(template), 0o644); err != nil {
|
if err := os.WriteFile(templatePath, []byte(template), 0o644); err != nil {
|
||||||
t.Fatalf("write session template: %v", err)
|
t.Fatalf("write session template: %v", err)
|
||||||
}
|
}
|
||||||
campaign := `campaign_id: sample-campaign
|
campaign := `schema_version: maximumdirect.rpg.campaign.v1
|
||||||
session_template_file: session.template.yml
|
id: sample-campaign
|
||||||
inputs:
|
references: {party: ./party.yml}
|
||||||
speakers_file: ./speakers.yml
|
narratio:
|
||||||
autocorrect_file: ./autocorrect.yml
|
session_template_file: session.template.yml
|
||||||
glossary_file: ./glossary.yml
|
inputs:
|
||||||
party_file: ./party.yml
|
speakers_file: ./speakers.yml
|
||||||
|
glossary_file: ./glossary.yml
|
||||||
`
|
`
|
||||||
if err := os.WriteFile(campaignPath, []byte(campaign), 0o644); err != nil {
|
if err := os.WriteFile(campaignPath, []byte(campaign), 0o644); err != nil {
|
||||||
t.Fatalf("write campaign config: %v", err)
|
t.Fatalf("write campaign config: %v", err)
|
||||||
|
|||||||
@@ -66,15 +66,50 @@ func TestInvalidDiscoveredSessionDoesNotTriggerRemoteFallback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRemoteSessionPrefersAuthoredDocumentOverCommittedSnapshot(t *testing.T) {
|
||||||
|
root := t.TempDir()
|
||||||
|
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, root)
|
||||||
|
fake := &storage.FakeBackend{}
|
||||||
|
cfg, _, _, _ := seedRestoreCommittedState(t, fake, pipelinePath, campaignPath, filepath.Join(filepath.Dir(pipelinePath), "session.yml"))
|
||||||
|
current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", nil)
|
||||||
|
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(current.SessionPrefix, current.RunID), "prepare/inputs/session.yml")
|
||||||
|
fake.SeedObject(storage.FakeObject{Key: key, Data: []byte("session_id: 2026-05-03\ntitle: Committed\ninputs: {audio_s3: {prefix: audio/}}\n")})
|
||||||
|
current.Commit.Artifacts = append(current.Commit.Artifacts, remoteRestoreArtifact(fake, artifacts.RemoteArtifactTypeRunFile, "run:prepare/inputs/session.yml", key))
|
||||||
|
commitData, err := artifacts.EncodeRemoteCommitManifest(*current.Commit)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
commitKey := artifacts.S3RunCommitKey(current.SessionPrefix, current.RunID)
|
||||||
|
fake.SeedObject(storage.FakeObject{Key: commitKey, Data: commitData})
|
||||||
|
pointer, err := artifacts.EncodeCurrentCommitPointer(artifacts.CurrentCommitPointer{FormatVersion: artifacts.RemoteCommitFormatVersion, Campaign: cfg.Session.Campaign, SessionID: cfg.Session.SessionID, RunID: current.RunID, CommitKey: commitKey, CommitSHA256: restoreCommitSHA256(commitData), CommitSize: int64(len(commitData)), CommitGeneration: fake.Objects[commitKey].ETag})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fake.SeedObject(storage.FakeObject{Key: artifacts.S3CurrentCommitPointerKey(current.SessionPrefix), Data: pointer})
|
||||||
|
seedRemoteSessionConfig(t, fake, cfg.Session.SessionID, "session_id: 2026-05-03\ntitle: Authored\ninputs: {audio_s3: {prefix: audio/}}\n")
|
||||||
|
setSessionConfigSearchPaths(t, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||||
|
deps, _ := remoteSessionLoaderDependencies(fake)
|
||||||
|
acquired := newConfigurationAcquisition(configurationSelection{Config: suppliedSelection(pipelinePath), CampaignFile: suppliedSelection(campaignPath), Session: suppliedSelection(cfg.Session.SessionID)}, deps)
|
||||||
|
defer acquired.Close()
|
||||||
|
session, err := acquired.Session(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if session.Title != "Authored" || acquired.session.Source.Source != "session_config.s3" {
|
||||||
|
t.Fatalf("selected session: %+v, source: %+v", session, acquired.session.Source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRemoteSessionLoadingRetainsCampaignCanonicalParty(t *testing.T) {
|
func TestRemoteSessionLoadingRetainsCampaignCanonicalParty(t *testing.T) {
|
||||||
workspaceRoot := t.TempDir()
|
workspaceRoot := t.TempDir()
|
||||||
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
|
||||||
canonicalCampaign := `campaign_id: sample-campaign
|
canonicalCampaign := `schema_version: maximumdirect.rpg.campaign.v1
|
||||||
inputs:
|
id: sample-campaign
|
||||||
speakers_file: ./speakers.yml
|
references: {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
|
||||||
`
|
`
|
||||||
if err := os.WriteFile(campaignPath, []byte(canonicalCampaign), 0o644); err != nil {
|
if err := os.WriteFile(campaignPath, []byte(canonicalCampaign), 0o644); err != nil {
|
||||||
t.Fatalf("write canonical campaign: %v", err)
|
t.Fatalf("write canonical campaign: %v", err)
|
||||||
|
|||||||
@@ -117,10 +117,14 @@ func initializeSession(ctx context.Context, request *sessionInitializationInput,
|
|||||||
}
|
}
|
||||||
base := &config.LoadedPipelineCampaign{Pipeline: pipeline, PipelinePath: acquired.pipelinePath, Campaign: campaign, CampaignPath: acquired.campaignPath, Party: *party, ArtifactCatalog: catalog}
|
base := &config.LoadedPipelineCampaign{Pipeline: pipeline, PipelinePath: acquired.pipelinePath, Campaign: campaign, CampaignPath: acquired.campaignPath, Party: *party, ArtifactCatalog: catalog}
|
||||||
|
|
||||||
|
template := base.Campaign.SessionTemplateFile
|
||||||
|
if strings.TrimSpace(template) == "" {
|
||||||
|
template = base.Pipeline.Campaigns.SessionTemplateFile
|
||||||
|
}
|
||||||
input := sessionInitInput{
|
input := sessionInitInput{
|
||||||
Campaign: config.CampaignID(base.Campaign),
|
Campaign: config.CampaignID(base.Campaign),
|
||||||
CampaignPath: base.CampaignPath,
|
CampaignPath: base.CampaignPath,
|
||||||
TemplateFile: base.Campaign.SessionTemplateFile,
|
TemplateFile: template,
|
||||||
SessionID: sessionID,
|
SessionID: sessionID,
|
||||||
PreviousSessionID: previousSessionID,
|
PreviousSessionID: previousSessionID,
|
||||||
Date: date,
|
Date: date,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
@@ -12,6 +13,119 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSessionInitWithThreeCampaignDocuments(t *testing.T) {
|
||||||
|
pipeline, campaign, _ := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
data, err := os.ReadFile(campaign)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
data = bytes.Replace(data, []byte(" glossary_file: ./glossary.yml\n"), nil, 1)
|
||||||
|
if err := os.WriteFile(campaign, data, 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, name := range []string{"glossary.yml", "autocorrect.yml"} {
|
||||||
|
if err := os.Remove(filepath.Join(filepath.Dir(campaign), name)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output := filepath.Join(t.TempDir(), "session.yml")
|
||||||
|
if err := invokeNativeCommand(context.Background(), []string{"session", "init", "2026-06-07", "--config", pipeline, "--campaign-file", campaign, "--output", output}, &bytes.Buffer{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := config.LoadSessionWithOptions(output, sessionInitLoadOptions(t, campaign)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionInitSelectsTemplatesInPriorityOrder(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
installation, campaign bool
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"built in", false, false, ""},
|
||||||
|
{"installation", true, false, "Installation"},
|
||||||
|
{"campaign", true, true, "Campaign"},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
pipeline, campaign, _ := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
if tc.installation {
|
||||||
|
template := filepath.Join(filepath.Dir(pipeline), "installation.yml")
|
||||||
|
mustWriteTestFile(t, template, "session_id: '{{ session_id }}'\ntitle: Installation\ninputs: {audio_s3: {prefix: audio/}}\n")
|
||||||
|
data, err := os.ReadFile(pipeline)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
updated := strings.Replace(string(data), "campaigns:\n", "campaigns:\n session_template_file: installation.yml\n", 1)
|
||||||
|
if err := os.WriteFile(pipeline, []byte(updated), 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tc.campaign {
|
||||||
|
writeSessionInitTemplate(t, campaign, "session_id: '{{ session_id }}'\ntitle: Campaign\ninputs: {audio_s3: {prefix: audio/}}\n")
|
||||||
|
}
|
||||||
|
output := filepath.Join(t.TempDir(), "session.yml")
|
||||||
|
if err := invokeNativeCommand(context.Background(), []string{"session", "init", "2026-06-07", "--config", pipeline, "--campaign-file", campaign, "--output", output}, &bytes.Buffer{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
loaded, err := config.LoadSessionWithOptions(output, sessionInitLoadOptions(t, campaign))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if loaded.Title != tc.want {
|
||||||
|
t.Fatalf("title = %q, want %q", loaded.Title, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionInitDoesNotFallbackFromInvalidSelectedTemplate(t *testing.T) {
|
||||||
|
pipeline, campaign, _ := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
data, err := os.ReadFile(pipeline)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
updated := strings.Replace(string(data), "campaigns:\n", "campaigns:\n session_template_file: missing.yml\n", 1)
|
||||||
|
if err := os.WriteFile(pipeline, []byte(updated), 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
output := filepath.Join(t.TempDir(), "session.yml")
|
||||||
|
if err := invokeNativeCommand(context.Background(), []string{"session", "init", "2026-06-07", "--config", pipeline, "--campaign-file", campaign, "--output", output}, &bytes.Buffer{}); err == nil {
|
||||||
|
t.Fatal("expected missing template error")
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(output); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("unexpected output: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSessionInitInstallationTemplateUsesItsOwnSourceContext(t *testing.T) {
|
||||||
|
pipeline, campaign, _ := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
base := filepath.Dir(pipeline)
|
||||||
|
profile := filepath.Join(base, "profiles", "campaigns.yml")
|
||||||
|
template := filepath.Join(base, "profiles", "templates", "session.yml")
|
||||||
|
mustWriteTestFile(t, profile, "campaigns: {session_template_file: templates/session.yml}\n")
|
||||||
|
mustWriteTestFile(t, template, "config:\n imports:\n - path: detail.yml\nsession_id: '{{ session_id }}'\ninputs: {audio_s3: {prefix: audio/}}\n")
|
||||||
|
mustWriteTestFile(t, filepath.Join(filepath.Dir(template), "detail.yml"), "title: Imported installation template\n")
|
||||||
|
data, err := os.ReadFile(pipeline)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(pipeline, append([]byte("config:\n imports:\n - path: profiles/campaigns.yml\n"), data...), 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
output := filepath.Join(t.TempDir(), "session.yml")
|
||||||
|
if err := invokeNativeCommand(context.Background(), []string{"session", "init", "2026-06-07", "--config", pipeline, "--campaign-file", campaign, "--output", output}, &bytes.Buffer{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
loaded, err := config.LoadSessionWithOptions(output, sessionInitLoadOptions(t, campaign))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if loaded.Title != "Imported installation template" {
|
||||||
|
t.Fatalf("title = %q", loaded.Title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSessionInitMaterializesLocalTemplateImports(t *testing.T) {
|
func TestSessionInitMaterializesLocalTemplateImports(t *testing.T) {
|
||||||
pipeline, campaign, _ := writeValidConfigFiles(t, t.TempDir())
|
pipeline, campaign, _ := writeValidConfigFiles(t, t.TempDir())
|
||||||
writeSessionInitTemplate(t, campaign, "config:\n imports:\n - path: shared.yml\n required: true\nsession_id: '{{ session_id }}'\ninputs:\n audio_s3: {prefix: audio/}\n")
|
writeSessionInitTemplate(t, campaign, "config:\n imports:\n - path: shared.yml\n required: true\nsession_id: '{{ session_id }}'\ninputs:\n audio_s3: {prefix: audio/}\n")
|
||||||
|
|||||||
@@ -111,11 +111,6 @@ type CampaignConfig struct {
|
|||||||
type CampaignDocument struct {
|
type CampaignDocument struct {
|
||||||
SchemaVersion string `yaml:"schema_version"`
|
SchemaVersion string `yaml:"schema_version"`
|
||||||
ID string `yaml:"id"`
|
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"`
|
Narratio CampaignNarratio `yaml:"narratio"`
|
||||||
Extensions map[string]any `yaml:",inline"`
|
Extensions map[string]any `yaml:",inline"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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] {
|
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 {
|
return configkit.Definition[CampaignDocument]{Resolve: func(cfg *CampaignDocument, resolution *configkit.Resolution) error {
|
||||||
narratio := configkit.Keys("narratio")
|
narratio := configkit.Keys("narratio")
|
||||||
documentResource(resolution, narratio.Key("session_template_file"), &cfg.Narratio.SessionTemplateFile, invocationDir, sources)
|
documentResource(resolution, narratio.Key("session_template_file"), &cfg.Narratio.SessionTemplateFile, invocationDir, sources)
|
||||||
inputs := narratio.Key("inputs")
|
inputs := narratio.Key("inputs")
|
||||||
documentResource(resolution, inputs.Key("speakers_file"), &cfg.Narratio.Inputs.SpeakersFile, invocationDir, sources)
|
documentResource(resolution, inputs.Key("speakers_file"), &cfg.Narratio.Inputs.SpeakersFile, invocationDir, sources)
|
||||||
documentOptionalResource(resolution, inputs.Key("glossary_file"), &cfg.Narratio.Inputs.GlossaryFile, invocationDir, sources)
|
documentOptionalResource(resolution, inputs.Key("glossary_file"), &cfg.Narratio.Inputs.GlossaryFile, invocationDir, sources)
|
||||||
if party, ok := cfg.References["party"].(string); ok {
|
if references, ok := cfg.Extensions["references"].(map[string]any); ok {
|
||||||
documentResource(resolution, configkit.Keys("references", "party"), &party, invocationDir, sources)
|
if party, ok := references["party"].(string); ok {
|
||||||
cfg.References["party"] = party
|
documentResource(resolution, configkit.Keys("references", "party"), &party, invocationDir, sources)
|
||||||
}
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -99,21 +95,8 @@ func campaignDefinition(invocationDir string, sources map[string]string, expecte
|
|||||||
for key, value := range cfg.Extensions {
|
for key, value := range cfg.Extensions {
|
||||||
shared[key] = value
|
shared[key] = value
|
||||||
}
|
}
|
||||||
for _, field := range []struct {
|
shared["schema_version"] = cfg.SchemaVersion
|
||||||
name string
|
shared["id"] = cfg.ID
|
||||||
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 {
|
if err := domaininput.ValidateCampaign(shared); err != nil {
|
||||||
v.Error(configkit.Keys(), err.Error())
|
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,
|
SpeakersFile: doc.Narratio.Inputs.SpeakersFile, GlossaryFile: doc.Narratio.Inputs.GlossaryFile,
|
||||||
Glossary: doc.Narratio.Inputs.Glossary, Autocorrect: doc.Narratio.Inputs.Autocorrect,
|
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
|
cfg.Inputs.Setting = &value
|
||||||
}
|
}
|
||||||
if value, ok := doc.System.(string); ok {
|
if value, ok := doc.Extensions["system"].(string); ok {
|
||||||
cfg.Inputs.System = &value
|
cfg.Inputs.System = &value
|
||||||
}
|
}
|
||||||
if value, ok := doc.References["party"].(string); ok {
|
if references, ok := doc.Extensions["references"].(map[string]any); ok {
|
||||||
cfg.Inputs.PartyFile = value
|
if value, ok := references["party"].(string); ok {
|
||||||
|
cfg.Inputs.PartyFile = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ narratio:
|
|||||||
if !bytes.Contains(output, []byte("extension:")) {
|
if !bytes.Contains(output, []byte("extension:")) {
|
||||||
t.Fatalf("extension lost: %s", output)
|
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) {
|
func TestSharedCampaignLoadsWithRosterWithoutArtifactFamilies(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user