From c10efb99f9f5cfea008a0846a607a9386f9c75c2 Mon Sep 17 00:00:00 2001 From: Test User Date: Sat, 7 Feb 2026 01:45:53 -0700 Subject: [PATCH] fix: address PR review feedback from CodeRabbit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move history file init before auto-recovery logic to prevent log_circuit_transition from writing to nonexistent history file - Fix BSD date -j timezone handling: normalize tz (Z→+0000, ±HH:MM→±HHMM) and parse with %z format so UTC timestamps aren't misinterpreted as local - Update stale test counts in CLAUDE.md (420→484) and README.md (465→484) across badge, header, and inline comments --- CLAUDE.md | 2 +- README.md | 8 ++++---- lib/circuit_breaker.sh | 24 ++++++++++++------------ lib/date_utils.sh | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index ab46445..f90eb83 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -169,7 +169,7 @@ tmux attach -t ### Running Tests ```bash -# Run all tests (420 tests) +# Run all tests (484 tests) npm test # Run specific test suites diff --git a/README.md b/README.md index b5ade65..9eb6357 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI](https://github.com/frankbria/ralph-claude-code/actions/workflows/test.yml/badge.svg)](https://github.com/frankbria/ralph-claude-code/actions/workflows/test.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) ![Version](https://img.shields.io/badge/version-0.11.4-blue) -![Tests](https://img.shields.io/badge/tests-465%20passing-green) +![Tests](https://img.shields.io/badge/tests-484%20passing-green) [![GitHub Issues](https://img.shields.io/github/issues/frankbria/ralph-claude-code)](https://github.com/frankbria/ralph-claude-code/issues) [![Mentioned in Awesome Claude Code](https://awesome.re/mentioned-badge.svg)](https://github.com/hesreallyhim/awesome-claude-code) [![Follow on X](https://img.shields.io/twitter/follow/FrankBria18044?style=social)](https://x.com/FrankBria18044) @@ -18,7 +18,7 @@ Ralph is an implementation of the Geoffrey Huntley's technique for Claude Code t **Version**: v0.11.4 - Active Development **Core Features**: Working and tested -**Test Coverage**: 465 tests, 100% pass rate +**Test Coverage**: 484 tests, 100% pass rate ### What's Working Now - Autonomous development loops with intelligent exit detection @@ -624,7 +624,7 @@ If you want to run the test suite: # Install BATS testing framework npm install -g bats bats-support bats-assert -# Run all tests (465 tests) +# Run all tests (484 tests) npm test # Run specific test suites @@ -756,7 +756,7 @@ cd ralph-claude-code # Install dependencies and run tests npm install -npm test # All 465 tests must pass +npm test # All 484 tests must pass ``` ### Priority Contribution Areas diff --git a/lib/circuit_breaker.sh b/lib/circuit_breaker.sh index 3ca9bea..0ae26db 100644 --- a/lib/circuit_breaker.sh +++ b/lib/circuit_breaker.sh @@ -57,6 +57,18 @@ init_circuit_breaker() { EOF fi + # Ensure history file exists before any transition logging + if [[ -f "$CB_HISTORY_FILE" ]]; then + if ! jq '.' "$CB_HISTORY_FILE" > /dev/null 2>&1; then + # Corrupted, recreate + rm -f "$CB_HISTORY_FILE" + fi + fi + + if [[ ! -f "$CB_HISTORY_FILE" ]]; then + echo '[]' > "$CB_HISTORY_FILE" + fi + # Auto-recovery: check if OPEN state should transition (Issue #160) local current_state current_state=$(jq -r '.state' "$CB_STATE_FILE" 2>/dev/null || echo "$CB_STATE_CLOSED") @@ -111,18 +123,6 @@ EOF fi fi fi - - # Check if history file exists and is valid JSON - if [[ -f "$CB_HISTORY_FILE" ]]; then - if ! jq '.' "$CB_HISTORY_FILE" > /dev/null 2>&1; then - # Corrupted, recreate - rm -f "$CB_HISTORY_FILE" - fi - fi - - if [[ ! -f "$CB_HISTORY_FILE" ]]; then - echo '[]' > "$CB_HISTORY_FILE" - fi } # Get current circuit breaker state diff --git a/lib/date_utils.sh b/lib/date_utils.sh index ddd23fc..9aa33cb 100644 --- a/lib/date_utils.sh +++ b/lib/date_utils.sh @@ -66,10 +66,10 @@ parse_iso_to_epoch() { fi # Try BSD date -j (native macOS) - # Strip timezone suffix for BSD compatibility - local stripped="${iso_timestamp%%+*}" - stripped="${stripped%%Z*}" - if result=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$stripped" +%s 2>/dev/null) && [[ "$result" =~ ^[0-9]+$ ]]; then + # Normalize timezone for BSD parsing (Z → +0000, ±HH:MM → ±HHMM) + local tz_fixed + tz_fixed=$(echo "$iso_timestamp" | sed -E 's/Z$/+0000/; s/([+-][0-9]{2}):([0-9]{2})$/\1\2/') + if result=$(date -j -f "%Y-%m-%dT%H:%M:%S%z" "$tz_fixed" +%s 2>/dev/null) && [[ "$result" =~ ^[0-9]+$ ]]; then echo "$result" return fi