Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test: parameterize CI status tests (#516)
Maximilian Roosecb5fe3d9775
diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rsindex 73a1922d7..31cc75498 100644--- a/tests/integration_tests/ci_status.rs+++ b/tests/integration_tests/ci_status.rs@@ -18,339 +18,150 @@ fn get_branch_sha(repo: &TestRepo, branch: &str) -> String {repo.git_output(&["rev-parse", branch])}-#[rstest]-fn test_list_full_with_github_pr_passed(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");-- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh that returns PR data with passed checks- let pr_json = format!(- r#"[{{- "headRefOid": "{}",- "mergeStateStatus": "CLEAN",- "statusCheckRollup": [- {{"status": "COMPLETED", "conclusion": "SUCCESS"}}- ],- "url": "https://github.com/test-owner/test-repo/pull/1",- "headRepositoryOwner": {{"login": "test-owner"}}- }}]"#,- head_sha- );- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);+/// Helper to run a CI status test with the given mock data+fn run_ci_status_test(repo: &mut TestRepo, snapshot_name: &str, pr_json: &str, run_json: &str) {+ repo.setup_mock_gh_with_ci_data(pr_json, run_json);- let settings = setup_snapshot_settings(&repo);+ let settings = setup_snapshot_settings(repo);settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);+ let mut cmd = make_snapshot_cmd(repo, "list", &["--full"], None);repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);+ assert_cmd_snapshot!(snapshot_name, cmd);});}-#[rstest]-fn test_list_full_with_github_pr_failed(mut repo: TestRepo) {- // Add GitHub remote+/// Setup a repo with GitHub remote and feature worktree, returns head SHA+fn setup_github_repo_with_feature(repo: &mut TestRepo) -> String {repo.run_git(&["remote","add","origin","https://github.com/test-owner/test-repo.git",]);-- // Create a feature branch and push itrepo.add_worktree("feature");-- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh that returns PR data with failed checks- let pr_json = format!(- r#"[{{- "headRefOid": "{}",- "mergeStateStatus": "BLOCKED",- "statusCheckRollup": [- {{"status": "COMPLETED", "conclusion": "FAILURE"}}- ],- "url": "https://github.com/test-owner/test-repo/pull/1",- "headRepositoryOwner": {{"login": "test-owner"}}- }}]"#,- head_sha- );- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);-- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ get_branch_sha(repo, "feature")}-#[rstest]-fn test_list_full_with_github_pr_running(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");-- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh that returns PR data with running checks- let pr_json = format!(- r#"[{{- "headRefOid": "{}",- "mergeStateStatus": "UNKNOWN",- "statusCheckRollup": [- {{"status": "IN_PROGRESS", "conclusion": null}}- ],- "url": "https://github.com/test-owner/test-repo/pull/1",- "headRepositoryOwner": {{"login": "test-owner"}}- }}]"#,- head_sha- );- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);-- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });-}+// =============================================================================+// PR status tests (CheckRun format)+// =============================================================================#[rstest]-fn test_list_full_with_github_pr_conflicts(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");+#[case::passed("CLEAN", "COMPLETED", "SUCCESS", "github_pr_passed")]+#[case::failed("BLOCKED", "COMPLETED", "FAILURE", "github_pr_failed")]+#[case::running("UNKNOWN", "IN_PROGRESS", "null", "github_pr_running")]+#[case::conflicts("DIRTY", "COMPLETED", "SUCCESS", "github_pr_conflicts")]+fn test_list_full_with_github_pr_status(+ mut repo: TestRepo,+ #[case] merge_state: &str,+ #[case] status: &str,+ #[case] conclusion: &str,+ #[case] snapshot_name: &str,+) {+ let head_sha = setup_github_repo_with_feature(&mut repo);++ // Format conclusion - use raw value for null, quoted for strings+ let conclusion_json = if conclusion == "null" {+ "null".to_string()+ } else {+ format!("\"{}\"", conclusion)+ };- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh that returns PR data with merge conflictslet pr_json = format!(r#"[{{"headRefOid": "{}",- "mergeStateStatus": "DIRTY",+ "mergeStateStatus": "{}","statusCheckRollup": [- {{"status": "COMPLETED", "conclusion": "SUCCESS"}}+ {{"status": "{}", "conclusion": {}}}],"url": "https://github.com/test-owner/test-repo/pull/1","headRepositoryOwner": {{"login": "test-owner"}}}}]"#,- head_sha+ head_sha, merge_state, status, conclusion_json);- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, snapshot_name, &pr_json, "[]");}-#[rstest]-fn test_list_full_with_status_context_pending(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");-- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh with StatusContext (external CI) pending- let pr_json = format!(- r#"[{{- "headRefOid": "{}",- "mergeStateStatus": "UNKNOWN",- "statusCheckRollup": [- {{"state": "PENDING"}}- ],- "url": "https://github.com/test-owner/test-repo/pull/1",- "headRepositoryOwner": {{"login": "test-owner"}}- }}]"#,- head_sha- );- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);-- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });-}+// =============================================================================+// StatusContext tests (external CI systems like Jenkins)+// =============================================================================#[rstest]-fn test_list_full_with_status_context_failure(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");+#[case::pending("UNKNOWN", "PENDING", "status_context_pending")]+#[case::failure("BLOCKED", "FAILURE", "status_context_failure")]+fn test_list_full_with_status_context(+ mut repo: TestRepo,+ #[case] merge_state: &str,+ #[case] state: &str,+ #[case] snapshot_name: &str,+) {+ let head_sha = setup_github_repo_with_feature(&mut repo);- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh with StatusContext (external CI) failurelet pr_json = format!(r#"[{{"headRefOid": "{}",- "mergeStateStatus": "BLOCKED",+ "mergeStateStatus": "{}","statusCheckRollup": [- {{"state": "FAILURE"}}+ {{"state": "{}"}}],"url": "https://github.com/test-owner/test-repo/pull/1","headRepositoryOwner": {{"login": "test-owner"}}}}]"#,- head_sha+ head_sha, merge_state, state);- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, snapshot_name, &pr_json, "[]");}-#[rstest]-fn test_list_full_with_github_workflow_run(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it (so has_upstream is true)- repo.add_worktree("feature");-- // Get actual commit SHA so workflow run isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh with no PR but workflow run- let pr_json = "[]"; // No PR- let run_json = format!(- r#"[{{- "status": "completed",- "conclusion": "success",- "headSha": "{}"- }}]"#,- head_sha- );- repo.setup_mock_gh_with_ci_data(pr_json, &run_json);-- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });-}+// =============================================================================+// Workflow run tests (no PR, just workflow runs)+// =============================================================================#[rstest]-fn test_list_full_with_github_workflow_running(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);+#[case::completed("completed", "success", "github_workflow_run")]+#[case::running("in_progress", "null", "github_workflow_running")]+fn test_list_full_with_github_workflow(+ mut repo: TestRepo,+ #[case] status: &str,+ #[case] conclusion: &str,+ #[case] snapshot_name: &str,+) {+ let head_sha = setup_github_repo_with_feature(&mut repo);++ let conclusion_json = if conclusion == "null" {+ "null".to_string()+ } else {+ format!("\"{}\"", conclusion)+ };- // Create a feature branch and push it- repo.add_worktree("feature");-- // Get actual commit SHA so workflow run isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh with workflow run in progress- let pr_json = "[]"; // No PRlet run_json = format!(r#"[{{- "status": "in_progress",- "conclusion": null,+ "status": "{}",+ "conclusion": {},"headSha": "{}"}}]"#,- head_sha+ status, conclusion_json, head_sha);- repo.setup_mock_gh_with_ci_data(pr_json, &run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, snapshot_name, "[]", &run_json);}+// =============================================================================+// Special case tests (unique scenarios that don't fit parameterization)+// =============================================================================+#[rstest]fn test_list_full_with_stale_pr(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");+ setup_github_repo_with_feature(&mut repo);// Make additional commit locally (not pushed)- let worktree_path = repo.worktrees.get("feature").unwrap();+ let worktree_path = repo.worktrees.get("feature").unwrap().clone();std::fs::write(worktree_path.join("new_file.txt"), "new content").unwrap();- repo.stage_all(worktree_path);- repo.run_git_in(worktree_path, &["commit", "-m", "Local commit"]);+ repo.stage_all(&worktree_path);+ repo.run_git_in(&worktree_path, &["commit", "-m", "Local commit"]);- // Setup mock gh with PR data - use fake SHA to simulate stale PR- // (PR was created before the local commit, so PR HEAD differs from local HEAD)+ // PR HEAD differs from local HEAD - simulates stale PRlet pr_json = r#"[{"headRefOid": "old_sha_from_before_local_commit","mergeStateStatus": "CLEAN",@@ -360,35 +171,15 @@ fn test_list_full_with_stale_pr(mut repo: TestRepo) {"url": "https://github.com/test-owner/test-repo/pull/1","headRepositoryOwner": {"login": "test-owner"}}]"#;- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(pr_json, run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, "stale_pr", pr_json, "[]");}#[rstest]fn test_list_full_with_mixed_check_types(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");+ let head_sha = setup_github_repo_with_feature(&mut repo);- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh with mixed check types (CheckRun + StatusContext)- // One passed CheckRun, one pending StatusContext+ // Mixed: CheckRun (passed) + StatusContext (pending)let pr_json = format!(r#"[{{"headRefOid": "{}",@@ -402,34 +193,14 @@ fn test_list_full_with_mixed_check_types(mut repo: TestRepo) {}}]"#,head_sha);- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, "mixed_check_types", &pr_json, "[]");}#[rstest]fn test_list_full_with_no_ci_checks(mut repo: TestRepo) {- // Add GitHub remote- repo.run_git(&[- "remote",- "add",- "origin",- "https://github.com/test-owner/test-repo.git",- ]);-- // Create a feature branch and push it- repo.add_worktree("feature");+ let head_sha = setup_github_repo_with_feature(&mut repo);- // Get actual commit SHA so PR isn't marked as stale- let head_sha = get_branch_sha(&repo, "feature");-- // Setup mock gh with PR but no CI checkslet pr_json = format!(r#"[{{"headRefOid": "{}",@@ -440,35 +211,23 @@ fn test_list_full_with_no_ci_checks(mut repo: TestRepo) {}}]"#,head_sha);- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, "no_ci_checks", &pr_json, "[]");}#[rstest]fn test_list_full_filters_by_repo_owner(mut repo: TestRepo) {- // Add GitHub remote with specific owner+ // Use different org namerepo.run_git(&["remote","add","origin","https://github.com/my-org/test-repo.git",]);-- // Create a feature branch and push itrepo.add_worktree("feature");-- // Get actual commit SHA so PR isn't marked as stalelet head_sha = get_branch_sha(&repo, "feature");- // Setup mock gh with multiple PRs - only one from our org- // The first PR is from a different org, second is from our org+ // Multiple PRs - only one from our org (should filter to my-org's PR)let pr_json = format!(r#"[{{@@ -488,14 +247,6 @@ fn test_list_full_filters_by_repo_owner(mut repo: TestRepo) {]"#,head_sha);- let run_json = "[]";- repo.setup_mock_gh_with_ci_data(&pr_json, run_json);- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- let mut cmd = make_snapshot_cmd(&repo, "list", &["--full"], None);- repo.configure_mock_commands(&mut cmd);- // Should show passed (green) because it filters to my-org's PR- assert_cmd_snapshot!(cmd);- });+ run_ci_status_test(&mut repo, "filters_by_repo_owner", &pr_json, "[]");}diff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_filters_by_repo_owner.snap b/tests/snapshots/integration__integration_tests__ci_status__filters_by_repo_owner.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_filters_by_repo_owner.snaprename to tests/snapshots/integration__integration_tests__ci_status__filters_by_repo_owner.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_conflicts.snap b/tests/snapshots/integration__integration_tests__ci_status__github_pr_conflicts.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_conflicts.snaprename to tests/snapshots/integration__integration_tests__ci_status__github_pr_conflicts.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_failed.snap b/tests/snapshots/integration__integration_tests__ci_status__github_pr_failed.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_failed.snaprename to tests/snapshots/integration__integration_tests__ci_status__github_pr_failed.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_passed.snap b/tests/snapshots/integration__integration_tests__ci_status__github_pr_passed.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_passed.snaprename to tests/snapshots/integration__integration_tests__ci_status__github_pr_passed.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_running.snap b/tests/snapshots/integration__integration_tests__ci_status__github_pr_running.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_pr_running.snaprename to tests/snapshots/integration__integration_tests__ci_status__github_pr_running.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_workflow_run.snap b/tests/snapshots/integration__integration_tests__ci_status__github_workflow_run.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_workflow_run.snaprename to tests/snapshots/integration__integration_tests__ci_status__github_workflow_run.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_workflow_running.snap b/tests/snapshots/integration__integration_tests__ci_status__github_workflow_running.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_github_workflow_running.snaprename to tests/snapshots/integration__integration_tests__ci_status__github_workflow_running.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_mixed_check_types.snap b/tests/snapshots/integration__integration_tests__ci_status__mixed_check_types.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_mixed_check_types.snaprename to tests/snapshots/integration__integration_tests__ci_status__mixed_check_types.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_no_ci_checks.snap b/tests/snapshots/integration__integration_tests__ci_status__no_ci_checks.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_no_ci_checks.snaprename to tests/snapshots/integration__integration_tests__ci_status__no_ci_checks.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_stale_pr.snap b/tests/snapshots/integration__integration_tests__ci_status__stale_pr.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_stale_pr.snaprename to tests/snapshots/integration__integration_tests__ci_status__stale_pr.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_status_context_failure.snap b/tests/snapshots/integration__integration_tests__ci_status__status_context_failure.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_status_context_failure.snaprename to tests/snapshots/integration__integration_tests__ci_status__status_context_failure.snapdiff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_status_context_pending.snap b/tests/snapshots/integration__integration_tests__ci_status__status_context_pending.snapsimilarity index 100%rename from tests/snapshots/integration__integration_tests__ci_status__list_full_with_status_context_pending.snaprename to tests/snapshots/integration__integration_tests__ci_status__status_context_pending.snap