fix: replace dirname with POSIX parameter expansion in issue-sync scripts#2607
fix: replace dirname with POSIX parameter expansion in issue-sync scripts#2607marcusquinn wants to merge 1 commit intomainfrom
Conversation
…ipts
Replace $(dirname "${BASH_SOURCE[0]}") with ${BASH_SOURCE[0]%/*} in
issue-sync-helper.sh and issue-sync-lib.sh. The dirname command is not
available in stripped PATH environments (e.g., Claude Code MCP pulse
sessions), causing all TODO-to-GitHub issue syncs to fail silently.
The %/* parameter expansion is a bash builtin that performs the same
directory extraction without requiring an external command in PATH.
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 enhances the reliability of the issue synchronization scripts by refactoring how script directories are determined. By replacing an external command with a native bash parameter expansion, the scripts are now resilient to environments with restricted PATH variables, ensuring consistent operation and preventing silent failures in critical automated workflows. Highlights
Changelog
Activity
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)
WalkthroughFixed two bash scripts that fail in stripped PATH environments by replacing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 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 |
|
Duplicate of #2608 — closing in favour of the more complete fix. |
There was a problem hiding this comment.
Code Review
This pull request replaces the external dirname command with the more robust and performant POSIX parameter expansion ${BASH_SOURCE[0]%/*}. This is a great improvement, especially for environments with a minimal PATH. However, the current implementation is not a direct equivalent of dirname and introduces a regression in an edge case: when a script is executed from within its own directory without a path prefix. In this scenario, the parameter expansion returns the script name itself, causing the cd command to fail. I've provided suggestions to make the implementation fully robust and handle this case correctly.
| 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 using parameter expansion is a great improvement for performance and robustness in minimal environments, this specific implementation isn't a fully equivalent replacement for dirname. It introduces a failure case when the script is executed from its own directory without a path prefix (e.g., cd .agents/scripts && ./issue-sync-helper.sh would work, but issue-sync-helper.sh would fail if it's in the PATH and called from within its directory).
If ${BASH_SOURCE[0]} contains no slashes (e.g., just issue-sync-helper.sh), the expansion ${BASH_SOURCE[0]%/*} returns the script name itself. cding to a file will fail. dirname correctly returns . in this case.
To make this more robust and handle all invocation scenarios correctly, you could add a check for 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.
Similar to the other file, this change introduces a regression. While using parameter expansion is a great improvement, this specific implementation isn't a fully equivalent replacement for dirname. It introduces a failure case when the script is sourced from its own directory without a path prefix.
If ${BASH_SOURCE[0]} contains no slashes (e.g., just issue-sync-lib.sh), the expansion ${BASH_SOURCE[0]%/*} returns the script name itself. cding to a file will fail. dirname correctly returns . in this case.
To make this more robust and handle all invocation scenarios correctly, you could add a check for this edge case.
| SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" | |
| SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)" |
Summary
$(dirname "${BASH_SOURCE[0]}")with${BASH_SOURCE[0]%/*}inissue-sync-helper.sh(line 21) andissue-sync-lib.sh(line 31)dirnamecommand is an external binary not available in stripped PATH environments (e.g., Claude Code MCP pulse sessions), causing all TODO-to-GitHub issue syncs to fail silently across all 6 pulse-enabled repos%/*parameter expansion is a bash builtin that performs identical directory extraction without requiring any external commandVerification
Tested with
PATH=""— old version fails at line 21 withdirname: No such file or directory, new version passes through successfully. ShellCheck clean (zero new warnings).Note
~200 other scripts in
.agents/scripts/use the samedirnamepattern. This PR fixes only the two scripts in the critical pulse path. A follow-up issue should address the systemic pattern across all scripts.Closes #2605
Summary by CodeRabbit