claude-dev-env 1.69.0 → 1.69.2
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/hooks/blocking/code_rules_dead_config_field.py +284 -50
- package/hooks/blocking/code_rules_enforcer.py +5 -0
- package/hooks/blocking/code_rules_shared.py +47 -0
- package/hooks/blocking/tdd_enforcer.py +7 -2
- package/hooks/blocking/test_code_rules_enforcer_dead_config_field.py +336 -3
- package/hooks/blocking/test_code_rules_enforcer_ephemeral.py +383 -0
- package/hooks/blocking/test_tdd_enforcer.py +106 -1
- package/hooks/hooks_constants/code_rules_enforcer_constants.py +6 -0
- package/package.json +1 -1
|
@@ -223,19 +223,260 @@ def test_does_not_flag_field_used_only_as_replace_keyword(neutral_root: Path) ->
|
|
|
223
223
|
)
|
|
224
224
|
|
|
225
225
|
|
|
226
|
-
def
|
|
226
|
+
def test_flags_field_set_only_by_constructor_keyword_and_read_nowhere(
|
|
227
|
+
neutral_root: Path,
|
|
228
|
+
) -> None:
|
|
229
|
+
"""A field set ONLY by a ``*Config`` constructor keyword, read nowhere, is dead.
|
|
230
|
+
|
|
231
|
+
A constructor keyword writes the field; it is not a read. When ``debug_port``
|
|
232
|
+
is set by ``ThemeUpdateConfig(debug_port=1)`` and read through no config
|
|
233
|
+
instance anywhere in production, tuning it has no effect, so it is flagged as
|
|
234
|
+
dead config (CODE_RULES §9.8).
|
|
235
|
+
"""
|
|
227
236
|
consumer_body = (
|
|
228
237
|
"from os_update_workflow.config import ThemeUpdateConfig\n"
|
|
229
238
|
"\n"
|
|
230
239
|
"def build() -> ThemeUpdateConfig:\n"
|
|
231
|
-
"
|
|
240
|
+
" configuration = ThemeUpdateConfig(portal_url='x', debug_port=1, timeout_seconds=99)\n"
|
|
241
|
+
" print(configuration.portal_url)\n"
|
|
242
|
+
" print(configuration.timeout_seconds)\n"
|
|
243
|
+
" return configuration\n"
|
|
232
244
|
)
|
|
233
245
|
config_path = _build_config_package(
|
|
234
246
|
neutral_root / "workflow", THEME_UPDATE_CONFIG_BODY, consumer_body
|
|
235
247
|
)
|
|
236
248
|
issues = _check(THEME_UPDATE_CONFIG_BODY, str(config_path))
|
|
249
|
+
assert any("'debug_port'" in each_issue for each_issue in issues), (
|
|
250
|
+
f"Field set only by constructor keyword and read nowhere must be flagged, got: {issues}"
|
|
251
|
+
)
|
|
252
|
+
assert not any(
|
|
253
|
+
"'portal_url'" in each_issue or "'timeout_seconds'" in each_issue for each_issue in issues
|
|
254
|
+
), f"Fields read through the config instance must not be flagged, got: {issues}"
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def test_qualified_config_constructor_keyword_does_not_clear_field(
|
|
258
|
+
neutral_root: Path,
|
|
259
|
+
) -> None:
|
|
260
|
+
"""A qualified ``module.ThemeUpdateConfig(field=value)`` keyword is a write, not a read.
|
|
261
|
+
|
|
262
|
+
The constructor callee may be a qualified attribute (``config_module.ThemeUpdateConfig``)
|
|
263
|
+
rather than a bare name. Its keyword still writes the field, so a field set only
|
|
264
|
+
this way and read through no config instance is flagged dead.
|
|
265
|
+
"""
|
|
266
|
+
consumer_body = (
|
|
267
|
+
"import os_update_workflow.config as config_module\n"
|
|
268
|
+
"\n"
|
|
269
|
+
"def build() -> config_module.ThemeUpdateConfig:\n"
|
|
270
|
+
" configuration = config_module.ThemeUpdateConfig(\n"
|
|
271
|
+
" portal_url='x', debug_port=1, timeout_seconds=99\n"
|
|
272
|
+
" )\n"
|
|
273
|
+
" print(configuration.portal_url)\n"
|
|
274
|
+
" print(configuration.timeout_seconds)\n"
|
|
275
|
+
" return configuration\n"
|
|
276
|
+
)
|
|
277
|
+
config_path = _build_config_package(
|
|
278
|
+
neutral_root / "workflow", THEME_UPDATE_CONFIG_BODY, consumer_body
|
|
279
|
+
)
|
|
280
|
+
issues = _check(THEME_UPDATE_CONFIG_BODY, str(config_path))
|
|
281
|
+
assert any("'debug_port'" in each_issue for each_issue in issues), (
|
|
282
|
+
f"A qualified config constructor keyword is a write, so debug_port is flagged, got: {issues}"
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def test_does_not_flag_field_set_by_constructor_keyword_and_read_elsewhere(
|
|
287
|
+
neutral_root: Path,
|
|
288
|
+
) -> None:
|
|
289
|
+
"""A field set by a constructor keyword AND read via attribute elsewhere is live.
|
|
290
|
+
|
|
291
|
+
The constructor keyword does not clear the field, but a genuine attribute read
|
|
292
|
+
of the same field in another module does, so the field is not flagged.
|
|
293
|
+
"""
|
|
294
|
+
builder_body = (
|
|
295
|
+
"from os_update_workflow.config import ThemeUpdateConfig\n"
|
|
296
|
+
"\n"
|
|
297
|
+
"def build() -> ThemeUpdateConfig:\n"
|
|
298
|
+
" return ThemeUpdateConfig(portal_url='x', debug_port=1, timeout_seconds=99)\n"
|
|
299
|
+
)
|
|
300
|
+
config_path = _build_config_package(
|
|
301
|
+
neutral_root / "workflow", THEME_UPDATE_CONFIG_BODY, builder_body
|
|
302
|
+
)
|
|
303
|
+
reader_body = (
|
|
304
|
+
"from os_update_workflow.config import ThemeUpdateConfig\n"
|
|
305
|
+
"\n"
|
|
306
|
+
"def connect(configuration: ThemeUpdateConfig) -> int:\n"
|
|
307
|
+
" return configuration.debug_port\n"
|
|
308
|
+
)
|
|
309
|
+
(config_path.parent.parent / "reader.py").write_text(reader_body, encoding="utf-8")
|
|
310
|
+
issues = _check(THEME_UPDATE_CONFIG_BODY, str(config_path))
|
|
311
|
+
assert not any("'debug_port'" in each_issue for each_issue in issues), (
|
|
312
|
+
f"An attribute read in another module keeps debug_port live, got: {issues}"
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def test_flags_field_set_by_default_and_constructor_keyword_only(
|
|
317
|
+
neutral_root: Path,
|
|
318
|
+
) -> None:
|
|
319
|
+
"""The PR #317 dead-config shape: field set by config default + constructor keyword only.
|
|
320
|
+
|
|
321
|
+
``AppInfoConfig.sound_upload_max_attempts: int = submission_timing.sound_upload_max_attempts``
|
|
322
|
+
sets the field from a same-named attribute on another object inside the config
|
|
323
|
+
body, and the orchestrator sets ``sound_upload_timeout_ms`` by a constructor
|
|
324
|
+
keyword. Neither field is read through any config instance. The default-value
|
|
325
|
+
read inside the config body and the constructor keyword are both writes, so
|
|
326
|
+
both fields are flagged dead.
|
|
327
|
+
|
|
328
|
+
Residual limitation: when a consumer module's constructor VALUE expression
|
|
329
|
+
itself reads a same-named attribute on a different object
|
|
330
|
+
(``AppInfoConfig(field=other.field)``), the object-blind attribute-read
|
|
331
|
+
collector counts ``field`` as read and the field escapes. This test keeps the
|
|
332
|
+
constructor value a literal so the keyword-write and default-write exclusions
|
|
333
|
+
are exercised without that foreign-attribute leak.
|
|
334
|
+
"""
|
|
335
|
+
config_body = (
|
|
336
|
+
"from dataclasses import dataclass\n"
|
|
337
|
+
"import submission_timing_module as submission_timing\n"
|
|
338
|
+
"\n"
|
|
339
|
+
"@dataclass(frozen=True)\n"
|
|
340
|
+
"class AppInfoConfig:\n"
|
|
341
|
+
" sound_upload_timeout_ms: int = submission_timing.sound_upload_timeout_ms\n"
|
|
342
|
+
" sound_upload_max_attempts: int = submission_timing.sound_upload_max_attempts\n"
|
|
343
|
+
)
|
|
344
|
+
workflow_directory = neutral_root / "workflow"
|
|
345
|
+
config_package = workflow_directory / "os_update_workflow"
|
|
346
|
+
config_package.mkdir(parents=True)
|
|
347
|
+
(config_package / "__init__.py").write_text("", encoding="utf-8")
|
|
348
|
+
config_path = config_package / "config.py"
|
|
349
|
+
config_path.write_text(config_body, encoding="utf-8")
|
|
350
|
+
orchestrator_body = (
|
|
351
|
+
"from os_update_workflow.config import AppInfoConfig\n"
|
|
352
|
+
"\n"
|
|
353
|
+
"def build() -> AppInfoConfig:\n"
|
|
354
|
+
" config = AppInfoConfig(sound_upload_timeout_ms=60000)\n"
|
|
355
|
+
" return config\n"
|
|
356
|
+
)
|
|
357
|
+
(workflow_directory / "orchestrator.py").write_text(orchestrator_body, encoding="utf-8")
|
|
358
|
+
issues = _check(config_body, str(config_path))
|
|
359
|
+
assert any("'sound_upload_timeout_ms'" in each_issue for each_issue in issues), (
|
|
360
|
+
f"Field set by constructor keyword and read nowhere must be flagged, got: {issues}"
|
|
361
|
+
)
|
|
362
|
+
assert any("'sound_upload_max_attempts'" in each_issue for each_issue in issues), (
|
|
363
|
+
f"Field set by config default only and read nowhere must be flagged, got: {issues}"
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def test_does_not_flag_config_default_field_read_through_instance(
|
|
368
|
+
neutral_root: Path,
|
|
369
|
+
) -> None:
|
|
370
|
+
"""A field whose default reads a foreign attribute but is read through the instance is live.
|
|
371
|
+
|
|
372
|
+
The default-value exclusion only drops the self-referential read inside the
|
|
373
|
+
config body; a genuine ``config.sound_upload_timeout_ms`` read in production
|
|
374
|
+
keeps the field live.
|
|
375
|
+
"""
|
|
376
|
+
config_body = (
|
|
377
|
+
"from dataclasses import dataclass\n"
|
|
378
|
+
"import submission_timing_module as submission_timing\n"
|
|
379
|
+
"\n"
|
|
380
|
+
"@dataclass(frozen=True)\n"
|
|
381
|
+
"class AppInfoConfig:\n"
|
|
382
|
+
" sound_upload_timeout_ms: int = submission_timing.sound_upload_timeout_ms\n"
|
|
383
|
+
)
|
|
384
|
+
workflow_directory = neutral_root / "workflow"
|
|
385
|
+
config_package = workflow_directory / "os_update_workflow"
|
|
386
|
+
config_package.mkdir(parents=True)
|
|
387
|
+
(config_package / "__init__.py").write_text("", encoding="utf-8")
|
|
388
|
+
config_path = config_package / "config.py"
|
|
389
|
+
config_path.write_text(config_body, encoding="utf-8")
|
|
390
|
+
processor_body = (
|
|
391
|
+
"from os_update_workflow.config import AppInfoConfig\n"
|
|
392
|
+
"\n"
|
|
393
|
+
"def wait(config: AppInfoConfig) -> int:\n"
|
|
394
|
+
" return config.sound_upload_timeout_ms\n"
|
|
395
|
+
)
|
|
396
|
+
(workflow_directory / "processor.py").write_text(processor_body, encoding="utf-8")
|
|
397
|
+
issues = _check(config_body, str(config_path))
|
|
237
398
|
assert issues == [], (
|
|
238
|
-
f"
|
|
399
|
+
f"A genuine config-instance read keeps the field live, got: {issues}"
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def test_config_default_sourcing_differently_named_field_keeps_it_live(
|
|
404
|
+
neutral_root: Path,
|
|
405
|
+
) -> None:
|
|
406
|
+
"""A default that sources a DIFFERENTLY-named field on another config keeps it live.
|
|
407
|
+
|
|
408
|
+
``AppConfig.timeout_ms: int = DEFAULT_TIMING.base_timeout`` reads
|
|
409
|
+
``base_timeout`` on another config object inside the class body. The
|
|
410
|
+
default-value exclusion drops only the self-referential read whose attribute
|
|
411
|
+
name equals the field being defined; a differently-named attribute read is a
|
|
412
|
+
genuine consumer of ``base_timeout``, so it stays live and is not flagged.
|
|
413
|
+
"""
|
|
414
|
+
config_body = (
|
|
415
|
+
"from dataclasses import dataclass\n"
|
|
416
|
+
"\n"
|
|
417
|
+
"@dataclass(frozen=True)\n"
|
|
418
|
+
"class TimingConfig:\n"
|
|
419
|
+
" base_timeout: int\n"
|
|
420
|
+
" poll_interval: int\n"
|
|
421
|
+
"\n"
|
|
422
|
+
"DEFAULT_TIMING = TimingConfig(base_timeout=30, poll_interval=5)\n"
|
|
423
|
+
"\n"
|
|
424
|
+
"@dataclass(frozen=True)\n"
|
|
425
|
+
"class AppConfig:\n"
|
|
426
|
+
" timeout_ms: int = DEFAULT_TIMING.base_timeout\n"
|
|
427
|
+
" poll_interval: int = DEFAULT_TIMING.poll_interval\n"
|
|
428
|
+
)
|
|
429
|
+
workflow_directory = neutral_root / "workflow"
|
|
430
|
+
config_package = workflow_directory / "os_update_workflow"
|
|
431
|
+
config_package.mkdir(parents=True)
|
|
432
|
+
(config_package / "__init__.py").write_text("", encoding="utf-8")
|
|
433
|
+
config_path = config_package / "config.py"
|
|
434
|
+
config_path.write_text(config_body, encoding="utf-8")
|
|
435
|
+
consumer_body = (
|
|
436
|
+
"from os_update_workflow.config import AppConfig\n"
|
|
437
|
+
"\n"
|
|
438
|
+
"def run(app_config: AppConfig) -> int:\n"
|
|
439
|
+
" return app_config.timeout_ms + app_config.poll_interval\n"
|
|
440
|
+
)
|
|
441
|
+
(workflow_directory / "runner.py").write_text(consumer_body, encoding="utf-8")
|
|
442
|
+
issues = _check(config_body, str(config_path))
|
|
443
|
+
assert not any("'base_timeout'" in each_issue for each_issue in issues), (
|
|
444
|
+
f"A default sourcing a differently-named field must keep it live, got: {issues}"
|
|
445
|
+
)
|
|
446
|
+
assert not any("'poll_interval'" in each_issue for each_issue in issues), (
|
|
447
|
+
f"poll_interval is read both in the default and the consumer, got: {issues}"
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def test_self_referential_default_still_excludes_only_the_self_read(
|
|
452
|
+
neutral_root: Path,
|
|
453
|
+
) -> None:
|
|
454
|
+
"""The self-referential default read is still excluded after narrowing.
|
|
455
|
+
|
|
456
|
+
``sound_upload_timeout_ms: int = submission_timing.sound_upload_timeout_ms``
|
|
457
|
+
reads an attribute whose name equals the field being defined, so it is still
|
|
458
|
+
excluded; when that field is read by no module it stays flagged dead.
|
|
459
|
+
"""
|
|
460
|
+
config_body = (
|
|
461
|
+
"from dataclasses import dataclass\n"
|
|
462
|
+
"import submission_timing_module as submission_timing\n"
|
|
463
|
+
"\n"
|
|
464
|
+
"@dataclass(frozen=True)\n"
|
|
465
|
+
"class AppInfoConfig:\n"
|
|
466
|
+
" sound_upload_timeout_ms: int = submission_timing.sound_upload_timeout_ms\n"
|
|
467
|
+
)
|
|
468
|
+
workflow_directory = neutral_root / "workflow"
|
|
469
|
+
config_package = workflow_directory / "os_update_workflow"
|
|
470
|
+
config_package.mkdir(parents=True)
|
|
471
|
+
(config_package / "__init__.py").write_text("", encoding="utf-8")
|
|
472
|
+
config_path = config_package / "config.py"
|
|
473
|
+
config_path.write_text(config_body, encoding="utf-8")
|
|
474
|
+
(workflow_directory / "runner.py").write_text(
|
|
475
|
+
"def noop() -> None:\n pass\n", encoding="utf-8"
|
|
476
|
+
)
|
|
477
|
+
issues = _check(config_body, str(config_path))
|
|
478
|
+
assert any("'sound_upload_timeout_ms'" in each_issue for each_issue in issues), (
|
|
479
|
+
f"Self-referential default read is excluded, so the field stays flagged, got: {issues}"
|
|
239
480
|
)
|
|
240
481
|
|
|
241
482
|
|
|
@@ -416,6 +657,98 @@ def test_dataclasses_qualified_replace_call_suppresses_so_no_field_flagged(
|
|
|
416
657
|
)
|
|
417
658
|
|
|
418
659
|
|
|
660
|
+
def test_aliased_replace_read_keeps_field_live_despite_constructor_keyword(
|
|
661
|
+
neutral_root: Path,
|
|
662
|
+
) -> None:
|
|
663
|
+
"""An aliased ``replace`` keyword read survives a same-module constructor keyword.
|
|
664
|
+
|
|
665
|
+
A module constructs ``ThemeUpdateConfig(debug_port=1)`` (a write) and also reads
|
|
666
|
+
the field through an aliased ``dataclasses.replace`` —
|
|
667
|
+
``from dataclasses import replace as rep; rep(cfg, debug_port=2)``. The alias is
|
|
668
|
+
not the bare ``replace`` name, so the whole-instance reflective suppression does
|
|
669
|
+
not fire and the ``rep`` keyword stays a genuine field read. The constructor
|
|
670
|
+
keyword exclusion is scoped per-call, so the constructor's ``debug_port`` keyword
|
|
671
|
+
does not strip the ``rep`` keyword read and the field stays live.
|
|
672
|
+
"""
|
|
673
|
+
consumer_body = (
|
|
674
|
+
"from dataclasses import replace as rep\n"
|
|
675
|
+
"from os_update_workflow.config import ThemeUpdateConfig\n"
|
|
676
|
+
"\n"
|
|
677
|
+
"def build_then_repoint() -> ThemeUpdateConfig:\n"
|
|
678
|
+
" configuration = ThemeUpdateConfig(portal_url='x', debug_port=1, timeout_seconds=99)\n"
|
|
679
|
+
" return rep(configuration, debug_port=2)\n"
|
|
680
|
+
)
|
|
681
|
+
config_path = _build_config_package(
|
|
682
|
+
neutral_root / "workflow", THEME_UPDATE_CONFIG_BODY, consumer_body
|
|
683
|
+
)
|
|
684
|
+
issues = _check(THEME_UPDATE_CONFIG_BODY, str(config_path))
|
|
685
|
+
assert not any("'debug_port'" in each_issue for each_issue in issues), (
|
|
686
|
+
f"Aliased replace keyword read must keep debug_port live despite a"
|
|
687
|
+
f" same-module constructor keyword, got: {issues}"
|
|
688
|
+
)
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def test_factory_function_ending_in_config_keeps_field_live(
|
|
692
|
+
neutral_root: Path,
|
|
693
|
+
) -> None:
|
|
694
|
+
"""A keyword to a factory FUNCTION ending in ``Config`` is a read, not a write.
|
|
695
|
+
|
|
696
|
+
``getThemeConfig(debug_port=1)`` calls a factory function, not a ``*Config``
|
|
697
|
+
dataclass constructor. The keyword passes a value into the function, so it
|
|
698
|
+
counts as a field read. The constructor-keyword exclusion fires only for a
|
|
699
|
+
callee that names a known ``*Config`` dataclass defined under the scan root, so
|
|
700
|
+
a factory function whose name merely ends in ``Config`` does not strip the
|
|
701
|
+
field.
|
|
702
|
+
"""
|
|
703
|
+
consumer_body = (
|
|
704
|
+
"from os_update_workflow.config import ThemeUpdateConfig\n"
|
|
705
|
+
"\n"
|
|
706
|
+
"def getThemeConfig(portal_url: str, debug_port: int) -> ThemeUpdateConfig:\n"
|
|
707
|
+
" return ThemeUpdateConfig(\n"
|
|
708
|
+
" portal_url=portal_url, debug_port=debug_port, timeout_seconds=30\n"
|
|
709
|
+
" )\n"
|
|
710
|
+
"\n"
|
|
711
|
+
"def run() -> ThemeUpdateConfig:\n"
|
|
712
|
+
" print('x')\n"
|
|
713
|
+
" return getThemeConfig(portal_url='x', debug_port=1)\n"
|
|
714
|
+
)
|
|
715
|
+
config_path = _build_config_package(
|
|
716
|
+
neutral_root / "workflow", THEME_UPDATE_CONFIG_BODY, consumer_body
|
|
717
|
+
)
|
|
718
|
+
issues = _check(THEME_UPDATE_CONFIG_BODY, str(config_path))
|
|
719
|
+
assert not any("'debug_port'" in each_issue for each_issue in issues), (
|
|
720
|
+
f"A keyword passed to a factory function ending in Config must keep the"
|
|
721
|
+
f" field live, got: {issues}"
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
def test_dead_config_field_module_has_no_collection_parameter_naming_violation() -> None:
|
|
726
|
+
"""The hook module's own source must pass the collection-parameter naming check.
|
|
727
|
+
|
|
728
|
+
The cross-module dead-config-field check passes a ``set[str]`` of config class
|
|
729
|
+
names through several helpers; every such collection parameter must carry the
|
|
730
|
+
``all_`` prefix (CODE_RULES §5). Run the real collection-prefix check over this
|
|
731
|
+
module's on-disk source so a regression that drops the prefix fails here.
|
|
732
|
+
"""
|
|
733
|
+
collection_naming_path = (
|
|
734
|
+
Path(__file__).resolve().parent / "code_rules_naming_collection.py"
|
|
735
|
+
)
|
|
736
|
+
naming_specification = importlib.util.spec_from_file_location(
|
|
737
|
+
"code_rules_naming_collection", collection_naming_path
|
|
738
|
+
)
|
|
739
|
+
assert naming_specification is not None and naming_specification.loader is not None
|
|
740
|
+
code_rules_naming_collection = importlib.util.module_from_spec(naming_specification)
|
|
741
|
+
naming_specification.loader.exec_module(code_rules_naming_collection)
|
|
742
|
+
module_path = Path(__file__).resolve().parent / "code_rules_dead_config_field.py"
|
|
743
|
+
module_source = module_path.read_text(encoding="utf-8")
|
|
744
|
+
issues = code_rules_naming_collection.check_collection_prefix(
|
|
745
|
+
module_source, str(module_path)
|
|
746
|
+
)
|
|
747
|
+
assert not any("Collection parameter" in each_issue for each_issue in issues), (
|
|
748
|
+
f"dead-config-field module has a collection-parameter naming violation: {issues}"
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
|
|
419
752
|
def test_validate_content_dispatch_runs_dead_config_field_check(neutral_root: Path) -> None:
|
|
420
753
|
workflow_directory = neutral_root / "workflow"
|
|
421
754
|
config_package = workflow_directory / "os_update_workflow"
|