ralph-claude-code/tests/unit
Frank Bria 328294847d
feat(exit): detect permission denials and halt loop (Issue #101) (#142)
When Claude Code is denied permission to execute commands (e.g., npm install),
Ralph now detects this from the permission_denials array in the JSON output
and halts the loop immediately with clear guidance for the user.

Changes:
- Add permission denial detection to parse_json_response() in response_analyzer.sh
  - Extract permission_denials array from Claude Code JSON output
  - Track has_permission_denials, permission_denial_count, denied_commands
- Add analyze_response() support for permission denial fields
- Add permission denial exit condition to should_exit_gracefully() in ralph_loop.sh
  - Permission denial takes highest priority among exit conditions
  - Display helpful guidance for updating ALLOWED_TOOLS in .ralphrc
- Update circuit breaker with CB_PERMISSION_DENIAL_THRESHOLD=2
  - Track consecutive_permission_denials in state file
  - Open circuit after 2 consecutive loops with permission denials
- Add 11 new TDD tests (6 in test_json_parsing.bats, 5 in test_exit_detection.bats)
- Update documentation in CLAUDE.md and README.md

Test count: 452 (up from 452 - added 11 new tests)

Fixes #101

Co-authored-by: Test User <test@example.com>
2026-01-29 23:17:16 -07:00
..
test_cli_modern.bats fix(setup): create .ralphrc with consistent tool permissions (#137) 2026-01-28 21:10:02 -07:00
test_cli_parsing.bats fix(setup): create .ralphrc with consistent tool permissions (#137) 2026-01-28 21:10:02 -07:00
test_enable_core.bats refactor(naming): remove @ prefix from on-disk filenames (#131) 2026-01-26 15:40:27 -07:00
test_exit_detection.bats feat(exit): detect permission denials and halt loop (Issue #101) (#142) 2026-01-29 23:17:16 -07:00
test_json_parsing.bats feat(exit): detect permission denials and halt loop (Issue #101) (#142) 2026-01-29 23:17:16 -07:00
test_ralph_enable.bats refactor(naming): remove @ prefix from on-disk filenames (#131) 2026-01-26 15:40:27 -07:00
test_rate_limiting.bats feat(structure): migrate Ralph files to .ralph/ subfolder (#109) 2026-01-20 23:22:30 -07:00
test_session_continuity.bats fix(test): ensure RESPONSE_ANALYSIS_FILE is set before use in test 199 (#133) 2026-01-27 09:32:47 -07:00
test_task_sources.bats feat(enable): add ralph-enable wizard for existing projects (v0.11.0) (#124) 2026-01-25 14:37:25 -07:00
test_wizard_utils.bats fix(wizard): redirect prompts to stderr for clean command substitution (#130) 2026-01-26 14:47:06 -07:00