The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(hooks): run pre-push clippy only when the push carries Rust
obchainfc803925e394
diff --git a/.husky/pre-push b/.husky/pre-pushindex abbb148be3..04639bb6db 100755--- a/.husky/pre-push+++ b/.husky/pre-push@@ -22,6 +22,81 @@ run_check() {return "$CHECK_EXIT"}+# git hands the hook `<remote-name> <remote-url>` in argv and one+# `<local-ref> <local-oid> <remote-ref> <remote-oid>` line per pushed ref on+# stdin. Read it once, up front: the checks below consume no stdin of their+# own, and a second read would come back empty.+REMOTE_NAME="${1:-origin}"+PUSH_REFS="$(cat)"++# git pads a missing side of a push with an all-zero OID: a zero local OID is+# a branch deletion, a zero remote OID is a branch the remote has not seen.+# Length varies (40 hex for SHA-1, 64 for SHA-256), so test the digits.+is_zero_oid() {+ case "$1" in+ "") return 1 ;;+ *[!0]*) return 1 ;;+ *) return 0 ;;+ esac+}++# Every path this push would change, one per line.+#+# `UNRESOLVED` is emitted whenever the range cannot be worked out — an+# unrooted new branch, a missing object, a hook run by hand with no stdin.+# It is treated as "assume Rust changed" below, because the cost of guessing+# wrong that way is a slow push, and the other way is an unchecked one.+changed_paths_for_push() {+ while read -r _local_ref local_oid _remote_ref remote_oid; do+ [ -n "$local_oid" ] || continue+ # A deletion carries no content to check.+ if is_zero_oid "$local_oid"; then+ continue+ fi+ if is_zero_oid "$remote_oid"; then+ # New branch: diff from the parent of the oldest commit the remote does+ # not already have, so the range is what this push actually adds.+ OLDEST="$(git rev-list "$local_oid" --not --remotes="$REMOTE_NAME" 2>/dev/null | tail -n 1)"+ if [ -z "$OLDEST" ] || ! git rev-parse --verify --quiet "$OLDEST^" >/dev/null 2>&1; then+ echo "UNRESOLVED"+ continue+ fi+ git diff --name-only "$OLDEST^" "$local_oid" 2>/dev/null || echo "UNRESOLVED"+ else+ git diff --name-only "$remote_oid" "$local_oid" 2>/dev/null || echo "UNRESOLVED"+ fi+ done+}++PUSHED_PATHS="$(printf '%s\n' "$PUSH_REFS" | changed_paths_for_push)"++# Does this push touch anything clippy would have an opinion about?+#+# `pnpm rust:clippy` compiles three crates plus the Tauri shell with+# `-D warnings`, so before this gate existed ANY clippy error anywhere in the+# workspace blocked EVERY push — a README edit included — and the person+# pushing could not satisfy it from their own diff. CI gates its Rust lanes on+# changed areas for the same reason; this mirrors that.+#+# The narrower question of whether clippy belongs in a pre-push hook at all,+# given `--no-verify` is the habitual push, is left open deliberately: this+# removes the misattribution without deciding it. Set PRE_PUSH_FORCE_CLIPPY=1+# to run it regardless of what changed.+push_touches_rust() {+ if [ -n "${PRE_PUSH_FORCE_CLIPPY:-}" ]; then+ return 0+ fi+ # No ref lines at all — run by hand, or by something that does not speak the+ # pre-push protocol. Nothing to scope to, so run it. A push that DID report+ # refs and resolved no paths (a deletion, an empty commit) has no Rust in it+ # by construction and is left to skip.+ if [ -z "$PUSH_REFS" ]; then+ return 0+ fi+ printf '%s\n' "$PUSHED_PATHS" | grep -Eq \+ '(^|/)[^/]+\.rs$|(^|/)Cargo\.(toml|lock)$|(^|/)rust-toolchain\.toml$|^crates/|^vendor/|^UNRESOLVED$'+}+# Windows Git Bash can miss Node/Pnpm in PATH when hooks run.# Recover from common PATH drift by hydrating from where.exe.has_node() {@@ -104,10 +179,17 @@ COMPILE_EXIT=$?set -e# Run Clippy for both Rust codebases; Clippy also performs compile checks.-set +e-run_check pnpm rust:clippy-RUST_CLIPPY_EXIT=$?-set -e+# Only when the push carries Rust — see `push_touches_rust`.+RUST_CLIPPY_EXIT=0+if push_touches_rust; then+ set +e+ run_check pnpm rust:clippy+ RUST_CLIPPY_EXIT=$?+ set -e+else+ echo "No Rust changes in this push — skipping rust:clippy."+ echo "(PRE_PUSH_FORCE_CLIPPY=1 runs it anyway.)"+fi# Enforce scoped cmd-* tokens in components/commands/set +ediff --git a/scripts/__tests__/pre-push-hook.test.mjs b/scripts/__tests__/pre-push-hook.test.mjsnew file mode 100644index 0000000000..4f55fc17a8--- /dev/null+++ b/scripts/__tests__/pre-push-hook.test.mjs@@ -0,0 +1,217 @@+import assert from 'node:assert/strict';+import { execFileSync, spawnSync } from 'node:child_process';+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { dirname, join, resolve } from 'node:path';+import { after, test } from 'node:test';+import { fileURLToPath } from 'node:url';++const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../..');+const HOOK = resolve(REPO_ROOT, '.husky/pre-push');+const ZERO_OID = '0'.repeat(40);++const workspaces = [];+after(() => {+ for (const dir of workspaces) rmSync(dir, { recursive: true, force: true });+});++function git(cwd, ...args) {+ return execFileSync('git', args, { cwd, encoding: 'utf8' }).trim();+}++/**+ * A git repo with a bare origin and a `pnpm` stub on PATH.+ *+ * The stub records every invocation and fails the ones named in `PNPM_FAIL`,+ * so a test asserts on what the hook DID (which checks it ran, and its exit)+ * without a real format, lint, tsc or clippy run.+ */+function workspace() {+ const dir = mkdtempSync(join(tmpdir(), 'pre-push-hook-'));+ workspaces.push(dir);+ const repo = join(dir, 'repo');+ const origin = join(dir, 'origin.git');+ const bin = join(dir, 'bin');+ const log = join(dir, 'pnpm.log');+ mkdirSync(repo);+ mkdirSync(bin);++ execFileSync('git', ['init', '--quiet', '--bare', origin]);+ git(repo, 'init', '--quiet', '--initial-branch=main');+ git(repo, 'config', 'user.email', '[email protected]');+ git(repo, 'config', 'user.name', 'hook test');+ git(repo, 'remote', 'add', 'origin', origin);++ writeFileSync(+ join(bin, 'pnpm'),+ [+ '#!/bin/sh',+ 'echo "$*" >> "$PNPM_LOG"',+ 'for failing in $PNPM_FAIL; do',+ ' case "$*" in',+ ' *"$failing"*) exit 1 ;;',+ ' esac',+ 'done',+ 'exit 0',+ '',+ ].join('\n')+ );+ chmodSync(join(bin, 'pnpm'), 0o755);++ return { dir, repo, origin, bin, log };+}++function commit(ws, path, body, message) {+ const full = join(ws.repo, path);+ mkdirSync(dirname(full), { recursive: true });+ writeFileSync(full, body);+ git(ws.repo, 'add', path);+ git(ws.repo, 'commit', '--quiet', '-m', message);+ return git(ws.repo, 'rev-parse', 'HEAD');+}++function runHook(ws, refLines, { fail = '', env = {} } = {}) {+ writeFileSync(ws.log, '');+ const result = spawnSync('sh', [HOOK, 'origin', ws.origin], {+ cwd: ws.repo,+ encoding: 'utf8',+ input: refLines.map(line => `${line}\n`).join(''),+ env: {+ ...process.env,+ PATH: `${ws.bin}:${process.env.PATH}`,+ PNPM_LOG: ws.log,+ PNPM_FAIL: fail,+ PRE_PUSH_FORCE_CLIPPY: '',+ ...env,+ },+ });+ return {+ status: result.status,+ stdout: result.stdout ?? '',+ calls: readFileSync(ws.log, 'utf8').split('\n').filter(Boolean),+ };+}++function ranClippy(run) {+ return run.calls.includes('rust:clippy');+}++/** A repo whose `main` the origin already has, plus one extra local commit. */+function pushOf(path, body) {+ const ws = workspace();+ commit(ws, 'README.md', 'base\n', 'base');+ git(ws.repo, 'push', '--quiet', 'origin', 'main');+ const before = git(ws.repo, 'rev-parse', 'HEAD');+ const after_ = commit(ws, path, body, `touch ${path}`);+ return { ws, line: `refs/heads/main ${after_} refs/heads/main ${before}` };+}++// ── the clippy gate (#6533 defect 1) ───────────────────────────────────────++test('a push with no Rust changes does not run rust:clippy', () => {+ // The defect: `pnpm rust:clippy` compiles three crates plus the shell with+ // `-D warnings`, so one stale import anywhere blocked EVERY push, including+ // a README edit that cannot possibly fix it.+ const { ws, line } = pushOf('docs/guide.md', 'docs only\n');+ const run = runHook(ws, [line]);+ assert.equal(run.status, 0, run.stdout);+ assert.equal(ranClippy(run), false, `clippy ran for a docs-only push: ${run.calls}`);+ assert.match(run.stdout, /skipping rust:clippy/);+ // The rest of the hook is untouched by the gate.+ assert.deepEqual(run.calls, [+ 'format:check',+ 'lint',+ 'compile',+ '--dir app run lint:commands-tokens',+ '--dir app run lint:ui-tokens',+ ]);+});++test('a push that touches a .rs file still runs rust:clippy', () => {+ const { ws, line } = pushOf('crates/openhuman-core/src/lib.rs', 'pub fn a() {}\n');+ assert.equal(ranClippy(runHook(ws, [line])), true);+});++test('a push that touches a manifest still runs rust:clippy', () => {+ // A feature or dependency edit changes what compiles without touching a+ // single `.rs` file.+ const { ws, line } = pushOf('Cargo.toml', '[workspace]\n');+ assert.equal(ranClippy(runHook(ws, [line])), true);+});++test('a push that touches a vendored submodule path still runs rust:clippy', () => {+ const { ws, line } = pushOf('vendor/tinyagents/notes.md', 'x\n');+ assert.equal(ranClippy(runHook(ws, [line])), true);+});++test('a clippy failure in a Rust push still blocks it', () => {+ // The gate must not weaken the check it gates.+ const { ws, line } = pushOf('crates/openhuman-core/src/lib.rs', 'pub fn a() {}\n');+ const run = runHook(ws, [line], { fail: 'rust:clippy' });+ assert.equal(run.status, 1);+ assert.match(run.stdout, /Pre-push checks failed/);+});++test('PRE_PUSH_FORCE_CLIPPY runs it regardless of what changed', () => {+ const { ws, line } = pushOf('docs/guide.md', 'docs only\n');+ assert.equal(ranClippy(runHook(ws, [line], { env: { PRE_PUSH_FORCE_CLIPPY: '1' } })), true);+});++test('a hook run with no ref lines runs rust:clippy rather than skipping', () => {+ // Fail safe. Run by hand, or by anything that does not speak the pre-push+ // protocol, there is no range to read — guessing "no Rust" there would skip+ // the check silently, which is the worse of the two wrong answers.+ const { ws } = pushOf('docs/guide.md', 'docs only\n');+ assert.equal(ranClippy(runHook(ws, [])), true);+});++test('a new branch the remote has not seen is scoped to its own commits', () => {+ // The remote OID is all zeros here, so there is no `remote..local` range and+ // the hook has to work out what the push adds on its own. It must not fall+ // back to the whole history, or the first push of any branch would always+ // look like it touches Rust.+ const ws = workspace();+ commit(ws, 'crates/openhuman-core/src/lib.rs', 'pub fn a() {}\n', 'rust on main');+ git(ws.repo, 'push', '--quiet', 'origin', 'main');+ git(ws.repo, 'checkout', '--quiet', '-b', 'docs-branch');+ const head = commit(ws, 'docs/guide.md', 'docs only\n', 'docs on branch');+ const run = runHook(ws, [`refs/heads/docs-branch ${head} refs/heads/docs-branch ${ZERO_OID}`]);+ assert.equal(ranClippy(run), false, `clippy ran for a docs-only branch: ${run.calls}`);+});++test('a new branch that adds Rust runs rust:clippy', () => {+ const ws = workspace();+ commit(ws, 'README.md', 'base\n', 'base');+ git(ws.repo, 'push', '--quiet', 'origin', 'main');+ git(ws.repo, 'checkout', '--quiet', '-b', 'rust-branch');+ const head = commit(ws, 'crates/openhuman-core/src/lib.rs', 'pub fn a() {}\n', 'rust');+ const run = runHook(ws, [`refs/heads/rust-branch ${head} refs/heads/rust-branch ${ZERO_OID}`]);+ assert.equal(ranClippy(run), true);+});++test('a branch deletion has no content to check', () => {+ const ws = workspace();+ commit(ws, 'README.md', 'base\n', 'base');+ git(ws.repo, 'push', '--quiet', 'origin', 'main');+ const head = git(ws.repo, 'rev-parse', 'HEAD');+ const run = runHook(ws, [`(delete) ${ZERO_OID} refs/heads/gone ${head}`]);+ assert.equal(run.status, 0, run.stdout);+ assert.equal(ranClippy(run), false);+});++test('one Rust ref among several decides for the whole push', () => {+ const ws = workspace();+ commit(ws, 'README.md', 'base\n', 'base');+ git(ws.repo, 'push', '--quiet', 'origin', 'main');+ const base = git(ws.repo, 'rev-parse', 'HEAD');+ const docs = commit(ws, 'docs/guide.md', 'docs\n', 'docs');+ git(ws.repo, 'checkout', '--quiet', '-b', 'side', base);+ git(ws.repo, 'push', '--quiet', 'origin', 'side');+ const sideBase = git(ws.repo, 'rev-parse', 'HEAD');+ const rust = commit(ws, 'crates/openhuman-core/src/lib.rs', 'pub fn a() {}\n', 'rust');+ const run = runHook(ws, [+ `refs/heads/main ${docs} refs/heads/main ${base}`,+ `refs/heads/side ${rust} refs/heads/side ${sideBase}`,+ ]);+ assert.equal(ranClippy(run), true);+});