git bisect doesn't work on lockfiles — so I built whichdep

2026-11-24来源 dev.toEnglish
git bisect doesn't work on lockfiles — so I built whichdep

Your CI was green yesterday. Today a Dependabot PR, a cargo update, or a fresh install bumped 15 packages at once and your test suite went red.

git bisect can't help you here: your code didn't change — your lockfile did.

So you end up doing the dreaded manual loop: pinning packages one by one, fighting half-broken transitive dependency graphs, waiting on rebuilds, and wondering if a test failure is a real regression or just an invalid package combination.

I built whichdep (v0.1.0, Apache-2.0) to automate that loop across Cargo, uv, pip, npm, and pnpm.

whichdep isolating a breaking npm dependency update in 7 trials

Try it in one command

whichdep is written in Rust with zero external runtime dependencies, and ships prebuilt native binaries for Linux, macOS, and Windows across all three registries:

# Node.js / npm (no install needed) npx whichdep --good HEAD -- npm test # Python (PyPI / uv) uvx whichdep --good HEAD -- pytest # or: pip install whichdep # Rust (crates.io) cargo install whichdep 

You run it in your repo with the failing lockfile checked out and point --good at a working git revision (or lockfile path). Every trial runs in an isolated copy of your project, and build caches live outside your source tree — your working directory is never modified.

Why naive binary search breaks on lockfiles

At first glance, bisecting a lockfile diff sounds like a textbook binary search. In practice, three real-world constraints break naive bisection immediately:

1. Invalid lockfile mixes must not be blamed

If you apply half of a Cargo.lock or package-lock.json diff, you often produce a lockfile that cannot legally exist (a crate upgraded to a new major version without its updated transitive dependency, or a removed package still required by an un-upgraded parent).

If a tool treats "the package manager refused to install this mix" as "test failed", it confidently blames an innocent package.

whichdep uses three-valued outcomes (Pass, Fail, Unresolved) combined with Zeller's delta debugging (ddmin) and an adaptive binary-search strategy:

  • Each adapter parses the lockfile dependency graph and builds a dependency closure (up / down), so the search only proposes structurally closed configurations.
  • Before running your test command, whichdep verifies that the package manager kept the rendered lockfile as written (e.g., cargo fetch, npm ci, pnpm install --frozen-lockfile, uv sync --frozen, pip check).
  • Anything that cannot be resolved or built is classified Unresolved and skipped — never blamed.

2. True interactions vs. required companion updates

This was my favorite bug to catch right before v0.1.0.

When I tested whichdep against a live crates.io diff bumping rand from 0.8.5 to 0.9.5 (with RUSTFLAGS="-D warnings" turning the thread_rng deprecation into a failure), whichdep isolated the failure in 6 trials — and printed:

Cause: these updates break the tests together getrandom 0.2.17 → 0.3.4 rand 0.8.5 → 0.9.5 rand_chacha 0.3.1 → 0.9.0 rand_core 0.6.4 → 0.9.5 

And then suggested four separate cargo update ... --precise commands, starting with getrandom — which fails because rand 0.9.5 still requires getrandom 0.3!

The algorithm wasn't wrong — those four crates had to move together in the closure — but the explanation was misleading. They aren't four independent packages interacting; rand is the single root change and the other three are required companions.

Adding Closure::roots fixed both the diagnosis and the revert command:

Root cause rand 0.8.5 → 0.9.5 Required companion updates: getrandom 0.2.17 → 0.3.4 rand_chacha 0.3.1 → 0.9.0 rand_core 0.6.4 → 0.9.5 Verified: The bad lockfile without this cause passes the tests again. To put it back to the good version: cargo update rand@0.9.5 --precise 0.8.5 

Now "these updates break the tests together" is reserved exclusively for genuine multi-root interactions (when two independent packages pass individually and only fail when upgraded together).

3. Flaky tests and "never confidently wrong"

A single flaky failure can derail a bisection and point at an innocent package. Passing --repeat 3 makes whichdep run each trial multiple times and treat any disagreement as Unresolved instead of Fail.

In our seeded flakiness benchmark (tests/flakiness_e4.rs, 300 rounds per cell, n = 20, adaptive strategy):

Flake rate p --repeat 1 false causes --repeat 3 false causes
5% 0.7% 0.0%
10% 1.3% 0.0%
20% 8.7% 0.0%

And when a failure doesn't reproduce at all (for example, running the rand 0.9 test without RUSTFLAGS="-D warnings"), whichdep prints No result with the tail of the trial log — and even hints to try RUSTFLAGS="-D warnings" when Cargo emits compiler warnings on a passing run.

Early live-registry validation results

Before benchmarking large upstream repositories, I validated whichdep end-to-end against real PyPI, npm, and crates.io lockfiles using minimal synthetic reproducer harnesses for three well-known upstream breaking releases:

Ecosystem Breaking update Changes Trials Unresolved Wall time Result
Python (pip) httpx 0.27.2 → 0.28.1 (proxies= removed) 7 7 1 36s Exact root cause
Node (npm) chalk 4.1.2 → 6.0.1 (CJS → ESM) 14 7 0 4.2s Exact root cause · Verified
Rust (cargo) rand 0.8.5 → 0.9.5 (thread_rng under -D warnings) 9 6 0 6.0s Exact root cause + companions · Verified

Every one of those three live runs caught a real edge case that offline unit tests missed:

  • The httpx run revealed that pip needed reverse # via closure edges for removed transitive dependencies (sniffio) so revert verification passes cleanly.
  • The chalk run validated reverse closure restoration of 7 removed transitive packages in ~560ms per trial.
  • The rand run exposed the root-vs-companion UX bug and led to the -D warnings hint.

Running it automatically on Dependabot / Renovate PRs

whichdep also ships with a composite GitHub Action, sticky PR comments, $GITHUB_STEP_SUMMARY, and a machine-readable JSON format (whichdep-report-v2):

- uses: devel0mer/whichdep@v0.1.0 with: good: origin/${{ github.base_ref }} strategy: adaptive test-command: cargo test -q format: json out: whichdep-report.json github-summary: "true" 

(See docs/PLATFORM.md in the repo for the recommended two-job workflow so untrusted PR code never gets write permissions to comment on PRs.)

What's next — and help wanted!

The three runs above are live-registry synthetic validations — real packages and lockfiles, minimal harnesses. My next milestone (E1 in PLAN.md) is building a public regression corpus of real upstream repository breakages (e.g., Bevy #12044, real Dependabot/Renovate PRs across Cargo, uv, npm, and pnpm) and comparing ddmin vs. adaptive trial counts.

If you've recently hit a gnarly lockfile update or Dependabot PR that broke CI in a public repo, drop a link in the comments — I'd love to add it to the corpus and test whichdep against it!

原文:https://www.a8q9.cn/en/article/git-bisect-doesn-t-work-on-lockfiles-so-i-built-whichdep-e3723f.html

相关文章