Expose safe inheritance origins in explanations

This commit is contained in:
2026-10-03 17:19:05 +00:00
parent 1cfe0c5a01
commit b64010e729
5 changed files with 100 additions and 7 deletions

View File

@@ -61,11 +61,17 @@ type derivationView struct {
Reason string `yaml:"reason"`
Dependencies []string `yaml:"dependencies,omitempty"`
}
type inheritanceStepView struct {
From string `yaml:"from"`
To string `yaml:"to"`
Reference string `yaml:"reference"`
}
type explanationView struct {
Path string `yaml:"path"`
Source string `yaml:"source"`
Layer ck.Layer `yaml:"layer"`
Derivations []derivationView `yaml:"derivations,omitempty"`
Path string `yaml:"path"`
Source string `yaml:"source"`
Layer ck.Layer `yaml:"layer"`
Derivations []derivationView `yaml:"derivations,omitempty"`
Inheritance []inheritanceStepView `yaml:"inheritance,omitempty"`
}
// ExplanationYAML reports only origins and recorded resolution operations.
@@ -93,6 +99,11 @@ func ExplanationYAML(result *ck.Result[config.Config]) ([]byte, error) {
continue
}
record := explanationView{Path: path.String(), Layer: info.Origin.Layer, Source: string(info.Origin.Layer)}
for _, step := range info.Origin.Inheritance {
record.Inheritance = append(record.Inheritance, inheritanceStepView{
From: step.From.String(), To: step.To.String(), Reference: step.Reference.String(),
})
}
if len(info.Origin.Locations) > 0 {
if label := sources[info.Origin.Locations[0].SourceID]; label != "" {
record.Source = label