Reuse party provenance within each inspection
This commit is contained in:
@@ -263,6 +263,10 @@ output, including composite and inherited contributors, when refactoring.
|
||||
|
||||
## 8. P3: Reuse party metadata and per-character provenance within inspection
|
||||
|
||||
Status: Complete. Each source/catalog projection shares one native metadata
|
||||
snapshot, one source index, and a per-character cache. Imported-party, composite
|
||||
provenance, family, and command agreement tests pass under the race detector.
|
||||
|
||||
Stage: 9, consuming Stage 5's imported party result.
|
||||
|
||||
Locations: `internal/config/artifact_catalog.go:67–105` and
|
||||
|
||||
@@ -41,6 +41,7 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
sort.Strings(keys)
|
||||
records := make([]EffectiveArtifactRecord, 0, len(keys))
|
||||
pathsByID := pipelineSourcePaths(cfg)
|
||||
partySources := partyCharacterSourceLookup(party)
|
||||
for _, key := range keys {
|
||||
artifact := cfg.Scriptorium.Artifacts[key]
|
||||
record := EffectiveArtifactRecord{
|
||||
@@ -55,7 +56,7 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
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), ",")
|
||||
record.PartySource = strings.Join(partySources(member.CharacterID), ",")
|
||||
} else {
|
||||
record.DefinitionSources = declarationDefinitionSourcesWithIndex(cfg, configkit.Keys("scriptorium", "artifacts", key), pathsByID)
|
||||
}
|
||||
@@ -65,45 +66,58 @@ func EffectiveArtifactCatalog(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func partyCharacterSources(party ResolvedParty, id string) []string {
|
||||
if party.Canonical == nil || party.Canonical.authoring == nil {
|
||||
return nonEmptySortedStrings([]string{party.Source.Path})
|
||||
}
|
||||
result := party.Canonical.authoring
|
||||
path := configkit.Keys("characters", id)
|
||||
var ids []string
|
||||
add := func(origin configkit.Origin) {
|
||||
for _, location := range origin.Locations {
|
||||
ids = append(ids, location.SourceID)
|
||||
}
|
||||
for _, step := range origin.Inheritance {
|
||||
for _, location := range step.Locations {
|
||||
ids = append(ids, location.SourceID)
|
||||
}
|
||||
}
|
||||
}
|
||||
if info, ok := result.Metadata().Lookup(path); ok {
|
||||
add(info.Origin)
|
||||
}
|
||||
for _, change := range result.Metadata().History(path) {
|
||||
if change.Origin.Layer == configkit.LayerMain || change.Origin.Layer == configkit.LayerOverlay {
|
||||
add(change.Origin)
|
||||
}
|
||||
}
|
||||
var sources []string
|
||||
for _, id := range nonEmptySortedStrings(ids) {
|
||||
if source, ok := result.Source(id); ok {
|
||||
// partyCharacterSourceLookup owns a single inspection's detached native evidence.
|
||||
func partyCharacterSourceLookup(party ResolvedParty) func(string) []string {
|
||||
var metadata configkit.Metadata
|
||||
sources := map[string]string{}
|
||||
if party.Canonical != nil && party.Canonical.authoring != nil {
|
||||
result := party.Canonical.authoring
|
||||
metadata = result.Metadata()
|
||||
for _, source := range result.Sources() {
|
||||
name := source.Path
|
||||
if name == "" {
|
||||
name = source.Label
|
||||
}
|
||||
sources = append(sources, name)
|
||||
sources[source.ID] = name
|
||||
}
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
sources = append(sources, party.Source.Path)
|
||||
cache := map[string][]string{}
|
||||
return func(id string) []string {
|
||||
if value, ok := cache[id]; ok {
|
||||
return value
|
||||
}
|
||||
path := configkit.Keys("characters", id)
|
||||
var ids []string
|
||||
add := func(origin configkit.Origin) {
|
||||
for _, location := range origin.Locations {
|
||||
ids = append(ids, location.SourceID)
|
||||
}
|
||||
for _, step := range origin.Inheritance {
|
||||
for _, location := range step.Locations {
|
||||
ids = append(ids, location.SourceID)
|
||||
}
|
||||
}
|
||||
}
|
||||
if info, ok := metadata.Lookup(path); ok {
|
||||
add(info.Origin)
|
||||
}
|
||||
for _, change := range metadata.History(path) {
|
||||
if change.Origin.Layer == configkit.LayerMain || change.Origin.Layer == configkit.LayerOverlay {
|
||||
add(change.Origin)
|
||||
}
|
||||
}
|
||||
var paths []string
|
||||
for _, id := range nonEmptySortedStrings(ids) {
|
||||
if name := sources[id]; name != "" {
|
||||
paths = append(paths, name)
|
||||
}
|
||||
}
|
||||
if len(paths) == 0 {
|
||||
paths = append(paths, party.Source.Path)
|
||||
}
|
||||
cache[id] = nonEmptySortedStrings(paths)
|
||||
return cache[id]
|
||||
}
|
||||
return nonEmptySortedStrings(sources)
|
||||
}
|
||||
|
||||
func artifactFamilyDefinitionSources(cfg *PipelineConfig, key string) []string {
|
||||
|
||||
@@ -122,6 +122,7 @@ func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
return nil, err
|
||||
}
|
||||
families := ArtifactFamilies(cfg)
|
||||
partySources := partyCharacterSourceLookup(party)
|
||||
publishCount := 0
|
||||
if cfg.Publish != nil {
|
||||
publishCount = len(cfg.Publish.Outputs)
|
||||
@@ -132,7 +133,7 @@ func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]Effec
|
||||
continue
|
||||
}
|
||||
if familyKey, ok := generatedArtifactFamilyForPath(path, families); ok {
|
||||
records = appendGeneratedArtifactSources(records, path, familyKey, families, owners, party)
|
||||
records = appendGeneratedArtifactSources(records, path, familyKey, families, owners, partySources)
|
||||
continue
|
||||
}
|
||||
records = appendPipelineOwners(records, path, owners[path], cfg)
|
||||
@@ -334,7 +335,7 @@ func generatedArtifactFamilyForPath(path string, families ArtifactFamilyCatalog)
|
||||
return member.Family, exists
|
||||
}
|
||||
|
||||
func appendGeneratedArtifactSources(records []EffectivePipelineSourceRecord, path, familyKey string, families ArtifactFamilyCatalog, owners map[string][]string, party ResolvedParty) []EffectivePipelineSourceRecord {
|
||||
func appendGeneratedArtifactSources(records []EffectivePipelineSourceRecord, path, familyKey string, families ArtifactFamilyCatalog, owners map[string][]string, partySources func(string) []string) []EffectivePipelineSourceRecord {
|
||||
for _, source := range generatedArtifactSources(path, familyKey, families, owners) {
|
||||
role := "family"
|
||||
if source == pipelineDefaultOwnershipSource {
|
||||
@@ -344,7 +345,7 @@ func appendGeneratedArtifactSources(records []EffectivePipelineSourceRecord, pat
|
||||
}
|
||||
memberPath := strings.TrimPrefix(path, "scriptorium.artifacts.")
|
||||
memberKey, _, _ := strings.Cut(memberPath, ".")
|
||||
for _, source := range partyCharacterSources(party, families.Members[memberKey].CharacterID) {
|
||||
for _, source := range partySources(families.Members[memberKey].CharacterID) {
|
||||
records = append(records, EffectivePipelineSourceRecord{Path: path, Role: "party", Source: normalizedProvenancePath(source)})
|
||||
}
|
||||
return records
|
||||
|
||||
Reference in New Issue
Block a user