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) original := executeStagesFn t.Cleanup(func() { executeStagesFn = original }) var language string executeStagesFn = 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 := Run(context.Background(), []string{ "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", "testing", }, io.Discard); err != nil { t.Fatal(err) } if language != "fr" { t.Fatalf("explicit profile language = %q, want fr", language) } if err := Run(context.Background(), []string{ "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, }, io.Discard); err != nil { t.Fatal(err) } if language != "en" { t.Fatalf("default profile language = %q, want en", language) } for _, profile := range []string{"unknown", ""} { err := Run(context.Background(), []string{ "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", profile, }, io.Discard) if err == nil || !strings.Contains(err.Error(), "profile") { t.Fatalf("profile %q error = %v, want selection rejection", profile, err) } } } func enableCommandTestProfiles(t *testing.T, pipelinePath string) { t.Helper() data, err := os.ReadFile(pipelinePath) if err != nil { t.Fatal(err) } composition := "composition:\n default_profile: production\n profiles:\n production:\n overlay: production.yml\n testing:\n overlay: testing.yml\n" if err := os.WriteFile(pipelinePath, append([]byte(composition), data...), 0o644); err != nil { t.Fatal(err) } dir := filepath.Dir(pipelinePath) 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) } }