Reuse native source records and catalog source indexes

This commit is contained in:
2026-11-18 04:09:24 +00:00
parent 97a93d3393
commit 0e34ea1d48
5 changed files with 39 additions and 19 deletions

View File

@@ -40,6 +40,7 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
}
sort.Strings(keys)
records := make([]EffectiveArtifactRecord, 0, len(keys))
pathsByID := pipelineSourcePaths(cfg)
for _, key := range keys {
artifact := cfg.Scriptorium.Artifacts[key]
record := EffectiveArtifactRecord{
@@ -50,13 +51,13 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
Dependencies: append([]string(nil), artifact.DependsOn...),
}
if member, ok := cfg.familyCatalog.Members[key]; ok {
record.DefinitionSources = artifactFamilyDefinitionSources(cfg, member.Family)
record.DefinitionSources = append([]string(nil), cfg.familyCatalog.Families[member.Family].Sources...)
record.FamilyKey = member.Family
record.CharacterID = member.CharacterID
record.FamilySources = append([]string(nil), cfg.familyCatalog.Families[member.Family].Sources...)
record.PartySource = strings.Join(partyCharacterSources(party, member.CharacterID), ",")
} else {
record.DefinitionSources = artifactDefinitionSources(cfg, key)
record.DefinitionSources = declarationDefinitionSourcesWithIndex(cfg, configkit.Keys("scriptorium", "artifacts", key), pathsByID)
}
record.Dependencies = nonEmptySortedStrings(record.Dependencies)
records = append(records, record)
@@ -105,12 +106,6 @@ func partyCharacterSources(party ResolvedParty, id string) []string {
return nonEmptySortedStrings(sources)
}
func artifactDefinitionSources(cfg *PipelineConfig, key string) []string {
return declarationDefinitionSources(cfg,
configkit.Keys("scriptorium", "artifacts", key),
)
}
func artifactFamilyDefinitionSources(cfg *PipelineConfig, key string) []string {
return declarationDefinitionSources(cfg,
configkit.Keys("scriptorium", "artifact_families", key),
@@ -118,10 +113,13 @@ func artifactFamilyDefinitionSources(cfg *PipelineConfig, key string) []string {
}
func declarationDefinitionSources(cfg *PipelineConfig, declaration configkit.Path) []string {
return declarationDefinitionSourcesWithIndex(cfg, declaration, pipelineSourcePaths(cfg))
}
func declarationDefinitionSourcesWithIndex(cfg *PipelineConfig, declaration configkit.Path, pathsByID map[string]string) []string {
if cfg == nil || cfg.resolution == nil {
return nil
}
pathsByID := pipelineSourcePaths(cfg)
seen := map[string]struct{}{}
for _, change := range cfg.resolution.configkitMetadata.History(declaration) {
if change.Origin.Layer != configkit.LayerMain && change.Origin.Layer != configkit.LayerOverlay {

View File

@@ -59,11 +59,7 @@ func emptyImportSelections[T any](result *configkit.Result[T]) []EmptyImportSele
return nil
}
var selections []EmptyImportSelection
for _, listed := range result.Sources() {
source, ok := result.Source(listed.ID)
if !ok {
continue
}
for _, source := range result.Sources() {
name := source.Path
if name == "" {
name = source.Label

View File

@@ -0,0 +1,27 @@
package config
import "testing"
func TestEmptyImportSourcesIncludeNestedDeclarations(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "config:\n imports:\n - path: fragment.yml\n - path: absent-root.yml\n")
fragment := writePipelineFixture(t, dir, "fragment.yml", "config:\n imports:\n - path: absent-child.yml\n")
cfg, err := LoadPipeline(root)
if err != nil {
t.Fatal(err)
}
selections := EffectiveEmptyImports(cfg, nil)
if len(selections) != 2 {
t.Fatalf("empty selections: %#v", selections)
}
seen := map[string]bool{}
for _, selection := range selections {
if selection.Selector != "path" || selection.Path == "" || selection.Line == 0 {
t.Fatalf("incomplete evidence: %#v", selection)
}
seen[selection.Source] = true
}
if !seen[root] || !seen[fragment] {
t.Fatalf("source evidence: %#v", selections)
}
}

View File

@@ -345,11 +345,6 @@ func pipelineSourcePaths(cfg *PipelineConfig) map[string]string {
return paths
}
for _, source := range cfg.resolution.configkitSources {
if cfg.resolution.authoring != nil {
if found, ok := cfg.resolution.authoring.Source(source.ID); ok {
source = found
}
}
path := source.Path
if path == "" {
path = source.Label