Expose native configuration inspection scopes

This commit is contained in:
2026-11-20 05:02:46 +00:00
parent 1e67c429b7
commit c3c6849bed
31 changed files with 412 additions and 1567 deletions

View File

@@ -54,12 +54,8 @@ cache:
inputs:
audio_dir: ./audio
`)
cfg, err := Load(pipelinePath, sessionPath)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
err = Validate(cfg)
_, err := Load(pipelinePath, sessionPath)
if err == nil || !strings.Contains(err.Error(), "pipeline.cache.root is required") {
t.Fatalf("Validate() error = %v, want cache root error", err)
t.Fatalf("Load() error = %v, want cache root error", err)
}
}

View File

@@ -8,7 +8,7 @@ import (
func TestAuthoredPublishOutputCollectionOperations(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", `config:
root := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig+`config:
sequences:
- destination: [publish, outputs]
key: source

View File

@@ -9,7 +9,7 @@ import (
func TestImportedCampaignAndSessionResourcesRetainTheirSources(t *testing.T) {
dir := t.TempDir()
pipeline := writePipelineFixture(t, dir, "pipeline.yml", "workspace: {root: /tmp/narratio}\n")
pipeline := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig+"workspace: {root: /tmp/narratio}\n")
campaign := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: campaign/shared.yml\ncampaign_id: sample\n")
fragment := writePipelineFixture(t, dir, "campaign/shared.yml", `session_template_file: templates/session.yml
inputs:

View File

@@ -3,10 +3,8 @@ package config
import (
"fmt"
"path/filepath"
"sort"
"strings"
configkit "go.maximumdirect.net/configkit"
"gopkg.in/yaml.v3"
)
@@ -35,52 +33,6 @@ func NormalizedConfigurationPath(path string) string {
return normalizedProvenancePath(path)
}
// EffectivePipelineSourceRecord identifies one effective logical field and a
// safe source that contributed to it.
type EffectivePipelineSourceRecord struct {
Path string
Role string
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 _, source := range result.Sources() {
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.
@@ -92,7 +44,7 @@ type EffectivePipelineValueRecord struct {
// EffectivePipelineValues projects a fully resolved pipeline into sorted
// logical configuration values. Mappings are flattened, while sequences remain
// atomic values. The projection uses the same normalized effective mapping as
// config show and therefore excludes loader directives and family declarations.
// persistence and informational identity; it is not a native inspection view.
func EffectivePipelineValues(cfg *PipelineConfig) ([]EffectivePipelineValueRecord, error) {
if cfg == nil {
return nil, fmt.Errorf("pipeline config is required")
@@ -100,124 +52,6 @@ func EffectivePipelineValues(cfg *PipelineConfig) ([]EffectivePipelineValueRecor
return projectionValueRecords(projectEffectivePipeline(cfg))
}
// EffectivePipelineSources projects pipeline ownership after resolution.
// It never includes effective values or raw secret
// material, only logical paths and source identifiers.
func EffectivePipelineSources(cfg *PipelineConfig, party ResolvedParty) ([]EffectivePipelineSourceRecord, error) {
if cfg == nil {
return nil, fmt.Errorf("pipeline config is required")
}
values, err := EffectivePipelineValues(cfg)
if err != nil {
return nil, err
}
paths := make([]string, 0, len(values))
for _, value := range values {
paths = append(paths, value.Path)
}
owners, err := effectivePipelineOwners(cfg)
if err != nil {
return nil, err
}
publishCount := 0
if cfg.Publish != nil {
publishCount = len(cfg.Publish.Outputs)
}
records := make([]EffectivePipelineSourceRecord, 0, len(paths)+publishCount)
for _, path := range paths {
if path == "publish.outputs" {
continue
}
records = appendPipelineOwners(records, path, owners[path], cfg)
}
records = appendPublishOutputSources(records, cfg, owners)
sort.Slice(records, func(left, right int) bool {
if records[left].Path != records[right].Path {
return records[left].Path < records[right].Path
}
if records[left].Role != records[right].Role {
return records[left].Role < records[right].Role
}
return records[left].Source < records[right].Source
})
return records, nil
}
// EffectiveCampaignSources projects selected campaign and party ownership
// without retaining or rendering campaign values. Players are derived from the
// canonical party source.
func EffectiveCampaignSources(campaignPath string, campaign *CampaignConfig, party ResolvedParty) []EffectivePipelineSourceRecord {
if campaign == nil {
return nil
}
fields := []string{"campaign_id", "inputs.autocorrect_file", "inputs.glossary_file", "inputs.speakers_file", "inputs.party_file"}
if strings.TrimSpace(campaign.Inputs.SpellCatalogFile) != "" {
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,
EffectivePipelineSourceRecord{Path: "campaign.inputs.party_file", Role: "party", Source: partySource},
EffectivePipelineSourceRecord{Path: "derived.players", Role: "party", Source: partySource},
)
sort.Slice(records, func(left, right int) bool {
if records[left].Path != records[right].Path {
return records[left].Path < records[right].Path
}
if records[left].Role != records[right].Role {
return records[left].Role < records[right].Role
}
return records[left].Source < records[right].Source
})
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 materializes completed configuration for persistence.
// Credentials retain reference names; domain catalogs remain separate.
func MarshalEffectivePipeline(cfg *PipelineConfig) ([]byte, error) {
@@ -247,222 +81,6 @@ func MarshalEffectivePipeline(cfg *PipelineConfig) ([]byte, error) {
return output, nil
}
func effectivePipelineOwners(cfg *PipelineConfig) (map[string][]string, error) {
owners := make(map[string][]string)
if cfg.ConfigKitResult() == nil {
return owners, nil
}
paths, err := pipelineMetadataPaths(cfg)
if err != nil {
return nil, err
}
pathsByID := pipelineSourcePaths(cfg)
metadata := cfg.ConfigKitResult().Metadata()
for _, value := range paths {
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 metadata.History(configkit.Keys(value.segments...)) {
if change.Origin.Layer != configkit.LayerResolution {
continue
}
// Native Previous evidence identifies the input immediately before
// resolution, including composite and inherited origins.
for _, previous := range change.Previous {
if previous.Layer == configkit.LayerMain || previous.Layer == configkit.LayerOverlay {
sources = append(sources, ownershipSources(previous, pathsByID)...)
}
}
break
}
sources = nonEmptySortedStrings(sources)
}
}
owners[value.record.Path] = sources
}
if cfg.Scriptorium != nil {
for key, artifact := range cfg.Scriptorium.Artifacts {
paths := artifactDependencyOwnershipPaths(key, artifact)
if sources := sourcesForPipelinePaths(owners, paths); len(sources) != 0 {
sort.Strings(sources)
owners["scriptorium.artifacts."+key+".depends_on"] = sources
}
}
}
return owners, nil
}
func artifactDependencyOwnershipPaths(artifactKey string, artifact ScriptoriumArtifactConfig) []string {
var paths []string
for _, dependency := range artifact.DependsOn {
for _, origin := range artifact.dependencyOrigins[dependency] {
prefix := "scriptorium.artifacts." + artifactKey
if origin.family != "" {
prefix = "scriptorium.artifact_families." + origin.family
}
switch {
case origin.inputName != "":
paths = append(paths, prefix+".inputs."+origin.inputName+".source")
case origin.family != "":
paths = append(paths, prefix+".member_dependencies")
default:
paths = append(paths, prefix+".depends_on")
}
}
}
return paths
}
func generatedArtifactFamilyForPath(path string, families ArtifactFamilyCatalog) (string, bool) {
const prefix = "scriptorium.artifacts."
if !strings.HasPrefix(path, prefix) {
return "", false
}
memberPath := strings.TrimPrefix(path, prefix)
memberKey, _, _ := strings.Cut(memberPath, ".")
member, exists := families.Members[memberKey]
if !exists {
return "", false
}
_, exists = families.Families[member.Family]
return member.Family, exists
}
func appendGeneratedArtifactSources(records []EffectivePipelineSourceRecord, path, familyKey string, families ArtifactFamilyCatalog, owners map[string][]string, partySources func(string) []string) []EffectivePipelineSourceRecord {
for _, source := range generatedArtifactSources(path, familyKey, families, owners) {
role := "family"
if source == pipelineDefaultOwnershipSource {
role = "default"
}
records = append(records, EffectivePipelineSourceRecord{Path: path, Role: role, Source: normalizedProvenanceSource(source)})
}
memberPath := strings.TrimPrefix(path, "scriptorium.artifacts.")
memberKey, _, _ := strings.Cut(memberPath, ".")
for _, source := range partySources(families.Members[memberKey].CharacterID) {
records = append(records, EffectivePipelineSourceRecord{Path: path, Role: "party", Source: normalizedProvenancePath(source)})
}
return records
}
func generatedArtifactSources(path, familyKey string, families ArtifactFamilyCatalog, owners map[string][]string) []string {
const artifactPrefix = "scriptorium.artifacts."
memberPath := strings.TrimPrefix(path, artifactPrefix)
_, suffix, _ := strings.Cut(memberPath, ".")
familyPrefix := "scriptorium.artifact_families." + familyKey + "."
candidates := []string{familyPrefix + suffix}
switch {
case suffix == "output_path":
candidates = []string{familyPrefix + "output_path_pattern"}
case suffix == "depends_on":
candidates = []string{path, familyPrefix + "depends_on", familyPrefix + "member_dependencies"}
case strings.HasPrefix(suffix, "vars."):
variable := strings.TrimPrefix(suffix, "vars.")
candidates = []string{familyPrefix + "vars." + variable, familyPrefix + "member_vars." + variable}
}
sources := sourcesForPipelinePaths(owners, candidates)
if len(sources) != 0 {
return sources
}
if family, ok := families.Families[familyKey]; ok && len(family.Sources) != 0 {
return append([]string(nil), family.Sources...)
}
return []string{pipelineDefaultOwnershipSource}
}
func sourcesForPipelinePaths(owners map[string][]string, paths []string) []string {
seen := make(map[string]struct{})
var sources []string
for _, path := range paths {
for _, source := range owners[path] {
if _, exists := seen[source]; exists {
continue
}
seen[source] = struct{}{}
sources = append(sources, source)
}
}
return sources
}
func appendPipelineOwners(records []EffectivePipelineSourceRecord, path string, sources []string, cfg *PipelineConfig) []EffectivePipelineSourceRecord {
if len(sources) == 0 {
sources = []string{pipelineDefaultOwnershipSource}
}
for _, source := range sources {
records = append(records, EffectivePipelineSourceRecord{
Path: path, Role: pipelineSourceRole(cfg, source), Source: normalizedProvenanceSource(source),
})
}
return records
}
func appendPublishOutputSources(records []EffectivePipelineSourceRecord, cfg *PipelineConfig, owners map[string][]string) []EffectivePipelineSourceRecord {
if cfg == nil || cfg.Publish == nil {
return records
}
for index := range cfg.Publish.Outputs {
path := fmt.Sprintf("publish.outputs[%d]", index)
records = appendPipelineOwners(records, path, owners["publish.outputs"], cfg)
}
return records
}
func appendGeneratedPublishSources(records []EffectivePipelineSourceRecord, path, familyKey string, families ArtifactFamilyCatalog, owners map[string][]string, party ResolvedParty) []EffectivePipelineSourceRecord {
familyPrefix := "scriptorium.artifact_families." + familyKey + ".publish."
sources := sourcesForPipelinePaths(owners, []string{familyPrefix + "enabled", familyPrefix + "required", familyPrefix + "dest_pattern"})
if len(sources) == 0 {
if family, ok := families.Families[familyKey]; ok && len(family.Sources) != 0 {
sources = append([]string(nil), family.Sources...)
} else {
sources = []string{pipelineDefaultOwnershipSource}
}
}
for _, source := range sources {
role := "family"
if source == pipelineDefaultOwnershipSource {
role = "default"
}
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})
}
return records
}
func pipelineSourceRole(cfg *PipelineConfig, source string) string {
if source == pipelineDefaultOwnershipSource {
return "default"
}
if source == "resolution" {
return "resolution"
}
if cfg == nil || cfg.resolution == nil {
return "pipeline"
}
if source == cfg.resolution.rootPath {
return "root"
}
if cfg.resolution.selectedOverlay != nil && source == cfg.resolution.selectedOverlay.overlayPath {
return "overlay"
}
for _, imported := range cfg.resolution.imports {
if source == imported {
return "import"
}
}
return "pipeline"
}
func normalizedProvenanceSource(source string) string {
if source == pipelineDefaultOwnershipSource || source == "resolution" {
return source
}
return normalizedProvenancePath(source)
}
func normalizedProvenancePath(path string) string {
if strings.TrimSpace(path) == "" {
return ""
@@ -473,10 +91,3 @@ func normalizedProvenancePath(path string) string {
}
return filepath.Clean(abs)
}
func campaignInputSourcePath(campaignPath, configuredPath string) string {
if filepath.IsAbs(configuredPath) {
return normalizedProvenancePath(configuredPath)
}
return normalizedProvenancePath(filepath.Join(filepath.Dir(campaignPath), configuredPath))
}

View File

@@ -1,42 +0,0 @@
package config
import (
"path/filepath"
"testing"
)
func TestEffectiveResourceSourcesExcludeSupersededDefinitions(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "config:\n imports:\n - path: shared.yml\nnotarius:\n extends: audita\n")
writePipelineFixture(t, dir, "shared.yml", "audita: {config_path: old.yml}\n")
overlayPath := writePipelineFixture(t, dir, "overlays/testing.yml", "audita: {config_path: replacement.yml}\n")
overlay := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &overlay})
if err != nil {
t.Fatal(err)
}
records, err := EffectivePipelineSources(cfg, ResolvedParty{})
if err != nil {
t.Fatal(err)
}
for _, path := range []string{"audita.config_path", "notarius.config_path"} {
foundOverlay, foundResolution := false, false
for _, record := range records {
if record.Path != path {
continue
}
if record.Role == "overlay" && record.Source == overlayPath {
foundOverlay = true
}
if record.Role == "resolution" {
foundResolution = true
}
if record.Source == filepath.Join(dir, "shared.yml") {
t.Fatalf("superseded source for %s: %#v", path, record)
}
}
if !foundOverlay || !foundResolution {
t.Fatalf("missing effective evidence for %s: %#v", path, records)
}
}
}

View File

@@ -4,24 +4,24 @@ import "testing"
func TestEmptyImportSourcesIncludeNestedDeclarations(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "config:\n imports:\n - path: fragment.yml\n - path: absent-root.yml\n")
root := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig+"config:\n imports:\n - path: fragment.yml\n - path: absent-root.yml\n")
fragment := writePipelineFixture(t, dir, "fragment.yml", "config:\n imports:\n - path: absent-child.yml\n")
cfg, err := LoadPipeline(root)
if err != nil {
t.Fatal(err)
}
selections := EffectiveEmptyImports(cfg, nil)
if len(selections) != 2 {
t.Fatalf("empty selections: %#v", selections)
}
count := 0
seen := map[string]bool{}
for _, selection := range selections {
if selection.Selector != "path" || selection.Path == "" || selection.Line == 0 {
t.Fatalf("incomplete evidence: %#v", selection)
for _, source := range cfg.ConfigKitResult().Sources() {
for _, selection := range source.EmptyImportSelections {
count++
if selection.Selector != "path" || selection.Path.String() == "" || selection.Location.Line == 0 {
t.Fatalf("incomplete evidence: %#v", selection)
}
seen[source.Path] = true
}
seen[selection.Source] = true
}
if !seen[root] || !seen[fragment] {
t.Fatalf("source evidence: %#v", selections)
if count != 2 || !seen[root] || !seen[fragment] {
t.Fatalf("empty import count=%d sources=%v", count, seen)
}
}

View File

@@ -10,7 +10,7 @@ func TestPipelineMaterializationPreservesFinalValuesWithoutResolvingCredentialsA
const name = "NARRATIO_SNAPSHOT_TEST_KEY"
const secret = "synthetic-snapshot-secret"
t.Setenv(name, secret)
path := writePipelineFixture(t, t.TempDir(), "pipeline.yml", `audita:
path := writePipelineFixture(t, t.TempDir(), "pipeline.yml", testTranscriptionConfig+`audita:
credentials: [NARRATIO_SNAPSHOT_TEST_KEY]
scriptorium:
artifact_families:
@@ -21,9 +21,7 @@ scriptorium:
artifacts:
recap:
vars:
exact: 9007199254740993
nothing: null
empty: []
title: synthetic-title
`)
cfg, err := LoadPipeline(path)
if err != nil {
@@ -39,7 +37,7 @@ scriptorium:
if err != nil {
t.Fatal(err)
}
for _, expected := range []string{name, "9007199254740993", "nothing: null", "empty: []", "character_notes:", "artifact_families:"} {
for _, expected := range []string{name, "synthetic-title", "character_notes:", "artifact_families:"} {
if !strings.Contains(string(data), expected) {
t.Fatalf("snapshot missing %q: %s", expected, data)
}
@@ -51,8 +49,8 @@ scriptorium:
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")
nullPath := writePipelineFixture(t, dir, "null.yml", testTranscriptionConfig+"audita: {credentials: null}\n")
emptyPath := writePipelineFixture(t, dir, "empty.yml", testTranscriptionConfig+"audita: {credentials: []}\n")
nullConfig, err := LoadPipeline(nullPath)
if err != nil {
t.Fatal(err)

View File

@@ -13,7 +13,7 @@ import (
func TestNativePipelineResultOwnsCompletedConfiguration(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", `config:
root := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig+`config:
imports:
- path: settings/resources.yml
storage:

View File

@@ -103,6 +103,12 @@ func TestNormalizeLoadAndValidate(t *testing.T) {
}
return
}
if err != nil && tt.wantValidateErr != "" {
if !strings.Contains(err.Error(), tt.wantValidateErr) {
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
}
return
}
if err != nil {
t.Fatalf("Load() error = %v", err)
}

View File

@@ -197,16 +197,11 @@ notarius:
if err := os.WriteFile(blankPath, []byte(blankYAML), 0o644); err != nil {
t.Fatal(err)
}
blank, err := LoadPipeline(blankPath)
if err != nil {
t.Fatalf("LoadPipeline(explicit blank working directory) error = %v", err)
}
if blank.Notarius.WorkingDirectory != "" {
t.Fatalf("explicit blank working_directory = %q, want empty", blank.Notarius.WorkingDirectory)
}
if err := ValidatePipelineConfig(blank); err == nil || !strings.Contains(err.Error(), "working_directory is required") {
t.Fatalf("ValidatePipelineConfig() error = %v, want required working directory", err)
_, err := LoadPipeline(blankPath)
if err == nil || !strings.Contains(err.Error(), "working_directory is required") {
t.Fatalf("LoadPipeline() error = %v, want required working directory", err)
}
})
}
}

View File

@@ -47,6 +47,12 @@ func TestNotificationConfigSupportsOnlyNoopMode(t *testing.T) {
}
return
}
if err != nil && tt.wantValidate != "" {
if !strings.Contains(err.Error(), tt.wantValidate) {
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidate)
}
return
}
if err != nil {
t.Fatalf("Load() error = %v", err)
}

View File

@@ -257,11 +257,12 @@ func cloneStringMap(value map[string]string) map[string]string {
}
func validatePipelineConfigKit(cfg *PipelineConfig, validation *configkit.Validation) {
// Checks that depend on family expansion or campaign/session context remain
// at Narratio's explicit resolution boundary. This early definition check is
// deliberately limited to an invariant that is wholly file-local.
if strings.TrimSpace(cfg.Workspace.Root) == "" {
validation.Error(configkit.Keys("workspace", "root"), "workspace root is required")
// Concrete artifacts and publication actions are validated during domain
// derivation. These checks require only the completed pipeline document.
for _, issue := range pipelineConfigurationIssues(cfg) {
if issue.err != nil {
validation.Error(configkit.Keys(issue.path...), issue.err.Error())
}
}
}
@@ -286,58 +287,6 @@ func pipelineMetadataFromConfigKit(result *configkit.Result[PipelineConfig], opt
return resolved
}
func pipelineMetadataPaths(cfg *PipelineConfig) ([]projectedPipelineValue, error) {
effective, err := projectionDetailedRecords(projectEffectivePipeline(cfg))
if err != nil {
return nil, err
}
if cfg.Scriptorium == nil {
return effective, nil
}
families := cfg.Scriptorium.ArtifactFamilies
if len(families) == 0 {
return effective, nil
}
detailedFamilies, err := projectionDetailedRecords(map[string]any{"scriptorium": map[string]any{"artifact_families": families}})
if err != nil {
return nil, err
}
return append(effective, detailedFamilies...), nil
}
func ownershipSources(origin configkit.Origin, pathsByID map[string]string) []string {
if origin.Layer == configkit.LayerDefault || (origin.Layer == configkit.LayerResolution && origin.Operation == configkit.ChangeDerivedDefault) {
return []string{pipelineDefaultOwnershipSource}
}
if origin.Layer == configkit.LayerResolution {
return []string{"resolution"}
}
seen := map[string]struct{}{}
var sources []string
add := func(location configkit.Location) {
value := pathsByID[location.SourceID]
if value == "" {
value = location.SourceID
}
if _, ok := seen[value]; !ok {
seen[value] = struct{}{}
sources = append(sources, value)
}
}
for _, location := range origin.Locations {
add(location)
}
for _, inheritance := range origin.Inheritance {
for _, location := range inheritance.Locations {
add(location)
}
}
if len(sources) == 0 {
return []string{pipelineDefaultOwnershipSource}
}
return sources
}
func pipelineSourcePaths(cfg *PipelineConfig) map[string]string {
paths := make(map[string]string)
if cfg.ConfigKitResult() == nil {

View File

@@ -70,7 +70,7 @@ whisperx:
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, "pipeline.yml", testTranscriptionConfig+"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" {
@@ -280,7 +280,7 @@ whisperx:
}
}
func TestPipelineInheritanceRetainsZeroTimeoutForDomainValidation(t *testing.T) {
func TestPipelineInheritanceValidatesZeroTimeoutDuringLoading(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `config:
imports:
@@ -298,19 +298,11 @@ whisperx:
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.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") {
t.Fatalf("ValidatePipelineConfig() error = %v, want invalid zero timeout", err)
_, err := LoadPipeline(filepath.Join(dir, "pipeline.yml"))
if err == nil || !strings.Contains(err.Error(), "timeout must be positive") {
t.Fatalf("LoadPipeline() error = %v, want invalid zero timeout", err)
}
}
func TestPipelineExplicitEmptyTimeoutDoesNotReceiveDefault(t *testing.T) {
@@ -531,19 +523,7 @@ func TestNotariusCredentialOverlayReplacementAndProvenance(t *testing.T) {
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")
}
assertNativePipelineSource(t, cfg, configkit.Keys("notarius", "credentials"), overlay)
})
}
}
@@ -603,16 +583,7 @@ func TestNotariusCredentialRootProvenance(t *testing.T) {
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")
assertNativePipelineSource(t, cfg, configkit.Keys("notarius", "credentials"), root)
}
func TestNotariusCacheControlProfileReplacementAndNullReset(t *testing.T) {
@@ -649,19 +620,8 @@ func TestNotariusCacheControlProfileReplacementAndNullReset(t *testing.T) {
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)
}
assertNativePipelineSource(t, cfg, configkit.Keys("notarius", "resume"), overlay)
assertNativePipelineSource(t, cfg, configkit.Keys("notarius", "chunk_cache"), overlay)
})
}
}
@@ -708,3 +668,21 @@ func writePipelineFixture(t *testing.T, root, relative, contents string) string
}
func stringPointer(value string) *string { return &value }
const testTranscriptionConfig = "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\n"
func assertNativePipelineSource(t *testing.T, cfg *PipelineConfig, path configkit.Path, expected string) {
t.Helper()
result := cfg.ConfigKitResult()
info, ok := result.Metadata().Lookup(path)
if !ok {
t.Fatalf("native path %s is absent", path.String())
}
for _, location := range info.Origin.Locations {
source, ok := result.Source(location.SourceID)
if ok && source.Path == expected {
return
}
}
t.Fatalf("native path %s has no origin in %s: %#v", path.String(), expected, info.Origin)
}

View File

@@ -14,7 +14,7 @@ func TestPipelineDiscoverySelectsFirstSourceAndExplicitFileWins(t *testing.T) {
first := filepath.Join(dir, "first.yml")
second := filepath.Join(dir, "second.yml")
for path, root := range map[string]string{first: "/first", second: "/second"} {
if err := os.WriteFile(path, []byte("workspace:\n root: "+root+"\n"), 0o644); err != nil {
if err := os.WriteFile(path, []byte(testTranscriptionConfig+"workspace:\n root: "+root+"\n"), 0o644); err != nil {
t.Fatal(err)
}
}
@@ -65,7 +65,7 @@ func TestPipelineDiscoveryUsesWorkingDirectoryBeforeUserConfig(t *testing.T) {
userPath := filepath.Join(userDir, "config.yml")
localPath := filepath.Join(working, "narratio.yml")
for path, root := range map[string]string{userPath: "/user", localPath: "/working"} {
if err := os.WriteFile(path, []byte("workspace:\n root: "+root+"\n"), 0o644); err != nil {
if err := os.WriteFile(path, []byte(testTranscriptionConfig+"workspace:\n root: "+root+"\n"), 0o644); err != nil {
t.Fatal(err)
}
}

View File

@@ -7,7 +7,7 @@ import (
)
func TestPublishFieldResolutionPreservesUnchangedSourceHistory(t *testing.T) {
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", "publish:\n outputs:\n - source: narratio.transcript.final\n")
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", testTranscriptionConfig+"publish:\n outputs:\n - source: narratio.transcript.final\n")
cfg, err := LoadPipeline(root)
if err != nil {
t.Fatal(err)

View File

@@ -114,6 +114,12 @@ func TestRenderLoadAndValidate(t *testing.T) {
}
return
}
if err != nil && tt.wantValidateErr != "" {
if !strings.Contains(err.Error(), tt.wantValidateErr) {
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
}
return
}
if err != nil {
t.Fatalf("Load() error = %v", err)
}

View File

@@ -10,7 +10,7 @@ import (
func TestPipelineResourcePathsFollowEffectiveSources(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", `config:
root := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig+`config:
imports:
- path: fragments/shared.yml
workspace: {root: root-work}
@@ -24,6 +24,8 @@ notarius:
extends: audita
enabled: true
pipeline_id: dnd-session
outputs:
recap: {lane_id: recap, media_type: application/json, schema_id: recap, schema_version: "1"}
`)
writePipelineFixture(t, dir, "overlays/testing.yml", "audita:\n config_path: custom.yml\n")
base, err := LoadPipeline(root)
@@ -76,8 +78,8 @@ func TestResourceBaseUsesInvocationDirectoryForContextlessAndCLIValues(t *testin
func TestEquivalentPipelineResourceLayoutsHaveEqualDigests(t *testing.T) {
dir := t.TempDir()
first := writePipelineFixture(t, dir, "first.yml", "audita: {config_path: shared/tool.yml}\n")
second := writePipelineFixture(t, dir, "second.yml", "config:\n imports:\n - path: shared/settings.yml\n")
first := writePipelineFixture(t, dir, "first.yml", testTranscriptionConfig+"audita: {config_path: shared/tool.yml}\n")
second := writePipelineFixture(t, dir, "second.yml", testTranscriptionConfig+"config:\n imports:\n - path: shared/settings.yml\n")
writePipelineFixture(t, dir, "shared/settings.yml", "audita: {config_path: tool.yml}\n")
a, err := LoadPipeline(first)
if err != nil {

View File

@@ -14,7 +14,7 @@ import (
func TestSessionDefaultsCompleteBeforeNativeHandoff(t *testing.T) {
dir := t.TempDir()
pipeline := writePipelineFixture(t, dir, "pipeline.yml", "workspace: {root: work}\n")
pipeline := writePipelineFixture(t, dir, "pipeline.yml", testTranscriptionConfig+"workspace: {root: work}\n")
campaign := writePipelineFixture(t, dir, "campaign.yml", "config:\n imports:\n - path: campaign/resources.yml\ncampaign_id: campaign\n")
fragment := writePipelineFixture(t, dir, "campaign/resources.yml", `inputs:
speakers_file: speakers.yml

View File

@@ -135,6 +135,12 @@ func TestTrimLoadAndValidate(t *testing.T) {
}
return
}
if err != nil && tt.wantValidateErr != "" {
if !strings.Contains(err.Error(), tt.wantValidateErr) {
t.Fatalf("load validation error = %v, want %q", err, tt.wantValidateErr)
}
return
}
if err != nil {
t.Fatalf("Load() error = %v", err)
}

View File

@@ -61,54 +61,46 @@ func ValidateCampaignConfig(cfg *CampaignConfig) error {
return validateCampaign(cfg)
}
func validatePipeline(cfg *PipelineConfig) error {
// pipelineConfigurationIssue associates a file-local check with its native path.
type pipelineConfigurationIssue struct {
path []string
err error
}
func pipelineConfigurationIssues(cfg *PipelineConfig) []pipelineConfigurationIssue {
var workspaceErr, campaignErr error
if strings.TrimSpace(cfg.Workspace.Root) == "" {
return fmt.Errorf("pipeline.workspace.root is required")
workspaceErr = fmt.Errorf("pipeline.workspace.root is required")
}
if campaignID := cfg.Campaigns.DefaultCampaignID; campaignID != "" {
if err := pathsafe.ValidateOpaqueSegment(campaignID); err != nil {
return fmt.Errorf("pipeline.campaigns.default_campaign_id: %w", err)
if id := cfg.Campaigns.DefaultCampaignID; id != "" {
if err := pathsafe.ValidateOpaqueSegment(id); err != nil {
campaignErr = fmt.Errorf("pipeline.campaigns.default_campaign_id: %w", err)
}
}
if err := validateStorage(cfg.Storage); err != nil {
return err
}
if err := validateSpool(cfg.Spool); err != nil {
return err
}
if err := validateCache(cfg.Cache); err != nil {
return err
}
if err := validateNotarius(cfg.Notarius, cfg.Scriptorium); err != nil {
return err
}
if err := validateCleanupPublishPolicy(cfg); err != nil {
return err
}
if err := validateWhisperX(cfg.WhisperX); err != nil {
return err
}
if err := validateSeriatim(cfg.Seriatim); err != nil {
return err
}
if err := validateAudita(cfg.Audita); err != nil {
return err
}
if err := validateNormalize(cfg.Normalize); err != nil {
return err
}
if err := validateTrim(cfg.Trim); err != nil {
return err
}
if err := validateRender(cfg.Render); err != nil {
return err
}
if err := validateScriptoriumConfiguration(cfg.Scriptorium); err != nil {
return err
}
if err := validateNotification(cfg.Notification); err != nil {
return err
return []pipelineConfigurationIssue{
{[]string{"workspace", "root"}, workspaceErr},
{[]string{"campaigns", "default_campaign_id"}, campaignErr},
{[]string{"storage"}, validateStorage(cfg.Storage)},
{[]string{"spool"}, validateSpool(cfg.Spool)},
{[]string{"cache"}, validateCache(cfg.Cache)},
{[]string{"notarius"}, validateNotarius(cfg.Notarius, cfg.Scriptorium)},
{[]string{"publish"}, validateCleanupPublishPolicy(cfg)},
{[]string{"whisperx"}, validateWhisperX(cfg.WhisperX)},
{[]string{"seriatim"}, validateSeriatim(cfg.Seriatim)},
{[]string{"audita"}, validateAudita(cfg.Audita)},
{[]string{"normalize"}, validateNormalize(cfg.Normalize)},
{[]string{"trim"}, validateTrim(cfg.Trim)},
{[]string{"render"}, validateRender(cfg.Render)},
{[]string{"scriptorium"}, validateScriptoriumConfiguration(cfg.Scriptorium)},
{[]string{"notification"}, validateNotification(cfg.Notification)},
}
}
func validatePipeline(cfg *PipelineConfig) error {
for _, issue := range pipelineConfigurationIssues(cfg) {
if issue.err != nil {
return issue.err
}
}
return nil
}