codmap 0.0.34__tar.gz → 0.0.36__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 (172) hide show
  1. {codmap-0.0.34 → codmap-0.0.36}/PKG-INFO +2 -2
  2. {codmap-0.0.34 → codmap-0.0.36}/README.md +1 -1
  3. {codmap-0.0.34 → codmap-0.0.36}/codemap/cli.py +36 -2
  4. {codmap-0.0.34 → codmap-0.0.36}/codemap/diagnostics.py +55 -1
  5. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/griffe_extractor.py +2 -1
  6. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/roots.py +2 -0
  7. {codmap-0.0.34 → codmap-0.0.36}/codemap/incremental.py +2 -0
  8. {codmap-0.0.34 → codmap-0.0.36}/codemap/model.py +31 -1
  9. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/currency.py +6 -0
  10. {codmap-0.0.34 → codmap-0.0.36}/codmap.egg-info/PKG-INFO +2 -2
  11. {codmap-0.0.34 → codmap-0.0.36}/codmap.egg-info/SOURCES.txt +2 -0
  12. {codmap-0.0.34 → codmap-0.0.36}/pyproject.toml +1 -1
  13. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c39_edge_resolution.py +20 -0
  14. codmap-0.0.36/tests/test_r1c91_route_vocabulary.py +150 -0
  15. codmap-0.0.36/tests/test_r1c92_sidecar_pair.py +126 -0
  16. {codmap-0.0.34 → codmap-0.0.36}/LICENSE +0 -0
  17. {codmap-0.0.34 → codmap-0.0.36}/codemap/__init__.py +0 -0
  18. {codmap-0.0.34 → codmap-0.0.36}/codemap/apidiff.py +0 -0
  19. {codmap-0.0.34 → codmap-0.0.36}/codemap/arch.py +0 -0
  20. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/__init__.py +0 -0
  21. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/attrflow.py +0 -0
  22. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/behavior.py +0 -0
  23. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/dataflow.py +0 -0
  24. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/dispatch.py +0 -0
  25. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/gsource.py +0 -0
  26. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/probe.py +0 -0
  27. {codmap-0.0.34 → codmap-0.0.36}/codemap/extract/union.py +0 -0
  28. {codmap-0.0.34 → codmap-0.0.36}/codemap/freshness.py +0 -0
  29. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/__init__.py +0 -0
  30. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/base.py +0 -0
  31. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/cocoindex.py +0 -0
  32. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/gate.py +0 -0
  33. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/gitnexus.py +0 -0
  34. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/registry.py +0 -0
  35. {codmap-0.0.34 → codmap-0.0.36}/codemap/integrations/transport.py +0 -0
  36. {codmap-0.0.34 → codmap-0.0.36}/codemap/provenance.py +0 -0
  37. {codmap-0.0.34 → codmap-0.0.36}/codemap/query.py +0 -0
  38. {codmap-0.0.34 → codmap-0.0.36}/codemap/scope.py +0 -0
  39. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/__init__.py +0 -0
  40. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/_scip_pb2.py +0 -0
  41. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/api_surface.py +0 -0
  42. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/apidiff.py +0 -0
  43. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/architecture.py +0 -0
  44. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/audit.py +0 -0
  45. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/check.py +0 -0
  46. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/ctags.py +0 -0
  47. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/impact.py +0 -0
  48. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/limits.py +0 -0
  49. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/livingdocs.py +0 -0
  50. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/mcp_server.py +0 -0
  51. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/mermaid.py +0 -0
  52. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/pack.py +0 -0
  53. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/rag.py +0 -0
  54. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/review.py +0 -0
  55. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/scip.py +0 -0
  56. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/semantic.py +0 -0
  57. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/server.py +0 -0
  58. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/session.py +0 -0
  59. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/subsystems.py +0 -0
  60. {codmap-0.0.34 → codmap-0.0.36}/codemap/serve/vault.py +0 -0
  61. {codmap-0.0.34 → codmap-0.0.36}/codemap/store.py +0 -0
  62. {codmap-0.0.34 → codmap-0.0.36}/codemap/tomlio.py +0 -0
  63. {codmap-0.0.34 → codmap-0.0.36}/codemap/watch.py +0 -0
  64. {codmap-0.0.34 → codmap-0.0.36}/codmap.egg-info/dependency_links.txt +0 -0
  65. {codmap-0.0.34 → codmap-0.0.36}/codmap.egg-info/entry_points.txt +0 -0
  66. {codmap-0.0.34 → codmap-0.0.36}/codmap.egg-info/requires.txt +0 -0
  67. {codmap-0.0.34 → codmap-0.0.36}/codmap.egg-info/top_level.txt +0 -0
  68. {codmap-0.0.34 → codmap-0.0.36}/setup.cfg +0 -0
  69. {codmap-0.0.34 → codmap-0.0.36}/tests/test_epistemic.py +0 -0
  70. {codmap-0.0.34 → codmap-0.0.36}/tests/test_gitnexus_router.py +0 -0
  71. {codmap-0.0.34 → codmap-0.0.36}/tests/test_impact_depth.py +0 -0
  72. {codmap-0.0.34 → codmap-0.0.36}/tests/test_integrations.py +0 -0
  73. {codmap-0.0.34 → codmap-0.0.36}/tests/test_issue3_serve_freshness.py +0 -0
  74. {codmap-0.0.34 → codmap-0.0.36}/tests/test_livingdocs.py +0 -0
  75. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m0_api_surface.py +0 -0
  76. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m11_argcontract.py +0 -0
  77. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m12_dataflow.py +0 -0
  78. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m15_review.py +0 -0
  79. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m16_architecture.py +0 -0
  80. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m17_mcp.py +0 -0
  81. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m18_freshness.py +0 -0
  82. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m1_5_semantics.py +0 -0
  83. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m1_query.py +0 -0
  84. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m2_views.py +0 -0
  85. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m32_watch.py +0 -0
  86. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m3_serve.py +0 -0
  87. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m4_behavior.py +0 -0
  88. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m5_deep.py +0 -0
  89. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m6_repo_scope.py +0 -0
  90. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m7_dispatch.py +0 -0
  91. {codmap-0.0.34 → codmap-0.0.36}/tests/test_m9_family.py +0 -0
  92. {codmap-0.0.34 → codmap-0.0.36}/tests/test_pack_honesty.py +0 -0
  93. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  94. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c13_grep_vs_graph.py +0 -0
  95. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c16_semantic.py +0 -0
  96. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c20_attribute_edges.py +0 -0
  97. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c21_flat_layout.py +0 -0
  98. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c22_source_visible_refs.py +0 -0
  99. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c23_hard_python.py +0 -0
  100. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c24_test_mapping.py +0 -0
  101. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c25_provenance.py +0 -0
  102. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c26_deep_union.py +0 -0
  103. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c27_config_honesty.py +0 -0
  104. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c28_limit_envelope.py +0 -0
  105. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c29_lazy_imports.py +0 -0
  106. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c2_ctags.py +0 -0
  107. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c30_local_import_calls.py +0 -0
  108. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c30f1_reexport_calls.py +0 -0
  109. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c30f2_check_scope.py +0 -0
  110. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c31_path_origin.py +0 -0
  111. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c32_report_json.py +0 -0
  112. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c33_query_signature.py +0 -0
  113. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c34_signature_kinds.py +0 -0
  114. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c35_contract_location.py +0 -0
  115. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c36_target_resolution.py +0 -0
  116. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c37_rule_mutation.py +0 -0
  117. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c38_tool_drift.py +0 -0
  118. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c3_arch_contract.py +0 -0
  119. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c3_dogfood.py +0 -0
  120. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c40_flow_reach.py +0 -0
  121. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c41_scope_membership.py +0 -0
  122. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c42_deep_tier_stability.py +0 -0
  123. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c43_incremental_splice.py +0 -0
  124. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c44_absent_answers.py +0 -0
  125. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c45_repeat_union.py +0 -0
  126. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c46_shadowed_definitions.py +0 -0
  127. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c47_incremental_resample.py +0 -0
  128. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c48_type_checking_imports.py +0 -0
  129. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c49_type_only_cycles.py +0 -0
  130. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c4_complexity.py +0 -0
  131. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c50_flow_entry_points.py +0 -0
  132. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c53_narrowing_declared.py +0 -0
  133. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c54_deterministic_rendering.py +0 -0
  134. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c55_override_grade.py +0 -0
  135. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c56_stub_files.py +0 -0
  136. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c57_facade_package.py +0 -0
  137. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c58_cycle_tangles.py +0 -0
  138. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c59_completeness_drop.py +0 -0
  139. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c5_apidiff.py +0 -0
  140. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c60_nested_definitions.py +0 -0
  141. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c62_phantom_rules.py +0 -0
  142. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c63_answer_format.py +0 -0
  143. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c64_dependency_probe.py +0 -0
  144. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c66_pack_direction.py +0 -0
  145. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c68_dotted_imports.py +0 -0
  146. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c69_contract_validation.py +0 -0
  147. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c6_pack.py +0 -0
  148. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c70_check_graph_currency.py +0 -0
  149. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  150. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  151. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c73_cli_version.py +0 -0
  152. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c74_call_site_conservation.py +0 -0
  153. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c75_reexported_class_calls.py +0 -0
  154. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c76_contract_table_typo.py +0 -0
  155. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c77_gate_probe_battery.py +0 -0
  156. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c78_forbidden_chains.py +0 -0
  157. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c7_edge_vocab.py +0 -0
  158. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c80_tests_through_helpers.py +0 -0
  159. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c81_protocol_dispatch.py +0 -0
  160. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c82_review_changed_lines.py +0 -0
  161. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  162. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c84_missing_roots.py +0 -0
  163. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  164. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  165. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c87_review_path_base.py +0 -0
  166. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c89_review_docs.py +0 -0
  167. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c8_deadcode.py +0 -0
  168. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c90_currency_without_recipe.py +0 -0
  169. {codmap-0.0.34 → codmap-0.0.36}/tests/test_r1c9_incremental.py +0 -0
  170. {codmap-0.0.34 → codmap-0.0.36}/tests/test_scip_export.py +0 -0
  171. {codmap-0.0.34 → codmap-0.0.36}/tests/test_scope.py +0 -0
  172. {codmap-0.0.34 → codmap-0.0.36}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.34
3
+ Version: 0.0.36
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, **1264 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1278 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, **1264 tests with no failures on
11
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1278 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 &
@@ -99,10 +99,19 @@ def _graph_from(args):
99
99
  graph = store.load(args.graph)
100
100
  if getattr(args, "func", None) not in (_cmd_check, _cmd_serve):
101
101
  _warn_if_behind(args.graph, graph, args)
102
+ _warn_if_newer_tool(args.graph, graph)
102
103
  return graph
103
104
  raise SystemExit("error: need --graph <file> or --build <path>")
104
105
 
105
106
 
107
+ def _warn_if_newer_tool(path: str, graph) -> None:
108
+ """R1-C91 D4: a cold read of a graph from a newer codemap says so, once, on stderr."""
109
+ from codemap.diagnostics import newer_tool_diagnostic
110
+ d = newer_tool_diagnostic(graph)
111
+ if d:
112
+ print(f"[warning] {path}: {d['message']} {d['consequence']}", file=sys.stderr)
113
+
114
+
106
115
  def _warn_if_behind(path: str, graph, args_for_currency=None) -> None:
107
116
  """R1-C85 D4: a cold read of a graph behind its tree says so, once, on stderr.
108
117
 
@@ -210,8 +219,10 @@ def _cmd_build(args) -> int:
210
219
  cwd=os.getcwd(), target=graph.target, scope=scope,
211
220
  roots_base=base)
212
221
  if incr_info is not None:
222
+ # R1-C92: a full build that had a reason says it — computed, never shown, before.
223
+ why = f" ({incr_info['reason']})" if incr_info.get("reason") else ""
213
224
  print(f"[incremental] {incr_info['mode']}: "
214
- f"{len(incr_info['affected'])} module(s) recomputed", file=sys.stderr)
225
+ f"{len(incr_info['affected'])} module(s) recomputed{why}", file=sys.stderr)
215
226
  print(args.out)
216
227
  else:
217
228
  print(store.dumps(graph))
@@ -294,8 +305,12 @@ def _incremental_build(args):
294
305
  return extract(args.path, deep=args.deep, repeat=getattr(args, "repeat", None) or 1), \
295
306
  {"mode": "full", "affected": []}
296
307
  old_graph = store.load(args.out)
297
- new_scope = resolve_scope(args.path)
298
308
  repeat = getattr(args, "repeat", None) or 1
309
+ why = _sidecar_mismatch(old_meta, old_graph)
310
+ if why:
311
+ return extract(args.path, deep=args.deep, repeat=repeat), \
312
+ {"mode": "full", "affected": [], "reason": why}
313
+ new_scope = resolve_scope(args.path)
299
314
  if old_graph.target != Path(args.path).resolve().name:
300
315
  return extract(args.path, deep=args.deep, repeat=repeat), {"mode": "full", "affected": []}
301
316
  return update_graph(old_graph, args.path, old_scope, new_scope, deep=args.deep,
@@ -325,6 +340,22 @@ def _core_subgraph(graph, offset: str = ""):
325
340
  return core
326
341
 
327
342
 
343
+ def _sidecar_mismatch(old_meta, old_graph) -> str | None:
344
+ """R1-C92 D1: the sidecar is the incremental baseline only if it describes this graph.
345
+
346
+ `meta.scope` and the graph's `provenance.scope_id` are written by one build and are
347
+ equal for a pair that belongs together. A graph replaced from outside (an atomic `mv`
348
+ of a fresh build) with the old sidecar left beside it made the next incremental build
349
+ diff against another tree: a graph 0 next to meta 1 missed every edit between 0 and 1
350
+ and still said `incremental`.
351
+ """
352
+ meta_id = ((old_meta or {}).get("scope") or {}).get("scope_id")
353
+ graph_id = (old_graph.provenance or {}).get("scope_id")
354
+ if meta_id and graph_id and meta_id != graph_id:
355
+ return "the sidecar describes another build than the graph"
356
+ return None
357
+
358
+
328
359
  def _incremental_core(args, repeat):
329
360
  """Update the core of an existing repo-scoped graph at ``args.out`` (R1-C86 D1).
330
361
 
@@ -342,6 +373,9 @@ def _incremental_core(args, repeat):
342
373
  if old_graph.target != Path(args.path).resolve().name or \
343
374
  not (old_graph.provenance or {}).get("roots"):
344
375
  return None, {"mode": "full", "affected": []}
376
+ why = _sidecar_mismatch(old_meta, old_graph)
377
+ if why:
378
+ return None, {"mode": "full", "affected": [], "reason": why}
345
379
  from codemap.extract.roots import _rel_to
346
380
  consumers, docs = tuple(args.consumer or ()), tuple(args.docs or ())
347
381
  new_scope = resolve_scope(args.path, consumers=consumers, docs=docs)
@@ -24,6 +24,7 @@ MODULE_COUNT_MISMATCH = "module_count_mismatch"
24
24
  SCOPE_MEMBERSHIP = "scope_membership"
25
25
  DEEP_TIER_UNSTABLE = "deep_tier_unstable"
26
26
  INCREMENTAL_DEEP_SPLICE = "incremental_deep_splice"
27
+ GRAPH_FROM_NEWER_TOOL = "graph_from_newer_tool"
27
28
 
28
29
  #: A ``warning`` invalidates the conclusions a surface draws from the graph — read them as
29
30
  #: unknown. A ``note`` states a fact about how the graph was built and invalidates nothing.
@@ -370,13 +371,66 @@ def module_count_diagnostic(graph) -> dict | None:
370
371
  }
371
372
 
372
373
 
374
+ def _version_tuple(v) -> tuple[int, ...] | None:
375
+ import re
376
+ m = re.match(r"(\d+(?:\.\d+)*)", str(v or ""))
377
+ return tuple(int(x) for x in m.group(1).split(".")) if m else None
378
+
379
+
380
+ def _running_version() -> str | None:
381
+ import codemap
382
+ return getattr(codemap, "__version__", None)
383
+
384
+
385
+ def newer_tool_diagnostic(graph, running: str | None = None) -> dict | None:
386
+ """Say when the graph was built by a newer codemap than the one reading it (R1-C91 D3).
387
+
388
+ Same schema, so it loads without a word — and the reader grades every route it does
389
+ not know as `unknown`, which `min_confidence` then drops. Measured on a consumer's
390
+ server: code 0.0.27 over a 0.0.34 graph, 2380 edges `unknown`, and `tool_restart_needed`
391
+ silent because it compares the running code with the *installed* one, never with the
392
+ graph. Either piece of evidence fires it: a newer recorded version, or routes this
393
+ build's table cannot grade (an uninstalled source tree has no version to compare).
394
+ """
395
+ from codemap.model import unrecognised_routes
396
+ running = running if running is not None else _running_version()
397
+ built_by = ((graph.provenance or {}).get("tool") or {}).get("version")
398
+ b, r = _version_tuple(built_by), _version_tuple(running)
399
+ newer = b is not None and r is not None and b > r
400
+ unknown = unrecognised_routes(graph)
401
+ if not newer and not unknown:
402
+ return None
403
+ edges = sum(unknown.values())
404
+ parts = []
405
+ if newer:
406
+ parts.append(f"this graph was built by codemap {built_by}, and codemap {running} is "
407
+ "reading it")
408
+ if unknown:
409
+ listed = ", ".join(f"{k} ({n})" for k, n in unknown.items())
410
+ parts.append(f"{edges} edge(s) carry routes this codemap does not know: {listed}")
411
+ # Not newer, yet unknown routes: an older graph with a route since retired, or an
412
+ # uninstalled reader — rebuilding with this codemap is the remedy either way.
413
+ remedy = (f"read it with codemap {built_by} or newer (restart a long-running server)"
414
+ if newer else "rebuild it with this codemap")
415
+ return {
416
+ "code": GRAPH_FROM_NEWER_TOOL,
417
+ "severity": WARNING,
418
+ "built_by": built_by,
419
+ "running": running,
420
+ "unrecognised": unknown,
421
+ "consequence": ("Edges with an unknown route are graded `unknown` and dropped by "
422
+ "`min_confidence`; answers keep the shape of the older code."),
423
+ "message": "; ".join(parts) + f" — {remedy}.",
424
+ }
425
+
426
+
373
427
  def diagnostics(graph) -> list[dict]:
374
428
  """Every diagnostic that applies to ``graph`` (empty list when it looks sound)."""
375
429
  checks = (import_graph_diagnostic(graph), namespace_target_diagnostic(graph),
376
430
  cross_root_diagnostic(graph), schema_diagnostic(graph),
377
431
  unread_inputs_diagnostic(graph), module_count_diagnostic(graph),
378
432
  scope_membership_diagnostic(graph), deep_tier_diagnostic(graph),
379
- incremental_splice_diagnostic(graph))
433
+ incremental_splice_diagnostic(graph), newer_tool_diagnostic(graph))
380
434
  return [d for d in checks if d is not None]
381
435
 
382
436
 
@@ -35,7 +35,7 @@ from codemap.extract.gsource import (DOTTED_IMPORT_HINT, NESTED_IMPORT_HINT, mod
35
35
  module_identity)
36
36
  from codemap.extract.union import merge_samples
37
37
  from codemap.provenance import build_provenance
38
- from codemap.model import Edge, Graph, Node
38
+ from codemap.model import Edge, Graph, Node, check_routes
39
39
 
40
40
  # griffe object kinds we turn into definition nodes (aliases handled separately).
41
41
  _NODE_KINDS = {"module", "class", "function", "attribute"}
@@ -266,6 +266,7 @@ def extract(package_path: str | Path, *, deep: bool = False, repeat: int = 1) ->
266
266
  graph.provenance = build_provenance(tier="deep" if deep else "fast",
267
267
  inputs=graph.provenance.get("inputs"),
268
268
  samples=stats)
269
+ check_routes(graph) # R1-C91 D2: every build guards the route table
269
270
  return graph
270
271
 
271
272
 
@@ -152,6 +152,8 @@ def extract_repo(
152
152
  "docs": sorted(_rel_to(Path(p).resolve(), base) for p in docs),
153
153
  "mode": mode,
154
154
  }})
155
+ from codemap.model import check_routes
156
+ check_routes(graph) # R1-C91 D2
155
157
  return graph
156
158
 
157
159
 
@@ -312,4 +312,6 @@ def update_graph(old_graph: Graph, package_path, old_scope: dict, new_scope: dic
312
312
  stats = {"runs": repeat, "unstable": _count_seen(graph)}
313
313
  graph.provenance = build_provenance(tier=tier, inputs=graph.provenance.get("inputs"),
314
314
  incremental=True, samples=stats)
315
+ from codemap.model import check_routes
316
+ check_routes(graph) # R1-C91 D2: the splice carries old edges forward
315
317
  return graph, {"mode": "incremental", "affected": sorted(affected)}
@@ -194,6 +194,9 @@ RESOLUTIONS: dict[tuple[str, str], dict[str, str]] = {
194
194
  "means": "route", "confidence": "heuristic",
195
195
  "how": "a call on a Protocol method fanned out to every structural implementer — "
196
196
  "the receiver is one of them, which one is not known (R1-C81)"},
197
+ ("calls", "local"): {"means": "route", "confidence": "exact",
198
+ "how": "a consumer-root call to a def at the level of the same module "
199
+ "(R1-C80); the consumer-root form of `module`"},
197
200
  ("calls", "typed"): {"means": "route", "confidence": "exact",
198
201
  "how": "a consumer-root call on an expression typed by a constructor "
199
202
  "or a return annotation (R1-C81)"},
@@ -214,6 +217,9 @@ RESOLUTIONS: dict[tuple[str, str], dict[str, str]] = {
214
217
  "how": "the symbol is named as a value (dict entry, default=…)"},
215
218
  ("references", "doc"): {"means": "site", "confidence": "exact",
216
219
  "how": "a documentation file names the symbol"},
220
+ ("references", "local"): {"means": "route", "confidence": "exact",
221
+ "how": "a consumer root names a def at the level of the same module "
222
+ "without calling it (R1-C80)"},
217
223
  ("references", "imported"): {"means": "route", "confidence": "exact",
218
224
  "how": "a consumer root names an imported core symbol"},
219
225
  ("reads", "string-key"): {"means": "route", "confidence": "exact",
@@ -245,7 +251,7 @@ def resolution_of(edge, *, strict: bool = True) -> dict[str, str] | None:
245
251
  ``None`` is a legitimate answer (``contains`` has no route), and it is distinct from
246
252
  a value the table does not know. Under ``strict`` that one raises — a silent unknown
247
253
  is how an open vocabulary pretends to be closed — and this is the form the guard test
248
- and the extractor use. Reading a *foreign* graph passes ``strict=False`` and gets an
254
+ uses; the builders check a whole graph with :func:`check_routes` (R1-C91). Reading a *foreign* graph passes ``strict=False`` and gets an
249
255
  ``unknown`` grade instead: refusing to open an artifact from another version is a
250
256
  worse answer than saying which part of it this build cannot grade.
251
257
  """
@@ -268,6 +274,30 @@ def confidence_of(edge, *, strict: bool = True) -> str | None:
268
274
  return row["confidence"] if row else None
269
275
 
270
276
 
277
+ def unrecognised_routes(graph) -> dict[str, int]:
278
+ """``{"type:resolution": edges}`` for every pair this build's table does not know (R1-C91)."""
279
+ out: dict[str, int] = {}
280
+ for e in graph.edges:
281
+ value = e.extras.get("resolution")
282
+ if value is not None and (e.type, value) not in RESOLUTIONS:
283
+ key = f"{e.type}:{value}"
284
+ out[key] = out.get(key, 0) + 1
285
+ return dict(sorted(out.items()))
286
+
287
+
288
+ def check_routes(graph) -> None:
289
+ """Refuse a graph this build produced with a route its own table does not grade (R1-C91 D2).
290
+
291
+ Called by every builder, so every build in the suite guards the table — not a fixture
292
+ list someone has to remember to extend. That list missed R1-C80's `local` for six
293
+ releases, and every repo graph carried 1107 edges graded `unknown` on one tree.
294
+ """
295
+ unknown = unrecognised_routes(graph)
296
+ if unknown:
297
+ raise KeyError(f"this build emitted route(s) its table does not know: {unknown} — add "
298
+ "them to RESOLUTIONS (codemap/model.py) with their meaning and grade")
299
+
300
+
271
301
  # The subset of EDGE_TYPES an incremental build splices from the old graph for modules
272
302
  # it did not recompute (``incremental.py``) — and therefore the classes a deep+incremental
273
303
  # graph answers from an *earlier* build's jedi sample (R1-C43). Lives with the vocabulary
@@ -88,6 +88,12 @@ def graph_currency(graph_path: str, graph_scope_id: str | None, *, roots: dict |
88
88
  if not meta or not meta.get("argv"):
89
89
  return _via_roots(graph_scope_id, roots, target, base,
90
90
  "no build recipe beside the graph")
91
+ # R1-C92 D2: a sidecar left beside a replaced graph describes another build — its
92
+ # recipe and its baseline would answer for a tree this graph never saw.
93
+ meta_id = (meta.get("scope") or {}).get("scope_id")
94
+ if meta_id and meta_id != graph_scope_id:
95
+ return _via_roots(graph_scope_id, roots, target, base,
96
+ "the sidecar describes another build than the graph")
91
97
  cwd = meta.get("cwd")
92
98
  if not cwd or not os.path.isdir(cwd):
93
99
  return _via_roots(graph_scope_id, roots, target, base,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.34
3
+ Version: 0.0.36
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, **1264 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1278 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 &
@@ -162,6 +162,8 @@ tests/test_r1c87_review_path_base.py
162
162
  tests/test_r1c89_review_docs.py
163
163
  tests/test_r1c8_deadcode.py
164
164
  tests/test_r1c90_currency_without_recipe.py
165
+ tests/test_r1c91_route_vocabulary.py
166
+ tests/test_r1c92_sidecar_pair.py
165
167
  tests/test_r1c9_incremental.py
166
168
  tests/test_scip_export.py
167
169
  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.34"
12
+ version = "0.0.36"
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
@@ -57,6 +57,25 @@ def _consumer_reference_probe(tmp: Path):
57
57
  return extract_repo(core, consumers=(use,), mode="full")
58
58
 
59
59
 
60
+ def _consumer_local_probe(tmp: Path):
61
+ """R1-C91: a consumer helper called and named inside its own module (`local`, R1-C80).
62
+
63
+ The route shipped in 0.0.28 without a row, and this list did not contain a build that
64
+ emitted it, so both directions of the closed-vocabulary check stayed green for six
65
+ releases. The builders now check every graph (D2); this probe keeps the reverse
66
+ direction — every row observed — honest for `local`.
67
+ """
68
+ core = tmp / "lcore"
69
+ core.mkdir()
70
+ (core / "__init__.py").write_text("")
71
+ (core / "m.py").write_text("def act():\n return 1\n")
72
+ use = tmp / "ltests"
73
+ use.mkdir()
74
+ (use / "test_m.py").write_text("from lcore.m import act\n\n\ndef _helper():\n return act()\n\n\n"
75
+ "def test_it():\n _helper()\n\n\nHOOKS = [_helper]\n")
76
+ return extract_repo(core, consumers=(use,), mode="full")
77
+
78
+
60
79
  def _protocol_probe(tmp: Path):
61
80
  """R1-C81: a call on a Protocol method, typed in a consumer, fanned out to its implementer."""
62
81
  core = tmp / "pcore"
@@ -87,6 +106,7 @@ def builds():
87
106
  docs=(FIX / "reporoot" / "docs",), mode="full")
88
107
  out["consumer-ref"] = _consumer_reference_probe(tmp)
89
108
  out["protocol"] = _protocol_probe(tmp)
109
+ out["consumer-local"] = _consumer_local_probe(tmp)
90
110
  return out
91
111
 
92
112
 
@@ -0,0 +1,150 @@
1
+ """R1-C91 — every route the extractor emits is graded; a graph from a newer codemap says so.
2
+
3
+ Design `docs/design/route_vocabulary_drift.md` (pre-registered 66feb01).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ from pathlib import Path
10
+
11
+ import pytest
12
+
13
+ from codemap import model, store
14
+ from codemap.cli import main
15
+ from codemap.diagnostics import GRAPH_FROM_NEWER_TOOL, diagnostics, newer_tool_diagnostic
16
+ from codemap.extract import extract_repo
17
+ from codemap.query import Query
18
+ from codemap.serve.session import Session
19
+
20
+ FILES = {
21
+ "pkg/__init__.py": "",
22
+ "pkg/core.py": "def act():\n return 1\n",
23
+ "tests/test_a.py": ("from pkg.core import act\n\n\n"
24
+ "def _helper():\n return act()\n\n\n"
25
+ "def test_through_helper():\n assert _helper() == 1\n\n\n"
26
+ "HOOKS = [_helper]\n"),
27
+ }
28
+
29
+
30
+ def _write(root: Path):
31
+ for rel, body in FILES.items():
32
+ p = root / rel
33
+ p.parent.mkdir(parents=True, exist_ok=True)
34
+ p.write_text(body)
35
+
36
+
37
+ def _build(root: Path):
38
+ return extract_repo(str(root / "pkg"), consumers=(str(root / "tests"),), mode="full")
39
+
40
+
41
+ @pytest.fixture
42
+ def repo(tmp_path):
43
+ root = tmp_path / "repo"
44
+ _write(root)
45
+ return root
46
+
47
+
48
+ def _local(graph):
49
+ return {(e.type, e.source, e.target) for e in graph.edges
50
+ if e.extras.get("resolution") == "local"}
51
+
52
+
53
+ # -- D1 -------------------------------------------------------------------------------------
54
+
55
+ def test_E1_local_routes_are_graded_exact_and_survive_min_confidence(repo):
56
+ graph = _build(repo)
57
+ local = _local(graph)
58
+ helper = "tests.test_a._helper"
59
+ assert ("calls", "tests.test_a.test_through_helper", helper) in local
60
+ assert ("references", "tests.test_a", helper) in local, "the fixture must name it uncalled"
61
+ for e in graph.edges:
62
+ if e.extras.get("resolution") == "local":
63
+ assert model.confidence_of(e) == "exact"
64
+ q = Query(graph)
65
+ assert "unknown" not in q.confidence_map()["by_grade"]
66
+ assert "tests.test_a.test_through_helper" in q.callers(helper, min_confidence="exact")
67
+
68
+
69
+ # -- D2 -------------------------------------------------------------------------------------
70
+
71
+ def test_E5_a_builder_refuses_a_route_its_table_does_not_know(repo, monkeypatch):
72
+ for key in (("calls", "local"), ("references", "local")):
73
+ monkeypatch.delitem(model.RESOLUTIONS, key)
74
+ with pytest.raises(KeyError, match="local"):
75
+ _build(repo)
76
+
77
+
78
+ # -- D3 -------------------------------------------------------------------------------------
79
+
80
+ def _stamped(graph, version):
81
+ graph.provenance = {**graph.provenance,
82
+ "tool": {**(graph.provenance.get("tool") or {}), "version": version}}
83
+ return graph
84
+
85
+
86
+ def test_E3_a_newer_builder_is_named(repo):
87
+ graph = _stamped(_build(repo), "99.0.0")
88
+ d = newer_tool_diagnostic(graph, running="0.0.35")
89
+ assert d["code"] == GRAPH_FROM_NEWER_TOOL and d["severity"] == "warning"
90
+ assert d["built_by"] == "99.0.0" and d["running"] == "0.0.35" and d["unrecognised"] == {}
91
+ assert "99.0.0 or newer" in d["message"]
92
+ assert any(x["code"] == GRAPH_FROM_NEWER_TOOL for x in diagnostics(graph))
93
+
94
+
95
+ def test_E3_unknown_routes_are_listed_with_counts(repo):
96
+ graph = _build(repo)
97
+ e = next(e for e in graph.edges if e.extras.get("resolution") == "imported")
98
+ e.extras["resolution"] = "future"
99
+ # Read the reader's version from the graph itself: a literal here went stale the moment
100
+ # the package version moved past it, and the graph then read as "newer" (0.0.36 release CI).
101
+ built = graph.provenance["tool"]["version"]
102
+ d = newer_tool_diagnostic(graph, running=built)
103
+ assert d["unrecognised"] == {f"{e.type}:future": 1}
104
+ assert "rebuild it with this codemap" in d["message"], "not newer: the remedy is a rebuild"
105
+
106
+
107
+ def test_unknown_routes_fire_without_a_running_version(repo):
108
+ graph = _build(repo)
109
+ next(e for e in graph.edges if e.extras.get("resolution")).extras["resolution"] = "future"
110
+ assert newer_tool_diagnostic(graph, running="")["unrecognised"]
111
+
112
+
113
+ def test_E2_an_older_or_equal_graph_with_known_routes_is_silent(repo):
114
+ graph = _build(repo)
115
+ for v in ("0.0.1", "0.0.35"):
116
+ assert newer_tool_diagnostic(_stamped(graph, v), running="0.0.35") is None
117
+
118
+
119
+ def test_the_running_version_compares_by_number_not_by_string(repo):
120
+ graph = _stamped(_build(repo), "0.0.100")
121
+ assert newer_tool_diagnostic(graph, running="0.0.99") is not None
122
+ assert newer_tool_diagnostic(_stamped(graph, "0.0.9"), running="0.0.10") is None
123
+
124
+
125
+ def test_stats_carries_it(repo, tmp_path):
126
+ graph = _stamped(_build(repo), "99.0.0")
127
+ out = Session(graph).handle({"op": "stats"})
128
+ codes = [d["code"] for d in out["result"].get("diagnostics", [])]
129
+ assert GRAPH_FROM_NEWER_TOOL in codes
130
+
131
+
132
+ # -- D4 -------------------------------------------------------------------------------------
133
+
134
+ def test_E3_cold_cli_read_warns_once_and_keeps_stdout(repo, tmp_path, capsys, monkeypatch):
135
+ monkeypatch.chdir(repo)
136
+ g = tmp_path / "g.json"
137
+ assert main(["build", "pkg", "--consumer", "tests", "--mode", "full", "-o", str(g)]) == 0
138
+ capsys.readouterr()
139
+ assert main(["query", "act", "--graph", str(g)]) == 0
140
+ plain = capsys.readouterr()
141
+ assert "graph_from_newer_tool" not in plain.err and "built by codemap" not in plain.err
142
+
143
+ data = json.loads(g.read_text())
144
+ data["provenance"]["tool"]["version"] = "99.0.0"
145
+ g.write_text(json.dumps(data))
146
+ assert main(["query", "act", "--graph", str(g)]) == 0
147
+ stamped = capsys.readouterr()
148
+ lines = [ln for ln in stamped.err.splitlines() if "built by codemap 99.0.0" in ln]
149
+ assert len(lines) == 1 and lines[0].startswith("[warning]")
150
+ assert stamped.out == plain.out
@@ -0,0 +1,126 @@
1
+ """R1-C92 — a graph and its sidecar must describe one build, or the sidecar is not used.
2
+
3
+ Design `docs/design/sidecar_pair.md` (pre-registered 8f525ea).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import shutil
10
+ from pathlib import Path
11
+
12
+ import pytest
13
+
14
+ from codemap import store
15
+ from codemap.cli import main
16
+ from codemap.serve.session import Session
17
+
18
+
19
+ def _write(root: Path, files: dict):
20
+ for rel, body in files.items():
21
+ p = root / rel
22
+ p.parent.mkdir(parents=True, exist_ok=True)
23
+ p.write_text(body)
24
+
25
+
26
+ BASE = {"pkg/__init__.py": "", **{f"pkg/m{i}.py": f"def f{i}():\n return {i}\n" for i in range(1, 7)}}
27
+ STATE1 = {"pkg/m1.py": "from pkg.m3 import f3\n\n\ndef f1():\n return f3()\n"}
28
+ EDIT = {"pkg/m2.py": "def f2():\n return 22\n"}
29
+ CALL = ("calls", "pkg.m1.f1", "pkg.m3.f3")
30
+
31
+
32
+ def _build(out: Path, *extra) -> str:
33
+ return main(["build", "pkg", "-o", str(out), *extra])
34
+
35
+
36
+ def _pair(dst: Path, graph: Path, meta_of: Path):
37
+ shutil.copy(graph, dst)
38
+ shutil.copy(str(meta_of) + ".meta.json", str(dst) + ".meta.json")
39
+
40
+
41
+ def _edges(path: Path):
42
+ return {(e["type"], e["source"], e["target"]) for e in json.loads(path.read_text())["edges"]}
43
+
44
+
45
+ def _same(a: Path, b: Path) -> bool:
46
+ x, y = json.loads(a.read_text()), json.loads(b.read_text())
47
+ for g in (x, y):
48
+ g["provenance"].pop("incremental", None)
49
+ return x == y
50
+
51
+
52
+ @pytest.fixture
53
+ def tree(tmp_path, monkeypatch):
54
+ root = tmp_path / "t"
55
+ _write(root, BASE)
56
+ monkeypatch.chdir(root)
57
+ g0, g1 = tmp_path / "g0.json", tmp_path / "g1.json"
58
+ assert _build(g0) == 0
59
+ _write(root, STATE1)
60
+ assert _build(g1) == 0
61
+ return root, tmp_path, g0, g1
62
+
63
+
64
+ def test_E1_graph_older_than_its_sidecar_is_rebuilt_in_full(tree, capsys):
65
+ root, tmp, g0, g1 = tree
66
+ g = tmp / "g.json"
67
+ _pair(g, g0, g1)
68
+ _write(root, EDIT)
69
+ capsys.readouterr()
70
+ assert _build(g, "--incremental") == 0
71
+ err = capsys.readouterr().err
72
+ assert "[incremental] full" in err and "the sidecar describes another build" in err
73
+ full = tmp / "full.json"
74
+ assert _build(full) == 0
75
+ assert CALL in _edges(g), "the edit between graph and sidecar must not be lost"
76
+ assert _same(g, full)
77
+
78
+
79
+ def test_E2_graph_newer_than_its_sidecar_is_rebuilt_in_full(tree, capsys):
80
+ root, tmp, g0, g1 = tree
81
+ g = tmp / "g.json"
82
+ _pair(g, g1, g0)
83
+ _write(root, EDIT)
84
+ capsys.readouterr()
85
+ assert _build(g, "--incremental") == 0
86
+ assert "the sidecar describes another build" in capsys.readouterr().err
87
+
88
+
89
+ def test_E3_a_matched_pair_stays_incremental(tree, capsys):
90
+ root, tmp, g0, g1 = tree
91
+ _write(root, EDIT)
92
+ capsys.readouterr()
93
+ assert _build(g1, "--incremental") == 0
94
+ err = capsys.readouterr().err
95
+ assert "[incremental] incremental: 1 module(s) recomputed\n" in err
96
+ full = tmp / "full.json"
97
+ assert _build(full) == 0
98
+ assert _same(g1, full)
99
+
100
+
101
+ def test_E4_repo_scoped_mismatch_is_rebuilt_in_full(tmp_path, monkeypatch, capsys):
102
+ root = tmp_path / "t"
103
+ _write(root, {**BASE, "tests/test_m.py": "from pkg.m1 import f1\n\n\ndef test_f1():\n f1()\n"})
104
+ monkeypatch.chdir(root)
105
+ flags = ("--consumer", "tests", "--mode", "full")
106
+ g0, g1, g = tmp_path / "g0.json", tmp_path / "g1.json", tmp_path / "g.json"
107
+ assert _build(g0, *flags) == 0
108
+ _write(root, STATE1)
109
+ assert _build(g1, *flags) == 0
110
+ _pair(g, g0, g1)
111
+ _write(root, EDIT)
112
+ capsys.readouterr()
113
+ assert _build(g, *flags, "--incremental") == 0
114
+ assert "the sidecar describes another build" in capsys.readouterr().err
115
+ assert CALL in _edges(g)
116
+
117
+
118
+ def test_E5_currency_does_not_use_a_foreign_sidecar(tree):
119
+ root, tmp, g0, g1 = tree
120
+ g = tmp / "g.json"
121
+ _pair(g, g0, g1)
122
+ c = Session(store.load(str(g)), graph_path=str(g), currency_ttl=0,
123
+ source_root=str(root)).handle({"op": "stats"})["currency"]
124
+ assert c["status"] == "behind"
125
+ assert c["via"].startswith("provenance roots under"), c
126
+ assert "changed" not in c, "no counts from another build's baseline"
File without changes
File without changes
File without changes
File without changes