Skip to content

chore(hooks): run typecheck in pre-commit, drop deprecated husky bootstrap - #521

Merged
ndycode merged 3 commits into
mainfrom
claude/audit-05-precommit-typecheck
Jun 10, 2026
Merged

chore(hooks): run typecheck in pre-commit, drop deprecated husky bootstrap#521
ndycode merged 3 commits into
mainfrom
claude/audit-05-precommit-typecheck

Conversation

@ndycode

@ndycode ndycode commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Part 5 of the repo-wide audit (#517, #518, #519, #520). Two small dev-tooling fixes to .husky/pre-commit:

  1. Remove the deprecated husky v9 bootstrap lines (#!/bin/sh + . "$(dirname "$0")/_/husky.sh"). Husky prints a deprecation warning on every commit today and these lines will hard-fail in husky v10.

  2. Add npm run typecheck to the pre-commit gate. The hook previously ran only lint-staged (eslint), while CI requires typecheck — so type errors silently reached the PR stage. tsc --noEmit completes in ~5s on this codebase, cheap enough to gate every commit. (--no-verify remains available for emergencies, as before.)

Testing

The hook exercised itself on this branch's own commit: lint-staged + typecheck both ran, no deprecation warning, commit succeeded.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB


Generated by Claude Code

note: greptile review for oc-chatgpt-multi-auth. cite files like lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.

Greptile Summary

drops the deprecated husky v9 bootstrap shim and adds npm run typecheck (tsc --noEmit) to the pre-commit gate, chained with && so a lint failure correctly blocks the commit. a new vitest contract test locks in the fail-fast invariant and the removal of the deprecated bootstrap.

  • .husky/pre-commit: single-line npx lint-staged && npm run typecheck replaces the multi-line husky-v9 form; && chaining propagates non-zero exit codes to git as required.
  • test/precommit-hook.test.ts: contract test verifies no ; chaining, no deprecated husky.sh shim, and that multi-line hooks carry set -e — adds regression coverage for both changes in this PR.

Confidence Score: 5/5

safe to merge — the hook change is correct and the test adds meaningful regression coverage

the two-file change is narrowly scoped: the hook now correctly uses && so lint failures block the commit, the deprecated bootstrap is gone, and the new contract test locks both invariants in. no runtime code paths, no token handling, no windows filesystem operations are touched.

no files require special attention

Important Files Changed

Filename Overview
.husky/pre-commit removes deprecated husky v9 bootstrap and chains lint-staged + typecheck with &&, correctly propagating non-zero exit codes to git
test/precommit-hook.test.ts new contract test guards against multi-line hooks without set -e and semicolon chaining, but doesn't assert against

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[git commit] --> B[pre-commit hook]
    B --> C[npx lint-staged]
    C -->|exit non-zero| D[hook exits non-zero\ngit blocks commit]
    C -->|exit 0| E[npm run typecheck\ntsc --noEmit]
    E -->|exit non-zero| D
    E -->|exit 0| F[hook exits 0\ngit proceeds with commit]
Loading

Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
test/precommit-hook.test.ts:22-29
the test guards against `;` chaining but not `||` chaining. `npx lint-staged || npm run typecheck` would pass every assertion here yet is fail-open: typecheck only runs when lint-staged *fails*, which is the opposite of the desired behaviour.

```suggestion
		// Commands on a single line must be chained with && (";" ignores the
		// first command's failure) for the same reason. Also guard against ||
		// which is fail-open (second command only runs when the first fails).
		for (const line of commandLines) {
			expect(
				line,
				`hook line must not chain commands with ';': ${line}`,
			).not.toContain(";");
			expect(
				line,
				`hook line must not chain commands with '||': ${line}`,
			).not.toContain("||");
		}
```

Reviews (3): Last reviewed commit: "test(hooks): guard pre-commit fail-fast ..." | Re-trigger Greptile

…ootstrap

- the husky v9 bootstrap lines (#!/usr/bin/env sh + husky.sh sourcing) print
  a deprecation warning on every commit and will hard-fail in husky v10
- pre-commit only ran lint-staged (eslint), so type errors reached CI before
  anyone noticed; tsc --noEmit takes ~5s here, cheap enough to gate commits

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

pre-commit hook adds explicit typecheck after lint-staged and removes the Husky shell wrapper initialization. the change simplifies the hook script and ensures TypeScript validation runs before commit.

Changes

Pre-commit hook typecheck

Layer / File(s) Summary
Pre-commit hook with typecheck step
.husky/pre-commit
Hook runs npx lint-staged followed by npm run typecheck; Husky shell wrapper initialization removed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

note: this is a minimal change to the git hook, but several edge cases matter: (1) ensure npm run typecheck is defined in package.json and won't fail or hang on windows. (2) verify the simplified shebang still works across linux, macos, and windows git hooks. (3) no regression test exists for the hook behavior itself—only integration tests running the full commit workflow would catch a broken hook, and those are often skipped in ci. (4) concurrent commits or hook execution could surface race conditions if typecheck accesses shared temp files.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning title exceeds 72 character limit at 74 characters, violating conventional commits format requirement. shorten title to ≤72 characters, e.g. 'chore(hooks): run typecheck, drop husky v9 bootstrap' (55 chars).
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description comprehensively covers the changes, testing approach, and includes detailed technical context with Greptile analysis. All critical information is present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/audit-05-precommit-typecheck
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/audit-05-precommit-typecheck

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread .husky/pre-commit Outdated
Review follow-up: plain sh runs sequential lines unconditionally and exits
with the last command's status, so a lint-staged failure followed by a
clean typecheck would let the commit through. Chain with && so the first
failure short-circuits.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.husky/pre-commit:
- Around line 1-2: Add a regression guard that asserts the .husky/pre-commit
hook preserves fail-fast behavior when multiple commands are present: implement
a CI check (e.g., a lightweight script run in CI) that reads .husky/pre-commit
and fails if the file contains multiple commands like "npx lint-staged" and "npm
run typecheck" but does not include either "&&" or "set -e"; update CI config to
run this check (name it e.g. husky-precommit-guard) so future edits that drop
the "&&" or "set -e" will cause the pipeline to fail.
- Around line 1-2: Make the pre-commit hook fail-fast: update the
.husky/pre-commit file to start with a POSIX shebang (#!/usr/bin/env sh), ensure
the file is executable (chmod +x), and make the two commands run atomically by
either adding "set -e" at top or joining them with "&&" (e.g., npx lint-staged
&& npm run typecheck) so a failure stops the commit; then add a regression test
(e.g., a new test named assertPreCommitHookIsFailFast) that reads the hook and
asserts it contains either "set -e" or "&&" to prevent future drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6027e6c9-152b-4d97-8f76-31d770350781

📥 Commits

Reviewing files that changed from the base of the PR and between 98d9819 and a502a7a.

📒 Files selected for processing (1)
  • .husky/pre-commit
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Greptile Review

Comment thread .husky/pre-commit Outdated
Review follow-up: lock the hook contract with a small regression test —
multi-line hooks must set -e, single-line hooks must not chain with ';',
and the deprecated husky v9 bootstrap must not return.

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
@ndycode
ndycode merged commit d60d0ae into main Jun 10, 2026
2 checks passed
luo178 pushed a commit to luo178/codex-multi-auth that referenced this pull request Jun 23, 2026
…audit

Snapshot audit against v2.3.0-beta.1 (HEAD 98d9819) covering architecture,
security, correctness/concurrency, testing/CI, packaging, and docs/DX:

- verified findings table (4 HIGH, 13 MEDIUM, 5 LOW) with file:line evidence
- index of the five companion fix PRs (ndycode#517-ndycode#521)
- prioritized refactor roadmap with concrete seams for codex-manager.ts,
  fetch-helpers.ts, runtime-rotation-proxy.ts, retry consolidation,
  error-contract adoption, CI consolidation, and packaging trims
- rejected-findings section recording disproven automated claims so future
  audits do not re-litigate them

https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants