claude-dev-env 7.0.0 → 7.1.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/.agents/skills/pull-request/scripts/pull_request.py +2 -0
- package/.agents/skills/pull-request/scripts/test_pull_request.py +34 -0
- package/.agents/skills/session-continuity/AGENTS.md +1 -0
- package/.agents/skills/session-continuity/CLAUDE.md +1 -0
- package/.agents/skills/session-continuity/README.md +189 -0
- package/.agents/skills/session-continuity/SKILL.md +114 -0
- package/.agents/skills/session-continuity/continuity.mjs +375 -0
- package/.agents/skills/session-continuity/continuity.test.mjs +303 -0
- package/.agents/skills/syncing-submodules/scripts/test_sync_parent_pointer.py +0 -7
- package/.agents/skills/windows-scheduled-task/SKILL.md +153 -0
- package/bin/cde.mjs +36 -8
- package/bin/cde.test.mjs +48 -0
- package/bin/ever-shipped-skills.mjs +2 -20
- package/bin/ever-shipped-skills.test.mjs +8 -0
- package/bin/expand_home_directory_tokens.mjs +4 -5
- package/bin/expand_home_directory_tokens.test.mjs +128 -0
- package/bin/git_hooks_installer.mjs +22 -3
- package/bin/git_hooks_installer.test.mjs +159 -5
- package/bin/install-session-continuity.mjs +78 -0
- package/bin/install-session-continuity.test.mjs +42 -0
- package/bin/install.codex-rules.test.mjs +5 -2
- package/bin/install.cursor-rules.test.mjs +5 -2
- package/bin/install.mjs +478 -63
- package/bin/install.policy-lint.test.mjs +56 -4
- package/bin/install.profiles.test.mjs +10 -0
- package/bin/install.prune.test.mjs +227 -17
- package/bin/install.test.mjs +500 -120
- package/bin/install.transaction.test.mjs +3 -3
- package/docs/CODE_RULES.md +1 -1
- package/hooks/blocking/code_rules_banned_identifiers.py +3 -0
- package/hooks/blocking/precommit_code_rules_gate.py +5 -8
- package/hooks/blocking/test_bash_dispatcher_interpreter_starts.py +7 -52
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +0 -69
- package/hooks/blocking/test_code_rules_banned_identifiers.py +64 -0
- package/hooks/blocking/test_pre_tool_use_dispatcher.py +10 -244
- package/hooks/blocking/test_shared_stdin_adoption.py +1 -47
- package/hooks/git-hooks/git_hooks_constants/verification_notice_constants.py +116 -0
- package/hooks/git-hooks/post_commit.py +33 -0
- package/hooks/git-hooks/pre_commit.py +18 -90
- package/hooks/git-hooks/pre_push.py +45 -541
- package/hooks/git-hooks/test_installed_policy_lint.py +55 -6
- package/hooks/git-hooks/test_native_hook_support.py +129 -0
- package/hooks/git-hooks/test_native_policy_commit.py +39 -6
- package/hooks/git-hooks/test_post_commit.py +43 -0
- package/hooks/git-hooks/test_pre_commit.py +36 -392
- package/hooks/git-hooks/test_pre_push.py +48 -1631
- package/hooks/git-hooks/test_verification_notice.py +60 -0
- package/hooks/git-hooks/test_verification_start.py +173 -0
- package/hooks/git-hooks/verification_notice.py +192 -0
- package/hooks/git-hooks/verification_notice_context.py +253 -0
- package/hooks/git-hooks/verification_notice_state.py +237 -0
- package/hooks/git-hooks/verification_start.py +100 -0
- package/hooks/hooks.json +0 -119
- package/hooks/hooks_constants/banned_identifiers_constants.py +4 -0
- package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +1 -15
- package/hooks/hooks_constants/post_tool_use_dispatcher_constants.py +0 -4
- package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +0 -50
- package/hooks/hooks_constants/stop_dispatcher_constants.py +1 -4
- package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +3 -66
- package/hooks/hooks_constants/test_pre_tool_use_dispatcher_constants.py +42 -185
- package/hooks/hooks_constants/test_stop_dispatcher_constants.py +3 -25
- package/hooks/validation/test_post_tool_use_dispatcher.py +35 -298
- package/hooks/validators/run_all_validators.py +5 -1
- package/hooks/validators/security_checks.py +57 -2
- package/hooks/validators/test_hook_timing_harness.py +2 -5
- package/hooks/validators/test_run_all_validators_mutation_tool_parity.py +3 -11
- package/hooks/validators/test_run_all_validators_policy_lint.py +36 -0
- package/hooks/validators/test_security_checks.py +57 -0
- package/package.json +1 -1
- package/rules/confirm-implementation-forks.md +2 -0
- package/rules/git-workflow.md +12 -0
- package/rules/pstack-host-mapping.md +48 -0
- package/rules/vault-context.md +3 -5
- package/rules/verify-runtime-state.md +7 -0
- package/scripts/audit-hooks-cli.mjs +5 -0
- package/scripts/audit-hooks.mjs +72 -16
- package/scripts/automatic_advisory/__init__.py +1 -0
- package/scripts/automatic_advisory/checkout.py +51 -0
- package/scripts/automatic_advisory/cli.py +334 -0
- package/scripts/automatic_advisory/config/__init__.py +1 -0
- package/scripts/automatic_advisory/config/constants.py +93 -0
- package/scripts/automatic_advisory/config/timing.py +4 -0
- package/scripts/automatic_advisory/configuration.py +197 -0
- package/scripts/automatic_advisory/execution.py +350 -0
- package/scripts/automatic_advisory/git.py +69 -0
- package/scripts/automatic_advisory/model.py +107 -0
- package/scripts/automatic_advisory/process_host.py +32 -0
- package/scripts/automatic_advisory/publisher.py +84 -0
- package/scripts/automatic_advisory/runner.py +399 -0
- package/scripts/automatic_advisory/state.py +116 -0
- package/scripts/automatic_advisory/window_flags.py +41 -0
- package/scripts/automatic_advisory/windows_job.py +122 -0
- package/scripts/codex_compat_materializer.py +99 -13
- package/scripts/durable_post_lint.py +30 -2
- package/scripts/durable_post_lint_config/config/constants.py +10 -0
- package/scripts/durable_post_lint_config/config/test_constants.py +13 -0
- package/scripts/local_report_cli.py +184 -0
- package/scripts/local_report_core.py +247 -0
- package/scripts/local_report_publisher.py +12 -0
- package/scripts/local_report_validation.py +357 -0
- package/scripts/local_verification/__init__.py +23 -0
- package/scripts/local_verification/check_runner.py +364 -0
- package/scripts/local_verification/check_support.py +99 -0
- package/scripts/local_verification/cli.py +158 -0
- package/scripts/local_verification/command_runner.py +84 -0
- package/scripts/local_verification/config/__init__.py +1 -0
- package/scripts/local_verification/config/constants.py +89 -0
- package/scripts/local_verification/config/timing.py +1 -0
- package/scripts/local_verification/git_state.py +146 -0
- package/scripts/local_verification/manifest.py +224 -0
- package/scripts/local_verification/model.py +174 -0
- package/scripts/local_verification/runner.py +234 -0
- package/scripts/policy_lint/adapter_pairing.py +58 -3
- package/scripts/policy_lint/config/approved_test_pairs.py +323 -0
- package/scripts/pr_verification/__init__.py +1 -0
- package/scripts/pr_verification/branch_refs.py +114 -0
- package/scripts/pr_verification/config/__init__.py +1 -0
- package/scripts/pr_verification/config/constants.py +84 -0
- package/scripts/pr_verification/config/timing.py +5 -0
- package/scripts/pr_verification/github.py +137 -0
- package/scripts/pr_verification/github_api.py +376 -0
- package/scripts/pr_verification/github_labels.py +88 -0
- package/scripts/pr_verification/github_parsing.py +182 -0
- package/scripts/pr_verification/github_transport.py +91 -0
- package/scripts/pr_verification/lock.py +122 -0
- package/scripts/pr_verification/model.py +43 -0
- package/scripts/pr_verification/requirements.txt +1 -0
- package/scripts/test_durable_post_lint.py +97 -0
- package/scripts/tests/test-audit-hooks-cli.mjs +150 -0
- package/scripts/tests/test-audit-hooks.mjs +94 -2
- package/scripts/tests/test_automatic_advisory.py +376 -0
- package/scripts/tests/test_automatic_advisory_job_cleanup.py +71 -0
- package/scripts/tests/test_automatic_advisory_polling.py +216 -0
- package/scripts/tests/test_automatic_advisory_recovery.py +320 -0
- package/scripts/tests/test_automatic_advisory_repairs.py +400 -0
- package/scripts/tests/test_automatic_advisory_settings.py +48 -0
- package/scripts/tests/test_automatic_advisory_window_flags.py +163 -0
- package/scripts/tests/test_closed_pr_label.py +157 -0
- package/scripts/tests/test_codex_compat_materializer.py +189 -6
- package/scripts/tests/test_github_labels.py +101 -0
- package/scripts/tests/test_github_transport.py +125 -0
- package/scripts/tests/test_local_report_publisher.py +396 -0
- package/scripts/tests/test_local_report_publisher_cli.py +85 -0
- package/scripts/tests/test_local_verification.py +348 -0
- package/scripts/tests/test_local_verification_cli.py +98 -0
- package/scripts/tests/test_policy_lint_rules_pairing.py +163 -0
- package/scripts/tests/test_pr_verification_github.py +392 -0
- package/scripts/tests/test_pr_verification_lock.py +168 -0
- package/scripts/tests/test_verification_notice.py +347 -0
- package/hooks/blocking/ask_user_question_shape_blocker.py +0 -83
- package/hooks/blocking/bot_mention_comment_blocker.py +0 -76
- package/hooks/blocking/claude_md_orphan_file_blocker.py +0 -129
- package/hooks/blocking/cursor_cli_python_misfire_blocker.py +0 -108
- package/hooks/blocking/destructive_command_blocker.py +0 -2073
- package/hooks/blocking/fable_spawn_gate.py +0 -187
- package/hooks/blocking/luna_fast_mode_gate.py +0 -160
- package/hooks/blocking/nas_ssh_binary_enforcer.py +0 -163
- package/hooks/blocking/orchestrator_refresh_reschedule_gate.py +0 -260
- package/hooks/blocking/package_inventory_stale_blocker.py +0 -107
- package/hooks/blocking/pii_prevention_blocker.py +0 -365
- package/hooks/blocking/piped_pytest_blocker.py +0 -1223
- package/hooks/blocking/question_to_user_enforcer.py +0 -130
- package/hooks/blocking/send_user_file_open_locally_blocker.py +0 -71
- package/hooks/blocking/sensitive_file_protector.py +0 -167
- package/hooks/blocking/session_edit_stage_gate.py +0 -684
- package/hooks/blocking/session_handoff_blocker.py +0 -182
- package/hooks/blocking/shell_substitution_blocker.py +0 -350
- package/hooks/blocking/test_ask_user_question_shape.py +0 -69
- package/hooks/blocking/test_bot_mention_comment_blocker.py +0 -131
- package/hooks/blocking/test_claude_md_orphan_file_blocker.py +0 -1277
- package/hooks/blocking/test_cursor_cli_python_misfire_blocker.py +0 -208
- package/hooks/blocking/test_destructive_command_blocker.py +0 -2024
- package/hooks/blocking/test_destructive_command_blocker_deny_mode.py +0 -105
- package/hooks/blocking/test_destructive_command_blocker_no_verify.py +0 -122
- package/hooks/blocking/test_destructive_command_blocker_patterns.py +0 -133
- package/hooks/blocking/test_fable_spawn_gate.py +0 -381
- package/hooks/blocking/test_inventory_deadlock_resolution.py +0 -154
- package/hooks/blocking/test_luna_fast_mode_gate.py +0 -211
- package/hooks/blocking/test_nas_ssh_binary_enforcer.py +0 -225
- package/hooks/blocking/test_orchestrator_refresh_reschedule_gate.py +0 -231
- package/hooks/blocking/test_package_inventory_stale_blocker.py +0 -382
- package/hooks/blocking/test_pii_prevention_blocker.py +0 -1222
- package/hooks/blocking/test_pii_prevention_windows_git_path.py +0 -41
- package/hooks/blocking/test_pii_write_surface_ephemeral.py +0 -221
- package/hooks/blocking/test_piped_pytest_blocker.py +0 -587
- package/hooks/blocking/test_precommit_code_rules_gate_native_owner.py +0 -233
- package/hooks/blocking/test_question_to_user_enforcer.py +0 -169
- package/hooks/blocking/test_send_user_file_open_locally_blocker.py +0 -118
- package/hooks/blocking/test_sensitive_file_protector.py +0 -365
- package/hooks/blocking/test_session_edit_stage_gate.py +0 -537
- package/hooks/blocking/test_session_edit_stage_gate_staging.py +0 -64
- package/hooks/blocking/test_session_edit_stage_gate_support.py +0 -204
- package/hooks/blocking/test_session_edit_stage_gate_tracker.py +0 -116
- package/hooks/blocking/test_session_handoff_blocker.py +0 -318
- package/hooks/blocking/test_shell_substitution_blocker.py +0 -298
- package/hooks/blocking/test_unscoped_search_blocker.py +0 -102
- package/hooks/blocking/test_write_existing_file_blocker.py +0 -122
- package/hooks/blocking/tests/test_pii_prevention_blocker.py +0 -259
- package/hooks/blocking/unscoped_search_blocker.py +0 -391
- package/hooks/blocking/write_existing_file_blocker.py +0 -124
- package/hooks/hooks_constants/bot_mention_comment_blocker_constants.py +0 -19
- package/hooks/hooks_constants/cursor_cli_python_misfire_blocker_constants.py +0 -79
- package/hooks/hooks_constants/fable_spawn_gate_constants.py +0 -61
- package/hooks/hooks_constants/luna_fast_mode_gate_constants.py +0 -45
- package/hooks/hooks_constants/nas_ssh_binary_enforcer_constants.py +0 -20
- package/hooks/hooks_constants/orchestrator_refresh_reschedule_gate_constants.py +0 -57
- package/hooks/hooks_constants/send_user_file_open_locally_blocker_constants.py +0 -17
- package/hooks/hooks_constants/sensitive_file_protector_constants.py +0 -40
- package/hooks/hooks_constants/session_handoff_blocker_constants.py +0 -10
- package/hooks/hooks_constants/shell_substitution_blocker_constants.py +0 -80
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"""Production-path tests for native staged-gate ownership.
|
|
2
|
-
|
|
3
|
-
The tests run the Agent Bash dispatcher and a native Git pre-commit hook against
|
|
4
|
-
the same isolated repository. The agent path passes the commit through. The
|
|
5
|
-
native path runs the staged gate and controls the commit.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
from collections.abc import Iterator
|
|
11
|
-
from contextlib import contextmanager
|
|
12
|
-
import json
|
|
13
|
-
import stat
|
|
14
|
-
import subprocess
|
|
15
|
-
import sys
|
|
16
|
-
from pathlib import Path
|
|
17
|
-
|
|
18
|
-
import pytest
|
|
19
|
-
|
|
20
|
-
HOOKS_ROOT = Path(__file__).resolve().parent.parent
|
|
21
|
-
BLOCKING_ROOT = HOOKS_ROOT / "blocking"
|
|
22
|
-
GIT_HOOKS_ROOT = HOOKS_ROOT / "git-hooks"
|
|
23
|
-
DISPATCHER_SOURCE_PATH = BLOCKING_ROOT / "bash_pre_tool_use_dispatcher.py"
|
|
24
|
-
GIT_COMMAND_TIMEOUT_SECONDS = 60
|
|
25
|
-
CLEAN_MODULE_SOURCE = (
|
|
26
|
-
"def add_one(number: int) -> int:\n"
|
|
27
|
-
' """Increase the number.\n\n'
|
|
28
|
-
" Args:\n number: The input number.\n\n"
|
|
29
|
-
" Returns:\n The next number.\n"
|
|
30
|
-
' """\n'
|
|
31
|
-
" return number + 1\n"
|
|
32
|
-
)
|
|
33
|
-
PAIRED_TEST_SOURCE = (
|
|
34
|
-
"from widget import add_one\n\n"
|
|
35
|
-
"def test_add_one() -> None:\n assert add_one(1) == 2\n"
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def run_git(
|
|
40
|
-
repository_root: Path,
|
|
41
|
-
*git_arguments: str,
|
|
42
|
-
check: bool = True,
|
|
43
|
-
) -> subprocess.CompletedProcess[str]:
|
|
44
|
-
"""Run one isolated Git command and return its captured process record."""
|
|
45
|
-
return subprocess.run(
|
|
46
|
-
["git", *git_arguments],
|
|
47
|
-
cwd=str(repository_root),
|
|
48
|
-
check=check,
|
|
49
|
-
capture_output=True,
|
|
50
|
-
text=True,
|
|
51
|
-
timeout=GIT_COMMAND_TIMEOUT_SECONDS,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def initialize_repository(repository_root: Path) -> None:
|
|
56
|
-
"""Create a repository with one committed base file and no active hook."""
|
|
57
|
-
run_git(repository_root, "init")
|
|
58
|
-
run_git(repository_root, "config", "user.name", "Hook Test")
|
|
59
|
-
run_git(repository_root, "config", "user.email", "hook-test@example.invalid")
|
|
60
|
-
run_git(repository_root, "config", "core.hooksPath", "absent_fixture_hooks")
|
|
61
|
-
(repository_root / "README.md").write_text("base\n", encoding="utf-8")
|
|
62
|
-
run_git(repository_root, "add", "README.md")
|
|
63
|
-
run_git(repository_root, "commit", "-m", "base")
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def write_gate_script(gate_path: Path, marker_path: Path, exit_code: int) -> None:
|
|
67
|
-
"""Write a staged-gate fixture that records arguments and exits."""
|
|
68
|
-
gate_path.write_text(
|
|
69
|
-
"import pathlib\n"
|
|
70
|
-
"import sys\n"
|
|
71
|
-
f"pathlib.Path({str(marker_path)!r}).write_text("
|
|
72
|
-
"'\\n'.join(sys.argv[1:]), encoding='utf-8')\n"
|
|
73
|
-
f"sys.exit({exit_code})\n",
|
|
74
|
-
encoding="utf-8",
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def install_native_pre_commit(hooks_path: Path) -> None:
|
|
79
|
-
"""Register the actual package owner with its complete linter dependency tree."""
|
|
80
|
-
hooks_path.mkdir()
|
|
81
|
-
pre_commit_path = hooks_path / "pre-commit"
|
|
82
|
-
pre_commit_path.write_text(
|
|
83
|
-
"#!/usr/bin/env python3\n"
|
|
84
|
-
"import sys\n"
|
|
85
|
-
f"sys.path.insert(0, {str(GIT_HOOKS_ROOT)!r})\n"
|
|
86
|
-
"import pre_commit\n"
|
|
87
|
-
"sys.exit(pre_commit.main())\n",
|
|
88
|
-
encoding="utf-8",
|
|
89
|
-
)
|
|
90
|
-
pre_commit_path.chmod(pre_commit_path.stat().st_mode | stat.S_IXUSR)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def configured_hooks_path(repository_root: Path) -> str | None:
|
|
94
|
-
"""Return the repository-local hooks path when one is configured."""
|
|
95
|
-
completed_config = run_git(
|
|
96
|
-
repository_root,
|
|
97
|
-
"config",
|
|
98
|
-
"--local",
|
|
99
|
-
"--get",
|
|
100
|
-
"core.hooksPath",
|
|
101
|
-
check=False,
|
|
102
|
-
)
|
|
103
|
-
if completed_config.returncode != 0:
|
|
104
|
-
return None
|
|
105
|
-
return completed_config.stdout.strip()
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def restore_hooks_path(repository_root: Path, prior_hooks_path: str | None) -> None:
|
|
109
|
-
"""Restore the repository-local hooks path captured before a benchmark."""
|
|
110
|
-
if prior_hooks_path is None:
|
|
111
|
-
run_git(
|
|
112
|
-
repository_root,
|
|
113
|
-
"config",
|
|
114
|
-
"--local",
|
|
115
|
-
"--unset-all",
|
|
116
|
-
"core.hooksPath",
|
|
117
|
-
check=False,
|
|
118
|
-
)
|
|
119
|
-
return
|
|
120
|
-
run_git(repository_root, "config", "--local", "core.hooksPath", prior_hooks_path)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
@contextmanager
|
|
124
|
-
def temporary_hooks_path(repository_root: Path, benchmark_hooks_path: Path) -> Iterator[None]:
|
|
125
|
-
"""Apply a benchmark hooks path and restore the prior local setting."""
|
|
126
|
-
prior_hooks_path = configured_hooks_path(repository_root)
|
|
127
|
-
run_git(repository_root, "config", "--local", "core.hooksPath", str(benchmark_hooks_path))
|
|
128
|
-
try:
|
|
129
|
-
yield
|
|
130
|
-
finally:
|
|
131
|
-
restore_hooks_path(repository_root, prior_hooks_path)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def stage_module(repository_root: Path) -> None:
|
|
135
|
-
"""Stage a valid module and matching test before exercising the legacy gate."""
|
|
136
|
-
(repository_root / "widget.py").write_text(CLEAN_MODULE_SOURCE, encoding="utf-8")
|
|
137
|
-
(repository_root / "test_widget.py").write_text(PAIRED_TEST_SOURCE, encoding="utf-8")
|
|
138
|
-
run_git(repository_root, "add", "widget.py", "test_widget.py")
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
def build_bash_payload(repository_root: Path) -> str:
|
|
142
|
-
"""Build the Bash dispatcher payload for a commit in the fixture repository."""
|
|
143
|
-
commit_command = f'git -C "{repository_root}" commit -m add'
|
|
144
|
-
return json.dumps({"tool_name": "Bash", "tool_input": {"command": commit_command}})
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
def run_agent_dispatcher(repository_root: Path) -> subprocess.CompletedProcess[str]:
|
|
148
|
-
"""Run the production Bash dispatcher against the fixture commit command."""
|
|
149
|
-
return subprocess.run(
|
|
150
|
-
[sys.executable, str(DISPATCHER_SOURCE_PATH)],
|
|
151
|
-
cwd=str(repository_root),
|
|
152
|
-
input=build_bash_payload(repository_root),
|
|
153
|
-
capture_output=True,
|
|
154
|
-
text=True,
|
|
155
|
-
timeout=GIT_COMMAND_TIMEOUT_SECONDS,
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def run_native_commit(repository_root: Path) -> subprocess.CompletedProcess[str]:
|
|
160
|
-
"""Run the real Git commit that invokes the configured native hook."""
|
|
161
|
-
return run_git(
|
|
162
|
-
repository_root,
|
|
163
|
-
"commit",
|
|
164
|
-
"-m",
|
|
165
|
-
"add widget",
|
|
166
|
-
check=False,
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def test_agent_dispatcher_passes_commit_through_without_running_gate(
|
|
171
|
-
tmp_path: Path,
|
|
172
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
173
|
-
) -> None:
|
|
174
|
-
"""The Agent Bash path continues the commit without running the staged gate."""
|
|
175
|
-
initialize_repository(tmp_path)
|
|
176
|
-
stage_module(tmp_path)
|
|
177
|
-
gate_marker_path = tmp_path / "agent_gate_invocation.txt"
|
|
178
|
-
gate_path = tmp_path / "agent_gate.py"
|
|
179
|
-
write_gate_script(gate_path, gate_marker_path, exit_code=1)
|
|
180
|
-
monkeypatch.setenv("CODE_RULES_GATE_PATH", str(gate_path))
|
|
181
|
-
|
|
182
|
-
completed_dispatcher = run_agent_dispatcher(tmp_path)
|
|
183
|
-
|
|
184
|
-
assert completed_dispatcher.returncode == 0, completed_dispatcher.stderr
|
|
185
|
-
assert completed_dispatcher.stdout.strip() == ""
|
|
186
|
-
assert not gate_marker_path.exists()
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
@pytest.mark.parametrize("gate_exit_code, expected_commit_exit_code", [(1, 1), (0, 0)])
|
|
190
|
-
def test_installed_native_pre_commit_controls_staged_gate_decision(
|
|
191
|
-
tmp_path: Path,
|
|
192
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
193
|
-
gate_exit_code: int,
|
|
194
|
-
expected_commit_exit_code: int,
|
|
195
|
-
) -> None:
|
|
196
|
-
"""The native Git hook runs the staged gate and returns its commit decision."""
|
|
197
|
-
initialize_repository(tmp_path)
|
|
198
|
-
native_hooks_path = tmp_path / "native_hooks"
|
|
199
|
-
install_native_pre_commit(native_hooks_path)
|
|
200
|
-
stage_module(tmp_path)
|
|
201
|
-
gate_marker_path = tmp_path / "native_gate_invocation.txt"
|
|
202
|
-
gate_path = tmp_path / "native_gate.py"
|
|
203
|
-
write_gate_script(gate_path, gate_marker_path, gate_exit_code)
|
|
204
|
-
monkeypatch.setenv("CODE_RULES_GATE_PATH", str(gate_path))
|
|
205
|
-
|
|
206
|
-
with temporary_hooks_path(tmp_path, native_hooks_path):
|
|
207
|
-
completed_commit = run_native_commit(tmp_path)
|
|
208
|
-
|
|
209
|
-
assert completed_commit.returncode == expected_commit_exit_code
|
|
210
|
-
assert gate_marker_path.read_text(encoding="utf-8") == "--immediate"
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
def test_temporary_hooks_path_restores_shared_worktree_config_on_timeout(
|
|
214
|
-
tmp_path: Path,
|
|
215
|
-
) -> None:
|
|
216
|
-
initialize_repository(tmp_path)
|
|
217
|
-
supported_hooks_path = tmp_path / "supported_hooks"
|
|
218
|
-
supported_hooks_path.mkdir()
|
|
219
|
-
run_git(tmp_path, "config", "core.hooksPath", str(supported_hooks_path))
|
|
220
|
-
unrelated_worktree = tmp_path.parent / "unrelated_worktree"
|
|
221
|
-
run_git(tmp_path, "worktree", "add", "--detach", str(unrelated_worktree))
|
|
222
|
-
benchmark_hooks_path = tmp_path / "benchmark_hooks"
|
|
223
|
-
benchmark_hooks_path.mkdir()
|
|
224
|
-
|
|
225
|
-
try:
|
|
226
|
-
with pytest.raises(subprocess.TimeoutExpired):
|
|
227
|
-
with temporary_hooks_path(tmp_path, benchmark_hooks_path):
|
|
228
|
-
raise subprocess.TimeoutExpired("benchmark", 1)
|
|
229
|
-
|
|
230
|
-
assert configured_hooks_path(tmp_path) == str(supported_hooks_path)
|
|
231
|
-
assert configured_hooks_path(unrelated_worktree) == str(supported_hooks_path)
|
|
232
|
-
finally:
|
|
233
|
-
run_git(tmp_path, "worktree", "remove", "--force", str(unrelated_worktree))
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"""Tests for question_to_user_enforcer hook response shape and detection logic."""
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
import subprocess
|
|
6
|
-
import sys
|
|
7
|
-
|
|
8
|
-
HOOK_SCRIPT_PATH = os.path.join(
|
|
9
|
-
os.path.dirname(__file__), "question_to_user_enforcer.py"
|
|
10
|
-
)
|
|
11
|
-
_HOOKS_DIR = os.path.dirname(HOOK_SCRIPT_PATH)
|
|
12
|
-
_HOOKS_ROOT = os.path.join(_HOOKS_DIR, "..")
|
|
13
|
-
if _HOOKS_DIR not in sys.path:
|
|
14
|
-
sys.path.insert(0, _HOOKS_DIR)
|
|
15
|
-
if _HOOKS_ROOT not in sys.path:
|
|
16
|
-
sys.path.insert(0, _HOOKS_ROOT)
|
|
17
|
-
import question_to_user_enforcer
|
|
18
|
-
from hooks_constants.messages import USER_FACING_ASKUSERQUESTION_NOTICE
|
|
19
|
-
from hooks_constants.text_stripping import strip_code_and_quotes
|
|
20
|
-
|
|
21
|
-
CLEAN_DECLARATIVE_MESSAGE = "I applied the rename across both files. The tests pass."
|
|
22
|
-
TRAILING_QUESTION_MESSAGE = (
|
|
23
|
-
"I applied the rename across both files. Should this also propagate to the docs?"
|
|
24
|
-
)
|
|
25
|
-
WANT_ME_TO_MESSAGE = "I finished the refactor.\n\nWant me to open the PR now?"
|
|
26
|
-
SHOULD_I_STATEMENT_MESSAGE = (
|
|
27
|
-
"The diff is ready.\n\nShould I proceed with committing it."
|
|
28
|
-
)
|
|
29
|
-
FENCED_CODE_QUESTION_MESSAGE = (
|
|
30
|
-
"Here is the diagnostic snippet:\n\n"
|
|
31
|
-
"```python\n"
|
|
32
|
-
"print('does this work?')\n"
|
|
33
|
-
"```\n\n"
|
|
34
|
-
"The snippet confirms the behavior."
|
|
35
|
-
)
|
|
36
|
-
RHETORICAL_MIDDLE_MESSAGE = (
|
|
37
|
-
"Consider the failure mode.\n\n"
|
|
38
|
-
"What happens if the queue is empty? The handler short-circuits cleanly.\n\n"
|
|
39
|
-
"That covers the edge case."
|
|
40
|
-
)
|
|
41
|
-
QUESTION_WITH_TRAILING_DOUBLE_QUOTE_MESSAGE = (
|
|
42
|
-
'I renamed the flag.\n\nDid you mean "enable_fast_path?"'
|
|
43
|
-
)
|
|
44
|
-
QUESTION_WITH_TRAILING_SINGLE_QUOTE_MESSAGE = (
|
|
45
|
-
"I renamed the flag.\n\nDid you mean 'enable_fast_path?'"
|
|
46
|
-
)
|
|
47
|
-
QUESTION_WITH_TRAILING_PAREN_MESSAGE = (
|
|
48
|
-
"I finished the refactor.\n\nShould I also bump the version (minor or patch?)"
|
|
49
|
-
)
|
|
50
|
-
QUESTION_WITH_TRAILING_BRACKET_MESSAGE = (
|
|
51
|
-
"I finished the refactor.\n\nShould I also bump the version [minor or patch?]"
|
|
52
|
-
)
|
|
53
|
-
QUESTION_WITH_TRAILING_SPACE_MESSAGE = (
|
|
54
|
-
"I finished the refactor.\n\nShould I also bump the version? "
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def run_hook_with_payload(payload: dict) -> subprocess.CompletedProcess:
|
|
59
|
-
hook_input_payload = json.dumps(payload)
|
|
60
|
-
return subprocess.run(
|
|
61
|
-
[sys.executable, HOOK_SCRIPT_PATH],
|
|
62
|
-
input=hook_input_payload,
|
|
63
|
-
capture_output=True,
|
|
64
|
-
text=True,
|
|
65
|
-
check=False,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def run_hook_with_message(assistant_message: str) -> subprocess.CompletedProcess:
|
|
70
|
-
return run_hook_with_payload({"last_assistant_message": assistant_message})
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def test_blocker_uses_shared_strip_code_and_quotes() -> None:
|
|
74
|
-
assert question_to_user_enforcer.strip_code_and_quotes is strip_code_and_quotes
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def test_clean_declarative_message_passes_through():
|
|
78
|
-
completed_process = run_hook_with_message(CLEAN_DECLARATIVE_MESSAGE)
|
|
79
|
-
assert completed_process.returncode == 0
|
|
80
|
-
assert completed_process.stdout == ""
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def test_final_paragraph_ending_with_question_mark_emits_block():
|
|
84
|
-
completed_process = run_hook_with_message(TRAILING_QUESTION_MESSAGE)
|
|
85
|
-
assert completed_process.returncode == 0
|
|
86
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
87
|
-
assert parsed_response["decision"] == "block"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def test_want_me_to_preamble_in_final_paragraph_emits_block():
|
|
91
|
-
completed_process = run_hook_with_message(WANT_ME_TO_MESSAGE)
|
|
92
|
-
assert completed_process.returncode == 0
|
|
93
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
94
|
-
assert parsed_response["decision"] == "block"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def test_should_i_preamble_without_question_mark_emits_block():
|
|
98
|
-
completed_process = run_hook_with_message(SHOULD_I_STATEMENT_MESSAGE)
|
|
99
|
-
assert completed_process.returncode == 0
|
|
100
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
101
|
-
assert parsed_response["decision"] == "block"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def test_question_mark_inside_fenced_code_block_passes_through():
|
|
105
|
-
completed_process = run_hook_with_message(FENCED_CODE_QUESTION_MESSAGE)
|
|
106
|
-
assert completed_process.returncode == 0
|
|
107
|
-
assert completed_process.stdout == ""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def test_stop_hook_active_flag_passes_through():
|
|
111
|
-
completed_process = run_hook_with_payload(
|
|
112
|
-
{
|
|
113
|
-
"last_assistant_message": TRAILING_QUESTION_MESSAGE,
|
|
114
|
-
"stop_hook_active": True,
|
|
115
|
-
}
|
|
116
|
-
)
|
|
117
|
-
assert completed_process.returncode == 0
|
|
118
|
-
assert completed_process.stdout == ""
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def test_rhetorical_middle_paragraph_with_declarative_final_passes_through():
|
|
122
|
-
completed_process = run_hook_with_message(RHETORICAL_MIDDLE_MESSAGE)
|
|
123
|
-
assert completed_process.returncode == 0
|
|
124
|
-
assert completed_process.stdout == ""
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def test_block_response_json_shape():
|
|
128
|
-
completed_process = run_hook_with_message(TRAILING_QUESTION_MESSAGE)
|
|
129
|
-
assert completed_process.returncode == 0
|
|
130
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
131
|
-
assert parsed_response["decision"] == "block"
|
|
132
|
-
assert "AskUserQuestion" in parsed_response["reason"]
|
|
133
|
-
assert parsed_response["systemMessage"] == USER_FACING_ASKUSERQUESTION_NOTICE
|
|
134
|
-
assert parsed_response["suppressOutput"] is True
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def test_question_followed_by_double_quote_emits_block():
|
|
138
|
-
completed_process = run_hook_with_message(QUESTION_WITH_TRAILING_DOUBLE_QUOTE_MESSAGE)
|
|
139
|
-
assert completed_process.returncode == 0
|
|
140
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
141
|
-
assert parsed_response["decision"] == "block"
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def test_question_followed_by_single_quote_emits_block():
|
|
145
|
-
completed_process = run_hook_with_message(QUESTION_WITH_TRAILING_SINGLE_QUOTE_MESSAGE)
|
|
146
|
-
assert completed_process.returncode == 0
|
|
147
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
148
|
-
assert parsed_response["decision"] == "block"
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def test_question_followed_by_closing_paren_emits_block():
|
|
152
|
-
completed_process = run_hook_with_message(QUESTION_WITH_TRAILING_PAREN_MESSAGE)
|
|
153
|
-
assert completed_process.returncode == 0
|
|
154
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
155
|
-
assert parsed_response["decision"] == "block"
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def test_question_followed_by_closing_bracket_emits_block():
|
|
159
|
-
completed_process = run_hook_with_message(QUESTION_WITH_TRAILING_BRACKET_MESSAGE)
|
|
160
|
-
assert completed_process.returncode == 0
|
|
161
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
162
|
-
assert parsed_response["decision"] == "block"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def test_question_followed_by_trailing_space_emits_block():
|
|
166
|
-
completed_process = run_hook_with_message(QUESTION_WITH_TRAILING_SPACE_MESSAGE)
|
|
167
|
-
assert completed_process.returncode == 0
|
|
168
|
-
parsed_response = json.loads(completed_process.stdout)
|
|
169
|
-
assert parsed_response["decision"] == "block"
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"""Unit tests for the send-user-file-open-locally PreToolUse hook."""
|
|
2
|
-
|
|
3
|
-
import importlib.util
|
|
4
|
-
import io
|
|
5
|
-
import json
|
|
6
|
-
import pathlib
|
|
7
|
-
import sys
|
|
8
|
-
from unittest import mock
|
|
9
|
-
|
|
10
|
-
_HOOK_DIR = pathlib.Path(__file__).parent
|
|
11
|
-
if str(_HOOK_DIR) not in sys.path:
|
|
12
|
-
sys.path.insert(0, str(_HOOK_DIR))
|
|
13
|
-
|
|
14
|
-
hook_spec = importlib.util.spec_from_file_location(
|
|
15
|
-
"send_user_file_open_locally_blocker",
|
|
16
|
-
_HOOK_DIR / "send_user_file_open_locally_blocker.py",
|
|
17
|
-
)
|
|
18
|
-
assert hook_spec is not None
|
|
19
|
-
assert hook_spec.loader is not None
|
|
20
|
-
hook_module = importlib.util.module_from_spec(hook_spec)
|
|
21
|
-
hook_spec.loader.exec_module(hook_module)
|
|
22
|
-
|
|
23
|
-
_should_block = hook_module._should_block
|
|
24
|
-
|
|
25
|
-
from hooks_constants.send_user_file_open_locally_blocker_constants import (
|
|
26
|
-
CORRECTIVE_MESSAGE,
|
|
27
|
-
PROACTIVE_STATUS,
|
|
28
|
-
TOOL_NAME,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def test_blocks_normal_status() -> None:
|
|
33
|
-
assert _should_block("normal") is True
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def test_blocks_empty_status() -> None:
|
|
37
|
-
assert _should_block("") is True
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def test_blocks_unknown_status() -> None:
|
|
41
|
-
assert _should_block("whatever") is True
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def test_allows_proactive_status() -> None:
|
|
45
|
-
assert _should_block(PROACTIVE_STATUS) is False
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_corrective_message_points_to_native_windows_app() -> None:
|
|
49
|
-
assert "native Windows app" in CORRECTIVE_MESSAGE
|
|
50
|
-
assert "Invoke-Item -LiteralPath" in CORRECTIVE_MESSAGE
|
|
51
|
-
assert "Show-Asset.ps1" not in CORRECTIVE_MESSAGE
|
|
52
|
-
assert "Cursor.exe" in CORRECTIVE_MESSAGE
|
|
53
|
-
assert "EPIPE" in CORRECTIVE_MESSAGE
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def test_corrective_message_names_proactive_escape_hatch() -> None:
|
|
57
|
-
assert PROACTIVE_STATUS in CORRECTIVE_MESSAGE
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def _run_main_with_io(input_text: str) -> str:
|
|
61
|
-
with mock.patch("sys.stdin", io.StringIO(input_text)):
|
|
62
|
-
with mock.patch("sys.stdout", new_callable=io.StringIO) as mock_stdout:
|
|
63
|
-
try:
|
|
64
|
-
hook_module.main()
|
|
65
|
-
except SystemExit:
|
|
66
|
-
pass
|
|
67
|
-
return mock_stdout.getvalue()
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def test_main_blocks_normal_attach() -> None:
|
|
71
|
-
hook_input = {
|
|
72
|
-
"tool_name": TOOL_NAME,
|
|
73
|
-
"tool_input": {"files": ["report.html"], "status": "normal"},
|
|
74
|
-
}
|
|
75
|
-
output_text = _run_main_with_io(json.dumps(hook_input))
|
|
76
|
-
output = json.loads(output_text)
|
|
77
|
-
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
78
|
-
assert "native Windows app" in output["hookSpecificOutput"]["permissionDecisionReason"]
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def test_main_allows_proactive_attach() -> None:
|
|
82
|
-
hook_input = {
|
|
83
|
-
"tool_name": TOOL_NAME,
|
|
84
|
-
"tool_input": {"files": ["report.html"], "status": "proactive"},
|
|
85
|
-
}
|
|
86
|
-
assert _run_main_with_io(json.dumps(hook_input)) == ""
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def test_main_blocks_when_status_missing() -> None:
|
|
90
|
-
hook_input = {
|
|
91
|
-
"tool_name": TOOL_NAME,
|
|
92
|
-
"tool_input": {"files": ["report.html"]},
|
|
93
|
-
}
|
|
94
|
-
output_text = _run_main_with_io(json.dumps(hook_input))
|
|
95
|
-
output = json.loads(output_text)
|
|
96
|
-
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def test_main_blocks_when_tool_input_is_null() -> None:
|
|
100
|
-
hook_input = {
|
|
101
|
-
"tool_name": TOOL_NAME,
|
|
102
|
-
"tool_input": None,
|
|
103
|
-
}
|
|
104
|
-
output_text = _run_main_with_io(json.dumps(hook_input))
|
|
105
|
-
output = json.loads(output_text)
|
|
106
|
-
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def test_main_passes_wrong_tool_name() -> None:
|
|
110
|
-
hook_input = {
|
|
111
|
-
"tool_name": "Write",
|
|
112
|
-
"tool_input": {"files": ["report.html"], "status": "normal"},
|
|
113
|
-
}
|
|
114
|
-
assert _run_main_with_io(json.dumps(hook_input)) == ""
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def test_main_passes_malformed_json() -> None:
|
|
118
|
-
assert _run_main_with_io("not valid json {{{") == ""
|