ok
This commit is contained in:
@@ -439,3 +439,76 @@ class TestPreToolUseHook:
|
||||
result = pretooluse_hook(hook_data, config)
|
||||
assert result["permissionDecision"] == "deny"
|
||||
assert "any" in result["reason"].lower()
|
||||
|
||||
def test_type_ignore_usage_denied_on_analysis_failure(self):
|
||||
config = QualityConfig()
|
||||
hook_data = {
|
||||
"tool_name": "Write",
|
||||
"tool_input": {
|
||||
"file_path": "example.py",
|
||||
"content": (
|
||||
"def sample() -> None:\n"
|
||||
" value = unknown # type: ignore[attr-defined]\n"
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
with patch(
|
||||
"code_quality_guard._perform_quality_check",
|
||||
side_effect=RuntimeError("boom"),
|
||||
):
|
||||
result = pretooluse_hook(hook_data, config)
|
||||
|
||||
assert result["permissionDecision"] == "deny"
|
||||
assert "type: ignore" in result["reason"].lower()
|
||||
assert "fix these issues" in result["reason"].lower()
|
||||
|
||||
def test_type_ignore_usage_denied(self):
|
||||
config = QualityConfig(enforcement_mode="strict")
|
||||
hook_data = {
|
||||
"tool_name": "Write",
|
||||
"tool_input": {
|
||||
"file_path": "example.py",
|
||||
"content": (
|
||||
"def example() -> None:\n" " value = unknown # type: ignore\n"
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
with patch("code_quality_guard.analyze_code_quality") as mock_analyze:
|
||||
mock_analyze.return_value = {}
|
||||
|
||||
result = pretooluse_hook(hook_data, config)
|
||||
assert result["permissionDecision"] == "deny"
|
||||
assert "type: ignore" in result["reason"].lower()
|
||||
|
||||
def test_type_ignore_usage_detected_in_multiedit(self):
|
||||
config = QualityConfig()
|
||||
hook_data = {
|
||||
"tool_name": "MultiEdit",
|
||||
"tool_input": {
|
||||
"file_path": "example.py",
|
||||
"edits": [
|
||||
{
|
||||
"old_string": "pass",
|
||||
"new_string": (
|
||||
"def helper() -> None:\n" " pass # type: ignore\n"
|
||||
),
|
||||
},
|
||||
{
|
||||
"old_string": "pass",
|
||||
"new_string": (
|
||||
"def handler() -> None:\n"
|
||||
" value = unknown # type: ignore[attr-defined]\n"
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
with patch("code_quality_guard.analyze_code_quality") as mock_analyze:
|
||||
mock_analyze.return_value = {}
|
||||
|
||||
result = pretooluse_hook(hook_data, config)
|
||||
assert result["permissionDecision"] == "deny"
|
||||
assert "type: ignore" in result["reason"].lower()
|
||||
|
||||
Reference in New Issue
Block a user