Preserve campaign defaults in materialized sessions
This commit is contained in:
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -49,18 +50,35 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
if id == "" {
|
||||
id = sessionID
|
||||
}
|
||||
result := doc.ConfigKitResult()
|
||||
var metadata configkit.Metadata
|
||||
if result != nil {
|
||||
metadata = result.Metadata()
|
||||
}
|
||||
// Materialized sessions retain authored overrides and receiving-campaign defaults.
|
||||
inputValue := func(name, value string) *string {
|
||||
if result != nil {
|
||||
if !metadata.IsExplicit(configkit.Keys("inputs", name)) {
|
||||
return nil
|
||||
}
|
||||
} else if value == "" {
|
||||
return nil
|
||||
}
|
||||
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"`
|
||||
GlossaryFile string `yaml:"glossary_file,omitempty"`
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
AutocorrectFile *string `yaml:"autocorrect_file,omitempty"`
|
||||
GlossaryFile *string `yaml:"glossary_file,omitempty"`
|
||||
SpellCatalogFile *string `yaml:"spell_catalog_file,omitempty"`
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3, doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.GlossaryFile, nil}
|
||||
if doc.Inputs.SpellCatalogFile != "" || sessionFieldExplicit(doc, "spell_catalog_file") {
|
||||
inputs.SpellCatalogFile = &doc.Inputs.SpellCatalogFile
|
||||
}
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||
inputValue("autocorrect_file", doc.Inputs.AutocorrectFile),
|
||||
inputValue("glossary_file", doc.Inputs.GlossaryFile),
|
||||
inputValue("spell_catalog_file", doc.Inputs.SpellCatalogFile)}
|
||||
value := struct {
|
||||
SessionID string `yaml:"session_id"`
|
||||
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
||||
|
||||
@@ -89,6 +89,47 @@ func TestSessionDefaultsCompleteBeforeNativeHandoff(t *testing.T) {
|
||||
if !reflect.DeepEqual(reloaded.Inputs, cfg.Session.Inputs) {
|
||||
t.Fatalf("standalone rendering lost effective values or explicit clearing: %s", materialized)
|
||||
}
|
||||
writePipelineFixture(t, dir, "campaign/resources.yml", `inputs:
|
||||
speakers_file: replacement-speakers.yml
|
||||
autocorrect_file: replacement-autocorrect.yml
|
||||
glossary_file: replacement-glossary.yml
|
||||
party_file: party.yml
|
||||
spell_catalog_file: replacement-spells.yml
|
||||
`)
|
||||
receiving, err := LoadCampaign(campaign)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reloaded, err = LoadSessionBytesWithOptions("materialized", materialized, SessionLoadOptions{Campaign: receiving, CampaignPath: campaign})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reloaded.Inputs.GlossaryFile != receiving.Inputs.GlossaryFile || reloaded.Inputs.AutocorrectFile != receiving.Inputs.AutocorrectFile {
|
||||
t.Fatalf("materialization froze inherited inputs: %+v", reloaded.Inputs)
|
||||
}
|
||||
if reloaded.Inputs.SpeakersFile != cfg.Session.Inputs.SpeakersFile || reloaded.Inputs.SpellCatalogFile != "" {
|
||||
t.Fatalf("materialization lost explicit override or clearing: %+v", reloaded.Inputs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaterializedSessionOmitsInheritedSpellCatalog(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
campaignPath := writePipelineFixture(t, dir, "campaign.yml", "campaign_id: campaign\ninputs: {speakers_file: speakers.yml, autocorrect_file: autocorrect.yml, glossary_file: glossary.yml, party_file: party.yml, spell_catalog_file: spells.yml}\n")
|
||||
campaign, err := LoadCampaign(campaignPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
session, err := LoadSessionBytesWithOptions("session.yml", []byte("session_id: session\ninputs: {audio_dir: audio}\n"), SessionLoadOptions{Campaign: campaign, CampaignPath: campaignPath})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := RenderSessionDocument(&Config{Session: session}, "session")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(data), "spell_catalog_file") || strings.Contains(string(data), "speakers_file") {
|
||||
t.Fatalf("materialized inherited fields: %s", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionDefaultsRespectExplicitEmptyInputsAndIdentity(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user