Skip to content

Surface lockfile discovery failures via typed exceptions (#79) - #131

Draft
leynos wants to merge 1 commit into
mainfrom
issue-79-inject-lockfile-fs-io
Draft

Surface lockfile discovery failures via typed exceptions (#79)#131
leynos wants to merge 1 commit into
mainfrom
issue-79-inject-lockfile-fs-io

Conversation

@leynos

@leynos leynos commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #79

  • discover_tracked_lockfiles previously hid a non-git workspace behind a warning and a silent empty tuple. It now raises a typed NotAGitRepositoryError (subclass of LockfileDiscoveryError) for non-git workspaces; other git failures keep raising LockfileDiscoveryError.
  • The skip policy moves to the caller: publish pre-flight catches NotAGitRepositoryError, warns, and continues — preserving operator behaviour while making the condition explicit at the API.
  • I/O is confined to ports: git access through the injected runner, filesystem access through the injected manifest_exists adapter; the function performs no direct I/O of its own (documented in the docstring).

Testing

  • New tests/integration/test_lockfile_discovery.py exercises discovery against real git repositories in temporary directories through the real subprocess runner, without stubbing internals: tracked vs untracked lockfiles, target/ exclusion, manifest adjacency, and the non-git typed error.
  • The silent-skip unit test is replaced with a typed-exception assertion; a caller-policy test pins the pre-flight skip behaviour.
  • make check-fmt, make lint, make typecheck, and make test (565 passed) all green after rebasing onto current main.
  • coderabbit review --agent: 0 findings.

🤖 Generated with Claude Code

Summary by Sourcery

Surface non-git workspaces as typed errors during Cargo.lock discovery and delegate skip policy to the publish pre-flight caller.

New Features:

  • Introduce a NotAGitRepositoryError subclass of LockfileDiscoveryError to represent lockfile discovery in non-git workspaces.

Bug Fixes:

  • Ensure non-git workspaces no longer appear as a silent success with an empty lockfile set during discovery.

Enhancements:

  • Refine lockfile discovery error handling to raise explicit exceptions on git failures rather than returning sentinel values.
  • Confine I/O in lockfile discovery to injected git runner and manifest-existence adapters to improve testability and separation of concerns.

Tests:

  • Add integration tests for lockfile discovery against real git repositories, covering tracked vs untracked lockfiles, target directory exclusion, manifest adjacency, and non-git error handling.
  • Update unit tests to assert typed exceptions for non-git workspaces and to verify the publish pre-flight skip policy for non-git repositories.

References

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1f363596-0d4d-4574-bcc6-65c8690acf29

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-79-inject-lockfile-fs-io

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors lockfile discovery to surface non-git workspaces via a typed exception instead of a silent skip, moves the skip policy to the publish preflight caller, and adds integration and unit tests that exercise discovery against real git repositories and assert the new error-handling behavior.

Sequence diagram for lockfile discovery error propagation and skip policy

sequenceDiagram
    participant PublishPreflight
    participant discover_tracked_lockfiles
    participant runner
    participant _raise_git_ls_files_failure

    PublishPreflight->>discover_tracked_lockfiles: discover_tracked_lockfiles(workspace_root, runner_with_env)
    discover_tracked_lockfiles->>runner: runner(("git", "ls-files", "**/Cargo.lock", "Cargo.lock"), cwd=workspace_root)
    runner-->>discover_tracked_lockfiles: exit_code, stdout, stderr

    alt exit_code != 0
        discover_tracked_lockfiles->>_raise_git_ls_files_failure: _raise_git_ls_files_failure(exit_code, stdout, stderr, workspace_root)
        alt ["not a git repository" in detail]
            _raise_git_ls_files_failure-->>PublishPreflight: raise NotAGitRepositoryError
            PublishPreflight->>PublishPreflight: LOGGER.warning("Skipping lockfile freshness validation...")
            PublishPreflight-->>PublishPreflight: return
        else other git failure
            _raise_git_ls_files_failure-->>PublishPreflight: raise LockfileDiscoveryError
        end
    else exit_code == 0
        discover_tracked_lockfiles-->>PublishPreflight: tracked_lockfiles
    end
Loading

File-Level Changes

Change Details Files
Surface non-git workspaces as a typed discovery error instead of silently returning an empty result.
  • Introduce NotAGitRepositoryError as a LockfileDiscoveryError subclass with documentation on caller-owned skip policy.
  • Replace _handle_git_ls_files_failure with _raise_git_ls_files_failure that always raises typed errors for non-zero git ls-files exit codes.
  • Update discover_tracked_lockfiles to call the new helper on git failures, document raised exceptions in the docstring, and clarify that all I/O goes through injected runner and manifest_exists ports.
lading/commands/lockfile.py
Move the non-git workspace skip policy into publish preflight validation logic.
  • Wrap discover_tracked_lockfiles in _validate_lockfile_freshness with a try/except for NotAGitRepositoryError.
  • On NotAGitRepositoryError, log a warning that freshness validation is being skipped for a non-git workspace and return early without running cargo commands.
lading/commands/publish_preflight.py
Align unit tests with the new typed error behavior and caller-owned skip policy.
  • Change the discover_tracked_lockfiles non-git directory unit test to expect NotAGitRepositoryError instead of an empty tuple.
  • Add a preflight unit test that injects a discovery function raising NotAGitRepositoryError and asserts that validation logs a warning and performs no cargo runner calls.
tests/unit/test_lockfile.py
tests/unit/publish/test_preflight_lockfile_validation.py
Add integration tests that exercise lockfile discovery against real git repositories via the subprocess runner.
  • Create helper functions to initialize temporary git repos, add crates with/without manifests, and run git commands with deterministic identity.
  • Add tests that verify discovery returns only tracked lockfiles with adjacent manifests, ignores untracked and target/ lockfiles, and raises NotAGitRepositoryError for non-git directories when invoked with subprocess_runner.
tests/integration/test_lockfile_discovery.py

Assessment against linked issues

Issue Objective Addressed Explanation
#79 Refactor discover_tracked_lockfiles so all filesystem operations (lockfile enumeration, manifest existence checks) are routed through injected ports (runner/manifest_exists) and the function performs no direct Path I/O.
#79 Make lockfile discovery failures explicit in the public API by surfacing errors (e.g., via typed exceptions) instead of logging warnings and returning empty tuples silently.
#79 Replace the previous mock-based tests for lockfile discovery with real integration tests that exercise discovery (and related behaviour) against temporary directories and real git/subprocess interactions.

Possibly linked issues


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

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lodyai
lodyai Bot force-pushed the issue-79-inject-lockfile-fs-io branch from 3739c1e to c6ad97d Compare June 16, 2026 19:04
discover_tracked_lockfiles hid a non-git workspace behind a warning
and a silent empty tuple, so callers could not distinguish "no
tracked lockfiles" from "discovery never ran". Filesystem access was
also mixed into the function rather than confined to a port.

Raise a typed NotAGitRepositoryError (subclass of
LockfileDiscoveryError) for non-git workspaces and keep
LockfileDiscoveryError for other git failures. The skip policy moves
to the caller: publish pre-flight catches NotAGitRepositoryError,
warns, and continues, preserving existing operator behaviour while
making the condition explicit at the API.

Filesystem access is now documented as confined to the injected
manifest_exists port and git access to the injected runner; the
function performs no direct I/O of its own.

Replace the silent-skip unit test with a typed-exception assertion,
add a caller-policy test for the pre-flight skip, and add integration
tests that exercise discovery against real git repositories in
temporary directories through the real subprocess runner (tracked
versus untracked lockfiles, target/ exclusion, manifest adjacency,
and the non-git error).

Closes #79
@lodyai
lodyai Bot force-pushed the issue-79-inject-lockfile-fs-io branch from c6ad97d to f3ce412 Compare July 27, 2026 22:04
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No quality gates enabled for this code.

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.

Inject filesystem I/O into discover_tracked_lockfiles and surface failures via exceptions

1 participant