codmap 0.0.33__tar.gz → 0.0.34__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 (170) hide show
  1. {codmap-0.0.33 → codmap-0.0.34}/PKG-INFO +2 -2
  2. {codmap-0.0.33 → codmap-0.0.34}/README.md +1 -1
  3. {codmap-0.0.33 → codmap-0.0.34}/codemap/cli.py +69 -13
  4. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/roots.py +6 -1
  5. {codmap-0.0.33 → codmap-0.0.34}/codemap/incremental.py +46 -7
  6. {codmap-0.0.33 → codmap-0.0.34}/codemap/model.py +4 -1
  7. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/currency.py +46 -5
  8. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/session.py +4 -2
  9. {codmap-0.0.33 → codmap-0.0.34}/codmap.egg-info/PKG-INFO +2 -2
  10. {codmap-0.0.33 → codmap-0.0.34}/codmap.egg-info/SOURCES.txt +2 -0
  11. {codmap-0.0.33 → codmap-0.0.34}/pyproject.toml +1 -1
  12. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c44_absent_answers.py +7 -2
  13. codmap-0.0.34/tests/test_r1c86_incremental_repo_scope.py +195 -0
  14. codmap-0.0.34/tests/test_r1c90_currency_without_recipe.py +86 -0
  15. {codmap-0.0.33 → codmap-0.0.34}/LICENSE +0 -0
  16. {codmap-0.0.33 → codmap-0.0.34}/codemap/__init__.py +0 -0
  17. {codmap-0.0.33 → codmap-0.0.34}/codemap/apidiff.py +0 -0
  18. {codmap-0.0.33 → codmap-0.0.34}/codemap/arch.py +0 -0
  19. {codmap-0.0.33 → codmap-0.0.34}/codemap/diagnostics.py +0 -0
  20. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/__init__.py +0 -0
  21. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/attrflow.py +0 -0
  22. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/behavior.py +0 -0
  23. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/dataflow.py +0 -0
  24. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/dispatch.py +0 -0
  25. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/griffe_extractor.py +0 -0
  26. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/gsource.py +0 -0
  27. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/probe.py +0 -0
  28. {codmap-0.0.33 → codmap-0.0.34}/codemap/extract/union.py +0 -0
  29. {codmap-0.0.33 → codmap-0.0.34}/codemap/freshness.py +0 -0
  30. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/__init__.py +0 -0
  31. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/base.py +0 -0
  32. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/cocoindex.py +0 -0
  33. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/gate.py +0 -0
  34. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/gitnexus.py +0 -0
  35. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/registry.py +0 -0
  36. {codmap-0.0.33 → codmap-0.0.34}/codemap/integrations/transport.py +0 -0
  37. {codmap-0.0.33 → codmap-0.0.34}/codemap/provenance.py +0 -0
  38. {codmap-0.0.33 → codmap-0.0.34}/codemap/query.py +0 -0
  39. {codmap-0.0.33 → codmap-0.0.34}/codemap/scope.py +0 -0
  40. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/__init__.py +0 -0
  41. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/_scip_pb2.py +0 -0
  42. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/api_surface.py +0 -0
  43. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/apidiff.py +0 -0
  44. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/architecture.py +0 -0
  45. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/audit.py +0 -0
  46. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/check.py +0 -0
  47. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/ctags.py +0 -0
  48. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/impact.py +0 -0
  49. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/limits.py +0 -0
  50. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/livingdocs.py +0 -0
  51. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/mcp_server.py +0 -0
  52. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/mermaid.py +0 -0
  53. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/pack.py +0 -0
  54. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/rag.py +0 -0
  55. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/review.py +0 -0
  56. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/scip.py +0 -0
  57. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/semantic.py +0 -0
  58. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/server.py +0 -0
  59. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/subsystems.py +0 -0
  60. {codmap-0.0.33 → codmap-0.0.34}/codemap/serve/vault.py +0 -0
  61. {codmap-0.0.33 → codmap-0.0.34}/codemap/store.py +0 -0
  62. {codmap-0.0.33 → codmap-0.0.34}/codemap/tomlio.py +0 -0
  63. {codmap-0.0.33 → codmap-0.0.34}/codemap/watch.py +0 -0
  64. {codmap-0.0.33 → codmap-0.0.34}/codmap.egg-info/dependency_links.txt +0 -0
  65. {codmap-0.0.33 → codmap-0.0.34}/codmap.egg-info/entry_points.txt +0 -0
  66. {codmap-0.0.33 → codmap-0.0.34}/codmap.egg-info/requires.txt +0 -0
  67. {codmap-0.0.33 → codmap-0.0.34}/codmap.egg-info/top_level.txt +0 -0
  68. {codmap-0.0.33 → codmap-0.0.34}/setup.cfg +0 -0
  69. {codmap-0.0.33 → codmap-0.0.34}/tests/test_epistemic.py +0 -0
  70. {codmap-0.0.33 → codmap-0.0.34}/tests/test_gitnexus_router.py +0 -0
  71. {codmap-0.0.33 → codmap-0.0.34}/tests/test_impact_depth.py +0 -0
  72. {codmap-0.0.33 → codmap-0.0.34}/tests/test_integrations.py +0 -0
  73. {codmap-0.0.33 → codmap-0.0.34}/tests/test_issue3_serve_freshness.py +0 -0
  74. {codmap-0.0.33 → codmap-0.0.34}/tests/test_livingdocs.py +0 -0
  75. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m0_api_surface.py +0 -0
  76. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m11_argcontract.py +0 -0
  77. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m12_dataflow.py +0 -0
  78. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m15_review.py +0 -0
  79. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m16_architecture.py +0 -0
  80. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m17_mcp.py +0 -0
  81. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m18_freshness.py +0 -0
  82. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m1_5_semantics.py +0 -0
  83. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m1_query.py +0 -0
  84. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m2_views.py +0 -0
  85. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m32_watch.py +0 -0
  86. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m3_serve.py +0 -0
  87. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m4_behavior.py +0 -0
  88. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m5_deep.py +0 -0
  89. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m6_repo_scope.py +0 -0
  90. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m7_dispatch.py +0 -0
  91. {codmap-0.0.33 → codmap-0.0.34}/tests/test_m9_family.py +0 -0
  92. {codmap-0.0.33 → codmap-0.0.34}/tests/test_pack_honesty.py +0 -0
  93. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  94. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c13_grep_vs_graph.py +0 -0
  95. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c16_semantic.py +0 -0
  96. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c20_attribute_edges.py +0 -0
  97. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c21_flat_layout.py +0 -0
  98. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c22_source_visible_refs.py +0 -0
  99. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c23_hard_python.py +0 -0
  100. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c24_test_mapping.py +0 -0
  101. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c25_provenance.py +0 -0
  102. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c26_deep_union.py +0 -0
  103. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c27_config_honesty.py +0 -0
  104. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c28_limit_envelope.py +0 -0
  105. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c29_lazy_imports.py +0 -0
  106. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c2_ctags.py +0 -0
  107. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c30_local_import_calls.py +0 -0
  108. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c30f1_reexport_calls.py +0 -0
  109. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c30f2_check_scope.py +0 -0
  110. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c31_path_origin.py +0 -0
  111. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c32_report_json.py +0 -0
  112. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c33_query_signature.py +0 -0
  113. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c34_signature_kinds.py +0 -0
  114. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c35_contract_location.py +0 -0
  115. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c36_target_resolution.py +0 -0
  116. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c37_rule_mutation.py +0 -0
  117. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c38_tool_drift.py +0 -0
  118. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c39_edge_resolution.py +0 -0
  119. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c3_arch_contract.py +0 -0
  120. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c3_dogfood.py +0 -0
  121. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c40_flow_reach.py +0 -0
  122. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c41_scope_membership.py +0 -0
  123. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c42_deep_tier_stability.py +0 -0
  124. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c43_incremental_splice.py +0 -0
  125. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c45_repeat_union.py +0 -0
  126. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c46_shadowed_definitions.py +0 -0
  127. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c47_incremental_resample.py +0 -0
  128. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c48_type_checking_imports.py +0 -0
  129. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c49_type_only_cycles.py +0 -0
  130. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c4_complexity.py +0 -0
  131. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c50_flow_entry_points.py +0 -0
  132. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c53_narrowing_declared.py +0 -0
  133. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c54_deterministic_rendering.py +0 -0
  134. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c55_override_grade.py +0 -0
  135. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c56_stub_files.py +0 -0
  136. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c57_facade_package.py +0 -0
  137. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c58_cycle_tangles.py +0 -0
  138. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c59_completeness_drop.py +0 -0
  139. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c5_apidiff.py +0 -0
  140. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c60_nested_definitions.py +0 -0
  141. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c62_phantom_rules.py +0 -0
  142. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c63_answer_format.py +0 -0
  143. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c64_dependency_probe.py +0 -0
  144. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c66_pack_direction.py +0 -0
  145. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c68_dotted_imports.py +0 -0
  146. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c69_contract_validation.py +0 -0
  147. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c6_pack.py +0 -0
  148. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c70_check_graph_currency.py +0 -0
  149. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  150. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  151. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c73_cli_version.py +0 -0
  152. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c74_call_site_conservation.py +0 -0
  153. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c75_reexported_class_calls.py +0 -0
  154. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c76_contract_table_typo.py +0 -0
  155. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c77_gate_probe_battery.py +0 -0
  156. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c78_forbidden_chains.py +0 -0
  157. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c7_edge_vocab.py +0 -0
  158. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c80_tests_through_helpers.py +0 -0
  159. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c81_protocol_dispatch.py +0 -0
  160. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c82_review_changed_lines.py +0 -0
  161. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  162. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c84_missing_roots.py +0 -0
  163. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  164. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c87_review_path_base.py +0 -0
  165. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c89_review_docs.py +0 -0
  166. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c8_deadcode.py +0 -0
  167. {codmap-0.0.33 → codmap-0.0.34}/tests/test_r1c9_incremental.py +0 -0
  168. {codmap-0.0.33 → codmap-0.0.34}/tests/test_scip_export.py +0 -0
  169. {codmap-0.0.33 → codmap-0.0.34}/tests/test_scope.py +0 -0
  170. {codmap-0.0.33 → codmap-0.0.34}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.33
3
+ Version: 0.0.34
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, **1249 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1264 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 &
@@ -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, **1249 tests with no failures on
11
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1264 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 &
@@ -98,12 +98,12 @@ def _graph_from(args):
98
98
  if getattr(args, "graph", None):
99
99
  graph = store.load(args.graph)
100
100
  if getattr(args, "func", None) not in (_cmd_check, _cmd_serve):
101
- _warn_if_behind(args.graph, graph)
101
+ _warn_if_behind(args.graph, graph, args)
102
102
  return graph
103
103
  raise SystemExit("error: need --graph <file> or --build <path>")
104
104
 
105
105
 
106
- def _warn_if_behind(path: str, graph) -> None:
106
+ def _warn_if_behind(path: str, graph, args_for_currency=None) -> None:
107
107
  """R1-C85 D4: a cold read of a graph behind its tree says so, once, on stderr.
108
108
 
109
109
  `check` prints its own currency line and `serve` puts it in every envelope; every
@@ -111,11 +111,18 @@ def _warn_if_behind(path: str, graph) -> None:
111
111
  current or unknown, so stdout and exit codes never change.
112
112
  """
113
113
  from codemap.serve.currency import graph_currency
114
- c = graph_currency(path, (graph.provenance or {}).get("scope_id"))
114
+ prov = graph.provenance or {}
115
+ c = graph_currency(path, prov.get("scope_id"), roots=prov.get("roots"),
116
+ target=graph.target, base=getattr(args_for_currency, "source_root", None))
115
117
  if c.get("status") == "behind":
116
- print(f"[warning] {path} is behind its source tree ({c.get('added', 0)} added, "
117
- f"{c.get('changed', 0)} changed, {c.get('removed', 0)} removed since it was "
118
- "built) — answers describe the older tree; rebuild", file=sys.stderr)
118
+ counts = (f" ({c.get('added', 0)} added, {c.get('changed', 0)} changed, "
119
+ f"{c.get('removed', 0)} removed since it was built)" if "changed" in c else "")
120
+ print(f"[warning] {path} is behind its source tree{counts} — answers describe the "
121
+ "older tree; rebuild", file=sys.stderr)
122
+ elif c.get("status") == "unknown":
123
+ # R1-C90 D2: "could not check" is said, once — silence read as "current".
124
+ print(f"[note] could not check {path} against the source tree: {c.get('reason')}",
125
+ file=sys.stderr)
119
126
 
120
127
 
121
128
  def _refuse_bad_roots(args) -> bool:
@@ -148,12 +155,11 @@ def _cmd_build(args) -> int:
148
155
  if _refuse_bad_roots(args):
149
156
  return 2
150
157
  if args.consumer or args.docs:
151
- if getattr(args, "incremental", False):
152
- # R1-C44 / D6: the flag used to be swallowed here without a word. Not an
153
- # error — a stated boundary: the incremental path is single-package.
154
- print("[note] --incremental was not applied: --consumer/--docs make this a "
155
- "repo-scoped build, which is always full (the incremental path is "
156
- "single-package only)", file=sys.stderr)
158
+ core_graph = None
159
+ if getattr(args, "incremental", False) and args.out:
160
+ # R1-C86 D1: the core is updated incrementally; the consumer and doc scans
161
+ # (deterministic `ast`, ~6 s on bquant) rerun in full on top of it.
162
+ core_graph, incr_info = _incremental_core(args, repeat)
157
163
  graph = extract_repo(
158
164
  args.path,
159
165
  consumers=tuple(args.consumer or ()),
@@ -161,6 +167,7 @@ def _cmd_build(args) -> int:
161
167
  mode=args.mode,
162
168
  deep=args.deep,
163
169
  repeat=repeat,
170
+ core_graph=core_graph,
164
171
  )
165
172
  elif getattr(args, "incremental", False) and args.out:
166
173
  graph, incr_info = _incremental_build(args)
@@ -295,6 +302,54 @@ def _incremental_build(args):
295
302
  repeat=repeat)
296
303
 
297
304
 
305
+ def _core_subgraph(graph, offset: str = ""):
306
+ """The core part of a repo-scoped graph: core nodes, and edges whose source is one (R1-C86).
307
+
308
+ ``offset`` is the core's parent relative to the graph's path base (R1-C31). A repo
309
+ build re-roots core files by it, and `extract_repo` will do so again, so it is
310
+ stripped here or an unchanged core would come back with the prefix twice.
311
+ """
312
+ import copy
313
+ from codemap.model import Graph
314
+ core = Graph(target=graph.target)
315
+ core.provenance = dict(graph.provenance or {})
316
+ core.provenance.pop("roots", None)
317
+ pre = f"{offset}/" if offset not in ("", ".") else ""
318
+ for nid, n in graph.nodes.items():
319
+ if (n.extras or {}).get("root", "core") == "core":
320
+ n = copy.copy(n)
321
+ if pre and n.file and n.file.startswith(pre):
322
+ n.file = n.file[len(pre):]
323
+ core.nodes[nid] = n
324
+ core.edges = [e for e in graph.edges if e.source in core.nodes]
325
+ return core
326
+
327
+
328
+ def _incremental_core(args, repeat):
329
+ """Update the core of an existing repo-scoped graph at ``args.out`` (R1-C86 D1).
330
+
331
+ Returns ``(core_graph or None, info)``; None means "build the core in full" (first
332
+ build, no sidecar scope, a different target, or a graph that was not repo-scoped).
333
+ """
334
+ from codemap.freshness import read_meta
335
+ from codemap.incremental import update_graph
336
+ from codemap.scope import resolve_scope
337
+ old_meta = read_meta(args.out)
338
+ old_scope = (old_meta or {}).get("scope")
339
+ if not (Path(args.out).exists() and old_scope):
340
+ return None, {"mode": "full", "affected": []}
341
+ old_graph = store.load(args.out)
342
+ if old_graph.target != Path(args.path).resolve().name or \
343
+ not (old_graph.provenance or {}).get("roots"):
344
+ return None, {"mode": "full", "affected": []}
345
+ from codemap.extract.roots import _rel_to
346
+ consumers, docs = tuple(args.consumer or ()), tuple(args.docs or ())
347
+ new_scope = resolve_scope(args.path, consumers=consumers, docs=docs)
348
+ offset = _rel_to(Path(args.path).resolve().parent, roots_base(args.path, consumers, docs))
349
+ return update_graph(_core_subgraph(old_graph, offset), args.path, old_scope, new_scope,
350
+ deep=args.deep, repeat=repeat)
351
+
352
+
298
353
  def _watch_build_argv(args) -> list[str]:
299
354
  """The build recipe this watch replays — recorded in the sidecar, not the watch argv.
300
355
 
@@ -1120,7 +1175,8 @@ def build_parser() -> argparse.ArgumentParser:
1120
1175
  "only changed modules (R1-C9). Byte-identical to a full build on "
1121
1176
  "the fast tier; on --deep it carries the earlier build's jedi "
1122
1177
  "sample forward (docs/incremental.md). Much faster on --deep. "
1123
- "Single-package only (no --consumer/--docs).")
1178
+ "With --consumer/--docs the core is updated and the consumer and "
1179
+ "doc scans rerun in full (R1-C86).")
1124
1180
  b.add_argument("--repeat", type=int, default=1, metavar="N",
1125
1181
  help="--deep only: run the jedi layer N times and union the samples. "
1126
1182
  "One deep build is one sample (a real edge was present in 75%% "
@@ -105,9 +105,14 @@ def extract_repo(
105
105
  mode: str = "thin",
106
106
  deep: bool = False,
107
107
  repeat: int = 1,
108
+ core_graph: Graph | None = None,
108
109
  ) -> Graph:
109
110
  """Build a repo-scoped graph: core package + consumer roots + doc roots.
110
111
 
112
+ ``core_graph`` (R1-C86): an already-built core graph — the incremental path updates the
113
+ core and hands it here, so the consumer and doc scans have one implementation for
114
+ full and incremental builds.
115
+
111
116
  ``core`` is analysed exactly as the single-package extractor (griffe, plus the
112
117
  behavioral pass when ``deep``, unioned over ``repeat`` samples — R1-C45).
113
118
  ``consumers`` and ``docs`` are extra root directories scanned for references into
@@ -120,7 +125,7 @@ def extract_repo(
120
125
  if problems:
121
126
  raise ValueError("; ".join(problems))
122
127
 
123
- graph = extract(core, deep=deep, repeat=repeat)
128
+ graph = core_graph if core_graph is not None else extract(core, deep=deep, repeat=repeat)
124
129
  core_pkg = graph.target
125
130
  for node in graph.nodes.values():
126
131
  node.extras.setdefault("root", "core")
@@ -73,7 +73,12 @@ _BEHAVIOR_REF_RES = frozenset({"name", "annotation"})
73
73
  # Node-extras keys owned by the two jedi-sensitive passes (spliced for unaffected).
74
74
  # `shadows` (R1-C46) is stamped by the behavioral pass too, so an unaffected module keeps
75
75
  # it — or the fast tier's byte-identity to a full build (R1-C9) breaks on it.
76
- _BEHAVIORAL_EXTRAS = ("calls", "control", "complexity", "attr_access", "shadows")
76
+ # R1-C86: `calls_nested` (calls inside nested defs, counted on the owner) and
77
+ # `calls_shadowed` (on the module node) are stamped by the same pass and were missing,
78
+ # so every unaffected module with a nested def lost them: on a bquant commit replay, 26
79
+ # nodes differed from a full build. A guard now derives the set from the passes.
80
+ _BEHAVIORAL_EXTRAS = ("calls", "control", "complexity", "attr_access", "shadows",
81
+ "calls_nested", "calls_shadowed")
77
82
  # Old edge types whose target landing in a changed/removed module makes the source
78
83
  # module stale (it must re-resolve). Only the spliced passes matter here — and the serve
79
84
  # layer reads the same set to know which ops answer from a spliced class (R1-C44).
@@ -84,7 +89,26 @@ _DEP_EDGE_TYPES = SPLICED_EDGE_TYPES
84
89
  _FULL_FALLBACK_FRACTION = 0.5
85
90
 
86
91
 
87
- def _path_to_module(rel_path: str, target_pkg: str) -> str | None:
92
+ def _package_prefix(package_path, scope: dict, target_pkg: str) -> str:
93
+ """The package's path relative to the scope root (R1-C86 D0).
94
+
95
+ In git mode the scope root is the repository root, so ``research/shared`` or
96
+ ``src/pkg``; in fs mode it is the package's parent, so just ``pkg``. Falls back to
97
+ the package name when the root is unknown or the package is not under it.
98
+ """
99
+ import os
100
+ root = scope.get("root") if scope else None
101
+ if root:
102
+ try:
103
+ rel = os.path.relpath(Path(package_path).resolve(), Path(root).resolve())
104
+ except ValueError:
105
+ rel = ""
106
+ if rel and not rel.startswith(".."):
107
+ return rel.replace("\\", "/")
108
+ return target_pkg
109
+
110
+
111
+ def _path_to_module(rel_path: str, target_pkg: str, prefix: str | None = None) -> str | None:
88
112
  """Map a scope file path to a package module id, or None if it's not package code.
89
113
 
90
114
  ``bquant/analysis/pipeline.py`` → ``bquant.analysis.pipeline``;
@@ -95,8 +119,13 @@ def _path_to_module(rel_path: str, target_pkg: str) -> str | None:
95
119
  p = rel_path.replace("\\", "/")
96
120
  if not p.endswith(".py"):
97
121
  return None
98
- parts = p.split("/")
99
- if not parts or parts[0] != target_pkg:
122
+ prefix = prefix or target_pkg
123
+ # R1-C86 D0: the scope path is relative to the scope root (the git root in git mode),
124
+ # and the package may sit below it — `research/shared/m.py` is `shared.m`.
125
+ if p != prefix + ".py" and not p.startswith(prefix + "/"):
126
+ return None
127
+ parts = [target_pkg] + p[len(prefix) + 1:].split("/") if p.startswith(prefix + "/") else []
128
+ if not parts:
100
129
  return None
101
130
  if parts[-1] == "__init__.py":
102
131
  parts = parts[:-1]
@@ -143,6 +172,11 @@ def _affected_modules(old_graph, new_graph, base_mods, changed_removed, module_o
143
172
  def _splice_unaffected(new_graph, old_graph, unaffected, module_of) -> None:
144
173
  """Copy the two jedi passes' output for unaffected modules from the old graph."""
145
174
  for e in old_graph.edges:
175
+ # R1-C86: an edge from a node that no longer exists (a removed module's function)
176
+ # resolves, by longest prefix, to the package's root module — which is unaffected —
177
+ # and was copied forward. A full build has no such edge.
178
+ if e.source not in new_graph.nodes:
179
+ continue
146
180
  keep = False
147
181
  if e.type == "calls" and e.extras.get("resolution") in _BEHAVIOR_CALL_RES:
148
182
  keep = module_of(e.source) in unaffected
@@ -225,9 +259,10 @@ def update_graph(old_graph: Graph, package_path, old_scope: dict, new_scope: dic
225
259
  {"mode": "full", "affected": [], "reason": reason}
226
260
 
227
261
  d = diff_scopes(old_scope, new_scope)
228
- changed = {m for p in d["changed"] if (m := _path_to_module(p, target_pkg))}
229
- added = {m for p in d["added"] if (m := _path_to_module(p, target_pkg))}
230
- removed = {m for p in d["removed"] if (m := _path_to_module(p, target_pkg))}
262
+ prefix = _package_prefix(package_path, new_scope, target_pkg)
263
+ changed = {m for p in d["changed"] if (m := _path_to_module(p, target_pkg, prefix))}
264
+ added = {m for p in d["added"] if (m := _path_to_module(p, target_pkg, prefix))}
265
+ removed = {m for p in d["removed"] if (m := _path_to_module(p, target_pkg, prefix))}
231
266
 
232
267
  # No package .py file changed → a single-package graph is unaffected (doc/consumer
233
268
  # edits don't touch it). Return the old graph untouched.
@@ -267,6 +302,10 @@ def update_graph(old_graph: Graph, package_path, old_scope: dict, new_scope: dic
267
302
  stats = {"runs": 1}
268
303
  unaffected = module_ids - affected
269
304
  _splice_unaffected(graph, old_graph, unaffected, module_of)
305
+ # R1-C86 D2: the Protocol fan-out (R1-C81 D2) ran inside add_behavioral_layer, before
306
+ # the spliced deep calls existed; run it again so they fan out too (idempotent).
307
+ from codemap.extract.dispatch import add_protocol_dispatch
308
+ add_protocol_dispatch(graph)
270
309
  if repeat > 1:
271
310
  # `unstable` describes the artifact a reader holds, not the part this tick
272
311
  # touched: recount over recomputed and spliced edges alike.
@@ -132,7 +132,10 @@ SCHEMA_VERSION = "0.13"
132
132
  # cached `--currency-ttl` seconds, `checked_seconds_ago`); `stats` shows it beside
133
133
  # `freshness` (R1-C85, docs/design/mcp_graph_currency.md); `review` names the doc pages a
134
134
  # diff changes (`changed_docs`, R1-C89, docs/design/review_docs.md).
135
- ANSWER_FORMAT = 9
135
+ # 10 — `currency` says how it was checked (`via`: `recipe` or the graph's provenance roots,
136
+ # R1-C90), so a graph built elsewhere is `current`/`behind` where it was `unknown`; repo-scoped
137
+ # `build --incremental` is applied (R1-C86).
138
+ ANSWER_FORMAT = 10
136
139
 
137
140
  # Closed vocabulary of edge types (R1-C7). Node ``kind`` is deliberately an OPEN set
138
141
  # (DESIGN §2 — new entity kinds may appear), but edges are TYPED: every relationship
@@ -33,7 +33,45 @@ def recipe_scope_args(argv: list[str]) -> tuple[str, list[str], list[str]]:
33
33
  return ns.path, ns.consumer, ns.docs
34
34
 
35
35
 
36
- def graph_currency(graph_path: str, graph_scope_id: str | None) -> dict:
36
+ def _via_roots(graph_scope_id: str, roots: dict | None, target: str | None,
37
+ base: str | None, why: str) -> dict:
38
+ """R1-C90: no usable recipe — check from the graph's own recorded roots under ``base``.
39
+
40
+ A graph built on another machine records its roots relative to its path base
41
+ (R1-C25/R1-C31) and its input identity; the scope id depends on file content and
42
+ relative paths, not on where the tree lives, so the same roots under this directory
43
+ give a comparable id.
44
+ """
45
+ from pathlib import Path
46
+ b = Path(base or os.getcwd())
47
+ if roots:
48
+ core = b / roots.get("core", "")
49
+ consumers = tuple(b / c for c in roots.get("consumers") or ())
50
+ docs = tuple(b / d for d in roots.get("docs") or ())
51
+ elif target:
52
+ core, consumers, docs = b / target, (), ()
53
+ else:
54
+ return {"status": "unknown", "reason": why}
55
+ if not core.is_dir() or any(not p.is_dir() for p in (*consumers, *docs)):
56
+ return {"status": "unknown",
57
+ "reason": f"{why}; the graph's roots are not under {b} "
58
+ "(run from the directory the graph's paths are relative to, or "
59
+ "pass --source-root)"}
60
+ try:
61
+ from codemap.scope import resolve_scope
62
+ now = resolve_scope(str(core), consumers=tuple(map(str, consumers)),
63
+ docs=tuple(map(str, docs)))
64
+ except (Exception, SystemExit) as exc:
65
+ return {"status": "unknown", "reason": f"{why}; resolving the roots failed ({exc})"}
66
+ via = f"provenance roots under {b}"
67
+ if now["scope_id"] == graph_scope_id:
68
+ return {"status": "current", "scope_id": graph_scope_id, "via": via}
69
+ return {"status": "behind", "recorded": graph_scope_id, "current": now["scope_id"],
70
+ "via": via}
71
+
72
+
73
+ def graph_currency(graph_path: str, graph_scope_id: str | None, *, roots: dict | None = None,
74
+ target: str | None = None, base: str | None = None) -> dict:
37
75
  """Is the graph at ``graph_path`` the tree it would be judged as? (R1-C70)
38
76
 
39
77
  ``{"status": "current" | "behind" | "unknown", …}``. Design ``check_graph_currency.md`` D1:
@@ -48,10 +86,12 @@ def graph_currency(graph_path: str, graph_scope_id: str | None) -> dict:
48
86
  "reason": "the graph records no input identity (`provenance.scope_id`)"}
49
87
  meta = read_meta(graph_path)
50
88
  if not meta or not meta.get("argv"):
51
- return {"status": "unknown", "reason": "no build recipe beside the graph"}
89
+ return _via_roots(graph_scope_id, roots, target, base,
90
+ "no build recipe beside the graph")
52
91
  cwd = meta.get("cwd")
53
92
  if not cwd or not os.path.isdir(cwd):
54
- return {"status": "unknown", "reason": f"the recorded build directory is gone ({cwd})"}
93
+ return _via_roots(graph_scope_id, roots, target, base,
94
+ f"the recorded build directory is gone ({cwd})")
55
95
  try:
56
96
  from codemap.scope import diff_scopes, resolve_scope
57
97
  path, consumers, docs = recipe_scope_args(meta["argv"])
@@ -61,7 +101,8 @@ def graph_currency(graph_path: str, graph_scope_id: str | None) -> dict:
61
101
  except (Exception, SystemExit) as exc: # argparse exits on a recipe it cannot read
62
102
  return {"status": "unknown", "reason": f"the recorded scope could not be resolved ({exc})"}
63
103
  if now["scope_id"] == graph_scope_id:
64
- return {"status": "current", "scope_id": graph_scope_id}
104
+ return {"status": "current", "scope_id": graph_scope_id, "via": "recipe"}
65
105
  d = diff_scopes(meta.get("scope") or {}, now)
66
106
  return {"status": "behind", "recorded": graph_scope_id, "current": now["scope_id"],
67
- "added": len(d["added"]), "removed": len(d["removed"]), "changed": len(d["changed"])}
107
+ "added": len(d["added"]), "removed": len(d["removed"]), "changed": len(d["changed"]),
108
+ "via": "recipe"}
@@ -513,8 +513,10 @@ class Session:
513
513
  "compare against"}
514
514
  else:
515
515
  from codemap.serve.currency import graph_currency
516
- res = graph_currency(self.graph_path,
517
- (self.graph.provenance or {}).get("scope_id"))
516
+ prov = self.graph.provenance or {}
517
+ res = graph_currency(self.graph_path, prov.get("scope_id"),
518
+ roots=prov.get("roots"), target=self.graph.target,
519
+ base=self.source_root)
518
520
  if res.get("status") == "behind":
519
521
  res["hint"] = ("the source tree changed since this graph was built — "
520
522
  "rebuild it, then `reload` (or run `serve --watch`)")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.33
3
+ Version: 0.0.34
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, **1249 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1264 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 &
@@ -157,9 +157,11 @@ tests/test_r1c82_review_changed_lines.py
157
157
  tests/test_r1c83_foreign_graph_paths.py
158
158
  tests/test_r1c84_missing_roots.py
159
159
  tests/test_r1c85_mcp_graph_currency.py
160
+ tests/test_r1c86_incremental_repo_scope.py
160
161
  tests/test_r1c87_review_path_base.py
161
162
  tests/test_r1c89_review_docs.py
162
163
  tests/test_r1c8_deadcode.py
164
+ tests/test_r1c90_currency_without_recipe.py
163
165
  tests/test_r1c9_incremental.py
164
166
  tests/test_scip_export.py
165
167
  tests/test_scope.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.33"
12
+ version = "0.0.34"
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
@@ -181,14 +181,19 @@ def test_the_incremental_help_names_the_tier(capsys):
181
181
  assert "fast tier" in out and "jedi sample" in out
182
182
 
183
183
 
184
- def test_incremental_with_a_consumer_root_is_refused_out_loud(pkg, tmp_path, capsys):
184
+ def test_incremental_with_a_consumer_root_is_applied_and_says_what_it_did(pkg, tmp_path, capsys):
185
+ """R1-C44 stated a boundary here ("not applied: repo-scoped builds are always full").
186
+ R1-C86 lifted it: the core is updated incrementally and the scans rerun. What R1-C44
187
+ guarded still holds — the flag is never swallowed: the build names its mode."""
185
188
  cons = tmp_path / "tests"
186
189
  cons.mkdir()
187
190
  (cons / "test_x.py").write_text("from lonelypkg.core import helper\n\ndef test_h():\n helper()\n")
188
191
  out = tmp_path / "graph.json"
189
192
  assert cli.main(["build", str(pkg), "--incremental", "--consumer", str(cons), "-o", str(out)]) == 0
190
193
  err = capsys.readouterr().err
191
- assert "--incremental was not applied" in err and "repo-scoped" in err
194
+ assert "--incremental was not applied" not in err and "[incremental] full" in err
195
+ assert cli.main(["build", str(pkg), "--incremental", "--consumer", str(cons), "-o", str(out)]) == 0
196
+ assert "[incremental] unchanged" in capsys.readouterr().err
192
197
 
193
198
 
194
199
  def test_the_build_help_says_ids_start_with_the_directory_name(capsys):
@@ -0,0 +1,195 @@
1
+ """R1-C86 — incremental builds for repo-scoped graphs, and for a package that is not at the git root.
2
+
3
+ Design `docs/design/incremental_repo_scope.md` (pre-registered 3cb2c9c).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import shutil
10
+ import subprocess
11
+ from pathlib import Path
12
+
13
+ import pytest
14
+
15
+ from codemap.cli import main
16
+
17
+ pytestmark = pytest.mark.skipif(shutil.which("git") is None, reason="needs git")
18
+
19
+
20
+ def _git_repo(root: Path, files: dict[str, str]) -> Path:
21
+ for rel, body in files.items():
22
+ p = root / rel
23
+ p.parent.mkdir(parents=True, exist_ok=True)
24
+ p.write_text(body)
25
+ subprocess.run(["git", "init", "-q"], cwd=root, check=True)
26
+ subprocess.run(["git", "add", "."], cwd=root, check=True)
27
+ subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "a"],
28
+ cwd=root, check=True)
29
+ return root
30
+
31
+
32
+ def _modules(prefix: str, n: int = 6) -> dict[str, str]:
33
+ out = {f"{prefix}/__init__.py": ""}
34
+ for i in range(1, n + 1):
35
+ out[f"{prefix}/m{i}.py"] = f"def f{i}():\n return {i}\n\n\ndef g{i}():\n return f{i}()\n"
36
+ return out
37
+
38
+
39
+ def _same(a: Path, b: Path) -> bool:
40
+ x, y = json.loads(a.read_text()), json.loads(b.read_text())
41
+ for g in (x, y):
42
+ g["provenance"].pop("incremental", None)
43
+ return x == y
44
+
45
+
46
+ def _mode(capsys) -> str:
47
+ err = capsys.readouterr().err
48
+ line = next((ln for ln in err.splitlines() if ln.startswith("[incremental]")), "")
49
+ return line.split()[1].rstrip(":") if line else ""
50
+
51
+
52
+ # -- D0 ----------------------------------------------------------------------
53
+
54
+ @pytest.mark.parametrize("prefix", ["research/shared", "src/shared"])
55
+ def test_D0_a_package_below_the_git_root_sees_its_edit(tmp_path, monkeypatch, capsys, prefix):
56
+ root = _git_repo(tmp_path, _modules(prefix))
57
+ monkeypatch.chdir(root)
58
+ pkg = prefix
59
+ assert main(["build", pkg, "-o", "i.json"]) == 0
60
+ (root / prefix / "m3.py").write_text("def f3():\n return 33\n\n\ndef g3():\n return f3()\n")
61
+ capsys.readouterr()
62
+ assert main(["build", pkg, "--incremental", "-o", "i.json"]) == 0
63
+ assert _mode(capsys) == "incremental" # 0.0.33: "unchanged" — the edit was not seen
64
+ assert main(["build", pkg, "-o", "f.json"]) == 0
65
+ assert _same(root / "i.json", root / "f.json")
66
+
67
+
68
+ # -- D1 ----------------------------------------------------------------------
69
+
70
+ REPO = {**_modules("src/pkg"),
71
+ "tests/test_m1.py": "from pkg.m1 import f1\n\n\ndef test_f1():\n assert f1() == 1\n",
72
+ "docs/m1.md": "# m1\n\nUse `pkg.m1.f1`.\n"}
73
+ BUILD = ["build", "src/pkg", "--consumer", "tests", "--docs", "docs", "--mode", "full"]
74
+
75
+
76
+ @pytest.fixture
77
+ def repo(tmp_path, monkeypatch):
78
+ root = _git_repo(tmp_path, REPO)
79
+ monkeypatch.chdir(root)
80
+ assert main(BUILD + ["-o", "i.json"]) == 0
81
+ return root
82
+
83
+
84
+ EDITS = {
85
+ "core-edit": (lambda r: (r / "src/pkg/m3.py").write_text("def f3():\n return 9\n"), "incremental"),
86
+ "consumer-edit": (lambda r: (r / "tests/test_m1.py").open("a").write(
87
+ "\n\ndef test_again():\n assert f1()\n"), "unchanged"),
88
+ "doc-edit": (lambda r: (r / "docs/m1.md").open("a").write("\nAlso `pkg.m2.f2`.\n"), "unchanged"),
89
+ "core-add": (lambda r: (r / "src/pkg/m7.py").write_text(
90
+ "from pkg.m1 import f1\n\n\ndef k():\n return f1()\n"), "incremental"),
91
+ "core-remove": (lambda r: (r / "src/pkg/m6.py").unlink(), "incremental"),
92
+ }
93
+
94
+
95
+ @pytest.mark.parametrize("case", sorted(EDITS))
96
+ def test_E2_a_repo_scoped_incremental_build_equals_a_full_one(repo, capsys, case):
97
+ edit, mode = EDITS[case]
98
+ edit(repo)
99
+ capsys.readouterr()
100
+ assert main(BUILD + ["--incremental", "-o", "i.json"]) == 0
101
+ err_mode = _mode(capsys)
102
+ assert err_mode == mode, case
103
+ assert main(BUILD + ["-o", "f.json"]) == 0
104
+ assert _same(repo / "i.json", repo / "f.json"), case
105
+ assert json.loads((repo / "i.json").read_text())["provenance"].get("incremental") is True
106
+
107
+
108
+ def test_D1_the_old_note_is_gone(repo, capsys):
109
+ capsys.readouterr()
110
+ main(BUILD + ["--incremental", "-o", "i.json"])
111
+ assert "--incremental was not applied" not in capsys.readouterr().err
112
+
113
+
114
+ # -- D2 ----------------------------------------------------------------------
115
+
116
+ MENU = '''from typing import Protocol
117
+
118
+
119
+ class P(Protocol):
120
+ def band(self, k): ...
121
+
122
+
123
+ class A:
124
+ def band(self, k):
125
+ return k
126
+
127
+
128
+ class B:
129
+ def band(self, k):
130
+ return -k
131
+
132
+
133
+ class Spec:
134
+ def build(self) -> P:
135
+ return A()
136
+ '''
137
+
138
+
139
+ def test_D2_spliced_deep_callers_keep_their_protocol_fan_out(tmp_path, monkeypatch, capsys):
140
+ files = {"pkg/__init__.py": "", "pkg/menu.py": MENU,
141
+ "pkg/use.py": "from pkg.menu import Spec\n\n\ndef run(spec: Spec):\n return spec.build().band(1)\n"}
142
+ files.update({f"pkg/x{i}.py": f"def x{i}():\n return {i}\n" for i in range(1, 6)})
143
+ root = _git_repo(tmp_path, files)
144
+ monkeypatch.chdir(root)
145
+ assert main(["build", "pkg", "--deep", "-o", "g.json"]) == 0
146
+ fan = lambda: {(e["source"], e["target"]) for e in json.loads((root / "g.json").read_text())["edges"]
147
+ if e["type"] == "calls" and e.get("extras", {}).get("resolution") == "protocol"}
148
+ before = fan()
149
+ assert ("pkg.use.run", "pkg.menu.B.band") in before
150
+ (root / "pkg" / "x3.py").write_text("def x3():\n return 33\n") # pkg.use untouched
151
+ capsys.readouterr()
152
+ assert main(["build", "pkg", "--deep", "--incremental", "-o", "g.json"]) == 0
153
+ assert _mode(capsys) == "incremental"
154
+ assert ("pkg.use.run", "pkg.menu.B.band") in fan()
155
+
156
+
157
+ # -- found by the bquant replay (E3): node extras the splice did not carry ---------
158
+
159
+ def test_every_extras_key_the_jedi_passes_stamp_is_spliced(tmp_path):
160
+ """Derived, not listed: whatever add_behavior / add_attrflow add to node extras must be
161
+ in the splice set, or an unaffected module silently loses it (R1-C86 E3)."""
162
+ from codemap.extract.attrflow import add_attrflow
163
+ from codemap.extract.behavior import add_behavior
164
+ from codemap.extract.griffe_extractor import build_structural
165
+ from codemap.incremental import _BEHAVIORAL_EXTRAS
166
+ pkg = tmp_path / "pkg"
167
+ pkg.mkdir()
168
+ (pkg / "__init__.py").write_text("")
169
+ (pkg / "m.py").write_text(
170
+ "import os\n\n\nclass C:\n size = 1\n\n def go(self):\n return self.size\n\n\n"
171
+ "def outer():\n def inner():\n return os.getcwd()\n return inner()\n\n\n"
172
+ "def twice():\n return len([1])\n\n\ndef twice():\n return 2\n\n\n"
173
+ "if True:\n print(len([]))\n")
174
+ graph, root, name, sp = build_structural(str(pkg))
175
+ before = {nid: set(n.extras) for nid, n in graph.nodes.items()}
176
+ add_behavior(graph, root, name, deep=False, search_path=sp)
177
+ add_attrflow(graph, root, name, deep=False, search_path=sp)
178
+ stamped = set().union(*(set(n.extras) - before.get(nid, set()) for nid, n in graph.nodes.items()))
179
+ assert {"calls_nested", "calls_shadowed", "calls"} <= stamped # the fixture exercises them
180
+ assert stamped <= set(_BEHAVIORAL_EXTRAS), stamped - set(_BEHAVIORAL_EXTRAS)
181
+
182
+
183
+ def test_an_unaffected_module_with_a_nested_def_survives_an_incremental_build(tmp_path, monkeypatch, capsys):
184
+ files = _modules("pkg")
185
+ files["pkg/nested.py"] = ("import os\n\n\ndef outer():\n def inner():\n return os.getcwd()\n"
186
+ " return inner()\n")
187
+ root = _git_repo(tmp_path, files)
188
+ monkeypatch.chdir(root)
189
+ assert main(["build", "pkg", "-o", "i.json"]) == 0
190
+ (root / "pkg" / "m2.py").write_text("def f2():\n return 22\n")
191
+ capsys.readouterr()
192
+ assert main(["build", "pkg", "--incremental", "-o", "i.json"]) == 0
193
+ assert _mode(capsys) == "incremental"
194
+ assert main(["build", "pkg", "-o", "f.json"]) == 0
195
+ assert _same(root / "i.json", root / "f.json")