Use native configuration diff and source evidence
This commit is contained in:
@@ -54,7 +54,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 = party.Source.Path
|
||||
record.PartySource = strings.Join(partyCharacterSources(party, member.CharacterID), ",")
|
||||
} else {
|
||||
record.DefinitionSources = artifactDefinitionSources(cfg, key)
|
||||
}
|
||||
@@ -64,6 +64,47 @@ 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 {
|
||||
name := source.Path
|
||||
if name == "" {
|
||||
name = source.Label
|
||||
}
|
||||
sources = append(sources, name)
|
||||
}
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
sources = append(sources, party.Source.Path)
|
||||
}
|
||||
return nonEmptySortedStrings(sources)
|
||||
}
|
||||
|
||||
func artifactDefinitionSources(cfg *PipelineConfig, key string) []string {
|
||||
return declarationDefinitionSources(cfg,
|
||||
configkit.Keys("scriptorium", "artifacts", key),
|
||||
|
||||
@@ -72,3 +72,11 @@ func newPipelineInspection(cfg *PipelineConfig) (*configkit.Result[effectivePipe
|
||||
projection := projectEffectivePipeline(cfg)
|
||||
return configkit.Load(configkit.NoSource(), configkit.Options[effectivePipelineProjection]{Definition: configkit.Definition[effectivePipelineProjection]{Defaults: func() effectivePipelineProjection { return projection }}})
|
||||
}
|
||||
|
||||
// DiffEffectivePipelines compares frozen final-domain snapshots.
|
||||
func DiffEffectivePipelines(left, right *PipelineConfig) ([]configkit.Difference, error) {
|
||||
if left == nil || right == nil || left.resolution == nil || right.resolution == nil {
|
||||
return nil, fmt.Errorf("resolved pipelines are required")
|
||||
}
|
||||
return configkit.Diff(left.resolution.inspection, right.resolution.inspection)
|
||||
}
|
||||
|
||||
@@ -45,6 +45,48 @@ type EffectivePipelineSourceRecord struct {
|
||||
Source string
|
||||
}
|
||||
|
||||
// EmptyImportSelection describes a native optional selection that acquired no source.
|
||||
type EmptyImportSelection struct {
|
||||
Source string
|
||||
Path string
|
||||
Selector string
|
||||
Line int
|
||||
Column int
|
||||
}
|
||||
|
||||
func emptyImportSelections[T any](result *configkit.Result[T]) []EmptyImportSelection {
|
||||
if result == nil {
|
||||
return nil
|
||||
}
|
||||
var selections []EmptyImportSelection
|
||||
for _, listed := range result.Sources() {
|
||||
source, ok := result.Source(listed.ID)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name := source.Path
|
||||
if name == "" {
|
||||
name = source.Label
|
||||
}
|
||||
for _, item := range source.EmptyImportSelections {
|
||||
selections = append(selections, EmptyImportSelection{Source: name, Path: item.Path.String(), Selector: string(item.Selector), Line: item.Location.Line, Column: item.Location.Column})
|
||||
}
|
||||
}
|
||||
return selections
|
||||
}
|
||||
|
||||
// EffectiveEmptyImports reports only optional selections that acquired nothing.
|
||||
func EffectiveEmptyImports(pipeline *PipelineConfig, campaign *CampaignConfig) []EmptyImportSelection {
|
||||
var result []EmptyImportSelection
|
||||
if pipeline != nil && pipeline.resolution != nil {
|
||||
result = append(result, emptyImportSelections(pipeline.resolution.authoring)...)
|
||||
}
|
||||
if campaign != nil && campaign.resolution != nil {
|
||||
result = append(result, emptyImportSelections(campaign.resolution.campaign)...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// EffectivePipelineValueRecord identifies one normalized, secret-free
|
||||
// effective configuration value. Values use deterministic compact JSON
|
||||
// representations so command output can be compared without raw YAML layout.
|
||||
@@ -119,15 +161,19 @@ func EffectiveCampaignSources(campaignPath string, campaign *CampaignConfig, par
|
||||
if campaign == nil {
|
||||
return nil
|
||||
}
|
||||
campaignSource := normalizedProvenancePath(campaignPath)
|
||||
records := []EffectivePipelineSourceRecord{
|
||||
{Path: "campaign.campaign_id", Role: "campaign", Source: campaignSource},
|
||||
{Path: "campaign.inputs.autocorrect_file", Role: "campaign", Source: campaignSource},
|
||||
{Path: "campaign.inputs.glossary_file", Role: "campaign", Source: campaignSource},
|
||||
{Path: "campaign.inputs.speakers_file", Role: "campaign", Source: campaignSource},
|
||||
}
|
||||
fields := []string{"campaign_id", "inputs.autocorrect_file", "inputs.glossary_file", "inputs.speakers_file", "inputs.party_file"}
|
||||
if strings.TrimSpace(campaign.Inputs.SpellCatalogFile) != "" {
|
||||
records = append(records, EffectivePipelineSourceRecord{Path: "campaign.inputs.spell_catalog_file", Role: "campaign", Source: campaignSource})
|
||||
fields = append(fields, "inputs.spell_catalog_file")
|
||||
}
|
||||
var records []EffectivePipelineSourceRecord
|
||||
for _, field := range fields {
|
||||
sources := campaignDefinitionSources(campaign, configkit.Keys(strings.Split(field, ".")...))
|
||||
if len(sources) == 0 {
|
||||
sources = []string{campaignPath}
|
||||
}
|
||||
for _, source := range sources {
|
||||
records = append(records, EffectivePipelineSourceRecord{Path: "campaign." + field, Role: "campaign", Source: normalizedProvenancePath(source)})
|
||||
}
|
||||
}
|
||||
partySource := normalizedProvenancePath(party.Source.Path)
|
||||
records = append(records,
|
||||
@@ -146,6 +192,43 @@ func EffectiveCampaignSources(campaignPath string, campaign *CampaignConfig, par
|
||||
return records
|
||||
}
|
||||
|
||||
func campaignDefinitionSources(campaign *CampaignConfig, path configkit.Path) []string {
|
||||
if campaign.resolution == nil || campaign.resolution.campaign == nil {
|
||||
return nil
|
||||
}
|
||||
result := campaign.resolution.campaign
|
||||
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 {
|
||||
name := source.Path
|
||||
if name == "" {
|
||||
name = source.Label
|
||||
}
|
||||
sources = append(sources, name)
|
||||
}
|
||||
}
|
||||
return nonEmptySortedStrings(sources)
|
||||
}
|
||||
|
||||
// MarshalEffectivePipeline renders the validated, normalized pipeline as one
|
||||
// deterministic YAML document. Composition declarations and runtime-only
|
||||
// resolution data are excluded. Artifact family declarations are also omitted
|
||||
@@ -188,6 +271,14 @@ func effectivePipelineOwners(cfg *PipelineConfig) (map[string][]string, error) {
|
||||
sources := []string{pipelineDefaultOwnershipSource}
|
||||
if ok {
|
||||
sources = ownershipSources(info.Origin, pathsByID)
|
||||
if info.Origin.Layer == configkit.LayerResolution {
|
||||
for _, change := range cfg.resolution.configkitMetadata.History(configkit.Keys(value.segments...)) {
|
||||
if change.Origin.Layer == configkit.LayerMain || change.Origin.Layer == configkit.LayerOverlay {
|
||||
sources = append(sources, ownershipSources(change.Origin, pathsByID)...)
|
||||
}
|
||||
}
|
||||
sources = nonEmptySortedStrings(sources)
|
||||
}
|
||||
}
|
||||
owners[value.record.Path] = sources
|
||||
}
|
||||
@@ -247,8 +338,10 @@ func appendGeneratedArtifactSources(records []EffectivePipelineSourceRecord, pat
|
||||
}
|
||||
records = append(records, EffectivePipelineSourceRecord{Path: path, Role: role, Source: normalizedProvenanceSource(source)})
|
||||
}
|
||||
if source := normalizedProvenancePath(party.Source.Path); source != "" {
|
||||
records = append(records, EffectivePipelineSourceRecord{Path: path, Role: "party", Source: source})
|
||||
memberPath := strings.TrimPrefix(path, "scriptorium.artifacts.")
|
||||
memberKey, _, _ := strings.Cut(memberPath, ".")
|
||||
for _, source := range partyCharacterSources(party, families.Members[memberKey].CharacterID) {
|
||||
records = append(records, EffectivePipelineSourceRecord{Path: path, Role: "party", Source: normalizedProvenancePath(source)})
|
||||
}
|
||||
return records
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ const (
|
||||
// CanonicalParty is the normalized domain value for narratio.party.v1.
|
||||
type CanonicalParty struct {
|
||||
Characters []PartyCharacter
|
||||
authoring *configkit.Result[partyDocument]
|
||||
}
|
||||
|
||||
// PartyCharacter is one ordered character declaration from a canonical party.
|
||||
@@ -244,7 +245,7 @@ func canonicalPartyFromResult(result *configkit.Result[partyDocument]) *Canonica
|
||||
}
|
||||
return ordered[left].id < ordered[right].id
|
||||
})
|
||||
party := &CanonicalParty{Characters: make([]PartyCharacter, 0, len(ordered))}
|
||||
party := &CanonicalParty{Characters: make([]PartyCharacter, 0, len(ordered)), authoring: result}
|
||||
for _, orderedCharacter := range ordered {
|
||||
input := result.Config.Characters[orderedCharacter.id]
|
||||
classes := make([]PartyClass, len(input.Character.Classes))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -97,4 +98,13 @@ func TestImportedPartyExpandsFamilyIdentities(t *testing.T) {
|
||||
t.Fatalf("missing family member %q", id)
|
||||
}
|
||||
}
|
||||
catalog, err := EffectiveArtifactCatalog(cfg.Pipeline, cfg.Party)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, item := range catalog {
|
||||
if strings.HasPrefix(item.Key, "character_meta_") && !strings.Contains(item.PartySource, filepath.Join(dir, "roster.yml")) {
|
||||
t.Fatalf("catalog party source = %q", item.PartySource)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ type pipelineResolutionMetadata struct {
|
||||
configkitMetadata configkit.Metadata
|
||||
configkitSources []configkit.SourceInfo
|
||||
inspection *configkit.Result[effectivePipelineProjection]
|
||||
authoring *configkit.Result[PipelineConfig]
|
||||
}
|
||||
|
||||
type pipelineOverlaySelection struct {
|
||||
@@ -275,7 +276,7 @@ func validatePipelineConfigKit(cfg *PipelineConfig, validation *configkit.Valida
|
||||
func pipelineMetadataFromConfigKit(result *configkit.Result[PipelineConfig], opts PipelineLoadOptions) *pipelineResolutionMetadata {
|
||||
sources := result.Sources()
|
||||
resolved := &pipelineResolutionMetadata{
|
||||
configkitMetadata: result.Metadata(), configkitSources: sources,
|
||||
configkitMetadata: result.Metadata(), configkitSources: sources, authoring: result,
|
||||
}
|
||||
for index, source := range sources {
|
||||
path := source.Path
|
||||
@@ -356,6 +357,11 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user