Skip to content

refactor: replace process.stdin with Bun.stdin.json() - #47

Open
johnlindquist wants to merge 18 commits into
mainfrom
cu-feasible-gorilla
Open

johnlindquist wants to merge 18 commits into
mainfrom
cu-feasible-gorilla

Conversation

@johnlindquist

@johnlindquist johnlindquist commented Jul 29, 2025

Copy link
Copy Markdown
Owner

Summary

This PR refactors the stdin handling in the hooks system to use Bun's built-in JSON parsing capabilities.

Changes

  • 🔄 Replace process.stdin.on('data', ...) with await Bun.stdin.json() in templates/hooks/lib.ts
  • 🔄 Update runHook function to be async
  • 🔄 Update templates/hooks/index.ts to await the async runHook call
  • ✅ Add comprehensive unit tests for stdin handling
  • ✅ Update smoke tests to verify the new implementation

Benefits

  • Cleaner code: Removes manual stream handling and JSON parsing
  • More efficient: Uses Bun's optimized JSON parsing
  • Better error handling: Built-in JSON parsing handles malformed input
  • Modern approach: Aligns with Bun's recommended patterns

Testing

  • ✅ New unit tests pass for both small and large JSON payloads
  • ✅ Smoke tests updated to check for new implementation
  • ⚠️ Integration tests have pre-existing issues with signal-exit module (unrelated to this change)

Technical Details

The change modernizes the stdin handling from:

process.stdin.on('data', async (data) => {
  const inputData = JSON.parse(data.toString())
  // ...
})

To:

const inputData = await Bun.stdin.json()
// ...

This simplifies the code and leverages Bun's native capabilities for better performance and reliability.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of JSON input from standard input, ensuring asynchronous processing and better error management for hook scripts.
  • Tests

    • Updated existing tests to reflect the new asynchronous input handling approach.
    • Added new tests to verify correct parsing of JSON input from standard input and handling of large payloads in hook scripts.
  • Chores

    • Introduced a Git pre-push hook to run linting and tests before code pushes.
    • Updated GitHub Actions workflows and package scripts to use the Bun test runner with timeouts.
    • Enhanced test suite compatibility and stability on Windows with improved temp directory management and error handling.
  • Documentation

    • Added detailed examples and best practices for PreToolUse hook implementations.
    • Added README documentation for Git hooks setup and usage.

- Update runHook to use await Bun.stdin.json() for cleaner JSON parsing
- Make runHook function async and update callers
- Add comprehensive unit tests for stdin handling
- Update smoke tests to check for new implementation

This change modernizes the stdin handling to use Bun's built-in JSON
parsing capabilities, removing the need for manual stream handling
and JSON parsing.
@coderabbitai

coderabbitai Bot commented Jul 29, 2025

Copy link
Copy Markdown

Walkthrough

The changes update the stdin handling in hook scripts from a Node.js-style event-based approach to an asynchronous Bun-specific method using await Bun.stdin.json(). This update is reflected in both the implementation and associated tests. Additionally, a new test suite is introduced to verify correct stdin JSON parsing and handling of large payloads. The GitHub Actions workflow and package.json test scripts are switched to use bun test. A new Git pre-push hook and its documentation are added to enforce linting and testing before pushes. The init command tests are improved for Windows compatibility with enhanced temp directory handling and error management. A new markdown file documents PreToolUse hook examples from various repos.

Changes

Cohort / File(s) Change Summary
Hook Script Invocation Update
templates/hooks/index.ts
Adds await before runHook to ensure asynchronous execution is properly awaited.
Hook Implementation Refactor
templates/hooks/lib.ts
Refactors stdin handling: replaces event-based reading with await Bun.stdin.json(), updates runHook to return a Promise, and wraps logic in a try-catch for error handling.
Test Update for Stdin Handling
test/smoke/generated-files.test.ts
Updates test assertions to expect await Bun.stdin.json() instead of event-based stdin reading in generated files.
New Stdin Handling Tests
test/unit/stdin-handling.test.ts
Adds a new test suite with two tests: one for basic JSON stdin parsing and response, and one for handling large JSON payloads via stdin.
Git Hooks Setup
.githooks/README.md, .githooks/pre-push
Adds documentation and a shell script for a Git pre-push hook that runs linting and tests before allowing pushes.
CI Workflow Update
.github/workflows/test.yml
Changes GitHub Actions test steps to run bun test with timeouts instead of npm scripts.
Package.json Test Scripts Update
package.json
Switches test scripts from Mocha to Bun test runner with appropriate timeouts and directory targeting.
Init Command Test Improvements
test/commands/init.test.ts
Enhances Windows compatibility by using temporary directories, retrying cleanup on EBUSY errors, adding timeouts and windowsHide options to execSync calls, and improving error logging.
PreToolUse Hook Documentation
examples/pretooluse-hook-examples.md
Adds extensive markdown documentation with example PreToolUse hook implementations, patterns, best practices, and recommendations from various repos.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HookScript
    participant Bun

    User->>HookScript: Start process
    HookScript->>Bun: await Bun.stdin.json()
    Bun-->>HookScript: JSON input
    HookScript->>HookScript: Process input, invoke handler
    HookScript-->>User: Output JSON response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Suggested labels

released

Poem

A rabbit with code in its hat,
Swapped out old stdin—imagine that!
With Bun’s await, the input flows,
No more events, just JSON it knows.
Tests for big payloads now hop in the mix,
This update’s as smooth as a carrot-stick fix! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cu-feasible-gorilla

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 303a3e4 and 848bdd6.

📒 Files selected for processing (4)
  • templates/hooks/index.ts (1 hunks)
  • templates/hooks/lib.ts (1 hunks)
  • test/smoke/generated-files.test.ts (1 hunks)
  • test/unit/stdin-handling.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
templates/**/*

📄 CodeRabbit Inference Engine (CLAUDE.md)

Hook templates must be stored in the templates/ directory and copied to the user's .claude/ directory when initialized.

Files:

  • templates/hooks/index.ts
  • templates/hooks/lib.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Hooks are executed using the Bun runtime (required dependency).
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Test files should be organized and run using the provided bun scripts: `bun test`, `bun run test:unit`, `bun run test:integration`, `bun run test:smoke`, `bun run test:coverage`.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., `bun run build`, `bun run lint`, `bun run format`, `bun run clean`).
templates/hooks/index.ts (2)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Hooks are executed using the Bun runtime (required dependency).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create .claude/settings.json, .claude/hooks/index.ts, .claude/hooks/lib.ts, and .claude/hooks/session.ts.

test/smoke/generated-files.test.ts (4)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Test with a tsconfig.json in the current directory.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Test files should be organized and run using the provided bun scripts: bun test, bun run test:unit, bun run test:integration, bun run test:smoke, bun run test:coverage.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Hooks are executed using the Bun runtime (required dependency).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create .claude/settings.json, .claude/hooks/index.ts, .claude/hooks/lib.ts, and .claude/hooks/session.ts.

test/unit/stdin-handling.test.ts (6)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Test files should be organized and run using the provided bun scripts: bun test, bun run test:unit, bun run test:integration, bun run test:smoke, bun run test:coverage.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Test with a tsconfig.json in the current directory.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create .claude/settings.json, .claude/hooks/index.ts, .claude/hooks/lib.ts, and .claude/hooks/session.ts.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., bun run build, bun run lint, bun run format, bun run clean).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Hooks are executed using the Bun runtime (required dependency).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Test from different directories to catch path-related issues.

templates/hooks/lib.ts (3)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Hooks are executed using the Bun runtime (required dependency).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create .claude/settings.json, .claude/hooks/index.ts, .claude/hooks/lib.ts, and .claude/hooks/session.ts.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.825Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., bun run build, bun run lint, bun run format, bun run clean).

🧬 Code Graph Analysis (1)
templates/hooks/lib.ts (1)
src/commands/init.ts (1)
  • updateSettings (221-318)
🪛 GitHub Actions: test
test/unit/stdin-handling.test.ts

[error] 1-1: TypeScript error TS2307: Cannot find module 'bun:test' or its corresponding type declarations.

🔇 Additional comments (7)
templates/hooks/lib.ts (3)

149-149: LGTM: Function signature correctly updated to async.

The runHook function signature is properly updated to return Promise<void>, reflecting the asynchronous nature of the new stdin handling.


152-158: Excellent refactoring to use Bun's native JSON parsing.

The change from manual event-based process.stdin handling to await Bun.stdin.json() is a significant improvement:

  • Cleaner, more readable code
  • Leverages Bun's optimized JSON parsing
  • Eliminates manual stream handling and string concatenation
  • Better aligns with Bun's modern async patterns

229-232: Good error handling with appropriate fallback.

The try-catch block properly handles malformed JSON input and provides a sensible default response (action: 'continue') to prevent hook failures from blocking the system.

templates/hooks/index.ts (1)

145-145: LGTM: Correctly added await for async runHook call.

The addition of await is necessary since runHook now returns a Promise<void>. This ensures proper asynchronous execution flow.

test/smoke/generated-files.test.ts (1)

154-157: LGTM: Test expectation correctly updated for new stdin handling.

The test assertion properly validates that the generated lib.ts file uses the new await Bun.stdin.json() approach instead of the previous event-based process.stdin handling. This ensures the smoke test stays in sync with the implementation changes.

test/unit/stdin-handling.test.ts (2)

24-89: Excellent test coverage for basic JSON stdin handling.

This test thoroughly validates the new Bun.stdin.json() functionality:

  • Creates a realistic hook script that uses the new API
  • Tests actual process execution with stdin/stdout communication
  • Verifies correct JSON parsing and response generation
  • Includes proper error handling for process failures

The test design is robust and provides confidence in the refactoring.


91-154: Great test for large payload handling.

This test ensures the new stdin handling can manage large JSON payloads (100KB), which is important for hook systems that might receive substantial data. The test structure mirrors the first test with appropriate modifications for the large payload scenario.

Comment on lines +1 to +6
import {afterEach, beforeEach, describe, expect, it} from 'bun:test'
import {spawn} from 'child_process'
import {promises as fs} from 'fs'
import os from 'os'
import path from 'path'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the TypeScript import error for bun:test.

The pipeline is failing because TypeScript cannot find the bun:test module types. This is likely because the test environment doesn't have the proper Bun type definitions.

Based on the retrieved learnings that indicate tests should use the provided bun scripts, verify that the test environment has the correct Bun setup:

#!/bin/bash
# Check if @types/bun is installed and bun test types are available
cd "$(git rev-parse --show-toplevel)"
bun --version
ls -la node_modules/@types/bun/ 2>/dev/null || echo "No @types/bun found"
bun test --help | head -5
🧰 Tools
🪛 GitHub Actions: test

[error] 1-1: TypeScript error TS2307: Cannot find module 'bun:test' or its corresponding type declarations.

🤖 Prompt for AI Agents
In test/unit/stdin-handling.test.ts at the beginning of the file, the import
from 'bun:test' causes a TypeScript error due to missing Bun type definitions.
To fix this, ensure the test environment is correctly set up with Bun's type
definitions by verifying that @types/bun is installed and accessible. Run the
provided shell commands to check Bun's version, confirm the presence of
@types/bun in node_modules, and validate that 'bun test' is properly configured.
Adjust the environment or install missing types so TypeScript can resolve
'bun:test' module types without errors.

- Use unique temp directories for each test to avoid Windows file locking issues
- Add timeout and windowsHide options to all execSync calls
- Fix duplicate object properties in test configuration
- Update CI workflow to use 'bun test' directly instead of 'npm test'
- Remove unreachable code after this.skip() calls
- Increase execSync timeout from 10s to 30s for all tests
- Add better error logging in the 'runs setup' test
- Set explicit stdio options to prevent hanging
- Set 30s timeout for all tests to prevent Windows timeouts
- Ensure GitHub Actions already has the timeout flag
- Add better error logging to stdin tests to debug Windows issues
- Change permission test skip approach for bun test compatibility
- Add check for empty output before JSON parsing

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
examples/pretooluse-hook-examples.md (2)

293-307: Remove trailing colons from section headings

Markdown-lint (MD026) flags headings that end with punctuation. Deleting the colons keeps the headings valid and cleaner.

-### Common patterns observed:
+### Common patterns observed

-### Best practices identified:
+### Best practices identified

-### Recommendations for implementation:
+### Recommendations for implementation

104-109: Tighten wording in bullet points

Language-Tool highlights the phrase “with success/failure status” as wordy. Switching to a more concise wording improves readability.

- Returns structured HookResult objects with success/failure status and exit codes
+ Returns structured HookResult objects containing status flags and exit codes

- Hooks return standardized result objects with success/failure status
+ Hooks return standardized result objects that include status flags

Also applies to: 296-297

.github/workflows/test.yml (1)

69-69: Add missing newline at end of file.

The YAML file is missing a newline character at the end, which violates YAML formatting standards.

Apply this fix:

-      - run: bun test --timeout 30000 test/integration
+      - run: bun test --timeout 30000 test/integration
+
package.json (1)

93-93: Add missing newline at end of file.

The JSON file is missing a newline character at the end, which is a formatting best practice.

Apply this fix:

 }
+
.githooks/pre-push (1)

16-16: Consider using the package.json test script for consistency.

While bun test works correctly, using npm test (which now runs bun test --timeout 30000) would be more consistent with the package.json scripts and provide the same timeout configuration used in CI.

Apply this change for consistency:

-bun test
+npm test

This ensures the same timeout and configuration as defined in package.json and used in CI workflows.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 659672d and 2b45132.

📒 Files selected for processing (7)
  • .githooks/README.md (1 hunks)
  • .githooks/pre-push (1 hunks)
  • .github/workflows/test.yml (3 hunks)
  • examples/pretooluse-hook-examples.md (1 hunks)
  • package.json (1 hunks)
  • test/commands/init.test.ts (16 hunks)
  • test/unit/stdin-handling.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .githooks/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/stdin-handling.test.ts
🧰 Additional context used
📓 Path-based instructions (2)
package.json

📄 CodeRabbit Inference Engine (CLAUDE.md)

The project must use ESM modules ("type": "module").

Files:

  • package.json
{package.json,src/commands/**/*}

📄 CodeRabbit Inference Engine (CLAUDE.md)

When improving CLI help, update the package.json description to match README, update command descriptions in the static description field, run npx oclif manifest after changes, and consider removing irrelevant plugins.

Files:

  • package.json
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Hooks are executed using the Bun runtime (required dependency).
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., `bun run build`, `bun run lint`, `bun run format`, `bun run clean`).
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test files should be organized and run using the provided bun scripts: `bun test`, `bun run test:unit`, `bun run test:integration`, `bun run test:smoke`, `bun run test:coverage`.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create `.claude/settings.json`, `.claude/hooks/index.ts`, `.claude/hooks/lib.ts`, and `.claude/hooks/session.ts`.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to {package.json,src/commands/**/*} : When improving CLI help, update the package.json description to match README, update command descriptions in the static description field, run `npx oclif manifest` after changes, and consider removing irrelevant plugins.
package.json (8)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test files should be organized and run using the provided bun scripts: bun test, bun run test:unit, bun run test:integration, bun run test:smoke, bun run test:coverage.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., bun run build, bun run lint, bun run format, bun run clean).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to {package.json,src/commands/**/*} : When improving CLI help, update the package.json description to match README, update command descriptions in the static description field, run npx oclif manifest after changes, and consider removing irrelevant plugins.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to package.json : The project must use ESM modules ("type": "module").

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to bin/run.js : Use NODE_ENV=production to affect behavior during import time.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test with a tsconfig.json in the current directory.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Always test with the actual published npm package using npx package-name@latest before declaring a fix complete.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to bin/run.js : Set NODE_ENV=production in bin/run.js BEFORE importing @oclif/core to prevent TypeScript detection warnings.

.githooks/pre-push (3)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Ensure all existing tests pass before pushing.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., bun run build, bun run lint, bun run format, bun run clean).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test files should be organized and run using the provided bun scripts: bun test, bun run test:unit, bun run test:integration, bun run test:smoke, bun run test:coverage.

.github/workflows/test.yml (4)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test files should be organized and run using the provided bun scripts: bun test, bun run test:unit, bun run test:integration, bun run test:smoke, bun run test:coverage.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Commands for building, linting, formatting, and cleaning should use the provided bun scripts (e.g., bun run build, bun run lint, bun run format, bun run clean).

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Ensure all existing tests pass before pushing.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test with a tsconfig.json in the current directory.

test/commands/init.test.ts (7)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test with a tsconfig.json in the current directory.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test from different directories to catch path-related issues.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to {package.json,src/commands/**/*} : When improving CLI help, update the package.json description to match README, update command descriptions in the static description field, run npx oclif manifest after changes, and consider removing irrelevant plugins.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to bin/run.js : Set NODE_ENV=production in bin/run.js BEFORE importing @oclif/core to prevent TypeScript detection warnings.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create .claude/settings.json, .claude/hooks/index.ts, .claude/hooks/lib.ts, and .claude/hooks/session.ts.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Test files should be organized and run using the provided bun scripts: bun test, bun run test:unit, bun run test:integration, bun run test:smoke, bun run test:coverage.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to bin/run.js : Use NODE_ENV=production to affect behavior during import time.

examples/pretooluse-hook-examples.md (2)

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The generated hook system must create .claude/settings.json, .claude/hooks/index.ts, .claude/hooks/lib.ts, and .claude/hooks/session.ts.

Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:51:09.840Z
Learning: Applies to templates/**/* : Hook templates must be stored in the templates/ directory and copied to the user's .claude/ directory when initialized.

🪛 YAMLlint (1.37.1)
.github/workflows/test.yml

[error] 69-69: no new line character at the end of file

(new-line-at-end-of-file)

🪛 LanguageTool
examples/pretooluse-hook-examples.md

[style] ~108-~108: ‘with success’ might be wordy. Consider a shorter alternative.
Context: ...- Returns structured HookResult objects with success/failure status and exit codes - Handles...

(EN_WORDINESS_PREMIUM_WITH_SUCCESS)


[style] ~296-~296: ‘with success’ might be wordy. Consider a shorter alternative.
Context: ...ooks return standardized result objects with success/failure status 4. Error Handling: C...

(EN_WORDINESS_PREMIUM_WITH_SUCCESS)

🪛 markdownlint-cli2 (0.17.2)
examples/pretooluse-hook-examples.md

293-293: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


300-300: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


307-307: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)

🔇 Additional comments (9)
.github/workflows/test.yml (1)

28-28: LGTM! Test runner migration to Bun is consistent.

The switch from npm test commands to bun test --timeout 30000 aligns perfectly with the project's migration from mocha to Bun's test runner. The 30-second timeout is appropriate for the test execution requirements.

Also applies to: 54-54, 69-69

package.json (1)

83-86: LGTM! Consistent migration to Bun test runner.

The migration from mocha to bun test across all test scripts is well-executed:

  • Main test with 30-second timeout
  • Unit and command tests without timeout (appropriate for faster tests)
  • Integration and smoke tests with 10-second timeout (balanced for CI performance)

This aligns perfectly with the retrieved learnings about using bun scripts for testing.

.githooks/pre-push (1)

1-23: LGTM! Well-structured pre-push hook with quality gates.

The hook effectively enforces code quality by running linting and tests before allowing pushes. The error handling and user feedback are well-implemented.

test/commands/init.test.ts (6)

7-7: Good addition for cross-platform compatibility.

Adding the os import enables proper temp directory handling for Windows compatibility.


17-19: Excellent improvement for test isolation.

Using fs.mkdtemp() with the system temp directory creates unique test directories, preventing test interference and improving reliability across different environments.


22-35: Robust Windows-compatible cleanup implementation.

The retry mechanism for Windows EBUSY errors is a practical solution to filesystem locking issues. The graceful error handling with the 100ms delay and final error suppression ensures tests don't fail due to cleanup issues.


47-51: Comprehensive Windows compatibility and timeout improvements.

The addition of timeout: 30000 and windowsHide: true to all execSync calls significantly improves cross-platform reliability:

  • The 30-second timeout aligns with the bun test runner migration
  • windowsHide: true prevents console window flashing on Windows
  • Explicit stdio configuration in some calls ensures proper output handling

These changes demonstrate thorough attention to Windows compatibility issues.

Also applies to: 62-68, 84-85, 99-100, 144-145, 180-181, 192-193, 200-201, 213-214, 220-221, 233-234, 246-247, 272-273, 280-281, 301-302, 320-321, 332-333, 340-341, 366-367


71-77: Enhanced error diagnostics for debugging.

The detailed error logging with stdout/stderr output will significantly help with debugging test failures, especially in CI environments where detailed error information is crucial.


352-355: Appropriate platform-specific test exclusion.

Excluding the permission error test on Windows is correct since file permissions work differently on Windows. This prevents false test failures while maintaining coverage on Unix-like systems.

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.

1 participant