fix: issue-sync-helper.sh dirname failure in stripped PATH environments#2606
fix: issue-sync-helper.sh dirname failure in stripped PATH environments#2606alex-solovyev wants to merge 1 commit intomainfrom
Conversation
Replace `dirname` with ${BASH_SOURCE[0]%/*} in issue-sync-helper.sh and
issue-sync-lib.sh so they work in stripped PATH environments (e.g., Claude
Code MCP pulse sessions) where `dirname` is not available.
Closes #2605
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where issue synchronization scripts failed in environments with stripped PATH variables due to the unavailability of the Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
WalkthroughTwo shell scripts replace the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
|
Pulse supervisor: PR has a merge conflict (likely TODO.md divergence from main). Dispatching a worker to rebase and resolve. CI is still pending — will merge once CI passes and conflict is resolved. |
|
Duplicate of #2608 — closing in favour of the more complete fix. |
There was a problem hiding this comment.
Code Review
This pull request aims to improve script robustness by replacing the external dirname command with a bash parameter expansion. This is a good goal for portability. However, the current implementation introduces a regression in an edge case where the script is invoked without a path prefix, which can cause the script to fail. I've added comments with suggestions for a more robust implementation that handles this edge case correctly while still avoiding the dirname dependency.
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit | ||
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit |
There was a problem hiding this comment.
While ${BASH_SOURCE[0]%/*} is a good replacement for dirname to avoid an external command dependency, it behaves differently when ${BASH_SOURCE[0]} does not contain a /. For example, if the script is in the current directory and invoked as bash issue-sync-helper.sh, ${BASH_SOURCE[0]} will be issue-sync-helper.sh.
dirname "issue-sync-helper.sh"correctly returns.echo "${BASH_SOURCE[0]%/*}"returnsissue-sync-helper.sh, which causescdto fail.
This introduces a regression that can break the script in some invocation scenarios. A more robust approach would be to handle this edge case.
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit | |
| SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)" || exit |
| # Resolves SCRIPT_DIR from BASH_SOURCE so it works when sourced from any location. | ||
| if [[ -z "${SCRIPT_DIR:-}" ]]; then | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" |
There was a problem hiding this comment.
While ${BASH_SOURCE[0]%/*} is a good replacement for dirname to avoid an external command dependency, it behaves differently when ${BASH_SOURCE[0]} does not contain a /. For example, if this library is sourced from a script in the current directory that is invoked as bash script.sh, ${BASH_SOURCE[0]} will be issue-sync-lib.sh.
dirname "issue-sync-lib.sh"correctly returns.echo "${BASH_SOURCE[0]%/*}"returnsissue-sync-lib.sh, which causescdto fail.
This introduces a regression that can break the script in some invocation scenarios. A more robust approach would be to handle this edge case.
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" | |
| SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)" |
Summary
dirnamewith POSIX-compatible${BASH_SOURCE[0]%/*}parameter expansion inissue-sync-helper.shandissue-sync-lib.shdirname: command not founderror in stripped PATH environments (Claude Code MCP pulse sessions)Root Cause
dirnameis an external command that requires PATH to include/usr/bin. Claude Code MCP pulse sessions run with a stripped PATH that doesn't include it. The${var%/*}parameter expansion is a bash builtin that produces identical results without requiring any external command.Verification
${BASH_SOURCE[0]%/*}produces identical output todirname "${BASH_SOURCE[0]}"for both absolute and relative pathsCloses #2605
Summary by CodeRabbit