Retain authoritative pipeline and campaign load results
This commit is contained in:
@@ -127,6 +127,14 @@ Construction itself performs no credential bootstrap or acquisition.
|
||||
|
||||
## Stage 2: Retain authoritative pipeline and campaign load results
|
||||
|
||||
**Completed.** Pipeline and campaign loaders expose their actual typed native
|
||||
results, retaining structured load failures and recorded resolution evidence.
|
||||
Campaign configuration checks now run in its definition lifecycle; resource
|
||||
existence remains a domain concern. Removed duplicated pipeline metadata and
|
||||
post-load dependency merging. Native result/import/overlay checks and builds
|
||||
pass with Go 1.27.4. Two existing dependency tests await the separate concrete
|
||||
catalog in Stage 4; their expectations remain intact.
|
||||
|
||||
Read: roadmap ownership; `internal/config/pipeline_configkit.go`,
|
||||
`document_configkit.go`, `load.go`, `effective_digest.go`, and the upstream
|
||||
ConfigKit sections on recorded application resolution and inspection.
|
||||
|
||||
@@ -131,11 +131,12 @@ func declarationDefinitionSources(cfg *PipelineConfig, declaration configkit.Pat
|
||||
}
|
||||
|
||||
func declarationDefinitionSourcesWithIndex(cfg *PipelineConfig, declaration configkit.Path, pathsByID map[string]string) []string {
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
if cfg.ConfigKitResult() == nil {
|
||||
return nil
|
||||
}
|
||||
metadata := cfg.ConfigKitResult().Metadata()
|
||||
seen := map[string]struct{}{}
|
||||
for _, change := range cfg.resolution.configkitMetadata.History(declaration) {
|
||||
for _, change := range metadata.History(declaration) {
|
||||
if change.Origin.Layer != configkit.LayerMain && change.Origin.Layer != configkit.LayerOverlay {
|
||||
continue
|
||||
}
|
||||
@@ -149,7 +150,7 @@ func declarationDefinitionSourcesWithIndex(cfg *PipelineConfig, declaration conf
|
||||
}
|
||||
}
|
||||
if len(seen) == 0 {
|
||||
if info, ok := cfg.resolution.configkitMetadata.Lookup(declaration); ok {
|
||||
if info, ok := metadata.Lookup(declaration); ok {
|
||||
for _, location := range info.Origin.Locations {
|
||||
seen[location.SourceID] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,15 @@ type documentResolution struct {
|
||||
sources map[string]string
|
||||
}
|
||||
|
||||
// ConfigKitResult returns the campaign's actual completed native load result.
|
||||
// Constructed campaign values have no result.
|
||||
func (cfg *CampaignConfig) ConfigKitResult() *configkit.Result[CampaignConfig] {
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
return nil
|
||||
}
|
||||
return cfg.resolution.campaign
|
||||
}
|
||||
|
||||
func documentResource(resolution *configkit.Resolution, path configkit.Path, value *string, invocationDir string, sources map[string]string) {
|
||||
if info, ok := resolution.EntryInfo(path); ok && len(info.Origin.Locations) == 1 {
|
||||
if source, ok := resolution.Source(info.Origin.Locations[0].SourceID); ok {
|
||||
@@ -45,7 +54,7 @@ func campaignDefinition(invocationDir string, sources map[string]string) configk
|
||||
documentResource(resolution, inputs.Key(field.name), field.value, invocationDir, sources)
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}, Validate: validateCampaignConfigKit}
|
||||
}
|
||||
|
||||
func sessionDefinition(invocationDir string, sources map[string]string) configkit.Definition[SessionConfig] {
|
||||
@@ -78,9 +87,9 @@ func loadCampaignWithConfigKit(path string) (*CampaignConfig, error) {
|
||||
if err != nil {
|
||||
return nil, describeConfigKitLoadError("campaign", err)
|
||||
}
|
||||
cfg := result.Config
|
||||
cfg := &result.Config
|
||||
cfg.resolution = &documentResolution{campaign: result, sources: sources}
|
||||
return &cfg, nil
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func loadSessionSource(source configkit.Source, label string, opts SessionLoadOptions, imports bool) (*SessionConfig, string, error) {
|
||||
|
||||
@@ -98,9 +98,9 @@ func TestRemoteSessionResourceBaseIgnoresDiagnosticLabel(t *testing.T) {
|
||||
|
||||
func TestEquivalentDocumentLayoutsRenderIdentically(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
firstCampaign := writePipelineFixture(t, dir, "first-campaign.yml", "campaign_id: sample\ninputs: {speakers_file: shared/speakers.yml}\n")
|
||||
firstCampaign := writePipelineFixture(t, dir, "first-campaign.yml", "campaign_id: sample\ninputs: {speakers_file: shared/speakers.yml, autocorrect_file: shared/autocorrect.yml, glossary_file: shared/glossary.yml, party_file: shared/party.yml}\n")
|
||||
secondCampaign := writePipelineFixture(t, dir, "second-campaign.yml", "config:\n imports:\n - path: shared/campaign.yml\ncampaign_id: sample\n")
|
||||
writePipelineFixture(t, dir, "shared/campaign.yml", "inputs: {speakers_file: speakers.yml}\n")
|
||||
writePipelineFixture(t, dir, "shared/campaign.yml", "inputs: {speakers_file: speakers.yml, autocorrect_file: autocorrect.yml, glossary_file: glossary.yml, party_file: party.yml}\n")
|
||||
firstSession := writePipelineFixture(t, dir, "first-session.yml", "session_id: sample\ninputs: {audio_dir: shared/audio}\n")
|
||||
secondSession := writePipelineFixture(t, dir, "second-session.yml", "config:\n imports:\n - path: shared/session.yml\nsession_id: sample\n")
|
||||
writePipelineFixture(t, dir, "shared/session.yml", "inputs: {audio_dir: audio}\n")
|
||||
|
||||
@@ -255,7 +255,7 @@ func MarshalEffectivePipeline(cfg *PipelineConfig) ([]byte, error) {
|
||||
|
||||
func effectivePipelineOwners(cfg *PipelineConfig) (map[string][]string, error) {
|
||||
owners := make(map[string][]string)
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
if cfg.ConfigKitResult() == nil {
|
||||
return owners, nil
|
||||
}
|
||||
paths, err := pipelineMetadataPaths(cfg)
|
||||
@@ -263,13 +263,14 @@ func effectivePipelineOwners(cfg *PipelineConfig) (map[string][]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
pathsByID := pipelineSourcePaths(cfg)
|
||||
metadata := cfg.ConfigKitResult().Metadata()
|
||||
for _, value := range paths {
|
||||
info, ok := cfg.resolution.configkitMetadata.Lookup(configkit.Keys(value.segments...))
|
||||
info, ok := metadata.Lookup(configkit.Keys(value.segments...))
|
||||
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...)) {
|
||||
for _, change := range metadata.History(configkit.Keys(value.segments...)) {
|
||||
if change.Origin.Layer != configkit.LayerResolution {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ func LoadPipelineOverlayPair(path, leftOverlay, rightOverlay string) (*PipelineC
|
||||
}
|
||||
|
||||
func finalizeLoadedPipeline(cfg *PipelineConfig) (*PipelineConfig, error) {
|
||||
finalizeArtifactDependencies(cfg)
|
||||
if err := finalizePipelineResolution(cfg); err != nil {
|
||||
return nil, fmt.Errorf("load pipeline config: %w", err)
|
||||
}
|
||||
|
||||
115
internal/config/native_results_test.go
Normal file
115
internal/config/native_results_test.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestNativePipelineResultOwnsCompletedConfiguration(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "pipeline.yml", `config:
|
||||
imports:
|
||||
- path: settings/resources.yml
|
||||
storage:
|
||||
backend: ' LOCAL '
|
||||
scriptorium:
|
||||
artifacts:
|
||||
recap:
|
||||
depends_on: [authored]
|
||||
inputs:
|
||||
upstream: {source: narratio.artifact.inferred}
|
||||
artifact_families:
|
||||
notes:
|
||||
for_each: party.characters
|
||||
output_path_pattern: artifacts/{character_id}.md
|
||||
`)
|
||||
writePipelineFixture(t, dir, "settings/resources.yml", "workspace: {root: work}\n")
|
||||
writePipelineFixture(t, dir, "overlays/review.yml", "workspace: {root: overlay-work}\nscriptorium: {timeout: 3m}\n")
|
||||
for _, overlay := range []*string{nil, stringPointer("review")} {
|
||||
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: overlay})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := cfg.ConfigKitResult()
|
||||
if result == nil || cfg != &result.Config {
|
||||
t.Fatal("loader did not return the retained native configuration")
|
||||
}
|
||||
wantRoot := filepath.Join(dir, "settings", "work")
|
||||
if overlay != nil {
|
||||
wantRoot = filepath.Join(dir, "overlays", "overlay-work")
|
||||
}
|
||||
if cfg.Workspace.Root != wantRoot || cfg.Storage.Backend != StorageBackendLocal || cfg.Scriptorium.Binary != DefaultScriptoriumBinary {
|
||||
t.Fatalf("completed defaults/normalization: root=%q backend=%q binary=%q", cfg.Workspace.Root, cfg.Storage.Backend, cfg.Scriptorium.Binary)
|
||||
}
|
||||
if len(cfg.Scriptorium.ArtifactFamilies) != 1 || len(cfg.Scriptorium.Artifacts) != 1 || !reflect.DeepEqual(cfg.Scriptorium.Artifacts["recap"].DependsOn, []string{"authored"}) {
|
||||
t.Fatal("pipeline loading derived a domain catalog or rewrote authored dependencies")
|
||||
}
|
||||
var output bytes.Buffer
|
||||
if err := result.WriteEffective(&output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var shown PipelineConfig
|
||||
if err := yaml.Unmarshal(output.Bytes(), &shown); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if shown.Workspace != cfg.Workspace || shown.Storage.Backend != cfg.Storage.Backend || !reflect.DeepEqual(shown.Scriptorium, cfg.Scriptorium) {
|
||||
t.Fatalf("native show differs from completed configuration: %s", output.String())
|
||||
}
|
||||
for _, path := range []configkit.Path{configkit.Keys("workspace", "root"), configkit.Keys("storage", "backend"), configkit.Keys("scriptorium", "binary")} {
|
||||
explanation, ok := result.Explain(path)
|
||||
if !ok || len(explanation.History) == 0 {
|
||||
t.Fatalf("missing native resolution evidence for %v", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeCampaignResultValidatesConfigurationWithoutReadingResources(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: settings/defaults.yml\ncampaign_id: sample\n")
|
||||
writePipelineFixture(t, dir, "settings/defaults.yml", `inputs:
|
||||
speakers_file: speakers.yml
|
||||
autocorrect_file: autocorrect.yml
|
||||
glossary_file: glossary.yml
|
||||
party_file: party.yml
|
||||
`)
|
||||
cfg, err := LoadCampaign(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := cfg.ConfigKitResult()
|
||||
if result == nil || cfg != &result.Config || len(result.Sources()) != 2 {
|
||||
t.Fatal("campaign did not retain its original load and imported source")
|
||||
}
|
||||
if cfg.Inputs.PartyFile != filepath.Join(dir, "settings", "party.yml") {
|
||||
t.Fatalf("party resource base = %q", cfg.Inputs.PartyFile)
|
||||
}
|
||||
var output bytes.Buffer
|
||||
if err := result.WriteEffective(&output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var shown CampaignConfig
|
||||
if err := yaml.Unmarshal(output.Bytes(), &shown); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if shown.CampaignID != cfg.CampaignID || shown.Inputs != cfg.Inputs {
|
||||
t.Fatal("native show lost completed campaign values")
|
||||
}
|
||||
|
||||
invalid := writePipelineFixture(t, dir, "invalid.yml", "campaign_id: sample\n")
|
||||
_, err = LoadCampaign(invalid)
|
||||
var loadError *configkit.LoadError
|
||||
if !errors.As(err, &loadError) {
|
||||
t.Fatalf("campaign validation lost its native error: %v", err)
|
||||
}
|
||||
findings := loadError.Diagnostics()
|
||||
if len(findings) == 0 || findings[0].Code != configkit.CodeValidateError || findings[0].Path.String() != "/inputs/speakers_file" {
|
||||
t.Fatalf("campaign validation findings = %+v", findings)
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,19 @@ type pipelineResolutionMetadata struct {
|
||||
effectiveDigest string
|
||||
artifactFamilies map[string]ScriptoriumArtifactFamilyConfig
|
||||
artifactFamiliesExpanded bool
|
||||
configkitMetadata configkit.Metadata
|
||||
configkitSources []configkit.SourceInfo
|
||||
inspection *configkit.Result[effectivePipelineProjection]
|
||||
authoring *configkit.Result[PipelineConfig]
|
||||
}
|
||||
|
||||
// ConfigKitResult returns the authoritative native load result. Callers consume
|
||||
// its completed configuration without mutation. Constructed values have no result.
|
||||
func (cfg *PipelineConfig) ConfigKitResult() *configkit.Result[PipelineConfig] {
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
return nil
|
||||
}
|
||||
return cfg.resolution.authoring
|
||||
}
|
||||
|
||||
type pipelineOverlaySelection struct {
|
||||
name string
|
||||
source string
|
||||
@@ -46,9 +53,9 @@ func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*Pipeline
|
||||
if err != nil {
|
||||
return nil, describePipelineLoadError(err)
|
||||
}
|
||||
cfg := result.Config
|
||||
cfg := &result.Config
|
||||
cfg.resolution = pipelineMetadataFromConfigKit(result, opts)
|
||||
return &cfg, nil
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func loadPipelineConfigKitResult(source configkit.Source, overlay string) (*configkit.Result[PipelineConfig], error) {
|
||||
@@ -263,9 +270,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, authoring: result,
|
||||
}
|
||||
resolved := &pipelineResolutionMetadata{authoring: result}
|
||||
for index, source := range sources {
|
||||
path := source.Path
|
||||
if path == "" {
|
||||
@@ -341,10 +346,10 @@ func ownershipSources(origin configkit.Origin, pathsByID map[string]string) []st
|
||||
|
||||
func pipelineSourcePaths(cfg *PipelineConfig) map[string]string {
|
||||
paths := make(map[string]string)
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
if cfg.ConfigKitResult() == nil {
|
||||
return paths
|
||||
}
|
||||
for _, source := range cfg.resolution.configkitSources {
|
||||
for _, source := range cfg.ConfigKitResult().Sources() {
|
||||
path := source.Path
|
||||
if path == "" {
|
||||
path = source.Label
|
||||
|
||||
@@ -252,7 +252,7 @@ whisperx:
|
||||
t.Fatalf("absent Scriptorium timeout = %q, want default %q", cfg.Scriptorium.Timeout, DefaultScriptoriumTimeout)
|
||||
}
|
||||
|
||||
metadata := cfg.resolution.configkitMetadata
|
||||
metadata := cfg.ConfigKitResult().Metadata()
|
||||
for _, path := range []configkit.Path{
|
||||
configkit.Keys("scriptorium", "artifacts", "inherited", "render_debug"),
|
||||
configkit.Keys("scriptorium", "artifacts", "inherited", "vars", "empty"),
|
||||
@@ -305,7 +305,7 @@ whisperx:
|
||||
if got := cfg.Scriptorium.Artifacts["child"].Timeout; got != "0s" {
|
||||
t.Fatalf("inherited zero timeout = %q, want 0s", got)
|
||||
}
|
||||
if !cfg.resolution.configkitMetadata.IsExplicit(configkit.Keys("scriptorium", "artifacts", "child", "timeout")) {
|
||||
if !cfg.ConfigKitResult().Metadata().IsExplicit(configkit.Keys("scriptorium", "artifacts", "child", "timeout")) {
|
||||
t.Fatal("inherited zero timeout is not marked explicit")
|
||||
}
|
||||
if err := ValidatePipelineConfig(cfg); err == nil || !strings.Contains(err.Error(), "timeout must be positive") {
|
||||
@@ -330,7 +330,7 @@ whisperx:
|
||||
if cfg.Scriptorium.Timeout != "" {
|
||||
t.Fatalf("explicit empty Scriptorium timeout = %q, want empty", cfg.Scriptorium.Timeout)
|
||||
}
|
||||
if !cfg.resolution.configkitMetadata.IsExplicit(configkit.Keys("scriptorium", "timeout")) {
|
||||
if !cfg.ConfigKitResult().Metadata().IsExplicit(configkit.Keys("scriptorium", "timeout")) {
|
||||
t.Fatal("explicit empty Scriptorium timeout is not marked explicit")
|
||||
}
|
||||
if err := ValidatePipelineConfig(cfg); err != nil {
|
||||
|
||||
@@ -17,13 +17,13 @@ func TestPublishFieldResolutionPreservesUnchangedSourceHistory(t *testing.T) {
|
||||
t.Fatalf("missing resolved defaults: %#v", output)
|
||||
}
|
||||
base := configkit.Keys("publish", "outputs").Index(0)
|
||||
for _, change := range cfg.resolution.configkitMetadata.History(base.Key("source")) {
|
||||
for _, change := range cfg.ConfigKitResult().Metadata().History(base.Key("source")) {
|
||||
if change.Origin.Layer == configkit.LayerResolution {
|
||||
t.Fatalf("untouched source has resolution history: %#v", change)
|
||||
}
|
||||
}
|
||||
for _, field := range []string{"required", "dest"} {
|
||||
info, ok := cfg.resolution.configkitMetadata.Lookup(base.Key(field))
|
||||
info, ok := cfg.ConfigKitResult().Metadata().Lookup(base.Key(field))
|
||||
if !ok || info.Origin.Layer != configkit.LayerResolution {
|
||||
t.Fatalf("missing field origin for %s: %#v", field, info)
|
||||
}
|
||||
|
||||
@@ -4,36 +4,50 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||
)
|
||||
|
||||
func validateCampaign(cfg *CampaignConfig) error {
|
||||
_, err := campaignConfigurationError(cfg)
|
||||
return err
|
||||
}
|
||||
|
||||
func validateCampaignConfigKit(cfg *CampaignConfig, validation *configkit.Validation) {
|
||||
path, err := campaignConfigurationError(cfg)
|
||||
if err != nil {
|
||||
validation.Error(path, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func campaignConfigurationError(cfg *CampaignConfig) (configkit.Path, error) {
|
||||
if cfg == nil {
|
||||
return fmt.Errorf("campaign config is required")
|
||||
return configkit.Keys(), fmt.Errorf("campaign config is required")
|
||||
}
|
||||
if CampaignID(cfg) == "" {
|
||||
return fmt.Errorf("campaign.campaign_id is required")
|
||||
return configkit.Keys("campaign_id"), fmt.Errorf("campaign.campaign_id is required")
|
||||
}
|
||||
if err := pathsafe.ValidateOpaqueSegment(cfg.CampaignID); err != nil {
|
||||
return fmt.Errorf("campaign.campaign_id: %w", err)
|
||||
return configkit.Keys("campaign_id"), fmt.Errorf("campaign.campaign_id: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.SpeakersFile) == "" {
|
||||
return fmt.Errorf("campaign.inputs.speakers_file is required")
|
||||
return configkit.Keys("inputs", "speakers_file"), fmt.Errorf("campaign.inputs.speakers_file is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.AutocorrectFile) == "" {
|
||||
return fmt.Errorf("campaign.inputs.autocorrect_file is required")
|
||||
return configkit.Keys("inputs", "autocorrect_file"), fmt.Errorf("campaign.inputs.autocorrect_file is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.GlossaryFile) == "" {
|
||||
return fmt.Errorf("campaign.inputs.glossary_file is required")
|
||||
return configkit.Keys("inputs", "glossary_file"), fmt.Errorf("campaign.inputs.glossary_file is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.Inputs.PartyFile) == "" {
|
||||
return fmt.Errorf("campaign.inputs.party_file is required")
|
||||
return configkit.Keys("inputs", "party_file"), fmt.Errorf("campaign.inputs.party_file is required")
|
||||
}
|
||||
if cfg.Inputs.SpellCatalogFile != "" && strings.TrimSpace(cfg.Inputs.SpellCatalogFile) == "" {
|
||||
return fmt.Errorf("campaign.inputs.spell_catalog_file must be non-empty when provided")
|
||||
return configkit.Keys("inputs", "spell_catalog_file"), fmt.Errorf("campaign.inputs.spell_catalog_file must be non-empty when provided")
|
||||
}
|
||||
return nil
|
||||
return configkit.Keys(), nil
|
||||
}
|
||||
|
||||
func validateSpool(cfg SpoolConfig) error {
|
||||
|
||||
Reference in New Issue
Block a user