Files
narratio/internal/config/pipeline_configkit_test.go

711 lines
27 KiB
Go

package config
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
configkit "go.maximumdirect.net/configkit"
)
func TestPipelineConfigKitImportsOverlayAndBaseSelection(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: config/workspace.yml
- path: config/artifact.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "config/workspace.yml", "workspace:\n root: /srv/base\n")
writePipelineFixture(t, dir, "config/artifact.yml", `scriptorium:
artifacts:
recap:
enabled: false
output_path: artifacts/recap.md
`)
writePipelineFixture(t, dir, "overlays/testing.yml", "workspace:\n root: /srv/testing\n")
writePipelineFixture(t, dir, "overlays/identical.yml", "workspace:\n root: /srv/base\n")
writePipelineFixture(t, dir, "overlays/unselected.yml", "unknown: [\n")
root := filepath.Join(dir, "pipeline.yml")
var baseDigest string
for _, profile := range []*string{nil, stringPointer(""), stringPointer("default")} {
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: profile})
if err != nil {
t.Fatalf("load base selection %#v: %v", profile, err)
}
if cfg.Workspace.Root != "/srv/base" {
t.Fatalf("base workspace = %q", cfg.Workspace.Root)
}
if baseDigest == "" {
baseDigest = EffectivePipelineDigest(cfg)
} else if EffectivePipelineDigest(cfg) != baseDigest {
t.Fatal("equivalent base selections changed effective digest")
}
}
identical := "identical"
unchanged, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &identical})
if err != nil {
t.Fatal(err)
}
if EffectivePipelineDigest(unchanged) != baseDigest {
t.Fatal("equivalent overlay changed effective digest")
}
selected := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &selected})
if err != nil {
t.Fatal(err)
}
if cfg.Workspace.Root != "/srv/testing" || len(EffectivePipelineImports(cfg)) != 2 {
t.Fatalf("profiled pipeline = %#v, imports=%#v", cfg.Workspace, EffectivePipelineImports(cfg))
}
profile, ok := SelectedPipelineOverlay(cfg)
if !ok || profile.Name != "testing" || profile.OverlayPath != filepath.Join(dir, "overlays", "testing.yml") {
t.Fatalf("selected profile = %#v, %v", profile, ok)
}
}
func TestPipelineOverlayDoesNotDiscoverLegacyDirectory(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", "config:\n imports:\n - path: profiles/shared.yml\n")
writePipelineFixture(t, dir, "profiles/shared.yml", "workspace:\n root: /srv/base\n")
writePipelineFixture(t, dir, "profiles/testing.yml", "workspace:\n root: /srv/old\n")
if base, err := LoadPipeline(filepath.Join(dir, "pipeline.yml")); err != nil || base.Workspace.Root != "/srv/base" {
t.Fatalf("explicit import from profiles directory = %#v, %v", base, err)
}
selected := "testing"
if _, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: &selected}); err == nil || !strings.Contains(err.Error(), "overlay.missing") {
t.Fatalf("legacy selected file result = %v, want missing overlay", err)
}
}
func TestPipelineConfigKitComposesDisjointDefinitionsAndHonorsOverlay(t *testing.T) {
for _, test := range []struct {
name, first, second, replacement, removal string
}{
{
name: "artifact",
first: "scriptorium:\n artifacts:\n recap:\n enabled: true\n prompt_id: dnd.recap\n",
second: "scriptorium:\n artifacts:\n recap:\n output_path: artifacts/recap.md\n",
replacement: "scriptorium:\n artifacts:\n recap:\n output_path: artifacts/replaced.md\n",
removal: "scriptorium:\n artifacts: null\n",
},
{
name: "artifact family",
first: "scriptorium:\n artifact_families:\n recap:\n enabled: true\n for_each: party.characters\n prompt_id: dnd.recap\n profile_id: production\n",
second: "scriptorium:\n artifact_families:\n recap:\n output_path_pattern: artifacts/{character_id}.md\n",
replacement: "scriptorium:\n artifact_families:\n recap:\n output_path_pattern: artifacts/{character_id}_replaced.md\n",
removal: "scriptorium:\n artifact_families: null\n",
},
} {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), `schema_version: narratio.party.v1
characters:
alice:
player: {name: Alice Player}
character:
name: Alice
classes: [{name: wizard}]
`)
pipeline := `config:
imports:
- path: first.yml
- path: second.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, pipeline)
writePipelineFixture(t, dir, "first.yml", test.first)
writePipelineFixture(t, dir, "second.yml", test.second)
writePipelineFixture(t, dir, "overlays/replacement.yml", test.replacement)
writePipelineFixture(t, dir, "overlays/removal.yml", test.removal)
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
if err != nil {
t.Fatalf("load disjoint contributions: %v", err)
}
if test.name == "artifact" {
artifact := cfg.Pipeline.Scriptorium.Artifacts["recap"]
if !artifact.Enabled || artifact.PromptID != "dnd.recap" || artifact.OutputPath != "artifacts/recap.md" {
t.Fatalf("composed artifact = %#v", artifact)
}
} else {
artifact := cfg.Pipeline.Scriptorium.Artifacts["recap_alice"]
if !artifact.Enabled || artifact.PromptID != "dnd.recap" || artifact.OutputPath != "artifacts/alice.md" {
t.Fatalf("composed artifact family member = %#v", artifact)
}
}
replacement := "replacement"
cfg, err = LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{Overlay: &replacement})
if err != nil {
t.Fatalf("load replacement overlay: %v", err)
}
if test.name == "artifact" && cfg.Pipeline.Scriptorium.Artifacts["recap"].OutputPath != "artifacts/replaced.md" {
t.Fatalf("overlay artifact replacement = %#v", cfg.Pipeline.Scriptorium.Artifacts["recap"])
}
if test.name == "artifact family" && cfg.Pipeline.Scriptorium.Artifacts["recap_alice"].OutputPath != "artifacts/alice_replaced.md" {
t.Fatalf("overlay family replacement = %#v", cfg.Pipeline.Scriptorium.Artifacts["recap_alice"])
}
removal := "removal"
cfg, err = LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{Overlay: &removal})
if err != nil {
t.Fatalf("load removal overlay: %v", err)
}
if len(cfg.Pipeline.Scriptorium.Artifacts) != 0 {
t.Fatalf("overlay left artifacts after removal: %#v", cfg.Pipeline.Scriptorium.Artifacts)
}
})
}
t.Run("structural conflict remains a loader error", func(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: first.yml
- path: second.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "first.yml", "workspace:\n root: /srv/first\n")
writePipelineFixture(t, dir, "second.yml", "workspace:\n root: /srv/second\n")
if _, err := LoadPipeline(filepath.Join(dir, "pipeline.yml")); err == nil || !strings.Contains(strings.ToLower(err.Error()), "conflict") {
t.Fatalf("structural conflict error = %v", err)
}
})
}
func TestPipelineInheritancePreservesPresenceAndPathBases(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: config/parent.yml
- path: config/children.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "config/parent.yml", `scriptorium:
artifacts:
base:
enabled: false
prompt_id: dnd.base
render_debug: false
vars:
empty: ""
flag: false
null_base:
enabled: false
vars: null
`)
writePipelineFixture(t, dir, "config/children.yml", `scriptorium:
artifacts:
inherited:
extends: base
output_path: artifacts/inherited.md
overridden:
extends: base
output_path: artifacts/overridden.md
render_debug: false
null_child:
extends: null_base
output_path: artifacts/null.md
absent:
enabled: false
output_path: artifacts/absent.md
`)
writePipelineFixture(t, dir, "overlays/testing.yml", `scriptorium:
artifacts:
base:
prompt_id: dnd.overlay
render_debug: true
`)
cfg, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: stringPointer("testing")})
if err != nil {
t.Fatalf("LoadPipelineWithOptions() error = %v", err)
}
artifacts := cfg.Scriptorium.Artifacts
if got := artifacts["inherited"]; got.PromptID != "dnd.overlay" || got.OutputPath != "artifacts/inherited.md" || got.RenderDebug == nil || !*got.RenderDebug {
t.Fatalf("inherited artifact after overlay = %#v", got)
}
if got := artifacts["overridden"]; got.PromptID != "dnd.overlay" || got.RenderDebug == nil || *got.RenderDebug {
t.Fatalf("child override after overlay = %#v", got)
}
if got := artifacts["inherited"].Vars["empty"]; got != "" {
t.Fatalf("inherited empty variable = %#v, want empty string", got)
}
if got := artifacts["inherited"].Vars["flag"]; got != false {
t.Fatalf("inherited false variable = %#v, want false", got)
}
if artifacts["null_child"].Vars != nil {
t.Fatalf("inherited null vars = %#v, want nil", artifacts["null_child"].Vars)
}
if artifacts["absent"].RenderDebug != nil {
t.Fatalf("absent render_debug = %#v, want nil", artifacts["absent"].RenderDebug)
}
if cfg.Scriptorium.Timeout != DefaultScriptoriumTimeout {
t.Fatalf("absent Scriptorium timeout = %q, want default %q", cfg.Scriptorium.Timeout, DefaultScriptoriumTimeout)
}
metadata := cfg.resolution.configkitMetadata
for _, path := range []configkit.Path{
configkit.Keys("scriptorium", "artifacts", "inherited", "render_debug"),
configkit.Keys("scriptorium", "artifacts", "inherited", "vars", "empty"),
configkit.Keys("scriptorium", "artifacts", "inherited", "vars", "flag"),
configkit.Keys("scriptorium", "artifacts", "null_child", "vars"),
} {
if !metadata.IsExplicit(path) {
t.Errorf("inherited path %v is not explicit", path)
}
}
if metadata.IsExplicit(configkit.Keys("scriptorium", "artifacts", "absent", "render_debug")) {
t.Fatal("absent render_debug is marked explicit")
}
if metadata.IsExplicit(configkit.Keys("scriptorium", "artifacts", "absent", "vars", "empty")) {
t.Fatal("absent variable is marked explicit")
}
if metadata.IsExplicit(configkit.Keys("scriptorium", "artifacts", "absent", "vars")) {
t.Fatal("absent vars mapping is marked explicit")
}
if metadata.IsExplicit(configkit.Keys("scriptorium", "timeout")) {
t.Fatal("defaulted Scriptorium timeout is marked explicit")
}
if err := ValidatePipelineConfig(cfg); err != nil {
t.Fatalf("ValidatePipelineConfig() error = %v", err)
}
}
func TestPipelineInheritanceRetainsZeroTimeoutForDomainValidation(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: artifacts.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "artifacts.yml", `scriptorium:
artifacts:
base:
enabled: false
timeout: 0s
child:
extends: base
output_path: artifacts/child.md
`)
cfg, err := LoadPipeline(filepath.Join(dir, "pipeline.yml"))
if err != nil {
t.Fatalf("LoadPipeline() error = %v", err)
}
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")) {
t.Fatal("inherited zero timeout is not marked explicit")
}
if err := ValidatePipelineConfig(cfg); err == nil || !strings.Contains(err.Error(), "timeout must be positive") {
t.Fatalf("ValidatePipelineConfig() error = %v, want invalid zero timeout", err)
}
}
func TestPipelineExplicitEmptyTimeoutDoesNotReceiveDefault(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: timeout.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "timeout.yml", "scriptorium:\n timeout: \"\"\n")
cfg, err := LoadPipeline(filepath.Join(dir, "pipeline.yml"))
if err != nil {
t.Fatalf("LoadPipeline() error = %v", err)
}
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")) {
t.Fatal("explicit empty Scriptorium timeout is not marked explicit")
}
if err := ValidatePipelineConfig(cfg); err != nil {
t.Fatalf("ValidatePipelineConfig() error = %v, want existing empty-timeout behavior", err)
}
}
func TestInheritedNotariusPathsKeepPipelineRootBase(t *testing.T) {
dir := t.TempDir()
pipelinePath := writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: profiles/notarius.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "profiles/notarius.yml", `audita:
config_path: notarius/config.yml
notarius:
extends: audita
enabled: true
pipeline_id: dnd-session
outputs:
npc_registry:
lane_id: npc-registry
media_type: application/json
schema_id: notarius.dnd.npc_registry
schema_version: v1
`)
cfg, err := LoadPipeline(pipelinePath)
if err != nil {
t.Fatalf("LoadPipeline() error = %v", err)
}
wantConfigPath := filepath.Join(dir, "notarius", "config.yml")
if cfg.Notarius.ConfigPath != wantConfigPath {
t.Fatalf("imported Notarius config_path = %q, want pipeline-root path %q", cfg.Notarius.ConfigPath, wantConfigPath)
}
if got, want := cfg.Notarius.WorkingDirectory, filepath.Dir(wantConfigPath); got != want {
t.Fatalf("derived Notarius working_directory = %q, want pipeline-root directory %q", got, want)
}
}
func TestPipelineConfigKitInheritsArtifactAcrossImports(t *testing.T) {
dir := t.TempDir()
writePartyResolutionFile(t, filepath.Join(dir, "party.yml"), `schema_version: narratio.party.v1
characters:
alice:
player: {name: Alice Player}
character:
name: Alice
classes: [{name: wizard}]
`)
pipeline := `config:
imports:
- path: artifacts/parent.yml
- path: artifacts/child.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`
pipelinePath, campaignPath, sessionPath := writeArtifactFamilyConfig(t, dir, pipeline)
writePipelineFixture(t, dir, "artifacts/parent.yml", `scriptorium:
artifacts:
session_recap:
enabled: true
prompt_id: dnd.session_recap
profile_id: production
output_path: artifacts/session_recap.md
`)
writePipelineFixture(t, dir, "artifacts/child.yml", `scriptorium:
artifacts:
session_notes:
extends: session_recap
output_path: artifacts/session_notes.md
`)
cfg, err := LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, SessionLoadOptions{})
if err != nil {
t.Fatal(err)
}
parent := cfg.Pipeline.Scriptorium.Artifacts["session_recap"]
child, ok := cfg.Pipeline.Scriptorium.Artifacts["session_notes"]
if !ok {
t.Fatal("inherited child artifact identity was not retained")
}
if parent.OutputPath != "artifacts/session_recap.md" || child.OutputPath != "artifacts/session_notes.md" {
t.Fatalf("artifact destinations = parent %q, child %q", parent.OutputPath, child.OutputPath)
}
if !child.Enabled || child.PromptID != "dnd.session_recap" || child.ProfileID != "production" {
t.Fatalf("inherited child artifact = %#v", child)
}
}
func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
const production = "NARRATIO_PROFILE_UNUSED_PROD_KEY"
const testingKey = "NARRATIO_PROFILE_TEST_KEY"
t.Setenv(production, "")
if err := os.Unsetenv(production); err != nil {
t.Fatal(err)
}
t.Setenv(testingKey, "synthetic-test-key")
for _, credential := range []string{testingKey, "null"} {
t.Run(credential, func(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n credentials: ["+production+"]\nscriptorium:\n extends: audita\n")
selected := "[" + credential + "]"
if credential == "null" {
selected = credential
}
writePipelineFixture(t, dir, "overlays/testing.yml", "audita:\n credentials: "+selected+"\n")
profile := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &profile})
if err != nil {
t.Fatal(err)
}
if credential == "null" {
if len(cfg.Audita.Credentials) != 0 {
t.Fatal("profile did not remove the base credential")
}
if len(cfg.Scriptorium.Credentials) != 0 {
t.Fatal("inherited profile credential was not removed")
}
} else if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != testingKey || !cfg.Audita.Credentials[0].IsResolved() {
t.Fatal("profile credential was not resolved")
} else if len(cfg.Scriptorium.Credentials) != 1 || cfg.Scriptorium.Credentials[0].EnvName() != testingKey || cfg.Scriptorium.Credentials[0].Value() != "synthetic-test-key" {
t.Fatal("inherited profile credential was not resolved")
}
})
}
}
func TestAuditaModulesPreserveOmittedEmptyAndReplacementSelections(t *testing.T) {
for _, test := range []struct {
name, base, overlay string
wantNil bool
want []string
}{
{name: "omitted", wantNil: true},
{name: "null", base: " modules: null\n", wantNil: true},
{name: "empty", base: " modules: []\n", want: []string{}},
{name: "overlay empty", base: " modules: [glossary]\n", overlay: "audita:\n modules: []\n", want: []string{}},
{name: "overlay order", base: " modules: []\n", overlay: "audita:\n modules: [grammar, glossary, grammar]\n", want: []string{"grammar", "glossary", "grammar"}},
} {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n binary: audita\n"+test.base)
options := PipelineLoadOptions{}
if test.overlay != "" {
writePipelineFixture(t, dir, "overlays/testing.yml", test.overlay)
selection := "testing"
options.Overlay = &selection
}
cfg, err := LoadPipelineWithOptions(root, options)
if err != nil {
t.Fatal(err)
}
if (cfg.Audita.Modules == nil) != test.wantNil || !reflect.DeepEqual(cfg.Audita.Modules, test.want) {
t.Fatalf("modules = %#v, want %#v (nil=%v)", cfg.Audita.Modules, test.want, test.wantNil)
}
})
}
}
func TestAuditaRejectsRetiredConfigurationFields(t *testing.T) {
for _, field := range []string{"llm_api_key", "base_url", "model", "validation_model", "total_llm_concurrency", "proposal_llm_concurrency", "validation_llm_concurrency", "work_dir_retention", "report"} {
t.Run(field, func(t *testing.T) {
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n "+field+": retired\n")
if _, err := LoadPipeline(root); err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
t.Fatalf("error = %v, want unknown field", err)
}
})
}
}
func TestNotariusCredentialOverlayReplacementAndProvenance(t *testing.T) {
const baseKey = "NARRATIO_NOTARIUS_UNUSED_BASE_KEY"
const profileKey = "NARRATIO_NOTARIUS_PROFILE_KEY"
if err := os.Unsetenv(baseKey); err != nil {
t.Fatal(err)
}
t.Setenv(profileKey, "synthetic-notarius-profile-key")
for _, credential := range []string{"[" + profileKey + "]", "null", "[]"} {
t.Run(credential, func(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+baseKey+"]\n")
overlay := writePipelineFixture(t, dir, "overlays/testing.yml", "notarius:\n credentials: "+credential+"\n")
profile := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &profile})
if err != nil {
t.Fatal(err)
}
if credential == "null" || credential == "[]" {
if len(cfg.Notarius.Credentials) != 0 {
t.Fatal("overlay did not clear base credentials")
}
return
}
if len(cfg.Notarius.Credentials) != 1 || cfg.Notarius.Credentials[0].EnvName() != profileKey || !cfg.Notarius.Credentials[0].IsResolved() {
t.Fatal("overlay credential was not resolved")
}
sources, err := EffectivePipelineSources(cfg, ResolvedParty{})
if err != nil {
t.Fatal(err)
}
found := false
for _, source := range sources {
if source.Path == "notarius.credentials" {
found = source.Source == overlay
}
}
if !found {
t.Fatal("Notarius credential provenance did not identify the selected overlay")
}
})
}
}
func TestNotariusRetiredConfigProfileRejected(t *testing.T) {
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n config_profile: testing\n")
if _, err := LoadPipelineWithOptions(root, PipelineLoadOptions{}); err == nil {
t.Fatal("retired Notarius config_profile field was accepted")
}
}
func TestNotariusConfigOverlayComposition(t *testing.T) {
tests := []struct {
name string
baseValue string
overlayName string
overlay string
want *string
}{
{name: "omitted"},
{name: "explicit empty", baseValue: `""`, want: stringPointer("")},
{name: "explicit default", baseValue: "default", want: stringPointer("default")},
{name: "base named selection", baseValue: "production", want: stringPointer("production")},
{name: "profile replaces named selection", baseValue: "production", overlayName: "testing", overlay: "notarius:\n config_overlay: inexpensive\n", want: stringPointer("inexpensive")},
{name: "profile clears named selection", baseValue: "production", overlayName: "testing", overlay: "notarius:\n config_overlay: null\n"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
rootYAML := "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n"
if test.baseValue != "" {
rootYAML += " config_overlay: " + test.baseValue + "\n"
}
root := writePipelineFixture(t, dir, "pipeline.yml", rootYAML)
options := PipelineLoadOptions{}
if test.overlayName != "" {
writePipelineFixture(t, dir, "overlays/"+test.overlayName+".yml", test.overlay)
options.Overlay = &test.overlayName
}
cfg, err := LoadPipelineWithOptions(root, options)
if err != nil {
t.Fatal(err)
}
if cfg.Notarius == nil || !reflect.DeepEqual(cfg.Notarius.ConfigOverlay, test.want) {
t.Fatalf("config overlay = %#v, want %#v", cfg.Notarius.ConfigOverlay, test.want)
}
})
}
}
func TestNotariusCredentialRootProvenance(t *testing.T) {
const envName = "NARRATIO_NOTARIUS_ROOT_KEY"
t.Setenv(envName, "synthetic-notarius-root-key")
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n")
cfg, err := LoadPipeline(root)
if err != nil {
t.Fatal(err)
}
sources, err := EffectivePipelineSources(cfg, ResolvedParty{})
if err != nil {
t.Fatal(err)
}
for _, source := range sources {
if source.Path == "notarius.credentials" && source.Source == root {
return
}
}
t.Fatal("Notarius credential provenance did not identify the root pipeline")
}
func TestNotariusCacheControlProfileReplacementAndNullReset(t *testing.T) {
tests := []struct {
name string
overlay string
wantResume bool
wantMode string
wantSource bool
wantNil bool
}{
{name: "replacement", overlay: "notarius:\n resume: true\n chunk_cache: refresh\n", wantResume: true, wantMode: "refresh", wantSource: true},
{name: "null reset", overlay: "notarius: null\n", wantNil: true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n resume: false\n chunk_cache: bypass\n")
overlay := writePipelineFixture(t, dir, "overlays/testing.yml", test.overlay)
profile := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &profile})
if err != nil {
t.Fatal(err)
}
if test.wantNil {
if cfg.Notarius != nil {
t.Fatalf("Notarius = %#v, want null reset", cfg.Notarius)
}
return
}
if cfg.Notarius == nil || cfg.Notarius.Resume != test.wantResume || cfg.Notarius.ChunkCache != test.wantMode {
t.Fatalf("cache controls = resume %v, mode %q; want resume %v, mode %q", cfg.Notarius.Resume, cfg.Notarius.ChunkCache, test.wantResume, test.wantMode)
}
if !test.wantSource {
return
}
sources, err := EffectivePipelineSources(cfg, ResolvedParty{})
if err != nil {
t.Fatal(err)
}
found := map[string]bool{}
for _, source := range sources {
if source.Path == "notarius.resume" || source.Path == "notarius.chunk_cache" {
found[source.Path] = source.Source == overlay
}
}
if !found["notarius.resume"] || !found["notarius.chunk_cache"] {
t.Fatalf("cache-control provenance did not identify profile: %#v", found)
}
})
}
}
func TestPipelineConfigKitAllowsOneBaseDeclarationWithProfileOverride(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
- path: artifact.yml
whisperx:
transcribe_url: https://transcription.example.test/transcribe
`)
writePipelineFixture(t, dir, "artifact.yml", "scriptorium:\n artifacts:\n recap:\n prompt_id: base\n output_path: artifacts/recap.md\n")
writePipelineFixture(t, dir, "overlays/testing.yml", "scriptorium:\n artifacts:\n recap:\n prompt_id: testing\n")
profile := "testing"
cfg, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: &profile})
if err != nil {
t.Fatal(err)
}
if got := cfg.Scriptorium.Artifacts["recap"].PromptID; got != "testing" {
t.Fatalf("profile prompt = %q, want testing", got)
}
}
func TestPipelineConfigKitRejectsUnknownDirectiveAlias(t *testing.T) {
dir := t.TempDir()
path := writePipelineFixture(t, dir, "pipeline.yml", "composition:\n imports: []\n")
_, err := LoadPipeline(path)
if err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
t.Fatalf("composition alias error = %v", err)
}
}
func writePipelineFixture(t *testing.T, root, relative, contents string) string {
t.Helper()
path := filepath.Join(root, filepath.FromSlash(relative))
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte(contents), 0o644); err != nil {
t.Fatal(err)
}
return path
}
func stringPointer(value string) *string { return &value }