claude-dev-env 1.59.0 → 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CLAUDE.md +4 -0
  2. package/audit-rubrics/category_rubrics/category-b-selector-engine-compat.md +1 -1
  3. package/audit-rubrics/category_rubrics/category-e-dead-code.md +1 -0
  4. package/audit-rubrics/category_rubrics/category-f-silent-failures.md +1 -1
  5. package/audit-rubrics/category_rubrics/category-o-docstring-vs-impl-drift.md +1 -1
  6. package/audit-rubrics/prompts/category-b-selector-engine-compat.md +2 -2
  7. package/audit-rubrics/prompts/category-e-dead-code.md +17 -4
  8. package/audit-rubrics/prompts/category-f-silent-failures.md +1 -0
  9. package/docs/CODE_RULES.md +2 -2
  10. package/hooks/blocking/code_rules_annotations_length.py +189 -10
  11. package/hooks/blocking/code_rules_dead_module_constant.py +321 -0
  12. package/hooks/blocking/code_rules_duplicate_body.py +152 -0
  13. package/hooks/blocking/code_rules_enforcer.py +38 -15
  14. package/hooks/blocking/code_rules_orphan_css_class.py +196 -0
  15. package/hooks/blocking/code_rules_typeddict_stub.py +172 -0
  16. package/hooks/blocking/config/__init__.py +5 -0
  17. package/hooks/blocking/config/verified_commit_constants.py +118 -0
  18. package/hooks/blocking/destructive_command_blocker.py +483 -61
  19. package/hooks/blocking/test_code_rules_enforcer_annotations.py +240 -0
  20. package/hooks/blocking/test_code_rules_enforcer_cap_meta.py +1 -0
  21. package/hooks/blocking/test_code_rules_enforcer_cross_skill_duplicate.py +146 -0
  22. package/hooks/blocking/test_code_rules_enforcer_dead_module_constant.py +188 -0
  23. package/hooks/blocking/test_code_rules_enforcer_dispatch_wiring.py +82 -0
  24. package/hooks/blocking/test_code_rules_enforcer_orphan_css_class.py +196 -0
  25. package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias.py +415 -0
  26. package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias_hook_routing.py +156 -0
  27. package/hooks/blocking/test_destructive_command_blocker.py +213 -0
  28. package/hooks/blocking/test_verdict_directory_write_blocker.py +720 -0
  29. package/hooks/blocking/test_verification_verdict_store.py +490 -0
  30. package/hooks/blocking/test_verified_commit_gate.py +495 -0
  31. package/hooks/blocking/test_verified_commit_message_accuracy_blocker.py +131 -0
  32. package/hooks/blocking/test_verifier_verdict_minter.py +193 -0
  33. package/hooks/blocking/verdict_directory_write_blocker.py +667 -0
  34. package/hooks/blocking/verification_verdict_store.py +686 -0
  35. package/hooks/blocking/verified_commit_gate.py +535 -0
  36. package/hooks/blocking/verified_commit_message_accuracy_blocker.py +152 -0
  37. package/hooks/blocking/verifier_verdict_minter.py +221 -0
  38. package/hooks/diagnostic/test_hook_log_extractor.py +3 -3
  39. package/hooks/hooks.json +43 -1
  40. package/hooks/hooks_constants/blocking_check_limits.py +1 -0
  41. package/hooks/hooks_constants/code_rules_enforcer_constants.py +6 -0
  42. package/hooks/hooks_constants/dead_module_constant_constants.py +20 -0
  43. package/hooks/hooks_constants/destructive_command_segment_constants.py +15 -0
  44. package/hooks/hooks_constants/duplicate_function_body_constants.py +22 -5
  45. package/hooks/hooks_constants/orphan_css_class_constants.py +40 -0
  46. package/hooks/hooks_constants/precommit_code_rules_gate_constants.py +1 -1
  47. package/hooks/validation/mypy_validator.py +59 -7
  48. package/hooks/validation/test_mypy_validator.py +94 -0
  49. package/package.json +1 -1
  50. package/rules/file-global-constants.md +7 -1
  51. package/rules/no-cross-skill-duplicate-helpers.md +29 -0
  52. package/rules/orphan-css-class.md +23 -0
  53. package/skills/_shared/pr-loop/scripts/preflight_worktree.py +392 -0
  54. package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/preflight_constants.py +70 -0
  55. package/skills/_shared/pr-loop/scripts/test_preflight_worktree.py +263 -0
  56. package/skills/autoconverge/SKILL.md +54 -17
  57. package/skills/autoconverge/reference/closing-report.md +59 -17
  58. package/skills/autoconverge/workflow/aggregate_runs.py +371 -0
  59. package/skills/autoconverge/workflow/autoconverge_report_constants/render_report_constants.py +192 -76
  60. package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +76 -0
  61. package/skills/autoconverge/workflow/converge.contract.test.mjs +395 -206
  62. package/skills/autoconverge/workflow/converge.mjs +520 -57
  63. package/skills/autoconverge/workflow/convergence_summary.py +110 -0
  64. package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-ab1c2d3e4f5a6b7c8.jsonl +2 -0
  65. package/skills/autoconverge/workflow/fixtures/wf_run/workflows/wf_881252e6-700.json +7 -0
  66. package/skills/autoconverge/workflow/render_report.py +488 -397
  67. package/skills/autoconverge/workflow/test_aggregate_runs.py +134 -0
  68. package/skills/autoconverge/workflow/test_convergence_summary.py +132 -0
  69. package/skills/autoconverge/workflow/test_render_report.py +518 -259
  70. package/skills/pr-converge/reference/per-tick.md +28 -8
  71. package/skills/rebase/SKILL.md +2 -4
  72. package/system-prompts/software-engineer.xml +2 -6
  73. package/hooks/blocking/content_search_to_zoekt_redirector.py +0 -59
  74. package/hooks/blocking/content_search_zoekt_bash_block_reason.py +0 -25
  75. package/hooks/blocking/content_search_zoekt_block_payload.py +0 -21
  76. package/hooks/blocking/content_search_zoekt_indexed_paths.py +0 -24
  77. package/hooks/blocking/content_search_zoekt_indexed_roots_config.py +0 -131
  78. package/hooks/blocking/content_search_zoekt_redirect_guidance.py +0 -52
  79. package/hooks/blocking/test_content_search_to_zoekt_redirector_integration.py +0 -61
  80. package/hooks/blocking/test_content_search_to_zoekt_redirector_unit.py +0 -92
  81. package/hooks/blocking/test_content_search_zoekt_indexed_roots_config.py +0 -102
@@ -0,0 +1,156 @@
1
+ """Entry-point tests proving the zero-payload-alias check guards hook-infrastructure files.
2
+
3
+ A pass-through alias inside a hook module is the motivating case for the
4
+ zero-payload-alias check, so the deny must fire on the same PreToolUse path a
5
+ live Write into ``packages/claude-dev-env/hooks/blocking`` would take — not only
6
+ through ``validate_content``, which hook files never reach at PreToolUse. These
7
+ tests drive the real ``main()`` stdin entry point and the pre-check CLI with a
8
+ hook-infrastructure target.
9
+
10
+ Each test builds a temporary tree whose tail mirrors a production hook directory
11
+ (``packages/claude-dev-env/hooks/blocking``) so ``is_hook_infrastructure`` matches
12
+ the target path the same way it would for the real directory.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import contextlib
18
+ import io
19
+ import json
20
+ import pathlib
21
+ import shutil
22
+ import subprocess
23
+ import sys
24
+ import tempfile
25
+ from collections.abc import Iterator
26
+ from types import SimpleNamespace
27
+
28
+ import pytest
29
+
30
+ _HOOK_DIRECTORY = pathlib.Path(__file__).resolve().parent
31
+ _HOOKS_PARENT = _HOOK_DIRECTORY.parent
32
+ if str(_HOOK_DIRECTORY) not in sys.path:
33
+ sys.path.insert(0, str(_HOOK_DIRECTORY))
34
+ if str(_HOOKS_PARENT) not in sys.path:
35
+ sys.path.insert(0, str(_HOOKS_PARENT))
36
+
37
+ from code_rules_enforcer import main # noqa: E402
38
+
39
+ code_rules_enforcer = SimpleNamespace(main=main, sys=sys)
40
+
41
+ _ENFORCER_SCRIPT_PATH = _HOOK_DIRECTORY / "code_rules_enforcer.py"
42
+
43
+ PASS_THROUGH_ALIAS_SOURCE = (
44
+ "def find_bare_path_segments(content: str) -> set[str]:\n"
45
+ " return {part for part in content.split() if part}\n"
46
+ "\n"
47
+ "def find_bare_index_segments(content: str) -> set[str]:\n"
48
+ " return find_bare_path_segments(content)\n"
49
+ )
50
+
51
+ _HOOK_INFRASTRUCTURE_TAIL = pathlib.Path("packages") / "claude-dev-env" / "hooks" / "blocking"
52
+
53
+
54
+ @pytest.fixture
55
+ def hook_blocking_dir() -> Iterator[pathlib.Path]:
56
+ base_directory = pathlib.Path(tempfile.mkdtemp())
57
+ blocking_directory = base_directory / _HOOK_INFRASTRUCTURE_TAIL
58
+ blocking_directory.mkdir(parents=True)
59
+ try:
60
+ yield blocking_directory
61
+ finally:
62
+ shutil.rmtree(base_directory, ignore_errors=False)
63
+
64
+
65
+ def _run_main_with_write_payload(
66
+ file_path: str,
67
+ content: str,
68
+ monkeypatch: pytest.MonkeyPatch,
69
+ capsys: pytest.CaptureFixture[str],
70
+ ) -> str:
71
+ """Drive ``main()`` through its stdin entry point for a Write and return stdout.
72
+
73
+ Args:
74
+ file_path: The on-disk path the Write targets.
75
+ content: The whole-file body the Write would create.
76
+ monkeypatch: The fixture used to redirect ``sys.stdin``.
77
+ capsys: The fixture used to capture the deny payload on stdout.
78
+
79
+ Returns:
80
+ The captured stdout, which holds the deny payload when violations fire.
81
+ """
82
+ write_payload = json.dumps(
83
+ {
84
+ "tool_name": "Write",
85
+ "tool_input": {"file_path": file_path, "content": content},
86
+ }
87
+ )
88
+ monkeypatch.setattr(code_rules_enforcer.sys, "stdin", io.StringIO(write_payload))
89
+ with contextlib.suppress(SystemExit):
90
+ code_rules_enforcer.main([])
91
+ return capsys.readouterr().out
92
+
93
+
94
+ def test_write_of_pass_through_alias_into_hook_directory_denies(
95
+ hook_blocking_dir: pathlib.Path,
96
+ monkeypatch: pytest.MonkeyPatch,
97
+ capsys: pytest.CaptureFixture[str],
98
+ ) -> None:
99
+ """A Write that introduces a pass-through alias into a hook file is denied.
100
+
101
+ The target lives under a hook-infrastructure path the full code-rules suite
102
+ exempts, so this proves the zero-payload-alias check still fires on the exact
103
+ directory its docstring names as the motivating case — at the PreToolUse Write
104
+ point, not only through ``validate_content``."""
105
+ new_file = hook_blocking_dir / "new_blocker.py"
106
+ stdout = _run_main_with_write_payload(
107
+ str(new_file), PASS_THROUGH_ALIAS_SOURCE, monkeypatch, capsys
108
+ )
109
+ assert stdout != "", (
110
+ "A pass-through alias written into a hook-infrastructure file must produce "
111
+ "a deny payload, got empty stdout"
112
+ )
113
+ deny_payload = json.loads(stdout)
114
+ decision = deny_payload["hookSpecificOutput"]["permissionDecision"]
115
+ reason = deny_payload["hookSpecificOutput"]["permissionDecisionReason"]
116
+ assert decision == "deny", f"expected deny, got: {decision!r}"
117
+ assert "find_bare_index_segments" in reason, (
118
+ f"the deny reason must name the pass-through alias, got: {reason!r}"
119
+ )
120
+
121
+
122
+ def test_precheck_of_pass_through_alias_at_hook_target_exits_nonzero(
123
+ hook_blocking_dir: pathlib.Path,
124
+ tmp_path_factory: pytest.TempPathFactory,
125
+ ) -> None:
126
+ """The pre-check CLI flags a pass-through alias judged at a hook-infrastructure target.
127
+
128
+ Driving the real ``--check`` argv path proves the gate's pre-check mode also
129
+ routes a hook ``.py`` target through the zero-payload-alias check rather than
130
+ exiting clean on the blanket hook-infrastructure exemption."""
131
+ staging_directory = tmp_path_factory.mktemp("staging")
132
+ candidate_file = staging_directory / "candidate.py"
133
+ candidate_file.write_text(PASS_THROUGH_ALIAS_SOURCE, encoding="utf-8")
134
+ target_path = str(hook_blocking_dir / "new_blocker.py")
135
+ completed = subprocess.run(
136
+ [
137
+ sys.executable,
138
+ str(_ENFORCER_SCRIPT_PATH),
139
+ "--check",
140
+ str(candidate_file),
141
+ "--as",
142
+ target_path,
143
+ ],
144
+ input="",
145
+ capture_output=True,
146
+ text=True,
147
+ check=False,
148
+ )
149
+ assert completed.returncode == 1, (
150
+ "a pass-through alias at a hook target must exit nonzero, got: "
151
+ f"{completed.returncode}, stdout: {completed.stdout!r}, "
152
+ f"stderr: {completed.stderr!r}"
153
+ )
154
+ assert "find_bare_index_segments" in completed.stdout, (
155
+ f"the pre-check must name the pass-through alias, got: {completed.stdout!r}"
156
+ )
@@ -247,6 +247,10 @@ def test_rm_rf_asks_when_any_target_is_non_ephemeral() -> None:
247
247
  assert response["hookSpecificOutput"]["permissionDecision"] == "ask"
248
248
 
249
249
 
250
+ def test_rm_rf_asks_when_target_has_nested_temp_segment_not_at_root() -> None:
251
+ _assert_hook_asks("rm -rf /home/victim/temp/secret")
252
+
253
+
250
254
  def test_rm_rf_asks_when_double_dash_includes_hyphen_prefixed_non_ephemeral_target() -> None:
251
255
  payload = _make_bash_payload("rm -rf -- /tmp/scratch -non_ephemeral")
252
256
 
@@ -404,6 +408,26 @@ def test_rm_rf_asks_when_tool_input_cwd_is_ephemeral_but_rm_target_is_absolute_n
404
408
  assert response["hookSpecificOutput"]["permissionDecision"] == "ask"
405
409
 
406
410
 
411
+ def test_rm_rf_asks_when_subshell_cd_changes_dir_before_relative_rm() -> None:
412
+ _assert_hook_asks('cd "/tmp/scratch" && (cd /; rm -rf etc)')
413
+
414
+
415
+ def test_rm_rf_asks_when_second_top_level_cd_changes_dir_before_relative_rm() -> None:
416
+ _assert_hook_asks('cd "/tmp/scratch" && cd / && rm -rf etc')
417
+
418
+
419
+ def test_rm_rf_asks_when_pushd_changes_dir_before_relative_rm() -> None:
420
+ _assert_hook_asks('cd "/tmp/scratch" && pushd / && rm -rf etc')
421
+
422
+
423
+ def test_rm_rf_allowed_when_subshell_cd_present_but_rm_target_is_absolute_ephemeral() -> None:
424
+ _assert_hook_allows('cd "/tmp/scratch" && (cd /; rm -rf /tmp/scratch/keep)')
425
+
426
+
427
+ def test_rm_rf_asks_when_cd_ephemeral_but_target_has_nested_tmp_segment_not_at_root() -> None:
428
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf /home/victim/tmp/secret')
429
+
430
+
407
431
  def test_git_push_force_asks_when_leading_cd_into_ephemeral_subdirectory() -> None:
408
432
  payload = _make_bash_payload('cd "/tmp/bugteam_scratch" && git push --force')
409
433
 
@@ -1038,6 +1062,14 @@ def test_compound_rm_allowed_when_two_absolute_ephemeral_targets_then_echo() ->
1038
1062
  _assert_hook_allows("rm -rf /tmp/pr136 /tmp/difftest && echo 'cleaned'")
1039
1063
 
1040
1064
 
1065
+ def test_compound_rm_allowed_when_subshell_paren_glued_rm_targets_absolute_ephemeral() -> None:
1066
+ _assert_hook_allows("rm -rf /tmp/a && (rm -rf /tmp/b)")
1067
+
1068
+
1069
+ def test_compound_rm_asks_when_subshell_paren_glued_rm_targets_non_ephemeral() -> None:
1070
+ _assert_hook_asks("rm -rf /tmp/a && (rm -rf /etc)")
1071
+
1072
+
1041
1073
  def test_compound_rm_allowed_when_followed_by_gh_pipeline_and_echo() -> None:
1042
1074
  _assert_hook_allows('rm -rf /tmp/reply && gh pr checks 19 2>&1 | head -5 && echo "x"')
1043
1075
 
@@ -1142,6 +1174,14 @@ def test_compound_rm_asks_when_second_rm_target_glues_redirect_to_non_ephemeral_
1142
1174
  _assert_hook_asks("rm -rf /tmp/a /tmp/b>/etc/hosts")
1143
1175
 
1144
1176
 
1177
+ def test_rm_rf_asks_when_cd_ephemeral_but_rm_segment_redirects_to_non_ephemeral_file() -> None:
1178
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf /tmp/x>/etc/passwd')
1179
+
1180
+
1181
+ def test_rm_rf_asks_when_cd_ephemeral_but_relative_rm_target_redirects_to_non_ephemeral_file() -> None:
1182
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf build>/etc/passwd')
1183
+
1184
+
1145
1185
  def test_compound_rm_asks_when_git_config_sets_value_after_ephemeral_rm() -> None:
1146
1186
  _assert_hook_asks("rm -rf /tmp/x && git config --global user.name evil")
1147
1187
 
@@ -1517,6 +1557,26 @@ def test_subshell_grouped_rm_asks_when_benign_command_precedes_grouped_rm() -> N
1517
1557
  _assert_hook_asks("echo hi; (rm -rf /etc)")
1518
1558
 
1519
1559
 
1560
+ def test_string_execution_asks_when_subshell_paren_glued_to_bash_dash_c() -> None:
1561
+ _assert_hook_asks('cd "/tmp/scratch" && (bash -c \'rm -rf /etc\')')
1562
+
1563
+
1564
+ def test_string_execution_asks_when_subshell_paren_glued_to_timeout_wrapping_bash() -> None:
1565
+ _assert_hook_asks('cd "/tmp/scratch" && (timeout 5 bash -c \'rm -rf /etc\')')
1566
+
1567
+
1568
+ def test_rm_rf_asks_when_cd_ephemeral_but_subshell_paren_glued_to_rm_targets_etc() -> None:
1569
+ _assert_hook_asks('cd "/tmp/scratch" && (rm -rf /etc)')
1570
+
1571
+
1572
+ def test_rm_rf_asks_when_cd_ephemeral_but_brace_glued_to_rm_targets_etc() -> None:
1573
+ _assert_hook_asks('cd "/tmp/scratch" && {rm -rf /etc;}')
1574
+
1575
+
1576
+ def test_rm_rf_allowed_when_cd_ephemeral_and_subshell_paren_wraps_relative_ephemeral_target() -> None:
1577
+ _assert_hook_allows('cd "/tmp/scratch" && (rm -rf build)')
1578
+
1579
+
1520
1580
  # --- convergence branch exemption unit tests ---
1521
1581
 
1522
1582
  import importlib.util
@@ -1773,3 +1833,156 @@ def test_launcher_execution_allows_when_timeout_infinity_wraps_ephemeral_rm() ->
1773
1833
 
1774
1834
  def test_launcher_execution_allows_when_timeout_seconds_wraps_ephemeral_rm() -> None:
1775
1835
  _assert_hook_allows("timeout 5 rm -rf /tmp/scratch")
1836
+
1837
+
1838
+ def test_rm_rf_allowed_when_cd_worktree_then_temp_env_var_rm_then_mkdir_tar_compound() -> None:
1839
+ _assert_hook_allows(
1840
+ 'cd "/Users/dev/proj/.git/worktrees/spindle" '
1841
+ '&& rm -rf "$TEMP/pr621_check" '
1842
+ '&& mkdir -p "$TEMP/pr621_check" '
1843
+ "&& git archive HEAD packages | tar -x -C \"$TEMP/pr621_check\" "
1844
+ '&& ls "$TEMP/pr621_check/packages" | head -40'
1845
+ )
1846
+
1847
+
1848
+ def test_rm_rf_allowed_when_cd_worktree_then_find_exec_rm_then_pytest_compound() -> None:
1849
+ _assert_hook_allows(
1850
+ 'cd "/Users/dev/proj/worktrees/os-update-system" '
1851
+ '&& find shared_utils/samsung_utils -name "__pycache__" -type d '
1852
+ "-exec rm -rf {} + 2>/dev/null"
1853
+ '; PYTHONPATH="/Users/dev/proj/worktrees/os-update-system" '
1854
+ 'C:/Python313/python.exe -m pytest "tests/" -p no:cacheprovider -q 2>&1 | tail -15'
1855
+ )
1856
+
1857
+
1858
+ def test_rm_rf_allowed_when_cd_ephemeral_and_sibling_mkdir_has_dash_p_flag() -> None:
1859
+ _assert_hook_allows('cd "/tmp/scratch" && rm -rf build && mkdir -p out')
1860
+
1861
+
1862
+ def test_rm_rf_allowed_when_cd_ephemeral_and_rm_target_uses_temp_env_var() -> None:
1863
+ _assert_hook_allows('cd "/tmp/scratch" && rm -rf "$TEMP/build"')
1864
+
1865
+
1866
+ def test_rm_rf_asks_when_cd_ephemeral_but_bash_dash_c_executes_rm_on_non_ephemeral() -> None:
1867
+ _assert_hook_asks("cd \"/tmp/scratch\" && rm -rf build && bash -c 'rm -rf /etc'")
1868
+
1869
+
1870
+ def test_rm_rf_asks_when_cd_ephemeral_but_rm_target_uses_non_temp_env_var() -> None:
1871
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf "$HOME/important"')
1872
+
1873
+
1874
+ def test_rm_rf_asks_when_cd_ephemeral_and_second_rm_segment_targets_non_ephemeral() -> None:
1875
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf build && rm -rf /etc/passwd')
1876
+
1877
+
1878
+ def test_rm_rf_asks_when_cd_ephemeral_but_bin_rm_targets_non_ephemeral() -> None:
1879
+ _assert_hook_asks('cd "/tmp/scratch" && /bin/rm -rf /etc')
1880
+
1881
+
1882
+ def test_rm_rf_asks_when_cd_ephemeral_but_target_is_command_substitution() -> None:
1883
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf $(somecmd)')
1884
+
1885
+
1886
+ def test_rm_rf_asks_when_cd_ephemeral_but_target_is_brace_expansion_escaping_namespace() -> None:
1887
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf {build,/etc}')
1888
+
1889
+
1890
+ def test_rm_rf_asks_when_cd_ephemeral_but_temp_var_splices_after_absolute_literal_prefix() -> None:
1891
+ _assert_hook_asks('cd "/tmp/scratch" && rm -rf /data$TMP/x')
1892
+
1893
+
1894
+ def test_rm_rf_asks_when_cd_ephemeral_but_find_exec_rm_search_root_escapes_namespace() -> None:
1895
+ _assert_hook_asks('cd "/tmp/scratch" && find /etc -name x -exec rm -rf {} +')
1896
+
1897
+
1898
+ def test_rm_rf_asks_when_cd_ephemeral_but_subshell_find_exec_rm_search_root_escapes() -> None:
1899
+ _assert_hook_asks('cd "/tmp/scratch" && (find /etc -exec rm -rf {} +)')
1900
+
1901
+
1902
+ def test_rm_rf_asks_when_find_exec_rm_safe_but_sibling_standalone_rm_targets_non_ephemeral() -> None:
1903
+ _assert_hook_asks(
1904
+ 'cd "/tmp/scratch" && find . -name x -exec rm -rf {} + ; rm -rf /etc/passwd'
1905
+ )
1906
+
1907
+
1908
+ def test_rm_rf_asks_when_cd_ephemeral_but_find_exec_rm_redirects_to_non_ephemeral_file() -> None:
1909
+ _assert_hook_asks('cd "/tmp/scratch" && find /tmp/scratch -exec rm -rf {} + >/etc/passwd')
1910
+
1911
+
1912
+ def test_rm_rf_allowed_when_cd_ephemeral_and_relative_build_target() -> None:
1913
+ _assert_hook_allows('cd "/tmp/scratch" && rm -rf build')
1914
+
1915
+
1916
+ def test_rm_rf_allowed_when_cd_ephemeral_and_find_exec_rm_search_root_is_dot() -> None:
1917
+ _assert_hook_allows('cd "/tmp/scratch" && find . -name x -exec rm -rf {} +')
1918
+
1919
+
1920
+ def test_rm_rf_asks_when_cd_ephemeral_but_find_exec_bash_dash_c_deletes_non_ephemeral() -> None:
1921
+ _assert_hook_asks("cd \"/tmp/scratch\" && find . -exec bash -c 'rm -rf /etc' \\;")
1922
+
1923
+
1924
+ def test_rm_rf_asks_when_cd_ephemeral_but_find_exec_sh_dash_c_deletes_non_ephemeral() -> None:
1925
+ _assert_hook_asks("cd \"/tmp/scratch\" && find . -exec sh -c 'rm -rf /etc' \\;")
1926
+
1927
+
1928
+ def test_rm_rf_asks_when_cd_ephemeral_but_find_execdir_bash_dash_c_deletes_non_ephemeral() -> None:
1929
+ _assert_hook_asks("cd \"/tmp/scratch\" && find . -execdir bash -c 'rm -rf /etc' \\;")
1930
+
1931
+
1932
+ def test_rm_rf_asks_when_cd_ephemeral_but_find_exec_python_dash_c_deletes_non_ephemeral() -> None:
1933
+ _assert_hook_asks(
1934
+ "cd \"/tmp/scratch\" && find . -exec python -c 'import os; os.system(\"rm -rf /etc\")' \\;"
1935
+ )
1936
+
1937
+
1938
+ # H1: find global option before the search root must not defeat the escape check
1939
+
1940
+
1941
+ def test_rm_rf_asks_when_find_dash_l_global_option_precedes_non_ephemeral_search_root() -> None:
1942
+ _assert_hook_asks('cd "/tmp/scratch" && find -L /etc -name x -exec rm -rf {} +')
1943
+
1944
+
1945
+ def test_rm_rf_asks_when_find_dash_p_global_option_precedes_non_ephemeral_execdir_root() -> None:
1946
+ _assert_hook_asks('cd "/tmp/scratch" && find -P /etc -execdir rm -rf {} +')
1947
+
1948
+
1949
+ def test_rm_rf_asks_when_find_optimization_level_option_precedes_non_ephemeral_search_root() -> None:
1950
+ _assert_hook_asks('cd "/tmp/scratch" && find -O3 /etc -exec rm -rf {} +')
1951
+
1952
+
1953
+ def test_rm_rf_asks_when_standalone_find_optimization_option_precedes_non_ephemeral_search_root() -> None:
1954
+ _assert_hook_asks('cd "/tmp/scratch" && find -O /etc -exec rm -rf {} +')
1955
+
1956
+
1957
+ def test_rm_rf_asks_when_find_debug_option_value_precedes_non_ephemeral_search_root() -> None:
1958
+ _assert_hook_asks('cd "/tmp/scratch" && find -D tree /etc -exec rm -rf {} +')
1959
+
1960
+
1961
+ def test_rm_rf_allowed_when_find_global_option_precedes_ephemeral_dot_search_root() -> None:
1962
+ _assert_hook_allows('cd "/tmp/scratch" && find -L . -name x -exec rm -rf {} +')
1963
+
1964
+
1965
+ # H2: multi -exec with a \\; terminator must not sever the destructive action from detection
1966
+
1967
+
1968
+ def test_rm_rf_asks_when_multi_exec_second_action_runs_bash_dash_c_deleting_non_ephemeral() -> None:
1969
+ _assert_hook_asks(
1970
+ "cd \"/tmp/scratch\" && find . -exec touch {} \\; -exec bash -c 'rm -rf /etc' \\;"
1971
+ )
1972
+
1973
+
1974
+ def test_rm_rf_asks_when_multi_exec_second_action_runs_sh_dash_c_deleting_non_ephemeral() -> None:
1975
+ _assert_hook_asks(
1976
+ "cd \"/tmp/scratch\" && find . -exec echo {} \\; -exec sh -c 'rm -rf /etc' \\;"
1977
+ )
1978
+
1979
+
1980
+ def test_rm_rf_allowed_when_multi_exec_both_actions_target_only_ephemeral_paths() -> None:
1981
+ _assert_hook_allows("cd \"/tmp/scratch\" && find . -exec echo {} \\; -exec rm -rf {} \\;")
1982
+
1983
+
1984
+ # H3: parallel forwarding an interpreter that deletes a non-ephemeral path must ask
1985
+
1986
+
1987
+ def test_rm_rf_asks_when_parallel_forwards_bash_dash_c_deleting_non_ephemeral() -> None:
1988
+ _assert_hook_asks("cd \"/tmp/scratch\" && parallel bash -c 'rm -rf /etc' ::: x")