All checks were successful
ci/woodpecker/tag/release Pipeline was successful
79 lines
3.1 KiB
Go
79 lines
3.1 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/v4/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)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|