Retain authoritative pipeline and campaign load results
This commit is contained in:
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user