diff --git a/docs/internal/configuration.md b/docs/internal/configuration.md index 56fea7b..a4a3eec 100644 --- a/docs/internal/configuration.md +++ b/docs/internal/configuration.md @@ -28,6 +28,16 @@ invocation directory provide the fallback. Explicit CLI paths use the invocation directory. Reference-catalog entries are resolved individually from their native field origins; selection does not read unused vocabulary files. See [resource rules](../config.md#pipeline-imports-and-overlays). +## Resolved Domain Validation + +`Validate` checks cross-document storage/audio relations and product destinations +after the configuration handoff. These rejections use `DomainInputError`; +catalog derivation retains `ArtifactCatalogInputError`. Both preserve their +causes for the application's [CLI classification](../cli.md#cancellation-and-exit-status). +Native loading errors retain their existing classification. Path-resolution +failures during destination validation remain operational. Joined operational +or cancellation causes retain precedence over input errors. + ## Invocation Acquisition `internal/app/configuration_acquisition.go` owns lazy invocation selections and diff --git a/docs/roadmap/audit/catalog.md b/docs/roadmap/audit/catalog.md index 060052c..d18b5c3 100644 --- a/docs/roadmap/audit/catalog.md +++ b/docs/roadmap/audit/catalog.md @@ -41,9 +41,9 @@ their scope. Unless assigned otherwise, a finding remains independent audit remediation. Shared code does not make a refactoring a prerequisite or assign the whole finding to a roadmap. -Seventeen entries are closed by the safety, transfer, audio discovery, S3 -planning, prerequisite-history, publication-import, and associated documentation -work; 26 remain open. **Planned** identifies +Eighteen entries are closed by the safety, transfer, audio discovery, S3 +planning, prerequisite-history, publication-import, CLI classification, and +associated documentation work; 25 remain open. **Planned** identifies an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending lifecycle is removed. **Coordinate** identifies shared changes, not a commitment that a related feature implements the entire finding. Findings close only after their @@ -473,7 +473,17 @@ Related: [CAT-09](#cat-09--p2-bound-publications-simultaneously-open-source-desc ### CAT-15 — P3: Preserve input-error classification for resolved domain validation -Status: Open +Status: Closed + +**Closure.** Explicit storage/audio and product-destination rejections retain a +cause-preserving `config.DomainInputError`, recognized by the existing CLI +classifier. Loading and environmental errors retain their ordinary types. +[`domain_validation_test.go`](../../../internal/app/domain_validation_test.go) +exercises real-command rejection of both reported conflicts and invalid product +placement, valid local/S3 and destination counterparts, missing configuration, +and joined operational/cancellation precedence. Existing native and catalog +classification regressions remain passing. See +[configuration internals](../../internal/configuration.md#resolved-domain-validation). Original findings: [EH-01](06-error-handling.md#eh-01--p3-domain-configuration-failures-lose-the-cli-input-classification), [TE-06](08-testing.md#te-06--p3-cli-classification-tests-omit-real-resolved-domain-rejections). diff --git a/internal/app/command_outcome.go b/internal/app/command_outcome.go index 9a99d9d..a6ded9d 100644 --- a/internal/app/command_outcome.go +++ b/internal/app/command_outcome.go @@ -30,7 +30,7 @@ func operationOutcome(err error) commandkit.Outcome { func classifyOperationError(err error) commandkit.OutcomeKind { switch err.(type) { - case *inputError, *config.ArtifactCatalogInputError: + case *inputError, *config.ArtifactCatalogInputError, *config.DomainInputError: return commandkit.OutcomeUsage } switch wrapped := err.(type) { diff --git a/internal/app/domain_validation_test.go b/internal/app/domain_validation_test.go new file mode 100644 index 0000000..1b645ee --- /dev/null +++ b/internal/app/domain_validation_test.go @@ -0,0 +1,78 @@ +package app + +import ( + "bytes" + "context" + "errors" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "gitea.maximumdirect.net/eric/narratio/internal/config" + "go.maximumdirect.net/commandkit" +) + +func TestResolvedDomainValidationCLIClassification(t *testing.T) { + for _, tc := range []struct { + name string + localStorage bool + s3Audio bool + normalizePath string + missingConfig bool + wantStatus int + }{ + {name: "incompatible storage and audio", localStorage: true, s3Audio: true, wantStatus: 2}, + {name: "local audio with local storage", localStorage: true}, + {name: "s3 audio with s3 storage", s3Audio: true}, + {name: "colliding transcript destinations", normalizePath: "transcripts/base.json", wantStatus: 2}, + {name: "invalid transcript placement", normalizePath: "transcripts/nested/final.json", wantStatus: 2}, + {name: "distinct transcript destinations", normalizePath: "transcripts/final.json"}, + {name: "missing configuration is operational", missingConfig: true, wantStatus: 1}, + } { + t.Run(tc.name, func(t *testing.T) { + pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir()) + data, err := os.ReadFile(pipeline) + if err != nil { + t.Fatal(err) + } + pipelineYAML := string(data) + if tc.localStorage { + pipelineYAML = strings.Replace(pipelineYAML, "storage:\n backend: s3\n s3:\n bucket: test-bucket\n", "storage:\n backend: local\n", 1) + } + if tc.normalizePath != "" { + pipelineYAML += "normalize:\n output_path: " + tc.normalizePath + "\n" + } + mustWriteTestFile(t, pipeline, pipelineYAML) + if tc.s3Audio { + mustWriteTestFile(t, session, "session_id: 2026-05-03\ninputs:\n audio_s3: {prefix: audio/session/}\n") + } + if tc.missingConfig { + pipeline = filepath.Join(t.TempDir(), "missing.yml") + } + var out, diagnostics bytes.Buffer + outcome := Execute(context.Background(), []string{"session", "plan", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session}, commandkit.Streams{Out: &out, Err: &diagnostics}) + if outcome.Status != tc.wantStatus { + t.Fatalf("status = %d, want %d; cause = %v; diagnostics = %s", outcome.Status, tc.wantStatus, outcome.Cause, diagnostics.String()) + } + var domain *config.DomainInputError + if tc.wantStatus != 2 { + if errors.As(outcome.Cause, &domain) { + t.Fatalf("non-domain outcome received a domain input marker: %v", outcome.Cause) + } + return + } + if !errors.As(outcome.Cause, &domain) || errors.Unwrap(domain) == nil || !errors.Is(outcome.Cause, errors.Unwrap(domain)) { + t.Fatalf("domain validation lost its typed cause: %v", outcome.Cause) + } + for _, failure := range []error{errors.New("storage unavailable"), context.Canceled} { + joined := fmt.Errorf("command: %w", errors.Join(outcome.Cause, failure)) + combined := operationOutcome(joined) + if combined.Status != 1 || !errors.Is(combined.Cause, outcome.Cause) || !errors.Is(combined.Cause, failure) || !errors.Is(combined.Cause, errors.Unwrap(domain)) { + t.Fatalf("operational precedence or causes lost: %+v", combined) + } + } + }) + } +} diff --git a/internal/config/input_error.go b/internal/config/input_error.go new file mode 100644 index 0000000..da66e0c --- /dev/null +++ b/internal/config/input_error.go @@ -0,0 +1,14 @@ +package config + +import "fmt" + +// DomainInputError identifies a rejected value or relation in completed +// configuration. Environmental failures retain their ordinary error types. +type DomainInputError struct{ cause error } + +func (e *DomainInputError) Error() string { return e.cause.Error() } +func (e *DomainInputError) Unwrap() error { return e.cause } + +func domainInputErrorf(format string, args ...any) error { + return &DomainInputError{cause: fmt.Errorf(format, args...)} +} diff --git a/internal/config/product_destinations.go b/internal/config/product_destinations.go index cf857e3..3d2a37d 100644 --- a/internal/config/product_destinations.go +++ b/internal/config/product_destinations.go @@ -27,10 +27,10 @@ func validateProductDestinations(cfg *Config, catalog *ArtifactCatalog) error { } destination = filepath.Clean(destination) if filepath.Dir(destination) != filepath.Join(root, category) { - return fmt.Errorf("%s destination %q must be directly under %s/", producer, configured, category) + return domainInputErrorf("%s destination %q must be directly under %s/", producer, configured, category) } if previous, exists := owners[destination]; exists { - return fmt.Errorf("%s and %s both produce %q", previous, producer, destination) + return domainInputErrorf("%s and %s both produce %q", previous, producer, destination) } owners[destination] = producer return nil diff --git a/internal/config/validate_core.go b/internal/config/validate_core.go index 75ec87f..a30e280 100644 --- a/internal/config/validate_core.go +++ b/internal/config/validate_core.go @@ -109,13 +109,13 @@ func validateCrossConfig(pipeline *PipelineConfig, session *SessionConfig) error audioS3Enabled := session.Inputs.AudioS3 != nil publishUploadEnabled := publishUploadConfiguredForS3(pipeline) if audioS3Enabled && !strings.EqualFold(strings.TrimSpace(pipeline.Storage.Backend), StorageBackendS3) { - return fmt.Errorf("pipeline.storage.backend must be s3 when session.inputs.audio_s3 is configured") + return domainInputErrorf("pipeline.storage.backend must be s3 when session.inputs.audio_s3 is configured") } if !audioS3Enabled && !publishUploadEnabled { return nil } if pipeline.Storage.S3 == nil || strings.TrimSpace(pipeline.Storage.S3.Bucket) == "" { - return fmt.Errorf("pipeline.storage.s3.bucket is required when S3 session audio or publish upload is enabled") + return domainInputErrorf("pipeline.storage.s3.bucket is required when S3 session audio or publish upload is enabled") } return nil }