fix(monitor): detect tmux base-index after starting the server (+ macOS bash 3.2 test portability) - #330
Conversation
Walkthrough
Changestmux base-index ordering fix
macOS bash 3.2 test portability
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/unit/test_log_rotation.bats`:
- Around line 84-86: The BSD stat stub branch prints the byte count using wc -c
but then falls through to the real_stat exec call on the following line,
appending extra output. Add a return statement immediately after the wc -c line
to terminate that branch and prevent fall-through to the exec statement,
ensuring the stub outputs only the byte count without additional output from the
real stat command.
🪄 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: CHILL
Plan: Pro
Run ID: 3473e6ba-83e8-4c43-821c-aa845c7df9d5
📒 Files selected for processing (6)
ralph_loop.shtests/integration/test_monitor.batstests/integration/test_tmux_integration.batstests/unit/test_log_rotation.batstests/unit/test_notifications.batstests/unit/test_ralph_enable.bats
| # Portable byte count — real stat's -c%s is GNU-only and fails on BSD/macOS, | ||
| # which silently defeated this fallback simulation there. wc -c works everywhere. | ||
| wc -c < "\$1" |
There was a problem hiding this comment.
Terminate the BSD stat stub branch after printing size.
On Line 86, the stub prints byte count via wc -c, but then falls through to Line 88 (exec "$real_stat" "$@"). That can append extra output and make the fallback simulation inaccurate.
Proposed fix
if [[ "$1" == "-f%z" ]]; then
shift
# Portable byte count — real stat's -c%s is GNU-only and fails on BSD/macOS,
# which silently defeated this fallback simulation there. wc -c works everywhere.
wc -c < "$1"
+ exit 0
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Portable byte count — real stat's -c%s is GNU-only and fails on BSD/macOS, | |
| # which silently defeated this fallback simulation there. wc -c works everywhere. | |
| wc -c < "\$1" | |
| if [[ "$1" == "-f%z" ]]; then | |
| shift | |
| # Portable byte count — real stat's -c%s is GNU-only and fails on BSD/macOS, | |
| # which silently defeated this fallback simulation there. wc -c works everywhere. | |
| wc -c < "$1" | |
| exit 0 | |
| fi |
🤖 Prompt for 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.
In `@tests/unit/test_log_rotation.bats` around lines 84 - 86, The BSD stat stub
branch prints the byte count using wc -c but then falls through to the real_stat
exec call on the following line, appending extra output. Add a return statement
immediately after the wc -c line to terminate that branch and prevent
fall-through to the exec statement, ensuring the stub outputs only the byte
count without additional output from the real stat command.
setup_tmux_session() detected base-index/pane-base-index before creating the tmux session. `tmux show-options` does not auto-start a server, so on the first `ralph --monitor` run (no server yet) detection silently errored and defaulted to 0. With a `base-index 1` / `pane-base-index 1` config this made every pane/window target off-by-one (e.g. pane `1.0`, window `0`), so the `ralph --live` loop command was sent to a nonexistent pane and tmux opened to empty idle panes — the loop never started. Detect AFTER `tmux new-session` starts the server (which sources the user's config), making detection reliable even on first run. Mirrors the reorder in the test's inline setup_tmux_session copy and adds a regression test asserting `new-session` precedes `show-options` in the call log. Co-Authored-By: Claude <noreply@anthropic.com>
The suite assumed bash 4+/5. On macOS the system shell is bash 3.2.57, and two platform gaps broke 15 tests (all green on Linux CI): 1. `source <(process-substitution)` does NOT define functions on bash 3.2 (they silently stay undefined → "command not found"). This broke all 11 test_monitor.bats tests and 2 test_ralph_enable.bats tests that sourced via `<()`. Fix: write to a temp file and `source` the file (works on 3.2 and 5 alike). 2. `head -n -1` is a GNU coreutils extension (BSD head rejects it: "illegal line count -- -1"). Fix: `sed '$d'` (POSIX). 3. test_log_rotation: the BSD-stat fallback stub delegated to `real stat -c%s` (GNU-only), which fails on macOS and silently defeated the fallback under test. Fix: return the size via portable `wc -c`. 4. test_notifications: the notify-send branch is unreachable on macOS (osascript is always present; /bin symlinks to /usr/bin so it cannot be hidden via PATH). Skip that test on Darwin — it still runs on Linux CI. Result: `npm test` is 1275/1275 green on macOS (was 1260/1274). Co-Authored-By: Claude <noreply@anthropic.com>
5919e0c to
f9c1c66
Compare
Cross-family review — opencode (zai/glm-5.2)Review Findings1. Major —
|
Without exit 0 the stub fell through to exec'ing the real stat (with $1 already shifted off), appending multi-line default-format output after the byte count and polluting the captured file_size. Flagged by CodeRabbit and the cross-family GLM review; mutation-verified (breaking the -f%z fallback in log_utils.sh now fails the test).
Final Triage Summary (PR #330)Cutoff: 2026-07-10T18:21:42Z — no new findings since cutoff. Fixed
Skipped (with justification)
CI note
Demo
|
What
Two related macOS-support fixes — both verified on Darwin (bash 3.2.57) and unchanged on Linux CI.
1. fix(monitor): detect tmux base-index AFTER starting the server
setup_tmux_session()detectedbase-index/pane-base-indexbefore creating the tmux session.tmux show-optionsdoes not auto-start a server, so on the firstralph --monitorrun (no server yet) detection silently errored and defaulted to0. With abase-index 1/pane-base-index 1config this made everywindow.panetarget off-by-one (e.g. pane1.0, window0), so theralph --liveloop command was sent to a nonexistent pane — tmux opened to empty idle panes and the loop never started.Fix: detect after
tmux new-sessionstarts the server (which sources the user's config), so detection is reliable even on first run. Mirrors the reorder in the test's inlinesetup_tmux_sessionand adds a regression test assertingnew-sessionprecedesshow-optionsin the call log.2. test: make the bats suite portable to macOS bash 3.2
15 tests passed on Linux CI but failed on macOS. Root causes:
source <(process-substitution)does not define functions on bash 3.2 (they silently stay undefined → "command not found"). Broke 11test_monitor.bats+ 2test_ralph_enable.batstests. Fix: write to a temp file andsourcethe file.head -n -1is GNU-only (BSD head rejects it: "illegal line count"). Fix:sed '$d'.test_log_rotationBSD-stat stub delegated to GNUstat -c%s(fails on BSD). Fix: portablewc -c.test_notificationsnotify-send branch is unreachable on macOS (osascript always present;/binsymlinks to/usr/bin). Skip on Darwin — still runs on Linux CI.Verification
npm test: 1275/1275 green on macOS (was 1260/1274); tmux integration suite 32/32.0→ empty panes) and confirmed the fix end-to-end on a real project with abase-index 1config on a first--monitorrun — the Ralph loop now starts correctly and runs Claude iterations.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
ralph --monitorrun when no tmux server exists.Tests