Skip to content

Stop hook: scope clippy + tests to affected crates instead of --workspace #465

Description

@zackees

Problem

ci/hooks/check-on-stop.py runs cargo clippy --workspace --all-targets and cargo test --workspace on every Stop where any file changed. Even one-line edits in fbuild-core rebuild + retest all 11 crates' worth of tests, benches, and binaries.

Locally measured: ~5+ minutes for the full workspace test compile + run, ~2-3 min for workspace clippy, sharing the same target/ so they serialize on the cargo lock anyway.

Fix

Diff git diff --name-only HEAD --diff-filter=ACMR against crates/<name>/... and run scoped commands:

```python
changed = git_diff_names()
crates = set()
needs_full = False
for path in changed:
if path.startswith("crates/"):
crates.add(path.split("/")[1])
elif path in ("Cargo.lock", "Cargo.toml", "rust-toolchain.toml"):
needs_full = True
elif path.startswith(".cargo/"):
needs_full = True

if needs_full:
run("soldr cargo clippy --workspace --all-targets -- -D warnings")
run("soldr cargo test --workspace")
else:
for c in crates:
run(f"soldr cargo clippy -p {c} --all-targets -- -D warnings")
if crates:
args = " ".join(f"-p {c}" for c in crates)
run(f"soldr cargo test {args}")
```

(Same logic the existing ci/lint.py:detect_crate already encodes for single-file edits — generalize it to multi-file.)

Why workspace-wide should stay in pre-push / CI

Workspace-wide guarantees we don't break a cross-crate interaction; that's catchable on push to a remote where CI also runs the same matrix. Stop hook is per-conversation interactive feedback — it should match what the user can read in <60s.

Acceptance

  • Single-crate .rs edit + Stop: hook runs cargo clippy -p <crate> + cargo test -p <crate> only. <60s warm.
  • Cargo.toml / Cargo.lock / toolchain change: hook falls back to --workspace. (Same behavior as today.)
  • pre-push hook (new or augmented) runs the full --workspace lint + test so escapes are still caught before share.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions