claude-dev-env 1.41.0 → 1.43.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.
- package/CLAUDE.md +8 -0
- package/_shared/pr-loop/scripts/_claude_permissions_common.py +232 -8
- package/_shared/pr-loop/scripts/code_rules_gate.py +293 -8
- package/_shared/pr-loop/scripts/fix_hookspath.py +96 -5
- package/_shared/pr-loop/scripts/grant_project_claude_permissions.py +124 -20
- package/_shared/pr-loop/scripts/post_audit_thread.py +4 -4
- package/_shared/pr-loop/scripts/pr_loop_shared_constants/claude_permissions_constants.py +90 -0
- package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/claude_settings_keys_constants.py +2 -0
- package/_shared/pr-loop/scripts/preflight.py +13 -31
- package/_shared/pr-loop/scripts/reviews_disabled.py +2 -16
- package/_shared/pr-loop/scripts/revoke_project_claude_permissions.py +76 -33
- package/_shared/pr-loop/scripts/tests/conftest.py +1 -51
- package/_shared/pr-loop/scripts/tests/test_agent_config_carveout.py +385 -0
- package/_shared/pr-loop/scripts/tests/test_claude_permissions_common.py +4 -2
- package/_shared/pr-loop/scripts/tests/test_claude_permissions_constants.py +37 -2
- package/_shared/pr-loop/scripts/tests/test_claude_settings_keys_constants.py +4 -2
- package/_shared/pr-loop/scripts/tests/test_code_rules_gate_constants.py +4 -2
- package/_shared/pr-loop/scripts/tests/test_fix_hookspath_constants.py +6 -2
- package/_shared/pr-loop/scripts/tests/test_grant_project_claude_permissions.py +2 -2
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread.py +1 -2
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread_constants.py +4 -2
- package/_shared/pr-loop/scripts/tests/test_preflight.py +17 -52
- package/_shared/pr-loop/scripts/tests/test_preflight_constants.py +6 -2
- package/_shared/pr-loop/scripts/tests/test_revoke_project_claude_permissions.py +5 -3
- package/agents/pr-description-writer.md +50 -140
- package/docs/PR_DESCRIPTION_GUIDE.md +101 -102
- package/hooks/_gh_pr_author_swap_utils.py +1 -1
- package/hooks/blocking/bot_mention_comment_blocker.py +4 -10
- package/hooks/blocking/code_rules_enforcer.py +217 -99
- package/hooks/blocking/code_rules_path_utils.py +8 -1
- package/hooks/blocking/destructive_command_blocker.py +1 -1
- package/hooks/blocking/es_exe_path_rewriter.py +7 -13
- package/hooks/blocking/gh_body_arg_blocker.py +6 -1
- package/hooks/blocking/gh_pr_author_enforcer.py +5 -5
- package/hooks/blocking/gh_pr_author_restore.py +5 -5
- package/hooks/blocking/hedging_language_blocker.py +4 -10
- package/hooks/blocking/md_path_exemptions.py +205 -0
- package/hooks/blocking/md_to_html_blocker.py +48 -20
- package/hooks/blocking/pr_converge_bugteam_enforcer.py +5 -11
- package/hooks/blocking/pr_description_enforcer.py +626 -41
- package/hooks/blocking/question_to_user_enforcer.py +4 -10
- package/hooks/blocking/state_description_blocker.py +6 -12
- package/hooks/blocking/tdd_enforcer.py +1 -1
- package/hooks/blocking/test_bot_mention_comment_blocker.py +1 -1
- package/hooks/blocking/test_code_rules_enforcer.py +3 -3
- package/hooks/blocking/test_code_rules_enforcer_any_exempt_files.py +1 -1
- package/hooks/blocking/test_code_rules_enforcer_cap_meta.py +0 -2
- package/hooks/blocking/test_code_rules_enforcer_comment_string_awareness.py +184 -0
- package/hooks/blocking/test_code_rules_enforcer_type_checking_scope.py +82 -0
- package/hooks/blocking/test_code_rules_enforcer_unused_imports.py +29 -29
- package/hooks/blocking/test_gh_body_arg_blocker.py +7 -8
- package/hooks/blocking/test_gh_pr_author_enforcer.py +1 -1
- package/hooks/blocking/test_gh_pr_author_restore.py +1 -1
- package/hooks/blocking/test_hedging_language_blocker.py +2 -2
- package/hooks/blocking/test_md_to_html_blocker.py +463 -8
- package/hooks/blocking/test_pr_converge_bugteam_enforcer.py +1 -1
- package/hooks/blocking/test_pr_description_enforcer.py +1210 -13
- package/hooks/blocking/test_question_to_user_enforcer.py +1 -1
- package/hooks/blocking/windows_rmtree_blocker.py +5 -11
- package/hooks/diagnostic/hook_log_extractor.py +1 -1
- package/hooks/diagnostic/hook_log_init.py +1 -1
- package/hooks/diagnostic/hook_log_stop_wrapper.py +1 -1
- package/hooks/diagnostic/test_hook_log_extractor.py +1 -1
- package/hooks/diagnostic/test_hook_log_init.py +2 -2
- package/hooks/diagnostic/test_hook_log_stop_wrapper.py +1 -1
- package/hooks/git-hooks/gate_utils.py +1 -1
- package/hooks/git-hooks/pre_commit.py +1 -1
- package/hooks/git-hooks/pre_push.py +1 -1
- package/hooks/git-hooks/test_config.py +5 -5
- package/hooks/git-hooks/test_pre_push.py +6 -6
- package/hooks/{config → hooks_constants}/code_rules_enforcer_constants.py +37 -0
- package/hooks/hooks_constants/code_rules_path_utils_constants.py +28 -0
- package/hooks/hooks_constants/md_to_html_blocker_constants.py +82 -0
- package/hooks/{config → hooks_constants}/pr_converge_bugteam_enforcer_state.py +1 -1
- package/hooks/hooks_constants/pr_description_enforcer_constants.py +154 -0
- package/hooks/{config → hooks_constants}/pre_tool_use_stdin.py +1 -1
- package/hooks/{config → hooks_constants}/project_paths_reader.py +2 -2
- package/hooks/{config → hooks_constants}/test_banned_identifiers_constants.py +1 -1
- package/hooks/{config → hooks_constants}/test_dynamic_stderr_handler.py +1 -1
- package/hooks/{config → hooks_constants}/test_hardcoded_user_path_constants.py +1 -1
- package/hooks/{config → hooks_constants}/test_hook_log_extractor_constants.py +2 -2
- package/hooks/hooks_constants/test_md_to_html_blocker_constants.py +110 -0
- package/hooks/{config → hooks_constants}/test_messages.py +2 -6
- package/hooks/{config → hooks_constants}/test_path_rewriter_constants.py +1 -1
- package/hooks/hooks_constants/test_pr_description_enforcer_constants.py +292 -0
- package/hooks/{config → hooks_constants}/test_pre_tool_use_stdin.py +2 -2
- package/hooks/{config → hooks_constants}/test_project_paths_reader.py +3 -3
- package/hooks/{config → hooks_constants}/test_session_env_cleanup_constants.py +1 -1
- package/hooks/{config → hooks_constants}/test_setup_project_paths_constants.py +2 -2
- package/hooks/{config → hooks_constants}/test_unused_module_import_constants.py +1 -1
- package/hooks/lifecycle/pr_converge_bugteam_skill_tracker.py +5 -11
- package/hooks/lifecycle/test_pr_converge_bugteam_skill_tracker.py +1 -1
- package/hooks/session/gh_pr_author_session_cleanup.py +5 -6
- package/hooks/session/session_env_cleanup.py +4 -10
- package/hooks/session/test_gh_pr_author_session_cleanup.py +1 -1
- package/hooks/session/test_untracked_repo_detector.py +2 -2
- package/hooks/session/untracked_repo_detector.py +6 -12
- package/hooks/test__gh_pr_author_swap_utils.py +1 -1
- package/hooks/validators/run_all_validators.py +16 -5
- package/hooks/validators/test_output_formatter.py +46 -0
- package/hooks/workflow/doc_gist_auto_publish.py +1 -1
- package/hooks/workflow/md_to_html_companion.py +8 -15
- package/hooks/workflow/test_md_to_html_companion.py +184 -23
- package/package.json +1 -1
- package/rules/ask-user-question-required.md +1 -1
- package/rules/vault-context.md +1 -1
- package/scripts/{config → dev_env_scripts_constants}/timing.py +1 -1
- package/scripts/setup_project_paths.py +49 -11
- package/scripts/sweep_empty_dirs.py +10 -1
- package/scripts/test_setup_project_paths.py +2 -2
- package/scripts/test_sweep_empty_dirs.py +2 -6
- package/skills/_shared/pr-loop/scripts/_path_resolver.py +1 -1
- package/skills/_shared/pr-loop/scripts/build_audit_prompt.py +1 -1
- package/skills/_shared/pr-loop/scripts/build_fix_prompt.py +1 -1
- package/skills/_shared/pr-loop/scripts/init_loop_state.py +1 -1
- package/skills/_shared/pr-loop/scripts/teardown_worktrees.py +1 -1
- package/skills/_shared/pr-loop/scripts/write_audit_outcomes.py +2 -2
- package/skills/_shared/pr-loop/scripts/write_fix_outcomes.py +2 -2
- package/skills/bugteam/PROMPTS.md +1 -1
- package/skills/bugteam/SKILL.md +1 -1
- package/skills/bugteam/reference/github-pr-reviews.md +1 -1
- package/skills/bugteam/scripts/{_claude_permissions_common.py → _bugteam_permissions_common.py} +110 -13
- package/skills/bugteam/scripts/bugteam_code_rules_gate.py +1 -13
- package/skills/bugteam/scripts/bugteam_fix_hookspath.py +1 -16
- package/skills/bugteam/scripts/bugteam_preflight.py +1 -13
- package/skills/bugteam/scripts/bugteam_scripts_constants/claude_permissions_common_constants.py +69 -0
- package/skills/bugteam/scripts/grant_project_claude_permissions.py +117 -12
- package/skills/bugteam/scripts/probe_code_rules_enforcer_check.py +1 -1
- package/skills/bugteam/scripts/reflow_skill_md.py +1 -1
- package/skills/bugteam/scripts/revoke_project_claude_permissions.py +71 -25
- package/skills/bugteam/scripts/{test__claude_permissions_common.py → test__bugteam_permissions_common.py} +4 -4
- package/skills/bugteam/scripts/test_agent_config_carveout.py +356 -0
- package/skills/bugteam/scripts/test_bugteam_fix_hookspath.py +0 -26
- package/skills/bugteam/scripts/{test_claude_permissions_common.py → test_bugteam_permissions_common.py} +3 -66
- package/skills/bugteam/scripts/test_bugteam_preflight.py +2 -27
- package/skills/bugteam/scripts/windows_safe_rmtree.py +1 -1
- package/skills/doc-gist/SKILL.md +1 -1
- package/skills/doc-gist/scripts/gist_upload.py +1 -1
- package/skills/implement/SKILL.md +66 -0
- package/skills/implement/scripts/append_note.py +133 -0
- package/skills/implement/scripts/implement_scripts_constants/__init__.py +0 -0
- package/skills/implement/scripts/implement_scripts_constants/notes_constants.py +12 -0
- package/skills/implement/scripts/test_append_note.py +191 -0
- package/skills/pr-converge/pr_converge_skill_constants/__init__.py +0 -0
- package/skills/pr-converge/{config → pr_converge_skill_constants}/constants.py +6 -1
- package/skills/pr-converge/scripts/check_bugbot_ci.py +2 -2
- package/skills/pr-converge/scripts/check_convergence.py +175 -29
- package/skills/pr-converge/scripts/check_pending_reviews.py +2 -2
- package/skills/pr-converge/scripts/fetch_copilot_reviews.py +2 -2
- package/skills/pr-converge/scripts/post_fix_reply.py +2 -2
- package/skills/pr-converge/scripts/pr_converge_scripts_constants/__init__.py +0 -0
- package/skills/pr-converge/scripts/{config → pr_converge_scripts_constants}/pr_converge_constants.py +1 -1
- package/skills/pr-converge/scripts/reflow_skill_md.py +90 -16
- package/skills/pr-converge/scripts/test_check_bugbot_ci.py +1 -1
- package/skills/pr-converge/scripts/test_check_convergence.py +324 -0
- package/skills/pr-converge/scripts/test_reflow_skill_md.py +0 -31
- package/skills/refine/SKILL.md +257 -0
- package/skills/refine/templates/implementation-notes-template.html +56 -0
- package/skills/refine/templates/plan-template.md +60 -0
- package/skills/session-log/SKILL.md +98 -233
- package/_shared/pr-loop/scripts/config/claude_permissions_constants.py +0 -36
- package/hooks/config/pr_description_enforcer_constants.py +0 -19
- package/hooks/config/test_pr_description_enforcer_constants.py +0 -82
- package/skills/bugteam/scripts/config/claude_permissions_common_constants.py +0 -20
- package/skills/bugteam/scripts/test_grant_project_claude_permissions.py +0 -55
- package/skills/bugteam/scripts/test_revoke_project_claude_permissions.py +0 -55
- package/skills/pr-converge/scripts/evict_cached_config_modules.py +0 -20
- package/skills/pr-converge/scripts/test_evict_cached_config_modules.py +0 -22
- /package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/__init__.py +0 -0
- /package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/code_rules_gate_constants.py +0 -0
- /package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/fix_hookspath_constants.py +0 -0
- /package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/post_audit_thread_constants.py +0 -0
- /package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/preflight_constants.py +0 -0
- /package/_shared/pr-loop/scripts/{config → pr_loop_shared_constants}/reviews_disabled_constants.py +0 -0
- /package/hooks/git-hooks/{config.py → git_hooks_constants/__init__.py} +0 -0
- /package/hooks/{config → hooks_constants}/__init__.py +0 -0
- /package/hooks/{config → hooks_constants}/any_type_config.py +0 -0
- /package/hooks/{config → hooks_constants}/banned_identifiers_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/blocking_check_limits.py +0 -0
- /package/hooks/{config → hooks_constants}/bot_mention_comment_blocker_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/convergence_branch_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/doc_gist_auto_publish_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/dynamic_stderr_handler.py +0 -0
- /package/hooks/{config → hooks_constants}/gh_pr_author_swap_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/hardcoded_user_path_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/hook_log_extractor_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/html_companion_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/inline_tuple_string_magic_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/messages.py +0 -0
- /package/hooks/{config → hooks_constants}/path_rewriter_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/pr_converge_bugteam_enforcer_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/session_env_cleanup_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/setup_project_paths_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/state_description_blocker_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/stuttering_check_config.py +0 -0
- /package/hooks/{config → hooks_constants}/stuttering_import_binding_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/sys_path_insert_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/unused_module_import_constants.py +0 -0
- /package/hooks/{config → hooks_constants}/windows_rmtree_blocker_constants.py +0 -0
- /package/{skills/_shared/pr-loop/scripts/config → hooks/lifecycle}/__init__.py +0 -0
- /package/{skills/bugteam/scripts/config → hooks/session}/__init__.py +0 -0
- /package/scripts/{config → dev_env_scripts_constants}/__init__.py +0 -0
- /package/skills/{doc-gist/scripts/config → _shared/pr-loop/scripts/skills_pr_loop_constants}/__init__.py +0 -0
- /package/skills/_shared/pr-loop/scripts/{config → skills_pr_loop_constants}/path_resolver_constants.py +0 -0
- /package/skills/{pr-converge/config → bugteam/scripts/bugteam_scripts_constants}/__init__.py +0 -0
- /package/skills/bugteam/scripts/{config → bugteam_scripts_constants}/bugteam_code_rules_gate_constants.py +0 -0
- /package/skills/bugteam/scripts/{config → bugteam_scripts_constants}/bugteam_fix_hookspath_constants.py +0 -0
- /package/skills/bugteam/scripts/{config → bugteam_scripts_constants}/bugteam_preflight_constants.py +0 -0
- /package/skills/bugteam/scripts/{config → bugteam_scripts_constants}/probe_code_rules_enforcer_check_constants.py +0 -0
- /package/skills/bugteam/scripts/{config → bugteam_scripts_constants}/reflow_skill_md_constants.py +0 -0
- /package/skills/bugteam/scripts/{config → bugteam_scripts_constants}/windows_safe_rmtree_constants.py +0 -0
- /package/skills/{pr-converge/scripts/config → doc-gist/scripts/doc_gist_scripts_constants}/__init__.py +0 -0
- /package/skills/doc-gist/scripts/{config → doc_gist_scripts_constants}/gist_upload_constants.py +0 -0
- /package/skills/pr-converge/scripts/{config → pr_converge_scripts_constants}/reflow_skill_md_constants.py +0 -0
|
@@ -29,7 +29,7 @@ hook_module_spec.loader.exec_module(hook_module)
|
|
|
29
29
|
|
|
30
30
|
import _gh_pr_author_swap_utils as swap_utils_module # noqa: E402
|
|
31
31
|
|
|
32
|
-
from
|
|
32
|
+
from hooks_constants.gh_pr_author_swap_constants import STATE_FILE_PERMISSION_MODE # noqa: E402
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
def _make_stdin_payload(command: str, session_id: str = "test-session-001") -> str:
|
|
@@ -14,7 +14,7 @@ from unittest import mock
|
|
|
14
14
|
|
|
15
15
|
import pytest
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from hooks_constants.gh_pr_author_swap_constants import STATE_FILE_PERMISSION_MODE
|
|
18
18
|
|
|
19
19
|
_HOOK_DIR = pathlib.Path(__file__).parent
|
|
20
20
|
if str(_HOOK_DIR) not in sys.path:
|
|
@@ -10,13 +10,13 @@ import tempfile
|
|
|
10
10
|
HOOK_SCRIPT_PATH = os.path.join(os.path.dirname(__file__), "hedging_language_blocker.py")
|
|
11
11
|
_HOOKS_DIR = os.path.dirname(HOOK_SCRIPT_PATH)
|
|
12
12
|
_HOOKS_ROOT = os.path.join(_HOOKS_DIR, "..")
|
|
13
|
-
_HOOK_CONFIG_DIR = os.path.join(_HOOKS_ROOT, "
|
|
13
|
+
_HOOK_CONFIG_DIR = os.path.join(_HOOKS_ROOT, "hooks_constants")
|
|
14
14
|
if _HOOKS_DIR not in sys.path:
|
|
15
15
|
sys.path.insert(0, _HOOKS_DIR)
|
|
16
16
|
if _HOOKS_ROOT not in sys.path:
|
|
17
17
|
sys.path.insert(0, _HOOKS_ROOT)
|
|
18
18
|
import hedging_language_blocker
|
|
19
|
-
from
|
|
19
|
+
from hooks_constants.messages import USER_FACING_NOTICE
|
|
20
20
|
|
|
21
21
|
RESEARCH_MODE_SKILL_BODY_MARKER = "Three anti-hallucination constraints are ALWAYS active."
|
|
22
22
|
HEDGING_MESSAGE = "This is likely correct."
|
|
@@ -1,15 +1,67 @@
|
|
|
1
|
-
"""Tests for md_to_html_blocker hook.
|
|
2
|
-
|
|
1
|
+
"""Tests for md_to_html_blocker hook.
|
|
2
|
+
|
|
3
|
+
Subprocess CWD is rooted in a per-session sandbox created lazily by a
|
|
4
|
+
session-scoped fixture so that relative-path test cases canonicalize outside
|
|
5
|
+
any `.claude-plugin/` ancestor, outside the OS temp directory, and outside the
|
|
6
|
+
exempt home-relative subdirectories. The sandbox is a real repo root (it
|
|
7
|
+
carries a `.git` marker) so relative `README.md` / `CHANGELOG.md` writes
|
|
8
|
+
exercise the repo-root exemption path. This keeps tests independent of where
|
|
9
|
+
pytest itself is run.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import functools
|
|
3
13
|
import importlib
|
|
4
14
|
import json
|
|
5
15
|
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import stat
|
|
6
18
|
import subprocess
|
|
7
19
|
import sys
|
|
20
|
+
import tempfile
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
import pytest
|
|
8
24
|
|
|
9
25
|
|
|
10
26
|
HOOK_SCRIPT_PATH = os.path.join(os.path.dirname(__file__), "md_to_html_blocker.py")
|
|
11
27
|
|
|
12
28
|
|
|
29
|
+
def _strip_read_only_and_retry(removal_function, target_path, *_exc_info):
|
|
30
|
+
try:
|
|
31
|
+
os.chmod(target_path, stat.S_IWRITE)
|
|
32
|
+
removal_function(target_path)
|
|
33
|
+
except OSError:
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _force_rmtree(target_path: str) -> None:
|
|
38
|
+
handler_kw = (
|
|
39
|
+
{"onexc": _strip_read_only_and_retry}
|
|
40
|
+
if sys.version_info >= (3, 12)
|
|
41
|
+
else {"onerror": _strip_read_only_and_retry}
|
|
42
|
+
)
|
|
43
|
+
try:
|
|
44
|
+
shutil.rmtree(target_path, **handler_kw)
|
|
45
|
+
except OSError:
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@functools.lru_cache(maxsize=1)
|
|
50
|
+
def _get_sandbox_parent_directory() -> str:
|
|
51
|
+
sandbox_parent = tempfile.mkdtemp(prefix="pytest_md_blocker_", dir=str(Path.home()))
|
|
52
|
+
git_marker_path = os.path.join(sandbox_parent, ".git")
|
|
53
|
+
Path(git_marker_path).touch()
|
|
54
|
+
return sandbox_parent
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.fixture(scope="session", autouse=True)
|
|
58
|
+
def _cleanup_sandbox_parent_directory():
|
|
59
|
+
yield
|
|
60
|
+
if _get_sandbox_parent_directory.cache_info().currsize:
|
|
61
|
+
_force_rmtree(_get_sandbox_parent_directory())
|
|
62
|
+
_get_sandbox_parent_directory.cache_clear()
|
|
63
|
+
|
|
64
|
+
|
|
13
65
|
class _RunHook:
|
|
14
66
|
def __call__(self, tool_name: str, tool_input: dict) -> subprocess.CompletedProcess:
|
|
15
67
|
payload = json.dumps({"tool_name": tool_name, "tool_input": tool_input})
|
|
@@ -19,24 +71,32 @@ class _RunHook:
|
|
|
19
71
|
capture_output=True,
|
|
20
72
|
text=True,
|
|
21
73
|
check=False,
|
|
74
|
+
cwd=_get_sandbox_parent_directory(),
|
|
22
75
|
)
|
|
23
76
|
|
|
24
77
|
|
|
25
78
|
_run_hook = _RunHook()
|
|
26
79
|
|
|
27
80
|
|
|
28
|
-
def
|
|
29
|
-
"""
|
|
81
|
+
def test_block_messages_mention_claude_dev_env_source_exemptions():
|
|
82
|
+
"""Block messages must surface the `packages/claude-dev-env/<dir>/` anchored
|
|
83
|
+
exemption so contributors aren't misled when a `.md` write is denied
|
|
84
|
+
elsewhere. Ensures docs/, rules/, and system-prompts/ source files
|
|
85
|
+
render as writable in the user-facing message."""
|
|
30
86
|
hook_dir = os.path.dirname(HOOK_SCRIPT_PATH)
|
|
31
87
|
if hook_dir not in sys.path:
|
|
32
88
|
sys.path.insert(0, hook_dir)
|
|
33
|
-
|
|
34
89
|
blocker_module = importlib.import_module("md_to_html_blocker")
|
|
35
90
|
importlib.reload(blocker_module)
|
|
36
91
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
92
|
+
context_message = blocker_module._block_context()
|
|
93
|
+
system_message = blocker_module._block_system_message()
|
|
94
|
+
combined_messages = context_message + " " + system_message
|
|
95
|
+
assert "claude-dev-env" in combined_messages, (
|
|
96
|
+
"Block messages must mention claude-dev-env source-directory exemption; "
|
|
97
|
+
f"got context={context_message!r} system={system_message!r}"
|
|
98
|
+
)
|
|
99
|
+
|
|
40
100
|
|
|
41
101
|
|
|
42
102
|
def test_blocks_write_md_file():
|
|
@@ -69,6 +129,55 @@ def test_blocks_uppercase_md_extension():
|
|
|
69
129
|
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
70
130
|
|
|
71
131
|
|
|
132
|
+
def test_module_imports_path_segments_from_hooks_constants():
|
|
133
|
+
"""The blocker pulls the two leading path segments (`packages` and
|
|
134
|
+
`claude-dev-env`) through the centralised hooks_constants module rather
|
|
135
|
+
than inlining them as raw string literals."""
|
|
136
|
+
hook_dir = os.path.dirname(HOOK_SCRIPT_PATH)
|
|
137
|
+
if hook_dir not in sys.path:
|
|
138
|
+
sys.path.insert(0, hook_dir)
|
|
139
|
+
blocker_module = importlib.import_module("md_to_html_blocker")
|
|
140
|
+
importlib.reload(blocker_module)
|
|
141
|
+
assert blocker_module.PACKAGES_TOP_LEVEL_SEGMENT == "packages"
|
|
142
|
+
assert blocker_module.CLAUDE_DEV_ENV_REPO_NAME_SEGMENT == "claude-dev-env"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_module_imports_top_directories_from_hooks_constants():
|
|
146
|
+
"""The exempt-top-directories set must live in `hooks_constants/` rather
|
|
147
|
+
than as a file-global single-use constant in the blocker module. The
|
|
148
|
+
blocker imports the centralized constant; a regression that reintroduces
|
|
149
|
+
a local module-scope copy would fail this assertion."""
|
|
150
|
+
hook_dir = os.path.dirname(HOOK_SCRIPT_PATH)
|
|
151
|
+
if hook_dir not in sys.path:
|
|
152
|
+
sys.path.insert(0, hook_dir)
|
|
153
|
+
blocker_module = importlib.import_module("md_to_html_blocker")
|
|
154
|
+
importlib.reload(blocker_module)
|
|
155
|
+
assert hasattr(blocker_module, "ALL_CLAUDE_CODE_SOURCE_TOP_DIRECTORIES"), (
|
|
156
|
+
"Blocker module must import ALL_CLAUDE_CODE_SOURCE_TOP_DIRECTORIES from "
|
|
157
|
+
"hooks_constants/ (file-global single-use rule)."
|
|
158
|
+
)
|
|
159
|
+
assert not hasattr(blocker_module, "_claude_code_source_top_directories"), (
|
|
160
|
+
"Local _claude_code_source_top_directories must not be re-introduced; "
|
|
161
|
+
"use the imported constant from hooks_constants/ instead."
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_blocks_nested_packages_claude_dev_env_path():
|
|
166
|
+
"""`packages/claude-dev-env/` exemption is anchored to top-level use only;
|
|
167
|
+
a nested directory like `notes/packages/claude-dev-env/docs/...` is NOT a
|
|
168
|
+
Claude Code source path and must still be blocked. Substring matching let
|
|
169
|
+
this bypass through; segment-anchored matching prevents it."""
|
|
170
|
+
result = _run_hook(
|
|
171
|
+
"Write",
|
|
172
|
+
{"file_path": "notes/packages/claude-dev-env/docs/guide.md", "content": "# Hello"},
|
|
173
|
+
)
|
|
174
|
+
assert result.returncode == 0
|
|
175
|
+
output = json.loads(result.stdout)
|
|
176
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny", (
|
|
177
|
+
f"Nested fake claude-dev-env path must still be blocked; got {output!r}"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
72
181
|
def test_passes_html_file():
|
|
73
182
|
result = _run_hook(
|
|
74
183
|
"Write",
|
|
@@ -143,6 +252,29 @@ def test_blocks_changelog_not_at_root():
|
|
|
143
252
|
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
144
253
|
|
|
145
254
|
|
|
255
|
+
def test_blocks_relative_readme_when_cwd_is_not_repo_root():
|
|
256
|
+
sandbox_parent = _get_sandbox_parent_directory()
|
|
257
|
+
non_repo_cwd = os.path.join(sandbox_parent, "not-a-repo")
|
|
258
|
+
os.makedirs(non_repo_cwd, exist_ok=True)
|
|
259
|
+
payload = json.dumps(
|
|
260
|
+
{
|
|
261
|
+
"tool_name": "Write",
|
|
262
|
+
"tool_input": {"file_path": "README.md", "content": "# README"},
|
|
263
|
+
}
|
|
264
|
+
)
|
|
265
|
+
result = subprocess.run(
|
|
266
|
+
[sys.executable, HOOK_SCRIPT_PATH],
|
|
267
|
+
input=payload,
|
|
268
|
+
capture_output=True,
|
|
269
|
+
text=True,
|
|
270
|
+
check=False,
|
|
271
|
+
cwd=non_repo_cwd,
|
|
272
|
+
)
|
|
273
|
+
assert result.returncode == 0
|
|
274
|
+
output = json.loads(result.stdout)
|
|
275
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
276
|
+
|
|
277
|
+
|
|
146
278
|
def test_unknown_tool_passes():
|
|
147
279
|
result = _run_hook(
|
|
148
280
|
"Grep",
|
|
@@ -315,3 +447,326 @@ def test_blocks_md_with_curly_braces_in_path():
|
|
|
315
447
|
assert result.returncode == 0
|
|
316
448
|
output = json.loads(result.stdout)
|
|
317
449
|
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def test_passes_home_session_log_directory():
|
|
453
|
+
home_directory = os.path.expanduser("~")
|
|
454
|
+
session_log_path = os.path.join(home_directory, "SessionLog", "decisions", "note.md")
|
|
455
|
+
result = _run_hook(
|
|
456
|
+
"Write",
|
|
457
|
+
{"file_path": session_log_path, "content": "# Note"},
|
|
458
|
+
)
|
|
459
|
+
assert result.returncode == 0
|
|
460
|
+
assert result.stdout == ""
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def test_passes_home_claude_plans_directory():
|
|
464
|
+
home_directory = os.path.expanduser("~")
|
|
465
|
+
plans_path = os.path.join(home_directory, ".claude", "plans", "plan.md")
|
|
466
|
+
result = _run_hook(
|
|
467
|
+
"Write",
|
|
468
|
+
{"file_path": plans_path, "content": "# Plan"},
|
|
469
|
+
)
|
|
470
|
+
assert result.returncode == 0
|
|
471
|
+
assert result.stdout == ""
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def test_blocks_home_directory_other_md_file():
|
|
475
|
+
home_directory = os.path.expanduser("~")
|
|
476
|
+
other_path = os.path.join(home_directory, "docs", "guide.md")
|
|
477
|
+
result = _run_hook(
|
|
478
|
+
"Write",
|
|
479
|
+
{"file_path": other_path, "content": "# Guide"},
|
|
480
|
+
)
|
|
481
|
+
assert result.returncode == 0
|
|
482
|
+
output = json.loads(result.stdout)
|
|
483
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def test_passes_tilde_session_log_path():
|
|
487
|
+
result = _run_hook(
|
|
488
|
+
"Write",
|
|
489
|
+
{"file_path": "~/SessionLog/decisions/note.md", "content": "# Note"},
|
|
490
|
+
)
|
|
491
|
+
assert result.returncode == 0
|
|
492
|
+
assert result.stdout == ""
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def test_passes_tilde_claude_plans_path():
|
|
496
|
+
result = _run_hook(
|
|
497
|
+
"Write",
|
|
498
|
+
{"file_path": "~/.claude/plans/plan.md", "content": "# Plan"},
|
|
499
|
+
)
|
|
500
|
+
assert result.returncode == 0
|
|
501
|
+
assert result.stdout == ""
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def test_blocks_tilde_other_home_md_file():
|
|
505
|
+
result = _run_hook(
|
|
506
|
+
"Write",
|
|
507
|
+
{"file_path": "~/docs/guide.md", "content": "# Guide"},
|
|
508
|
+
)
|
|
509
|
+
assert result.returncode == 0
|
|
510
|
+
output = json.loads(result.stdout)
|
|
511
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def test_passes_system_temp_directory():
|
|
515
|
+
temp_md_path = os.path.join(tempfile.gettempdir(), "bugteam-scratch", "pr-body.md")
|
|
516
|
+
result = _run_hook(
|
|
517
|
+
"Write",
|
|
518
|
+
{"file_path": temp_md_path, "content": "# Scratch"},
|
|
519
|
+
)
|
|
520
|
+
assert result.returncode == 0
|
|
521
|
+
assert result.stdout == ""
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def test_passes_dot_claude_plugin_directory():
|
|
525
|
+
result = _run_hook(
|
|
526
|
+
"Write",
|
|
527
|
+
{"file_path": ".claude-plugin/manifest.md", "content": "# Manifest"},
|
|
528
|
+
)
|
|
529
|
+
assert result.returncode == 0
|
|
530
|
+
assert result.stdout == ""
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
def test_passes_nested_dot_claude_plugin_directory():
|
|
534
|
+
result = _run_hook(
|
|
535
|
+
"Write",
|
|
536
|
+
{
|
|
537
|
+
"file_path": "Y:/repo/.claude-plugin/skills/foo/SKILL.md",
|
|
538
|
+
"content": "# Skill",
|
|
539
|
+
},
|
|
540
|
+
)
|
|
541
|
+
assert result.returncode == 0
|
|
542
|
+
assert result.stdout == ""
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def test_passes_skill_md_at_any_depth():
|
|
546
|
+
result = _run_hook(
|
|
547
|
+
"Write",
|
|
548
|
+
{
|
|
549
|
+
"file_path": "packages/dev-env/skills/pr-converge/SKILL.md",
|
|
550
|
+
"content": "# Skill",
|
|
551
|
+
},
|
|
552
|
+
)
|
|
553
|
+
assert result.returncode == 0
|
|
554
|
+
assert result.stdout == ""
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def test_passes_skill_md_uppercase():
|
|
558
|
+
result = _run_hook(
|
|
559
|
+
"Write",
|
|
560
|
+
{"file_path": "any/path/SKILL.MD", "content": "# Skill"},
|
|
561
|
+
)
|
|
562
|
+
assert result.returncode == 0
|
|
563
|
+
assert result.stdout == ""
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
def test_passes_agents_directory_anywhere():
|
|
567
|
+
result = _run_hook(
|
|
568
|
+
"Write",
|
|
569
|
+
{
|
|
570
|
+
"file_path": "packages/dev-env/agents/pr-description-writer.md",
|
|
571
|
+
"content": "# Agent",
|
|
572
|
+
},
|
|
573
|
+
)
|
|
574
|
+
assert result.returncode == 0
|
|
575
|
+
assert result.stdout == ""
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def test_passes_skills_reference_directory():
|
|
579
|
+
result = _run_hook(
|
|
580
|
+
"Write",
|
|
581
|
+
{
|
|
582
|
+
"file_path": "packages/dev-env/skills/pr-converge/reference/per-tick.md",
|
|
583
|
+
"content": "# Reference",
|
|
584
|
+
},
|
|
585
|
+
)
|
|
586
|
+
assert result.returncode == 0
|
|
587
|
+
assert result.stdout == ""
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def test_passes_commands_directory_anywhere():
|
|
591
|
+
result = _run_hook(
|
|
592
|
+
"Write",
|
|
593
|
+
{"file_path": "commands/pyguide-health.md", "content": "# Command"},
|
|
594
|
+
)
|
|
595
|
+
assert result.returncode == 0
|
|
596
|
+
assert result.stdout == ""
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def test_passes_claude_dev_env_docs_dir():
|
|
600
|
+
"""A .md file under ``packages/claude-dev-env/docs/`` is exempt. The
|
|
601
|
+
segment-anywhere rule does not list ``docs``; this exemption fires only
|
|
602
|
+
via the anchored helper."""
|
|
603
|
+
result = _run_hook(
|
|
604
|
+
"Write",
|
|
605
|
+
{
|
|
606
|
+
"file_path": "packages/claude-dev-env/docs/PR_DESCRIPTION_GUIDE.md",
|
|
607
|
+
"content": "# Guide",
|
|
608
|
+
},
|
|
609
|
+
)
|
|
610
|
+
assert result.returncode == 0
|
|
611
|
+
assert result.stdout == ""
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
def test_passes_claude_dev_env_rules_dir():
|
|
615
|
+
"""A .md file under ``packages/claude-dev-env/rules/`` is exempt. The
|
|
616
|
+
segment-anywhere rule does not list ``rules``; the anchored helper is
|
|
617
|
+
the only path to this exemption."""
|
|
618
|
+
result = _run_hook(
|
|
619
|
+
"Write",
|
|
620
|
+
{
|
|
621
|
+
"file_path": "packages/claude-dev-env/rules/my-rule.md",
|
|
622
|
+
"content": "# Rule",
|
|
623
|
+
},
|
|
624
|
+
)
|
|
625
|
+
assert result.returncode == 0
|
|
626
|
+
assert result.stdout == ""
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
def test_passes_claude_dev_env_system_prompts_dir():
|
|
630
|
+
"""A .md file under ``packages/claude-dev-env/system-prompts/`` is
|
|
631
|
+
exempt via the anchored helper."""
|
|
632
|
+
result = _run_hook(
|
|
633
|
+
"Write",
|
|
634
|
+
{
|
|
635
|
+
"file_path": "packages/claude-dev-env/system-prompts/new-prompt.md",
|
|
636
|
+
"content": "# Prompt",
|
|
637
|
+
},
|
|
638
|
+
)
|
|
639
|
+
assert result.returncode == 0
|
|
640
|
+
assert result.stdout == ""
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def test_passes_claude_dev_env_windows_backslash_path():
|
|
644
|
+
"""A Windows-style backslash relative path under
|
|
645
|
+
``packages\\claude-dev-env\\<dir>\\`` is exempt."""
|
|
646
|
+
result = _run_hook(
|
|
647
|
+
"Write",
|
|
648
|
+
{
|
|
649
|
+
"file_path": "packages\\claude-dev-env\\docs\\windows-style.md",
|
|
650
|
+
"content": "# Guide",
|
|
651
|
+
},
|
|
652
|
+
)
|
|
653
|
+
assert result.returncode == 0
|
|
654
|
+
assert result.stdout == ""
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
def test_passes_claude_dev_env_absolute_drive_letter_path():
|
|
658
|
+
"""A Windows absolute drive-letter path containing the anchored
|
|
659
|
+
``packages\\claude-dev-env\\<dir>\\`` indicator at any depth is exempt."""
|
|
660
|
+
result = _run_hook(
|
|
661
|
+
"Write",
|
|
662
|
+
{
|
|
663
|
+
"file_path": "Y:\\repo\\packages\\claude-dev-env\\docs\\drive-letter.md",
|
|
664
|
+
"content": "# Guide",
|
|
665
|
+
},
|
|
666
|
+
)
|
|
667
|
+
assert result.returncode == 0
|
|
668
|
+
assert result.stdout == ""
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
def test_blocks_md_under_packages_but_not_in_anchored_source_subdir():
|
|
672
|
+
"""A .md file inside the package but under a non-source subtree (e.g.
|
|
673
|
+
``packages/claude-dev-env/hooks/blocking/``) is blocked. The anchored
|
|
674
|
+
helper accepts only the named source subdirectories (agents, docs,
|
|
675
|
+
skills, rules, system-prompts, commands)."""
|
|
676
|
+
result = _run_hook(
|
|
677
|
+
"Write",
|
|
678
|
+
{
|
|
679
|
+
"file_path": "packages/claude-dev-env/hooks/blocking/notes.md",
|
|
680
|
+
"content": "# Notes",
|
|
681
|
+
},
|
|
682
|
+
)
|
|
683
|
+
assert result.returncode == 0
|
|
684
|
+
output = json.loads(result.stdout)
|
|
685
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def test_blocks_nested_claude_dev_env_substring_does_not_bypass():
|
|
689
|
+
"""A path that contains the anchored prefix as a non-leading substring
|
|
690
|
+
(e.g. ``notes/packages/claude-dev-env/docs/foo.md``) is blocked. The
|
|
691
|
+
anchored helper matches only at the start of the path (relative) or at
|
|
692
|
+
the root of an absolute path."""
|
|
693
|
+
result = _run_hook(
|
|
694
|
+
"Write",
|
|
695
|
+
{
|
|
696
|
+
"file_path": "notes/packages/claude-dev-env/docs/foo.md",
|
|
697
|
+
"content": "# Notes",
|
|
698
|
+
},
|
|
699
|
+
)
|
|
700
|
+
assert result.returncode == 0
|
|
701
|
+
output = json.loads(result.stdout)
|
|
702
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def test_blocks_ordinary_docs_md_file():
|
|
706
|
+
result = _run_hook(
|
|
707
|
+
"Write",
|
|
708
|
+
{"file_path": "docs/intro.md", "content": "# Intro"},
|
|
709
|
+
)
|
|
710
|
+
assert result.returncode == 0
|
|
711
|
+
output = json.loads(result.stdout)
|
|
712
|
+
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
def test_passes_relative_path_from_home_cwd():
|
|
716
|
+
home_directory = os.path.expanduser("~")
|
|
717
|
+
payload = json.dumps(
|
|
718
|
+
{
|
|
719
|
+
"tool_name": "Write",
|
|
720
|
+
"tool_input": {
|
|
721
|
+
"file_path": "SessionLog/decisions/note.md",
|
|
722
|
+
"content": "# Note",
|
|
723
|
+
},
|
|
724
|
+
}
|
|
725
|
+
)
|
|
726
|
+
result = subprocess.run(
|
|
727
|
+
[sys.executable, HOOK_SCRIPT_PATH],
|
|
728
|
+
input=payload,
|
|
729
|
+
capture_output=True,
|
|
730
|
+
text=True,
|
|
731
|
+
check=False,
|
|
732
|
+
cwd=home_directory,
|
|
733
|
+
)
|
|
734
|
+
assert result.returncode == 0
|
|
735
|
+
assert result.stdout == ""
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
def test_passes_canonicalized_home_path():
|
|
739
|
+
canonical_home = os.path.realpath(os.path.expanduser("~"))
|
|
740
|
+
canonical_path = os.path.join(canonical_home, "SessionLog", "canonical-note.md")
|
|
741
|
+
result = _run_hook(
|
|
742
|
+
"Write",
|
|
743
|
+
{"file_path": canonical_path, "content": "# Canonical"},
|
|
744
|
+
)
|
|
745
|
+
assert result.returncode == 0
|
|
746
|
+
assert result.stdout == ""
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
def test_passes_relative_path_under_cwd_plugin_root_marker(tmp_path):
|
|
750
|
+
plugin_root = tmp_path / "plugin-cwd-repo"
|
|
751
|
+
(plugin_root / ".claude-plugin").mkdir(parents=True)
|
|
752
|
+
(plugin_root / "subdir").mkdir(parents=True)
|
|
753
|
+
|
|
754
|
+
payload = json.dumps(
|
|
755
|
+
{
|
|
756
|
+
"tool_name": "Write",
|
|
757
|
+
"tool_input": {
|
|
758
|
+
"file_path": "subdir/design.md",
|
|
759
|
+
"content": "# Design",
|
|
760
|
+
},
|
|
761
|
+
}
|
|
762
|
+
)
|
|
763
|
+
result = subprocess.run(
|
|
764
|
+
[sys.executable, HOOK_SCRIPT_PATH],
|
|
765
|
+
input=payload,
|
|
766
|
+
capture_output=True,
|
|
767
|
+
text=True,
|
|
768
|
+
check=False,
|
|
769
|
+
cwd=str(plugin_root),
|
|
770
|
+
)
|
|
771
|
+
assert result.returncode == 0
|
|
772
|
+
assert result.stdout == ""
|
|
@@ -34,7 +34,7 @@ assert hook_spec.loader is not None
|
|
|
34
34
|
hook_module = importlib.util.module_from_spec(hook_spec)
|
|
35
35
|
hook_spec.loader.exec_module(hook_module)
|
|
36
36
|
|
|
37
|
-
from
|
|
37
|
+
from hooks_constants.pr_converge_bugteam_enforcer_constants import (
|
|
38
38
|
BUGTEAM_PHASE,
|
|
39
39
|
CLAUDE_JOB_DIR_ENV_VAR,
|
|
40
40
|
PR_CONVERGE_STATE_FILENAME,
|