Orchestrata Ultimate › Tests › Reference › claude › test_instruction_enforcer_hook
Tests reference — tests/claude/test_instruction_enforcer_hook.py
Module of tests/claude, split out because the directory page would be too large.
Prose pending.
tests/claude/test_instruction_enforcer_hook.py
source · 99 tests · 1390 lines
Tests for
claude/hooks/instruction_enforcer_hook.py— the PreToolUse
| Kind | Name | Line | Description |
|---|---|---|---|
| function | test_get_claude_md_locations_returns_three_paths_ending_in_claude_md |
180 | |
| function | test_get_constraints_locations_returns_three_paths_ending_in_constraints_json |
189 | |
| function | test_static_location_lists_exist_for_backward_compatibility |
199 | |
| function | test_extract_json_empty_content_returns_none |
210 | |
| function | test_extract_json_full_markers_valid_json |
216 | |
| function | test_extract_json_full_markers_invalid_json_falls_through_to_pattern2 |
223 | BEGIN/END markers present but the JSON inside is malformed: pattern 1 |
| function | test_extract_json_no_markers_pattern2_with_version_key |
249 | |
| function | test_extract_json_pattern2_invalid_json_returns_none |
256 | |
| function | test_extract_json_no_json_block_at_all_returns_none |
262 | |
| function | test_load_constraints_prefers_claude_md_over_json |
272 | |
| function | test_load_constraints_falls_back_to_json_when_no_claude_md |
280 | |
| function | test_load_constraints_falls_back_to_json_when_md_has_no_json_block |
287 | |
| function | test_load_constraints_invalid_json_file_is_skipped |
297 | A malformed CLAUDE.constraints.json at the highest-priority JSON |
| function | test_load_constraints_returns_none_when_nothing_found |
311 | |
| function | test_load_constraints_unreadable_claude_md_is_skipped |
316 | loc.exists() is True but read_text() raises PermissionError (L181's |
| function | test_prohibited_patterns_empty_config_returns_none |
337 | |
| function | test_prohibited_patterns_fallback_top_level_list |
342 | No "rules" key at all -> falls back to the top-level |
| function | test_prohibited_patterns_context_any_matches_every_tool |
362 | |
| function | test_prohibited_patterns_context_matches_exact_tool_name |
369 | |
| function | test_prohibited_patterns_git_commit_context_requires_git_commit_in_cmd |
376 | |
| function | test_prohibited_patterns_python_test_file_context |
393 | |
| function | test_prohibited_patterns_assistant_response_context_always_skipped |
416 | |
| function | test_prohibited_patterns_unrecognized_context_falls_to_else_continue |
422 | |
| function | test_prohibited_patterns_empty_pattern_is_skipped |
428 | |
| function | test_prohibited_patterns_content_selection_per_tool_name |
434 | |
| function | test_prohibited_patterns_invalid_regex_is_skipped_not_raised |
450 | |
| function | test_prohibited_patterns_no_rule_matches_returns_none |
462 | |
| function | test_required_workflows_non_bash_returns_none |
476 | |
| function | test_required_workflows_fallback_top_level_list |
488 | |
| function | test_required_workflows_invalid_regex_is_skipped |
501 | |
| function | test_required_workflows_no_match_returns_none |
519 | |
| function | test_package_manager_non_bash_returns_none |
538 | |
| function | test_package_manager_str_config_with_package_extracted |
543 | |
| function | test_package_manager_dict_config_custom_tool |
554 | |
| function | test_package_manager_dict_config_defaults |
567 | |
| function | test_package_manager_no_package_after_install_yields_empty_package |
578 | |
| function | test_package_manager_no_prohibited_match_returns_none |
586 | |
| function | test_safe_file_removal_non_bash_returns_none |
600 | |
| function | test_safe_file_removal_destructive_root_rm_blocked |
605 | |
| function | test_safe_file_removal_destructive_disk_wipe_blocked |
613 | |
| function | test_safe_file_removal_destructive_fork_bomb_blocked |
621 | |
| function | test_safe_file_removal_home_workspace_exempted_from_destructive_block |
627 | The negative lookahead home(?!/mohamed/workspace) deliberately |
| function | test_safe_file_removal_other_home_path_still_destructive |
640 | |
| function | test_safe_file_removal_system_path_blocked |
648 | |
| function | test_safe_file_removal_recursive_redirects_to_shutil_rmtree |
656 | |
| function | test_safe_file_removal_rmdir_without_r_redirects_to_os_rmdir |
663 | |
| function | test_safe_file_removal_single_file_redirects_to_os_remove |
670 | |
| function | test_safe_file_removal_unrelated_command_returns_none |
683 | |
| function | test_testing_mocking_non_write_edit_returns_none |
693 | |
| function | test_testing_mocking_non_test_file_returns_none |
698 | |
| function | test_testing_mocking_allowed_by_default_returns_none |
707 | |
| function | test_testing_mocking_disallowed_catches_magicmock |
717 | |
| function | test_testing_mocking_disallowed_catches_monkeypatch_and_new_string |
729 | |
| function | test_testing_mocking_no_pattern_matches_clean_test_returns_none |
740 | |
| function | test_git_attribution_non_bash_returns_none |
759 | |
| function | test_git_attribution_no_git_commit_returns_none |
764 | |
| function | test_git_attribution_disabled_via_config_returns_none |
769 | |
| function | test_git_attribution_blocks_claude_coauthor |
780 | |
| function | test_git_attribution_clean_commit_returns_none |
791 | |
| function | test_execute_alternative_no_alternative_returns_none |
804 | |
| function | test_execute_alternative_uv_add_no_package_returns_none |
809 | |
| function | test_execute_alternative_uv_add_fails_outside_a_uv_project |
815 | A tmp_path with no pyproject.toml is not a uv project: uv add |
| function | test_execute_alternative_python3_shutil_remove_succeeds |
830 | |
| function | test_execute_alternative_python3_shutil_remove_fails_on_missing_file |
841 | |
| function | test_execute_alternative_unrecognized_alternative_returns_none |
852 | |
| function | test_execute_alternative_uv_add_binary_not_found |
874 | L628-629: subprocess.run(["uv", "add", ...]) itself raising |
| function | test_execute_alternative_python3_shutil_bash_not_found |
889 | L650-651: the ["bash", "-c", alternative] launch itself raising |
| function | test_format_block_response_with_alternative |
904 | |
| function | test_format_block_response_with_required_no_alternative |
915 | |
| function | test_format_block_response_no_alternative_no_required |
924 | |
| function | test_format_redirect_response_short_command |
931 | |
| function | test_format_redirect_response_long_command_is_truncated |
942 | |
| function | test_format_warn_response_with_alternative |
953 | |
| function | test_format_warn_response_with_required |
962 | |
| function | test_format_warn_response_neither |
968 | |
| function | test_enforce_critical_returns_block_json |
980 | |
| function | test_enforce_error_redirect_with_package_returns_allow_with_updated_input |
988 | |
| function | test_enforce_error_redirect_package_extracted_from_command_not_result |
1002 | L763-767: check_prohibited_patterns never sets "package" in its |
| function | test_enforce_error_redirect_long_original_command_is_truncated |
1037 | |
| function | test_enforce_error_redirect_without_package_falls_back_to_block |
1051 | check_safe_file_removal's ERROR result carries "alternative" (a |
| function | test_enforce_error_with_neither_redirect_nor_alternative_blocks |
1066 | L797-798: distinct from the case above — check_git_attribution's |
| function | test_enforce_warn_returns_allow_with_warning |
1087 | |
| function | test_enforce_no_match_returns_none |
1113 | |
| function | test_enforce_writes_audit_log_entry |
1119 | log_enforcement() is called on every match — the entry must land |
| function | test_enforce_log_enforcement_swallows_open_error_on_log_file |
1133 | The open(LOG_FILE, "a") / write is guarded by ``except OSError: |
| function | test_defect_log_enforcement_mkdir_not_guarded_crashes_the_hook |
1151 | KNOWN DEFECT (reported, not silently patched — see task report): |
| function | test_run_enforcement_checks_no_constraints_returns_none |
1191 | |
| function | test_run_enforcement_checks_critical_returns_block |
1197 | |
| function | test_run_enforcement_checks_error_redirect_with_package |
1205 | |
| function | test_run_enforcement_checks_package_extracted_from_command_not_result |
1217 | L850-854: the "uv add" IN alt guard (distinct from enforce()'s |
| function | test_run_enforcement_checks_error_redirect_without_package_falls_back |
1253 | Mirrors enforce()'s fallback: no "uv add" in the alternative and no |
| function | test_run_enforcement_checks_error_without_redirect_blocks |
1268 | |
| function | test_run_enforcement_checks_warn_returns_allow |
1297 | |
| function | test_run_enforcement_checks_no_match_returns_none |
1326 | |
| function | test_main_malformed_stdin_json_exits_zero_silently |
1338 | |
| function | test_main_no_constraints_found_exits_zero_silently |
1353 | |
| function | test_main_enforce_returns_none_exits_zero_silently |
1362 | |
| function | test_main_prints_block_decision_and_exits_zero |
1372 | |
| function | test_main_default_tool_name_and_input_are_empty_dicts |
1383 | A payload missing tool_name/tool_input altogether must not raise — |