Derive artifact catalogs from the selected party without changing configuration
This commit is contained in:
@@ -197,6 +197,15 @@ no later operation changes the captured session or campaign result.
|
||||
|
||||
## Stage 4: Derive party products and concrete artifact catalogs
|
||||
|
||||
**Completed.** Exposed the retained typed party result and exact explicit-roster
|
||||
selection. Concrete artifacts, dependency closure, family/member provenance,
|
||||
players, and publication rules are derived separately; completed pipeline and
|
||||
campaign values remain unchanged. Removed expansion state from PipelineConfig.
|
||||
The full configuration package and maintained examples pass with Go 1.27.4,
|
||||
including the dependency tests deferred from Stage 2 and independent-roster
|
||||
regressions. Whole-application compilation awaits the family-origin consumers'
|
||||
catalog wiring in Stage 5; no compatibility dispatcher or snapshot was added.
|
||||
|
||||
Read: `internal/config/party*.go`, `artifact_families.go`, `artifact_catalog.go`,
|
||||
the family declarations in `config.go`, and the roadmap's ownership boundary.
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -27,15 +26,20 @@ type EffectiveArtifactRecord struct {
|
||||
// EffectiveArtifactCatalog returns the deterministic concrete artifact catalog
|
||||
// consumed by runtime planning.
|
||||
func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]EffectiveArtifactRecord, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("pipeline config is required")
|
||||
catalog, err := DeriveArtifactCatalog(cfg, party)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cfg.Scriptorium == nil || len(cfg.Scriptorium.Artifacts) == 0 {
|
||||
return []EffectiveArtifactRecord{}, nil
|
||||
return catalog.Records, nil
|
||||
}
|
||||
|
||||
func concreteArtifactRecords(cfg *PipelineConfig, catalog *ArtifactCatalog, party ResolvedParty) []EffectiveArtifactRecord {
|
||||
if len(catalog.Artifacts) == 0 {
|
||||
return []EffectiveArtifactRecord{}
|
||||
}
|
||||
|
||||
keys := make([]string, 0, len(cfg.Scriptorium.Artifacts))
|
||||
for key := range cfg.Scriptorium.Artifacts {
|
||||
keys := make([]string, 0, len(catalog.Artifacts))
|
||||
for key := range catalog.Artifacts {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
@@ -43,7 +47,7 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
pathsByID := pipelineSourcePaths(cfg)
|
||||
partySources := partyCharacterSourceLookup(party)
|
||||
for _, key := range keys {
|
||||
artifact := cfg.Scriptorium.Artifacts[key]
|
||||
artifact := catalog.Artifacts[key]
|
||||
record := EffectiveArtifactRecord{
|
||||
Key: key,
|
||||
SourceID: artifactpolicy.ConfiguredSourceID(key),
|
||||
@@ -51,11 +55,11 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
OutputPath: artifact.OutputPath,
|
||||
Dependencies: append([]string(nil), artifact.DependsOn...),
|
||||
}
|
||||
if member, ok := cfg.familyCatalog.Members[key]; ok {
|
||||
record.DefinitionSources = append([]string(nil), cfg.familyCatalog.Families[member.Family].Sources...)
|
||||
if member, ok := catalog.Families.Members[key]; ok {
|
||||
record.DefinitionSources = append([]string(nil), catalog.Families.Families[member.Family].Sources...)
|
||||
record.FamilyKey = member.Family
|
||||
record.CharacterID = member.CharacterID
|
||||
record.FamilySources = append([]string(nil), cfg.familyCatalog.Families[member.Family].Sources...)
|
||||
record.FamilySources = append([]string(nil), catalog.Families.Families[member.Family].Sources...)
|
||||
record.PartySource = strings.Join(partySources(member.CharacterID), ",")
|
||||
} else {
|
||||
record.DefinitionSources = declarationDefinitionSourcesWithIndex(cfg, configkit.Keys("scriptorium", "artifacts", key), pathsByID)
|
||||
@@ -63,7 +67,7 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
record.Dependencies = nonEmptySortedStrings(record.Dependencies)
|
||||
records = append(records, record)
|
||||
}
|
||||
return records, nil
|
||||
return records
|
||||
}
|
||||
|
||||
// partyCharacterSourceLookup owns a single inspection's detached native evidence.
|
||||
|
||||
@@ -14,16 +14,13 @@ type artifactDependencyOrigin struct {
|
||||
family string
|
||||
}
|
||||
|
||||
func finalizeArtifactDependencies(cfg *PipelineConfig) {
|
||||
if cfg == nil || cfg.Scriptorium == nil {
|
||||
return
|
||||
}
|
||||
for artifactName, artifact := range cfg.Scriptorium.Artifacts {
|
||||
func resolveArtifactDependencies(artifacts map[string]ScriptoriumArtifactConfig, families ArtifactFamilyCatalog) {
|
||||
for artifactName, artifact := range artifacts {
|
||||
priorOrigins := artifact.dependencyOrigins
|
||||
origins := make(map[string][]artifactDependencyOrigin)
|
||||
dependencies := make(map[string]struct{})
|
||||
family := ""
|
||||
if member, ok := cfg.familyCatalog.Members[artifactName]; ok {
|
||||
if member, ok := families.Members[artifactName]; ok {
|
||||
family = member.Family
|
||||
}
|
||||
|
||||
@@ -65,7 +62,7 @@ func finalizeArtifactDependencies(cfg *PipelineConfig) {
|
||||
|
||||
artifact.DependsOn = sortedDependencyKeys(dependencies)
|
||||
artifact.dependencyOrigins = origins
|
||||
cfg.Scriptorium.Artifacts[artifactName] = artifact
|
||||
artifacts[artifactName] = artifact
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFinalizeArtifactDependenciesUnionsNormalizesAndIsIdempotent(t *testing.T) {
|
||||
func TestArtifactDependencyResolutionUnionsNormalizesAndIsIdempotent(t *testing.T) {
|
||||
cfg := dependencyTestPipeline([]string{" beta ", "alpha", "beta"})
|
||||
artifact := cfg.Scriptorium.Artifacts["result"]
|
||||
artifact.Inputs["gamma"] = ScriptoriumInputConfig{Source: "narratio.artifact.gamma"}
|
||||
@@ -14,7 +14,7 @@ func TestFinalizeArtifactDependenciesUnionsNormalizesAndIsIdempotent(t *testing.
|
||||
cfg.Scriptorium.Artifacts["result"] = artifact
|
||||
cfg.Scriptorium.Artifacts["gamma"] = ScriptoriumArtifactConfig{}
|
||||
|
||||
finalizeArtifactDependencies(cfg)
|
||||
resolveArtifactDependencies(cfg.Scriptorium.Artifacts, ArtifactFamilyCatalog{})
|
||||
want := []string{"alpha", "beta", "gamma"}
|
||||
got := cfg.Scriptorium.Artifacts["result"]
|
||||
if !reflect.DeepEqual(got.DependsOn, want) {
|
||||
@@ -25,7 +25,7 @@ func TestFinalizeArtifactDependenciesUnionsNormalizesAndIsIdempotent(t *testing.
|
||||
}
|
||||
|
||||
firstOrigins := cloneDependencyOrigins(got.dependencyOrigins)
|
||||
finalizeArtifactDependencies(cfg)
|
||||
resolveArtifactDependencies(cfg.Scriptorium.Artifacts, ArtifactFamilyCatalog{})
|
||||
got = cfg.Scriptorium.Artifacts["result"]
|
||||
if !reflect.DeepEqual(got.DependsOn, want) {
|
||||
t.Fatalf("dependencies after second finalization = %#v, want %#v", got.DependsOn, want)
|
||||
@@ -66,7 +66,7 @@ func TestInferredArtifactDependencyDiagnosticsPointToInputs(t *testing.T) {
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
cfg := &PipelineConfig{Scriptorium: &ScriptoriumConfig{Artifacts: test.artifacts}}
|
||||
finalizeArtifactDependencies(cfg)
|
||||
resolveArtifactDependencies(cfg.Scriptorium.Artifacts, ArtifactFamilyCatalog{})
|
||||
err := ValidateScriptoriumArtifactDependencies(cfg.Scriptorium.Artifacts)
|
||||
if err == nil {
|
||||
t.Fatal("expected dependency validation error")
|
||||
@@ -84,7 +84,7 @@ func TestExplicitAndInferredDependencyGraphsHaveEqualDigests(t *testing.T) {
|
||||
explicit := dependencyTestPipeline([]string{"alpha"})
|
||||
inferred := dependencyTestPipeline(nil)
|
||||
for _, cfg := range []*PipelineConfig{explicit, inferred} {
|
||||
finalizeArtifactDependencies(cfg)
|
||||
resolveArtifactDependencies(cfg.Scriptorium.Artifacts, ArtifactFamilyCatalog{})
|
||||
cfg.resolution = &pipelineResolutionMetadata{}
|
||||
if err := recomputePipelineEffectiveDigest(cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -22,46 +22,41 @@ var memberVariableSelectors = map[string]func(PartyCharacter) string{
|
||||
"character.alias_summary": func(character PartyCharacter) string { return character.AliasSummary() },
|
||||
}
|
||||
|
||||
func retainArtifactFamilyDeclarations(cfg *PipelineConfig) {
|
||||
if cfg == nil || cfg.Scriptorium == nil || cfg.resolution == nil {
|
||||
return
|
||||
// DeriveArtifactCatalog interprets the completed pipeline and selected roster
|
||||
// without changing either native configuration result.
|
||||
func DeriveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) (*ArtifactCatalog, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("pipeline config is required")
|
||||
}
|
||||
cfg.resolution.artifactFamilies = cloneArtifactFamilyDefinitions(cfg.Scriptorium.ArtifactFamilies)
|
||||
}
|
||||
|
||||
func expandPipelineArtifactFamilies(cfg *PipelineConfig, party ResolvedParty) error {
|
||||
if cfg == nil || cfg.Scriptorium == nil || cfg.resolution == nil || cfg.resolution.artifactFamiliesExpanded {
|
||||
return nil
|
||||
result := &ArtifactCatalog{Artifacts: map[string]ScriptoriumArtifactConfig{}}
|
||||
if cfg.Scriptorium == nil {
|
||||
return finishArtifactCatalog(cfg, result, party)
|
||||
}
|
||||
families := cfg.resolution.artifactFamilies
|
||||
if len(families) == 0 {
|
||||
families = cloneArtifactFamilyDefinitions(cfg.Scriptorium.ArtifactFamilies)
|
||||
families := cfg.Scriptorium.ArtifactFamilies
|
||||
if len(families) > 0 && party.Canonical == nil {
|
||||
return nil, fmt.Errorf("pipeline.scriptorium.artifact_families requires a canonical party")
|
||||
}
|
||||
if len(families) == 0 {
|
||||
return nil
|
||||
}
|
||||
if party.Canonical == nil {
|
||||
return fmt.Errorf("pipeline.scriptorium.artifact_families requires a canonical campaign party")
|
||||
}
|
||||
|
||||
expanded := cloneArtifactDefinitions(cfg.Scriptorium.Artifacts)
|
||||
if err := rejectConcreteMemberArtifactSources(expanded); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
familyKeys := sortedFamilyKeys(families)
|
||||
for _, familyKey := range familyKeys {
|
||||
if !artifactpolicy.IsConfiguredKey(familyKey) {
|
||||
return fmt.Errorf("pipeline.scriptorium.artifact_families keys must match ^[a-z][a-z0-9_]*$")
|
||||
return nil, fmt.Errorf("pipeline.scriptorium.artifact_families keys must match ^[a-z][a-z0-9_]*$")
|
||||
}
|
||||
if _, exists := expanded[familyKey]; exists {
|
||||
return fmt.Errorf("pipeline.scriptorium.artifact_families.%s collides with configured artifact key %q", familyKey, familyKey)
|
||||
return nil, fmt.Errorf("pipeline.scriptorium.artifact_families.%s collides with configured artifact key %q", familyKey, familyKey)
|
||||
}
|
||||
}
|
||||
if err := validateFamilyMemberDependencies(families, familyKeys); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
characters := append([]PartyCharacter(nil), party.Canonical.Characters...)
|
||||
characters := []PartyCharacter(nil)
|
||||
if party.Canonical != nil {
|
||||
characters = append(characters, party.Canonical.Characters...)
|
||||
}
|
||||
sort.Slice(characters, func(left, right int) bool { return characters[left].ID < characters[right].ID })
|
||||
catalog := ArtifactFamilyCatalog{Families: make(map[string]ArtifactFamilyOrigin, len(familyKeys)), Members: map[string]ArtifactFamilyMemberOrigin{}}
|
||||
outputOwners := make(map[string]string, len(expanded))
|
||||
@@ -74,10 +69,10 @@ func expandPipelineArtifactFamilies(cfg *PipelineConfig, party ResolvedParty) er
|
||||
family := families[familyKey]
|
||||
prefix := "pipeline.scriptorium.artifact_families." + familyKey
|
||||
if strings.TrimSpace(family.ForEach) != partyCharactersFamilySource {
|
||||
return fmt.Errorf("%s.for_each must be %q", prefix, partyCharactersFamilySource)
|
||||
return nil, fmt.Errorf("%s.for_each must be %q", prefix, partyCharactersFamilySource)
|
||||
}
|
||||
if err := validateFamilyOutputPattern(prefix+".output_path_pattern", family.OutputPathPattern); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
familyOrigin := ArtifactFamilyOrigin{
|
||||
Members: make([]string, 0, len(characters)),
|
||||
@@ -88,26 +83,26 @@ func expandPipelineArtifactFamilies(cfg *PipelineConfig, party ResolvedParty) er
|
||||
for _, character := range characters {
|
||||
key := familyKey + "_" + character.ID
|
||||
if !artifactpolicy.IsConfiguredKey(key) {
|
||||
return fmt.Errorf("%s generates invalid artifact key %q", prefix, key)
|
||||
return nil, fmt.Errorf("%s generates invalid artifact key %q", prefix, key)
|
||||
}
|
||||
if _, exists := expanded[key]; exists {
|
||||
return fmt.Errorf("%s generates artifact key %q that collides with another artifact", prefix, key)
|
||||
return nil, fmt.Errorf("%s generates artifact key %q that collides with another artifact", prefix, key)
|
||||
}
|
||||
outputPath := strings.ReplaceAll(family.OutputPathPattern, characterIDToken, character.ID)
|
||||
if prior, exists := outputOwners[outputPath]; exists {
|
||||
return fmt.Errorf("%s.output_path_pattern generates output path %q already used by artifact %q", prefix, outputPath, prior)
|
||||
return nil, fmt.Errorf("%s.output_path_pattern generates output path %q already used by artifact %q", prefix, outputPath, prior)
|
||||
}
|
||||
vars, err := resolveFamilyVars(prefix, family, character)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
dependencies, err := expandedFamilyDependencies(prefix, family, character.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
inputs, err := expandFamilyInputs(prefix, family, character.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
expanded[key] = ScriptoriumArtifactConfig{
|
||||
Enabled: family.Enabled, DependsOn: dependencies, RenderDebug: family.RenderDebug,
|
||||
@@ -120,52 +115,43 @@ func expandPipelineArtifactFamilies(cfg *PipelineConfig, party ResolvedParty) er
|
||||
}
|
||||
catalog.Families[familyKey] = familyOrigin
|
||||
}
|
||||
cfg.Scriptorium.Artifacts = expanded
|
||||
if err := expandFamilyPublishRules(cfg, catalog); err != nil {
|
||||
return err
|
||||
}
|
||||
applyMissingPublishDestinations(cfg.Publish, cfg.Scriptorium, cfg.Notarius)
|
||||
cfg.Scriptorium.ArtifactFamilies = nil
|
||||
cfg.familyCatalog = catalog
|
||||
cfg.resolution.artifactFamiliesExpanded = true
|
||||
finalizeArtifactDependencies(cfg)
|
||||
for key, member := range cfg.familyCatalog.Members {
|
||||
member.Dependencies = append([]string(nil), cfg.Scriptorium.Artifacts[key].DependsOn...)
|
||||
cfg.familyCatalog.Members[key] = member
|
||||
}
|
||||
if err := rejectConcreteMemberArtifactSources(expanded); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateScriptorium(cfg.Scriptorium, cfg.Notarius); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validatePublish(cfg.Publish, cfg.Scriptorium, cfg.Notarius); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := recomputePipelineEffectiveDigest(cfg); err != nil {
|
||||
return fmt.Errorf("refresh expanded pipeline digest: %w", err)
|
||||
}
|
||||
return nil
|
||||
result.Artifacts = expanded
|
||||
result.Families = catalog
|
||||
return finishArtifactCatalog(cfg, result, party)
|
||||
}
|
||||
|
||||
func expandFamilyPublishRules(cfg *PipelineConfig, catalog ArtifactFamilyCatalog) error {
|
||||
if cfg == nil || cfg.Scriptorium == nil {
|
||||
return nil
|
||||
func finishArtifactCatalog(cfg *PipelineConfig, catalog *ArtifactCatalog, party ResolvedParty) (*ArtifactCatalog, error) {
|
||||
resolveArtifactDependencies(catalog.Artifacts, catalog.Families)
|
||||
for key, member := range catalog.Families.Members {
|
||||
member.Dependencies = append([]string(nil), catalog.Artifacts[key].DependsOn...)
|
||||
catalog.Families.Members[key] = member
|
||||
}
|
||||
if err := validateConcreteArtifacts(catalog.Artifacts, cfg.Notarius); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := deriveFamilyPublishRules(cfg, catalog); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
catalog.Records = concreteArtifactRecords(cfg, catalog, party)
|
||||
return catalog, nil
|
||||
}
|
||||
|
||||
func deriveFamilyPublishRules(cfg *PipelineConfig, catalog *ArtifactCatalog) error {
|
||||
if cfg.Publish == nil {
|
||||
for familyKey, family := range catalog.Families {
|
||||
for familyKey, family := range catalog.Families.Families {
|
||||
if family.Publish != nil && family.Publish.Enabled {
|
||||
return fmt.Errorf("pipeline.scriptorium.artifact_families.%s.publish requires pipeline.publish", familyKey)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
catalog.PublishOutputs = append([]PublishOutputRule(nil), cfg.Publish.Outputs...)
|
||||
generated := make([]PublishOutputRule, 0)
|
||||
explicitSources := make(map[string]struct{}, len(cfg.Publish.Outputs))
|
||||
for _, rule := range cfg.Publish.Outputs {
|
||||
explicitSources[strings.TrimSpace(rule.Source)] = struct{}{}
|
||||
}
|
||||
for familyKey, family := range catalog.Families {
|
||||
for familyKey, family := range catalog.Families.Families {
|
||||
if family.Publish == nil || !family.Publish.Enabled {
|
||||
continue
|
||||
}
|
||||
@@ -179,8 +165,8 @@ func expandFamilyPublishRules(cfg *PipelineConfig, catalog ArtifactFamilyCatalog
|
||||
if _, conflict := explicitSources[artifactpolicy.ConfiguredSourceID(key)]; conflict {
|
||||
return fmt.Errorf("pipeline.scriptorium.artifact_families.%s.publish conflicts with explicit publish source %q", familyKey, artifactpolicy.ConfiguredSourceID(key))
|
||||
}
|
||||
origin := catalog.Members[key]
|
||||
dest := cfg.Scriptorium.Artifacts[key].OutputPath
|
||||
origin := catalog.Families.Members[key]
|
||||
dest := catalog.Artifacts[key].OutputPath
|
||||
if pattern != "" {
|
||||
dest = strings.ReplaceAll(pattern, characterIDToken, origin.CharacterID)
|
||||
}
|
||||
@@ -188,17 +174,27 @@ func expandFamilyPublishRules(cfg *PipelineConfig, catalog ArtifactFamilyCatalog
|
||||
generated = append(generated, PublishOutputRule{Source: artifactpolicy.ConfiguredSourceID(key), Dest: dest, Required: &required})
|
||||
}
|
||||
}
|
||||
if len(generated) == 0 {
|
||||
return nil
|
||||
}
|
||||
cfg.Publish.Outputs = append(cfg.Publish.Outputs, generated...)
|
||||
sort.Slice(cfg.Publish.Outputs, func(i, j int) bool {
|
||||
if cfg.Publish.Outputs[i].Dest == cfg.Publish.Outputs[j].Dest {
|
||||
return cfg.Publish.Outputs[i].Source < cfg.Publish.Outputs[j].Source
|
||||
catalog.PublishOutputs = append(catalog.PublishOutputs, generated...)
|
||||
outputPaths := artifactOutputPathMap(catalog.Artifacts)
|
||||
extractions := notariusOutputKeySet(cfg.Notarius)
|
||||
for index, rule := range catalog.PublishOutputs {
|
||||
if strings.TrimSpace(rule.Dest) != "" {
|
||||
continue
|
||||
}
|
||||
return cfg.Publish.Outputs[i].Dest < cfg.Publish.Outputs[j].Dest
|
||||
})
|
||||
return nil
|
||||
dest, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(strings.TrimSpace(rule.Source), "", outputPaths, extractions)
|
||||
if err == nil {
|
||||
catalog.PublishOutputs[index].Dest = dest
|
||||
}
|
||||
}
|
||||
if len(generated) > 0 {
|
||||
sort.Slice(catalog.PublishOutputs, func(i, j int) bool {
|
||||
if catalog.PublishOutputs[i].Dest == catalog.PublishOutputs[j].Dest {
|
||||
return catalog.PublishOutputs[i].Source < catalog.PublishOutputs[j].Source
|
||||
}
|
||||
return catalog.PublishOutputs[i].Dest < catalog.PublishOutputs[j].Dest
|
||||
})
|
||||
}
|
||||
return validatePublishedOutputs(catalog.PublishOutputs, outputPaths, extractions)
|
||||
}
|
||||
|
||||
func validateFamilyMemberDependencies(families map[string]ScriptoriumArtifactFamilyConfig, familyKeys []string) error {
|
||||
@@ -388,29 +384,6 @@ func cloneArtifactVars(in map[string]any) map[string]any {
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneArtifactFamilyDefinitions(in map[string]ScriptoriumArtifactFamilyConfig) map[string]ScriptoriumArtifactFamilyConfig {
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make(map[string]ScriptoriumArtifactFamilyConfig, len(in))
|
||||
for key, family := range in {
|
||||
family.DependsOn = append([]string(nil), family.DependsOn...)
|
||||
family.MemberDependencies = append([]string(nil), family.MemberDependencies...)
|
||||
family.Inputs = cloneArtifactInputs(family.Inputs)
|
||||
family.Vars = cloneArtifactVars(family.Vars)
|
||||
if len(family.MemberVars) > 0 {
|
||||
memberVars := make(map[string]string, len(family.MemberVars))
|
||||
for name, selector := range family.MemberVars {
|
||||
memberVars[name] = selector
|
||||
}
|
||||
family.MemberVars = memberVars
|
||||
}
|
||||
family.Publish = cloneArtifactFamilyPublish(family.Publish)
|
||||
out[key] = family
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneArtifactFamilyPublish(in *ScriptoriumArtifactFamilyPublishConfig) *ScriptoriumArtifactFamilyPublishConfig {
|
||||
if in == nil {
|
||||
return nil
|
||||
|
||||
@@ -68,15 +68,15 @@ characters:
|
||||
if err := Validate(cfg); err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
}
|
||||
if len(cfg.Pipeline.Scriptorium.ArtifactFamilies) != 0 {
|
||||
t.Fatalf("adapter-facing artifact families = %#v, want none", cfg.Pipeline.Scriptorium.ArtifactFamilies)
|
||||
if len(cfg.Pipeline.Scriptorium.ArtifactFamilies) != 2 {
|
||||
t.Fatalf("authored artifact families = %#v, want both declarations", cfg.Pipeline.Scriptorium.ArtifactFamilies)
|
||||
}
|
||||
keys := sortedArtifactKeys(cfg.Pipeline.Scriptorium.Artifacts)
|
||||
keys := sortedArtifactKeys(cfg.ArtifactCatalog.Artifacts)
|
||||
wantKeys := []string{"character_items_alpha", "character_items_zeta", "character_meta_alpha", "character_meta_zeta"}
|
||||
if !reflect.DeepEqual(keys, wantKeys) {
|
||||
t.Fatalf("artifact keys = %#v, want %#v", keys, wantKeys)
|
||||
}
|
||||
alpha := cfg.Pipeline.Scriptorium.Artifacts["character_items_alpha"]
|
||||
alpha := cfg.ArtifactCatalog.Artifacts["character_items_alpha"]
|
||||
if alpha.Enabled || alpha.OutputPath != "artifacts/characters/alpha/items.md" {
|
||||
t.Fatalf("alpha artifact = %#v", alpha)
|
||||
}
|
||||
@@ -85,11 +85,11 @@ characters:
|
||||
}) {
|
||||
t.Fatalf("alpha vars = %#v", alpha.Vars)
|
||||
}
|
||||
zeta := cfg.Pipeline.Scriptorium.Artifacts["character_items_zeta"]
|
||||
zeta := cfg.ArtifactCatalog.Artifacts["character_items_zeta"]
|
||||
if got := zeta.Vars["classes"]; got != "wizard 8 / fighter" {
|
||||
t.Fatalf("zeta class summary = %#v", got)
|
||||
}
|
||||
catalog := ArtifactFamilies(cfg.Pipeline)
|
||||
catalog := ArtifactFamilies(cfg.ArtifactCatalog)
|
||||
if got, want := catalog.Families["character_meta"].Sources, []string{absolutePath(t, pipelinePath)}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("family sources = %#v, want %#v", got, want)
|
||||
}
|
||||
@@ -120,7 +120,7 @@ characters:
|
||||
if err != nil {
|
||||
t.Fatalf("reordered LoadWithSessionOptions() error = %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(cfg.Pipeline.Scriptorium.Artifacts, again.Pipeline.Scriptorium.Artifacts) || !reflect.DeepEqual(ArtifactFamilies(cfg.Pipeline), ArtifactFamilies(again.Pipeline)) || firstDigest != EffectivePipelineDigest(again.Pipeline) {
|
||||
if !reflect.DeepEqual(cfg.ArtifactCatalog.Artifacts, again.ArtifactCatalog.Artifacts) || !reflect.DeepEqual(ArtifactFamilies(cfg.ArtifactCatalog), ArtifactFamilies(again.ArtifactCatalog)) || firstDigest != EffectivePipelineDigest(again.Pipeline) {
|
||||
t.Fatalf("reordered source maps changed expansion")
|
||||
}
|
||||
}
|
||||
@@ -189,12 +189,11 @@ func TestArtifactFamiliesRejectGeneratedKeyAndOutputCollisions(t *testing.T) {
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
pipeline := &PipelineConfig{
|
||||
Scriptorium: &ScriptoriumConfig{Artifacts: test.artifacts},
|
||||
resolution: &pipelineResolutionMetadata{artifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{"character_meta": base}},
|
||||
Scriptorium: &ScriptoriumConfig{Artifacts: test.artifacts, ArtifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{"character_meta": base}},
|
||||
}
|
||||
err := expandPipelineArtifactFamilies(pipeline, ResolvedParty{Canonical: document})
|
||||
_, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document})
|
||||
if err == nil || !strings.Contains(err.Error(), test.wantError) {
|
||||
t.Fatalf("expandPipelineArtifactFamilies() error = %v, want %q", err, test.wantError)
|
||||
t.Fatalf("DeriveArtifactCatalog() error = %v, want %q", err, test.wantError)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -232,18 +231,18 @@ characters:
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items := cfg.Pipeline.Scriptorium.Artifacts["character_items_arannis"]
|
||||
items := cfg.ArtifactCatalog.Artifacts["character_items_arannis"]
|
||||
if !reflect.DeepEqual(items.DependsOn, []string{"character_meta_arannis", "session_recap"}) {
|
||||
t.Fatalf("member dependencies = %#v", items.DependsOn)
|
||||
}
|
||||
if got := items.Inputs["prior_meta"].Source; got != "narratio.artifact.character_meta_arannis" {
|
||||
t.Fatalf("rewritten member source = %q", got)
|
||||
}
|
||||
catalog := ArtifactFamilies(cfg.Pipeline)
|
||||
catalog := ArtifactFamilies(cfg.ArtifactCatalog)
|
||||
if got := catalog.Members["character_items_arannis"]; !reflect.DeepEqual(got.Dependencies, items.DependsOn) || got.Inputs["prior_meta"] != "narratio.artifact.character_meta_arannis" {
|
||||
t.Fatalf("member provenance = %#v", got)
|
||||
}
|
||||
for key, artifact := range cfg.Pipeline.Scriptorium.Artifacts {
|
||||
for key, artifact := range cfg.ArtifactCatalog.Artifacts {
|
||||
for name, input := range artifact.Inputs {
|
||||
if strings.Contains(input.Source, "narratio.member_artifact.") {
|
||||
t.Fatalf("unresolved source at %s.%s = %q", key, name, input.Source)
|
||||
@@ -286,8 +285,7 @@ func TestArtifactFamiliesRejectInvalidMemberDependenciesAndSources(t *testing.T)
|
||||
"explicit": {Inputs: map[string]ScriptoriumInputConfig{
|
||||
"bad": {Source: "narratio.member_artifact.character_meta"},
|
||||
}},
|
||||
}},
|
||||
resolution: &pipelineResolutionMetadata{artifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{
|
||||
}, ArtifactFamilies: map[string]ScriptoriumArtifactFamilyConfig{
|
||||
"character_meta": {ForEach: partyCharactersFamilySource, OutputPathPattern: "artifacts/{character_id}.md"},
|
||||
}},
|
||||
}
|
||||
@@ -295,12 +293,11 @@ func TestArtifactFamiliesRejectInvalidMemberDependenciesAndSources(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := expandPipelineArtifactFamilies(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(err.Error(), "outside an artifact family") {
|
||||
if _, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(err.Error(), "outside an artifact family") {
|
||||
t.Fatalf("concrete member source error = %v", err)
|
||||
}
|
||||
pipeline.Scriptorium.Artifacts["explicit"] = ScriptoriumArtifactConfig{Inputs: map[string]ScriptoriumInputConfig{"bad": {Source: "narratio.member_artifact."}}}
|
||||
pipeline.resolution.artifactFamiliesExpanded = false
|
||||
if err := expandPipelineArtifactFamilies(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(err.Error(), "malformed member artifact source") {
|
||||
if _, err := DeriveArtifactCatalog(pipeline, ResolvedParty{Canonical: document}); err == nil || !strings.Contains(err.Error(), "malformed member artifact source") {
|
||||
t.Fatalf("malformed concrete member source error = %v", err)
|
||||
}
|
||||
}
|
||||
@@ -319,16 +316,17 @@ func TestFamilyPublishRulesExpandToConcreteArtifacts(t *testing.T) {
|
||||
}, Members: map[string]ArtifactFamilyMemberOrigin{
|
||||
"character_meta_alpha": {CharacterID: "alpha"}, "character_meta_zeta": {CharacterID: "zeta"},
|
||||
}}
|
||||
if err := expandFamilyPublishRules(cfg, catalog); err != nil {
|
||||
derived := &ArtifactCatalog{Artifacts: cfg.Scriptorium.Artifacts, Families: catalog}
|
||||
if err := deriveFamilyPublishRules(cfg, derived); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := cfg.Publish.Outputs; len(got) != 2 || got[0].Source != "narratio.artifact.character_meta_alpha" || got[0].Dest != "published/alpha.md" || got[0].Required == nil || !*got[0].Required {
|
||||
if got := derived.PublishOutputs; len(got) != 2 || got[0].Source != "narratio.artifact.character_meta_alpha" || got[0].Dest != "published/alpha.md" || got[0].Required == nil || !*got[0].Required {
|
||||
t.Fatalf("generated publish rules = %#v", got)
|
||||
}
|
||||
cfg.Publish.Outputs = nil
|
||||
catalog.Families["character_meta"] = ArtifactFamilyOrigin{Members: []string{"character_meta_alpha"}, Publish: &ScriptoriumArtifactFamilyPublishConfig{Enabled: true}}
|
||||
cfg.Publish = nil
|
||||
if err := expandFamilyPublishRules(cfg, catalog); err == nil || !strings.Contains(err.Error(), "requires pipeline.publish") {
|
||||
if err := deriveFamilyPublishRules(cfg, derived); err == nil || !strings.Contains(err.Error(), "requires pipeline.publish") {
|
||||
t.Fatalf("missing publish error = %v", err)
|
||||
}
|
||||
}
|
||||
@@ -381,7 +379,7 @@ whisperx:
|
||||
"character_summary_alice": "artifacts/characters/alice/summary.md",
|
||||
"character_notes_alice": "artifacts/characters/alice/notes.md",
|
||||
} {
|
||||
artifact, ok := cfg.Pipeline.Scriptorium.Artifacts[key]
|
||||
artifact, ok := cfg.ArtifactCatalog.Artifacts[key]
|
||||
if !ok {
|
||||
t.Fatalf("inherited family member %q is missing", key)
|
||||
}
|
||||
@@ -394,7 +392,7 @@ whisperx:
|
||||
"narratio.artifact.character_summary_alice": "published/characters/alice/summary.md",
|
||||
"narratio.artifact.character_notes_alice": "published/characters/alice/notes.md",
|
||||
}
|
||||
for _, rule := range cfg.Pipeline.Publish.Outputs {
|
||||
for _, rule := range cfg.ArtifactCatalog.PublishOutputs {
|
||||
if want, ok := wantPublish[rule.Source]; ok {
|
||||
if rule.Dest != want {
|
||||
t.Errorf("family publish destination for %q = %q, want %q", rule.Source, rule.Dest, want)
|
||||
@@ -575,15 +573,11 @@ publish:
|
||||
if err != nil {
|
||||
t.Fatalf("LoadWithSessionOptions() error = %v", err)
|
||||
}
|
||||
if got := cfg.Pipeline.Publish.Outputs[0].Dest; got != test.wantDest {
|
||||
if got := cfg.ArtifactCatalog.PublishOutputs[0].Dest; got != test.wantDest {
|
||||
t.Fatalf("resolved runtime destination = %q, want %q", got, test.wantDest)
|
||||
}
|
||||
effective, err := MarshalEffectivePipeline(cfg.Pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(effective), "dest: "+test.wantDest+"\n") {
|
||||
t.Fatalf("effective pipeline omitted resolved destination:\n%s", effective)
|
||||
if got := cfg.Pipeline.Publish.Outputs[0].Dest; got != test.dest {
|
||||
t.Fatalf("catalog derivation changed authored destination: %q, want %q", got, test.dest)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
125
internal/config/catalog_derivation_test.go
Normal file
125
internal/config/catalog_derivation_test.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCatalogDerivationKeepsNativeInputsAndRostersIndependent(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Chdir(dir)
|
||||
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, artifactFamilyPipelineYAML(`
|
||||
character_notes:
|
||||
enabled: true
|
||||
for_each: party.characters
|
||||
prompt_id: notes
|
||||
output_path_pattern: artifacts/{character_id}.md
|
||||
member_vars:
|
||||
player: player.name
|
||||
publish:
|
||||
enabled: true
|
||||
required: true
|
||||
`))
|
||||
writePipelineFixture(t, dir, "party.yml", canonicalPartyFixture)
|
||||
explicit := "selected.yml"
|
||||
writePipelineFixture(t, dir, explicit, `schema_version: narratio.party.v1
|
||||
characters:
|
||||
other:
|
||||
player: {name: Selected Player}
|
||||
character: {name: Other, classes: [{name: ranger}]}
|
||||
`)
|
||||
pipeline, err := LoadPipeline(pipelinePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
campaign, err := LoadCampaign(campaignPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beforePipeline, err := json.Marshal(pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beforeCampaign, err := json.Marshal(campaign)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var beforeShow bytes.Buffer
|
||||
if err := pipeline.ConfigKitResult().WriteEffective(&beforeShow); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defaultContext, err := LoadPipelineCampaign(pipelinePath, pipeline, campaignPath, campaign)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
selectedContext, err := LoadPipelineCampaignWithPartyFile(pipelinePath, pipeline, campaignPath, campaign, &explicit)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
selected := selectedContext.ArtifactCatalog
|
||||
if len(selected.Artifacts) != 1 || selected.Artifacts["character_notes_other"].Vars["player"] != "Selected Player" {
|
||||
t.Fatalf("selected catalog = %+v", selected)
|
||||
}
|
||||
if _, found := defaultContext.ArtifactCatalog.Artifacts["character_notes_other"]; found {
|
||||
t.Fatal("second roster changed the first catalog")
|
||||
}
|
||||
if !strings.Contains(string(selectedContext.Party.Players), "Selected Player") || strings.Contains(string(defaultContext.Party.Players), "Selected Player") {
|
||||
t.Fatal("players did not follow the independently selected roster")
|
||||
}
|
||||
if result := selectedContext.Party.Canonical.ConfigKitResult(); result == nil || result.Config.Characters["other"].Player.Name != "Selected Player" || result.Sources()[0].Path != filepath.Join(dir, explicit) {
|
||||
t.Fatalf("party lost its actual selected native result: %+v", result)
|
||||
}
|
||||
afterPipeline, _ := json.Marshal(pipeline)
|
||||
afterCampaign, _ := json.Marshal(campaign)
|
||||
var afterShow bytes.Buffer
|
||||
if err := pipeline.ConfigKitResult().WriteEffective(&afterShow); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(beforePipeline, afterPipeline) || !bytes.Equal(beforeCampaign, afterCampaign) || beforeShow.String() != afterShow.String() {
|
||||
t.Fatal("catalog derivation changed completed native configuration")
|
||||
}
|
||||
if len(pipeline.Scriptorium.ArtifactFamilies) != 1 || len(pipeline.Scriptorium.Artifacts) != 0 {
|
||||
t.Fatal("domain definitions leaked into pipeline configuration")
|
||||
}
|
||||
if len(selected.PublishOutputs) != len(pipeline.Publish.Outputs)+1 {
|
||||
t.Fatal("family publication actions were not derived separately")
|
||||
}
|
||||
cfg, err := LoadSessionWithPipelineCampaignOptions(selectedContext, sessionPath, SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Validate(cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.StableInputs.PartyFile.Path != filepath.Join(dir, explicit) || cfg.StableInputs.PartyFile.Source != "party_file" || cfg.Campaign.Inputs.PartyFile != filepath.Join(dir, "party.yml") {
|
||||
t.Fatalf("explicit party source or unchanged campaign default: %+v", cfg.StableInputs.PartyFile)
|
||||
}
|
||||
repeated, err := DeriveArtifactCatalog(pipeline, selectedContext.Party)
|
||||
if err != nil || !reflect.DeepEqual(selected, repeated) {
|
||||
t.Fatalf("repeated derivation changed catalog: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplicitPartySelectionNeverFallsBack(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}\n")
|
||||
writePipelineFixture(t, dir, "party.yml", canonicalPartyFixture)
|
||||
campaign, err := LoadCampaign(campaignPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
invalid := writePipelineFixture(t, dir, "invalid.yml", "schema_version: invalid\n")
|
||||
for _, path := range []string{"", filepath.Join(dir, "missing.yml"), invalid} {
|
||||
if _, err := ResolveParty(campaignPath, campaign, &path); err == nil {
|
||||
t.Fatalf("explicit party %q fell back", path)
|
||||
}
|
||||
}
|
||||
path := filepath.Join(dir, "party.yml")
|
||||
if party, err := ResolveParty("", nil, &path); err != nil || party.Canonical.ConfigKitResult() == nil {
|
||||
t.Fatalf("exact party selection acquired unrelated campaign context: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,10 @@ type Config struct {
|
||||
CampaignDocument *CampaignConfig
|
||||
SessionDocument *SessionConfig
|
||||
|
||||
StableInputs ResolvedStableInputs
|
||||
SessionSource SessionSource
|
||||
Party ResolvedParty
|
||||
StableInputs ResolvedStableInputs
|
||||
SessionSource SessionSource
|
||||
Party ResolvedParty
|
||||
ArtifactCatalog *ArtifactCatalog
|
||||
}
|
||||
|
||||
// PipelineConfig contains durable pipeline-level settings.
|
||||
@@ -37,16 +38,24 @@ type PipelineConfig struct {
|
||||
Notarius *NotariusConfig `yaml:"notarius" json:"notarius"`
|
||||
Notification NotificationConfig `yaml:"notification" json:"notification"`
|
||||
|
||||
resolution *pipelineResolutionMetadata `yaml:"-" json:"-"`
|
||||
familyCatalog ArtifactFamilyCatalog `yaml:"-" json:"-"`
|
||||
resolution *pipelineResolutionMetadata `yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
// ArtifactFamilies returns a copy of runtime-only expansion provenance.
|
||||
func ArtifactFamilies(cfg *PipelineConfig) ArtifactFamilyCatalog {
|
||||
if cfg == nil {
|
||||
// ArtifactCatalog contains domain products derived from completed pipeline
|
||||
// configuration and one selected canonical roster.
|
||||
type ArtifactCatalog struct {
|
||||
Artifacts map[string]ScriptoriumArtifactConfig
|
||||
Families ArtifactFamilyCatalog
|
||||
PublishOutputs []PublishOutputRule
|
||||
Records []EffectiveArtifactRecord
|
||||
}
|
||||
|
||||
// ArtifactFamilies returns a copy of the derived family/member provenance.
|
||||
func ArtifactFamilies(catalog *ArtifactCatalog) ArtifactFamilyCatalog {
|
||||
if catalog == nil {
|
||||
return ArtifactFamilyCatalog{}
|
||||
}
|
||||
return cloneArtifactFamilyCatalog(cfg.familyCatalog)
|
||||
return cloneArtifactFamilyCatalog(catalog.Families)
|
||||
}
|
||||
|
||||
// CampaignsConfig configures the local campaign registry.
|
||||
@@ -350,8 +359,7 @@ type SessionAudioS3Input struct {
|
||||
Prefix string `yaml:"prefix" json:"prefix"`
|
||||
}
|
||||
|
||||
// ResolvedStableInputs records where stable input file paths came from after
|
||||
// campaign/session merge.
|
||||
// ResolvedStableInputs records the origins of completed stable input paths.
|
||||
type ResolvedStableInputs struct {
|
||||
SpeakersFile ResolvedInputFile
|
||||
AutocorrectFile ResolvedInputFile
|
||||
@@ -360,19 +368,20 @@ type ResolvedStableInputs struct {
|
||||
SpellCatalogFile ResolvedInputFile
|
||||
}
|
||||
|
||||
// ResolvedInputFile records one merged config path and its source config file.
|
||||
// ResolvedInputFile records one effective input path and its declaring source.
|
||||
type ResolvedInputFile struct {
|
||||
Path string
|
||||
ConfigPath string
|
||||
Source string
|
||||
}
|
||||
|
||||
// ResolvedParty records the campaign-owned canonical party and its non-secret
|
||||
// ResolvedParty records the selected canonical party and its non-secret
|
||||
// source provenance. It is runtime-only and must never be copied into manifests
|
||||
// as raw party content.
|
||||
type ResolvedParty struct {
|
||||
Source PartySource
|
||||
Canonical *CanonicalParty
|
||||
Players []byte
|
||||
}
|
||||
|
||||
// PartySource identifies the selected party input without retaining its raw
|
||||
|
||||
@@ -36,9 +36,7 @@ func NormalizedConfigurationPath(path string) string {
|
||||
}
|
||||
|
||||
// EffectivePipelineSourceRecord identifies one effective logical field and a
|
||||
// safe source that contributed to it. Generated values intentionally have two
|
||||
// records: their family declaration and the canonical party that supplied the
|
||||
// member-specific value.
|
||||
// safe source that contributed to it.
|
||||
type EffectivePipelineSourceRecord struct {
|
||||
Path string
|
||||
Role string
|
||||
@@ -102,8 +100,8 @@ func EffectivePipelineValues(cfg *PipelineConfig) ([]EffectivePipelineValueRecor
|
||||
return projectionValueRecords(projectEffectivePipeline(cfg))
|
||||
}
|
||||
|
||||
// EffectivePipelineSources projects pipeline ownership after defaults and
|
||||
// optional family expansion. It never includes effective values or raw secret
|
||||
// EffectivePipelineSources projects pipeline ownership after resolution.
|
||||
// It never includes effective values or raw secret
|
||||
// material, only logical paths and source identifiers.
|
||||
func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]EffectivePipelineSourceRecord, error) {
|
||||
if cfg == nil {
|
||||
@@ -121,8 +119,6 @@ func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
families := ArtifactFamilies(cfg)
|
||||
partySources := partyCharacterSourceLookup(party)
|
||||
publishCount := 0
|
||||
if cfg.Publish != nil {
|
||||
publishCount = len(cfg.Publish.Outputs)
|
||||
@@ -132,13 +128,9 @@ func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
if path == "publish.outputs" {
|
||||
continue
|
||||
}
|
||||
if familyKey, ok := generatedArtifactFamilyForPath(path, families); ok {
|
||||
records = appendGeneratedArtifactSources(records, path, familyKey, families, owners, partySources)
|
||||
continue
|
||||
}
|
||||
records = appendPipelineOwners(records, path, owners[path], cfg)
|
||||
}
|
||||
records = appendPublishOutputSources(records, cfg, families, party, owners)
|
||||
records = appendPublishOutputSources(records, cfg, owners)
|
||||
sort.Slice(records, func(left, right int) bool {
|
||||
if records[left].Path != records[right].Path {
|
||||
return records[left].Path < records[right].Path
|
||||
@@ -404,25 +396,12 @@ func appendPipelineOwners(records []EffectivePipelineSourceRecord, path string,
|
||||
return records
|
||||
}
|
||||
|
||||
func appendPublishOutputSources(records []EffectivePipelineSourceRecord, cfg *PipelineConfig, families ArtifactFamilyCatalog, party ResolvedParty, owners map[string][]string) []EffectivePipelineSourceRecord {
|
||||
func appendPublishOutputSources(records []EffectivePipelineSourceRecord, cfg *PipelineConfig, owners map[string][]string) []EffectivePipelineSourceRecord {
|
||||
if cfg == nil || cfg.Publish == nil {
|
||||
return records
|
||||
}
|
||||
generated := make(map[string]string)
|
||||
for familyKey, family := range families.Families {
|
||||
if family.Publish == nil || !family.Publish.Enabled {
|
||||
continue
|
||||
}
|
||||
for _, key := range family.Members {
|
||||
generated["narratio.artifact."+key] = familyKey
|
||||
}
|
||||
}
|
||||
for index, output := range cfg.Publish.Outputs {
|
||||
for index := range cfg.Publish.Outputs {
|
||||
path := fmt.Sprintf("publish.outputs[%d]", index)
|
||||
if familyKey, ok := generated[strings.TrimSpace(output.Source)]; ok {
|
||||
records = appendGeneratedPublishSources(records, path, familyKey, families, owners, party)
|
||||
continue
|
||||
}
|
||||
records = appendPipelineOwners(records, path, owners["publish.outputs"], cfg)
|
||||
}
|
||||
return records
|
||||
|
||||
@@ -54,7 +54,6 @@ func finalizeLoadedPipeline(cfg *PipelineConfig) (*PipelineConfig, error) {
|
||||
if err := finalizePipelineResolution(cfg); err != nil {
|
||||
return nil, fmt.Errorf("load pipeline config: %w", err)
|
||||
}
|
||||
retainArtifactFamilyDeclarations(cfg)
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -156,24 +155,31 @@ func LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath string, sess
|
||||
// subsequent local or remote session resolution. It prevents a command from
|
||||
// reloading the root pipeline after campaign selection.
|
||||
type LoadedPipelineCampaign struct {
|
||||
PipelinePath string
|
||||
Pipeline *PipelineConfig
|
||||
CampaignPath string
|
||||
Campaign *CampaignConfig
|
||||
Party ResolvedParty
|
||||
PipelinePath string
|
||||
Pipeline *PipelineConfig
|
||||
CampaignPath string
|
||||
Campaign *CampaignConfig
|
||||
Party ResolvedParty
|
||||
ArtifactCatalog *ArtifactCatalog
|
||||
}
|
||||
|
||||
// LoadPipelineCampaign combines already loaded pipeline and campaign documents
|
||||
// with their campaign-owned party source. Callers that later resolve a session
|
||||
// retain this context rather than independently reimplementing party loading.
|
||||
func LoadPipelineCampaign(pipelinePath string, pipeline *PipelineConfig, campaignPath string, campaign *CampaignConfig) (LoadedPipelineCampaign, error) {
|
||||
return LoadPipelineCampaignWithPartyFile(pipelinePath, pipeline, campaignPath, campaign, nil)
|
||||
}
|
||||
|
||||
// LoadPipelineCampaignWithPartyFile derives domain context using an explicit
|
||||
// invocation-relative roster file or the campaign's default when omitted.
|
||||
func LoadPipelineCampaignWithPartyFile(pipelinePath string, pipeline *PipelineConfig, campaignPath string, campaign *CampaignConfig, partyFile *string) (LoadedPipelineCampaign, error) {
|
||||
if pipeline == nil {
|
||||
return LoadedPipelineCampaign{}, fmt.Errorf("pipeline config is required")
|
||||
}
|
||||
if campaign == nil {
|
||||
return LoadedPipelineCampaign{}, fmt.Errorf("campaign config is required")
|
||||
}
|
||||
party, err := resolveCampaignParty(campaignPath, campaign)
|
||||
party, err := ResolveParty(campaignPath, campaign, partyFile)
|
||||
if err != nil {
|
||||
return LoadedPipelineCampaign{}, err
|
||||
}
|
||||
@@ -181,9 +187,8 @@ func LoadPipelineCampaign(pipelinePath string, pipeline *PipelineConfig, campaig
|
||||
}
|
||||
|
||||
// LoadPipelineCampaignWithParty combines an already loaded pipeline and
|
||||
// campaign with one already resolved campaign-owned party. It is useful when
|
||||
// more than one independently resolved pipeline must be expanded against the
|
||||
// exact same party document.
|
||||
// campaign with one already resolved party. Independently loaded pipelines can
|
||||
// derive their catalogs against the same selected roster.
|
||||
func LoadPipelineCampaignWithParty(pipelinePath string, pipeline *PipelineConfig, campaignPath string, campaign *CampaignConfig, party ResolvedParty) (LoadedPipelineCampaign, error) {
|
||||
if pipeline == nil {
|
||||
return LoadedPipelineCampaign{}, fmt.Errorf("pipeline config is required")
|
||||
@@ -194,15 +199,24 @@ func LoadPipelineCampaignWithParty(pipelinePath string, pipeline *PipelineConfig
|
||||
if party.Canonical == nil {
|
||||
return LoadedPipelineCampaign{}, fmt.Errorf("resolved campaign party is required")
|
||||
}
|
||||
if err := expandPipelineArtifactFamilies(pipeline, party); err != nil {
|
||||
if party.Players == nil {
|
||||
players, err := party.Canonical.PlayersYAML()
|
||||
if err != nil {
|
||||
return LoadedPipelineCampaign{}, err
|
||||
}
|
||||
party.Players = players
|
||||
}
|
||||
catalog, err := DeriveArtifactCatalog(pipeline, party)
|
||||
if err != nil {
|
||||
return LoadedPipelineCampaign{}, err
|
||||
}
|
||||
return LoadedPipelineCampaign{
|
||||
PipelinePath: pipelinePath,
|
||||
Pipeline: pipeline,
|
||||
CampaignPath: campaignPath,
|
||||
Campaign: campaign,
|
||||
Party: party,
|
||||
PipelinePath: pipelinePath,
|
||||
Pipeline: pipeline,
|
||||
CampaignPath: campaignPath,
|
||||
Campaign: campaign,
|
||||
Party: party,
|
||||
ArtifactCatalog: catalog,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -240,14 +254,15 @@ func ResolveLoadedPipelineCampaign(loaded LoadedPipelineCampaign, sessionPath st
|
||||
loaded.Party = party
|
||||
}
|
||||
cfg := &Config{
|
||||
Pipeline: loaded.Pipeline,
|
||||
Campaign: loaded.Campaign,
|
||||
Session: sessionCfg,
|
||||
PipelinePath: loaded.PipelinePath,
|
||||
CampaignPath: loaded.CampaignPath,
|
||||
SessionPath: sessionPath,
|
||||
SessionSource: sessionSource,
|
||||
Party: loaded.Party,
|
||||
Pipeline: loaded.Pipeline,
|
||||
Campaign: loaded.Campaign,
|
||||
Session: sessionCfg,
|
||||
PipelinePath: loaded.PipelinePath,
|
||||
CampaignPath: loaded.CampaignPath,
|
||||
SessionPath: sessionPath,
|
||||
SessionSource: sessionSource,
|
||||
Party: loaded.Party,
|
||||
ArtifactCatalog: loaded.ArtifactCatalog,
|
||||
}
|
||||
cfg.CampaignDocument = loaded.Campaign
|
||||
cfg.SessionDocument = sessionCfg
|
||||
@@ -265,6 +280,7 @@ func ResolveLoadedPipelineCampaign(loaded LoadedPipelineCampaign, sessionPath st
|
||||
if strings.TrimSpace(cfg.SessionSource.LocalPath) == "" {
|
||||
cfg.SessionSource.LocalPath = sessionPath
|
||||
}
|
||||
stableInputs.PartyFile = ResolvedInputFile{Path: loaded.Party.Source.Path, ConfigPath: loaded.Party.Source.ConfigPath, Source: loaded.Party.Source.Source}
|
||||
cfg.StableInputs = stableInputs
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -406,17 +406,17 @@ func TestExamplesLoadAndValidate(t *testing.T) {
|
||||
"character_items_arannis",
|
||||
"character_items_brenna",
|
||||
} {
|
||||
if _, exists := cfg.Pipeline.Scriptorium.Artifacts[key]; !exists {
|
||||
if _, exists := cfg.ArtifactCatalog.Artifacts[key]; !exists {
|
||||
t.Fatalf("expanded artifact %q is absent", key)
|
||||
}
|
||||
}
|
||||
if got := cfg.Pipeline.Scriptorium.Artifacts["character_items_arannis"].Inputs["character_meta"].Source; got != "narratio.artifact.character_meta_arannis" {
|
||||
if got := cfg.ArtifactCatalog.Artifacts["character_items_arannis"].Inputs["character_meta"].Source; got != "narratio.artifact.character_meta_arannis" {
|
||||
t.Fatalf("same-member input source = %q", got)
|
||||
}
|
||||
if got := cfg.Pipeline.Scriptorium.Artifacts["player_handout"].DependsOn; !reflect.DeepEqual(got, []string{"session_recap"}) {
|
||||
if got := cfg.ArtifactCatalog.Artifacts["player_handout"].DependsOn; !reflect.DeepEqual(got, []string{"session_recap"}) {
|
||||
t.Fatalf("input-only artifact dependency = %#v", got)
|
||||
}
|
||||
if got := cfg.Pipeline.Scriptorium.Artifacts["character_items_arannis"].DependsOn; !reflect.DeepEqual(got, []string{"character_meta_arannis"}) {
|
||||
if got := cfg.ArtifactCatalog.Artifacts["character_items_arannis"].DependsOn; !reflect.DeepEqual(got, []string{"character_meta_arannis"}) {
|
||||
t.Fatalf("family input dependency = %#v", got)
|
||||
}
|
||||
if cfg.Party.Canonical == nil || len(cfg.Party.Canonical.Characters) != 2 {
|
||||
@@ -426,11 +426,11 @@ func TestExamplesLoadAndValidate(t *testing.T) {
|
||||
if characters[0].Player.Name != characters[1].Player.Name || len(characters[0].Character.Aliases) != 2 || len(characters[1].Character.Classes) != 2 {
|
||||
t.Fatalf("canonical party does not preserve repeated player, aliases, and multiclass data: %#v", characters)
|
||||
}
|
||||
if len(cfg.Pipeline.Publish.Outputs) != 3 {
|
||||
t.Fatalf("publish outputs = %#v, want transcript plus two family outputs", cfg.Pipeline.Publish.Outputs)
|
||||
if len(cfg.ArtifactCatalog.PublishOutputs) != 3 {
|
||||
t.Fatalf("publish outputs = %#v, want transcript plus two family outputs", cfg.ArtifactCatalog.PublishOutputs)
|
||||
}
|
||||
foundTranscript := false
|
||||
for _, output := range cfg.Pipeline.Publish.Outputs {
|
||||
for _, output := range cfg.ArtifactCatalog.PublishOutputs {
|
||||
if output.Source == "narratio.transcript.final_markdown" {
|
||||
foundTranscript = true
|
||||
if output.Required == nil || *output.Required != (profile.selection == "") {
|
||||
@@ -463,11 +463,11 @@ func TestExamplesLoadAndValidate(t *testing.T) {
|
||||
t.Fatalf("effective artifact catalog has %d records, want %d", len(catalog), wantCatalogSize)
|
||||
}
|
||||
if profile.selection == "testing" {
|
||||
artifact, exists := cfg.Pipeline.Scriptorium.Artifacts["testing_notes"]
|
||||
artifact, exists := cfg.ArtifactCatalog.Artifacts["testing_notes"]
|
||||
if !exists || artifact.Enabled {
|
||||
t.Fatalf("testing-only disabled artifact = %#v", artifact)
|
||||
}
|
||||
recap := cfg.Pipeline.Scriptorium.Artifacts["session_recap"]
|
||||
recap := cfg.ArtifactCatalog.Artifacts["session_recap"]
|
||||
if artifact.PromptID != "dnd.session_recap" ||
|
||||
artifact.PromptID != recap.PromptID ||
|
||||
artifact.ProfileID != recap.ProfileID ||
|
||||
|
||||
@@ -806,10 +806,9 @@ func TestExtractionReferencesRequireDeclaredOutput(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, testPipelineBaseYAML+"\n"+tt.body, testSessionBaseYAML)
|
||||
cfg, err := Load(pipelinePath, sessionPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
if err == nil {
|
||||
err = Validate(cfg)
|
||||
}
|
||||
err = Validate(cfg)
|
||||
if len(tt.wantErr) == 0 {
|
||||
if err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
|
||||
@@ -22,7 +22,16 @@ const (
|
||||
// CanonicalParty is the normalized domain value for narratio.party.v1.
|
||||
type CanonicalParty struct {
|
||||
Characters []PartyCharacter
|
||||
authoring *configkit.Result[partyDocument]
|
||||
authoring *configkit.Result[PartyConfig]
|
||||
}
|
||||
|
||||
// ConfigKitResult returns the actual completed party load, independently of
|
||||
// roster and players projections.
|
||||
func (p *CanonicalParty) ConfigKitResult() *configkit.Result[PartyConfig] {
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
return p.authoring
|
||||
}
|
||||
|
||||
// PartyCharacter is one ordered character declaration from a canonical party.
|
||||
@@ -51,7 +60,8 @@ type PartyClass struct {
|
||||
Level *int
|
||||
}
|
||||
|
||||
type partyDocument struct {
|
||||
// PartyConfig is the authored roster schema retained by ConfigKit.
|
||||
type PartyConfig struct {
|
||||
SchemaVersion string `yaml:"schema_version"`
|
||||
Characters map[string]partyCharacter `yaml:"characters"`
|
||||
}
|
||||
@@ -95,14 +105,14 @@ func LoadParty(path string) (*CanonicalParty, error) {
|
||||
}
|
||||
|
||||
func loadParty(source configkit.Source, imports bool) (*CanonicalParty, error) {
|
||||
definition := configkit.Definition[partyDocument]{
|
||||
definition := configkit.Definition[PartyConfig]{
|
||||
Version: &configkit.VersionRule{
|
||||
Path: configkit.Keys("schema_version"),
|
||||
Check: validatePartyVersion,
|
||||
},
|
||||
Validate: validatePartyDocument,
|
||||
}
|
||||
result, err := configkit.Load(source, configkit.Options[partyDocument]{Imports: imports, Definition: definition})
|
||||
result, err := configkit.Load(source, configkit.Options[PartyConfig]{Imports: imports, Definition: definition})
|
||||
if err != nil {
|
||||
return nil, describeConfigKitLoadError("party", err)
|
||||
}
|
||||
@@ -119,13 +129,13 @@ func validatePartyVersion(version configkit.Version, validation *configkit.Valid
|
||||
return nil
|
||||
}
|
||||
|
||||
func validatePartyDocument(document *partyDocument, validation *configkit.Validation) {
|
||||
func validatePartyDocument(document *PartyConfig, validation *configkit.Validation) {
|
||||
if problem := firstPartyDomainError(document); problem != nil {
|
||||
validation.Error(problem.path, problem.message)
|
||||
}
|
||||
}
|
||||
|
||||
func firstPartyDomainError(document *partyDocument) *partyDomainError {
|
||||
func firstPartyDomainError(document *PartyConfig) *partyDomainError {
|
||||
charactersPath := configkit.Keys("characters")
|
||||
if document == nil || len(document.Characters) == 0 {
|
||||
return &partyDomainError{path: charactersPath, message: "characters must be non-empty"}
|
||||
@@ -206,7 +216,7 @@ func partyNameAmbiguous(name string, existing []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func canonicalPartyFromResult(result *configkit.Result[partyDocument]) *CanonicalParty {
|
||||
func canonicalPartyFromResult(result *configkit.Result[PartyConfig]) *CanonicalParty {
|
||||
type orderedCharacter struct {
|
||||
id string
|
||||
location configkit.Location
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestImportedPartyExpandsFamilyIdentities(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{"character_meta_alpha", "character_meta_beta"} {
|
||||
if _, ok := cfg.Pipeline.Scriptorium.Artifacts[id]; !ok {
|
||||
if _, ok := cfg.ArtifactCatalog.Artifacts[id]; !ok {
|
||||
t.Fatalf("missing family member %q", id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,12 @@ func resolvePartyInput(input ResolvedInputFile) (ResolvedParty, error) {
|
||||
if err != nil {
|
||||
return ResolvedParty{}, fmt.Errorf("parse party input %q: %w", path, err)
|
||||
}
|
||||
players, err := party.PlayersYAML()
|
||||
if err != nil {
|
||||
return ResolvedParty{}, err
|
||||
}
|
||||
return ResolvedParty{
|
||||
Players: players,
|
||||
Source: PartySource{
|
||||
Path: path,
|
||||
ConfigPath: configPath,
|
||||
@@ -59,3 +64,19 @@ func resolveCampaignParty(campaignPath string, campaign *CampaignConfig) (Resolv
|
||||
}
|
||||
return resolvePartyInput(input)
|
||||
}
|
||||
|
||||
// ResolveParty loads the exact explicit party file, or the campaign's configured
|
||||
// default. Explicit paths are relative to the invocation directory.
|
||||
func ResolveParty(campaignPath string, campaign *CampaignConfig, explicitFile *string) (ResolvedParty, error) {
|
||||
if explicitFile == nil {
|
||||
return resolveCampaignParty(campaignPath, campaign)
|
||||
}
|
||||
if *explicitFile == "" {
|
||||
return ResolvedParty{}, fmt.Errorf("explicit party file path is required")
|
||||
}
|
||||
path, err := filepath.Abs(*explicitFile)
|
||||
if err != nil {
|
||||
return ResolvedParty{}, fmt.Errorf("resolve explicit party file: %w", err)
|
||||
}
|
||||
return resolvePartyInput(ResolvedInputFile{Path: path, ConfigPath: path, Source: "party_file"})
|
||||
}
|
||||
|
||||
@@ -13,15 +13,13 @@ import (
|
||||
)
|
||||
|
||||
type pipelineResolutionMetadata struct {
|
||||
rootPath string
|
||||
imports []string
|
||||
sources []string
|
||||
selectedOverlay *pipelineOverlaySelection
|
||||
effectiveDigest string
|
||||
artifactFamilies map[string]ScriptoriumArtifactFamilyConfig
|
||||
artifactFamiliesExpanded bool
|
||||
inspection *configkit.Result[effectivePipelineProjection]
|
||||
authoring *configkit.Result[PipelineConfig]
|
||||
rootPath string
|
||||
imports []string
|
||||
sources []string
|
||||
selectedOverlay *pipelineOverlaySelection
|
||||
effectiveDigest string
|
||||
inspection *configkit.Result[effectivePipelineProjection]
|
||||
authoring *configkit.Result[PipelineConfig]
|
||||
}
|
||||
|
||||
// ConfigKitResult returns the authoritative native load result. Callers consume
|
||||
@@ -298,9 +296,6 @@ func pipelineMetadataPaths(cfg *PipelineConfig) ([]projectedPipelineValue, error
|
||||
return effective, nil
|
||||
}
|
||||
families := cfg.Scriptorium.ArtifactFamilies
|
||||
if cfg.resolution != nil && len(cfg.resolution.artifactFamilies) != 0 {
|
||||
families = cfg.resolution.artifactFamilies
|
||||
}
|
||||
if len(families) == 0 {
|
||||
return effective, nil
|
||||
}
|
||||
|
||||
@@ -129,12 +129,12 @@ whisperx:
|
||||
t.Fatalf("load disjoint contributions: %v", err)
|
||||
}
|
||||
if test.name == "artifact" {
|
||||
artifact := cfg.Pipeline.Scriptorium.Artifacts["recap"]
|
||||
artifact := cfg.ArtifactCatalog.Artifacts["recap"]
|
||||
if !artifact.Enabled || artifact.PromptID != "dnd.recap" || artifact.OutputPath != "artifacts/recap.md" {
|
||||
t.Fatalf("composed artifact = %#v", artifact)
|
||||
}
|
||||
} else {
|
||||
artifact := cfg.Pipeline.Scriptorium.Artifacts["recap_alice"]
|
||||
artifact := cfg.ArtifactCatalog.Artifacts["recap_alice"]
|
||||
if !artifact.Enabled || artifact.PromptID != "dnd.recap" || artifact.OutputPath != "artifacts/alice.md" {
|
||||
t.Fatalf("composed artifact family member = %#v", artifact)
|
||||
}
|
||||
@@ -145,11 +145,11 @@ whisperx:
|
||||
if err != nil {
|
||||
t.Fatalf("load replacement overlay: %v", err)
|
||||
}
|
||||
if test.name == "artifact" && cfg.Pipeline.Scriptorium.Artifacts["recap"].OutputPath != "artifacts/replaced.md" {
|
||||
t.Fatalf("overlay artifact replacement = %#v", cfg.Pipeline.Scriptorium.Artifacts["recap"])
|
||||
if test.name == "artifact" && cfg.ArtifactCatalog.Artifacts["recap"].OutputPath != "artifacts/replaced.md" {
|
||||
t.Fatalf("overlay artifact replacement = %#v", cfg.ArtifactCatalog.Artifacts["recap"])
|
||||
}
|
||||
if test.name == "artifact family" && cfg.Pipeline.Scriptorium.Artifacts["recap_alice"].OutputPath != "artifacts/alice_replaced.md" {
|
||||
t.Fatalf("overlay family replacement = %#v", cfg.Pipeline.Scriptorium.Artifacts["recap_alice"])
|
||||
if test.name == "artifact family" && cfg.ArtifactCatalog.Artifacts["recap_alice"].OutputPath != "artifacts/alice_replaced.md" {
|
||||
t.Fatalf("overlay family replacement = %#v", cfg.ArtifactCatalog.Artifacts["recap_alice"])
|
||||
}
|
||||
|
||||
removal := "removal"
|
||||
@@ -157,8 +157,8 @@ whisperx:
|
||||
if err != nil {
|
||||
t.Fatalf("load removal overlay: %v", err)
|
||||
}
|
||||
if len(cfg.Pipeline.Scriptorium.Artifacts) != 0 {
|
||||
t.Fatalf("overlay left artifacts after removal: %#v", cfg.Pipeline.Scriptorium.Artifacts)
|
||||
if len(cfg.ArtifactCatalog.Artifacts) != 0 {
|
||||
t.Fatalf("overlay left artifacts after removal: %#v", cfg.ArtifactCatalog.Artifacts)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -410,8 +410,8 @@ whisperx:
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parent := cfg.Pipeline.Scriptorium.Artifacts["session_recap"]
|
||||
child, ok := cfg.Pipeline.Scriptorium.Artifacts["session_notes"]
|
||||
parent := cfg.ArtifactCatalog.Artifacts["session_recap"]
|
||||
child, ok := cfg.ArtifactCatalog.Artifacts["session_notes"]
|
||||
if !ok {
|
||||
t.Fatal("inherited child artifact identity was not retained")
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
||||
`,
|
||||
assert: func(t *testing.T, cfg *Config) {
|
||||
t.Helper()
|
||||
artifact := cfg.Pipeline.Scriptorium.Artifacts["session_recap"]
|
||||
artifact := cfg.ArtifactCatalog.Artifacts["session_recap"]
|
||||
if artifact.RenderDebug == nil || *artifact.RenderDebug != true {
|
||||
t.Fatalf("artifact render_debug = %#v, want true", artifact.RenderDebug)
|
||||
}
|
||||
@@ -320,8 +320,8 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
||||
if cfg.Pipeline.Scriptorium == nil {
|
||||
t.Fatal("scriptorium config should be present")
|
||||
}
|
||||
if len(cfg.Pipeline.Scriptorium.Artifacts) != 2 {
|
||||
t.Fatalf("scriptorium.artifacts count = %d, want 2", len(cfg.Pipeline.Scriptorium.Artifacts))
|
||||
if len(cfg.ArtifactCatalog.Artifacts) != 2 {
|
||||
t.Fatalf("scriptorium.artifacts count = %d, want 2", len(cfg.ArtifactCatalog.Artifacts))
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -418,7 +418,7 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
||||
`,
|
||||
assert: func(t *testing.T, cfg *Config) {
|
||||
t.Helper()
|
||||
dependencies := cfg.Pipeline.Scriptorium.Artifacts["player_handout"].DependsOn
|
||||
dependencies := cfg.ArtifactCatalog.Artifacts["player_handout"].DependsOn
|
||||
if len(dependencies) != 1 || dependencies[0] != "session_recap" {
|
||||
t.Fatalf("inferred dependencies = %#v, want [session_recap]", dependencies)
|
||||
}
|
||||
@@ -555,15 +555,12 @@ func TestScriptoriumLoadAndValidate(t *testing.T) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
if err == nil {
|
||||
if tt.assert != nil {
|
||||
tt.assert(t, cfg)
|
||||
}
|
||||
err = Validate(cfg)
|
||||
}
|
||||
|
||||
if tt.assert != nil {
|
||||
tt.assert(t, cfg)
|
||||
}
|
||||
|
||||
err = Validate(cfg)
|
||||
if len(tt.wantValidateErr) > 0 {
|
||||
if err == nil {
|
||||
t.Fatalf("expected validation error containing %q, got nil", tt.wantValidateErr)
|
||||
@@ -591,10 +588,10 @@ func TestScriptoriumDiagnosticsAreIndependentOfMapInsertionOrder(t *testing.T) {
|
||||
secondArtifacts["alpha"] = invalidArtifact
|
||||
secondArtifacts["beta"] = invalidArtifact
|
||||
|
||||
firstErr := validateScriptorium(&ScriptoriumConfig{Binary: "scriptorium", Artifacts: firstArtifacts}, nil)
|
||||
secondErr := validateScriptorium(&ScriptoriumConfig{Binary: "scriptorium", Artifacts: secondArtifacts}, nil)
|
||||
firstErr := validateConcreteArtifacts(firstArtifacts, nil)
|
||||
secondErr := validateConcreteArtifacts(secondArtifacts, nil)
|
||||
if firstErr == nil || secondErr == nil {
|
||||
t.Fatalf("validateScriptorium() errors = %v / %v, want validation failures", firstErr, secondErr)
|
||||
t.Fatalf("concrete artifact validation errors = %v / %v, want validation failures", firstErr, secondErr)
|
||||
}
|
||||
if firstErr.Error() != secondErr.Error() {
|
||||
t.Fatalf("equivalent maps produced different diagnostics:\nfirst: %v\nsecond: %v", firstErr, secondErr)
|
||||
@@ -621,10 +618,9 @@ scriptorium:
|
||||
`
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||
cfg, err := Load(pipelinePath, sessionPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
if err == nil {
|
||||
err = Validate(cfg)
|
||||
}
|
||||
err = Validate(cfg)
|
||||
if err == nil || !strings.Contains(err.Error(), "pipeline.scriptorium.artifacts.session_recap.inputs.transcript.source") || !strings.Contains(err.Error(), "unsupported") {
|
||||
t.Fatalf("Validate() error = %v, want source field and unsupported category", err)
|
||||
}
|
||||
|
||||
@@ -266,10 +266,9 @@ inputs:
|
||||
}
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, sessionYAML)
|
||||
cfg, err := Load(pipelinePath, sessionPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
if err == nil {
|
||||
err = Validate(cfg)
|
||||
}
|
||||
err = Validate(cfg)
|
||||
if tt.wantErr != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
||||
t.Fatalf("Validate() error = %v, want %q", err, tt.wantErr)
|
||||
@@ -460,10 +459,9 @@ publish:
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||
|
||||
cfg, err := Load(pipelinePath, sessionPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
if err == nil {
|
||||
err = Validate(cfg)
|
||||
}
|
||||
err = Validate(cfg)
|
||||
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
|
||||
t.Fatalf("Validate() error = %v, want to contain %q", err, tt.wantErr)
|
||||
}
|
||||
@@ -481,10 +479,9 @@ publish:
|
||||
`
|
||||
pipelinePath, sessionPath := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
|
||||
cfg, err := Load(pipelinePath, sessionPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
if err == nil {
|
||||
err = Validate(cfg)
|
||||
}
|
||||
err = Validate(cfg)
|
||||
if err == nil || !strings.Contains(err.Error(), "pipeline.publish.outputs[0].source") || !strings.Contains(err.Error(), "unsupported") {
|
||||
t.Fatalf("Validate() error = %v, want source field and unsupported category", err)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ func Validate(cfg *Config) error {
|
||||
if err := validateResolvedPartyInputs(cfg); err != nil {
|
||||
return fmt.Errorf("campaign/session config invalid: %w", err)
|
||||
}
|
||||
if _, err := DeriveArtifactCatalog(cfg.Pipeline, cfg.Party); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateCrossConfig(cfg.Pipeline, cfg.Session, cfg.StableInputs); err != nil {
|
||||
return fmt.Errorf("pipeline/session config invalid: %w", err)
|
||||
}
|
||||
@@ -79,9 +82,6 @@ func validatePipeline(cfg *PipelineConfig) error {
|
||||
if err := validateNotarius(cfg.Notarius, cfg.Scriptorium); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validatePublish(cfg.Publish, cfg.Scriptorium, cfg.Notarius); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateCleanupPublishPolicy(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func validatePipeline(cfg *PipelineConfig) error {
|
||||
if err := validateRender(cfg.Render); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateScriptorium(cfg.Scriptorium, cfg.Notarius); err != nil {
|
||||
if err := validateScriptoriumConfiguration(cfg.Scriptorium); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateNotification(cfg.Notification); err != nil {
|
||||
|
||||
@@ -124,8 +124,8 @@ func validateResolvedPartyInputs(cfg *Config) error {
|
||||
if cfg.Party.Canonical == nil {
|
||||
return fmt.Errorf("canonical party data is required")
|
||||
}
|
||||
if cfg.Party.Source.Source != "campaign_config" {
|
||||
return fmt.Errorf("canonical party must be sourced by campaign_config")
|
||||
if cfg.Party.Source.Source != "campaign_config" && cfg.Party.Source.Source != "party_file" {
|
||||
return fmt.Errorf("canonical party must be sourced by campaign_config or an explicit party_file")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -69,14 +69,9 @@ func validateStorage(cfg StorageConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validatePublish(cfg *PublishConfig, scriptorium *ScriptoriumConfig, notarius *NotariusConfig) error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
configuredOutputs := scriptoriumOutputPathMap(scriptorium)
|
||||
extractionOutputs := notariusOutputKeySet(notarius)
|
||||
func validatePublishedOutputs(outputs []PublishOutputRule, configuredOutputs map[string]string, extractionOutputs map[string]struct{}) error {
|
||||
seenDest := map[string]struct{}{}
|
||||
for i, item := range cfg.Outputs {
|
||||
for i, item := range outputs {
|
||||
prefix := fmt.Sprintf("pipeline.publish.outputs[%d]", i)
|
||||
source := strings.TrimSpace(item.Source)
|
||||
if source == "" {
|
||||
@@ -122,16 +117,18 @@ func validateCleanupPublishPolicy(cfg *PipelineConfig) error {
|
||||
}
|
||||
|
||||
func scriptoriumOutputPathMap(scriptorium *ScriptoriumConfig) map[string]string {
|
||||
out := map[string]string{}
|
||||
if scriptorium == nil || len(scriptorium.Artifacts) == 0 {
|
||||
return out
|
||||
if scriptorium == nil {
|
||||
return map[string]string{}
|
||||
}
|
||||
for _, key := range sortedStringKeys(scriptorium.Artifacts) {
|
||||
artifactCfg := scriptorium.Artifacts[key]
|
||||
if !artifactpolicy.IsConfiguredKey(key) {
|
||||
continue
|
||||
return artifactOutputPathMap(scriptorium.Artifacts)
|
||||
}
|
||||
|
||||
func artifactOutputPathMap(artifacts map[string]ScriptoriumArtifactConfig) map[string]string {
|
||||
out := make(map[string]string, len(artifacts))
|
||||
for _, key := range sortedStringKeys(artifacts) {
|
||||
if artifactpolicy.IsConfiguredKey(key) {
|
||||
out[strings.TrimSpace(key)] = strings.TrimSpace(artifacts[key].OutputPath)
|
||||
}
|
||||
out[strings.TrimSpace(key)] = strings.TrimSpace(artifactCfg.OutputPath)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
)
|
||||
|
||||
func validateScriptorium(cfg *ScriptoriumConfig, notarius *NotariusConfig) error {
|
||||
func validateScriptoriumConfiguration(cfg *ScriptoriumConfig) error {
|
||||
if cfg == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -22,16 +22,26 @@ func validateScriptorium(cfg *ScriptoriumConfig, notarius *NotariusConfig) error
|
||||
if err := validateDuration("pipeline.scriptorium.timeout", cfg.Timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
artifactNames, configuredArtifacts, err := validateScriptoriumArtifactKeys(cfg.Artifacts)
|
||||
names, _, err := validateScriptoriumArtifactKeys(cfg.Artifacts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateScriptoriumDeclarations(cfg.Artifacts, artifactNames); err != nil {
|
||||
if err := validateScriptoriumDeclarations(cfg.Artifacts, names); err != nil {
|
||||
return err
|
||||
}
|
||||
return validateScriptoriumVariables(cfg.Artifacts, names)
|
||||
}
|
||||
|
||||
func validateConcreteArtifacts(artifacts map[string]ScriptoriumArtifactConfig, notarius *NotariusConfig) error {
|
||||
artifactNames, configuredArtifacts, err := validateScriptoriumArtifactKeys(artifacts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateScriptoriumDeclarations(artifacts, artifactNames); err != nil {
|
||||
return err
|
||||
}
|
||||
referencedArtifacts, err := validateScriptoriumDependenciesAndInputs(
|
||||
cfg.Artifacts,
|
||||
artifacts,
|
||||
artifactNames,
|
||||
configuredArtifacts,
|
||||
notariusOutputKeySet(notarius),
|
||||
@@ -39,13 +49,13 @@ func validateScriptorium(cfg *ScriptoriumConfig, notarius *NotariusConfig) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateScriptoriumVariables(cfg.Artifacts, artifactNames); err != nil {
|
||||
if err := validateScriptoriumVariables(artifacts, artifactNames); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateScriptoriumReferencedOutputs(cfg.Artifacts, referencedArtifacts); err != nil {
|
||||
if err := validateScriptoriumReferencedOutputs(artifacts, referencedArtifacts); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ValidateScriptoriumArtifactDependencies(cfg.Artifacts); err != nil {
|
||||
if err := ValidateScriptoriumArtifactDependencies(artifacts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user