claude-dev-env 1.59.0 → 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CLAUDE.md +4 -0
  2. package/audit-rubrics/category_rubrics/category-b-selector-engine-compat.md +1 -1
  3. package/audit-rubrics/category_rubrics/category-e-dead-code.md +1 -0
  4. package/audit-rubrics/category_rubrics/category-f-silent-failures.md +1 -1
  5. package/audit-rubrics/category_rubrics/category-o-docstring-vs-impl-drift.md +1 -1
  6. package/audit-rubrics/prompts/category-b-selector-engine-compat.md +2 -2
  7. package/audit-rubrics/prompts/category-e-dead-code.md +17 -4
  8. package/audit-rubrics/prompts/category-f-silent-failures.md +1 -0
  9. package/docs/CODE_RULES.md +2 -2
  10. package/hooks/blocking/code_rules_annotations_length.py +189 -10
  11. package/hooks/blocking/code_rules_dead_module_constant.py +321 -0
  12. package/hooks/blocking/code_rules_duplicate_body.py +152 -0
  13. package/hooks/blocking/code_rules_enforcer.py +38 -15
  14. package/hooks/blocking/code_rules_orphan_css_class.py +196 -0
  15. package/hooks/blocking/code_rules_typeddict_stub.py +172 -0
  16. package/hooks/blocking/config/__init__.py +5 -0
  17. package/hooks/blocking/config/verified_commit_constants.py +118 -0
  18. package/hooks/blocking/destructive_command_blocker.py +483 -61
  19. package/hooks/blocking/test_code_rules_enforcer_annotations.py +240 -0
  20. package/hooks/blocking/test_code_rules_enforcer_cap_meta.py +1 -0
  21. package/hooks/blocking/test_code_rules_enforcer_cross_skill_duplicate.py +146 -0
  22. package/hooks/blocking/test_code_rules_enforcer_dead_module_constant.py +188 -0
  23. package/hooks/blocking/test_code_rules_enforcer_dispatch_wiring.py +82 -0
  24. package/hooks/blocking/test_code_rules_enforcer_orphan_css_class.py +196 -0
  25. package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias.py +415 -0
  26. package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias_hook_routing.py +156 -0
  27. package/hooks/blocking/test_destructive_command_blocker.py +213 -0
  28. package/hooks/blocking/test_verdict_directory_write_blocker.py +720 -0
  29. package/hooks/blocking/test_verification_verdict_store.py +490 -0
  30. package/hooks/blocking/test_verified_commit_gate.py +495 -0
  31. package/hooks/blocking/test_verified_commit_message_accuracy_blocker.py +131 -0
  32. package/hooks/blocking/test_verifier_verdict_minter.py +193 -0
  33. package/hooks/blocking/verdict_directory_write_blocker.py +667 -0
  34. package/hooks/blocking/verification_verdict_store.py +686 -0
  35. package/hooks/blocking/verified_commit_gate.py +535 -0
  36. package/hooks/blocking/verified_commit_message_accuracy_blocker.py +152 -0
  37. package/hooks/blocking/verifier_verdict_minter.py +221 -0
  38. package/hooks/diagnostic/test_hook_log_extractor.py +3 -3
  39. package/hooks/hooks.json +43 -1
  40. package/hooks/hooks_constants/blocking_check_limits.py +1 -0
  41. package/hooks/hooks_constants/code_rules_enforcer_constants.py +6 -0
  42. package/hooks/hooks_constants/dead_module_constant_constants.py +20 -0
  43. package/hooks/hooks_constants/destructive_command_segment_constants.py +15 -0
  44. package/hooks/hooks_constants/duplicate_function_body_constants.py +22 -5
  45. package/hooks/hooks_constants/orphan_css_class_constants.py +40 -0
  46. package/hooks/hooks_constants/precommit_code_rules_gate_constants.py +1 -1
  47. package/hooks/validation/mypy_validator.py +59 -7
  48. package/hooks/validation/test_mypy_validator.py +94 -0
  49. package/package.json +1 -1
  50. package/rules/file-global-constants.md +7 -1
  51. package/rules/no-cross-skill-duplicate-helpers.md +29 -0
  52. package/rules/orphan-css-class.md +23 -0
  53. package/skills/_shared/pr-loop/scripts/preflight_worktree.py +392 -0
  54. package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/preflight_constants.py +70 -0
  55. package/skills/_shared/pr-loop/scripts/test_preflight_worktree.py +263 -0
  56. package/skills/autoconverge/SKILL.md +54 -17
  57. package/skills/autoconverge/reference/closing-report.md +59 -17
  58. package/skills/autoconverge/workflow/aggregate_runs.py +371 -0
  59. package/skills/autoconverge/workflow/autoconverge_report_constants/render_report_constants.py +192 -76
  60. package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +76 -0
  61. package/skills/autoconverge/workflow/converge.contract.test.mjs +395 -206
  62. package/skills/autoconverge/workflow/converge.mjs +520 -57
  63. package/skills/autoconverge/workflow/convergence_summary.py +110 -0
  64. package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-ab1c2d3e4f5a6b7c8.jsonl +2 -0
  65. package/skills/autoconverge/workflow/fixtures/wf_run/workflows/wf_881252e6-700.json +7 -0
  66. package/skills/autoconverge/workflow/render_report.py +488 -397
  67. package/skills/autoconverge/workflow/test_aggregate_runs.py +134 -0
  68. package/skills/autoconverge/workflow/test_convergence_summary.py +132 -0
  69. package/skills/autoconverge/workflow/test_render_report.py +518 -259
  70. package/skills/pr-converge/reference/per-tick.md +28 -8
  71. package/skills/rebase/SKILL.md +2 -4
  72. package/system-prompts/software-engineer.xml +2 -6
  73. package/hooks/blocking/content_search_to_zoekt_redirector.py +0 -59
  74. package/hooks/blocking/content_search_zoekt_bash_block_reason.py +0 -25
  75. package/hooks/blocking/content_search_zoekt_block_payload.py +0 -21
  76. package/hooks/blocking/content_search_zoekt_indexed_paths.py +0 -24
  77. package/hooks/blocking/content_search_zoekt_indexed_roots_config.py +0 -131
  78. package/hooks/blocking/content_search_zoekt_redirect_guidance.py +0 -52
  79. package/hooks/blocking/test_content_search_to_zoekt_redirector_integration.py +0 -61
  80. package/hooks/blocking/test_content_search_to_zoekt_redirector_unit.py +0 -92
  81. package/hooks/blocking/test_content_search_zoekt_indexed_roots_config.py +0 -102
@@ -0,0 +1,196 @@
1
+ """Unit tests for the orphan-CSS-class check in code_rules_enforcer hook."""
2
+
3
+ import importlib.util
4
+ import pathlib
5
+ import sys
6
+ import tempfile
7
+ import textwrap
8
+ from collections.abc import Iterator
9
+ from pathlib import Path
10
+
11
+ import pytest
12
+
13
+ _HOOK_DIR = pathlib.Path(__file__).parent
14
+ if str(_HOOK_DIR) not in sys.path:
15
+ sys.path.insert(0, str(_HOOK_DIR))
16
+
17
+ hook_spec = importlib.util.spec_from_file_location(
18
+ "code_rules_orphan_css_class",
19
+ _HOOK_DIR / "code_rules_orphan_css_class.py",
20
+ )
21
+ assert hook_spec is not None
22
+ assert hook_spec.loader is not None
23
+ hook_module = importlib.util.module_from_spec(hook_spec)
24
+ hook_spec.loader.exec_module(hook_module)
25
+ check_orphan_css_classes = hook_module.check_orphan_css_classes
26
+
27
+ PRODUCTION_FILE_PATH = "packages/app/render/report.py"
28
+ TEST_FILE_PATH = "packages/app/render/test_report.py"
29
+
30
+ MARKUP_WITH_ORPHAN = (
31
+ "def render() -> str:\n"
32
+ ' style = "<style>.card { color: red; }</style>"\n'
33
+ ' body = \'<div class="card">x</div><div class="ghost">y</div>\'\n'
34
+ " return style + body\n"
35
+ )
36
+
37
+ MARKUP_ALL_DEFINED = (
38
+ "def render() -> str:\n"
39
+ ' style = "<style>.card { color: red; } .row { margin: 0; }</style>"\n'
40
+ ' body = \'<div class="card"><span class="row">x</span></div>\'\n'
41
+ " return style + body\n"
42
+ )
43
+
44
+
45
+ def test_should_flag_class_with_no_matching_selector() -> None:
46
+ issues = check_orphan_css_classes(MARKUP_WITH_ORPHAN, PRODUCTION_FILE_PATH)
47
+ assert any("'ghost'" in each_issue for each_issue in issues), (
48
+ f"Expected 'ghost' flagged as orphan, got: {issues}"
49
+ )
50
+
51
+
52
+ def test_should_not_flag_class_with_matching_selector() -> None:
53
+ issues = check_orphan_css_classes(MARKUP_WITH_ORPHAN, PRODUCTION_FILE_PATH)
54
+ assert not any("'card'" in each_issue for each_issue in issues), (
55
+ f"'card' has a .card selector and must not flag, got: {issues}"
56
+ )
57
+
58
+
59
+ def test_should_not_flag_when_every_class_is_defined() -> None:
60
+ issues = check_orphan_css_classes(MARKUP_ALL_DEFINED, PRODUCTION_FILE_PATH)
61
+ assert issues == [], f"Every class is defined; expected no issues, got: {issues}"
62
+
63
+
64
+ def test_should_flag_each_class_in_a_multi_class_attribute() -> None:
65
+ content = (
66
+ "def render() -> str:\n"
67
+ ' style = "<style>.pf { padding: 0; }</style>"\n'
68
+ " body = '<div class=\"pf problem\">x</div>'\n"
69
+ " return style + body\n"
70
+ )
71
+ issues = check_orphan_css_classes(content, PRODUCTION_FILE_PATH)
72
+ assert any("'problem'" in each_issue for each_issue in issues), (
73
+ f"Second class 'problem' in the attribute must flag, got: {issues}"
74
+ )
75
+ assert not any("'pf'" in each_issue for each_issue in issues), (
76
+ f"First class 'pf' has a selector and must not flag, got: {issues}"
77
+ )
78
+
79
+
80
+ def test_should_not_flag_when_no_style_block_present() -> None:
81
+ content = "def render() -> str:\n return '<div class=\"card\">x</div>'\n"
82
+ issues = check_orphan_css_classes(content, PRODUCTION_FILE_PATH)
83
+ assert issues == [], (
84
+ f"No <style> source nearby; the stylesheet lives outside the scan, got: {issues}"
85
+ )
86
+
87
+
88
+ def test_should_not_flag_when_no_class_attribute_present() -> None:
89
+ content = (
90
+ 'def render() -> str:\n return "<style>.card { color: red; }</style><div>x</div>"\n'
91
+ )
92
+ issues = check_orphan_css_classes(content, PRODUCTION_FILE_PATH)
93
+ assert issues == [], f"No class attribute in markup; got: {issues}"
94
+
95
+
96
+ def test_should_skip_test_files() -> None:
97
+ issues = check_orphan_css_classes(MARKUP_WITH_ORPHAN, TEST_FILE_PATH)
98
+ assert issues == [], f"Test files are exempt; got: {issues}"
99
+
100
+
101
+ def test_should_include_line_number_and_class_name() -> None:
102
+ issues = check_orphan_css_classes(MARKUP_WITH_ORPHAN, PRODUCTION_FILE_PATH)
103
+ orphan_issue = next(each for each in issues if "'ghost'" in each)
104
+ assert "Line 3" in orphan_issue, (
105
+ f"Orphan 'ghost' sits on line 3 of the markup; got: {orphan_issue}"
106
+ )
107
+
108
+
109
+ def test_should_report_each_orphan_class_once() -> None:
110
+ content = (
111
+ "def render() -> str:\n"
112
+ ' style = "<style>.card { color: red; }</style>"\n'
113
+ " a = '<div class=\"ghost\">x</div>'\n"
114
+ " b = '<div class=\"ghost\">y</div>'\n"
115
+ " return style + a + b\n"
116
+ )
117
+ issues = check_orphan_css_classes(content, PRODUCTION_FILE_PATH)
118
+ ghost_issues = [each for each in issues if "'ghost'" in each]
119
+ assert len(ghost_issues) == 1, f"A repeated orphan class reports once; got: {ghost_issues}"
120
+
121
+
122
+ def test_should_handle_syntax_error_gracefully() -> None:
123
+ content = "def broken(\n this is not python\n"
124
+ issues = check_orphan_css_classes(content, PRODUCTION_FILE_PATH)
125
+ assert issues == [], f"A syntax error yields no issues; got: {issues}"
126
+
127
+
128
+ _SIBLING_MARKUP_SOURCE = textwrap.dedent(
129
+ """\
130
+ from report_constants import HTML_STYLE_BLOCK
131
+
132
+
133
+ def render() -> str:
134
+ body = (
135
+ '<details class="appendix">'
136
+ '<div class="appendix-body">x</div></details>'
137
+ )
138
+ return HTML_STYLE_BLOCK + body
139
+ """
140
+ )
141
+
142
+
143
+ @pytest.fixture
144
+ def production_render_package() -> Iterator[Path]:
145
+ """Yield a neutrally named package directory for the markup and constants modules.
146
+
147
+ pytest's ``tmp_path`` carries the test function name, so any path under it
148
+ holds a ``test_`` segment that the enforcer's ``is_test_file`` predicate
149
+ matches and exempts. A package created under the default ``tempfile`` prefix
150
+ keeps that segment out of the path, so the cross-module orphan-class check
151
+ runs against the markup module as production code.
152
+
153
+ Yields:
154
+ A freshly created package directory, removed when the test finishes.
155
+ """
156
+ with tempfile.TemporaryDirectory() as base_directory:
157
+ package_directory = Path(base_directory) / "render"
158
+ package_directory.mkdir()
159
+ yield package_directory
160
+
161
+
162
+ def test_should_resolve_selectors_from_a_sibling_module(
163
+ production_render_package: Path,
164
+ ) -> None:
165
+ constants_module = production_render_package / "report_constants.py"
166
+ constants_module.write_text(
167
+ 'HTML_STYLE_BLOCK = "<style>.appendix { margin: 0; }'
168
+ ' .appendix-body { padding: 0; }</style>"\n',
169
+ encoding="utf-8",
170
+ )
171
+ markup_module = production_render_package / "report.py"
172
+ markup_module.write_text(_SIBLING_MARKUP_SOURCE, encoding="utf-8")
173
+ issues = check_orphan_css_classes(_SIBLING_MARKUP_SOURCE, str(markup_module))
174
+ assert issues == [], (
175
+ f"A sibling module defines every selector; expected no issues, got: {issues}"
176
+ )
177
+
178
+
179
+ def test_should_flag_orphan_even_when_a_sibling_defines_other_selectors(
180
+ production_render_package: Path,
181
+ ) -> None:
182
+ constants_module = production_render_package / "report_constants.py"
183
+ constants_module.write_text(
184
+ 'HTML_STYLE_BLOCK = "<style>.appendix { margin: 0; }</style>"\n',
185
+ encoding="utf-8",
186
+ )
187
+ markup_module = production_render_package / "report.py"
188
+ markup_module.write_text(_SIBLING_MARKUP_SOURCE, encoding="utf-8")
189
+ issues = check_orphan_css_classes(_SIBLING_MARKUP_SOURCE, str(markup_module))
190
+ assert any("'appendix-body'" in each_issue for each_issue in issues), (
191
+ f"'appendix-body' has no selector in any sibling; must flag, got: {issues}"
192
+ )
193
+ assert not any(
194
+ "'appendix'" in each_issue and "appendix-body" not in each_issue
195
+ for each_issue in issues
196
+ ), f"'appendix' is defined in the sibling and must not flag, 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
+ )