Skip to content

Comments

fix: handle NVIM environment variable in test script#35

Merged
greggh merged 2 commits intogreggh:mainfrom
krishna-bala:krishna.fix-test-runner
Jun 10, 2025
Merged

fix: handle NVIM environment variable in test script#35
greggh merged 2 commits intogreggh:mainfrom
krishna-bala:krishna.fix-test-runner

Conversation

@krishna-bala
Copy link
Collaborator

@krishna-bala krishna-bala commented Jun 3, 2025

Summary

  • Fixes test script failing when run from within Neovim/Claude Code
  • Detects when $NVIM points to a socket instead of the nvim executable
  • Automatically falls back to finding nvim in PATH when needed

Problem

When running make test from within claude-code.nvim, the test script would fail with permission errors because the $NVIM environment variable points to a Neovim socket (e.g., /run/user/1000/nvim.xxxxx.0) instead of the actual nvim executable.

Solution

The test script now checks if $NVIM is:

  1. A valid executable file → uses it
  2. A socket or invalid path → falls back to which nvim

Test plan

  • Added test_nvim_detection.sh script that verifies all scenarios work correctly
  • Tested running make test from within claude-code.nvim - now works properly
  • Tested running make test from regular terminal - continues to work as before
  • Added documentation to DEVELOPMENT.md explaining the behavior

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced a script to test detection of the Neovim executable, ensuring robust handling of the NVIM environment variable in various scenarios.
  • Documentation

    • Added detailed instructions on running tests from within Neovim, including explanation of NVIM detection logic and usage of the new test script.
  • Bug Fixes

    • Improved test script logic to correctly identify and use the appropriate Neovim executable, preventing issues when NVIM points to a socket or invalid path.

When Claude Code runs inside Neovim, the NVIM environment variable
points to a socket path instead of the nvim executable. This caused
the test script to fail with permission errors.

The fix checks if NVIM is an executable file (not a socket) before
using it, otherwise falls back to finding nvim in PATH.

This allows tests to run properly both from within Claude Code/Neovim
and from regular terminals.

Added:
- Test script to verify NVIM detection logic works correctly
- Documentation in DEVELOPMENT.md explaining the behavior
@coderabbitai
Copy link

coderabbitai bot commented Jun 3, 2025

Walkthrough

A new section was added to the documentation explaining how the test script handles the $NVIM environment variable when running tests inside Neovim. The test script was updated to more robustly detect and use the correct Neovim executable, avoiding socket files. A new script was introduced to verify this detection logic through several scenarios.

Changes

File(s) Change Summary
DEVELOPMENT.md Added documentation on running tests inside Neovim and details about $NVIM detection logic.
scripts/test.sh Improved logic for detecting and using the Neovim executable, with clearer messaging and checks.
scripts/test_nvim_detection.sh New script to test various $NVIM environment variable scenarios and validate detection logic.

Poem

In burrows deep where code does dwell,
The rabbit checks which Neovim shell.
If sockets appear, it hops away—
To find the right path for tests to play.
Now scripts are wise, detection tight,
With docs to guide you day and night!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
scripts/test.sh (1)

20-26: Use POSIX‐compliant command lookup
which is not guaranteed on all systems. Prefer the POSIX-standard command -v nvim and handle its exit status. For example:

-  NVIM=$(which nvim)
+  if ! NVIM=$(command -v nvim); then
+    echo "Error: nvim not found in PATH"
+    exit 1
+  fi
DEVELOPMENT.md (2)

190-194: Surround your Markdown lists with blank lines
Per MD032, add an empty line before and after the bullet list to improve rendering:

...
The test script will:

- Use the `$NVIM` variable…
- Fall back to finding `nvim`- Display which nvim binary…
...
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

191-191: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)


195-199: Ensure fenced code blocks are separated by blank lines
Per MD031, insert blank lines before and after your bash block:

To verify the NVIM detection logic works correctly, you can run:

```bash
./scripts/test_nvim_detection.sh

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

196-196: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)

</details>

</details>

</blockquote></details>
<details>
<summary>scripts/test_nvim_detection.sh (1)</summary><blockquote>

`23-31`: **Avoid masking return values when exporting**  
ShellCheck SC2155 recommends separating assignment and export. Also switch `which` to `command -v`:
```diff
-   export NVIM="$(which nvim)"
+   if ! NVIM=$(command -v nvim); then
+     echo "Error: nvim not found in PATH"
+     exit 1
+   fi
+   export NVIM
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 25-25: Declare and assign separately to avoid masking return values.

(SC2155)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ffdf35d and d3693c1.

📒 Files selected for processing (3)
  • DEVELOPMENT.md (1 hunks)
  • scripts/test.sh (1 hunks)
  • scripts/test_nvim_detection.sh (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
DEVELOPMENT.md

191-191: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)


196-196: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)

🪛 Shellcheck (0.10.0)
scripts/test_nvim_detection.sh

[warning] 25-25: Declare and assign separately to avoid masking return values.

(SC2155)

🔇 Additional comments (1)
scripts/test.sh (1)

15-19: Logic for selecting NVIM executable is sound
The added check correctly ensures $NVIM is only used when it’s set, executable, and not a socket, before falling back to PATH.

- Replace 'which' with POSIX-compliant 'command -v' in test scripts
- Fix markdown formatting issues in DEVELOPMENT.md (add blank lines)
- Separate variable declaration and assignment in test_nvim_detection.sh
- Add robust absolute path resolution using readlink and BASH_SOURCE
- Enhance error handling with 'set -euo pipefail' for strict mode
- Replace unreliable $0 references in bash -c contexts

These changes improve portability, reliability, and follow shell scripting
best practices while addressing all linting and formatting issues.
Copy link

@coderabbitai coderabbitai bot left a comment

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 (3)
DEVELOPMENT.md (3)

188-188: Add comma for non-restrictive clause
Insert a comma before “which” to improve readability:
“…handles the $NVIM environment variable, which normally points to a socket file…”

🧰 Tools
🪛 LanguageTool

[uncategorized] ~188-~188: Possible missing comma found.
Context: ...tically handles the $NVIM environment variable which normally points to a socket file ...

(AI_HYDRA_LEO_MISSING_COMMA)


192-195: Backtick nvim and clarify “binary”
Wrap nvim in backticks in the third bullet and consider explicitly calling it a “Neovim binary” for consistency:
“- Display which nvim binary is being used for transparency”


196-200: Note script execution permission
Recommend adding a note that scripts/test_nvim_detection.sh must be executable (e.g., chmod +x) or can be run via bash to avoid “permission denied” errors in some environments.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d3693c1 and da46677.

📒 Files selected for processing (3)
  • DEVELOPMENT.md (1 hunks)
  • scripts/test.sh (1 hunks)
  • scripts/test_nvim_detection.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/test.sh
  • scripts/test_nvim_detection.sh
🧰 Additional context used
🪛 LanguageTool
DEVELOPMENT.md

[uncategorized] ~188-~188: Possible missing comma found.
Context: ...tically handles the $NVIM environment variable which normally points to a socket file ...

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (1)
DEVELOPMENT.md (1)

186-186: New subsection heading looks good
The “### Running Tests from Within Neovim/Claude Code” heading is clear and consistent with the existing style.

@greggh
Copy link
Owner

greggh commented Jun 5, 2025

Another great one. Same thing, we'll get this going in a couple days.

@greggh greggh merged commit 275c476 into greggh:main Jun 10, 2025
7 of 11 checks passed
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