← Back to Pull requests

Preserve compatible pins in hatch env lock --check #2417

Open
mitre88 opened this pull request with 40 lines diff across 4 files
View on GitHub
mitre88 mitre88 commented on Sep 08, 2026 15:47 UTC
Author

Fixes #2406.

Problem


UvLocker.in_sync (used by hatch env lock --check) writes a fresh lock into an empty temp file and compares it to the committed lock. uv pip compile only keeps compatible pins when the output file already exists; with a blank file it always resolves to the newest versions. So --check fails whenever a dependency publishes a new release, even if the committed pin still satisfies the constraint.

Fix


Copy the existing lockfile into the temp path before calling generate, matching how uv lock --check / uv pip compile treat an existing output (pins kept unless --upgrade). Apply the same seed in the pip locker.

Verified manually: compiling tombi>=1.4 into a file already pinned at 1.4.1 keeps 1.4.1; compiling into a missing file resolves to the newest (1.5.2).

Tests


  • test_uv_in_sync_seeds_existing_lockfile asserts generate sees the committed lock content as the seed.

  • Existing in_sync unit tests still pass.
  • AI disclosure


    Assisted with Cursor while implementing and writing the PR. I reviewed the hatch locker code, confirmed uv pip compile pin behavior locally, and own the change.

    Diff: 40 lines (+40 / -0) across 4 files Reviewer: cjames23 Review duration: 59128m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.37) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 40 lines diff across 4 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 2 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    88%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.222
    Real PR Conversation Timeline
    4 items
    cjames23 cjames23 commented on code on Sep 10, 2026 14:52 UTC
    Code Review
    tests/cli/env/test_lock.py:1
    @@ -395,6 +395,34 @@ def generate(_cls, _environment, _dependencies, output_path, **_kwargs):
         assert UvLocker.in_sync(object(), [], lock_path)
     
     
    +def test_uv_in_sync_seeds_existing_lockfile(helpers, monkeypatch, temp_dir):
    +    """``in_sync`` must pass the committed lock to ``generate`` as a seed.
    +
    +    ``uv pip compile`` keeps compatible pins when the output file already
    +    exists; a blank temp file would resolve to the newest versions and make
    +    ``hatch env lock --check`` fail on every new release (#2406).

    Remove references to issue numbers.

    cjames23 cjames23 commented on code on Sep 10, 2026 14:54 UTC
    Code Review
    tests/cli/env/test_lock.py:1
    @@ -395,6 +395,34 @@ def generate(_cls, _environment, _dependencies, output_path, **_kwargs):
         assert UvLocker.in_sync(object(), [], lock_path)
     
     
    +def test_uv_in_sync_seeds_existing_lockfile(helpers, monkeypatch, temp_dir):
    +    """``in_sync`` must pass the committed lock to ``generate`` as a seed.
    +
    +    ``uv pip compile`` keeps compatible pins when the output file already
    +    exists; a blank temp file would resolve to the newest versions and make

    These types of comments in a test like this do not add anything when the test name describes what is being tested.

    cjames23 cjames23 requested changes on Sep 10, 2026 14:54 UTC
    Changes Requested Reviewer

    Requested changes.

    Reviewers
    Assignees
    mitre88 mitre88
    Labels
    risk: low confidence: 88.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.6% (MEDIUM) · Higher = larger blast radius
    36.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.9% · Lower = rushed or shallow review
    88.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.1% · Safe to merge
    4.1%
    Repository