Classify resolved configuration mistakes as input errors
This commit is contained in:
@@ -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) {
|
||||
|
||||
78
internal/app/domain_validation_test.go
Normal file
78
internal/app/domain_validation_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
14
internal/config/input_error.go
Normal file
14
internal/config/input_error.go
Normal file
@@ -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...)}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user