Skip to content

Commit d719f1e

Browse files
duyetclaudeduyetbot
committed
fix(ralph-wiggum): fix shellcheck error and add comprehensive tests
Bug fix: - Fixed multiple stderr redirections in stop-hook.sh:140 - Changed `&& \` chain to proper if-statement Tests: - Added 10 new bats tests (21 total) - Cross-platform hash function tests (_hash) - API limit handler tests (rate limit detection, wait time) - All 21 tests passing Code quality: - Ran shellcheck on all scripts - zero errors - Updated iteration log 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Co-Authored-By: duyetbot <duyetbot@users.noreply.github.com>
1 parent b8b6e23 commit d719f1e

4 files changed

Lines changed: 95 additions & 8 deletions

File tree

.claude/iteration-log.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
# Iteration Log
22

3-
## Iteration 3 (Current)
3+
## Iteration 4 (Current)
4+
5+
### What Was Done
6+
1. **Extended Test Coverage**
7+
- Added 10 new bats tests (21 total, up from 11)
8+
- New tests for cross-platform hash function (`_hash`)
9+
- New tests for api_limit_handler (rate limit detection, wait time calculation)
10+
- All 21 tests passing
11+
12+
2. **Bug Fix**
13+
- Fixed shellcheck error in `stop-hook.sh` line 140
14+
- Issue: Multiple stderr redirections competing (`&>/dev/null 2>/dev/null`)
15+
- Fixed by using proper if-statement instead of `&&` chain
16+
17+
3. **Code Quality**
18+
- Ran shellcheck on all scripts
19+
- Zero errors (only style warnings about `local` declarations)
20+
21+
### What Was Found
22+
- All scripts pass shellcheck with no errors
23+
- Test coverage is comprehensive for core functionality
24+
- Documentation is complete for all plugins
25+
26+
### What Needs To Be Done Next
27+
- Documentation and scripts are in good shape
28+
- Consider this iteration complete pending user feedback
29+
30+
---
31+
32+
## Iteration 3
433

534
### What Was Done
635
1. **Plugin Documentation Updates**
@@ -22,11 +51,6 @@
2251
- Documentation is now consistent across all plugins
2352
- All major plugins have Installation, Usage, and Architecture sections
2453

25-
### What Needs To Be Done Next
26-
1. Add more bats tests for cross-platform hash function
27-
2. Consider adding CHANGELOG.md for version tracking
28-
3. Final review pass for any remaining issues
29-
3054
---
3155

3256
## Iteration 2

.claude/ralph-loop.local.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
active: true
3-
iteration: 2
3+
iteration: 3
44
max_iterations: 0
55
completion_promise: null
66
circuit_breaker: true

ralph-wiggum/hooks/stop-hook.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ if [[ "$ENABLE_CIRCUIT_BREAKER" == "true" ]] && type can_execute &>/dev/null; th
137137
echo "$LAST_OUTPUT" | grep -qiE "error|failed|exception|traceback" && ERROR_DETECTED="error_in_output"
138138

139139
FILES_CHANGED=0
140-
command -v git &>/dev/null && git rev-parse --git-dir &>/dev/null 2>/dev/null && \
140+
if command -v git &>/dev/null && git rev-parse --git-dir &>/dev/null; then
141141
FILES_CHANGED=$(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')
142+
fi
142143

143144
NEW_STATE=$(record_loop_result "$LAST_OUTPUT" "$ERROR_DETECTED" "$FILES_CHANGED")
144145

tests/ralph-wiggum.bats

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,39 @@ setup() {
99
# Source the lib scripts
1010
source "$BATS_TEST_DIRNAME/../ralph-wiggum/lib/response_analyzer.sh"
1111
source "$BATS_TEST_DIRNAME/../ralph-wiggum/lib/circuit_breaker.sh"
12+
source "$BATS_TEST_DIRNAME/../ralph-wiggum/lib/api_limit_handler.sh"
1213
}
1314

1415
teardown() {
1516
rm -rf "$RALPH_STATE_DIR"
1617
}
1718

19+
# Cross-Platform Hash Function Tests
20+
21+
@test "hash: _hash function exists and is callable" {
22+
run bash -c 'echo "test" | _hash'
23+
[[ "$status" -eq 0 ]]
24+
[[ -n "$output" ]]
25+
}
26+
27+
@test "hash: _hash produces consistent output" {
28+
hash1=$(echo "hello world" | _hash)
29+
hash2=$(echo "hello world" | _hash)
30+
[[ "$hash1" == "$hash2" ]]
31+
}
32+
33+
@test "hash: _hash produces different output for different input" {
34+
hash1=$(echo "hello" | _hash)
35+
hash2=$(echo "world" | _hash)
36+
[[ "$hash1" != "$hash2" ]]
37+
}
38+
39+
@test "hash: calculate_output_hash works" {
40+
result=$(calculate_output_hash "test string")
41+
[[ -n "$result" ]]
42+
[[ "$result" != "no_output" ]]
43+
}
44+
1845
# Response Analyzer Tests
1946

2047
@test "response_analyzer: init creates state file" {
@@ -79,3 +106,38 @@ teardown() {
79106
state=$(get_circuit_state)
80107
[[ "$state" == "CLOSED" ]]
81108
}
109+
110+
# API Limit Handler Tests
111+
112+
@test "api_limit_handler: init creates state file" {
113+
init_limit_handler
114+
[[ -f "$RALPH_STATE_DIR/ralph-limits.json" ]]
115+
}
116+
117+
@test "api_limit_handler: detect rate limit identifies 429" {
118+
result=$(detect_rate_limit "Error: 429 Too Many Requests")
119+
[[ "$result" == "true" ]]
120+
}
121+
122+
@test "api_limit_handler: detect rate limit identifies rate limit text" {
123+
result=$(detect_rate_limit "You have hit the rate limit")
124+
[[ "$result" == "true" ]]
125+
}
126+
127+
@test "api_limit_handler: detect rate limit returns false for normal text" {
128+
result=$(detect_rate_limit "Everything is working fine")
129+
[[ "$result" == "false" ]]
130+
}
131+
132+
@test "api_limit_handler: determine limit type identifies 5-hour limit" {
133+
result=$(determine_limit_type "You have exceeded your 5-hour usage limit")
134+
[[ "$result" == "5_hour_limit" ]]
135+
}
136+
137+
@test "api_limit_handler: calculate wait time returns correct seconds" {
138+
result=$(calculate_wait_time "5_hour_limit")
139+
[[ "$result" == "3600" ]]
140+
141+
result=$(calculate_wait_time "rate_limit")
142+
[[ "$result" == "60" ]]
143+
}

0 commit comments

Comments
 (0)