codmap 0.0.29__tar.gz → 0.0.30__tar.gz

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 (164) hide show
  1. {codmap-0.0.29 → codmap-0.0.30}/PKG-INFO +4 -3
  2. {codmap-0.0.29 → codmap-0.0.30}/README.md +3 -2
  3. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/attrflow.py +121 -0
  4. {codmap-0.0.29 → codmap-0.0.30}/codemap/model.py +7 -1
  5. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/review.py +112 -15
  6. {codmap-0.0.29 → codmap-0.0.30}/codmap.egg-info/PKG-INFO +4 -3
  7. {codmap-0.0.29 → codmap-0.0.30}/codmap.egg-info/SOURCES.txt +1 -0
  8. {codmap-0.0.29 → codmap-0.0.30}/pyproject.toml +1 -1
  9. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m15_review.py +4 -2
  10. codmap-0.0.30/tests/test_r1c82_review_changed_lines.py +163 -0
  11. {codmap-0.0.29 → codmap-0.0.30}/LICENSE +0 -0
  12. {codmap-0.0.29 → codmap-0.0.30}/codemap/__init__.py +0 -0
  13. {codmap-0.0.29 → codmap-0.0.30}/codemap/apidiff.py +0 -0
  14. {codmap-0.0.29 → codmap-0.0.30}/codemap/arch.py +0 -0
  15. {codmap-0.0.29 → codmap-0.0.30}/codemap/cli.py +0 -0
  16. {codmap-0.0.29 → codmap-0.0.30}/codemap/diagnostics.py +0 -0
  17. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/__init__.py +0 -0
  18. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/behavior.py +0 -0
  19. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/dataflow.py +0 -0
  20. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/dispatch.py +0 -0
  21. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/griffe_extractor.py +0 -0
  22. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/gsource.py +0 -0
  23. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/probe.py +0 -0
  24. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/roots.py +0 -0
  25. {codmap-0.0.29 → codmap-0.0.30}/codemap/extract/union.py +0 -0
  26. {codmap-0.0.29 → codmap-0.0.30}/codemap/freshness.py +0 -0
  27. {codmap-0.0.29 → codmap-0.0.30}/codemap/incremental.py +0 -0
  28. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/__init__.py +0 -0
  29. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/base.py +0 -0
  30. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/cocoindex.py +0 -0
  31. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/gate.py +0 -0
  32. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/gitnexus.py +0 -0
  33. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/registry.py +0 -0
  34. {codmap-0.0.29 → codmap-0.0.30}/codemap/integrations/transport.py +0 -0
  35. {codmap-0.0.29 → codmap-0.0.30}/codemap/provenance.py +0 -0
  36. {codmap-0.0.29 → codmap-0.0.30}/codemap/query.py +0 -0
  37. {codmap-0.0.29 → codmap-0.0.30}/codemap/scope.py +0 -0
  38. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/__init__.py +0 -0
  39. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/_scip_pb2.py +0 -0
  40. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/api_surface.py +0 -0
  41. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/apidiff.py +0 -0
  42. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/architecture.py +0 -0
  43. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/audit.py +0 -0
  44. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/check.py +0 -0
  45. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/ctags.py +0 -0
  46. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/currency.py +0 -0
  47. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/impact.py +0 -0
  48. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/limits.py +0 -0
  49. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/livingdocs.py +0 -0
  50. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/mcp_server.py +0 -0
  51. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/mermaid.py +0 -0
  52. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/pack.py +0 -0
  53. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/rag.py +0 -0
  54. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/scip.py +0 -0
  55. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/semantic.py +0 -0
  56. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/server.py +0 -0
  57. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/session.py +0 -0
  58. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/subsystems.py +0 -0
  59. {codmap-0.0.29 → codmap-0.0.30}/codemap/serve/vault.py +0 -0
  60. {codmap-0.0.29 → codmap-0.0.30}/codemap/store.py +0 -0
  61. {codmap-0.0.29 → codmap-0.0.30}/codemap/tomlio.py +0 -0
  62. {codmap-0.0.29 → codmap-0.0.30}/codemap/watch.py +0 -0
  63. {codmap-0.0.29 → codmap-0.0.30}/codmap.egg-info/dependency_links.txt +0 -0
  64. {codmap-0.0.29 → codmap-0.0.30}/codmap.egg-info/entry_points.txt +0 -0
  65. {codmap-0.0.29 → codmap-0.0.30}/codmap.egg-info/requires.txt +0 -0
  66. {codmap-0.0.29 → codmap-0.0.30}/codmap.egg-info/top_level.txt +0 -0
  67. {codmap-0.0.29 → codmap-0.0.30}/setup.cfg +0 -0
  68. {codmap-0.0.29 → codmap-0.0.30}/tests/test_epistemic.py +0 -0
  69. {codmap-0.0.29 → codmap-0.0.30}/tests/test_gitnexus_router.py +0 -0
  70. {codmap-0.0.29 → codmap-0.0.30}/tests/test_impact_depth.py +0 -0
  71. {codmap-0.0.29 → codmap-0.0.30}/tests/test_integrations.py +0 -0
  72. {codmap-0.0.29 → codmap-0.0.30}/tests/test_issue3_serve_freshness.py +0 -0
  73. {codmap-0.0.29 → codmap-0.0.30}/tests/test_livingdocs.py +0 -0
  74. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m0_api_surface.py +0 -0
  75. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m11_argcontract.py +0 -0
  76. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m12_dataflow.py +0 -0
  77. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m16_architecture.py +0 -0
  78. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m17_mcp.py +0 -0
  79. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m18_freshness.py +0 -0
  80. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m1_5_semantics.py +0 -0
  81. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m1_query.py +0 -0
  82. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m2_views.py +0 -0
  83. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m32_watch.py +0 -0
  84. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m3_serve.py +0 -0
  85. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m4_behavior.py +0 -0
  86. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m5_deep.py +0 -0
  87. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m6_repo_scope.py +0 -0
  88. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m7_dispatch.py +0 -0
  89. {codmap-0.0.29 → codmap-0.0.30}/tests/test_m9_family.py +0 -0
  90. {codmap-0.0.29 → codmap-0.0.30}/tests/test_pack_honesty.py +0 -0
  91. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  92. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c13_grep_vs_graph.py +0 -0
  93. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c16_semantic.py +0 -0
  94. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c20_attribute_edges.py +0 -0
  95. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c21_flat_layout.py +0 -0
  96. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c22_source_visible_refs.py +0 -0
  97. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c23_hard_python.py +0 -0
  98. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c24_test_mapping.py +0 -0
  99. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c25_provenance.py +0 -0
  100. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c26_deep_union.py +0 -0
  101. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c27_config_honesty.py +0 -0
  102. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c28_limit_envelope.py +0 -0
  103. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c29_lazy_imports.py +0 -0
  104. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c2_ctags.py +0 -0
  105. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c30_local_import_calls.py +0 -0
  106. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c30f1_reexport_calls.py +0 -0
  107. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c30f2_check_scope.py +0 -0
  108. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c31_path_origin.py +0 -0
  109. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c32_report_json.py +0 -0
  110. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c33_query_signature.py +0 -0
  111. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c34_signature_kinds.py +0 -0
  112. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c35_contract_location.py +0 -0
  113. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c36_target_resolution.py +0 -0
  114. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c37_rule_mutation.py +0 -0
  115. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c38_tool_drift.py +0 -0
  116. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c39_edge_resolution.py +0 -0
  117. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c3_arch_contract.py +0 -0
  118. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c3_dogfood.py +0 -0
  119. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c40_flow_reach.py +0 -0
  120. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c41_scope_membership.py +0 -0
  121. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c42_deep_tier_stability.py +0 -0
  122. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c43_incremental_splice.py +0 -0
  123. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c44_absent_answers.py +0 -0
  124. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c45_repeat_union.py +0 -0
  125. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c46_shadowed_definitions.py +0 -0
  126. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c47_incremental_resample.py +0 -0
  127. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c48_type_checking_imports.py +0 -0
  128. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c49_type_only_cycles.py +0 -0
  129. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c4_complexity.py +0 -0
  130. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c50_flow_entry_points.py +0 -0
  131. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c53_narrowing_declared.py +0 -0
  132. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c54_deterministic_rendering.py +0 -0
  133. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c55_override_grade.py +0 -0
  134. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c56_stub_files.py +0 -0
  135. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c57_facade_package.py +0 -0
  136. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c58_cycle_tangles.py +0 -0
  137. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c59_completeness_drop.py +0 -0
  138. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c5_apidiff.py +0 -0
  139. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c60_nested_definitions.py +0 -0
  140. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c62_phantom_rules.py +0 -0
  141. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c63_answer_format.py +0 -0
  142. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c64_dependency_probe.py +0 -0
  143. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c66_pack_direction.py +0 -0
  144. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c68_dotted_imports.py +0 -0
  145. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c69_contract_validation.py +0 -0
  146. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c6_pack.py +0 -0
  147. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c70_check_graph_currency.py +0 -0
  148. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  149. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  150. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c73_cli_version.py +0 -0
  151. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c74_call_site_conservation.py +0 -0
  152. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c75_reexported_class_calls.py +0 -0
  153. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c76_contract_table_typo.py +0 -0
  154. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c77_gate_probe_battery.py +0 -0
  155. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c78_forbidden_chains.py +0 -0
  156. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c7_edge_vocab.py +0 -0
  157. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c80_tests_through_helpers.py +0 -0
  158. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  159. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c84_missing_roots.py +0 -0
  160. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c8_deadcode.py +0 -0
  161. {codmap-0.0.29 → codmap-0.0.30}/tests/test_r1c9_incremental.py +0 -0
  162. {codmap-0.0.29 → codmap-0.0.30}/tests/test_scip_export.py +0 -0
  163. {codmap-0.0.29 → codmap-0.0.30}/tests/test_scope.py +0 -0
  164. {codmap-0.0.29 → codmap-0.0.30}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.29
3
+ Version: 0.0.30
4
4
  Summary: Static analyzer that turns a package's source into a queryable code graph.
5
5
  Author-email: kogriv <kogriv@gmail.com>
6
6
  License-Expression: MIT
@@ -44,7 +44,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
44
44
 
45
45
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
46
46
 
47
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1207 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1220 tests with no failures on
48
48
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
49
49
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
50
50
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -222,7 +222,8 @@ codemap serve --graph graph.json --watch
222
222
  (Ca/Ce/instability), god-objects & call-hubs, per-function complexity (cyclomatic / MI)
223
223
  blended with structural coupling.
224
224
  - **Impact / blast radius** — who uses X, across the whole repo (core + tests + docs).
225
- - **Change review** — a diff → the symbols it touches, their callers, signature-change surface,
225
+ - **Change review** — a diff → the symbols its changed lines touch (context lines and comments
226
+ between definitions are not changes), their callers or readers, signature-change surface,
226
227
  touched columns, cross-root consumers, risk rank.
227
228
  - **Dispatch seams** — registry/factory families and the Protocol each impl satisfies.
228
229
  - **Dataflow** — producers/consumers of a string-keyed DataFrame column.
@@ -8,7 +8,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
8
8
 
9
9
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
10
10
 
11
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1207 tests with no failures on
11
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1220 tests with no failures on
12
12
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
13
13
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
14
14
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -186,7 +186,8 @@ codemap serve --graph graph.json --watch
186
186
  (Ca/Ce/instability), god-objects & call-hubs, per-function complexity (cyclomatic / MI)
187
187
  blended with structural coupling.
188
188
  - **Impact / blast radius** — who uses X, across the whole repo (core + tests + docs).
189
- - **Change review** — a diff → the symbols it touches, their callers, signature-change surface,
189
+ - **Change review** — a diff → the symbols its changed lines touch (context lines and comments
190
+ between definitions are not changes), their callers or readers, signature-change surface,
190
191
  touched columns, cross-root consumers, risk rank.
191
192
  - **Dispatch seams** — registry/factory families and the Protocol each impl satisfies.
192
193
  - **Dataflow** — producers/consumers of a string-keyed DataFrame column.
@@ -106,6 +106,16 @@ def add_attrflow(graph, griffe_root, target_pkg: str, *, deep: bool = False,
106
106
  edges.add((node_id, attr_id, access, resolution))
107
107
  if counts["out"]:
108
108
  graph.nodes[node_id].extras["attr_access"] = counts
109
+ # R1-C82 D3b: module-level code and class bodies read constants too — the
110
+ # import-time check `if set(SURFACES) != set(SURFACE_NAMES): raise` is exactly
111
+ # the reader a review of SURFACE_NAMES must name. Source: the module / class.
112
+ for src_id, scope, cls_bound in _non_function_scopes(tree, modpath):
113
+ if src_id not in graph.nodes:
114
+ continue
115
+ for attr_id, access in _scope_name_reads(scope, cls_bound, graph, modpath,
116
+ imports, modmembers, pkg):
117
+ if attr_id != src_id:
118
+ edges.add((src_id, attr_id, access, "name"))
109
119
 
110
120
  for src, attr_id, access, resolution in sorted(edges):
111
121
  graph.add_edge(Edge("accesses", src, attr_id,
@@ -149,6 +159,7 @@ def _own_attr_uses(fnode, graph, modpath, members, imports, modmembers, pkg, scr
149
159
  # Attributes that are the callee of a call (``self.foo()``) are *method calls*,
150
160
  # handled by the behavioral layer — not field access. Skip exactly those.
151
161
  call_funcs = {id(n.func) for n in nodes if isinstance(n, ast.Call)}
162
+ yield from _module_name_uses(fnode, nodes, graph, modpath, imports, modmembers, pkg)
152
163
 
153
164
  for node in nodes:
154
165
  if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
@@ -195,6 +206,116 @@ def _own_attr_uses(fnode, graph, modpath, members, imports, modmembers, pkg, scr
195
206
  yield from _deep_attr(node, graph, pkg, script)
196
207
 
197
208
 
209
+ def _bound_names(fnode, nodes) -> tuple[set[str], set[str]]:
210
+ """(names bound locally in the function, names declared ``global``)."""
211
+ bound: set[str] = set()
212
+ a = fnode.args
213
+ for arg in (*a.posonlyargs, *a.args, *a.kwonlyargs, a.vararg, a.kwarg):
214
+ if arg is not None:
215
+ bound.add(arg.arg)
216
+ glob: set[str] = set()
217
+ for n in nodes:
218
+ if isinstance(n, ast.Name) and isinstance(n.ctx, (ast.Store, ast.Del)):
219
+ bound.add(n.id)
220
+ elif isinstance(n, (ast.Import, ast.ImportFrom)):
221
+ bound.update((al.asname or al.name).split(".")[0] for al in n.names)
222
+ elif isinstance(n, ast.ExceptHandler) and n.name:
223
+ bound.add(n.name)
224
+ elif isinstance(n, ast.Global):
225
+ glob.update(n.names)
226
+ elif isinstance(n, ast.arg):
227
+ bound.add(n.arg) # lambda parameters
228
+ return bound - glob, glob
229
+
230
+
231
+ def _module_name_uses(fnode, nodes, graph, modpath, imports, modmembers, pkg):
232
+ """Bare-name reads of a module attribute: ``x in NAMES`` (R1-C82 D3).
233
+
234
+ ``from pkg.contracts import NAMES`` gave only an ``export`` edge and a read of the
235
+ name inside a function gave none, so a module constant had "no consumers" in
236
+ ``review``/``impact`` while being read everywhere. Resolved through the module's
237
+ imports or its own members; emitted only onto a real ``attribute`` node. A local
238
+ binding of the same name shadows it. Unresolved bare names are not counted —
239
+ nearly all of them are locals and builtins. Fast tier.
240
+ """
241
+ bound, glob = _bound_names(fnode, nodes)
242
+ for n in nodes:
243
+ if not isinstance(n, ast.Name):
244
+ continue
245
+ if isinstance(n.ctx, ast.Load):
246
+ if n.id in bound:
247
+ continue
248
+ access = "read"
249
+ elif isinstance(n.ctx, ast.Store) and n.id in glob:
250
+ access = "write" # global NAME; NAME = …
251
+ else:
252
+ continue
253
+ if n.id in imports:
254
+ tgt = imports[n.id]
255
+ if not tgt.startswith(pkg):
256
+ continue
257
+ elif n.id in modmembers:
258
+ tgt = f"{modpath}.{n.id}"
259
+ else:
260
+ continue
261
+ if _is_attribute_node(graph, tgt):
262
+ yield tgt, access, "name"
263
+
264
+
265
+ _SCOPE_BARRIERS = (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef, ast.Lambda)
266
+
267
+
268
+ def _scope_walk(stmts):
269
+ """Every node of ``stmts`` that belongs to this scope — not into defs, classes, lambdas."""
270
+ todo = list(stmts)
271
+ while todo:
272
+ n = todo.pop()
273
+ yield n
274
+ if isinstance(n, _SCOPE_BARRIERS):
275
+ # decorators, defaults and bases are evaluated in the enclosing scope
276
+ if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)):
277
+ todo.extend(n.decorator_list)
278
+ todo.extend(d for d in (*n.args.defaults, *n.args.kw_defaults) if d is not None)
279
+ elif isinstance(n, ast.ClassDef):
280
+ todo.extend((*n.decorator_list, *n.bases, *(k.value for k in n.keywords)))
281
+ continue
282
+ todo.extend(ast.iter_child_nodes(n))
283
+
284
+
285
+ def _non_function_scopes(tree, modpath):
286
+ """(source id, nodes, names bound in that scope or None) for the module and each class body."""
287
+ yield modpath, list(_scope_walk(tree.body)), None
288
+
289
+ def classes(stmts, prefix):
290
+ for st in stmts:
291
+ if isinstance(st, ast.ClassDef):
292
+ cid = f"{prefix}.{st.name}"
293
+ nodes = list(_scope_walk(st.body))
294
+ bound = {n.id for n in nodes if isinstance(n, ast.Name)
295
+ and isinstance(n.ctx, (ast.Store, ast.Del))}
296
+ yield cid, nodes, bound
297
+ yield from classes(st.body, cid)
298
+ yield from classes(tree.body, modpath)
299
+
300
+
301
+ def _scope_name_reads(nodes, cls_bound, graph, modpath, imports, modmembers, pkg):
302
+ for n in nodes:
303
+ if not (isinstance(n, ast.Name) and isinstance(n.ctx, ast.Load)):
304
+ continue
305
+ if cls_bound is not None and n.id in cls_bound:
306
+ continue
307
+ if n.id in imports:
308
+ tgt = imports[n.id]
309
+ if not tgt.startswith(pkg):
310
+ continue
311
+ elif n.id in modmembers:
312
+ tgt = f"{modpath}.{n.id}"
313
+ else:
314
+ continue
315
+ if _is_attribute_node(graph, tgt):
316
+ yield tgt, "read"
317
+
318
+
198
319
  def _deep_attr(node, graph, pkg, script):
199
320
  """Resolve ``obj.field`` via jedi (deep tier); yield (attr_id | None, access, 'deep').
200
321
 
@@ -118,7 +118,10 @@ SCHEMA_VERSION = "0.13"
118
118
  # `--all-bands` lists every band, each row carrying its distance and confidence; a helper
119
119
  # function inside a collected test module costs no hop in `tests` and `covers`, so
120
120
  # distances move where one sits on the path (R1-C80, docs/design/tests_through_helpers.md).
121
- ANSWER_FORMAT = 5
121
+ # 6 — `review` reads changed lines, not whole hunks; a module's dossier counts direct references
122
+ # to the module (its importers), not every reference into every member, and has no call-site
123
+ # contract; module constants gain `accesses` readers (R1-C82, docs/design/review_changed_lines.md).
124
+ ANSWER_FORMAT = 6
122
125
 
123
126
  # Closed vocabulary of edge types (R1-C7). Node ``kind`` is deliberately an OPEN set
124
127
  # (DESIGN §2 — new entity kinds may appear), but edges are TYPED: every relationship
@@ -181,6 +184,9 @@ RESOLUTIONS: dict[tuple[str, str], dict[str, str]] = {
181
184
  "how": "`Class(...).attr` — the constructor names the owner"},
182
185
  ("accesses", "deep"): {"means": "route", "confidence": "inferred",
183
186
  "how": "owner type inferred by jedi (deep tier only)"},
187
+ ("accesses", "name"): {"means": "route", "confidence": "exact",
188
+ "how": "a module attribute read by bare name — through an import "
189
+ "or in its own module; a local binding shadows it (R1-C82)"},
184
190
  ("references", "annotation"): {"means": "site", "confidence": "exact",
185
191
  "how": "the symbol appears in a type annotation"},
186
192
  ("references", "name"): {"means": "site", "confidence": "exact",
@@ -51,16 +51,43 @@ def _risk(caller_n: int, consumers: dict[str, int], contract_sites: int,
51
51
  return "low", score
52
52
 
53
53
 
54
+ def _module_dossier(query: Query, sid: str, node) -> dict:
55
+ """A changed line of module-level code (R1-C82 D2): about the module, not its members.
56
+
57
+ The generic dossier sums callers and call sites over every member, which turned a
58
+ one-line constant edit into "[high] … 123 site(s) — check on signature change". A
59
+ module has no signature; what module-level code reaches is whoever imports it.
60
+ """
61
+ consumers: dict[str, int] = {}
62
+ for ref in query.references_to(sid, include_members=False):
63
+ consumers[ref["root"]] = consumers.get(ref["root"], 0) + 1
64
+ importers = sum(consumers.values())
65
+ risk, score = _risk(importers, {r: v for r, v in consumers.items() if r != "core"}, 0, False)
66
+ return {
67
+ "symbol": sid, "kind": "module", "file": node.file if node else None, "lines": None,
68
+ "callers": [], "callees": [], "call_contract": [],
69
+ "columns": {"reads": [], "writes": []},
70
+ "consumers_by_root": consumers,
71
+ "module_level": True,
72
+ "risk": risk, "risk_score": score,
73
+ }
74
+
75
+
54
76
  def build_symbol_dossier(query: Query, sid: str) -> dict:
55
77
  """Everything a reviewer needs about one changed symbol (F17)."""
56
78
  node = query.graph.nodes.get(sid)
57
79
  kind = node.kind if node else None
80
+ if kind == "module":
81
+ return _module_dossier(query, sid, node)
58
82
  callers = query.callers(sid)
59
83
  contract = query.call_contract(sid)
60
84
  cols = query.columns_of(sid) if kind == "function" else {"reads": [], "writes": []}
61
85
  consumers = _consumers_by_root(query, sid)
62
86
  touches = bool(cols["reads"] or cols["writes"])
63
- risk, score = _risk(len(callers), consumers, len(contract), touches)
87
+ # R1-C82: an attribute has no callers; its reach is who reads or writes it (the
88
+ # `accesses` edges D3 added), or a widely read constant would rank "low".
89
+ reach = sum(consumers.values()) if kind == "attribute" else len(callers)
90
+ risk, score = _risk(reach, consumers, len(contract), touches)
64
91
  return {
65
92
  "symbol": sid,
66
93
  "kind": kind,
@@ -102,6 +129,11 @@ def build_review(query: Query, *, hunks: list[dict] | None = None,
102
129
  ids.update(got)
103
130
  else:
104
131
  unresolved.append({"file": file, "range": [start, end]})
132
+ for rng in h.get("soft", []):
133
+ # D1b: a blank/comment line names its definition, never the module
134
+ start, end = int(rng[0]), int(rng[-1])
135
+ _defs, module = query._defs_in_file(file)
136
+ ids.update(s for s in query.symbols_in_range(file, start, end) if s != module)
105
137
  ids = {query.canonical(i) or i for i in ids}
106
138
  dossiers = [build_symbol_dossier(query, sid) for sid in sorted(ids)]
107
139
  dossiers.sort(key=lambda d: (-d["risk_score"], d["symbol"]))
@@ -154,7 +186,11 @@ def render_review(query: Query, *, hunks: list[dict] | None = None,
154
186
  for d in rv["changed"]:
155
187
  loc = f" ({d['file']}:{d['lines'][0]})" if d["file"] and d["lines"] else ""
156
188
  out.append(f"## [{d['risk']}] {d['symbol']}{loc}")
157
- if d["consumers_by_root"]:
189
+ if d.get("module_level"):
190
+ n = sum(d["consumers_by_root"].values())
191
+ out.append(f"- Module-level code changed (outside any definition) — runs on import; "
192
+ f"referenced directly by {n} site(s): {d['consumers_by_root'] or '—'}")
193
+ elif d["consumers_by_root"]:
158
194
  out.append(f"- Consumers by root: {d['consumers_by_root']}")
159
195
  if d["callers"]:
160
196
  out.append(f"- Callers ({len(d['callers'])}): "
@@ -171,27 +207,88 @@ def render_review(query: Query, *, hunks: list[dict] | None = None,
171
207
 
172
208
  # -- unified-diff hunk parsing (for CLI `codemap review <diff>`) --------------
173
209
 
210
+ def _soft(text: str) -> bool:
211
+ """A blank or comment-only line: no code changed on it (R1-C82 D1b)."""
212
+ t = text.strip()
213
+ return not t or t.startswith("#")
214
+
215
+
216
+ def _runs(lines: list[int]) -> list[list[int]]:
217
+ """Sorted line numbers → [[start, end], …] of consecutive runs."""
218
+ out: list[list[int]] = []
219
+ for n in sorted(set(lines)):
220
+ if out and n == out[-1][1] + 1:
221
+ out[-1][1] = n
222
+ else:
223
+ out.append([n, n])
224
+ return out
225
+
226
+
174
227
  def parse_unified_diff(text: str) -> list[dict]:
175
- """Parse a unified diff → [{file, ranges: [[start,end], …]}] (new-file lines).
228
+ """Parse a unified diff → [{file, ranges, soft}] in new-file line numbers.
176
229
 
177
- Reads ``+++ b/<path>`` targets and ``@@ -a,b +c,d @@`` hunk headers, taking the
178
- **new-file** side (``+c,d`` → lines ``c … c+d-1``). Deletions (``d == 0``)
179
- anchor a zero-width range at ``c`` so a pure deletion still maps to its site.
230
+ R1-C82 D1: only **changed** lines count. The ``@@ +c,d @@`` header spans the hunk's
231
+ context too (three lines each side by default), and reading it whole put untouched
232
+ neighbours — and, through module-level comments, the whole module — into a review of
233
+ a one-line change. Now ``+`` lines give their own numbers; a run of ``-`` lines with no
234
+ ``+`` (a pure deletion) anchors a zero-width range at the new-file line where it stood.
235
+
236
+ D1b: a changed line that is blank or a comment goes to ``soft`` instead of ``ranges``.
237
+ Inside a definition it still names that definition; outside every definition it
238
+ names nothing — a comment between two functions is not a change to the module.
180
239
  """
181
240
  import re
182
- hdr = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")
183
- files: dict[str, list] = {}
241
+ hdr = re.compile(r"^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
242
+ hard: dict[str, list[int]] = {}
243
+ soft: dict[str, list[int]] = {}
184
244
  current = None
245
+ cur = old_left = new_left = 0 # the header's counts tell body lines from headers
246
+ pending: list[str] = [] # texts of a run of '-' lines not yet followed by '+'
247
+
248
+ def flush():
249
+ if current and pending:
250
+ (soft if all(_soft(t) for t in pending) else hard)[current].append(cur)
251
+ pending.clear()
252
+
185
253
  for ln in text.splitlines():
254
+ if old_left > 0 or new_left > 0: # inside a hunk body
255
+ if ln.startswith("\\"):
256
+ continue # ""
257
+ tag, body = (ln[:1], ln[1:]) if ln else (" ", "")
258
+ if tag == "+":
259
+ pending.clear() # a replacement: '+' lines carry it
260
+ if current:
261
+ (soft if _soft(body) else hard)[current].append(cur)
262
+ cur += 1
263
+ new_left -= 1
264
+ elif tag == "-":
265
+ pending.append(body)
266
+ old_left -= 1
267
+ else: # context
268
+ flush()
269
+ cur += 1
270
+ old_left -= 1
271
+ new_left -= 1
272
+ if old_left <= 0 and new_left <= 0:
273
+ flush()
274
+ continue
186
275
  if ln.startswith("+++ "):
187
276
  path = ln[4:].strip().split("\t")[0]
188
277
  if path.startswith("b/"):
189
278
  path = path[2:]
190
279
  current = None if path == "/dev/null" else path
191
- files.setdefault(current, [])
192
- elif current and (m := hdr.match(ln)):
193
- start = int(m.group(1))
194
- count = int(m.group(2)) if m.group(2) is not None else 1
195
- end = start + count - 1 if count else start
196
- files[current].append([start, max(start, end)])
197
- return [{"file": f, "ranges": r} for f, r in files.items() if f and r]
280
+ if current:
281
+ hard.setdefault(current, [])
282
+ soft.setdefault(current, [])
283
+ elif m := hdr.match(ln):
284
+ old_left = int(m.group(1)) if m.group(1) is not None else 1
285
+ cur = int(m.group(2))
286
+ new_left = int(m.group(3)) if m.group(3) is not None else 1
287
+ if new_left == 0:
288
+ cur += 1 # "+c,0": the deletion sits after new line c
289
+ out = []
290
+ for f in hard:
291
+ h, so = _runs(hard[f]), _runs(soft.get(f, []))
292
+ if h or so:
293
+ out.append({"file": f, "ranges": h, "soft": so})
294
+ return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.29
3
+ Version: 0.0.30
4
4
  Summary: Static analyzer that turns a package's source into a queryable code graph.
5
5
  Author-email: kogriv <kogriv@gmail.com>
6
6
  License-Expression: MIT
@@ -44,7 +44,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
44
44
 
45
45
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
46
46
 
47
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1207 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1220 tests with no failures on
48
48
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
49
49
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
50
50
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -222,7 +222,8 @@ codemap serve --graph graph.json --watch
222
222
  (Ca/Ce/instability), god-objects & call-hubs, per-function complexity (cyclomatic / MI)
223
223
  blended with structural coupling.
224
224
  - **Impact / blast radius** — who uses X, across the whole repo (core + tests + docs).
225
- - **Change review** — a diff → the symbols it touches, their callers, signature-change surface,
225
+ - **Change review** — a diff → the symbols its changed lines touch (context lines and comments
226
+ between definitions are not changes), their callers or readers, signature-change surface,
226
227
  touched columns, cross-root consumers, risk rank.
227
228
  - **Dispatch seams** — registry/factory families and the Protocol each impl satisfies.
228
229
  - **Dataflow** — producers/consumers of a string-keyed DataFrame column.
@@ -152,6 +152,7 @@ tests/test_r1c77_gate_probe_battery.py
152
152
  tests/test_r1c78_forbidden_chains.py
153
153
  tests/test_r1c7_edge_vocab.py
154
154
  tests/test_r1c80_tests_through_helpers.py
155
+ tests/test_r1c82_review_changed_lines.py
155
156
  tests/test_r1c83_foreign_graph_paths.py
156
157
  tests/test_r1c84_missing_roots.py
157
158
  tests/test_r1c8_deadcode.py
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
9
9
  # version. README says this plainly, since `pip install codmap` / `import codemap` is a
10
10
  # seam a reader will otherwise hit by surprise.
11
11
  name = "codmap"
12
- version = "0.0.29"
12
+ version = "0.0.30"
13
13
  description = "Static analyzer that turns a package's source into a queryable code graph."
14
14
  readme = "README.md"
15
15
  # M20/D1: measured, not assumed. Each release of the declared range runs the full suite in
@@ -84,16 +84,18 @@ def test_parse_unified_diff_new_side_ranges():
84
84
  "--- a/flowpkg/produce.py\n"
85
85
  "+++ b/flowpkg/produce.py\n"
86
86
  "@@ -4,2 +4,3 @@ def compute(df):\n"
87
- " ctx\n+added\n"
87
+ " ctx\n+added\n ctx\n"
88
88
  )
89
89
  hunks = parse_unified_diff(diff)
90
- assert hunks == [{"file": "flowpkg/produce.py", "ranges": [[4, 6]]}]
90
+ # R1-C82 D1: the changed line only — the header's span includes context
91
+ assert hunks == [{"file": "flowpkg/produce.py", "ranges": [[5, 5]], "soft": []}]
91
92
 
92
93
 
93
94
  def test_parse_diff_then_review_end_to_end(q):
94
95
  diff = (
95
96
  "+++ b/flowpkg/produce.py\n"
96
97
  "@@ -4,2 +4,3 @@\n"
98
+ " ctx\n+ added = 1\n ctx\n"
97
99
  )
98
100
  rv = build_review(q, hunks=parse_unified_diff(diff))
99
101
  assert any(d["symbol"] == "flowpkg.produce.compute" for d in rv["changed"])
@@ -0,0 +1,163 @@
1
+ """R1-C82 — `review` reads changed lines, not hunks; a module constant has readers.
2
+
3
+ Design `docs/design/review_changed_lines.md` (pre-registered ab16f1e).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from pathlib import Path
9
+
10
+ import pytest
11
+
12
+ from codemap.extract import extract
13
+ from codemap.query import Query
14
+ from codemap.serve.review import build_review, parse_unified_diff, render_review
15
+
16
+ CONTRACTS = (
17
+ "import os\n" # 1
18
+ "\n" # 2
19
+ "NAMES = (\"a\", \"b\")\n" # 3
20
+ "# the surfaces\n" # 4
21
+ "LIMIT = 3\n" # 5
22
+ "\n" # 6
23
+ "\n" # 7
24
+ "class Spec:\n" # 8
25
+ " def check(self, x):\n" # 9
26
+ " return x in NAMES\n" # 10
27
+ "\n" # 11
28
+ "\n" # 12
29
+ "def use():\n" # 13
30
+ " return LIMIT + 1\n" # 14
31
+ "\n" # 15
32
+ "\n" # 16
33
+ "def caller_a():\n" # 17
34
+ " return use() + use()\n" # 18
35
+ )
36
+ GATES = (
37
+ "from pkg.contracts import NAMES\n"
38
+ "from pkg import contracts\n\n\n"
39
+ "def gate(x):\n return x in NAMES\n\n\n"
40
+ "def other():\n return contracts.LIMIT\n\n\n"
41
+ "def shadow(NAMES):\n return NAMES\n\n\n"
42
+ "def rebound():\n NAMES = ()\n return NAMES\n\n\n"
43
+ "def uses_spec():\n return contracts.use()\n\n\n"
44
+ "if set(NAMES) != {\"a\", \"b\"}:\n raise RuntimeError(\"drift\")\n\n\n" # import-time check
45
+ "class Holder:\n ALL = NAMES\n\n\n"
46
+ "class Own:\n NAMES = ()\n X = NAMES\n"
47
+ )
48
+
49
+
50
+ @pytest.fixture(scope="module")
51
+ def q(tmp_path_factory) -> Query:
52
+ root = tmp_path_factory.mktemp("r1c82")
53
+ (root / "pkg").mkdir()
54
+ (root / "pkg" / "__init__.py").write_text("")
55
+ (root / "pkg" / "contracts.py").write_text(CONTRACTS)
56
+ (root / "pkg" / "gates.py").write_text(GATES)
57
+ return Query(extract(str(root / "pkg")))
58
+
59
+
60
+ def _diff(start_old, lines, file="pkg/contracts.py"):
61
+ """A unified diff hunk; ``lines`` are body lines with their tag."""
62
+ old_n = sum(1 for ln in lines if ln[0] in " -")
63
+ new_n = sum(1 for ln in lines if ln[0] in " +")
64
+ return (f"--- a/{file}\n+++ b/{file}\n@@ -{start_old},{old_n} +{start_old},{new_n} @@\n"
65
+ + "\n".join(lines) + "\n")
66
+
67
+
68
+ ONE_CONSTANT = _diff(1, [" import os", " ", "-NAMES = (\"a\",)", "+NAMES = (\"a\", \"b\")",
69
+ " # the surfaces", " LIMIT = 3", " "])
70
+
71
+
72
+ def _accesses(q):
73
+ return {(e.source, e.target, e.extras.get("resolution")) for e in q.graph.edges if e.type == "accesses"}
74
+
75
+
76
+ # -- D1: changed lines only ---------------------------------------------------
77
+
78
+ def test_D1_context_lines_are_not_changes():
79
+ assert parse_unified_diff(ONE_CONSTANT) == [
80
+ {"file": "pkg/contracts.py", "ranges": [[3, 3]], "soft": []}]
81
+
82
+
83
+ def test_D1_a_pure_deletion_anchors_where_it_stood():
84
+ d = _diff(13, [" def use():", "- x = 1", " return LIMIT + 1"])
85
+ assert parse_unified_diff(d)[0]["ranges"] == [[14, 14]]
86
+
87
+
88
+ def test_D1_a_removed_line_that_looks_like_a_header_is_still_a_body_line():
89
+ d = _diff(9, [" def check(self, x):", "--- not a header", " return x in NAMES"])
90
+ assert parse_unified_diff(d)[0]["ranges"] == [[10, 10]]
91
+
92
+
93
+ def test_E1_one_constant_one_symbol(q):
94
+ rv = build_review(q, hunks=parse_unified_diff(ONE_CONSTANT))
95
+ assert [d["symbol"] for d in rv["changed"]] == ["pkg.contracts.NAMES"]
96
+ assert rv["summary"]["unresolved_hunks"] == []
97
+
98
+
99
+ # -- D1b: a comment between definitions is not a module change ----------------
100
+
101
+ def test_E4_a_comment_line_outside_definitions_names_nothing(q):
102
+ d = _diff(3, [" NAMES = (\"a\", \"b\")", "-# the surfaces", "+# the surfaces, renamed", " LIMIT = 3"])
103
+ rv = build_review(q, hunks=parse_unified_diff(d))
104
+ assert rv["changed"] == [] and rv["summary"]["unresolved_hunks"] == []
105
+
106
+
107
+ def test_D1b_a_comment_inside_a_definition_still_names_it(q):
108
+ d = _diff(13, [" def use():", "+ # why", " return LIMIT + 1"])
109
+ rv = build_review(q, hunks=parse_unified_diff(d))
110
+ assert [x["symbol"] for x in rv["changed"]] == ["pkg.contracts.use"]
111
+
112
+
113
+ # -- D2: a module dossier is about the module ---------------------------------
114
+
115
+ def test_E4_an_import_line_gives_the_module_without_a_call_site_contract(q):
116
+ d = _diff(1, ["-import os", "+import sys", " ", " NAMES = (\"a\", \"b\")"])
117
+ rv = build_review(q, hunks=parse_unified_diff(d))
118
+ (dossier,) = rv["changed"]
119
+ assert dossier["symbol"] == "pkg.contracts" and dossier["module_level"] is True
120
+ assert dossier["call_contract"] == [] and dossier["callers"] == []
121
+ # direct references to the module only: gates imports it — not the members' callers
122
+ assert dossier["consumers_by_root"] == {"core": 1}
123
+ md = render_review(q, hunks=parse_unified_diff(d))
124
+ assert "Module-level code changed" in md and "check on signature change" not in md
125
+
126
+
127
+ # -- D3: bare-name reads of a module attribute --------------------------------
128
+
129
+ def test_E3_bare_name_reads_are_accesses(q):
130
+ es = _accesses(q)
131
+ assert ("pkg.gates.gate", "pkg.contracts.NAMES", "name") in es # imported name
132
+ assert ("pkg.contracts.Spec.check", "pkg.contracts.NAMES", "name") in es # same module
133
+ assert ("pkg.contracts.use", "pkg.contracts.LIMIT", "name") in es
134
+ assert ("pkg.gates.other", "pkg.contracts.LIMIT", "class") in es # unchanged form
135
+
136
+
137
+ def test_E3_a_local_binding_shadows(q):
138
+ srcs = {s for s, t, _ in _accesses(q) if t == "pkg.contracts.NAMES"}
139
+ assert "pkg.gates.shadow" not in srcs and "pkg.gates.rebound" not in srcs
140
+
141
+
142
+ def test_E2_the_constant_dossier_names_its_readers(q):
143
+ rv = build_review(q, hunks=parse_unified_diff(ONE_CONSTANT))
144
+ (d,) = rv["changed"]
145
+ assert d["consumers_by_root"] == {"core": 4} # gate, Spec.check, gates (import time), Holder
146
+ assert d["risk"] != "low"
147
+
148
+
149
+ def test_D3_a_function_is_not_an_attribute(q):
150
+ # `use()` called by bare name stays in the calls layer
151
+ assert not any(t == "pkg.contracts.use" for _, t, _ in _accesses(q))
152
+
153
+
154
+ # -- D3b: module level and class bodies (amendment after the first run) -------
155
+
156
+ def test_D3b_an_import_time_check_is_a_reader(q):
157
+ assert ("pkg.gates", "pkg.contracts.NAMES", "name") in _accesses(q)
158
+
159
+
160
+ def test_D3b_a_class_body_read_and_its_shadow(q):
161
+ es = _accesses(q)
162
+ assert ("pkg.gates.Holder", "pkg.contracts.NAMES", "name") in es
163
+ assert not any(s == "pkg.gates.Own" for s, _, _ in es)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes