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

@@ -226,6 +226,10 @@ objects are unchanged by the authoring update.
## 7. P3: Reuse enumerated source records and one inspection source index ## 7. P3: Reuse enumerated source records and one inspection source index
Status: Complete. Source enumeration uses complete native records directly;
catalog projection shares one index and retained family sources. Nested empty
imports and existing composite/family inspection checks pass.
Stage: 9. Stage: 9.
Locations: `internal/config/effective_pipeline.go:57–75`, Locations: `internal/config/effective_pipeline.go:57–75`,

View File

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