codmap 0.0.28__tar.gz → 0.0.29__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 (163) hide show
  1. {codmap-0.0.28/codmap.egg-info → codmap-0.0.29}/PKG-INFO +4 -3
  2. {codmap-0.0.28 → codmap-0.0.29}/README.md +3 -2
  3. {codmap-0.0.28 → codmap-0.0.29}/codemap/cli.py +67 -15
  4. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/roots.py +29 -0
  5. {codmap-0.0.28 → codmap-0.0.29/codmap.egg-info}/PKG-INFO +4 -3
  6. {codmap-0.0.28 → codmap-0.0.29}/codmap.egg-info/SOURCES.txt +2 -0
  7. {codmap-0.0.28 → codmap-0.0.29}/pyproject.toml +1 -1
  8. codmap-0.0.29/tests/test_r1c83_foreign_graph_paths.py +125 -0
  9. codmap-0.0.29/tests/test_r1c84_missing_roots.py +126 -0
  10. {codmap-0.0.28 → codmap-0.0.29}/LICENSE +0 -0
  11. {codmap-0.0.28 → codmap-0.0.29}/codemap/__init__.py +0 -0
  12. {codmap-0.0.28 → codmap-0.0.29}/codemap/apidiff.py +0 -0
  13. {codmap-0.0.28 → codmap-0.0.29}/codemap/arch.py +0 -0
  14. {codmap-0.0.28 → codmap-0.0.29}/codemap/diagnostics.py +0 -0
  15. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/__init__.py +0 -0
  16. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/attrflow.py +0 -0
  17. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/behavior.py +0 -0
  18. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/dataflow.py +0 -0
  19. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/dispatch.py +0 -0
  20. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/griffe_extractor.py +0 -0
  21. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/gsource.py +0 -0
  22. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/probe.py +0 -0
  23. {codmap-0.0.28 → codmap-0.0.29}/codemap/extract/union.py +0 -0
  24. {codmap-0.0.28 → codmap-0.0.29}/codemap/freshness.py +0 -0
  25. {codmap-0.0.28 → codmap-0.0.29}/codemap/incremental.py +0 -0
  26. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/__init__.py +0 -0
  27. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/base.py +0 -0
  28. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/cocoindex.py +0 -0
  29. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/gate.py +0 -0
  30. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/gitnexus.py +0 -0
  31. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/registry.py +0 -0
  32. {codmap-0.0.28 → codmap-0.0.29}/codemap/integrations/transport.py +0 -0
  33. {codmap-0.0.28 → codmap-0.0.29}/codemap/model.py +0 -0
  34. {codmap-0.0.28 → codmap-0.0.29}/codemap/provenance.py +0 -0
  35. {codmap-0.0.28 → codmap-0.0.29}/codemap/query.py +0 -0
  36. {codmap-0.0.28 → codmap-0.0.29}/codemap/scope.py +0 -0
  37. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/__init__.py +0 -0
  38. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/_scip_pb2.py +0 -0
  39. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/api_surface.py +0 -0
  40. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/apidiff.py +0 -0
  41. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/architecture.py +0 -0
  42. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/audit.py +0 -0
  43. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/check.py +0 -0
  44. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/ctags.py +0 -0
  45. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/currency.py +0 -0
  46. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/impact.py +0 -0
  47. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/limits.py +0 -0
  48. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/livingdocs.py +0 -0
  49. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/mcp_server.py +0 -0
  50. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/mermaid.py +0 -0
  51. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/pack.py +0 -0
  52. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/rag.py +0 -0
  53. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/review.py +0 -0
  54. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/scip.py +0 -0
  55. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/semantic.py +0 -0
  56. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/server.py +0 -0
  57. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/session.py +0 -0
  58. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/subsystems.py +0 -0
  59. {codmap-0.0.28 → codmap-0.0.29}/codemap/serve/vault.py +0 -0
  60. {codmap-0.0.28 → codmap-0.0.29}/codemap/store.py +0 -0
  61. {codmap-0.0.28 → codmap-0.0.29}/codemap/tomlio.py +0 -0
  62. {codmap-0.0.28 → codmap-0.0.29}/codemap/watch.py +0 -0
  63. {codmap-0.0.28 → codmap-0.0.29}/codmap.egg-info/dependency_links.txt +0 -0
  64. {codmap-0.0.28 → codmap-0.0.29}/codmap.egg-info/entry_points.txt +0 -0
  65. {codmap-0.0.28 → codmap-0.0.29}/codmap.egg-info/requires.txt +0 -0
  66. {codmap-0.0.28 → codmap-0.0.29}/codmap.egg-info/top_level.txt +0 -0
  67. {codmap-0.0.28 → codmap-0.0.29}/setup.cfg +0 -0
  68. {codmap-0.0.28 → codmap-0.0.29}/tests/test_epistemic.py +0 -0
  69. {codmap-0.0.28 → codmap-0.0.29}/tests/test_gitnexus_router.py +0 -0
  70. {codmap-0.0.28 → codmap-0.0.29}/tests/test_impact_depth.py +0 -0
  71. {codmap-0.0.28 → codmap-0.0.29}/tests/test_integrations.py +0 -0
  72. {codmap-0.0.28 → codmap-0.0.29}/tests/test_issue3_serve_freshness.py +0 -0
  73. {codmap-0.0.28 → codmap-0.0.29}/tests/test_livingdocs.py +0 -0
  74. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m0_api_surface.py +0 -0
  75. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m11_argcontract.py +0 -0
  76. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m12_dataflow.py +0 -0
  77. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m15_review.py +0 -0
  78. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m16_architecture.py +0 -0
  79. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m17_mcp.py +0 -0
  80. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m18_freshness.py +0 -0
  81. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m1_5_semantics.py +0 -0
  82. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m1_query.py +0 -0
  83. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m2_views.py +0 -0
  84. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m32_watch.py +0 -0
  85. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m3_serve.py +0 -0
  86. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m4_behavior.py +0 -0
  87. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m5_deep.py +0 -0
  88. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m6_repo_scope.py +0 -0
  89. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m7_dispatch.py +0 -0
  90. {codmap-0.0.28 → codmap-0.0.29}/tests/test_m9_family.py +0 -0
  91. {codmap-0.0.28 → codmap-0.0.29}/tests/test_pack_honesty.py +0 -0
  92. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  93. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c13_grep_vs_graph.py +0 -0
  94. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c16_semantic.py +0 -0
  95. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c20_attribute_edges.py +0 -0
  96. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c21_flat_layout.py +0 -0
  97. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c22_source_visible_refs.py +0 -0
  98. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c23_hard_python.py +0 -0
  99. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c24_test_mapping.py +0 -0
  100. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c25_provenance.py +0 -0
  101. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c26_deep_union.py +0 -0
  102. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c27_config_honesty.py +0 -0
  103. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c28_limit_envelope.py +0 -0
  104. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c29_lazy_imports.py +0 -0
  105. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c2_ctags.py +0 -0
  106. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c30_local_import_calls.py +0 -0
  107. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c30f1_reexport_calls.py +0 -0
  108. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c30f2_check_scope.py +0 -0
  109. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c31_path_origin.py +0 -0
  110. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c32_report_json.py +0 -0
  111. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c33_query_signature.py +0 -0
  112. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c34_signature_kinds.py +0 -0
  113. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c35_contract_location.py +0 -0
  114. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c36_target_resolution.py +0 -0
  115. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c37_rule_mutation.py +0 -0
  116. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c38_tool_drift.py +0 -0
  117. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c39_edge_resolution.py +0 -0
  118. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c3_arch_contract.py +0 -0
  119. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c3_dogfood.py +0 -0
  120. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c40_flow_reach.py +0 -0
  121. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c41_scope_membership.py +0 -0
  122. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c42_deep_tier_stability.py +0 -0
  123. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c43_incremental_splice.py +0 -0
  124. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c44_absent_answers.py +0 -0
  125. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c45_repeat_union.py +0 -0
  126. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c46_shadowed_definitions.py +0 -0
  127. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c47_incremental_resample.py +0 -0
  128. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c48_type_checking_imports.py +0 -0
  129. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c49_type_only_cycles.py +0 -0
  130. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c4_complexity.py +0 -0
  131. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c50_flow_entry_points.py +0 -0
  132. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c53_narrowing_declared.py +0 -0
  133. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c54_deterministic_rendering.py +0 -0
  134. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c55_override_grade.py +0 -0
  135. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c56_stub_files.py +0 -0
  136. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c57_facade_package.py +0 -0
  137. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c58_cycle_tangles.py +0 -0
  138. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c59_completeness_drop.py +0 -0
  139. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c5_apidiff.py +0 -0
  140. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c60_nested_definitions.py +0 -0
  141. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c62_phantom_rules.py +0 -0
  142. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c63_answer_format.py +0 -0
  143. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c64_dependency_probe.py +0 -0
  144. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c66_pack_direction.py +0 -0
  145. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c68_dotted_imports.py +0 -0
  146. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c69_contract_validation.py +0 -0
  147. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c6_pack.py +0 -0
  148. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c70_check_graph_currency.py +0 -0
  149. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  150. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  151. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c73_cli_version.py +0 -0
  152. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c74_call_site_conservation.py +0 -0
  153. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c75_reexported_class_calls.py +0 -0
  154. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c76_contract_table_typo.py +0 -0
  155. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c77_gate_probe_battery.py +0 -0
  156. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c78_forbidden_chains.py +0 -0
  157. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c7_edge_vocab.py +0 -0
  158. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c80_tests_through_helpers.py +0 -0
  159. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c8_deadcode.py +0 -0
  160. {codmap-0.0.28 → codmap-0.0.29}/tests/test_r1c9_incremental.py +0 -0
  161. {codmap-0.0.28 → codmap-0.0.29}/tests/test_scip_export.py +0 -0
  162. {codmap-0.0.28 → codmap-0.0.29}/tests/test_scope.py +0 -0
  163. {codmap-0.0.28 → codmap-0.0.29}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.28
3
+ Version: 0.0.29
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, **1189 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1207 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 &
@@ -170,7 +170,8 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
170
170
  # build the canonical graph of a package (its directory name is the package name every id starts with)
171
171
  codemap build ./yourpkg -o graph.json
172
172
 
173
- # repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact
173
+ # repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact;
174
+ # one flag per root — a root that is not a directory is refused, exit 2
174
175
  codemap build ./yourpkg --deep --mode full --consumer ./tests --docs ./docs -o graph.json
175
176
 
176
177
  # deep tier: union N independent samples (one build misses a real edge ~1 time in 4)
@@ -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, **1189 tests with no failures on
11
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1207 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 &
@@ -134,7 +134,8 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
134
134
  # build the canonical graph of a package (its directory name is the package name every id starts with)
135
135
  codemap build ./yourpkg -o graph.json
136
136
 
137
- # repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact
137
+ # repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact;
138
+ # one flag per root — a root that is not a directory is refused, exit 2
138
139
  codemap build ./yourpkg --deep --mode full --consumer ./tests --docs ./docs -o graph.json
139
140
 
140
141
  # deep tier: union N independent samples (one build misses a real edge ~1 time in 4)
@@ -49,7 +49,7 @@ from pathlib import Path
49
49
  from codemap import store
50
50
  from codemap.diagnostics import diagnostics
51
51
  from codemap.extract import extract, extract_repo
52
- from codemap.extract.roots import roots_base
52
+ from codemap.extract.roots import root_problems, roots_base
53
53
  from codemap.provenance import build_provenance
54
54
  from codemap.query import Query
55
55
  from codemap.serve import (
@@ -100,6 +100,19 @@ def _graph_from(args):
100
100
  raise SystemExit("error: need --graph <file> or --build <path>")
101
101
 
102
102
 
103
+ def _refuse_bad_roots(args) -> bool:
104
+ """R1-C84: print every unreadable ``--consumer``/``--docs`` root; True means refuse (exit 2).
105
+
106
+ Checked before anything is built — a `--deep` core pass must not spend minutes on a
107
+ graph that will lack a root — and before ``-o`` is touched.
108
+ """
109
+ problems = root_problems(tuple(getattr(args, "consumer", None) or ()),
110
+ tuple(getattr(args, "docs", None) or ()))
111
+ for p in problems:
112
+ print(f"error: {p}", file=sys.stderr)
113
+ return bool(problems)
114
+
115
+
103
116
  def _cmd_build(args) -> int:
104
117
  incr_info = None
105
118
  repeat = getattr(args, "repeat", None)
@@ -114,6 +127,8 @@ def _cmd_build(args) -> int:
114
127
  print(f"error: --repeat {repeat} needs --deep — the fast tier is byte-stable, so "
115
128
  "repeating it unions identical samples", file=sys.stderr)
116
129
  return 2
130
+ if _refuse_bad_roots(args):
131
+ return 2
117
132
  if args.consumer or args.docs:
118
133
  if getattr(args, "incremental", False):
119
134
  # R1-C44 / D6: the flag used to be swallowed here without a word. Not an
@@ -311,6 +326,8 @@ def _cmd_watch(args) -> int:
311
326
  import argparse as _argparse
312
327
  from codemap.watch import DebouncedPoller, scope_probe
313
328
 
329
+ if _refuse_bad_roots(args):
330
+ return 2
314
331
  consumers = tuple(args.consumer or ())
315
332
  docs = tuple(args.docs or ())
316
333
  build_args = _argparse.Namespace(
@@ -328,7 +345,11 @@ def _cmd_watch(args) -> int:
328
345
  # and it would pollute a pipeline this watcher is composed into. Everything
329
346
  # this command says goes to stderr — stdout stays empty on purpose.
330
347
  with contextlib.redirect_stdout(sys.stderr):
331
- _cmd_build(build_args)
348
+ rc = _cmd_build(build_args)
349
+ if rc != 0:
350
+ # R1-C84: a refusal returns 2 rather than raising (a root deleted while
351
+ # watching); it is a failed rebuild, never "rebuilt".
352
+ raise RuntimeError(f"build exited {rc}")
332
353
  except Exception as exc:
333
354
  # A failed rebuild leaves the previous graph in place, and says so. Silence
334
355
  # here would be the same defect this project keeps fixing: a stale answer
@@ -402,6 +423,8 @@ def _cmd_scope(args) -> int:
402
423
  return 0 if not (d["added"] or d["removed"] or d["changed"]) else 1
403
424
  if not args.path:
404
425
  raise SystemExit("error: scope needs <path> (or --diff A B)")
426
+ if _refuse_bad_roots(args):
427
+ return 2
405
428
  scope = resolve_scope(args.path, consumers=tuple(args.consumer or ()),
406
429
  docs=tuple(args.docs or ()), use_git=not args.no_git)
407
430
  if args.json:
@@ -545,26 +568,50 @@ def _local_nodeids(ids: list[str], args) -> tuple[list[str], str | None]:
545
568
  there**: a rewrite that cannot be verified is not printed, and the caveat says which
546
569
  directory the untouched path belongs to instead of leaving the reader to find out from
547
570
  pytest. The op's own payload keeps the graph-relative id, which is the portable one.
571
+
572
+ R1-C83: a graph built on another machine (or another checkout) records a directory
573
+ that is not here. One base was tried, so a line that ran fine from the repo root still
574
+ drew "could not be located", and from anywhere else there was no way to name the root.
575
+ Now ``--source-root`` is the only base when given; otherwise the sidecar's directory if
576
+ it exists here, then the current one — each path against the first base where that
577
+ file is, so nothing unverified is printed.
548
578
  """
549
579
  from codemap.freshness import read_meta
550
580
  meta = read_meta(getattr(args, "graph", None) or "") or {}
551
- base = meta.get("roots_base")
552
- if not base:
553
- return ids, ("paths are relative to the build roots' common directory — run from "
554
- "there, or rebuild with this codemap so the sidecar records it")
555
- out, resolved = [], 0
581
+ recorded = meta.get("roots_base")
582
+ explicit = getattr(args, "source_root", None)
583
+ if explicit:
584
+ bases = [explicit]
585
+ else:
586
+ bases = [b for b in (recorded,) if b and os.path.isdir(b)] + [os.getcwd()]
587
+ out, missing = [], 0
556
588
  for nid in ids:
557
589
  path, sep, tail = nid.partition("::")
558
- full = os.path.join(base, path)
559
- if os.path.exists(full):
560
- out.append(os.path.relpath(full, os.getcwd()) + sep + tail)
561
- resolved += 1
590
+ for b in bases:
591
+ full = os.path.join(b, path)
592
+ if os.path.exists(full):
593
+ out.append(os.path.relpath(full, os.getcwd()) + sep + tail)
594
+ break
562
595
  else:
563
596
  out.append(nid)
564
- if resolved != len(ids):
565
- return out, (f"{len(ids) - resolved} of {len(ids)} path(s) could not be located on "
566
- f"this machine and are printed as the graph stores them — relative to "
567
- f"`{base}`")
597
+ missing += 1
598
+ if missing:
599
+ if explicit:
600
+ return out, (f"{missing} of {len(ids)} path(s) not found under `--source-root "
601
+ f"{explicit}` and are printed as the graph stores them")
602
+ if not recorded:
603
+ return out, ("paths are relative to the build roots' common directory — run from "
604
+ "there, pass `--source-root`, or rebuild with this codemap so the "
605
+ "sidecar records it")
606
+ tried = " and ".join(f"`{b}`" for b in bases)
607
+ away = ("" if os.path.isdir(recorded) else
608
+ f" (the graph was built in `{recorded}`, which is not on this machine)")
609
+ return out, (f"{missing} of {len(ids)} path(s) could not be located under {tried}{away} "
610
+ f"and are printed as the graph stores them — pass `--source-root` with "
611
+ f"the directory the graph's paths are relative to")
612
+ if recorded and not explicit and not os.path.isdir(recorded):
613
+ return out, (f"the graph was built in `{recorded}`, which is not on this machine; "
614
+ f"paths located from the current directory")
568
615
  return out, None
569
616
 
570
617
 
@@ -1091,6 +1138,9 @@ def build_parser() -> argparse.ArgumentParser:
1091
1138
  t.add_argument("--all-bands", action="store_true",
1092
1139
  help="List every band within --depth, not only the nearest (R1-C80).")
1093
1140
  t.add_argument("--format", choices=["text", "json"], default="text")
1141
+ t.add_argument("--source-root", metavar="DIR",
1142
+ help="Directory the graph's paths are relative to on this machine, for the "
1143
+ "printed pytest line (default: the build's own, else the current one).")
1094
1144
  t.set_defaults(func=_cmd_tests)
1095
1145
 
1096
1146
  r = sub.add_parser("report", help="Render a report over the graph.")
@@ -1105,6 +1155,8 @@ def build_parser() -> argparse.ArgumentParser:
1105
1155
  r.add_argument("--min-confidence", choices=["low", "medium", "high"], default=None,
1106
1156
  help="report dead-code: only show candidates at/above this confidence.")
1107
1157
  r.add_argument("--format", choices=["markdown", "json"], default="markdown")
1158
+ r.add_argument("--source-root", metavar="DIR",
1159
+ help="Where codemap.toml is read for `dead-code` (default: current dir).")
1108
1160
  r.set_defaults(func=_cmd_report)
1109
1161
 
1110
1162
  e = sub.add_parser("export", help="Export a view: rag (JSONL) | vault | mermaid | scip | ctags | docs.")
@@ -61,6 +61,32 @@ def roots_base(core: str | Path, consumers=(), docs=()) -> Path:
61
61
  return Path(os.path.commonpath([str(p) for p in parents]))
62
62
 
63
63
 
64
+ def root_problems(consumers=(), docs=()) -> list[str]:
65
+ """Every ``--consumer`` / ``--docs`` root that cannot be read, in words (R1-C84).
66
+
67
+ The scanners skip a root that is not a directory, so a typo or two roots passed in
68
+ one string (`--consumer tests,examples`) built a graph without them, exit 0, and the
69
+ provenance still listed the root as read. Callers refuse on any problem instead.
70
+ An existing empty directory is not a problem: the graph simply has nothing from it.
71
+ """
72
+ problems = []
73
+ for flag, paths in (("--consumer", consumers), ("--docs", docs)):
74
+ for raw in paths:
75
+ p = Path(raw)
76
+ if p.is_dir():
77
+ continue
78
+ if p.exists():
79
+ problems.append(f"`{flag} {raw}`: not a directory")
80
+ continue
81
+ msg = f"`{flag} {raw}`: no such directory"
82
+ parts = [s for s in str(raw).split(",") if s]
83
+ if len(parts) > 1 and all(Path(s).is_dir() for s in parts):
84
+ msg += (" — looks like a list; pass the flag once per root: `"
85
+ + " ".join(f"{flag} {s}" for s in parts) + "`")
86
+ problems.append(msg)
87
+ return problems
88
+
89
+
64
90
  def _reroot_files(graph, offset: str) -> None:
65
91
  """Prefix every node's ``file`` with ``offset`` (the core pass wrote them relative to
66
92
  the core's own parent, which may be below the common origin)."""
@@ -90,6 +116,9 @@ def extract_repo(
90
116
  """
91
117
  if mode not in ("thin", "full"):
92
118
  raise ValueError(f"mode must be 'thin' or 'full', got {mode!r}")
119
+ problems = root_problems(consumers, docs)
120
+ if problems:
121
+ raise ValueError("; ".join(problems))
93
122
 
94
123
  graph = extract(core, deep=deep, repeat=repeat)
95
124
  core_pkg = graph.target
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.28
3
+ Version: 0.0.29
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, **1189 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1207 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 &
@@ -170,7 +170,8 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
170
170
  # build the canonical graph of a package (its directory name is the package name every id starts with)
171
171
  codemap build ./yourpkg -o graph.json
172
172
 
173
- # repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact
173
+ # repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact;
174
+ # one flag per root — a root that is not a directory is refused, exit 2
174
175
  codemap build ./yourpkg --deep --mode full --consumer ./tests --docs ./docs -o graph.json
175
176
 
176
177
  # deep tier: union N independent samples (one build misses a real edge ~1 time in 4)
@@ -152,6 +152,8 @@ 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_r1c83_foreign_graph_paths.py
156
+ tests/test_r1c84_missing_roots.py
155
157
  tests/test_r1c8_deadcode.py
156
158
  tests/test_r1c9_incremental.py
157
159
  tests/test_scip_export.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.28"
12
+ version = "0.0.29"
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
@@ -0,0 +1,125 @@
1
+ """R1-C83 — the `pytest` line of a graph built elsewhere: the current directory is tried, `--source-root` is taken.
2
+
3
+ Design `docs/design/foreign_graph_paths.md` (pre-registered 8966f98).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ from pathlib import Path
10
+
11
+ import pytest
12
+
13
+ from codemap.cli import main
14
+
15
+ FOREIGN = "/srv/elsewhere/repo"
16
+
17
+
18
+ @pytest.fixture
19
+ def setup(tmp_path, monkeypatch):
20
+ repo = tmp_path / "repo"
21
+ for rel, body in {
22
+ "pkg/__init__.py": "",
23
+ "pkg/core.py": "def act():\n return 1\n\n\ndef unused_thing():\n return 2\n",
24
+ "tests/test_a.py": "from pkg.core import act\n\n\ndef test_a():\n assert act()\n",
25
+ }.items():
26
+ p = repo / rel
27
+ p.parent.mkdir(parents=True, exist_ok=True)
28
+ p.write_text(body)
29
+ out = tmp_path / "graphs"
30
+ out.mkdir()
31
+ monkeypatch.chdir(repo)
32
+ assert main(["build", "pkg", "--consumer", "tests", "--mode", "full", "-o", str(out / "g.json")]) == 0
33
+ return tmp_path, repo, out / "g.json"
34
+
35
+
36
+ def _foreign(graph: Path, drop=False):
37
+ meta = Path(str(graph) + ".meta.json")
38
+ if drop:
39
+ meta.unlink()
40
+ return
41
+ m = json.loads(meta.read_text())
42
+ m["roots_base"] = FOREIGN
43
+ meta.write_text(json.dumps(m))
44
+
45
+
46
+ def _tests(capsys, graph, *extra):
47
+ capsys.readouterr()
48
+ rc = main(["tests", "act", "--graph", str(graph), *extra])
49
+ cap = capsys.readouterr()
50
+ line = next(x for x in cap.out.splitlines() if x.startswith("pytest "))
51
+ return rc, line, cap.err
52
+
53
+
54
+ def test_E1_foreign_sidecar_from_the_repo_root_is_not_a_false_alarm(setup, capsys):
55
+ _, repo, g = setup
56
+ _foreign(g)
57
+ rc, line, err = _tests(capsys, g)
58
+ assert rc == 0 and line == "pytest tests/test_a.py::test_a"
59
+ assert "could not be located" not in err
60
+ assert f"the graph was built in `{FOREIGN}`, which is not on this machine" in err
61
+
62
+
63
+ def test_E2_source_root_from_the_parent(setup, capsys, monkeypatch):
64
+ tmp, repo, g = setup
65
+ _foreign(g)
66
+ monkeypatch.chdir(tmp)
67
+ rc, line, err = _tests(capsys, g, "--source-root", "repo")
68
+ assert line == "pytest repo/tests/test_a.py::test_a"
69
+ assert "not found" not in err and "could not be located" not in err
70
+
71
+
72
+ def test_E3_a_wrong_source_root_is_named_and_cwd_is_not_tried(setup, capsys):
73
+ _, repo, g = setup
74
+ _foreign(g)
75
+ rc, line, err = _tests(capsys, g, "--source-root", "pkg") # cwd would have worked
76
+ assert line == "pytest tests/test_a.py::test_a" # as stored, not rewritten
77
+ assert "1 of 1 path(s) not found under `--source-root pkg`" in err
78
+
79
+
80
+ def test_E4_no_sidecar(setup, capsys, monkeypatch):
81
+ tmp, repo, g = setup
82
+ _foreign(g, drop=True)
83
+ rc, line, err = _tests(capsys, g)
84
+ assert line == "pytest tests/test_a.py::test_a" and "common directory" not in err
85
+ monkeypatch.chdir(tmp)
86
+ rc, line, err = _tests(capsys, g)
87
+ assert "pass `--source-root`" in err
88
+
89
+
90
+ def test_E4_foreign_and_not_found_names_both(setup, capsys, monkeypatch):
91
+ tmp, repo, g = setup
92
+ _foreign(g)
93
+ monkeypatch.chdir(tmp)
94
+ rc, line, err = _tests(capsys, g)
95
+ assert "could not be located" in err and f"built in `{FOREIGN}`" in err and "pass `--source-root`" in err
96
+
97
+
98
+ def test_E5_a_local_graph_from_the_parent_is_unchanged(setup, capsys, monkeypatch):
99
+ tmp, repo, g = setup
100
+ monkeypatch.chdir(tmp)
101
+ rc, line, err = _tests(capsys, g)
102
+ assert line == "pytest repo/tests/test_a.py::test_a"
103
+ assert "could not be located" not in err and "built in" not in err
104
+
105
+
106
+ def test_E6_json_ignores_source_root(setup, capsys):
107
+ _, repo, g = setup
108
+ capsys.readouterr()
109
+ main(["tests", "act", "--graph", str(g), "--format", "json"])
110
+ a = capsys.readouterr().out
111
+ main(["tests", "act", "--graph", str(g), "--format", "json", "--source-root", "/nowhere"])
112
+ assert capsys.readouterr().out == a
113
+
114
+
115
+ def test_E7_report_dead_code_reads_the_whitelist_under_source_root(setup, capsys, monkeypatch):
116
+ tmp, repo, g = setup
117
+ (repo / "codemap.toml").write_text('[dead_code]\nwhitelist = ["pkg.core.unused_thing"]\n')
118
+ monkeypatch.chdir(tmp)
119
+ capsys.readouterr()
120
+ main(["report", "dead-code", "--graph", str(g), "--format", "json"])
121
+ without = json.loads(capsys.readouterr().out)["whitelist"]
122
+ main(["report", "dead-code", "--graph", str(g), "--format", "json", "--source-root", "repo"])
123
+ with_root = json.loads(capsys.readouterr().out)["whitelist"]
124
+ assert without["patterns"] == [] # read from cwd: no codemap.toml there
125
+ assert with_root["patterns"] == ["pkg.core.unused_thing"]
@@ -0,0 +1,126 @@
1
+ """R1-C84 — a `--consumer` / `--docs` root that is not a directory is refused, not skipped.
2
+
3
+ Design `docs/design/missing_roots.md` (pre-registered 0e2a9c1).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import shutil
9
+ from pathlib import Path
10
+
11
+ import pytest
12
+
13
+ from codemap import cli
14
+ from codemap.cli import main
15
+ from codemap.extract import extract_repo
16
+
17
+
18
+ @pytest.fixture
19
+ def repo(tmp_path, monkeypatch) -> Path:
20
+ for rel, body in {
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\ndef test_a():\n assert act()\n",
24
+ "examples/ex.py": "from pkg.core import act\n\nact()\n",
25
+ }.items():
26
+ p = tmp_path / rel
27
+ p.parent.mkdir(parents=True, exist_ok=True)
28
+ p.write_text(body)
29
+ (tmp_path / "empty").mkdir()
30
+ monkeypatch.chdir(tmp_path)
31
+ return tmp_path
32
+
33
+
34
+ def _build(*extra) -> int:
35
+ return main(["build", "pkg", "-o", "g.json", "--mode", "full", *extra])
36
+
37
+
38
+ def test_E1_missing_consumer_exits_2_and_leaves_the_graph_alone(repo, capsys):
39
+ assert _build("--consumer", "tests") == 0
40
+ before = Path("g.json").read_bytes()
41
+ capsys.readouterr()
42
+ assert _build("--consumer", "nope") == 2
43
+ err = capsys.readouterr().err
44
+ assert "error: `--consumer nope`: no such directory" in err
45
+ assert Path("g.json").read_bytes() == before
46
+
47
+
48
+ def test_E2_a_list_in_one_string_gets_the_split_command(repo, capsys):
49
+ assert _build("--consumer", "tests,examples") == 2
50
+ err = capsys.readouterr().err
51
+ assert "looks like a list; pass the flag once per root: `--consumer tests --consumer examples`" in err
52
+ assert _build("--consumer", "tests,nope") == 2
53
+ err = capsys.readouterr().err
54
+ assert "no such directory" in err and "looks like a list" not in err
55
+
56
+
57
+ def test_E3_missing_docs_and_a_file_as_root(repo, capsys):
58
+ assert _build("--docs", "nope") == 2
59
+ assert "error: `--docs nope`: no such directory" in capsys.readouterr().err
60
+ assert _build("--consumer", "pkg/core.py") == 2
61
+ assert "error: `--consumer pkg/core.py`: not a directory" in capsys.readouterr().err
62
+
63
+
64
+ def test_E3_every_problem_is_named_not_just_the_first(repo, capsys):
65
+ assert _build("--consumer", "tests", "--consumer", "nope1", "--docs", "nope2") == 2
66
+ err = capsys.readouterr().err
67
+ assert "`--consumer nope1`" in err and "`--docs nope2`" in err
68
+
69
+
70
+ def test_E4_scope_and_watch_refuse_the_same_way(repo, capsys):
71
+ assert main(["scope", "pkg", "--consumer", "nope", "--no-git"]) == 2
72
+ assert "`--consumer nope`: no such directory" in capsys.readouterr().err
73
+ assert main(["watch", "pkg", "-o", "w.json", "--consumer", "nope"]) == 2
74
+ assert "`--consumer nope`: no such directory" in capsys.readouterr().err
75
+ assert not Path("w.json").exists()
76
+
77
+
78
+ def test_E4_refresh_names_a_root_deleted_since_the_build(repo, capsys, monkeypatch):
79
+ assert _build("--consumer", "tests", "--consumer", "examples") == 0
80
+ shutil.rmtree(repo / "examples")
81
+ capsys.readouterr()
82
+ assert main(["refresh", str(repo / "g.json")]) == 2
83
+ assert "`--consumer examples`: no such directory" in capsys.readouterr().err
84
+
85
+
86
+ def test_E4_watch_reports_a_refused_rebuild_as_failed(repo, capsys, monkeypatch):
87
+ # a root deleted while watching: _cmd_build returns 2 instead of raising
88
+ monkeypatch.setattr(cli, "_cmd_build", lambda a: 2)
89
+ seen = {}
90
+
91
+ class Poller:
92
+ QUICK_MAX = 1
93
+
94
+ def __init__(self, probe, rebuild, **kw):
95
+ seen["rebuild"] = rebuild
96
+
97
+ def run(self, *a, **kw):
98
+ seen["result"] = seen["rebuild"]("sid-x")
99
+
100
+ monkeypatch.setattr("codemap.watch.DebouncedPoller", Poller)
101
+ monkeypatch.setattr(cli, "_watch_start_is_stale", lambda out, sid: False)
102
+ main(["watch", "pkg", "-o", "w.json", "--consumer", "tests"])
103
+ assert seen["result"] is False
104
+ assert "rebuild FAILED" in capsys.readouterr().err
105
+
106
+
107
+ def test_E5_refused_before_the_core_is_extracted(repo, capsys, monkeypatch):
108
+ def boom(*a, **kw):
109
+ raise AssertionError("core extracted before the roots were checked")
110
+ monkeypatch.setattr("codemap.extract.roots.extract", boom)
111
+ monkeypatch.setattr(cli, "extract_repo", lambda *a, **kw: boom())
112
+ assert _build("--deep", "--consumer", "nope") == 2
113
+ assert "no such directory" in capsys.readouterr().err
114
+
115
+
116
+ def test_E6_the_library_refuses_too(repo):
117
+ with pytest.raises(ValueError, match="`--consumer nope`: no such directory"):
118
+ extract_repo("pkg", consumers=("tests", "nope"))
119
+ with pytest.raises(ValueError, match="`--docs README.md`: not a directory"):
120
+ Path("README.md").write_text("x\n")
121
+ extract_repo("pkg", docs=("README.md",))
122
+
123
+
124
+ def test_E7_an_empty_directory_is_still_a_legal_root(repo):
125
+ assert _build("--consumer", "empty") == 0
126
+ assert _build("--consumer", "tests", "--docs", "empty") == 0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes