Preserve derived publication and preparation evidence
This commit is contained in:
@@ -29,6 +29,14 @@ func (cfg *Config) ConcreteArtifacts() map[string]ScriptoriumArtifactConfig {
|
||||
return cfg.ArtifactCatalog.Artifacts
|
||||
}
|
||||
|
||||
// PublicationOutputs returns publication actions derived for the selected roster.
|
||||
func (cfg *Config) PublicationOutputs() []PublishOutputRule {
|
||||
if cfg == nil || cfg.ArtifactCatalog == nil {
|
||||
return nil
|
||||
}
|
||||
return cfg.ArtifactCatalog.PublishOutputs
|
||||
}
|
||||
|
||||
// PipelineConfig contains durable pipeline-level settings.
|
||||
type PipelineConfig struct {
|
||||
Workspace WorkspaceConfig `yaml:"workspace" json:"workspace"`
|
||||
|
||||
@@ -46,37 +46,26 @@ func finalizePipelineResolution(cfg *PipelineConfig) error {
|
||||
return recomputePipelineEffectiveDigest(cfg)
|
||||
}
|
||||
|
||||
// recomputePipelineEffectiveDigest is the single package-owned hook for
|
||||
// refreshing provenance after later resolution expands concrete pipeline
|
||||
// values. Loader directives and runtime provenance are not serialized.
|
||||
// recomputePipelineEffectiveDigest records informational configuration identity.
|
||||
// Derived domain products are not part of this configuration projection.
|
||||
func recomputePipelineEffectiveDigest(cfg *PipelineConfig) error {
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
return fmt.Errorf("pipeline resolution metadata is required")
|
||||
}
|
||||
snapshot, err := newPipelineInspection(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
canonical, err := projectionJSON(snapshot.Config)
|
||||
canonical, err := projectionJSON(projectEffectivePipeline(cfg))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
digestInput := append([]byte(effectivePipelineDigestVersion), canonical...)
|
||||
digest := sha256.Sum256(digestInput)
|
||||
cfg.resolution.effectiveDigest = hex.EncodeToString(digest[:])
|
||||
cfg.resolution.inspection = snapshot
|
||||
return nil
|
||||
}
|
||||
|
||||
func newPipelineInspection(cfg *PipelineConfig) (*configkit.Result[effectivePipelineProjection], error) {
|
||||
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.
|
||||
// DiffEffectivePipelines compares the authoritative native load results.
|
||||
func DiffEffectivePipelines(left, right *PipelineConfig) ([]configkit.Difference, error) {
|
||||
if left == nil || right == nil || left.resolution == nil || right.resolution == nil {
|
||||
if left == nil || right == nil || left.ConfigKitResult() == nil || right.ConfigKitResult() == nil {
|
||||
return nil, fmt.Errorf("resolved pipelines are required")
|
||||
}
|
||||
return configkit.Diff(left.resolution.inspection, right.resolution.inspection)
|
||||
return configkit.Diff(left.ConfigKitResult(), right.ConfigKitResult())
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// EffectivePipelineRootPath reports the absolute root pipeline path retained
|
||||
@@ -218,31 +218,33 @@ func campaignDefinitionSources(campaign *CampaignConfig, path configkit.Path) []
|
||||
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
|
||||
// because a resolved pipeline exposes their concrete artifacts instead.
|
||||
// MarshalEffectivePipeline materializes completed configuration for persistence.
|
||||
// Credentials retain reference names; domain catalogs remain separate.
|
||||
func MarshalEffectivePipeline(cfg *PipelineConfig) ([]byte, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("pipeline config is required")
|
||||
}
|
||||
|
||||
var snapshot *configkit.Result[effectivePipelineProjection]
|
||||
if cfg.resolution != nil {
|
||||
snapshot = cfg.resolution.inspection
|
||||
canonical, err := projectionJSON(projectEffectivePipeline(cfg))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if snapshot == nil {
|
||||
var err error
|
||||
snapshot, err = newPipelineInspection(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var document yaml.Node
|
||||
if err := yaml.Unmarshal(canonical, &document); err != nil {
|
||||
return nil, fmt.Errorf("decode pipeline materialization: %w", err)
|
||||
}
|
||||
var blockStyle func(*yaml.Node)
|
||||
blockStyle = func(node *yaml.Node) {
|
||||
node.Style = 0
|
||||
for _, child := range node.Content {
|
||||
blockStyle(child)
|
||||
}
|
||||
}
|
||||
var output bytes.Buffer
|
||||
if err := snapshot.WriteEffective(&output); err != nil {
|
||||
blockStyle(&document)
|
||||
output, err := yaml.Marshal(&document)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("serialize effective pipeline: %w", err)
|
||||
}
|
||||
return output.Bytes(), nil
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func effectivePipelineOwners(cfg *PipelineConfig) (map[string][]string, error) {
|
||||
|
||||
@@ -8,9 +8,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// effectivePipelineProjection is the single safe, schema-specific view used
|
||||
// for inspection, comparison, and identity. Runtime metadata and unresolved
|
||||
// family declarations have no slot in this type.
|
||||
// effectivePipelineProjection safely materializes configuration for persistence
|
||||
// and informational identity. Native results own inspection and comparison.
|
||||
type effectivePipelineProjection struct {
|
||||
Workspace WorkspaceConfig `yaml:"workspace" json:"workspace"`
|
||||
Campaigns CampaignsConfig `yaml:"campaigns" json:"campaigns"`
|
||||
@@ -70,12 +69,13 @@ type effectiveNotariusConfig struct {
|
||||
}
|
||||
|
||||
type effectiveScriptoriumConfig struct {
|
||||
Credentials []string `yaml:"credentials" json:"credentials"`
|
||||
Binary string `yaml:"binary" json:"binary"`
|
||||
ConfigPath string `yaml:"config_path" json:"config_path"`
|
||||
Timeout string `yaml:"timeout" json:"timeout"`
|
||||
RenderDebug bool `yaml:"render_debug" json:"render_debug"`
|
||||
Artifacts map[string]ScriptoriumArtifactConfig `yaml:"artifacts" json:"artifacts"`
|
||||
ArtifactFamilies map[string]ScriptoriumArtifactFamilyConfig `yaml:"artifact_families,omitempty" json:"artifact_families,omitempty"`
|
||||
Credentials []string `yaml:"credentials" json:"credentials"`
|
||||
Binary string `yaml:"binary" json:"binary"`
|
||||
ConfigPath string `yaml:"config_path" json:"config_path"`
|
||||
Timeout string `yaml:"timeout" json:"timeout"`
|
||||
RenderDebug bool `yaml:"render_debug" json:"render_debug"`
|
||||
Artifacts map[string]ScriptoriumArtifactConfig `yaml:"artifacts" json:"artifacts"`
|
||||
}
|
||||
|
||||
type projectedPipelineValue struct {
|
||||
@@ -104,7 +104,8 @@ func projectEffectivePipeline(cfg *PipelineConfig) effectivePipelineProjection {
|
||||
Credentials: secretReferenceNames(cfg.Scriptorium.Credentials),
|
||||
Binary: cfg.Scriptorium.Binary, ConfigPath: cfg.Scriptorium.ConfigPath,
|
||||
Timeout: cfg.Scriptorium.Timeout, RenderDebug: cfg.Scriptorium.RenderDebug,
|
||||
Artifacts: cfg.Scriptorium.Artifacts,
|
||||
Artifacts: cfg.Scriptorium.Artifacts,
|
||||
ArtifactFamilies: cfg.Scriptorium.ArtifactFamilies,
|
||||
}
|
||||
}
|
||||
return projection
|
||||
|
||||
@@ -6,13 +6,18 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInspectionSnapshotPreservesFinalValuesWithoutResolvingCredentialsAgain(t *testing.T) {
|
||||
func TestPipelineMaterializationPreservesFinalValuesWithoutResolvingCredentialsAgain(t *testing.T) {
|
||||
const name = "NARRATIO_SNAPSHOT_TEST_KEY"
|
||||
const secret = "synthetic-snapshot-secret"
|
||||
t.Setenv(name, secret)
|
||||
path := writePipelineFixture(t, t.TempDir(), "pipeline.yml", `audita:
|
||||
credentials: [NARRATIO_SNAPSHOT_TEST_KEY]
|
||||
scriptorium:
|
||||
artifact_families:
|
||||
character_notes:
|
||||
enabled: false
|
||||
for_each: party.characters
|
||||
output_path_pattern: artifacts/{character_id}.md
|
||||
artifacts:
|
||||
recap:
|
||||
vars:
|
||||
@@ -24,9 +29,6 @@ scriptorium:
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
artifact := cfg.Scriptorium.Artifacts["recap"]
|
||||
artifact.Vars["config"] = map[string]any{"extends": "ordinary-data"}
|
||||
cfg.Scriptorium.Artifacts["recap"] = artifact
|
||||
if err := os.Unsetenv(name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -37,7 +39,7 @@ scriptorium:
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, expected := range []string{name, "9007199254740993", "ordinary-data", "nothing: null", "empty: []"} {
|
||||
for _, expected := range []string{name, "9007199254740993", "nothing: null", "empty: []", "character_notes:", "artifact_families:"} {
|
||||
if !strings.Contains(string(data), expected) {
|
||||
t.Fatalf("snapshot missing %q: %s", expected, data)
|
||||
}
|
||||
@@ -47,7 +49,7 @@ scriptorium:
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectionSnapshotKeepsEmptyCredentialListDistinctFromNull(t *testing.T) {
|
||||
func TestPipelineMaterializationKeepsEmptyCredentialListDistinctFromNull(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
nullPath := writePipelineFixture(t, dir, "null.yml", "audita: {credentials: null}\n")
|
||||
emptyPath := writePipelineFixture(t, dir, "empty.yml", "audita: {credentials: []}\n")
|
||||
|
||||
@@ -18,7 +18,6 @@ type pipelineResolutionMetadata struct {
|
||||
sources []string
|
||||
selectedOverlay *pipelineOverlaySelection
|
||||
effectiveDigest string
|
||||
inspection *configkit.Result[effectivePipelineProjection]
|
||||
authoring *configkit.Result[PipelineConfig]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user