Skip to content

Add CI tests and fix all tests#1

Merged
aesteve-rh merged 9 commits intomainfrom
ci-tests
Sep 11, 2025
Merged

Add CI tests and fix all tests#1
aesteve-rh merged 9 commits intomainfrom
ci-tests

Conversation

@aesteve-rh
Copy link
Copy Markdown
Owner

@aesteve-rh aesteve-rh commented Sep 11, 2025

Summary by Sourcery

Add CI pipeline, introduce version flag, streamline developer documentation, update tox config, and fix tests for new logging and schema behaviors

New Features:

  • Add --version flag to the CLI
  • Introduce GitHub Actions CI workflow with linting, formatting, type checking, and multi-version testing

Bug Fixes:

  • Update CLI and schema tests to assert logging calls and updated messages
  • Correct schema file name in tests and allow missing schema path scenarios

Enhancements:

  • Simplify and prune README.developers.md by removing outdated sections
  • Adjust tox.ini to use correct coverage path

Build:

  • Update tox.ini commands to point to the git_crossref package for coverage

CI:

  • Add .github/workflows/ci.yml defining linting, formatting, type-checking, and test jobs

Documentation:

  • Streamline developer guide by removing architecture, release automation, and contribution details

Tests:

  • Revise test_main.py to use patched logger assertions
  • Refactor test_schema.py to handle permission errors and valid/invalid JSON cases

Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 11, 2025

Reviewer's Guide

This PR introduces a comprehensive GitHub Actions CI pipeline, streamlines the developer README, enhances the CLI with a --version flag, updates tox testing paths, and adjusts the test suites to match new logging behavior and schema conventions.

Sequence diagram for CI pipeline job execution

sequenceDiagram
    participant Dev as Developer
    participant GitHub as GitHub Actions
    participant Lint as Linting Job
    participant Format as Formatting Job
    participant Type as Type Checking Job
    participant Test as Test Job
    Dev->>GitHub: Push or PR to main
    GitHub->>Lint: Start linting
    GitHub->>Format: Start formatting
    GitHub->>Type: Start type checking
    Lint-->>GitHub: Linting complete
    Format-->>GitHub: Formatting check complete
    Type-->>GitHub: Type checking complete
    GitHub->>Test: Start tests (after all pre-stage jobs)
    Test-->>GitHub: Test results
Loading

File-Level Changes

Change Details Files
Overhauled developer guide README
  • Removed outdated sections (Project Structure, Architecture, CI/CD, Contributing)
  • Simplified install instructions to pip install -e .
  • Condensed Testing and Publishing instructions and reorganized TOC
README.developers.md
Set up CI pipeline and update test runners
  • Added .github/workflows/ci.yml with linting, formatting, type-checking, and test jobs
  • Updated tox.ini test commands and coverage paths
.github/workflows/ci.yml
tox.ini
Enhance CLI with version flag and adjust logging initialization
  • Added --version option in click.group callback to echo version
  • Switched logging setup to use configure_logging helper
  • Updated verbose flag wiring accordingly
src/git_crossref/main.py
Fix and align test suites
  • Refactored test_main.py to mock configure_logging/logger calls and update expected messages
  • Renamed schema filename in tests, improved get_schema_path tests, and updated JSON/PermissionError handling
tests/test_main.py
tests/test_schema.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • You’ve removed the detailed project structure and architecture section from README.developers.md — consider moving essential parts into a separate doc or brief overview so new contributors still have a high-level orientation.
  • The CI coverage commands in both tox.ini and the GitHub workflow target git_crossref but the code lives under src/git_crossref; please verify the coverage paths match your source layout to avoid gaps.
  • The formatting job only checks src/ but not the tests/ directory — including tests/ in your black/isort checks will keep formatting consistent across the entire repo.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’ve removed the detailed project structure and architecture section from README.developers.md — consider moving essential parts into a separate doc or brief overview so new contributors still have a high-level orientation.
- The CI coverage commands in both tox.ini and the GitHub workflow target `git_crossref` but the code lives under `src/git_crossref`; please verify the coverage paths match your source layout to avoid gaps.
- The formatting job only checks `src/` but not the `tests/` directory — including `tests/` in your black/isort checks will keep formatting consistent across the entire repo.

## Individual Comments

### Comment 1
<location> `tests/test_main.py:213` </location>
<code_context>
+            result = runner.invoke(cli, ["init"], input="y\n")
+            assert result.exit_code == 0
+            mock_logger.warning.assert_called_with("Configuration file already exists: %s", config_path)
+            # When file exists, no output to stdout, just warning to stderr
+            assert result.output == ""

     @patch("git_crossref.main.get_config_path")
</code_context>

<issue_to_address>
Consider testing the case where the configuration file exists but is not writable.

Adding a test for a non-writable configuration file will help verify that permission errors are handled correctly by the CLI.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        with patch("git_crossref.main.logger") as mock_logger:
            result = runner.invoke(cli, ["init"], input="y\n")
            assert result.exit_code == 0
            mock_logger.warning.assert_called_with("Configuration file already exists: %s", config_path)
=======
        with patch("git_crossref.main.logger") as mock_logger:
            result = runner.invoke(cli, ["init"], input="y\n")
            assert result.exit_code == 0
            mock_logger.warning.assert_called_with("Configuration file already exists: %s", config_path)

    def test_init_file_exists_not_writable(self, mock_get_config_path, runner, temp_dir):
        import os
        config_path.write_text("existing config")
        # Make the file read-only
        config_path.chmod(0o444)
        mock_get_config_path.return_value = config_path

        with patch("git_crossref.main.logger") as mock_logger:
            result = runner.invoke(cli, ["init"], input="y\n")
            # Should fail due to permission error
            assert result.exit_code != 0
            mock_logger.error.assert_called()
            # Optionally, check the error message contains permission denied
            error_args = mock_logger.error.call_args[0]
            assert "Permission denied" in error_args[0] or "permission" in error_args[0].lower()
        # Restore permissions so temp cleanup works
        config_path.chmod(0o666)
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `tests/test_main.py:296` </location>
<code_context>
+            with patch("git_crossref.main.logger") as mock_logger:
+                result = runner.invoke(cli, ["clone", "--remote", "nonexistent"])
+                assert result.exit_code == 1
+                mock_logger.error.assert_called_with("Remote '%s' not found in configuration", "nonexistent")


 class TestCleanCommand:
</code_context>

<issue_to_address>
Test does not verify the CLI output for user-facing error messages.

Please add an assertion to check that the CLI displays a clear error message to the user.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                result = runner.invoke(cli, ["clone", "--remote", "nonexistent"])
                assert result.exit_code == 1
                mock_logger.error.assert_called_with("Remote '%s' not found in configuration", "nonexistent")
=======
                result = runner.invoke(cli, ["clone", "--remote", "nonexistent"])
                assert result.exit_code == 1
                mock_logger.error.assert_called_with("Remote '%s' not found in configuration", "nonexistent")
                assert "Remote 'nonexistent' not found in configuration" in result.output
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `tests/test_schema.py:59` </location>
<code_context>
-            assert path == schema_file
-
-    def test_get_schema_path_not_exists(self, temp_dir):
+        # Test that get_schema_path returns a valid path or None
+        path = get_schema_path()
+        # In development environment, schema should exist
+        # In tox environment, it might not be copied, so allow None
+        if path is not None:
+            assert path.name == "gitcrossref-schema.json"
+            assert path.exists()
+        # Test passes if path is None (schema not found) or points to existing file
+
+    def test_get_schema_path_not_exists(self):
</code_context>

<issue_to_address>
Test for get_schema_path is environment-dependent and may be flaky.

Parametrize the test or use controlled mocking to ensure consistent results across environments and prevent CI flakiness.
</issue_to_address>

### Comment 4
<location> `README.developers.md:161` </location>
<code_context>
-index-servers =
-    pypi
-    testpypi
+4. Upload to the package to pypi:

-[pypi]
</code_context>

<issue_to_address>
Typo: 'Upload to the package to pypi' should be 'Upload the package to PyPI'.

Please update the phrase to 'Upload the package to PyPI' for accuracy.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/test_main.py Outdated
Comment thread tests/test_main.py Outdated
Comment thread tests/test_schema.py Outdated
Comment thread README.developers.md Outdated
Comment thread tests/test_schema.py Outdated
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
@aesteve-rh aesteve-rh merged commit b8d212f into main Sep 11, 2025
7 checks passed
@aesteve-rh aesteve-rh deleted the ci-tests branch September 11, 2025 12:42
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.

1 participant