diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 5ec4e92..bfa02b5 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -354,6 +354,16 @@ used consistently, and app-only acquisition avoids unrelated inputs/services. ## Stage 8: Expose genuine configuration scopes through ckconfig +**Completed.** Installed native app (default), campaign, session, and party +scopes using retained typed results, native diagnostics, and lazy acquisition. +Pipeline file-local checks now run within ConfigKit validation. Removed the +handwritten config dispatcher, show/validation/source renderers, and synthetic +source reconciliation; comparison and domain-catalog conversion retain their +scheduled owners. Native scope/path/explanation, filtered validation, aggregate +failure, lazy discovery, secret-safe bundle inspection, and bounded execution +checks pass. Configuration, stage, and artifact suites and builds pass with Go +1.27.4; remaining command and comparison tests await their scheduled conversion. + Read: upstream `Suite`, `Selector`, `FromConfigKit`, `AdaptDiagnostics`, and the native configuration CLI contract; Narratio's old `config_commands.go`. diff --git a/internal/app/assembled_workflow_test.go b/internal/app/assembled_workflow_test.go index 0b06551..19ea644 100644 --- a/internal/app/assembled_workflow_test.go +++ b/internal/app/assembled_workflow_test.go @@ -3,7 +3,6 @@ package app import ( "bytes" "context" - "io" "os" "path/filepath" "reflect" @@ -253,19 +252,8 @@ func TestAssembledSplitBundleCommandsUseOneEffectiveFamilyConfiguration(t *testi t.Fatalf("example workspace stat = %v, want absent", err) } - var validated bytes.Buffer - if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &validated); err != nil { - t.Fatalf("validate production base: %v", err) - } - if !strings.Contains(validated.String(), "overlay=none") { - t.Fatalf("validate output = %q, want production base", validated.String()) - } - for _, command := range []func(context.Context, []string, io.Writer) error{ConfigShow, ConfigSources} { - if err := command(context.Background(), []string{ - "--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing", - }, io.Discard); err != nil { - t.Fatalf("testing inspection command %T: %v", command, err) - } + for _, operation := range []string{"validate", "show", "sources"} { + nativeInspectionForTest(t, []string{"config", operation, "--config", pipelinePath, "--overlay", "testing"}) } var diff bytes.Buffer if err := ConfigDiff(context.Background(), []string{ diff --git a/internal/app/catalog_execution_test.go b/internal/app/catalog_execution_test.go index f90d0ed..406ead5 100644 --- a/internal/app/catalog_execution_test.go +++ b/internal/app/catalog_execution_test.go @@ -23,7 +23,9 @@ import ( func TestSelectedPartyCatalogDrivesBoundedAnalysis(t *testing.T) { dir := t.TempDir() pipelinePath := filepath.Join(dir, "pipeline.yml") - mustWriteTestFile(t, pipelinePath, `workspace: + mustWriteTestFile(t, pipelinePath, `whisperx: + transcribe_url: https://transcription.example.test/transcribe +workspace: root: `+filepath.Join(dir, "work")+` scriptorium: artifact_families: diff --git a/internal/app/commands.go b/internal/app/commands.go index cd888ba..20e5b69 100644 --- a/internal/app/commands.go +++ b/internal/app/commands.go @@ -16,6 +16,7 @@ func NewApplication() (*commandkit.App, error) { func newApplication(deps commandDependencies, executor pipelineExecutor) (*commandkit.App, error) { return commandkit.New( commandkit.Identity{Name: "narratio", Version: buildinfo.Version}, + configurationCommand(deps), commandkit.Group("artifacts", "Inspect and regenerate configured artifacts."), commandkit.Group("session", "Manage and inspect sessions."), ) diff --git a/internal/app/config_artifacts_test.go b/internal/app/config_artifacts_test.go index a17fabd..284a557 100644 --- a/internal/app/config_artifacts_test.go +++ b/internal/app/config_artifacts_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "errors" - "io" "path/filepath" "reflect" "strings" @@ -100,156 +99,6 @@ func TestConfigArtifactsReportsOverlayFamilyContributors(t *testing.T) { t.Fatalf("generated family definitions = %#v", got) } - var sources bytes.Buffer - if err := ConfigSources(context.Background(), args, &sources); err != nil { - t.Fatal(err) - } - want := "scriptorium.artifacts.character_note_arannis.prompt_id\tfamily\t" + overlayPath - if !strings.Contains(sources.String(), want) { - t.Fatalf("sources output missing overlay family contributor %q:\n%s", want, sources.String()) - } -} - -func TestConfigInspectionReportsInheritedCompositeSources(t *testing.T) { - t.Setenv("NARRATIO_CONFIG_INSPECTION_KEY", "synthetic-inspection-secret") - pipelinePath, campaignPath := writeInspectionFamilyConfig(t) - dir := filepath.Dir(pipelinePath) - parentPath := filepath.Join(dir, "families", "parent.yml") - childPath := filepath.Join(dir, "families", "child.yml") - overlayPath := filepath.Join(dir, "overlays", "testing.yml") - mustWriteTestFile(t, pipelinePath, `config: - imports: - - path: families/parent.yml - - path: families/child.yml -workspace: - root: `+filepath.Join(dir, "workspace")+` -campaigns: - root: `+filepath.Join(dir, "campaigns")+` -whisperx: - transcribe_url: https://transcription.example.com/transcribe -audita: - credentials: [NARRATIO_CONFIG_INSPECTION_KEY] -scriptorium: - extends: audita -`) - mustWriteTestFile(t, parentPath, `scriptorium: - artifact_families: - character_meta: - enabled: false - for_each: party.characters - prompt_id: dnd.character_meta - profile_id: production - output_path_pattern: artifacts/characters/{character_id}/meta.md - artifacts: - notes: - enabled: false - prompt_id: dnd.notes -`) - mustWriteTestFile(t, childPath, `scriptorium: - artifact_families: - character_note: - extends: character_meta - profile_id: testing - output_path_pattern: artifacts/characters/{character_id}/note.md - artifacts: - notes: - output_path: artifacts/notes.md -`) - mustWriteTestFile(t, overlayPath, `scriptorium: - artifact_families: - character_note: - prompt_id: dnd.character_note.testing - artifacts: - notes: - output_path: artifacts/notes-testing.md -`) - expandedOverlayPath := filepath.Join(dir, "overlays", "expanded.yml") - mustWriteTestFile(t, expandedOverlayPath, `scriptorium: - extends: null - credentials: [NARRATIO_CONFIG_INSPECTION_KEY] - artifact_families: - character_note: - enabled: false - for_each: party.characters - prompt_id: dnd.character_note.testing - profile_id: testing - output_path_pattern: artifacts/characters/{character_id}/note.md - artifacts: - notes: - output_path: artifacts/notes-testing.md -`) - args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"} - if err := ConfigValidate(context.Background(), args, io.Discard); err != nil { - t.Fatalf("ConfigValidate() error = %v", err) - } - var effective bytes.Buffer - if err := ConfigShow(context.Background(), args, &effective); err != nil { - t.Fatalf("ConfigShow() error = %v", err) - } - for _, want := range []string{"NARRATIO_CONFIG_INSPECTION_KEY", "character_note_arannis:", "dnd.character_note.testing", "artifacts/characters/arannis/note.md"} { - if !strings.Contains(effective.String(), want) { - t.Errorf("effective show omitted %q:\n%s", want, effective.String()) - } - } - if strings.Contains(effective.String(), "synthetic-inspection-secret") { - t.Fatal("effective show exposed a credential value") - } - - var catalog bytes.Buffer - if err := ConfigArtifacts(context.Background(), args, &catalog); err != nil { - t.Fatal(err) - } - records := catalogRecordsByKey(t, catalog.String()) - notes := records["notes"] - if strings.Contains(catalog.String(), "synthetic-inspection-secret") { - t.Fatal("artifact catalog exposed a credential value") - } - if notes[4] != "artifacts/notes-testing.md" { - t.Fatalf("composed artifact output = %#v", notes) - } - for _, contributor := range []string{parentPath, childPath, overlayPath} { - if !strings.Contains(notes[2], contributor) { - t.Errorf("composed artifact definitions %q omit %q", notes[2], contributor) - } - } - - note := records["character_note_arannis"] - if note[4] != "artifacts/characters/arannis/note.md" || note[6] != "character_note" || note[7] != "arannis" { - t.Fatalf("inherited family catalog identity and output = %#v", note) - } - for _, contributor := range []string{parentPath, childPath, overlayPath} { - if !strings.Contains(note[2], contributor) || !strings.Contains(note[8], contributor) { - t.Errorf("family provenance = definitions %q, family sources %q; want %q", note[2], note[8], contributor) - } - } - - var sources bytes.Buffer - if err := ConfigSources(context.Background(), args, &sources); err != nil { - t.Fatal(err) - } - for _, want := range []string{ - "scriptorium.artifacts.notes.output_path\toverlay\t" + overlayPath, - "scriptorium.artifacts.character_note_arannis.output_path\tfamily\t" + childPath, - "scriptorium.artifacts.character_note_arannis.prompt_id\tfamily\t" + overlayPath, - "scriptorium.credentials\troot\t" + pipelinePath, - } { - if !strings.Contains(sources.String(), want) { - t.Errorf("effective source output missing %q:\n%s", want, sources.String()) - } - } - if strings.Contains(sources.String(), "synthetic-inspection-secret") { - t.Fatal("source inspection exposed a credential value") - } - var diff bytes.Buffer - if err := ConfigDiff(context.Background(), []string{"testing", "expanded", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil { - t.Fatalf("ConfigDiff() error = %v", err) - } - if diff.String() != "no differences\n" { - t.Fatalf("equivalent inherited/expanded overlays diff = %q", diff.String()) - } - if strings.Contains(diff.String(), "synthetic-inspection-secret") { - t.Fatal("configuration diff exposed a credential value") - } } func TestConfigArtifactsReportsBaseAndOverlayContributors(t *testing.T) { diff --git a/internal/app/config_commands.go b/internal/app/config_commands.go index cde3e42..ad2125f 100644 --- a/internal/app/config_commands.go +++ b/internal/app/config_commands.go @@ -30,125 +30,6 @@ type inspectionConfig struct { ArtifactCatalog *config.ArtifactCatalog } -// Config dispatches read-only pipeline configuration commands. -func Config(ctx context.Context, args []string, out io.Writer) error { - return configWithDependencies(ctx, args, out, commandDependencies{}) -} - -func configWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error { - deps = normalizeCommandDependencies(deps) - if len(args) == 0 { - return fmt.Errorf("config: expected subcommand: validate|show|sources|artifacts|diff") - } - if args[0] == "--help" || args[0] == "-h" { - writeConfigCommandUsage(out) - return nil - } - switch args[0] { - case "validate": - return configValidateWithDependencies(ctx, args[1:], out, deps) - case "show": - return configShowWithDependencies(ctx, args[1:], out, deps) - case "sources": - return configSourcesWithDependencies(ctx, args[1:], out, deps) - case "artifacts": - return configArtifactsWithDependencies(ctx, args[1:], out, deps) - case "diff": - return configDiffWithDependencies(ctx, args[1:], out, deps) - default: - return fmt.Errorf("config: unknown subcommand %q", args[0]) - } -} - -// ConfigValidate validates one fully resolved effective pipeline without -// loading session state or constructing runtime collaborators. -func ConfigValidate(ctx context.Context, args []string, out io.Writer) error { - return configValidateWithDependencies(ctx, args, out, commandDependencies{}) -} - -func configValidateWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error { - flags, err := parseInspectionFlags("config validate", args, out) - if err != nil { - if errors.Is(err, flag.ErrHelp) { - return nil - } - return err - } - resolved, err := resolveInspectionConfigWithDependencies(flags, deps) - if err != nil { - return fmt.Errorf("config validate: %w", err) - } - _, err = fmt.Fprintf(out, "Configuration valid: root=%s; overlay=%s; digest=%s\n", - inspectionRootPath(resolved), inspectionOverlay(resolved.Pipeline), config.EffectivePipelineDigest(resolved.Pipeline)) - return err -} - -// ConfigShow validates and renders one fully resolved effective pipeline -// without loading session state or constructing runtime collaborators. -func ConfigShow(ctx context.Context, args []string, out io.Writer) error { - return configShowWithDependencies(ctx, args, out, commandDependencies{}) -} - -func configShowWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error { - flags, err := parseInspectionFlags("config show", args, out) - if err != nil { - if errors.Is(err, flag.ErrHelp) { - return nil - } - return err - } - resolved, err := resolveInspectionConfigWithDependencies(flags, deps) - if err != nil { - return fmt.Errorf("config show: %w", err) - } - data, err := config.MarshalEffectivePipeline(resolved.Pipeline) - if err != nil { - return fmt.Errorf("config show: %w", err) - } - _, err = out.Write(data) - return err -} - -// ConfigSources validates and reports deterministic effective configuration -// ownership without loading session state or runtime collaborators. -func ConfigSources(ctx context.Context, args []string, out io.Writer) error { - return configSourcesWithDependencies(ctx, args, out, commandDependencies{}) -} - -func configSourcesWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error { - flags, err := parseInspectionFlags("config sources", args, out) - if err != nil { - if errors.Is(err, flag.ErrHelp) { - return nil - } - return err - } - resolved, err := resolveInspectionConfigWithDependencies(flags, deps) - if err != nil { - return fmt.Errorf("config sources: %w", err) - } - records, err := config.EffectivePipelineSources(resolved.Pipeline, resolved.Party) - if err != nil { - return fmt.Errorf("config sources: %w", err) - } - records = append(records, config.EffectiveCampaignSources(resolved.CampaignPath, resolved.Campaign, resolved.Party)...) - sortInspectionSourceRecords(records) - if err := writeInspectionSourceHeader(out, resolved); err != nil { - return err - } - for _, record := range records { - if _, err := fmt.Fprintf(out, "%s\t%s\t%s\n", record.Path, record.Role, record.Source); err != nil { - return err - } - } - for _, selection := range config.EffectiveEmptyImports(resolved.Pipeline, resolved.Campaign) { - if _, err := fmt.Fprintf(out, "empty_import\t%s\t%s\t%s:%d:%d\n", selection.Path, selection.Selector, selection.Source, selection.Line, selection.Column); err != nil { - return err - } - } - return nil -} - // ConfigArtifacts validates and reports the effective concrete artifact catalog // without loading session state or runtime collaborators. func ConfigArtifacts(ctx context.Context, args []string, out io.Writer) error { @@ -312,82 +193,3 @@ func validateInspectionCampaign(path string, campaign *config.CampaignConfig) er } return nil } - -func inspectionRootPath(resolved *inspectionConfig) string { - if resolved == nil { - return "" - } - if root := config.EffectivePipelineRootPath(resolved.Pipeline); root != "" { - return root - } - return resolved.PipelinePath -} - -func inspectionOverlay(pipeline *config.PipelineConfig) string { - if overlay, ok := config.SelectedPipelineOverlay(pipeline); ok { - return overlay.Name - } - return "none" -} - -func writeConfigCommandUsage(out io.Writer) { - fmt.Fprintln(out, "Usage: narratio config ") - fmt.Fprintln(out) - fmt.Fprintln(out, "Use config validate to check an effective pipeline, config show to print normalized YAML, config sources to report ownership, config artifacts to list concrete artifacts, or config diff to compare two overlays.") -} - -func writeInspectionSourceHeader(out io.Writer, resolved *inspectionConfig) error { - if _, err := fmt.Fprintf(out, "root: %s\n", inspectionRootPath(resolved)); err != nil { - return err - } - imports := config.EffectivePipelineImports(resolved.Pipeline) - if len(imports) == 0 { - if _, err := fmt.Fprintln(out, "imports: none"); err != nil { - return err - } - } - for _, imported := range imports { - if _, err := fmt.Fprintf(out, "import: %s\n", config.NormalizedConfigurationPath(imported)); err != nil { - return err - } - } - if overlay, ok := config.SelectedPipelineOverlay(resolved.Pipeline); ok { - if _, err := fmt.Fprintf(out, "overlay: name=%s selection=%s path=%s\n", overlay.Name, overlay.Source, config.NormalizedConfigurationPath(overlay.OverlayPath)); err != nil { - return err - } - } else if _, err := fmt.Fprintln(out, "overlay: none"); err != nil { - return err - } - if resolved.Campaign == nil { - if _, err := fmt.Fprintln(out, "campaign: none"); err != nil { - return err - } - if _, err := fmt.Fprintln(out, "party: none"); err != nil { - return err - } - } else { - if _, err := fmt.Fprintf(out, "campaign: id=%s source=%s\n", config.CampaignID(resolved.Campaign), config.NormalizedConfigurationPath(resolved.CampaignPath)); err != nil { - return err - } - if _, err := fmt.Fprintf(out, "party: source=%s\n", config.NormalizedConfigurationPath(resolved.Party.Source.Path)); err != nil { - return err - } - } - if _, err := fmt.Fprintf(out, "digest: %s\n", config.EffectivePipelineDigest(resolved.Pipeline)); err != nil { - return err - } - _, err := fmt.Fprintln(out, "path\trole\tsource") - return err -} - -func sortInspectionSourceRecords(records []config.EffectivePipelineSourceRecord) { - 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 - }) -} diff --git a/internal/app/config_commands_test.go b/internal/app/config_commands_test.go index 4b2b545..1c56e95 100644 --- a/internal/app/config_commands_test.go +++ b/internal/app/config_commands_test.go @@ -4,8 +4,6 @@ import ( "bytes" "context" "io" - "net/http" - "net/http/httptest" "os" "path/filepath" "strings" @@ -15,47 +13,12 @@ import ( configkit "go.maximumdirect.net/configkit" ) -func TestConfigCommandHelpAndDispatch(t *testing.T) { - for _, test := range []struct { - name string - args []string - want string - code int - }{ - {name: "top level help", args: []string{"config", "--help"}, want: "Usage: narratio config "}, - {name: "validate help", args: []string{"config", "validate", "--help"}, want: "Usage: narratio config validate"}, - {name: "show help", args: []string{"config", "show", "--help"}, want: "Usage: narratio config show"}, - {name: "sources help", args: []string{"config", "sources", "--help"}, want: "Usage: narratio config sources"}, - {name: "artifacts help", args: []string{"config", "artifacts", "--help"}, want: "Usage: narratio config artifacts"}, - {name: "diff help", args: []string{"config", "diff", "--help"}, want: "Usage: narratio config diff"}, - {name: "unknown", args: []string{"config", "unknown"}, want: `config: unknown subcommand "unknown"`, code: 1}, - {name: "missing", args: []string{"config"}, want: "config: expected subcommand: validate|show|sources|artifacts|diff", code: 1}, - {name: "session flag", args: []string{"config", "validate", "--session", "session.yml"}, want: "flag provided but not defined", code: 1}, - {name: "stage flag", args: []string{"config", "show", "--from", "prepare"}, want: "flag provided but not defined", code: 1}, - {name: "force flag", args: []string{"config", "show", "--force"}, want: "flag provided but not defined", code: 1}, - {name: "artifact flag", args: []string{"config", "show", "--artifacts", "recap"}, want: "flag provided but not defined", code: 1}, - {name: "retired selector", args: []string{"config", "validate", "--profile", "testing"}, want: "flag provided but not defined", code: 1}, - } { - t.Run(test.name, func(t *testing.T) { - var stdout, stderr bytes.Buffer - code := executeForTest(test.args, &stdout, &stderr) - if code != test.code { - t.Fatalf("exit code = %d, want %d; stdout=%q stderr=%q", code, test.code, stdout.String(), stderr.String()) - } - combined := stdout.String() + stderr.String() - if !strings.Contains(combined, test.want) { - t.Fatalf("output = %q, want %q", combined, test.want) - } - }) - } -} - func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) { dir := t.TempDir() pipelinePath := filepath.Join(dir, "pipeline.yml") mustWriteTestFile(t, pipelinePath, "workspace:\n root: "+filepath.Join(dir, "workspace")+"\nwhisperx:\n transcribe_url: https://transcription.example.com/transcribe\n") - for _, subcommand := range []string{"validate", "show", "sources", "artifacts"} { + for _, subcommand := range []string{"validate", "show", "sources"} { t.Run(subcommand, func(t *testing.T) { calls := 0 deps := commandDependencies{ @@ -82,68 +45,6 @@ func TestExecuteConfigUsesInvocationPipelineLoader(t *testing.T) { } } -func TestConfigValidateAndShowPipelineOnlyAreSideEffectFree(t *testing.T) { - dir := t.TempDir() - workspaceRoot := filepath.Join(dir, "workspace-does-not-exist") - pipelinePath := filepath.Join(dir, "pipeline.yml") - secretsDir := filepath.Join(dir, "secrets") - const secret = "inspection-secret-must-not-escape" - mustWriteTestFile(t, filepath.Join(secretsDir, "INSPECTION_SECRET"), secret+"\n") - calls := 0 - server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { calls++ })) - defer server.Close() - mustWriteTestFile(t, pipelinePath, `workspace: - root: `+workspaceRoot+` -whisperx: - transcribe_url: `+server.URL+` -`) - t.Setenv("INSPECTION_SECRET", secret) - - var validateOut bytes.Buffer - if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &validateOut); err != nil { - t.Fatalf("ConfigValidate() error = %v", err) - } - if !strings.Contains(validateOut.String(), "Configuration valid: root=") || !strings.Contains(validateOut.String(), "; overlay=none; digest=") { - t.Fatalf("validate output = %q", validateOut.String()) - } - - var showOut bytes.Buffer - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath}, &showOut); err != nil { - t.Fatalf("ConfigShow() error = %v", err) - } - show := showOut.String() - if !strings.HasSuffix(show, "\n") || !strings.Contains(show, "workspace:\n") || !strings.Contains(show, "root: "+workspaceRoot) { - t.Fatalf("show output = %q", show) - } - if strings.Contains(show, "artifact_families") || strings.Contains(show, "resolution") { - t.Fatalf("show output leaked resolution-only fields: %q", show) - } - if strings.Contains(show, secret) { - t.Fatalf("show output leaked a raw secret: %q", show) - } - var sourcesOut bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", pipelinePath}, &sourcesOut); err != nil { - t.Fatalf("ConfigSources() error = %v", err) - } - if strings.Contains(sourcesOut.String(), secret) { - t.Fatalf("sources output leaked a raw secret: %q", sourcesOut.String()) - } - writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n") - var diffOut bytes.Buffer - if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &diffOut); err != nil { - t.Fatalf("ConfigDiff() error = %v", err) - } - if strings.Contains(diffOut.String(), secret) { - t.Fatalf("diff output leaked a raw secret: %q", diffOut.String()) - } - if calls != 0 { - t.Fatalf("inspection invoked configured external endpoint %d time(s)", calls) - } - if _, err := os.Stat(workspaceRoot); !os.IsNotExist(err) { - t.Fatalf("workspace root stat error = %v, want absent", err) - } -} - func TestConfigDiffReportsSemanticOverlayChanges(t *testing.T) { workspaceRoot := t.TempDir() pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot) @@ -208,56 +109,6 @@ scriptorium: } } -func TestConfigShowPreservesNullAndEmptyCollections(t *testing.T) { - dir := t.TempDir() - pipelinePath := filepath.Join(dir, "pipeline.yml") - mustWriteTestFile(t, pipelinePath, `workspace: - root: /tmp/narratio-work -whisperx: - transcribe_url: https://transcription.example.test/transcribe -audita: - modules: null -scriptorium: - artifacts: null -`) - mustWriteTestFile(t, filepath.Join(dir, "overlays", "empty.yml"), `audita: - modules: [] -scriptorium: - artifacts: {} -`) - - var base, empty bytes.Buffer - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath}, &base); err != nil { - t.Fatal(err) - } - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "empty"}, &empty); err != nil { - t.Fatal(err) - } - for _, want := range []string{"modules: null\n", "artifacts: null\n"} { - if !strings.Contains(base.String(), want) { - t.Fatalf("base show output missing %q:\n%s", want, base.String()) - } - } - for _, want := range []string{"modules: []\n", "artifacts: {}\n"} { - if !strings.Contains(empty.String(), want) { - t.Fatalf("empty-overlay show output missing %q:\n%s", want, empty.String()) - } - } - - var diff bytes.Buffer - if err := ConfigDiff(context.Background(), []string{"default", "empty", "--config", pipelinePath}, &diff); err != nil { - t.Fatal(err) - } - for _, want := range []string{ - "changed\t/audita/modules\tnull\t[]\n", - "changed\t/scriptorium/artifacts\tnull\t{}\n", - } { - if !strings.Contains(diff.String(), want) { - t.Fatalf("diff output missing %q:\n%s", want, diff.String()) - } - } -} - func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) { pipelinePath, campaignPath := writeInspectionFamilyConfig(t) writeInspectionOverlays(t, pipelinePath, `scriptorium: @@ -374,126 +225,6 @@ func TestConfigDiffBootstrapsSecretsOnceForBothOverlays(t *testing.T) { } } -func TestConfigInspectionOutputsNeverExposeResolvedCredentialValues(t *testing.T) { - const firstCanary = "inspection-credential-canary-one" - const secondCanary = "inspection-credential-canary-two" - for name, value := range map[string]string{ - "NARRATIO_INSPECT_ACCESS": firstCanary, - "NARRATIO_INSPECT_SECRET": firstCanary, - "NARRATIO_INSPECT_LLM_ONE": firstCanary, - "NARRATIO_INSPECT_LLM_TWO": secondCanary, - "NARRATIO_INSPECT_NOTARIUS_ONE": firstCanary, - "NARRATIO_INSPECT_NOTARIUS_TWO": secondCanary, - } { - t.Setenv(name, value) - } - workspaceRoot := t.TempDir() - pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot) - pipelineData, err := os.ReadFile(pipelinePath) - if err != nil { - t.Fatal(err) - } - pipelineYAML := strings.Replace(string(pipelineData), " bucket: test-bucket\n", ` bucket: test-bucket - access_key_id: NARRATIO_INSPECT_ACCESS - secret_access_key: NARRATIO_INSPECT_SECRET -`, 1) - pipelineYAML += `notarius: - enabled: false - credentials: [NARRATIO_INSPECT_NOTARIUS_ONE] -` - if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil { - t.Fatal(err) - } - writeInspectionOverlays(t, pipelinePath, - "audita:\n proposal_profile: production\n credentials: [NARRATIO_INSPECT_LLM_ONE]\n", - "audita:\n proposal_profile: testing\n credentials: [NARRATIO_INSPECT_LLM_TWO]\nnotarius:\n credentials: [NARRATIO_INSPECT_NOTARIUS_TWO]\n", - ) - mustWriteTestFile(t, filepath.Join(filepath.Dir(pipelinePath), "overlays", "without-notarius-key.yml"), "notarius:\n credentials: []\n") - - var validate bytes.Buffer - if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &validate); err != nil { - t.Fatalf("config validate: %v", err) - } - - var show bytes.Buffer - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &show); err != nil { - t.Fatalf("config show: %v", err) - } - var sources bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &sources); err != nil { - t.Fatalf("config sources: %v", err) - } - var catalog bytes.Buffer - if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &catalog); err != nil { - t.Fatalf("config artifacts: %v", err) - } - var diff bytes.Buffer - if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &diff); err != nil { - t.Fatalf("config diff: %v", err) - } - var removed bytes.Buffer - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "without-notarius-key"}, &removed); err != nil { - t.Fatalf("config show with removed Notarius credential: %v", err) - } - for label, output := range map[string]string{"show": show.String(), "sources": sources.String(), "artifacts": catalog.String(), "diff": diff.String()} { - if strings.Contains(output, firstCanary) || strings.Contains(output, secondCanary) { - t.Fatalf("%s output exposed credential value: %q", label, output) - } - } - for _, reference := range []string{"NARRATIO_INSPECT_ACCESS", "NARRATIO_INSPECT_SECRET", "NARRATIO_INSPECT_LLM_ONE", "NARRATIO_INSPECT_NOTARIUS_ONE"} { - if !strings.Contains(show.String(), reference) { - t.Fatalf("show omitted safe credential reference %q: %q", reference, show.String()) - } - } - if !strings.Contains(diff.String(), "NARRATIO_INSPECT_LLM_ONE") || !strings.Contains(diff.String(), "NARRATIO_INSPECT_LLM_TWO") || - !strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") || !strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_TWO") { - t.Fatalf("diff omitted safe credential references: %q", diff.String()) - } - if !strings.Contains(sources.String(), "notarius.credentials") { - t.Fatalf("sources omitted Notarius credential ownership: %q", sources.String()) - } - if strings.Contains(removed.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") { - t.Fatalf("empty overlay did not remove Notarius credential: %q", removed.String()) - } -} - -func TestConfigValidateRejectsUnavailableNotariusCredential(t *testing.T) { - const envName = "NARRATIO_INSPECT_NOTARIUS_MISSING" - restoreEnvAfterTest(t, envName) - path := filepath.Join(t.TempDir(), "pipeline.yml") - mustWriteTestFile(t, path, "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n") - err := ConfigValidate(context.Background(), []string{"--config", path}, io.Discard) - if err == nil || !strings.Contains(err.Error(), "secret.unset") { - t.Fatalf("ConfigValidate() error = %v, want unavailable credential failure", err) - } -} - -func TestConfigCommandsInspectMaintainedSplitBundleWithoutRuntimeState(t *testing.T) { - examplesDir := filepath.Join("..", "..", "examples") - pipelinePath := filepath.Join(examplesDir, "production-testing", "pipeline.yml") - campaignPath := filepath.Join(examplesDir, "campaigns", "sample-campaign", "campaign.yml") - workspacePath := filepath.Join(examplesDir, "production-testing", "workspace") - if _, err := os.Stat(workspacePath); !os.IsNotExist(err) { - t.Fatalf("example workspace stat = %v, want absent", err) - } - - for _, command := range []func(context.Context, []string, io.Writer) error{ConfigValidate, ConfigShow, ConfigSources, ConfigArtifacts} { - if err := command(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, io.Discard); err != nil { - t.Fatalf("inspection command %T error = %v", command, err) - } - } - var diff bytes.Buffer - if err := ConfigDiff(context.Background(), []string{"default", "testing", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil { - t.Fatalf("ConfigDiff() error = %v", err) - } - if !strings.Contains(diff.String(), "/audita/proposal_profile") { - t.Fatalf("split bundle overlay diff = %q, want proposal profile change", diff.String()) - } - if _, err := os.Stat(workspacePath); !os.IsNotExist(err) { - t.Fatalf("inspection created example workspace: %v", err) - } -} - func writeInspectionOverlays(t *testing.T, pipelinePath, production, testing string) { t.Helper() overlaysDir := filepath.Join(filepath.Dir(pipelinePath), "overlays") @@ -501,278 +232,6 @@ func writeInspectionOverlays(t *testing.T, pipelinePath, production, testing str mustWriteTestFile(t, filepath.Join(overlaysDir, "testing.yml"), testing) } -func TestConfigCommandsSelectOverlaysAndCampaigns(t *testing.T) { - workspaceRoot := t.TempDir() - pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot) - enableCommandTestOverlays(t, pipelinePath) - - var defaultOut bytes.Buffer - if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &defaultOut); err != nil { - t.Fatalf("default ConfigValidate() error = %v", err) - } - if !strings.Contains(defaultOut.String(), "overlay=none") { - t.Fatalf("default output = %q", defaultOut.String()) - } - - var explicitOut bytes.Buffer - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &explicitOut); err != nil { - t.Fatalf("explicit ConfigShow() error = %v", err) - } - if !strings.Contains(explicitOut.String(), "language: fr") { - t.Fatalf("explicit show output = %q", explicitOut.String()) - } - - for _, args := range [][]string{ - {"--config", pipelinePath, "--campaign", "sample-campaign"}, - {"--config", pipelinePath, "--campaign-file", campaignPath}, - } { - var out bytes.Buffer - if err := ConfigValidate(context.Background(), args, &out); err != nil { - t.Fatalf("ConfigValidate(%q) error = %v", args, err) - } - } -} - -func TestConfigCommandsExpandFamiliesAndRequireCampaign(t *testing.T) { - pipelinePath, campaignPath := writeInspectionFamilyConfig(t) - - for _, command := range []func(context.Context, []string, io.Writer) error{ConfigValidate, ConfigShow, ConfigArtifacts} { - var out bytes.Buffer - err := command(context.Background(), []string{"--config", pipelinePath}, &out) - if err == nil || !strings.Contains(err.Error(), "artifact_families requires a campaign") { - t.Fatalf("family command without campaign error = %v", err) - } - } - - var show bytes.Buffer - if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &show); err != nil { - t.Fatalf("ConfigShow() error = %v", err) - } - if !strings.Contains(show.String(), "character_note_arannis:") || strings.Contains(show.String(), "artifact_families") { - t.Fatalf("expanded show output = %q", show.String()) - } - - loadedPipeline, err := config.LoadPipeline(pipelinePath) - if err != nil { - t.Fatal(err) - } - loadedCampaign, err := config.LoadCampaign(campaignPath) - if err != nil { - t.Fatal(err) - } - loaded, err := config.LoadPipelineCampaign(pipelinePath, loadedPipeline, campaignPath, loadedCampaign) - if err != nil { - t.Fatal(err) - } - var validateOut bytes.Buffer - if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &validateOut); err != nil { - t.Fatal(err) - } - if !strings.Contains(validateOut.String(), "digest="+config.EffectivePipelineDigest(loaded.Pipeline)) { - t.Fatalf("inspection digest = %q, want %q", validateOut.String(), config.EffectivePipelineDigest(loaded.Pipeline)) - } -} - -func TestConfigValidateReportsCanonicalPartyAndImportErrors(t *testing.T) { - pipelinePath, campaignPath := writeInspectionFamilyConfig(t) - mustWriteTestFile(t, filepath.Join(filepath.Dir(campaignPath), "party.yml"), "schema_version: narratio.party.v2\ncharacters: {}\n") - if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, io.Discard); err == nil || !strings.Contains(err.Error(), "unsupported") { - t.Fatalf("canonical party error = %v", err) - } - - dir := t.TempDir() - rootPath := filepath.Join(dir, "pipeline.yml") - mustWriteTestFile(t, rootPath, `config: - imports: - - path: conf.yml -workspace: - root: /one -whisperx: - transcribe_url: https://transcription.example.com/transcribe -`) - mustWriteTestFile(t, filepath.Join(dir, "conf.yml"), "workspace:\n root: /two\n") - err := ConfigValidate(context.Background(), []string{"--config", rootPath}, io.Discard) - if err == nil || !strings.Contains(err.Error(), "/workspace/root") || !strings.Contains(err.Error(), "pipeline.yml") || !strings.Contains(err.Error(), "conf.yml") { - t.Fatalf("import diagnostic = %v", err) - } -} - -func TestConfigSourcesReportsStableOwnership(t *testing.T) { - workspaceRoot := t.TempDir() - pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot) - enableCommandTestOverlays(t, pipelinePath) - - args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"} - var first, second bytes.Buffer - if err := ConfigSources(context.Background(), args, &first); err != nil { - t.Fatalf("first ConfigSources() error = %v", err) - } - if err := ConfigSources(context.Background(), args, &second); err != nil { - t.Fatalf("second ConfigSources() error = %v", err) - } - if first.String() != second.String() { - t.Fatalf("sources output is not deterministic:\nfirst=%q\nsecond=%q", first.String(), second.String()) - } - output := first.String() - for _, want := range []string{ - "root: ", - "imports: none", - "overlay: name=testing selection=explicit path=", - "campaign: id=sample-campaign source=", - "party: source=", - "digest: ", - "path\trole\tsource\n", - "workspace.root\troot\t", - "whisperx.language\toverlay\t", - "derived.players\tparty\t", - "trim.enabled\tdefault\tdefault", - } { - if !strings.Contains(output, want) { - t.Fatalf("sources output missing %q:\n%s", want, output) - } - } -} - -func TestConfigSourcesReportsCanonicalFamilyAndPublishOrigins(t *testing.T) { - pipelinePath, campaignPath := writeInspectionFamilyConfig(t) - var out bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &out); err != nil { - t.Fatalf("ConfigSources() error = %v", err) - } - output := out.String() - partyPath := filepath.Join(filepath.Dir(campaignPath), "party.yml") - for _, want := range []string{ - "party: source=" + partyPath, - "derived.players\tparty\t" + partyPath, - "scriptorium.artifacts.character_note_arannis.enabled\tfamily\t" + pipelinePath, - "scriptorium.artifacts.character_note_arannis.enabled\tparty\t" + partyPath, - "scriptorium.artifacts.character_note_arannis.depends_on\tfamily\t" + pipelinePath, - "scriptorium.artifacts.character_note_arannis.inputs.prior.source\tparty\t" + partyPath, - "publish.outputs[", - "\tfamily\t" + pipelinePath, - "\tparty\t" + partyPath, - } { - if !strings.Contains(output, want) { - t.Fatalf("sources output missing %q:\n%s", want, output) - } - } -} - -func TestConfigSourcesPreservesOverlayOwnershipThroughFamilyExpansion(t *testing.T) { - pipelinePath, campaignPath := writeInspectionFamilyConfig(t) - overlayPath := filepath.Join(filepath.Dir(pipelinePath), "overlays", "testing.yml") - mustWriteTestFile(t, overlayPath, `scriptorium: - artifact_families: - character_note: - enabled: true - prompt_id: dnd.character_note -`) - - var out bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}, &out); err != nil { - t.Fatalf("ConfigSources() error = %v", err) - } - want := "scriptorium.artifacts.character_note_arannis.enabled\tfamily\t" + overlayPath - if !strings.Contains(out.String(), want) { - t.Fatalf("sources output missing overlay-generated ownership %q:\n%s", want, out.String()) - } -} - -func TestConfigSourcesAttributesInferredArtifactDependencies(t *testing.T) { - dir := t.TempDir() - pipelinePath := filepath.Join(dir, "pipeline.yml") - inputPath := filepath.Join(dir, "input-only.yml") - overlayPath := filepath.Join(dir, "overlays", "testing.yml") - mustWriteTestFile(t, pipelinePath, `config: - imports: - - path: input-only.yml -workspace: - root: /srv/narratio -whisperx: - transcribe_url: https://transcription.example.test/transcribe -scriptorium: - artifacts: - first: - enabled: false - output_path: artifacts/first.md - second: - enabled: false - output_path: artifacts/second.md - mixed: - enabled: false - output_path: artifacts/mixed.md - depends_on: [first] -`) - mustWriteTestFile(t, inputPath, `scriptorium: - artifacts: - input_only: - enabled: false - output_path: artifacts/input-only.md - inputs: - prior: - source: narratio.artifact.first -`) - mustWriteTestFile(t, overlayPath, `scriptorium: - artifacts: - mixed: - inputs: - prior: - source: narratio.artifact.second -`) - - var out bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &out); err != nil { - t.Fatal(err) - } - for _, want := range []string{ - "scriptorium.artifacts.input_only.depends_on\timport\t" + inputPath, - "scriptorium.artifacts.mixed.depends_on\troot\t" + pipelinePath, - "scriptorium.artifacts.mixed.depends_on\toverlay\t" + overlayPath, - } { - if !strings.Contains(out.String(), want) { - t.Fatalf("sources output missing dependency contributor %q:\n%s", want, out.String()) - } - } - if strings.Contains(out.String(), "scriptorium.artifacts.input_only.depends_on\tdefault\tdefault") { - t.Fatalf("inferred dependency retained default attribution:\n%s", out.String()) - } -} - -func TestConfigSourcesReportsRootImportOverlayAndDefaultOwnership(t *testing.T) { - dir := t.TempDir() - rootPath := filepath.Join(dir, "pipeline.yml") - importPath := filepath.Join(dir, "base.yml") - overlayPath := filepath.Join(dir, "overlays", "testing.yml") - mustWriteTestFile(t, rootPath, `config: - imports: - - path: base.yml -workspace: - root: /srv/narratio -whisperx: - transcribe_url: https://transcription.example.com/transcribe -`) - mustWriteTestFile(t, importPath, "storage:\n backend: local\n") - mustWriteTestFile(t, overlayPath, "whisperx:\n language: fr\n") - - var out bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", rootPath, "--overlay", "testing"}, &out); err != nil { - t.Fatalf("ConfigSources() error = %v", err) - } - output := out.String() - for _, want := range []string{ - "import: " + importPath, - "overlay: name=testing selection=explicit path=" + overlayPath, - "workspace.root\troot\t" + rootPath, - "storage.backend\timport\t" + importPath, - "whisperx.language\toverlay\t" + overlayPath, - "trim.enabled\tdefault\tdefault", - } { - if !strings.Contains(output, want) { - t.Fatalf("sources output missing %q:\n%s", want, output) - } - } -} - func writeInspectionFamilyConfig(t *testing.T) (string, string) { t.Helper() dir := t.TempDir() @@ -859,29 +318,23 @@ func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) { t.Chdir(root) campaign := filepath.Join(bundle, "campaigns", "sample-campaign", "campaign.yml") common := []string{"--campaign-file", campaign, "--secrets-dir", secrets} - for _, tc := range []struct { - name string - run func(context.Context, []string, io.Writer) error - want []string - }{ - {"validate", ConfigValidate, []string{pipeline}}, - {"show", ConfigShow, []string{"NARRATIO_BUNDLE_TEST_KEY", "character_meta_arannis"}}, - {"sources", ConfigSources, []string{"empty_import", "brenna.yml"}}, - {"artifacts", ConfigArtifacts, []string{"session_recap", "character_meta_arannis"}}, - } { - var out bytes.Buffer - if err := tc.run(context.Background(), common, &out); err != nil { - t.Fatalf("%s: %v", tc.name, err) + for _, operation := range []string{"validate", "show", "sources"} { + args := []string{"config", operation, "--secrets-dir", secrets} + out := nativeInspectionForTest(t, args) + if strings.Contains(out, secretValue) { + t.Fatalf("%s exposed credential value", operation) } - for _, want := range tc.want { - if !strings.Contains(out.String(), want) { - t.Errorf("%s output missing %q: %s", tc.name, want, out.String()) - } - } - if strings.Contains(out.String(), secretValue) { - t.Errorf("%s exposed credential value", tc.name) + if operation == "show" && !strings.Contains(out, "artifact_families") { + t.Fatal("native show omitted authored families") } } + var catalog bytes.Buffer + if err := ConfigArtifacts(context.Background(), common, &catalog); err != nil { + t.Fatal(err) + } + if !strings.Contains(catalog.String(), "character_meta_arannis") { + t.Fatal("domain catalog omitted concrete family member") + } var diff bytes.Buffer args := append([]string{"default", "testing"}, common...) if err := ConfigDiff(context.Background(), args, &diff); err != nil { diff --git a/internal/app/config_native_inspection_test.go b/internal/app/config_native_inspection_test.go index fe74e00..74817cf 100644 --- a/internal/app/config_native_inspection_test.go +++ b/internal/app/config_native_inspection_test.go @@ -23,18 +23,3 @@ func TestConfigDiffUsesEscapedPointersAndAtomicLists(t *testing.T) { } } } - -func TestConfigSourcesReportsEmptyOptionalImportAndNormalization(t *testing.T) { - dir := t.TempDir() - root := filepath.Join(dir, "pipeline.yml") - mustWriteTestFile(t, root, "config:\n imports:\n - path: absent.yml\nworkspace: {root: ./work}\nwhisperx: {transcribe_url: 'https://example.test/transcribe'}\n") - var output bytes.Buffer - if err := ConfigSources(context.Background(), []string{"--config", root}, &output); err != nil { - t.Fatal(err) - } - for _, want := range []string{"empty_import\t/config/imports/0\tpath\t" + root, "workspace.root\tresolution\tresolution", "workspace.root\troot\t" + root} { - if !strings.Contains(output.String(), want) { - t.Fatalf("sources lack %q: %s", want, output.String()) - } - } -} diff --git a/internal/app/configuration_commands.go b/internal/app/configuration_commands.go new file mode 100644 index 0000000..d561334 --- /dev/null +++ b/internal/app/configuration_commands.go @@ -0,0 +1,83 @@ +package app + +import ( + "context" + "errors" + + "gitea.maximumdirect.net/eric/narratio/internal/config" + "go.maximumdirect.net/ckconfig" + "go.maximumdirect.net/commandkit" + configkit "go.maximumdirect.net/configkit" +) + +type configurationInspectionState struct { + deps commandDependencies + acquisitions map[configurationSelection]*configurationAcquisition +} + +func (s *configurationInspectionState) acquisition(selection ckconfig.Selection, input configurationSelection) *configurationAcquisition { + input.Config, input.Overlay = selection.Config, selection.Overlay + acquired := s.acquisitions[input] + if acquired == nil { + acquired = newConfigurationAcquisition(input, s.deps) + s.acquisitions[input] = acquired + } + return acquired +} + +func configurationCommand(deps commandDependencies) commandkit.Command { + flags := newConfigurationFlags(func(input *configurationSelection) *configurationSelection { return input }) + app := ckconfig.FromConfigKit("app", "Application pipeline configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.PipelineConfig], error) { + acquired := state.acquisition(selection, input) + cfg, err := acquired.Pipeline(ctx) + if err != nil { + return nil, err + } + return cfg.ConfigKitResult(), nil + }) + campaign := ckconfig.FromConfigKit("campaign", "Campaign configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.CampaignConfig], error) { + acquired := state.acquisition(selection, input) + cfg, err := acquired.Campaign(ctx) + if err != nil { + return nil, err + } + return cfg.ConfigKitResult(), nil + }) + session := ckconfig.FromConfigKit("session", "Session configuration and campaign defaults.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (result *configkit.Result[config.SessionConfig], err error) { + acquired := state.acquisition(selection, input) + defer func() { err = errors.Join(err, acquired.Close()) }() + cfg, err := acquired.Session(ctx) + if err != nil { + return nil, err + } + return cfg.ConfigKitResult(), nil + }) + party := ckconfig.FromConfigKit("party", "Selected party configuration.", func(ctx context.Context, selection ckconfig.Selection, input configurationSelection, state *configurationInspectionState) (*configkit.Result[config.PartyConfig], error) { + acquired := state.acquisition(selection, input) + cfg, err := acquired.Party(ctx) + if err != nil { + return nil, err + } + return cfg.Canonical.ConfigKitResult(), nil + }) + return ckconfig.Command(ckconfig.Suite[configurationSelection, *configurationInspectionState]{ + NewState: func() *configurationInspectionState { + invocationDeps := normalizeCommandDependencies(deps) + invocationDeps.secretsBootstrap = &secretsBootstrap{} + return &configurationInspectionState{deps: invocationDeps, acquisitions: make(map[configurationSelection]*configurationAcquisition)} + }, + CheckInput: func(_ string, selection ckconfig.Selection, input configurationSelection) error { + input.Config, input.Overlay = selection.Config, selection.Overlay + return checkConfigurationSelection(input) + }, + Selectors: []ckconfig.Selector[configurationSelection]{ + {Binding: flags.Campaign, Scopes: []string{"campaign", "session", "party"}}, + {Binding: flags.CampaignFile, Scopes: []string{"campaign", "session", "party"}}, + {Binding: flags.Session, Scopes: []string{"session"}}, + {Binding: flags.SessionFile, Scopes: []string{"session"}}, + {Binding: flags.PartyFile, Scopes: []string{"party"}}, + {Binding: flags.SecretsDir, Scopes: []string{"app", "campaign", "session", "party"}}, + }, + Scopes: []ckconfig.Scope[configurationSelection, *configurationInspectionState]{app, campaign, session, party}, + }) +} diff --git a/internal/app/configuration_commands_test.go b/internal/app/configuration_commands_test.go new file mode 100644 index 0000000..ec15f30 --- /dev/null +++ b/internal/app/configuration_commands_test.go @@ -0,0 +1,169 @@ +package app + +import ( + "bytes" + "context" + "encoding/json" + "os" + "path/filepath" + "strings" + "testing" + + "gitea.maximumdirect.net/eric/narratio/internal/config" + "go.maximumdirect.net/commandkit" + configkit "go.maximumdirect.net/configkit" +) + +func TestConfigurationCommandsExposeNativeScopesLazily(t *testing.T) { + app, err := newApplication(commandDependencies{ + loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) { + t.Fatal("discovery loaded config") + return nil, nil + }, + loadSecretsDir: func(string) (*configkit.SecretsReport, error) { + t.Fatal("discovery bootstrapped secrets") + return nil, nil + }, + }, executePlan) + if err != nil { + t.Fatal(err) + } + for _, args := range [][]string{{"config", "scopes", "--format", "json"}, {"config", "--help"}, {"config", "show", "--help"}} { + var out, diagnostic bytes.Buffer + result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic}) + if result.Status != 0 { + t.Fatalf("%v: %v %s", args, result, diagnostic.String()) + } + if args[1] == "scopes" { + var inventory struct { + Scopes []struct { + Name string `json:"name"` + } `json:"scopes"` + } + if err := json.Unmarshal(out.Bytes(), &inventory); err != nil { + t.Fatal(err) + } + if len(inventory.Scopes) != 4 { + t.Fatalf("scopes=%s", out.String()) + } + } + } +} + +func TestConfigurationCommandsInspectActualDocuments(t *testing.T) { + pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir()) + campaignCfg, err := config.LoadCampaign(campaign) + if err != nil { + t.Fatal(err) + } + party, err := config.ResolveParty(campaign, campaignCfg, nil) + if err != nil { + t.Fatal(err) + } + for _, test := range []struct { + scope, field string + selectors []string + }{ + {"app", "workspace", []string{"--config", pipeline}}, + {"campaign", "campaign_id", []string{"--campaign-file", campaign}}, + {"session", "session_id", []string{"--campaign-file", campaign, "--session-file", session}}, + {"party", "characters", []string{"--party-file", party.Source.Path}}, + } { + t.Run(test.scope, func(t *testing.T) { + var out, diagnostic bytes.Buffer + args := append([]string{"config", "show", "--scope", test.scope, "--format", "json"}, test.selectors...) + result := Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic}) + if result.Status != 0 { + t.Fatalf("status=%d diagnostics=%s", result.Status, diagnostic.String()) + } + var document map[string]any + if err := json.Unmarshal(out.Bytes(), &document); err != nil { + t.Fatal(err) + } + if _, ok := document[test.field]; !ok { + t.Fatalf("missing %s: %s", test.field, out.String()) + } + }) + } +} + +func TestConfigurationCommandsUseNativeSourcesAndValidation(t *testing.T) { + dir := t.TempDir() + root := filepath.Join(dir, "pipeline.yml") + imported := filepath.Join(dir, "platform.yml") + if err := os.WriteFile(root, []byte("config:\n imports:\n - path: platform.yml\n"), 0600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(imported, []byte("workspace: {root: ./workspace}\nwhisperx: {transcribe_url: https://transcription.example.test/transcribe}\n"), 0600); err != nil { + t.Fatal(err) + } + var out, diagnostic bytes.Buffer + result := Execute(context.Background(), []string{"config", "sources", "--config", root, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic}) + if result.Status != 0 || !strings.Contains(out.String(), "platform.yml") { + t.Fatalf("sources=%s diagnostics=%s", out.String(), diagnostic.String()) + } + if err := os.WriteFile(imported, []byte("workspace: {unrecognized: value}\n"), 0600); err != nil { + t.Fatal(err) + } + out.Reset() + diagnostic.Reset() + result = Execute(context.Background(), []string{"config", "validate", "--config", root}, commandkit.Streams{Out: &out, Err: &diagnostic}) + if result.Status != 2 || !strings.Contains(diagnostic.String(), "decode.unknown_field") { + t.Fatalf("status=%d diagnostics=%s", result.Status, diagnostic.String()) + } +} + +func nativeInspectionForTest(t *testing.T, args []string) string { + t.Helper() + var out, diagnostic bytes.Buffer + outcome := Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostic}) + if outcome.Status != 0 { + t.Fatalf("%v: status=%d error=%v diagnostics=%s", args, outcome.Status, outcome.Cause, diagnostic.String()) + } + return out.String() +} + +func TestConfigurationCommandsExposeNativePathEvidence(t *testing.T) { + pipeline, _, _ := writeValidConfigFiles(t, t.TempDir()) + for _, args := range [][]string{ + {"show", "--path", "/workspace/root"}, + {"explain", "--path", "/workspace/root"}, + {"explain", "--list", "--under", "/workspace", "--historical"}, + } { + command := append([]string{"config"}, args...) + command = append(command, "--config", pipeline, "--format", "json") + output := nativeInspectionForTest(t, command) + if !json.Valid([]byte(output)) { + t.Fatalf("invalid native report: %s", output) + } + if args[0] == "explain" && !strings.Contains(output, "/workspace/root") { + t.Fatalf("missing native path evidence: %s", output) + } + } +} + +func TestConfigurationValidationFiltersDoNotHideFailure(t *testing.T) { + pipeline := filepath.Join(t.TempDir(), "pipeline.yml") + mustWriteTestFile(t, pipeline, "whisperx: {transcribe_url: https://transcription.example.test/transcribe, timeout: invalid}\n") + var out, diagnostic bytes.Buffer + outcome := Execute(context.Background(), []string{"config", "validate", "--config", pipeline, "--details", "--severity", "warning", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic}) + if outcome.Status != 2 { + t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String()) + } + if !json.Valid(out.Bytes()) || !strings.Contains(out.String(), "filtered") { + t.Fatalf("filtered failure report=%s", out.String()) + } +} + +func TestConfigurationAggregateDoesNotOmitUnavailableContext(t *testing.T) { + pipeline := filepath.Join(t.TempDir(), "pipeline.yml") + mustWriteTestFile(t, pipeline, "whisperx: {transcribe_url: https://transcription.example.test/transcribe}\n") + var out, diagnostic bytes.Buffer + outcome := Execute(context.Background(), []string{"config", "validate", "--scope", "all", "--config", pipeline, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic}) + if outcome.Status == 0 || outcome.Cause == nil { + t.Fatalf("missing context was silently omitted: %s", out.String()) + } + if !strings.Contains(out.String(), "campaign") { + t.Fatalf("missing aggregate scope report: %s", out.String()) + } +} diff --git a/internal/config/cache_config_test.go b/internal/config/cache_config_test.go index fda30f9..6757155 100644 --- a/internal/config/cache_config_test.go +++ b/internal/config/cache_config_test.go @@ -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) } } diff --git a/internal/config/collection_authoring_test.go b/internal/config/collection_authoring_test.go index fcb299e..b431bb2 100644 --- a/internal/config/collection_authoring_test.go +++ b/internal/config/collection_authoring_test.go @@ -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 diff --git a/internal/config/document_imports_test.go b/internal/config/document_imports_test.go index dba4240..241d72e 100644 --- a/internal/config/document_imports_test.go +++ b/internal/config/document_imports_test.go @@ -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: diff --git a/internal/config/effective_pipeline.go b/internal/config/effective_pipeline.go index c2ad685..0f26f30 100644 --- a/internal/config/effective_pipeline.go +++ b/internal/config/effective_pipeline.go @@ -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)) -} diff --git a/internal/config/effective_resource_sources_test.go b/internal/config/effective_resource_sources_test.go deleted file mode 100644 index 4b8e9bb..0000000 --- a/internal/config/effective_resource_sources_test.go +++ /dev/null @@ -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) - } - } -} diff --git a/internal/config/empty_import_sources_test.go b/internal/config/empty_import_sources_test.go index 3876a53..b673116 100644 --- a/internal/config/empty_import_sources_test.go +++ b/internal/config/empty_import_sources_test.go @@ -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) } } diff --git a/internal/config/inspection_snapshot_test.go b/internal/config/inspection_snapshot_test.go index ee2c483..3d57f67 100644 --- a/internal/config/inspection_snapshot_test.go +++ b/internal/config/inspection_snapshot_test.go @@ -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) diff --git a/internal/config/native_results_test.go b/internal/config/native_results_test.go index bee01bc..7c3c2ca 100644 --- a/internal/config/native_results_test.go +++ b/internal/config/native_results_test.go @@ -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: diff --git a/internal/config/normalize_test.go b/internal/config/normalize_test.go index c749975..3b6537a 100644 --- a/internal/config/normalize_test.go +++ b/internal/config/normalize_test.go @@ -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) } diff --git a/internal/config/notarius_test.go b/internal/config/notarius_test.go index 65ba72c..6d6dc62 100644 --- a/internal/config/notarius_test.go +++ b/internal/config/notarius_test.go @@ -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) } + }) } } diff --git a/internal/config/notification_test.go b/internal/config/notification_test.go index 8acda1c..ebcfc1e 100644 --- a/internal/config/notification_test.go +++ b/internal/config/notification_test.go @@ -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) } diff --git a/internal/config/pipeline_configkit.go b/internal/config/pipeline_configkit.go index 7c307d6..297a325 100644 --- a/internal/config/pipeline_configkit.go +++ b/internal/config/pipeline_configkit.go @@ -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 { diff --git a/internal/config/pipeline_configkit_test.go b/internal/config/pipeline_configkit_test.go index 7466f04..61ccc44 100644 --- a/internal/config/pipeline_configkit_test.go +++ b/internal/config/pipeline_configkit_test.go @@ -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) +} diff --git a/internal/config/pipeline_discovery_test.go b/internal/config/pipeline_discovery_test.go index 2032f83..af73e61 100644 --- a/internal/config/pipeline_discovery_test.go +++ b/internal/config/pipeline_discovery_test.go @@ -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) } } diff --git a/internal/config/publish_field_history_test.go b/internal/config/publish_field_history_test.go index f44514a..bd07213 100644 --- a/internal/config/publish_field_history_test.go +++ b/internal/config/publish_field_history_test.go @@ -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) diff --git a/internal/config/render_test.go b/internal/config/render_test.go index 5215bda..f92cba0 100644 --- a/internal/config/render_test.go +++ b/internal/config/render_test.go @@ -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) } diff --git a/internal/config/resource_base_test.go b/internal/config/resource_base_test.go index 8ebd1c4..5fe0b32 100644 --- a/internal/config/resource_base_test.go +++ b/internal/config/resource_base_test.go @@ -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 { diff --git a/internal/config/session_defaults_test.go b/internal/config/session_defaults_test.go index a08e1fb..4144e8e 100644 --- a/internal/config/session_defaults_test.go +++ b/internal/config/session_defaults_test.go @@ -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 diff --git a/internal/config/trim_test.go b/internal/config/trim_test.go index e8682af..aa1c3d0 100644 --- a/internal/config/trim_test.go +++ b/internal/config/trim_test.go @@ -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) } diff --git a/internal/config/validate.go b/internal/config/validate.go index 2f3b00d..f98a2bd 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -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 } diff --git a/internal/stage/analyze_test.go b/internal/stage/analyze_test.go index 19f107b..166f778 100644 --- a/internal/stage/analyze_test.go +++ b/internal/stage/analyze_test.go @@ -627,7 +627,7 @@ func TestAnalyzeRunsDependenciesBeforeDependents(t *testing.T) { paths := sessionPathsForEnv(env, m.SessionID) writeAnalyzeFile(t, filepath.Join(paths.TranscriptsDir, "final.trimmed.json"), `{"segments":[]}`) - writeAnalyzeFile(t, env.Config.PipelinePath, "workspace:\n root: "+env.Config.Pipeline.Workspace.Root+` + writeAnalyzeFile(t, env.Config.PipelinePath, "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nworkspace:\n root: "+env.Config.Pipeline.Workspace.Root+` scriptorium: binary: scriptorium artifacts: