Commit Graph
5 Commits
Author SHA1 Message Date
Kenneth WongandKenneth Wong cbcf8d8d9b fix(scripts): skip ci-precheck in the pre-push hook when a push only deletes refs (#4702)
## Description

The pre-push hook that `make install-git-hooks` writes runs the full
`make ci-precheck` (cargo fmt, clippy and the workspace tests, plus the
Python suite) even when a push only deletes branches. Its loop over the
refs on stdin skips deleted refs with `continue`, but the precheck runs
after the loop regardless, so `git push origin --delete <branch>` waits
several minutes for checks on code it doesn't send.

This PR tracks whether any ref in the push is an update, and exits 0
when none is.

No tracking issue.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- `scripts/install-git-hooks.sh` (the generated pre-push hook): set
`has_update=1` for every non-delete ref and `exit 0` after the loop when
no ref was an update. A push that mixes a delete with an update still
runs the precheck.
- The delete check now matches an all-zero sha of any length (`^0+$`),
so SHA-256 repositories (64-zero null id) are also recognised. The old
check compared against exactly 40 zeros.
- Removed the hook comment about gating only "main tracking branches";
the hook has no such pattern.
- `tests/test_install_git_hooks_script.py`: three end-to-end tests that
install the hooks into a temp repo and push to a bare remote with `make`
stubbed to log its calls. A branch update runs `make ci-precheck`; a
delete-only push does not (and the remote branch is gone); a push that
mixes a delete and an update runs it once.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`) (not run: no `headroom/`
code changed; the pre-commit mypy hook passed on the changed test file)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ pytest -q tests/test_install_git_hooks_script.py            # this branch
.......                                                         [100%]
7 passed in 3.97s

$ pytest -q tests/test_install_git_hooks_script.py            # same tests, origin/main's script
E   AssertionError: assert ['ci-precheck'] == []
FAILED tests/test_install_git_hooks_script.py::test_pre_push_skips_ci_precheck_for_a_delete_only_push
1 failed, 6 passed in 3.40s

$ ruff check tests/test_install_git_hooks_script.py
All checks passed!
$ ruff format --check tests/test_install_git_hooks_script.py
1 file already formatted
$ shellcheck -s bash scripts/install-git-hooks.sh
(no output)
$ npx commitlint --from origin/main --to HEAD
(exit 0)
```

pre-commit (ruff, ruff format, mypy, commitlint) passed on the commit.

## Real Behavior Proof

- Environment: macOS 27.2 arm64, git 2.x, bash 5; hooks installed by
each version of `scripts/install-git-hooks.sh` into a throwaway repo
with a bare remote; `make` stubbed to print instead of running the
precheck.
- Exact command / steps: install the hooks, push a `feature` branch with
`--no-verify`, then run `git push origin --delete feature` and `git push
origin HEAD:refs/heads/feature`, once with origin/main's script
(bb8d18a56) and once with this branch's.
- Observed result: origin/main runs `make ci-precheck` for the delete;
this branch skips it and still runs it for the branch push:

```text
== origin/main bb8d18a56
$ git push origin --delete feature
  [make ci-precheck] would run the full Rust + Python precheck
$ git push origin HEAD:refs/heads/feature
── pre-push: running 'make ci-precheck' before pushing HEAD → refs/heads/feature
  [make ci-precheck] would run the full Rust + Python precheck
== this branch
$ git push origin --delete feature
$ git push origin HEAD:refs/heads/feature
── pre-push: running 'make ci-precheck' before pushing HEAD → refs/heads/feature
  [make ci-precheck] would run the full Rust + Python precheck
```

- Not tested: a SHA-256 repository end to end (the regex change is
covered by reading only); Windows (the hook test module skips without
bash and git, as before); the full `make ci-precheck` itself (pushed
with `--no-verify`, since this PR changes only the hook script and its
test, and the precheck's `pip install -e .` would overwrite the local
venv used for the tests above).

## Runtime Rollout Safety

- Rollout-managed feature(s): none; contributor git hook only.
- Minimum rollout channel: N/A (not shipped in the package).
- Stable/default behavior changed: only for delete-only pushes, which no
longer run `make ci-precheck`. Every push that sends commits behaves as
before.
- Kill switch / disable path: N/A; contributors re-run `make
install-git-hooks` to pick up the change.
- Unsafe override required: no.
- Qualification impact: none; CI does not use this hook.
- Rollback path: revert this commit and re-run `make install-git-hooks`.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Screenshots (if applicable)

N/A

## Additional Notes

Documentation: N/A. `CONTRIBUTING.md` says the pre-push hook runs
ci-precheck "on every push"; a push that only deletes branches sends no
code, so I left that wording alone. Happy to add a note if you prefer.

The three existing shellcheck SC2034 warnings in the hook body
(`remote`, `url`, `remote_sha` unused) are unchanged by this PR.

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4702"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

Co-authored-by: Kenneth Wong <17061293+KennethWKZ@users.noreply.github.com>
2026-11-09 12:24:49 -06:00
0f4275f8b3 fix(scripts): resolve hooks dir via git so install-git-hooks works in linked worktrees (#4176)
## Description

`make install-git-hooks` fails in a linked Git worktree because
`scripts/install-git-hooks.sh` checks for a literal `.git/hooks`
directory. In a worktree `.git` is a file and the hooks live in the
shared common dir, so the script exits before installing anything. The
script now asks Git for the effective hooks directory (`git rev-parse
--git-path hooks`) and writes the pre-push hook there. `pre-commit
install` already handles worktrees.

Closes #4161

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- Resolve `HOOKS_DIR` with `git rev-parse --git-path hooks` instead of
assuming `.git/hooks`; fail clearly when not in a git checkout.
- Write `pre-push` to `$HOOKS_DIR` and print the real installed paths.
- Ordinary checkouts are unchanged (still `.git/hooks`, same output).

## Testing

- [x] Manual testing performed
- [ ] Unit tests / ruff / mypy: N/A, shell-only change with no Python
touched

### Test Output

```text
# linked worktree, before
$ ./scripts/install-git-hooks.sh
error: .git/hooks/ not found — run from a git checkout root

# linked worktree, after
✅ installed: /…/co/.git/hooks/pre-push
pre-commit installed at /…/co/.git/hooks/pre-commit
pre-commit installed at /…/co/.git/hooks/commit-msg

# ordinary checkout, after (unchanged)
✅ installed: .git/hooks/pre-push
✅ installed: .git/hooks/pre-commit (repo pre-commit checks via pre-commit)

# outside a git checkout
error: not inside a git checkout — run from a Headroom git checkout
```

## Real Behavior Proof

- Environment: Linux x86_64, git 2.43.0, pre-commit from a venv
- Exact command / steps: `git worktree add <dir> HEAD`, then
`./scripts/install-git-hooks.sh` from the worktree; repeated in the main
checkout and outside any repo
- Observed result: hooks install into the shared common dir; a commit
made in the worktree runs the pre-commit hooks (ruff/mypy hooks ran)
- Not tested: macOS; a repo with `core.hooksPath` set (pre-commit
refuses that config regardless)

## Runtime Rollout Safety

- Rollout-managed feature(s): None. Developer tooling only
(`scripts/install-git-hooks.sh`); no runtime code changes.
- Minimum rollout channel: Stable.
- Stable/default behavior changed: No. Proxy, library, and CLI behavior
are untouched; ordinary checkouts install hooks to the same `.git/hooks`
paths as before.
- Kill switch / disable path: Not applicable.
- Unsafe override required: No.
- Qualification impact: None.
- Rollback path: Revert this commit.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] I have performed a self-review of my code
- [x] I did **not** edit `CHANGELOG.md`

## Additional Notes

No hook bypass: the same pre-commit, commit-msg and pre-push hooks are
installed.
<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4176"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: JD Davis <mxjerrett@gmail.com>
2026-11-03 21:43:33 -06:00
96a7d7cbbe Fix CI lint failure by formatting PR governance scripts (#933)
`CI / lint (pull_request)` failed because `ruff format --check` detected
formatting drift in the new PR governance script and its tests. This PR
aligns those files with repository formatting rules so the lint job can
pass.

- **Root cause**
  - `ruff format --check .` reported two files as non-canonical:
    - `scripts/pr-governance.py`
    - `scripts/tests/test_pr_governance.py`

- **Change set**
  - Applied `ruff` formatting to only the two flagged files.
- No behavioral or logic changes; edits are line-wrap/format
normalization only.

- **Representative update**
  ```python
  parser.add_argument(
"--event", type=Path, required=True, help="Path to the GitHub event
payload JSON."
  )
  ```

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-12 17:11:39 -05:00
AshishandClaude Sonnet 4.6 3db6cd430f chore: wire pre-commit ruff hooks into make install-git-hooks (#786)
## Problem

`.pre-commit-config.yaml` already has `ruff` + `ruff-format` configured,
and `pre-commit>=3.0.0` is already in `[dev]` deps — but `make
install-git-hooks` never called `pre-commit install`. Every
contributor's repo had the hook **config** but no running hook.

PR #772 merged with inline-comment spacing and import-order violations
that ruff would have caught automatically. The maintainer had to add a
separate fixup commit (`fix: format issue 728 regression test`) to clean
it up.

## Changes

**`scripts/install-git-hooks.sh`** — after installing the pre-push hook,
also run `pre-commit install`. Falls back to `.venv/bin/pre-commit` when
`pre-commit` is not on `PATH`, with a clear warning if neither is found:

```
✅ installed: .git/hooks/pre-push
   Runs 'make ci-precheck' before every git push.
✅ installed: .git/hooks/pre-commit (ruff lint + format via pre-commit)
```

**`CONTRIBUTING.md`** — update PR workflow step 2 to mention `make
install-git-hooks` so contributors know to run it after `pip install`:

```
2. pip install -e ".[dev]" then make install-git-hooks — installs ruff on
   every commit and ci-precheck on every push.
```

## No behaviour change for existing code

Only the local dev setup script is touched. Nothing in the proxy, tests,
or CI pipeline changes.

## Real behavior proof

- **OS**: macOS darwin arm64
- **Steps**: ran `bash scripts/install-git-hooks.sh` with venv
available, then attempted a commit with a badly-formatted file
- **Result**: ruff caught and auto-fixed it before the commit landed

```
✅ installed: .git/hooks/pre-push
   Runs 'make ci-precheck' before every git push.
   Bypass (use sparingly): git push --no-verify
pre-commit installed at .git/hooks/pre-commit
✅ installed: .git/hooks/pre-commit (ruff lint + format via pre-commit)
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-09 23:09:22 -05:00
chopratejas d6a00ee89c ci: fix smart_crusher branch CI failures + add make ci-precheck pre-push gate
Five gates broke on the 2026-04-27 push of the smart_crusher branch.
Each is fixed below; the second half adds a `make ci-precheck` target
(plus an installable git pre-push hook) so the same dance never happens
again.

Failures fixed:

1. cargo fmt — 22 files had formatting drift introduced over the
   stage 3c.1 work. `cargo fmt --all` reformatted them; no semantic
   changes. `cargo test --workspace` still green (388 + supporting).

2. wheels job (macOS x86_64) — `fastembed -> ort -> ort-sys` does not
   publish prebuilt ONNX Runtime binaries for `x86_64-apple-darwin`.
   Removed that target from `.github/workflows/rust.yml`'s wheels
   matrix. Apple Silicon (`aarch64-apple-darwin`) covers macOS
   distribution; Intel macOS users can build from source. The matrix
   now has 2 targets: linux x86_64 + macOS aarch64.

3. test-extras (relevance.py) — `tests/test_relevance.py::TestSmartCrusherIntegration`
   constructs a `SmartCrusher`, which hard-imports `headroom._core`
   since the python implementation was retired in stage 3c.1b. The
   test-extras job didn't build the rust extension. Added the same
   `maturin build + symlink` block the main `test` job uses.

4. smoke-test (eval.yml) — same root cause:
   `compression_only.evaluate_ccr_lossless` instantiates a SmartCrusher.
   Same fix: build the rust extension before the smoke test runs.

5. commitlint — three rules tripped:
   - `subject-case` rejects PascalCase identifiers in subjects, but
     the project deliberately names classes (SmartCrusher, HfTokenizer,
     ContentRouter, DiffCompressor) in commit subjects. Disabled.
   - `footer-leading-blank` is a warning that the wagoid action turns
     into a CI failure; lines like `Module: foo.rs` in our bodies
     match the conventional footer pattern and trip it. Disabled.
   - `type-enum` doesn't include `parity`, but the project ships
     parity-test infrastructure as its own concern (separate from
     `test:`); added `parity` to the allowed types.

Pre-push verification — the prevention half:

`make ci-precheck` runs all of the above CI gates locally:
- `ci-precheck-rust`: cargo fmt --check + clippy + test --workspace.
- `ci-precheck-python`: builds the rust extension via maturin, then
  runs the smart_crusher-affected python test files (185 tests across
  test_transforms/, test_relevance*, test_ccr, test_acceptance,
  test_critical_fixes, test_quality_retention).
- `ci-precheck-commitlint`: `npx commitlint --from origin/main --to
  HEAD` against the same config CI uses. Skipped silently if npx is
  not on PATH (install Node 18+ to enable).

`make install-git-hooks` (or `scripts/install-git-hooks.sh`) installs
a git pre-push hook that runs `make ci-precheck` automatically.
Bypass with `--no-verify` only when truly needed.

When new CI gates land in `.github/workflows/`, mirror them into a
`make ci-precheck-*` target. The Makefile is the local mirror of the
CI configuration; keeping them in sync is a load-bearing invariant.

Verification: `make ci-precheck` runs green on this commit.
2026-04-27 11:13:47 -07:00