Use native configuration diff and source evidence
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user