Skip to main content

max / goingson

Add pre-push gate that builds test targets cargo check and cargo clippy compile only lib and bin targets, so a break confined to tests/ or a #[cfg(test)] module passes both. The sqlx 0.9 upgrade shipped that way. The hook runs cargo test --no-run --workspace before a push; --workspace matters because default-members is src-tauri alone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-07-22 04:07 UTC
Commit: d2a95ca3c199e6d8b0e9ff61bf9d9a259a43d5da
Parent: 6fc4566
2 files changed, +55 insertions, -0 deletions
@@ -272,6 +272,22 @@ Cloud sync is optional. The `SyncKitClient` lives in `AppState.sync_client` behi
272 272 - Test databases use in-memory SQLite (`:memory:`) with migrations applied
273 273 - Always verify the full pipeline: Rust command → repository → DB → response → JS render
274 274
275 + ### Git hooks
276 +
277 + Two gates live in `scripts/githooks`. Activate them once per clone:
278 +
279 + ```
280 + git config core.hooksPath scripts/githooks
281 + ```
282 +
283 + - `pre-commit` runs `cargo fmt --check` in every crate with staged `.rs` changes.
284 + - `pre-push` runs `cargo test --no-run --workspace`, which builds every test
285 + target without running it. `cargo check` and `cargo clippy` compile only lib
286 + and bin targets, so a break confined to `tests/` or a `#[cfg(test)]` module
287 + passes both and lands unnoticed.
288 +
289 + Both take `--no-verify` to bypass for work in progress.
290 +
275 291 ## When Adding Features
276 292
277 293 1. **Start with the Rust types** — define the model in `crates/core/src/models/`
@@ -0,0 +1,39 @@
1 + #!/bin/bash
2 + # Test-target compile gate: blocks a push whose test targets do not build.
3 + #
4 + # Activate in a fresh clone (one-time):
5 + # git config core.hooksPath scripts/githooks
6 + #
7 + # Bypass for a work-in-progress push: git push --no-verify
8 + #
9 + # `cargo check` and `cargo clippy` both compile only the lib and bin targets, so
10 + # a break confined to `tests/` or a `#[cfg(test)]` module is clean under both and
11 + # lands unnoticed (the sqlx 0.9 upgrade shipped exactly that way). `--no-run`
12 + # builds every test target without running them, which is the cheap half of the
13 + # suite and enough to catch a compile break. Tests still run separately.
14 + #
15 + # `--workspace` is load-bearing: default-members is src-tauri alone, so a bare
16 + # `cargo test --no-run` would skip core, db-sqlite, go-mcp, and got.
17 + set -euo pipefail
18 +
19 + ROOT="$(git rev-parse --show-toplevel)"
20 + cd "$ROOT"
21 +
22 + # Refs arrive on stdin as "<local ref> <local sha> <remote ref> <remote sha>".
23 + # A branch deletion has an all-zero local sha and no tree to build.
24 + pushing=0
25 + while read -r _local_ref local_sha _remote_ref _remote_sha; do
26 + case "$local_sha" in
27 + *[!0]*) pushing=1 ;;
28 + esac
29 + done
30 + [ "$pushing" -eq 1 ] || exit 0
31 +
32 + echo "pre-push: building test targets (cargo test --no-run --workspace)..."
33 + if ! cargo test --no-run --workspace; then
34 + echo "pre-push: test targets failed to build."
35 + echo "pre-push: push aborted (use --no-verify to bypass)."
36 + exit 1
37 + fi
38 +
39 + echo "pre-push: test targets build clean."