@@ -154,6 +154,38 @@ else
154154 fail " Path traversal to state.md" " exit 2 (blocked)" " exit $EXIT_CODE , result: $RESULT "
155155fi
156156
157+ # Test 5c: Strict delegation blocks direct source edits outside .humanize
158+ echo " "
159+ echo " Test 5c: Strict delegation blocks direct source edits"
160+ mkdir -p " $TEST_DIR /strict-edit/.humanize/rlcr/2026-01-19_13-00-00"
161+ cat > " $TEST_DIR /strict-edit/.humanize/rlcr/2026-01-19_13-00-00/state.md" << 'EOF '
162+ ---
163+ current_round: 2
164+ max_iterations: 42
165+ plan_file: plan.md
166+ start_branch: main
167+ base_branch: main
168+ push_every_round: false
169+ codex_model: o3-mini
170+ codex_effort: medium
171+ codex_timeout: 1200
172+ review_started: false
173+ plan_tracked: false
174+ agent_teams: true
175+ delegation_enforcement: strict
176+ ---
177+ EOF
178+ JSON=' {"tool_name":"Edit","tool_input":{"file_path":"' " $TEST_DIR " ' /strict-edit/src/app.py","old_string":"old","new_string":"new"}}'
179+ set +e
180+ RESULT=$( echo " $JSON " | CLAUDE_PROJECT_DIR=" $TEST_DIR /strict-edit" bash " $PROJECT_ROOT /hooks/loop-edit-validator.sh" 2>&1 )
181+ EXIT_CODE=$?
182+ set -e
183+ if [[ $EXIT_CODE -eq 2 ]] && echo " $RESULT " | grep -qi " strict delegation required" ; then
184+ pass " Strict delegation blocks direct source edits (exit 2)"
185+ else
186+ fail " Strict delegation source edit" " exit 2 with strict delegation message" " exit $EXIT_CODE , result: $RESULT "
187+ fi
188+
157189# ========================================
158190# Plan File Validator Tests
159191# ========================================
@@ -381,6 +413,38 @@ else
381413 fail " Unrelated command" " allowed through" " exit $EXIT_CODE , result: $RESULT "
382414fi
383415
416+ # Test 12d: Strict delegation blocks mutating Bash before direct implementation
417+ echo " "
418+ echo " Test 12d: Strict delegation blocks mutating Bash commands"
419+ mkdir -p " $TEST_DIR /strict-bash/.humanize/rlcr/2026-01-19_13-30-00"
420+ cat > " $TEST_DIR /strict-bash/.humanize/rlcr/2026-01-19_13-30-00/state.md" << 'EOF '
421+ ---
422+ current_round: 2
423+ max_iterations: 42
424+ plan_file: plan.md
425+ start_branch: main
426+ base_branch: main
427+ push_every_round: false
428+ codex_model: o3-mini
429+ codex_effort: medium
430+ codex_timeout: 1200
431+ review_started: false
432+ plan_tracked: false
433+ agent_teams: true
434+ delegation_enforcement: strict
435+ ---
436+ EOF
437+ JSON=' {"tool_name":"Bash","tool_input":{"command":"touch src/new_file.py"}}'
438+ set +e
439+ RESULT=$( echo " $JSON " | CLAUDE_PROJECT_DIR=" $TEST_DIR /strict-bash" bash " $PROJECT_ROOT /hooks/loop-bash-validator.sh" 2>&1 )
440+ EXIT_CODE=$?
441+ set -e
442+ if [[ $EXIT_CODE -eq 2 ]] && echo " $RESULT " | grep -qi " strict delegation required" ; then
443+ pass " Strict delegation blocks mutating Bash commands (exit 2)"
444+ else
445+ fail " Strict delegation Bash mutation" " exit 2 with strict delegation message" " exit $EXIT_CODE , result: $RESULT "
446+ fi
447+
384448# Test 13: Edit validator handles newlines in strings
385449echo " "
386450echo " Test 13: Edit validator handles newlines in strings"
@@ -410,6 +474,52 @@ else
410474 fail " Binary content handling" " exit < 128" " exit $EXIT_CODE "
411475fi
412476
477+ # Test 14b: Strict delegation blocks direct source writes outside .humanize
478+ echo " "
479+ echo " Test 14b: Strict delegation blocks direct source writes"
480+ mkdir -p " $TEST_DIR /strict-write/.humanize/rlcr/2026-01-19_14-00-00"
481+ cat > " $TEST_DIR /strict-write/.humanize/rlcr/2026-01-19_14-00-00/state.md" << 'EOF '
482+ ---
483+ current_round: 2
484+ max_iterations: 42
485+ plan_file: plan.md
486+ start_branch: main
487+ base_branch: main
488+ push_every_round: false
489+ codex_model: o3-mini
490+ codex_effort: medium
491+ codex_timeout: 1200
492+ review_started: false
493+ plan_tracked: false
494+ agent_teams: true
495+ delegation_enforcement: strict
496+ ---
497+ EOF
498+ JSON=' {"tool_name":"Write","tool_input":{"file_path":"' " $TEST_DIR " ' /strict-write/src/new_file.py","content":"print(1)"}}'
499+ set +e
500+ RESULT=$( echo " $JSON " | CLAUDE_PROJECT_DIR=" $TEST_DIR /strict-write" bash " $PROJECT_ROOT /hooks/loop-write-validator.sh" 2>&1 )
501+ EXIT_CODE=$?
502+ set -e
503+ if [[ $EXIT_CODE -eq 2 ]] && echo " $RESULT " | grep -qi " strict delegation required" ; then
504+ pass " Strict delegation blocks direct source writes (exit 2)"
505+ else
506+ fail " Strict delegation source write" " exit 2 with strict delegation message" " exit $EXIT_CODE , result: $RESULT "
507+ fi
508+
509+ # Test 14c: Strict delegation still allows bitlesson.md updates
510+ echo " "
511+ echo " Test 14c: Strict delegation allows bitlesson.md writes"
512+ JSON=' {"tool_name":"Write","tool_input":{"file_path":"' " $TEST_DIR " ' /strict-write/bitlesson.md","content":"# BitLesson\n"}}'
513+ set +e
514+ RESULT=$( echo " $JSON " | CLAUDE_PROJECT_DIR=" $TEST_DIR /strict-write" bash " $PROJECT_ROOT /hooks/loop-write-validator.sh" 2>&1 )
515+ EXIT_CODE=$?
516+ set -e
517+ if [[ $EXIT_CODE -eq 0 ]] && ! echo " $RESULT " | grep -q ' "decision".*:.*"block"' ; then
518+ pass " Strict delegation allows bitlesson.md writes"
519+ else
520+ fail " Strict delegation bitlesson allow" " exit 0 without block" " exit $EXIT_CODE , result: $RESULT "
521+ fi
522+
413523# ========================================
414524# Concurrent Access Tests
415525# ========================================
0 commit comments