Use native configuration diff and source evidence
This commit is contained in:
12
docs/cli.md
12
docs/cli.md
@@ -117,8 +117,10 @@ family declarations, and runtime provenance.
|
||||
effective values. Its header identifies the root, ordered imports, selected
|
||||
overlay and its file, selected campaign, party source, and digest. The
|
||||
remaining tab-separated records are sorted as `path`, `role`, and `source`.
|
||||
Roles distinguish root, import, overlay, centralized default, campaign, party,
|
||||
and generated family ownership. A generated party member has
|
||||
Roles distinguish root, import, overlay, normalization, centralized default,
|
||||
campaign, party, and generated family ownership. Records labeled
|
||||
`empty_import` identify the source-local declaration path, selector, and
|
||||
location of an optional import that selected no sources. A generated party member has
|
||||
one family record and one party record at the same logical path. The output
|
||||
never reads or prints secret values.
|
||||
|
||||
@@ -151,8 +153,10 @@ removed <path> <left-value>
|
||||
changed <path> <left-value> <right-value>
|
||||
```
|
||||
|
||||
Mappings are flattened to their logical field paths; lists remain one atomic
|
||||
value. The command compares defaulted concrete artifacts and publish rules, not
|
||||
Paths use JSON Pointer notation, with `~0` for `~` and `~1` for `/`. Native
|
||||
comparison reports a changed mapping region as one value when a whole mapping
|
||||
is added or removed; lists are compared as whole values. A `hidden_changed=true`
|
||||
field indicates a change hidden by redaction. The command compares defaulted concrete artifacts and publish rules, not
|
||||
overlay names, source-file layout, or formatting. It succeeds when differences
|
||||
are found, making it suitable for review and migration checks.
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ Test final family/publish expansion, inherited/expanded equivalence, large
|
||||
integer variables, null/empty values, safe rendering, credential-reference
|
||||
changes versus rotation, and no credential resolution during snapshot creation.
|
||||
|
||||
## Stage 9: Adopt native diff and truthful operator source inspection
|
||||
## Stage 9: Adopt native diff and truthful operator source inspection [x]
|
||||
|
||||
Read `internal/app/config_diff.go`, config command loaders/tests,
|
||||
`artifact_catalog.go`, and native Diff/source/history contracts.
|
||||
|
||||
@@ -272,7 +272,7 @@ func TestAssembledSplitBundleCommandsUseOneEffectiveFamilyConfiguration(t *testi
|
||||
}, &diff); err != nil {
|
||||
t.Fatalf("compare profiles: %v", err)
|
||||
}
|
||||
if !strings.Contains(diff.String(), "audita.proposal_profile") || !strings.Contains(diff.String(), "character_items_arannis.profile_id") {
|
||||
if !strings.Contains(diff.String(), "/audita/proposal_profile") || !strings.Contains(diff.String(), "/character_items_arannis/profile_id") {
|
||||
t.Fatalf("profile diff = %q, want proposal profile and expanded family changes", diff.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +140,11 @@ func configSourcesWithDependencies(_ context.Context, args []string, out io.Writ
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, selection := range config.EffectiveEmptyImports(resolved.Pipeline, resolved.Campaign) {
|
||||
if _, err := fmt.Fprintf(out, "empty_import\t%s\t%s\t%s:%d:%d\n", selection.Path, selection.Selector, selection.Source, selection.Line, selection.Column); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -186,24 +186,24 @@ scriptorium:
|
||||
}
|
||||
output := first.String()
|
||||
for _, want := range []string{
|
||||
"changed\taudita.modules\t[\"glossary\",\"grammar\"]\t[]\n",
|
||||
"changed\tworkspace.cleanup_after_publish\ttrue\tfalse\n",
|
||||
"changed\twhisperx.language\t\"en\"\t\"fr\"\n",
|
||||
"removed\tscriptorium.artifacts.production_only.enabled\tfalse\n",
|
||||
"added\tscriptorium.artifacts.testing_only.enabled\tfalse\n",
|
||||
"changed\t/audita/modules\t[\"glossary\",\"grammar\"]\t[]\n",
|
||||
"changed\t/workspace/cleanup_after_publish\ttrue\tfalse\n",
|
||||
"changed\t/whisperx/language\t\"en\"\t\"fr\"\n",
|
||||
"removed\t/scriptorium/artifacts/production_only\t{",
|
||||
"added\t/scriptorium/artifacts/testing_only\t{",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("diff output missing %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
if strings.Index(output, "audita.modules") > strings.Index(output, "workspace.cleanup_after_publish") {
|
||||
if strings.Index(output, "/audita/modules") > strings.Index(output, "/workspace/cleanup_after_publish") {
|
||||
t.Fatalf("diff records are not sorted by path:\n%s", output)
|
||||
}
|
||||
var reversed bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"testing", "production", "--config", pipelinePath}, &reversed); err != nil {
|
||||
t.Fatalf("reversed ConfigDiff() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(reversed.String(), "changed\twhisperx.language\t\"fr\"\t\"en\"\n") {
|
||||
if !strings.Contains(reversed.String(), "changed\t/whisperx/language\t\"fr\"\t\"en\"\n") {
|
||||
t.Fatalf("reversed diff did not independently resolve overlays:\n%s", reversed.String())
|
||||
}
|
||||
}
|
||||
@@ -249,8 +249,8 @@ scriptorium:
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"changed\taudita.modules\tnull\t[]\n",
|
||||
"changed\tscriptorium.artifacts\tnull\t{}\n",
|
||||
"changed\t/audita/modules\tnull\t[]\n",
|
||||
"changed\t/scriptorium/artifacts\tnull\t{}\n",
|
||||
} {
|
||||
if !strings.Contains(diff.String(), want) {
|
||||
t.Fatalf("diff output missing %q:\n%s", want, diff.String())
|
||||
@@ -289,9 +289,9 @@ func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) {
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"changed\tscriptorium.artifacts.character_note_arannis.enabled\tfalse\ttrue\n",
|
||||
"changed\tscriptorium.artifacts.character_note_arannis.vars.character_name\t\"Arannis\"\t\"wizard\"\n",
|
||||
"changed\tpublish.outputs\t",
|
||||
"changed\t/scriptorium/artifacts/character_note_arannis/enabled\tfalse\ttrue\n",
|
||||
"changed\t/scriptorium/artifacts/character_note_arannis/vars/character_name\t\"Arannis\"\t\"wizard\"\n",
|
||||
"changed\t/publish/outputs\t",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("family diff output missing %q:\n%s", want, output)
|
||||
@@ -486,7 +486,7 @@ func TestConfigCommandsInspectMaintainedSplitBundleWithoutRuntimeState(t *testin
|
||||
if err := ConfigDiff(context.Background(), []string{"default", "testing", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil {
|
||||
t.Fatalf("ConfigDiff() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(diff.String(), "audita.proposal_profile") {
|
||||
if !strings.Contains(diff.String(), "/audita/proposal_profile") {
|
||||
t.Fatalf("split bundle overlay diff = %q, want proposal profile change", diff.String())
|
||||
}
|
||||
if _, err := os.Stat(workspacePath); !os.IsNotExist(err) {
|
||||
|
||||
@@ -2,14 +2,16 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type configDiffFlags struct {
|
||||
@@ -30,13 +32,6 @@ type configDiffResolved struct {
|
||||
right *inspectionConfig
|
||||
}
|
||||
|
||||
type configDiffRecord struct {
|
||||
Kind string
|
||||
Path string
|
||||
Left string
|
||||
Right string
|
||||
}
|
||||
|
||||
// ConfigDiff compares two explicitly selected overlays through the same
|
||||
// read-only configuration resolution boundary used by config validate, show,
|
||||
// and sources. Differences describe normalized effective values rather than
|
||||
@@ -57,43 +52,42 @@ func configDiffWithDependencies(_ context.Context, args []string, out io.Writer,
|
||||
if err != nil {
|
||||
return fmt.Errorf("config diff: %w", err)
|
||||
}
|
||||
leftValues, err := config.EffectivePipelineValues(resolved.left.Pipeline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config diff: project left effective configuration: %w", err)
|
||||
}
|
||||
rightValues, err := config.EffectivePipelineValues(resolved.right.Pipeline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config diff: project right effective configuration: %w", err)
|
||||
}
|
||||
records, err := diffEffectivePipelineValues(leftValues, rightValues)
|
||||
differences, err := config.DiffEffectivePipelines(resolved.left.Pipeline, resolved.right.Pipeline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("config diff: %w", err)
|
||||
}
|
||||
leftDigest := config.EffectivePipelineDigest(resolved.left.Pipeline)
|
||||
rightDigest := config.EffectivePipelineDigest(resolved.right.Pipeline)
|
||||
if len(records) == 0 {
|
||||
if leftDigest != rightDigest {
|
||||
return fmt.Errorf("internal error: effective pipeline digests differ without a semantic difference")
|
||||
}
|
||||
if len(differences) == 0 {
|
||||
_, err := fmt.Fprintln(out, "no differences")
|
||||
return err
|
||||
}
|
||||
for _, record := range records {
|
||||
switch record.Kind {
|
||||
case "added":
|
||||
if _, err := fmt.Fprintf(out, "added\t%s\t%s\n", record.Path, record.Right); err != nil {
|
||||
for _, difference := range differences {
|
||||
kind := "changed"
|
||||
if !difference.Left.Present {
|
||||
kind = "added"
|
||||
}
|
||||
if !difference.Right.Present {
|
||||
kind = "removed"
|
||||
}
|
||||
fields := []string{kind, difference.Path.String()}
|
||||
if difference.Left.Present {
|
||||
value, err := compactSnapshot(difference.Left)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "removed":
|
||||
if _, err := fmt.Fprintf(out, "removed\t%s\t%s\n", record.Path, record.Left); err != nil {
|
||||
fields = append(fields, value)
|
||||
}
|
||||
if difference.Right.Present {
|
||||
value, err := compactSnapshot(difference.Right)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "changed":
|
||||
if _, err := fmt.Fprintf(out, "changed\t%s\t%s\t%s\n", record.Path, record.Left, record.Right); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("internal error: unsupported difference kind %q", record.Kind)
|
||||
fields = append(fields, value)
|
||||
}
|
||||
if difference.HiddenChanged {
|
||||
fields = append(fields, "hidden_changed=true")
|
||||
}
|
||||
if _, err := fmt.Fprintln(out, strings.Join(fields, "\t")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -264,50 +258,14 @@ func resolveSharedDiffCampaignPath(left, right *config.PipelineConfig, flags con
|
||||
return leftPath, nil
|
||||
}
|
||||
|
||||
func diffEffectivePipelineValues(left, right []config.EffectivePipelineValueRecord) ([]configDiffRecord, error) {
|
||||
leftByPath, err := effectivePipelineValueMap("left", left)
|
||||
func compactSnapshot(snapshot configkit.ValueSnapshot) (string, error) {
|
||||
var value any
|
||||
if err := yaml.Unmarshal([]byte(snapshot.YAML), &value); err != nil {
|
||||
return "", fmt.Errorf("decode safe diff value: %w", err)
|
||||
}
|
||||
encoded, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", fmt.Errorf("encode safe diff value: %w", err)
|
||||
}
|
||||
rightByPath, err := effectivePipelineValueMap("right", right)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paths := make([]string, 0, len(leftByPath)+len(rightByPath))
|
||||
seen := make(map[string]struct{}, len(leftByPath)+len(rightByPath))
|
||||
for path := range leftByPath {
|
||||
seen[path] = struct{}{}
|
||||
paths = append(paths, path)
|
||||
}
|
||||
for path := range rightByPath {
|
||||
if _, exists := seen[path]; !exists {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
}
|
||||
sort.Strings(paths)
|
||||
records := make([]configDiffRecord, 0)
|
||||
for _, path := range paths {
|
||||
leftValue, leftExists := leftByPath[path]
|
||||
rightValue, rightExists := rightByPath[path]
|
||||
switch {
|
||||
case !leftExists:
|
||||
records = append(records, configDiffRecord{Kind: "added", Path: path, Right: rightValue})
|
||||
case !rightExists:
|
||||
records = append(records, configDiffRecord{Kind: "removed", Path: path, Left: leftValue})
|
||||
case leftValue != rightValue:
|
||||
records = append(records, configDiffRecord{Kind: "changed", Path: path, Left: leftValue, Right: rightValue})
|
||||
}
|
||||
}
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func effectivePipelineValueMap(side string, records []config.EffectivePipelineValueRecord) (map[string]string, error) {
|
||||
values := make(map[string]string, len(records))
|
||||
for _, record := range records {
|
||||
if _, exists := values[record.Path]; exists {
|
||||
return nil, fmt.Errorf("internal error: %s effective configuration has duplicate path %q", side, record.Path)
|
||||
}
|
||||
values[record.Path] = record.Value
|
||||
}
|
||||
return values, nil
|
||||
return string(encoded), nil
|
||||
}
|
||||
|
||||
40
internal/app/config_native_inspection_test.go
Normal file
40
internal/app/config_native_inspection_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigDiffUsesEscapedPointersAndAtomicLists(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, root, "whisperx: {transcribe_url: 'https://example.test/transcribe'}\nscriptorium:\n artifacts:\n recap:\n enabled: false\n output_path: artifacts/recap.md\n vars: {'a/b~c': before}\naudita: {modules: [glossary, grammar]}\n")
|
||||
mustWriteTestFile(t, filepath.Join(dir, "overlays", "changed.yml"), "scriptorium:\n artifacts:\n recap:\n vars: {'a/b~c': after}\naudita: {modules: [glossary, homophones]}\n")
|
||||
var output bytes.Buffer
|
||||
if err := ConfigDiff(context.Background(), []string{"default", "changed", "--config", root}, &output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"changed\t/audita/modules\t[\"glossary\",\"grammar\"]\t[\"glossary\",\"homophones\"]", "changed\t/scriptorium/artifacts/recap/vars/a~1b~0c\t\"before\"\t\"after\""} {
|
||||
if !strings.Contains(output.String(), want) {
|
||||
t.Fatalf("diff lacks %q: %s", want, output.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSourcesReportsEmptyOptionalImportAndNormalization(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, root, "config:\n imports:\n - path: absent.yml\nworkspace: {root: ./work}\nwhisperx: {transcribe_url: 'https://example.test/transcribe'}\n")
|
||||
var output bytes.Buffer
|
||||
if err := ConfigSources(context.Background(), []string{"--config", root}, &output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{"empty_import\t/config/imports/0\tpath\t" + root, "workspace.root\tresolution\tresolution", "workspace.root\troot\t" + root} {
|
||||
if !strings.Contains(output.String(), want) {
|
||||
t.Fatalf("sources lack %q: %s", want, output.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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