claude-dev-env 1.59.0 → 1.60.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/audit-rubrics/category_rubrics/category-b-selector-engine-compat.md +1 -1
- package/audit-rubrics/category_rubrics/category-e-dead-code.md +1 -0
- package/audit-rubrics/category_rubrics/category-o-docstring-vs-impl-drift.md +1 -1
- package/audit-rubrics/prompts/category-b-selector-engine-compat.md +2 -2
- package/hooks/blocking/code_rules_dead_module_constant.py +321 -0
- package/hooks/blocking/code_rules_duplicate_body.py +152 -0
- package/hooks/blocking/code_rules_enforcer.py +30 -15
- package/hooks/blocking/code_rules_typeddict_stub.py +172 -0
- package/hooks/blocking/config/__init__.py +5 -0
- package/hooks/blocking/config/verified_commit_constants.py +106 -0
- package/hooks/blocking/test_code_rules_enforcer_cross_skill_duplicate.py +146 -0
- package/hooks/blocking/test_code_rules_enforcer_dead_module_constant.py +188 -0
- package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias.py +415 -0
- package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias_hook_routing.py +156 -0
- package/hooks/blocking/test_verdict_directory_write_blocker.py +720 -0
- package/hooks/blocking/test_verification_verdict_store.py +278 -0
- package/hooks/blocking/test_verified_commit_gate.py +368 -0
- package/hooks/blocking/test_verified_commit_message_accuracy_blocker.py +131 -0
- package/hooks/blocking/test_verifier_verdict_minter.py +214 -0
- package/hooks/blocking/verdict_directory_write_blocker.py +667 -0
- package/hooks/blocking/verification_verdict_store.py +446 -0
- package/hooks/blocking/verified_commit_gate.py +523 -0
- package/hooks/blocking/verified_commit_message_accuracy_blocker.py +152 -0
- package/hooks/blocking/verifier_verdict_minter.py +299 -0
- package/hooks/diagnostic/test_hook_log_extractor.py +3 -3
- package/hooks/hooks.json +43 -1
- package/hooks/hooks_constants/blocking_check_limits.py +1 -0
- package/hooks/hooks_constants/dead_module_constant_constants.py +20 -0
- package/hooks/hooks_constants/duplicate_function_body_constants.py +22 -5
- package/hooks/hooks_constants/precommit_code_rules_gate_constants.py +1 -1
- package/package.json +1 -1
- package/rules/file-global-constants.md +7 -1
- package/rules/no-cross-skill-duplicate-helpers.md +29 -0
- package/skills/_shared/pr-loop/scripts/preflight_worktree.py +392 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/preflight_constants.py +70 -0
- package/skills/_shared/pr-loop/scripts/test_preflight_worktree.py +263 -0
- package/skills/autoconverge/SKILL.md +54 -17
- package/skills/autoconverge/reference/closing-report.md +59 -17
- package/skills/autoconverge/workflow/aggregate_runs.py +371 -0
- package/skills/autoconverge/workflow/autoconverge_report_constants/render_report_constants.py +193 -76
- package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +76 -0
- package/skills/autoconverge/workflow/converge.contract.test.mjs +206 -206
- package/skills/autoconverge/workflow/converge.mjs +128 -6
- package/skills/autoconverge/workflow/convergence_summary.py +110 -0
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-ab1c2d3e4f5a6b7c8.jsonl +2 -0
- package/skills/autoconverge/workflow/fixtures/wf_run/workflows/wf_881252e6-700.json +7 -0
- package/skills/autoconverge/workflow/render_report.py +488 -397
- package/skills/autoconverge/workflow/test_aggregate_runs.py +134 -0
- package/skills/autoconverge/workflow/test_convergence_summary.py +132 -0
- package/skills/autoconverge/workflow/test_render_report.py +488 -259
- package/skills/pr-converge/reference/per-tick.md +28 -8
- package/skills/rebase/SKILL.md +2 -4
- package/system-prompts/software-engineer.xml +2 -6
- package/hooks/blocking/content_search_to_zoekt_redirector.py +0 -59
- package/hooks/blocking/content_search_zoekt_bash_block_reason.py +0 -25
- package/hooks/blocking/content_search_zoekt_block_payload.py +0 -21
- package/hooks/blocking/content_search_zoekt_indexed_paths.py +0 -24
- package/hooks/blocking/content_search_zoekt_indexed_roots_config.py +0 -131
- package/hooks/blocking/content_search_zoekt_redirect_guidance.py +0 -52
- package/hooks/blocking/test_content_search_to_zoekt_redirector_integration.py +0 -61
- package/hooks/blocking/test_content_search_to_zoekt_redirector_unit.py +0 -92
- package/hooks/blocking/test_content_search_zoekt_indexed_roots_config.py +0 -102
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib.util
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import stat
|
|
7
|
+
import tempfile
|
|
8
|
+
from collections.abc import Callable, Iterator
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
ENFORCER_PATH = Path(__file__).resolve().parent / "code_rules_enforcer.py"
|
|
14
|
+
specification = importlib.util.spec_from_file_location("code_rules_enforcer", ENFORCER_PATH)
|
|
15
|
+
assert specification is not None and specification.loader is not None
|
|
16
|
+
code_rules_enforcer = importlib.util.module_from_spec(specification)
|
|
17
|
+
specification.loader.exec_module(code_rules_enforcer)
|
|
18
|
+
|
|
19
|
+
CONSTANTS_BODY = 'MEDIUM_TERMINAL = "terminal"\nMEDIUM_CODE = "code"\nMEDIUM_TEXT = "text"\n'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _strip_read_only_and_retry(
|
|
23
|
+
removal_function: Callable[[str], object],
|
|
24
|
+
target_path: str,
|
|
25
|
+
_exc_info: BaseException,
|
|
26
|
+
) -> None:
|
|
27
|
+
try:
|
|
28
|
+
os.chmod(target_path, stat.S_IWRITE)
|
|
29
|
+
removal_function(target_path)
|
|
30
|
+
except OSError:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.fixture
|
|
35
|
+
def neutral_root() -> Iterator[Path]:
|
|
36
|
+
"""Yield a temp directory whose path carries no ``test_`` segment.
|
|
37
|
+
|
|
38
|
+
The enforcer's ``is_test_file`` keys on the full path string, and pytest's
|
|
39
|
+
own ``tmp_path`` directory name embeds the test name, which would make every
|
|
40
|
+
synthetic constants path look like a test file. A neutral ``mkdtemp`` root
|
|
41
|
+
mirrors how a production constants module path looks.
|
|
42
|
+
"""
|
|
43
|
+
neutral_directory = Path(tempfile.mkdtemp(prefix="deadconst-")).resolve()
|
|
44
|
+
try:
|
|
45
|
+
yield neutral_directory
|
|
46
|
+
finally:
|
|
47
|
+
shutil.rmtree(neutral_directory, onexc=_strip_read_only_and_retry)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _check(source: str, file_path: str) -> list[str]:
|
|
51
|
+
return code_rules_enforcer.check_dead_module_constants(source, file_path)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _build_constants_package(
|
|
55
|
+
workflow_directory: Path,
|
|
56
|
+
constants_body: str,
|
|
57
|
+
consumer_body: str,
|
|
58
|
+
) -> Path:
|
|
59
|
+
constants_package = workflow_directory / "report_constants"
|
|
60
|
+
constants_package.mkdir(parents=True)
|
|
61
|
+
(constants_package / "__init__.py").write_text("", encoding="utf-8")
|
|
62
|
+
constants_path = constants_package / "render_report_constants.py"
|
|
63
|
+
constants_path.write_text(constants_body, encoding="utf-8")
|
|
64
|
+
(workflow_directory / "render_report.py").write_text(consumer_body, encoding="utf-8")
|
|
65
|
+
return constants_path
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_flags_constant_imported_by_no_module_in_the_tree(neutral_root: Path) -> None:
|
|
69
|
+
consumer_body = (
|
|
70
|
+
"from report_constants.render_report_constants import (\n"
|
|
71
|
+
" MEDIUM_CODE,\n"
|
|
72
|
+
" MEDIUM_TERMINAL,\n"
|
|
73
|
+
")\n"
|
|
74
|
+
"\n"
|
|
75
|
+
"def panel_class(medium: str) -> str:\n"
|
|
76
|
+
" if medium == MEDIUM_TERMINAL:\n"
|
|
77
|
+
" return 'terminal'\n"
|
|
78
|
+
" return 'code-panel' if medium == MEDIUM_CODE else 'text-panel'\n"
|
|
79
|
+
)
|
|
80
|
+
constants_path = _build_constants_package(
|
|
81
|
+
neutral_root / "workflow", CONSTANTS_BODY, consumer_body
|
|
82
|
+
)
|
|
83
|
+
issues = _check(CONSTANTS_BODY, str(constants_path))
|
|
84
|
+
assert any("MEDIUM_TEXT" in each_issue for each_issue in issues), (
|
|
85
|
+
f"Expected dead MEDIUM_TEXT flagged, got: {issues}"
|
|
86
|
+
)
|
|
87
|
+
assert not any(
|
|
88
|
+
"MEDIUM_TERMINAL" in each_issue or "MEDIUM_CODE" in each_issue for each_issue in issues
|
|
89
|
+
), f"Imported constants must not be flagged, got: {issues}"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_does_not_flag_constant_imported_one_directory_up(neutral_root: Path) -> None:
|
|
93
|
+
consumer_uses_text = (
|
|
94
|
+
"from report_constants.render_report_constants import (\n"
|
|
95
|
+
" MEDIUM_CODE,\n"
|
|
96
|
+
" MEDIUM_TERMINAL,\n"
|
|
97
|
+
" MEDIUM_TEXT,\n"
|
|
98
|
+
")\n"
|
|
99
|
+
"\n"
|
|
100
|
+
"def panel_class(medium: str) -> str:\n"
|
|
101
|
+
" if medium == MEDIUM_TERMINAL:\n"
|
|
102
|
+
" return 'terminal'\n"
|
|
103
|
+
" if medium == MEDIUM_TEXT:\n"
|
|
104
|
+
" return 'text-panel'\n"
|
|
105
|
+
" return 'code-panel' if medium == MEDIUM_CODE else 'text-panel'\n"
|
|
106
|
+
)
|
|
107
|
+
constants_path = _build_constants_package(
|
|
108
|
+
neutral_root / "workflow", CONSTANTS_BODY, consumer_uses_text
|
|
109
|
+
)
|
|
110
|
+
issues = _check(CONSTANTS_BODY, str(constants_path))
|
|
111
|
+
assert issues == [], f"No constant is dead when all are imported, got: {issues}"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_does_not_flag_when_module_declares_dunder_all(neutral_root: Path) -> None:
|
|
115
|
+
constants_body = CONSTANTS_BODY + '__all__ = ["MEDIUM_TERMINAL"]\n'
|
|
116
|
+
consumer_body = (
|
|
117
|
+
"from report_constants.render_report_constants import MEDIUM_TERMINAL\n"
|
|
118
|
+
"\n"
|
|
119
|
+
"def label() -> str:\n"
|
|
120
|
+
" return MEDIUM_TERMINAL\n"
|
|
121
|
+
)
|
|
122
|
+
constants_path = _build_constants_package(
|
|
123
|
+
neutral_root / "workflow", constants_body, consumer_body
|
|
124
|
+
)
|
|
125
|
+
issues = _check(constants_body, str(constants_path))
|
|
126
|
+
assert issues == [], f"__all__ surface suppresses the check, got: {issues}"
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_does_not_run_on_ordinary_production_module(neutral_root: Path) -> None:
|
|
130
|
+
workflow_directory = neutral_root / "workflow"
|
|
131
|
+
workflow_directory.mkdir(parents=True)
|
|
132
|
+
ordinary_path = workflow_directory / "render_report.py"
|
|
133
|
+
body = "WIDGET_LIMIT = 5\n\ndef widgets() -> int:\n return WIDGET_LIMIT\n"
|
|
134
|
+
ordinary_path.write_text(body, encoding="utf-8")
|
|
135
|
+
issues = _check(body, str(ordinary_path))
|
|
136
|
+
assert issues == [], (
|
|
137
|
+
f"The dead-constant check runs only on dedicated constants modules, got: {issues}"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_runs_on_config_directory_module(neutral_root: Path) -> None:
|
|
142
|
+
package_directory = neutral_root / "app"
|
|
143
|
+
config_directory = package_directory / "config"
|
|
144
|
+
config_directory.mkdir(parents=True)
|
|
145
|
+
constants_body = "TIMEOUT_SECONDS = 30\nUNUSED_THRESHOLD = 99\n"
|
|
146
|
+
constants_path = config_directory / "timing.py"
|
|
147
|
+
constants_path.write_text(constants_body, encoding="utf-8")
|
|
148
|
+
consumer_body = (
|
|
149
|
+
"from config.timing import TIMEOUT_SECONDS\n"
|
|
150
|
+
"\n"
|
|
151
|
+
"def deadline() -> int:\n"
|
|
152
|
+
" return TIMEOUT_SECONDS\n"
|
|
153
|
+
)
|
|
154
|
+
(package_directory / "service.py").write_text(consumer_body, encoding="utf-8")
|
|
155
|
+
issues = _check(constants_body, str(constants_path))
|
|
156
|
+
assert any("UNUSED_THRESHOLD" in each_issue for each_issue in issues), (
|
|
157
|
+
f"Expected dead UNUSED_THRESHOLD flagged in config module, got: {issues}"
|
|
158
|
+
)
|
|
159
|
+
assert not any("TIMEOUT_SECONDS" in each_issue for each_issue in issues), (
|
|
160
|
+
f"Consumed config constant must not be flagged, got: {issues}"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def test_counts_a_reference_from_a_test_module(neutral_root: Path) -> None:
|
|
165
|
+
workflow_directory = neutral_root / "workflow"
|
|
166
|
+
constants_body = 'ONLY_TESTS_USE_THIS = "x"\n'
|
|
167
|
+
constants_path = workflow_directory / "render_report_constants.py"
|
|
168
|
+
workflow_directory.mkdir(parents=True)
|
|
169
|
+
constants_path.write_text(constants_body, encoding="utf-8")
|
|
170
|
+
test_body = (
|
|
171
|
+
"from render_report_constants import ONLY_TESTS_USE_THIS\n"
|
|
172
|
+
"\n"
|
|
173
|
+
"def test_value() -> None:\n"
|
|
174
|
+
" assert ONLY_TESTS_USE_THIS == 'x'\n"
|
|
175
|
+
)
|
|
176
|
+
(workflow_directory / "test_render_report.py").write_text(test_body, encoding="utf-8")
|
|
177
|
+
issues = _check(constants_body, str(constants_path))
|
|
178
|
+
assert issues == [], f"A constant used only by a test under the tree stays live, got: {issues}"
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_is_skipped_on_a_constants_test_file(neutral_root: Path) -> None:
|
|
182
|
+
workflow_directory = neutral_root / "workflow"
|
|
183
|
+
workflow_directory.mkdir(parents=True)
|
|
184
|
+
test_constants_path = workflow_directory / "test_render_report_constants.py"
|
|
185
|
+
body = 'UNREFERENCED = "y"\n'
|
|
186
|
+
test_constants_path.write_text(body, encoding="utf-8")
|
|
187
|
+
issues = _check(body, str(test_constants_path))
|
|
188
|
+
assert issues == [], f"Test files are exempt, got: {issues}"
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"""Tests for check_zero_payload_function_alias — flag pass-through function aliases.
|
|
2
|
+
|
|
3
|
+
CODE_RULES §9.5 discourages indirection without payload. A function whose entire
|
|
4
|
+
body (after an optional docstring) is a single `return other_function(...)` that
|
|
5
|
+
forwards its own parameters unchanged to another function defined in the same
|
|
6
|
+
module is a second name for one behavior. Callers should invoke the real function
|
|
7
|
+
directly. This check operates at function granularity, complementing the
|
|
8
|
+
module-level thin-wrapper check.
|
|
9
|
+
|
|
10
|
+
Hook infrastructure is NOT exempt: pass-through aliases inside hook modules are
|
|
11
|
+
the original motivating case. Test files and config files remain exempt because
|
|
12
|
+
re-binding aliases are legitimate scaffolding there.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import importlib.util
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from types import ModuleType
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _load_enforcer_module() -> ModuleType:
|
|
23
|
+
module_path = Path(__file__).parent / "code_rules_enforcer.py"
|
|
24
|
+
spec = importlib.util.spec_from_file_location("code_rules_enforcer", module_path)
|
|
25
|
+
assert spec is not None
|
|
26
|
+
assert spec.loader is not None
|
|
27
|
+
module = importlib.util.module_from_spec(spec)
|
|
28
|
+
spec.loader.exec_module(module)
|
|
29
|
+
return module
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
code_rules_enforcer = _load_enforcer_module()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def check_zero_payload_function_alias(content: str, file_path: str) -> list[str]:
|
|
36
|
+
return code_rules_enforcer.check_zero_payload_function_alias(content, file_path)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
PRODUCTION_FILE_PATH = "/project/src/detection.py"
|
|
40
|
+
HOOK_INFRASTRUCTURE_PATH = "/home/user/.claude/hooks/blocking/detection.py"
|
|
41
|
+
TEST_FILE_PATH = "/project/src/test_detection.py"
|
|
42
|
+
CONFIG_FILE_PATH = "/project/config/detection.py"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_should_flag_pass_through_alias_forwarding_same_parameters() -> None:
|
|
46
|
+
source = (
|
|
47
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
48
|
+
" return {part for part in content.split() if part}\n"
|
|
49
|
+
"\n"
|
|
50
|
+
"def find_bare_index_segments(content: str) -> set[str]:\n"
|
|
51
|
+
" return find_bare_path_segments(content)\n"
|
|
52
|
+
)
|
|
53
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
54
|
+
assert any("find_bare_index_segments" in each for each in issues), (
|
|
55
|
+
f"Expected pass-through alias flag, got: {issues!r}"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_should_flag_alias_inside_hook_infrastructure() -> None:
|
|
60
|
+
source = (
|
|
61
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
62
|
+
" return {part for part in content.split() if part}\n"
|
|
63
|
+
"\n"
|
|
64
|
+
"def find_bare_index_segments(content: str) -> set[str]:\n"
|
|
65
|
+
" return find_bare_path_segments(content)\n"
|
|
66
|
+
)
|
|
67
|
+
issues = check_zero_payload_function_alias(source, HOOK_INFRASTRUCTURE_PATH)
|
|
68
|
+
assert any("find_bare_index_segments" in each for each in issues), (
|
|
69
|
+
f"Hook infrastructure is the motivating case and must be flagged, got: {issues!r}"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_should_flag_alias_with_docstring_before_return() -> None:
|
|
74
|
+
source = (
|
|
75
|
+
"def compute_total(amount: int) -> int:\n"
|
|
76
|
+
" return amount * 2\n"
|
|
77
|
+
"\n"
|
|
78
|
+
"def calculate_total(amount: int) -> int:\n"
|
|
79
|
+
' """Forward to compute_total."""\n'
|
|
80
|
+
" return compute_total(amount)\n"
|
|
81
|
+
)
|
|
82
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
83
|
+
assert any("calculate_total" in each for each in issues), (
|
|
84
|
+
f"A docstring before the single return must not hide the alias, got: {issues!r}"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_should_not_flag_function_that_transforms_arguments() -> None:
|
|
89
|
+
source = (
|
|
90
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
91
|
+
" return {part for part in content.split() if part}\n"
|
|
92
|
+
"\n"
|
|
93
|
+
"def find_stripped_segments(content: str) -> set[str]:\n"
|
|
94
|
+
" return find_bare_path_segments(content.strip())\n"
|
|
95
|
+
)
|
|
96
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
97
|
+
assert issues == [], (
|
|
98
|
+
f"Transformed argument adds payload and must not be flagged, got: {issues!r}"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_should_not_flag_function_that_reorders_arguments() -> None:
|
|
103
|
+
source = (
|
|
104
|
+
"def divide(numerator: int, denominator: int) -> float:\n"
|
|
105
|
+
" return numerator / denominator\n"
|
|
106
|
+
"\n"
|
|
107
|
+
"def inverse_divide(denominator: int, numerator: int) -> float:\n"
|
|
108
|
+
" return divide(numerator, denominator)\n"
|
|
109
|
+
)
|
|
110
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
111
|
+
assert issues == [], (
|
|
112
|
+
f"Reordered arguments change behavior and must not be flagged, got: {issues!r}"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_should_not_flag_call_to_external_function() -> None:
|
|
117
|
+
source = (
|
|
118
|
+
"from other_module import real_helper\n"
|
|
119
|
+
"\n"
|
|
120
|
+
"def public_helper(value: int) -> int:\n"
|
|
121
|
+
" return real_helper(value)\n"
|
|
122
|
+
)
|
|
123
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
124
|
+
assert issues == [], (
|
|
125
|
+
f"A boundary wrapper around an imported function is not a same-module alias, "
|
|
126
|
+
f"got: {issues!r}"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_should_not_flag_method_call() -> None:
|
|
131
|
+
source = (
|
|
132
|
+
"def normalize(text: str) -> str:\n"
|
|
133
|
+
" return text.strip()\n"
|
|
134
|
+
)
|
|
135
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
136
|
+
assert issues == [], (
|
|
137
|
+
f"A call to a method on a parameter is real work, got: {issues!r}"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_should_not_flag_function_with_multiple_statements() -> None:
|
|
142
|
+
source = (
|
|
143
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
144
|
+
" return {part for part in content.split() if part}\n"
|
|
145
|
+
"\n"
|
|
146
|
+
"def find_logged_segments(content: str) -> set[str]:\n"
|
|
147
|
+
" all_segments = find_bare_path_segments(content)\n"
|
|
148
|
+
" return all_segments\n"
|
|
149
|
+
)
|
|
150
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
151
|
+
assert issues == [], (
|
|
152
|
+
f"A body with an intermediate binding is not a single pass-through, got: {issues!r}"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_should_not_flag_function_that_drops_keyword_only_parameter() -> None:
|
|
157
|
+
source = (
|
|
158
|
+
"def target(first: int) -> int:\n"
|
|
159
|
+
" return first\n"
|
|
160
|
+
"\n"
|
|
161
|
+
"def alias(first: int, *, second: int) -> int:\n"
|
|
162
|
+
" return target(first)\n"
|
|
163
|
+
)
|
|
164
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
165
|
+
assert issues == [], (
|
|
166
|
+
f"Dropping a keyword-only parameter changes behavior, not a pure alias, got: {issues!r}"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_should_not_flag_function_that_drops_var_positional_parameter() -> None:
|
|
171
|
+
source = (
|
|
172
|
+
"def target(first: int) -> int:\n"
|
|
173
|
+
" return first\n"
|
|
174
|
+
"\n"
|
|
175
|
+
"def alias(first: int, *rest: int) -> int:\n"
|
|
176
|
+
" return target(first)\n"
|
|
177
|
+
)
|
|
178
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
179
|
+
assert issues == [], (
|
|
180
|
+
f"Dropping *args changes behavior, not a pure alias, got: {issues!r}"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def test_should_not_flag_function_that_drops_var_keyword_parameter() -> None:
|
|
185
|
+
source = (
|
|
186
|
+
"def target(first: int) -> int:\n"
|
|
187
|
+
" return first\n"
|
|
188
|
+
"\n"
|
|
189
|
+
"def alias(first: int, **rest: int) -> int:\n"
|
|
190
|
+
" return target(first)\n"
|
|
191
|
+
)
|
|
192
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
193
|
+
assert issues == [], (
|
|
194
|
+
f"Dropping **kwargs changes behavior, not a pure alias, got: {issues!r}"
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_should_skip_test_file() -> None:
|
|
199
|
+
source = (
|
|
200
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
201
|
+
" return {part for part in content.split() if part}\n"
|
|
202
|
+
"\n"
|
|
203
|
+
"def find_bare_index_segments(content: str) -> set[str]:\n"
|
|
204
|
+
" return find_bare_path_segments(content)\n"
|
|
205
|
+
)
|
|
206
|
+
issues = check_zero_payload_function_alias(source, TEST_FILE_PATH)
|
|
207
|
+
assert issues == [], f"Test files exempt, got: {issues!r}"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def test_should_skip_config_file() -> None:
|
|
211
|
+
source = (
|
|
212
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
213
|
+
" return {part for part in content.split() if part}\n"
|
|
214
|
+
"\n"
|
|
215
|
+
"def find_bare_index_segments(content: str) -> set[str]:\n"
|
|
216
|
+
" return find_bare_path_segments(content)\n"
|
|
217
|
+
)
|
|
218
|
+
issues = check_zero_payload_function_alias(source, CONFIG_FILE_PATH)
|
|
219
|
+
assert issues == [], f"config/ files exempt, got: {issues!r}"
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def test_should_handle_syntax_error_gracefully() -> None:
|
|
223
|
+
issues = check_zero_payload_function_alias("def broken(\n", PRODUCTION_FILE_PATH)
|
|
224
|
+
assert issues == [], f"Syntax error must yield no issues, got: {issues!r}"
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def test_should_not_flag_empty_file() -> None:
|
|
228
|
+
issues = check_zero_payload_function_alias("", PRODUCTION_FILE_PATH)
|
|
229
|
+
assert issues == [], f"Empty file must not be flagged, got: {issues!r}"
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def test_should_not_flag_recursive_self_call() -> None:
|
|
233
|
+
source = (
|
|
234
|
+
"def walk(node: int) -> int:\n"
|
|
235
|
+
" return walk(node)\n"
|
|
236
|
+
)
|
|
237
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
238
|
+
assert issues == [], (
|
|
239
|
+
f"A self-call is recursion, not a zero-payload alias, got: {issues!r}"
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def test_should_flag_through_validate_content_for_hook_file() -> None:
|
|
244
|
+
source = (
|
|
245
|
+
"def find_bare_path_segments(content: str) -> set[str]:\n"
|
|
246
|
+
" return {part for part in content.split() if part}\n"
|
|
247
|
+
"\n"
|
|
248
|
+
"def find_bare_index_segments(content: str) -> set[str]:\n"
|
|
249
|
+
" return find_bare_path_segments(content)\n"
|
|
250
|
+
)
|
|
251
|
+
issues = code_rules_enforcer.validate_content(source, HOOK_INFRASTRUCTURE_PATH)
|
|
252
|
+
assert any("find_bare_index_segments" in each for each in issues), (
|
|
253
|
+
f"validate_content must surface the alias for hook files, got: {issues!r}"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def test_should_not_flag_property_decorated_forwarder() -> None:
|
|
258
|
+
source = (
|
|
259
|
+
"def compute_total(amount: int) -> int:\n"
|
|
260
|
+
" return amount * 2\n"
|
|
261
|
+
"\n"
|
|
262
|
+
"class Cart:\n"
|
|
263
|
+
" @property\n"
|
|
264
|
+
" def total(self, amount: int) -> int:\n"
|
|
265
|
+
" return compute_total(amount)\n"
|
|
266
|
+
)
|
|
267
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
268
|
+
assert issues == [], (
|
|
269
|
+
f"A @property forwarder gains attribute semantics, not a zero-payload alias, got: {issues!r}"
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def test_should_not_flag_lru_cache_decorated_forwarder() -> None:
|
|
274
|
+
source = (
|
|
275
|
+
"import functools\n"
|
|
276
|
+
"\n"
|
|
277
|
+
"def lookup(key: int) -> int:\n"
|
|
278
|
+
" return key\n"
|
|
279
|
+
"\n"
|
|
280
|
+
"@functools.lru_cache\n"
|
|
281
|
+
"def cached_lookup(key: int) -> int:\n"
|
|
282
|
+
" return lookup(key)\n"
|
|
283
|
+
)
|
|
284
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
285
|
+
assert issues == [], (
|
|
286
|
+
f"An @lru_cache forwarder adds memoization the target lacks, got: {issues!r}"
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def test_should_not_flag_forwarder_that_adds_a_default_value() -> None:
|
|
291
|
+
source = (
|
|
292
|
+
"def target(first: int, second: int) -> int:\n"
|
|
293
|
+
" return first + second\n"
|
|
294
|
+
"\n"
|
|
295
|
+
"def alias(first: int, second: int = 5) -> int:\n"
|
|
296
|
+
" return target(first, second)\n"
|
|
297
|
+
)
|
|
298
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
299
|
+
assert issues == [], (
|
|
300
|
+
f"A default value makes a call shape valid that the target rejects, got: {issues!r}"
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def test_should_flag_async_pass_through_alias() -> None:
|
|
305
|
+
source = (
|
|
306
|
+
"async def real(value: int) -> int:\n"
|
|
307
|
+
" return value\n"
|
|
308
|
+
"\n"
|
|
309
|
+
"async def alias(value: int) -> int:\n"
|
|
310
|
+
" return real(value)\n"
|
|
311
|
+
)
|
|
312
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
313
|
+
assert any("alias" in each for each in issues), (
|
|
314
|
+
f"An async pass-through alias must be flagged like its sync twin, got: {issues!r}"
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def test_should_not_flag_sync_alias_to_async_target() -> None:
|
|
319
|
+
source = (
|
|
320
|
+
"async def target(first: int) -> int:\n"
|
|
321
|
+
" return first\n"
|
|
322
|
+
"\n"
|
|
323
|
+
"def alias(first: int) -> int:\n"
|
|
324
|
+
" return target(first)\n"
|
|
325
|
+
)
|
|
326
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
327
|
+
assert issues == [], (
|
|
328
|
+
f"A sync alias to an async target returns a coroutine, changing the contract, got: {issues!r}"
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def test_should_not_flag_async_alias_to_sync_target() -> None:
|
|
333
|
+
source = (
|
|
334
|
+
"def target(first: int) -> int:\n"
|
|
335
|
+
" return first\n"
|
|
336
|
+
"\n"
|
|
337
|
+
"async def alias(first: int) -> int:\n"
|
|
338
|
+
" return target(first)\n"
|
|
339
|
+
)
|
|
340
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
341
|
+
assert issues == [], (
|
|
342
|
+
f"An async alias to a sync target changes the awaitability contract, got: {issues!r}"
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def test_should_not_flag_forwarder_whose_name_is_a_string_dispatch_target() -> None:
|
|
347
|
+
source = (
|
|
348
|
+
"from typing import Literal\n"
|
|
349
|
+
"\n"
|
|
350
|
+
"TransformName = Literal[\"verbatim\", \"near_verbatim\"]\n"
|
|
351
|
+
"\n"
|
|
352
|
+
"def strip_anthropic_refs(text: str) -> str:\n"
|
|
353
|
+
" return text.replace(\"Anthropic\", \"\")\n"
|
|
354
|
+
"\n"
|
|
355
|
+
"def near_verbatim(text: str) -> str:\n"
|
|
356
|
+
" return strip_anthropic_refs(text)\n"
|
|
357
|
+
"\n"
|
|
358
|
+
"def apply_transform(name: TransformName, text: str) -> str:\n"
|
|
359
|
+
" if name == \"near_verbatim\":\n"
|
|
360
|
+
" return near_verbatim(text)\n"
|
|
361
|
+
" return text\n"
|
|
362
|
+
)
|
|
363
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
364
|
+
assert issues == [], (
|
|
365
|
+
"A forwarder dispatched by its own name through a string literal must stay, "
|
|
366
|
+
f"got: {issues!r}"
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def test_should_not_flag_forwarder_calling_keyword_only_target_positionally() -> None:
|
|
371
|
+
source = (
|
|
372
|
+
"def target(first: int, *, second: int) -> int:\n"
|
|
373
|
+
" return first + second\n"
|
|
374
|
+
"\n"
|
|
375
|
+
"def alias(first: int, second: int) -> int:\n"
|
|
376
|
+
" return target(first, second)\n"
|
|
377
|
+
)
|
|
378
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
379
|
+
assert issues == [], (
|
|
380
|
+
"The target rejects the forwarded positional call (second is keyword-only), "
|
|
381
|
+
f"so the alias is not interchangeable with a direct call, got: {issues!r}"
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def test_should_not_flag_forwarder_whose_arity_mismatches_redefined_target() -> None:
|
|
386
|
+
source = (
|
|
387
|
+
"def target(first: int) -> int:\n"
|
|
388
|
+
" return first\n"
|
|
389
|
+
"\n"
|
|
390
|
+
"def alias(first: int) -> int:\n"
|
|
391
|
+
" return target(first)\n"
|
|
392
|
+
"\n"
|
|
393
|
+
"def target(first: int, second: int) -> int:\n"
|
|
394
|
+
" return first + second\n"
|
|
395
|
+
)
|
|
396
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
397
|
+
assert issues == [], (
|
|
398
|
+
"The live target needs two positional arguments but the forwarder passes one, "
|
|
399
|
+
f"so the forwarded call is invalid against the live target, got: {issues!r}"
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def test_should_flag_forwarder_calling_default_bearing_target_positionally() -> None:
|
|
404
|
+
source = (
|
|
405
|
+
"def target(first: int, second: int = 5) -> int:\n"
|
|
406
|
+
" return first + second\n"
|
|
407
|
+
"\n"
|
|
408
|
+
"def alias(first: int, second: int) -> int:\n"
|
|
409
|
+
" return target(first, second)\n"
|
|
410
|
+
)
|
|
411
|
+
issues = check_zero_payload_function_alias(source, PRODUCTION_FILE_PATH)
|
|
412
|
+
assert any("alias" in each for each in issues), (
|
|
413
|
+
"The target accepts the forwarded positional call, so the alias is a true "
|
|
414
|
+
f"pass-through and must be flagged, got: {issues!r}"
|
|
415
|
+
)
|