Skip to content

Add CLI-level test for import pipeline error handling in Bitbucket integration#1085

Merged
nathanjmcdougall merged 3 commits intomainfrom
copilot/test-import-pipelines-bitbucket
Nov 5, 2025
Merged

Add CLI-level test for import pipeline error handling in Bitbucket integration#1085
nathanjmcdougall merged 3 commits intomainfrom
copilot/test-import-pipelines-bitbucket

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 5, 2025

The issue raised concern that UnexpectedImportPipelineError could propagate unnecessarily to users when tools call update_bitbucket_steps(), which internally uses add_bitbucket_step_in_default().

Changes

  • Added test_import_pipeline_error_handled in tests/usethis/_ui/interface/test_interface_ci.py to verify the CLI handles import pipeline errors gracefully

The test uses CliRunner to test the usethis ci bitbucket command and ensures the error does NOT propagate as an unhandled exception:

def test_import_pipeline_error_handled(self, tmp_path: Path):
    """Test that import pipeline errors are handled gracefully at CLI level."""
    # Arrange - create a bitbucket-pipelines.yml with an import pipeline
    (tmp_path / "bitbucket-pipelines.yml").write_text(
        """\
image: atlassian/default-image:3
pipelines:
    default:
        import: shared-pipeline:master:share-pipeline-1
"""
    )
    # Add a tool so update_bitbucket_steps gets called
    (tmp_path / "pytest.ini").touch()
    
    # Act
    runner = CliRunner()
    with change_cwd(tmp_path):
        result = runner.invoke_safe(app, ["--backend=none"])
    
    # Assert - error should be caught and handled, not propagate as unhandled exception
    assert result.exit_code == 1, result.output
    assert "import pipeline" in result.output.lower()

This validates that the CLI layer properly catches UnexpectedImportPipelineError, displays an error message to the user, and exits gracefully with code 1 instead of propagating an unhandled exception.

Original prompt

This section details on the original issue you should resolve

<issue_title>Better test import pipelines for bitbucket</issue_title>
<issue_description>Motivation
I am concerned that the UnexpectedImportPipelineError might propagate all the way to the user unnecessarily. Some testing would be helpful.

Summary of desired enhancement
Test import pipelines for higher-level interfaces and ensure errors aren't propogating. Only one test is necessary
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for import pipelines in bitbucket Add test coverage for import pipeline error handling in Bitbucket integration Nov 5, 2025
Copy link
Copy Markdown
Collaborator

@nathanjmcdougall nathanjmcdougall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this test is testing at the wrong level. It should be in a different file, the one that tests with CLIRunner on the usethis ci bitbucket command. And you should test that the error does NOT propogate, i.e. that it does not get raised.

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 5, 2025

@copilot this test is testing at the wrong level. It should be in a different file, the one that tests with CLIRunner on the usethis ci bitbucket command. And you should test that the error does NOT p...

Moved the test to test_interface_ci.py and updated it to verify that the error is handled gracefully at the CLI level. The test now confirms that when an import pipeline exists, the usethis ci bitbucket command catches the error and exits with code 1, rather than propagating an unhandled exception. Commit: 833c68c

Copilot AI changed the title Add test coverage for import pipeline error handling in Bitbucket integration Add CLI-level test for import pipeline error handling in Bitbucket integration Nov 5, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Nov 5, 2025

CodSpeed Performance Report

Merging #1085 will not alter performance

Comparing copilot/test-import-pipelines-bitbucket (833c68c) with main (e7563ee)

Summary

✅ 2 untouched

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review November 5, 2025 08:15
@nathanjmcdougall nathanjmcdougall merged commit 1a413d7 into main Nov 5, 2025
23 of 36 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/test-import-pipelines-bitbucket branch November 5, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better test import pipelines for bitbucket

2 participants