claude-dev-env 1.77.0 → 1.79.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 (46) hide show
  1. package/audit-rubrics/category_rubrics/category-k-codebase-conflicts.md +1 -0
  2. package/bin/install.mjs +1 -0
  3. package/bin/install.test.mjs +3 -2
  4. package/hooks/blocking/CLAUDE.md +5 -2
  5. package/hooks/blocking/code_rules_dead_module_constant.py +215 -59
  6. package/hooks/blocking/code_rules_dead_split_branch.py +225 -0
  7. package/hooks/blocking/code_rules_docstrings.py +951 -6
  8. package/hooks/blocking/code_rules_enforcer.py +64 -0
  9. package/hooks/blocking/code_rules_naming_collection.py +76 -1
  10. package/hooks/blocking/code_rules_paired_test.py +517 -0
  11. package/hooks/blocking/code_rules_string_magic.py +71 -1
  12. package/hooks/blocking/code_rules_test_assertions.py +159 -1
  13. package/hooks/blocking/convergence_gate_blocker.py +24 -15
  14. package/hooks/blocking/env_var_table_code_drift_blocker.py +475 -0
  15. package/hooks/blocking/package_inventory_stale_blocker.py +54 -15
  16. package/hooks/blocking/test_code_rules_enforcer_dead_module_constant.py +89 -2
  17. package/hooks/blocking/test_code_rules_enforcer_dead_split_branch.py +105 -0
  18. package/hooks/blocking/test_code_rules_enforcer_docstring_field_runmode_outcome.py +129 -0
  19. package/hooks/blocking/test_code_rules_enforcer_docstring_length_constant_superlative.py +198 -0
  20. package/hooks/blocking/test_code_rules_enforcer_docstring_mark_glyph_enumeration.py +262 -0
  21. package/hooks/blocking/test_code_rules_enforcer_docstring_no_network.py +115 -0
  22. package/hooks/blocking/test_code_rules_enforcer_docstring_raises_largezipfile.py +226 -0
  23. package/hooks/blocking/test_code_rules_enforcer_docstring_unreferenced_param.py +160 -0
  24. package/hooks/blocking/test_code_rules_enforcer_module_docstring_data_schema_scope.py +82 -0
  25. package/hooks/blocking/test_code_rules_enforcer_paired_test.py +339 -0
  26. package/hooks/blocking/test_code_rules_enforcer_polarity_name_contradiction.py +76 -0
  27. package/hooks/blocking/test_code_rules_enforcer_vacuous_cleanup_assertion.py +132 -0
  28. package/hooks/blocking/test_code_rules_enforcer_whitespace_indentation_magic.py +74 -0
  29. package/hooks/blocking/test_convergence_gate_blocker.py +71 -0
  30. package/hooks/blocking/test_env_var_table_code_drift_blocker.py +94 -0
  31. package/hooks/blocking/test_package_inventory_stale_blocker.py +46 -0
  32. package/hooks/blocking/test_pre_tool_use_dispatcher.py +7 -7
  33. package/hooks/hooks_constants/CLAUDE.md +2 -0
  34. package/hooks/hooks_constants/blocking_check_limits.py +102 -0
  35. package/hooks/hooks_constants/code_rules_enforcer_constants.py +28 -0
  36. package/hooks/hooks_constants/env_var_table_code_drift_constants.py +64 -0
  37. package/hooks/hooks_constants/package_inventory_stale_blocker_constants.py +20 -9
  38. package/hooks/hooks_constants/paired_test_coverage_constants.py +35 -0
  39. package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +4 -0
  40. package/package.json +1 -1
  41. package/rules/CLAUDE.md +2 -0
  42. package/rules/docstring-prose-matches-implementation.md +56 -53
  43. package/rules/env-var-table-code-drift.md +24 -0
  44. package/rules/file-global-constants.md +2 -2
  45. package/rules/package-inventory-stale-entry.md +4 -4
  46. package/rules/paired-test-coverage.md +35 -0
@@ -0,0 +1,262 @@
1
+ """Tests for check_docstring_punctuation_mark_enumeration_coverage — O6 glyph drift.
2
+
3
+ A module defines a tuple of punctuation-mark glyphs (an em-dash, a spaced
4
+ double-hyphen, a semicolon) and a docstring enumerates those marks by their
5
+ English names while omitting one the tuple holds. The prose names two marks but
6
+ the detection set holds three, so a reader who trusts the enumeration believes a
7
+ mark that is active never triggers the check. This is the deterministic
8
+ glyph-prose slice of Category O6 docstring-prose-vs-implementation drift, the
9
+ companion to check_docstring_tuple_enumeration_match for glyph members named in
10
+ prose rather than identifier members named in inline code.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import importlib.util
16
+ from pathlib import Path
17
+ from types import ModuleType
18
+
19
+
20
+ def _load_enforcer_module() -> ModuleType:
21
+ module_path = Path(__file__).parent / "code_rules_enforcer.py"
22
+ spec = importlib.util.spec_from_file_location("code_rules_enforcer", module_path)
23
+ assert spec is not None
24
+ assert spec.loader is not None
25
+ module = importlib.util.module_from_spec(spec)
26
+ spec.loader.exec_module(module)
27
+ return module
28
+
29
+
30
+ code_rules_enforcer = _load_enforcer_module()
31
+
32
+
33
+ def check_docstring_punctuation_mark_enumeration_coverage(
34
+ content: str, file_path: str
35
+ ) -> list[str]:
36
+ return code_rules_enforcer.check_docstring_punctuation_mark_enumeration_coverage(
37
+ content, file_path
38
+ )
39
+
40
+
41
+ def validate_content(content: str, file_path: str, old_content: str) -> list[str]:
42
+ return code_rules_enforcer.validate_content(content, file_path, old_content)
43
+
44
+
45
+ PRODUCTION_FILE_PATH = "/project/src/runon_detector.py"
46
+ TEST_FILE_PATH = "/project/src/test_runon_detector.py"
47
+ HOOK_INFRASTRUCTURE_PATH = "/home/user/.claude/hooks/blocking/code_rules_docstrings.py"
48
+
49
+
50
+ def _drifted_two_marks_named_function() -> str:
51
+ return (
52
+ 'ALL_RUNON_JOINER_MARKERS = ("—", " -- ", ";")\n'
53
+ "\n"
54
+ "\n"
55
+ "def _sentence_carries_joiner(sentence_text: str) -> bool:\n"
56
+ ' """Report whether the sentence chains clauses with a joiner mark.\n'
57
+ "\n"
58
+ " The run-on marks are an em-dash or a semicolon, the two glyphs that\n"
59
+ " fuse independent clauses into one dense sentence.\n"
60
+ ' """\n'
61
+ " return any(each in sentence_text for each in ALL_RUNON_JOINER_MARKERS)\n"
62
+ )
63
+
64
+
65
+ def _complete_three_marks_named_function() -> str:
66
+ return (
67
+ 'ALL_RUNON_JOINER_MARKERS = ("—", " -- ", ";")\n'
68
+ "\n"
69
+ "\n"
70
+ "def _sentence_carries_joiner(sentence_text: str) -> bool:\n"
71
+ ' """Report whether the sentence chains clauses with a joiner mark.\n'
72
+ "\n"
73
+ " The run-on marks are an em-dash, a spaced double-hyphen, or a\n"
74
+ " semicolon, the glyphs that fuse independent clauses into one\n"
75
+ " dense sentence.\n"
76
+ ' """\n'
77
+ " return any(each in sentence_text for each in ALL_RUNON_JOINER_MARKERS)\n"
78
+ )
79
+
80
+
81
+ def _single_mark_named_function() -> str:
82
+ return (
83
+ 'ALL_RUNON_JOINER_MARKERS = ("—", " -- ", ";")\n'
84
+ "\n"
85
+ "\n"
86
+ "def _sentence_carries_joiner(sentence_text: str) -> bool:\n"
87
+ ' """Report whether the sentence chains clauses with an em-dash.\n'
88
+ "\n"
89
+ " The em-dash is the glyph that fuses clauses into one sentence.\n"
90
+ ' """\n'
91
+ " return any(each in sentence_text for each in ALL_RUNON_JOINER_MARKERS)\n"
92
+ )
93
+
94
+
95
+ def _non_glyph_tuple_function() -> str:
96
+ return (
97
+ 'ALL_OUTCOME_LABELS = ("alpha", "beta", "gamma")\n'
98
+ "\n"
99
+ "\n"
100
+ "def describe_outcome(label_text: str) -> bool:\n"
101
+ ' """Report the outcome named by an em-dash or a semicolon label.\n'
102
+ "\n"
103
+ " The labels carry a semicolon between the segments of each name.\n"
104
+ ' """\n'
105
+ " return label_text in ALL_OUTCOME_LABELS\n"
106
+ )
107
+
108
+
109
+ def test_should_flag_omitted_double_hyphen_mark() -> None:
110
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
111
+ _drifted_two_marks_named_function(), PRODUCTION_FILE_PATH
112
+ )
113
+ assert any("--" in each for each in issues), (
114
+ f"The docstring naming em-dash and semicolon but omitting the double-hyphen "
115
+ f"that ALL_RUNON_JOINER_MARKERS holds must be flagged, got: {issues!r}"
116
+ )
117
+
118
+
119
+ def test_should_report_category_o6_in_the_message() -> None:
120
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
121
+ _drifted_two_marks_named_function(), PRODUCTION_FILE_PATH
122
+ )
123
+ assert any("O6" in each for each in issues), (
124
+ f"Expected the Category O6 label in the message, got: {issues!r}"
125
+ )
126
+
127
+
128
+ def test_should_not_flag_complete_enumeration() -> None:
129
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
130
+ _complete_three_marks_named_function(), PRODUCTION_FILE_PATH
131
+ )
132
+ assert issues == [], f"A docstring naming all three marks must not be flagged, got: {issues!r}"
133
+
134
+
135
+ def test_should_not_flag_single_named_mark_below_threshold() -> None:
136
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
137
+ _single_mark_named_function(), PRODUCTION_FILE_PATH
138
+ )
139
+ assert issues == [], f"A docstring naming a single mark is not an enumeration, got: {issues!r}"
140
+
141
+
142
+ def test_should_not_flag_non_glyph_tuple() -> None:
143
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
144
+ _non_glyph_tuple_function(), PRODUCTION_FILE_PATH
145
+ )
146
+ assert issues == [], f"A tuple of non-punctuation members must not be flagged, got: {issues!r}"
147
+
148
+
149
+ def test_should_flag_on_hook_infrastructure_where_the_drift_lives() -> None:
150
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
151
+ _drifted_two_marks_named_function(), HOOK_INFRASTRUCTURE_PATH
152
+ )
153
+ assert any("--" in each for each in issues), (
154
+ f"The drift lives in hook modules, so the gate must run there, got: {issues!r}"
155
+ )
156
+
157
+
158
+ def test_should_skip_test_file() -> None:
159
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
160
+ _drifted_two_marks_named_function(), TEST_FILE_PATH
161
+ )
162
+ assert issues == [], f"Test files exempt, got: {issues!r}"
163
+
164
+
165
+ def test_should_handle_syntax_error_gracefully() -> None:
166
+ unparseable_naming_marks = 'def fetch(\n """An em-dash and a semicolon."""\n'
167
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
168
+ unparseable_naming_marks, PRODUCTION_FILE_PATH
169
+ )
170
+ assert issues == [], f"Syntax error must yield no issues, got: {issues!r}"
171
+
172
+
173
+ def _drifted_annotated_tuple_function() -> str:
174
+ return (
175
+ 'ALL_RUNON_JOINER_MARKERS: tuple[str, ...] = ("—", " -- ", ";")\n'
176
+ "\n"
177
+ "\n"
178
+ "def _sentence_carries_joiner(sentence_text: str) -> bool:\n"
179
+ ' """Report whether the sentence chains clauses with a joiner mark.\n'
180
+ "\n"
181
+ " The run-on marks are an em-dash or a semicolon.\n"
182
+ ' """\n'
183
+ " return any(each in sentence_text for each in ALL_RUNON_JOINER_MARKERS)\n"
184
+ )
185
+
186
+
187
+ def test_should_flag_annotated_same_module_tuple_drift() -> None:
188
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
189
+ _drifted_annotated_tuple_function(), PRODUCTION_FILE_PATH
190
+ )
191
+ assert any("--" in each for each in issues), (
192
+ f"An annotated marker tuple in the same module must be checked, got: {issues!r}"
193
+ )
194
+
195
+
196
+ def test_should_flag_drift_against_imported_companion_tuple(tmp_path: Path) -> None:
197
+ companion_directory = tmp_path / "marks_package"
198
+ companion_directory.mkdir()
199
+ (companion_directory / "joiner_marks.py").write_text(
200
+ 'ALL_RUNON_JOINER_MARKERS: tuple[str, ...] = ("—", " -- ", ";")\n',
201
+ encoding="utf-8",
202
+ )
203
+ consumer_directory = tmp_path / "blocking"
204
+ consumer_directory.mkdir()
205
+ consumer_source = (
206
+ "from marks_package.joiner_marks import ALL_RUNON_JOINER_MARKERS\n"
207
+ "\n"
208
+ "\n"
209
+ "def _sentence_carries_joiner(sentence_text: str) -> bool:\n"
210
+ ' """Report whether the sentence chains clauses with a joiner mark.\n'
211
+ "\n"
212
+ " The run-on marks are an em-dash or a semicolon, the two glyphs that\n"
213
+ " fuse independent clauses into one dense sentence.\n"
214
+ ' """\n'
215
+ " return any(each in sentence_text for each in ALL_RUNON_JOINER_MARKERS)\n"
216
+ )
217
+ consumer_path = consumer_directory / "runon_consumer.py"
218
+ consumer_path.write_text(consumer_source, encoding="utf-8")
219
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
220
+ consumer_source, str(consumer_path)
221
+ )
222
+ assert any("--" in each for each in issues), (
223
+ f"A docstring drifting from an imported companion marker tuple must be "
224
+ f"flagged so the split-file shape is caught, got: {issues!r}"
225
+ )
226
+
227
+
228
+ def test_should_not_resolve_companion_when_no_marks_named(tmp_path: Path) -> None:
229
+ companion_directory = tmp_path / "marks_package"
230
+ companion_directory.mkdir()
231
+ (companion_directory / "joiner_marks.py").write_text(
232
+ 'ALL_RUNON_JOINER_MARKERS: tuple[str, ...] = ("—", " -- ", ";")\n',
233
+ encoding="utf-8",
234
+ )
235
+ consumer_directory = tmp_path / "blocking"
236
+ consumer_directory.mkdir()
237
+ consumer_source = (
238
+ "from marks_package.joiner_marks import ALL_RUNON_JOINER_MARKERS\n"
239
+ "\n"
240
+ "\n"
241
+ "def _sentence_carries_joiner(sentence_text: str) -> bool:\n"
242
+ ' """Report whether the sentence carries any joiner glyph."""\n'
243
+ " return any(each in sentence_text for each in ALL_RUNON_JOINER_MARKERS)\n"
244
+ )
245
+ consumer_path = consumer_directory / "runon_consumer.py"
246
+ consumer_path.write_text(consumer_source, encoding="utf-8")
247
+ issues = check_docstring_punctuation_mark_enumeration_coverage(
248
+ consumer_source, str(consumer_path)
249
+ )
250
+ assert issues == [], (
251
+ f"A docstring naming no marks must not be flagged, got: {issues!r}"
252
+ )
253
+
254
+
255
+ def test_validate_content_surfaces_mark_glyph_drift() -> None:
256
+ issues = validate_content(
257
+ _drifted_two_marks_named_function(), PRODUCTION_FILE_PATH, old_content=""
258
+ )
259
+ matching_issues = [each for each in issues if "--" in each and "O6" in each]
260
+ assert matching_issues, (
261
+ f"Expected validate_content to surface the O6 mark-glyph drift, got: {issues!r}"
262
+ )
@@ -0,0 +1,115 @@
1
+ """Tests for check_docstring_no_network_claim_with_metadata_access — Category O6.
2
+
3
+ A docstring promising a code path returns "without touching the network" drifts
4
+ when the body calls a path-metadata method (``is_file``, ``stat``, ...): on a
5
+ network share each metadata call is a round-trip over the wire, so the no-network
6
+ claim is false. This is the deterministic slice of Category O6 (docstring prose
7
+ versus implementation drift) for a no-network claim.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import importlib.util
13
+ from pathlib import Path
14
+ from types import ModuleType
15
+
16
+
17
+ def _load_enforcer_module() -> ModuleType:
18
+ module_path = Path(__file__).parent / "code_rules_enforcer.py"
19
+ spec = importlib.util.spec_from_file_location("code_rules_enforcer", module_path)
20
+ assert spec is not None
21
+ assert spec.loader is not None
22
+ module = importlib.util.module_from_spec(spec)
23
+ spec.loader.exec_module(module)
24
+ return module
25
+
26
+
27
+ code_rules_enforcer = _load_enforcer_module()
28
+
29
+
30
+ def check_docstring_no_network_claim(content: str, file_path: str) -> list[str]:
31
+ return code_rules_enforcer.check_docstring_no_network_claim_with_metadata_access(
32
+ content, file_path
33
+ )
34
+
35
+
36
+ PRODUCTION_FILE_PATH = "/project/shared_utils/bws/secret_fetch.py"
37
+ TEST_FILE_PATH = "/project/shared_utils/bws/tests/test_secret_fetch.py"
38
+ HOOK_INFRASTRUCTURE_PATH = "/home/user/.claude/hooks/blocking/example.py"
39
+
40
+
41
+ def test_flags_no_network_claim_with_is_file_and_stat() -> None:
42
+ content = (
43
+ "def _ensure_local_bws_cache() -> str:\n"
44
+ ' """Return the local cache path, repopulating when stale.\n'
45
+ "\n"
46
+ " An existing cache is returned without touching the network; a\n"
47
+ " missing or size-mismatched cache is repopulated from the bundled\n"
48
+ " executable.\n"
49
+ ' """\n'
50
+ " if BUNDLED_BWS_EXECUTABLE_PATH.is_file():\n"
51
+ " bundled_size = BUNDLED_BWS_EXECUTABLE_PATH.stat().st_size\n"
52
+ " return str(LOCAL_BWS_CACHE_PATH)\n"
53
+ " return str(LOCAL_BWS_CACHE_PATH)\n"
54
+ )
55
+ issues = check_docstring_no_network_claim(content, PRODUCTION_FILE_PATH)
56
+ assert len(issues) == 1
57
+ assert "_ensure_local_bws_cache" in issues[0]
58
+ assert "without touching the network" in issues[0]
59
+
60
+
61
+ def test_flags_no_network_access_phrase_with_exists() -> None:
62
+ content = (
63
+ "def read_warm_cache(cache_path) -> str:\n"
64
+ ' """Serve the warm cache with no network access."""\n'
65
+ " if cache_path.exists():\n"
66
+ " return cache_path.read_text()\n"
67
+ " return ''\n"
68
+ )
69
+ assert len(check_docstring_no_network_claim(content, PRODUCTION_FILE_PATH)) == 1
70
+
71
+
72
+ def test_passes_when_claim_present_but_no_metadata_access() -> None:
73
+ content = (
74
+ "def read_warm_cache(cache_path) -> str:\n"
75
+ ' """Serve the warm cache without touching the network."""\n'
76
+ " return cache_path.read_text()\n"
77
+ )
78
+ assert check_docstring_no_network_claim(content, PRODUCTION_FILE_PATH) == []
79
+
80
+
81
+ def test_passes_when_metadata_access_but_no_network_claim() -> None:
82
+ content = (
83
+ "def _ensure_local_bws_cache(share_path) -> str:\n"
84
+ ' """Return the local cache path, repopulating when stale.\n'
85
+ "\n"
86
+ " The bundled share is stat-checked on every call to validate the\n"
87
+ " cache against the bundled executable size.\n"
88
+ ' """\n'
89
+ " if share_path.is_file():\n"
90
+ " return str(share_path)\n"
91
+ " return ''\n"
92
+ )
93
+ assert check_docstring_no_network_claim(content, PRODUCTION_FILE_PATH) == []
94
+
95
+
96
+ def test_test_files_are_exempt() -> None:
97
+ content = (
98
+ "def _ensure_local_bws_cache(share_path) -> str:\n"
99
+ ' """Return the cache without touching the network."""\n'
100
+ " if share_path.is_file():\n"
101
+ " return str(share_path)\n"
102
+ " return ''\n"
103
+ )
104
+ assert check_docstring_no_network_claim(content, TEST_FILE_PATH) == []
105
+
106
+
107
+ def test_hook_infrastructure_is_exempt() -> None:
108
+ content = (
109
+ "def _ensure_local_bws_cache(share_path) -> str:\n"
110
+ ' """Return the cache without touching the network."""\n'
111
+ " if share_path.is_file():\n"
112
+ " return str(share_path)\n"
113
+ " return ''\n"
114
+ )
115
+ assert check_docstring_no_network_claim(content, HOOK_INFRASTRUCTURE_PATH) == []
@@ -0,0 +1,226 @@
1
+ """Tests for check_docstring_raises_unraisable_largezipfile — O6 Raises drift.
2
+
3
+ A function's docstring Raises clause lists ``zipfile.LargeZipFile`` while the
4
+ function opens its ``zipfile.ZipFile`` writer with ZIP64 permitted (``allowZip64``
5
+ left at its default of True). The stdlib raises ``LargeZipFile`` only when an
6
+ entry needs ZIP64 AND ``allowZip64`` is False; with ZIP64 permitted the writer
7
+ transparently uses it and never raises. The Raises entry therefore documents an
8
+ exception the body cannot produce — the deterministic slice of Category O6
9
+ docstring-prose-vs-implementation drift where a writer-opened-with-default-ZIP64
10
+ disagrees with a LargeZipFile Raises clause.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import importlib.util
16
+ from pathlib import Path
17
+ from types import ModuleType
18
+
19
+
20
+ def _load_enforcer_module() -> ModuleType:
21
+ module_path = Path(__file__).parent / "code_rules_enforcer.py"
22
+ spec = importlib.util.spec_from_file_location("code_rules_enforcer", module_path)
23
+ assert spec is not None
24
+ assert spec.loader is not None
25
+ module = importlib.util.module_from_spec(spec)
26
+ spec.loader.exec_module(module)
27
+ return module
28
+
29
+
30
+ code_rules_enforcer = _load_enforcer_module()
31
+
32
+
33
+ def check_docstring_raises_unraisable_largezipfile(content: str, file_path: str) -> list[str]:
34
+ return code_rules_enforcer.check_docstring_raises_unraisable_largezipfile(content, file_path)
35
+
36
+
37
+ def validate_content(content: str, file_path: str, old_content: str) -> list[str]:
38
+ return code_rules_enforcer.validate_content(content, file_path, old_content)
39
+
40
+
41
+ PRODUCTION_FILE_PATH = "/project/src/stp_archive.py"
42
+ TEST_FILE_PATH = "/project/src/test_stp_archive.py"
43
+ HOOK_INFRASTRUCTURE_PATH = "/home/user/.claude/hooks/blocking/example.py"
44
+
45
+
46
+ def _default_zip64_writer_documenting_largezipfile() -> str:
47
+ return (
48
+ "import zipfile\n"
49
+ "from pathlib import Path\n"
50
+ "\n"
51
+ "def rewrite_stp_member_atomically(stp_path: Path, member_bytes: bytes) -> None:\n"
52
+ ' """Rewrite one member of an STP in place via a temp sibling.\n'
53
+ "\n"
54
+ " Raises:\n"
55
+ " OSError: When the streaming write or the rename fails.\n"
56
+ " zipfile.BadZipFile: When the source archive is not a valid ZIP.\n"
57
+ " zipfile.LargeZipFile: When an entry needs ZIP64 the writer forbids.\n"
58
+ ' """\n'
59
+ " with zipfile.ZipFile(stp_path, 'r') as source_archive:\n"
60
+ " with zipfile.ZipFile(stp_path, 'w', zipfile.ZIP_DEFLATED) as target_archive:\n"
61
+ " target_archive.writestr('IM/a.png', member_bytes)\n"
62
+ )
63
+
64
+
65
+ def test_should_flag_largezipfile_over_a_default_zip64_writer() -> None:
66
+ issues = check_docstring_raises_unraisable_largezipfile(
67
+ _default_zip64_writer_documenting_largezipfile(), PRODUCTION_FILE_PATH
68
+ )
69
+ assert any("LargeZipFile" in each for each in issues), (
70
+ f"A LargeZipFile Raises entry over a default-ZIP64 writer must flag, got: {issues!r}"
71
+ )
72
+
73
+
74
+ def test_should_report_category_o6_in_the_message() -> None:
75
+ issues = check_docstring_raises_unraisable_largezipfile(
76
+ _default_zip64_writer_documenting_largezipfile(), PRODUCTION_FILE_PATH
77
+ )
78
+ assert any("O6" in each for each in issues), (
79
+ f"Expected the Category O6 label in the message, got: {issues!r}"
80
+ )
81
+
82
+
83
+ def test_should_not_flag_when_writer_forbids_zip64_via_keyword() -> None:
84
+ source = (
85
+ "import zipfile\n"
86
+ "from pathlib import Path\n"
87
+ "\n"
88
+ "def rewrite(stp_path: Path, member_bytes: bytes) -> None:\n"
89
+ ' """Rewrite one member of an STP, forbidding ZIP64.\n'
90
+ "\n"
91
+ " Raises:\n"
92
+ " zipfile.LargeZipFile: When an entry needs ZIP64 the writer forbids.\n"
93
+ ' """\n'
94
+ " with zipfile.ZipFile(stp_path, 'w', allowZip64=False) as target_archive:\n"
95
+ " target_archive.writestr('IM/a.png', member_bytes)\n"
96
+ )
97
+ issues = check_docstring_raises_unraisable_largezipfile(source, PRODUCTION_FILE_PATH)
98
+ assert issues == [], (
99
+ f"A writer that forbids ZIP64 can raise LargeZipFile, so the clause is valid, got: {issues!r}"
100
+ )
101
+
102
+
103
+ def test_should_not_flag_when_writer_forbids_zip64_positionally() -> None:
104
+ source = (
105
+ "import zipfile\n"
106
+ "from pathlib import Path\n"
107
+ "\n"
108
+ "def rewrite(stp_path: Path, member_bytes: bytes) -> None:\n"
109
+ ' """Rewrite one member of an STP, forbidding ZIP64.\n'
110
+ "\n"
111
+ " Raises:\n"
112
+ " zipfile.LargeZipFile: When an entry needs ZIP64 the writer forbids.\n"
113
+ ' """\n'
114
+ " with zipfile.ZipFile(stp_path, 'w', zipfile.ZIP_DEFLATED, False) as target_archive:\n"
115
+ " target_archive.writestr('IM/a.png', member_bytes)\n"
116
+ )
117
+ issues = check_docstring_raises_unraisable_largezipfile(source, PRODUCTION_FILE_PATH)
118
+ assert issues == [], f"A positional allowZip64=False keeps the clause valid, got: {issues!r}"
119
+
120
+
121
+ def test_should_not_flag_when_function_opens_no_zip_writer() -> None:
122
+ source = (
123
+ "import zipfile\n"
124
+ "from pathlib import Path\n"
125
+ "\n"
126
+ "def patch_via_helper(stp_path: Path, member_bytes: bytes) -> None:\n"
127
+ ' """Patch one member through a helper writer.\n'
128
+ "\n"
129
+ " Raises:\n"
130
+ " zipfile.LargeZipFile: When the helper writer forbids ZIP64.\n"
131
+ ' """\n'
132
+ " write_member(stp_path, member_bytes)\n"
133
+ )
134
+ issues = check_docstring_raises_unraisable_largezipfile(source, PRODUCTION_FILE_PATH)
135
+ assert issues == [], (
136
+ f"With no visible writer the exception may propagate from a callee, got: {issues!r}"
137
+ )
138
+
139
+
140
+ def test_should_not_flag_read_only_open() -> None:
141
+ source = (
142
+ "import zipfile\n"
143
+ "from pathlib import Path\n"
144
+ "\n"
145
+ "def read_member(stp_path: Path) -> bytes:\n"
146
+ ' """Read one member of an STP.\n'
147
+ "\n"
148
+ " Raises:\n"
149
+ " zipfile.LargeZipFile: When an entry needs ZIP64 the writer forbids.\n"
150
+ ' """\n'
151
+ " with zipfile.ZipFile(stp_path) as source_archive:\n"
152
+ " return source_archive.read('IM/a.png')\n"
153
+ )
154
+ issues = check_docstring_raises_unraisable_largezipfile(source, PRODUCTION_FILE_PATH)
155
+ assert issues == [], (
156
+ f"A read-only open has no write-mode writer, so it is left alone, got: {issues!r}"
157
+ )
158
+
159
+
160
+ def test_should_not_flag_when_raises_omits_largezipfile() -> None:
161
+ source = (
162
+ "import zipfile\n"
163
+ "from pathlib import Path\n"
164
+ "\n"
165
+ "def rewrite(stp_path: Path, member_bytes: bytes) -> None:\n"
166
+ ' """Rewrite one member of an STP in place.\n'
167
+ "\n"
168
+ " Raises:\n"
169
+ " OSError: When the streaming write or the rename fails.\n"
170
+ ' """\n'
171
+ " with zipfile.ZipFile(stp_path, 'w', zipfile.ZIP_DEFLATED) as target_archive:\n"
172
+ " target_archive.writestr('IM/a.png', member_bytes)\n"
173
+ )
174
+ issues = check_docstring_raises_unraisable_largezipfile(source, PRODUCTION_FILE_PATH)
175
+ assert issues == [], f"A Raises clause without LargeZipFile must not flag, got: {issues!r}"
176
+
177
+
178
+ def test_should_flag_when_mode_passed_by_keyword() -> None:
179
+ source = (
180
+ "import zipfile\n"
181
+ "from pathlib import Path\n"
182
+ "\n"
183
+ "def rewrite(stp_path: Path, member_bytes: bytes) -> None:\n"
184
+ ' """Rewrite one member of an STP in place.\n'
185
+ "\n"
186
+ " Raises:\n"
187
+ " zipfile.LargeZipFile: When an entry needs ZIP64 the writer forbids.\n"
188
+ ' """\n'
189
+ " with zipfile.ZipFile(stp_path, mode='w') as target_archive:\n"
190
+ " target_archive.writestr('IM/a.png', member_bytes)\n"
191
+ )
192
+ issues = check_docstring_raises_unraisable_largezipfile(source, PRODUCTION_FILE_PATH)
193
+ assert any("LargeZipFile" in each for each in issues), (
194
+ f"A keyword mode='w' writer with default ZIP64 must flag, got: {issues!r}"
195
+ )
196
+
197
+
198
+ def test_should_skip_test_file() -> None:
199
+ issues = check_docstring_raises_unraisable_largezipfile(
200
+ _default_zip64_writer_documenting_largezipfile(), TEST_FILE_PATH
201
+ )
202
+ assert issues == [], f"Test files exempt, got: {issues!r}"
203
+
204
+
205
+ def test_should_skip_hook_infrastructure() -> None:
206
+ issues = check_docstring_raises_unraisable_largezipfile(
207
+ _default_zip64_writer_documenting_largezipfile(), HOOK_INFRASTRUCTURE_PATH
208
+ )
209
+ assert issues == [], f"Hook infrastructure exempt, got: {issues!r}"
210
+
211
+
212
+ def test_should_handle_syntax_error_gracefully() -> None:
213
+ issues = check_docstring_raises_unraisable_largezipfile("def rewrite(\n", PRODUCTION_FILE_PATH)
214
+ assert issues == [], f"Syntax error must yield no issues, got: {issues!r}"
215
+
216
+
217
+ def test_validate_content_surfaces_largezipfile_drift() -> None:
218
+ issues = validate_content(
219
+ _default_zip64_writer_documenting_largezipfile(),
220
+ PRODUCTION_FILE_PATH,
221
+ old_content="",
222
+ )
223
+ matching_issues = [each for each in issues if "LargeZipFile" in each and "O6" in each]
224
+ assert matching_issues, (
225
+ f"Expected validate_content to surface the O6 LargeZipFile drift, got: {issues!r}"
226
+ )