72 lines
2.4 KiB
Go
72 lines
2.4 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
)
|
|
|
|
func TestRunProfileSelectionFlowsThroughSharedLoader(t *testing.T) {
|
|
workspaceRoot := t.TempDir()
|
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
|
enableCommandTestProfiles(t, pipelinePath)
|
|
|
|
var language string
|
|
executor := func(_ context.Context, cfg *config.Config, _ BoundedPlan, _ RunOptions) (*RunSummary, error) {
|
|
language = cfg.Pipeline.WhisperX.Language
|
|
return &RunSummary{SessionID: cfg.Session.SessionID, ManifestPath: "manifest.json"}, nil
|
|
}
|
|
|
|
if err := runWithPipelineExecutor(context.Background(), []string{
|
|
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", "testing",
|
|
}, io.Discard, executor); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if language != "fr" {
|
|
t.Fatalf("explicit profile language = %q, want fr", language)
|
|
}
|
|
|
|
if err := runWithPipelineExecutor(context.Background(), []string{
|
|
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath,
|
|
}, io.Discard, executor); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if language != "en" {
|
|
t.Fatalf("base configuration language = %q, want en", language)
|
|
}
|
|
|
|
for _, profile := range []string{"unknown"} {
|
|
err := runWithPipelineExecutor(context.Background(), []string{
|
|
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", profile,
|
|
}, io.Discard, executor)
|
|
if err == nil || !strings.Contains(err.Error(), "profile") {
|
|
t.Fatalf("profile %q error = %v, want selection rejection", profile, err)
|
|
}
|
|
}
|
|
|
|
if err := runWithPipelineExecutor(context.Background(), []string{
|
|
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", "",
|
|
}, io.Discard, executor); err != nil {
|
|
t.Fatalf("explicit empty profile should select base: %v", err)
|
|
}
|
|
}
|
|
|
|
func enableCommandTestProfiles(t *testing.T, pipelinePath string) {
|
|
t.Helper()
|
|
dir := filepath.Join(filepath.Dir(pipelinePath), "profiles")
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "production.yml"), []byte("whisperx:\n language: en\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "testing.yml"), []byte("whisperx:\n language: fr\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|