codmap 0.0.46__tar.gz → 0.0.47__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 (219) hide show
  1. {codmap-0.0.46/codmap.egg-info → codmap-0.0.47}/PKG-INFO +2 -2
  2. {codmap-0.0.46 → codmap-0.0.47}/README.md +1 -1
  3. {codmap-0.0.46 → codmap-0.0.47}/codemap/advise/__init__.py +14 -5
  4. {codmap-0.0.46 → codmap-0.0.47}/codemap/advise/refresh.py +33 -5
  5. {codmap-0.0.46 → codmap-0.0.47}/codemap/cli.py +24 -10
  6. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/hooks.py +3 -2
  7. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/install.py +73 -14
  8. {codmap-0.0.46 → codmap-0.0.47/codmap.egg-info}/PKG-INFO +2 -2
  9. {codmap-0.0.46 → codmap-0.0.47}/codmap.egg-info/SOURCES.txt +3 -0
  10. {codmap-0.0.46 → codmap-0.0.47}/pyproject.toml +1 -1
  11. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c108_devkit.py +1 -1
  12. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c114_devkit_graph.py +1 -1
  13. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c119_first_build.py +10 -0
  14. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c121_devkit_trust.py +2 -2
  15. codmap-0.0.47/tests/test_r1c133_pin_links.py +138 -0
  16. codmap-0.0.47/tests/test_r1c134_refresh_recipe.py +77 -0
  17. codmap-0.0.47/tests/test_r1c135_advise_generations.py +110 -0
  18. {codmap-0.0.46 → codmap-0.0.47}/LICENSE +0 -0
  19. {codmap-0.0.46 → codmap-0.0.47}/codemap/__init__.py +0 -0
  20. {codmap-0.0.46 → codmap-0.0.47}/codemap/__main__.py +0 -0
  21. {codmap-0.0.46 → codmap-0.0.47}/codemap/advise/data/feed.json +0 -0
  22. {codmap-0.0.46 → codmap-0.0.47}/codemap/advise/data/matrix.toml +0 -0
  23. {codmap-0.0.46 → codmap-0.0.47}/codemap/advise/render.py +0 -0
  24. {codmap-0.0.46 → codmap-0.0.47}/codemap/apidiff.py +0 -0
  25. {codmap-0.0.46 → codmap-0.0.47}/codemap/arch.py +0 -0
  26. {codmap-0.0.46 → codmap-0.0.47}/codemap/atomic.py +0 -0
  27. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/__init__.py +0 -0
  28. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/artifacts.py +0 -0
  29. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/ratchet.py +0 -0
  30. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/state.py +0 -0
  31. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/agents_block.md +0 -0
  32. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/agents_block.ru.md +0 -0
  33. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/brief.txt +0 -0
  34. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/claude_hooks.json +0 -0
  35. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/codex_region.toml +0 -0
  36. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/contract_head.toml +0 -0
  37. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/cycles_region.toml +0 -0
  38. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/github-workflow.yml +0 -0
  39. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/gitlab-ci.yml +0 -0
  40. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/mcp_claude.args +0 -0
  41. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/post-commit.sh +0 -0
  42. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/templates/ratchet_region.toml +0 -0
  43. {codmap-0.0.46 → codmap-0.0.47}/codemap/devkit/usage.py +0 -0
  44. {codmap-0.0.46 → codmap-0.0.47}/codemap/diagnostics.py +0 -0
  45. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/__init__.py +0 -0
  46. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/attrflow.py +0 -0
  47. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/behavior.py +0 -0
  48. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/dataflow.py +0 -0
  49. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/dispatch.py +0 -0
  50. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/griffe_extractor.py +0 -0
  51. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/gsource.py +0 -0
  52. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/probe.py +0 -0
  53. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/roots.py +0 -0
  54. {codmap-0.0.46 → codmap-0.0.47}/codemap/extract/union.py +0 -0
  55. {codmap-0.0.46 → codmap-0.0.47}/codemap/freshness.py +0 -0
  56. {codmap-0.0.46 → codmap-0.0.47}/codemap/incremental.py +0 -0
  57. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/__init__.py +0 -0
  58. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/base.py +0 -0
  59. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/cocoindex.py +0 -0
  60. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/gate.py +0 -0
  61. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/gitnexus.py +0 -0
  62. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/registry.py +0 -0
  63. {codmap-0.0.46 → codmap-0.0.47}/codemap/integrations/transport.py +0 -0
  64. {codmap-0.0.46 → codmap-0.0.47}/codemap/model.py +0 -0
  65. {codmap-0.0.46 → codmap-0.0.47}/codemap/provenance.py +0 -0
  66. {codmap-0.0.46 → codmap-0.0.47}/codemap/query.py +0 -0
  67. {codmap-0.0.46 → codmap-0.0.47}/codemap/scope.py +0 -0
  68. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/__init__.py +0 -0
  69. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/_scip_pb2.py +0 -0
  70. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/api_surface.py +0 -0
  71. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/apidiff.py +0 -0
  72. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/architecture.py +0 -0
  73. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/audit.py +0 -0
  74. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/check.py +0 -0
  75. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/ctags.py +0 -0
  76. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/currency.py +0 -0
  77. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/impact.py +0 -0
  78. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/limits.py +0 -0
  79. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/livingdocs.py +0 -0
  80. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/mcp_server.py +0 -0
  81. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/mermaid.py +0 -0
  82. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/pack.py +0 -0
  83. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/rag.py +0 -0
  84. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/review.py +0 -0
  85. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/scip.py +0 -0
  86. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/semantic.py +0 -0
  87. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/server.py +0 -0
  88. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/session.py +0 -0
  89. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/subsystems.py +0 -0
  90. {codmap-0.0.46 → codmap-0.0.47}/codemap/serve/vault.py +0 -0
  91. {codmap-0.0.46 → codmap-0.0.47}/codemap/store.py +0 -0
  92. {codmap-0.0.46 → codmap-0.0.47}/codemap/tomlio.py +0 -0
  93. {codmap-0.0.46 → codmap-0.0.47}/codemap/watch.py +0 -0
  94. {codmap-0.0.46 → codmap-0.0.47}/codmap.egg-info/dependency_links.txt +0 -0
  95. {codmap-0.0.46 → codmap-0.0.47}/codmap.egg-info/entry_points.txt +0 -0
  96. {codmap-0.0.46 → codmap-0.0.47}/codmap.egg-info/requires.txt +0 -0
  97. {codmap-0.0.46 → codmap-0.0.47}/codmap.egg-info/top_level.txt +0 -0
  98. {codmap-0.0.46 → codmap-0.0.47}/setup.cfg +0 -0
  99. {codmap-0.0.46 → codmap-0.0.47}/tests/test_epistemic.py +0 -0
  100. {codmap-0.0.46 → codmap-0.0.47}/tests/test_gitnexus_router.py +0 -0
  101. {codmap-0.0.46 → codmap-0.0.47}/tests/test_impact_depth.py +0 -0
  102. {codmap-0.0.46 → codmap-0.0.47}/tests/test_integrations.py +0 -0
  103. {codmap-0.0.46 → codmap-0.0.47}/tests/test_issue3_serve_freshness.py +0 -0
  104. {codmap-0.0.46 → codmap-0.0.47}/tests/test_livingdocs.py +0 -0
  105. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m0_api_surface.py +0 -0
  106. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m11_argcontract.py +0 -0
  107. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m12_dataflow.py +0 -0
  108. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m15_review.py +0 -0
  109. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m16_architecture.py +0 -0
  110. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m17_mcp.py +0 -0
  111. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m18_freshness.py +0 -0
  112. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m1_5_semantics.py +0 -0
  113. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m1_query.py +0 -0
  114. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m2_views.py +0 -0
  115. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m32_watch.py +0 -0
  116. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m3_serve.py +0 -0
  117. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m4_behavior.py +0 -0
  118. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m5_deep.py +0 -0
  119. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m6_repo_scope.py +0 -0
  120. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m7_dispatch.py +0 -0
  121. {codmap-0.0.46 → codmap-0.0.47}/tests/test_m9_family.py +0 -0
  122. {codmap-0.0.46 → codmap-0.0.47}/tests/test_pack_honesty.py +0 -0
  123. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c109_namespace_source.py +0 -0
  124. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c110_advise.py +0 -0
  125. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c111_recipe.py +0 -0
  126. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c115_agents_block.py +0 -0
  127. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c116_known_cycles.py +0 -0
  128. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c118_dead_code.py +0 -0
  129. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c120_dispatch_absorbed.py +0 -0
  130. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c122_serve_robust.py +0 -0
  131. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c124_atomic_writes.py +0 -0
  132. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c125_graph_trust.py +0 -0
  133. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c126_scope_roles.py +0 -0
  134. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c127_require_current.py +0 -0
  135. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  136. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c13_grep_vs_graph.py +0 -0
  137. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c16_semantic.py +0 -0
  138. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c20_attribute_edges.py +0 -0
  139. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c21_flat_layout.py +0 -0
  140. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c22_source_visible_refs.py +0 -0
  141. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c23_hard_python.py +0 -0
  142. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c24_test_mapping.py +0 -0
  143. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c25_provenance.py +0 -0
  144. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c26_deep_union.py +0 -0
  145. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c27_config_honesty.py +0 -0
  146. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c28_limit_envelope.py +0 -0
  147. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c29_lazy_imports.py +0 -0
  148. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c2_ctags.py +0 -0
  149. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c30_local_import_calls.py +0 -0
  150. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c30f1_reexport_calls.py +0 -0
  151. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c30f2_check_scope.py +0 -0
  152. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c31_path_origin.py +0 -0
  153. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c32_report_json.py +0 -0
  154. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c33_query_signature.py +0 -0
  155. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c34_signature_kinds.py +0 -0
  156. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c35_contract_location.py +0 -0
  157. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c36_target_resolution.py +0 -0
  158. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c37_rule_mutation.py +0 -0
  159. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c38_tool_drift.py +0 -0
  160. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c39_edge_resolution.py +0 -0
  161. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c3_arch_contract.py +0 -0
  162. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c3_dogfood.py +0 -0
  163. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c40_flow_reach.py +0 -0
  164. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c41_scope_membership.py +0 -0
  165. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c42_deep_tier_stability.py +0 -0
  166. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c43_incremental_splice.py +0 -0
  167. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c44_absent_answers.py +0 -0
  168. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c45_repeat_union.py +0 -0
  169. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c46_shadowed_definitions.py +0 -0
  170. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c47_incremental_resample.py +0 -0
  171. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c48_type_checking_imports.py +0 -0
  172. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c49_type_only_cycles.py +0 -0
  173. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c4_complexity.py +0 -0
  174. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c50_flow_entry_points.py +0 -0
  175. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c53_narrowing_declared.py +0 -0
  176. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c54_deterministic_rendering.py +0 -0
  177. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c55_override_grade.py +0 -0
  178. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c56_stub_files.py +0 -0
  179. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c57_facade_package.py +0 -0
  180. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c58_cycle_tangles.py +0 -0
  181. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c59_completeness_drop.py +0 -0
  182. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c5_apidiff.py +0 -0
  183. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c60_nested_definitions.py +0 -0
  184. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c62_phantom_rules.py +0 -0
  185. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c63_answer_format.py +0 -0
  186. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c64_dependency_probe.py +0 -0
  187. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c66_pack_direction.py +0 -0
  188. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c68_dotted_imports.py +0 -0
  189. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c69_contract_validation.py +0 -0
  190. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c6_pack.py +0 -0
  191. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c70_check_graph_currency.py +0 -0
  192. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  193. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  194. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c73_cli_version.py +0 -0
  195. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c74_call_site_conservation.py +0 -0
  196. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c75_reexported_class_calls.py +0 -0
  197. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c76_contract_table_typo.py +0 -0
  198. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c77_gate_probe_battery.py +0 -0
  199. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c78_forbidden_chains.py +0 -0
  200. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c7_edge_vocab.py +0 -0
  201. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c80_tests_through_helpers.py +0 -0
  202. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c81_protocol_dispatch.py +0 -0
  203. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c82_review_changed_lines.py +0 -0
  204. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  205. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c84_missing_roots.py +0 -0
  206. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  207. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  208. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c87_review_path_base.py +0 -0
  209. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c89_review_docs.py +0 -0
  210. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c8_deadcode.py +0 -0
  211. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c90_currency_without_recipe.py +0 -0
  212. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c91_route_vocabulary.py +0 -0
  213. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c92_sidecar_pair.py +0 -0
  214. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c94_root_builds.py +0 -0
  215. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c95_r1c96_foreign_trees.py +0 -0
  216. {codmap-0.0.46 → codmap-0.0.47}/tests/test_r1c9_incremental.py +0 -0
  217. {codmap-0.0.46 → codmap-0.0.47}/tests/test_scip_export.py +0 -0
  218. {codmap-0.0.46 → codmap-0.0.47}/tests/test_scope.py +0 -0
  219. {codmap-0.0.46 → codmap-0.0.47}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.46
3
+ Version: 0.0.47
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
@@ -54,7 +54,7 @@ without a release.
54
54
 
55
55
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
56
56
 
57
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1476 tests with no failures on
57
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1499 tests with no failures on
58
58
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
59
59
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 32 ops (29 exposed
60
60
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -18,7 +18,7 @@ without a release.
18
18
 
19
19
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
20
20
 
21
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1476 tests with no failures on
21
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1499 tests with no failures on
22
22
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
23
23
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 32 ops (29 exposed
24
24
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -104,14 +104,17 @@ class Catalog:
104
104
  CURRENT = "current"
105
105
 
106
106
 
107
- def _served_dir(cdir: Path) -> Path:
108
- """The generation ``current`` names, or the cache itself for a pair written before generations existed."""
107
+ def _served_dir(cdir: Path) -> tuple[Path, str | None]:
108
+ """The generation ``current`` names, or the cache itself for a pair written before generations existed; and a
109
+ note when ``current`` names a generation that is not there (R1-C135: said, not silently replaced)."""
109
110
  try:
110
111
  name = (cdir / CURRENT).read_text(encoding="utf-8").strip()
111
112
  except OSError:
112
- return cdir
113
+ return cdir, None
113
114
  gen = cdir / name
114
- return gen if name.startswith("gen-") and "/" not in name and gen.is_dir() else cdir
115
+ if name.startswith("gen-") and "/" not in name and gen.is_dir():
116
+ return gen, None
117
+ return cdir, f"cache pointer `{CURRENT}` names {name!r}, which is not there; run `codemap advise --refresh`"
115
118
 
116
119
 
117
120
  def cache_dir() -> Path:
@@ -146,7 +149,13 @@ def load(cache: Path | None = None, packaged: Path | None = None) -> Catalog:
146
149
  cdir = cache if cache is not None else cache_dir()
147
150
  if not cdir.is_dir():
148
151
  return cat
149
- cm, cf, cerrs = _read_pair(_served_dir(cdir))
152
+ for _ in range(3): # R1-C135: one file there and the other gone = a publish in between
153
+ served, note = _served_dir(cdir)
154
+ cm, cf, cerrs = _read_pair(served)
155
+ if (cm is None) == (cf is None):
156
+ break
157
+ if note:
158
+ cat.notes.append(note)
150
159
  cat.notes.extend(f"cache ignored: {e}" for e in cerrs)
151
160
  m, f, src = pm, pf, {"matrix": "packaged", "feed": "packaged"}
152
161
  if cm is not None and cm.get("meta", {}).get("as_of", "") > pm.get("meta", {}).get("as_of", ""):
@@ -57,10 +57,18 @@ def refresh(base: str | None = None, cache: Path | None = None) -> dict:
57
57
  return out
58
58
 
59
59
 
60
+ #: R1-C135: a generation is removed only once it is this old and `current` does not name it — a reader that took
61
+ #: its path a moment ago, or a second publisher that has just pointed `current` at it, still finds it whole.
62
+ GRACE_SECONDS = 600
63
+
64
+
60
65
  def publish_pair(cdir: Path, mraw: bytes, fraw: bytes) -> None:
61
66
  """Publish matrix + feed as one generation (R1-C124): both files go to a new directory, then the pointer
62
67
  file ``current`` is replaced atomically. A failure before that leaves the previous pair served whole; a reader
63
- never sees one file of one generation beside the other file of another."""
68
+ never sees one file of one generation beside the other file of another.
69
+
70
+ Old generations are collected by :func:`collect`, not all at once (R1-C135): two publishers each removing
71
+ every generation but its own left `current` naming a removed one."""
64
72
  import shutil
65
73
  import tempfile
66
74
 
@@ -74,11 +82,31 @@ def publish_pair(cdir: Path, mraw: bytes, fraw: bytes) -> None:
74
82
  except BaseException:
75
83
  shutil.rmtree(gen, ignore_errors=True)
76
84
  raise
77
- for old in cdir.glob("gen-*"): # previous generations, and any torn leftovers
78
- if old.is_dir() and old.name != gen.name:
79
- shutil.rmtree(old, ignore_errors=True)
80
- for legacy in ("matrix.toml", "feed.json"): # a pre-0.0.46 pair at the top level
85
+ collect(cdir)
86
+ for legacy in ("matrix.toml", "feed.json"): # a pre-0.0.46 pair at the top level (load retries a split read)
81
87
  try:
82
88
  (cdir / legacy).unlink()
83
89
  except FileNotFoundError:
84
90
  pass
91
+
92
+
93
+ def collect(cdir: Path, now: float | None = None) -> list[str]:
94
+ """Remove generations `current` does not name *now* and that are older than :data:`GRACE_SECONDS`; the names."""
95
+ import shutil
96
+ import time
97
+
98
+ now = time.time() if now is None else now
99
+ try:
100
+ served = (cdir / CURRENT).read_text(encoding="utf-8").strip()
101
+ except OSError:
102
+ served = None
103
+ gone = []
104
+ for old in sorted(cdir.glob("gen-*")):
105
+ try:
106
+ young = now - old.stat().st_mtime < GRACE_SECONDS
107
+ except OSError:
108
+ continue
109
+ if old.is_dir() and old.name != served and not young:
110
+ shutil.rmtree(old, ignore_errors=True)
111
+ gone.append(old.name)
112
+ return gone
@@ -902,27 +902,41 @@ def _cmd_refresh(args) -> int:
902
902
  raise SystemExit(f"error: the recorded recipe beside {args.graph} is not repeated — {problem}; "
903
903
  f"rebuild by hand with `codemap build <package> -o {args.graph}`")
904
904
  cwd = meta.get("cwd")
905
- if cwd and os.path.isdir(cwd):
906
- os.chdir(cwd) # recorded argv may use paths relative to the build cwd
905
+ if cwd:
906
+ os.chdir(cwd) # recorded argv may use paths relative to the build cwd; _recipe_problem checked from it
907
907
  print(f"rebuilding {args.graph} …", file=sys.stderr)
908
908
  return main(meta["argv"])
909
909
 
910
910
 
911
911
  def _recipe_problem(meta: dict, graph: str) -> str | None:
912
- """Why a sidecar's ``argv`` is not a rebuild of ``graph`` (R1-C125): `refresh` repeats it as a command, and
913
- the sidecar is a file anyone can edit. Only `build`, writing back to this same graph, is repeated."""
912
+ """Why a sidecar's ``argv`` is not a rebuild of ``graph`` (R1-C125, R1-C134): `refresh` repeats it as a command,
913
+ and the sidecar is a file anyone can edit. Only `build`, writing back to this same graph, is repeated.
914
+
915
+ The recipe is read by the very parser that will run it — a repeated `-o`, an abbreviated `--ou`, an attached
916
+ `-oX` mean to the check what they mean to `build` — and from the working directory it will run in.
917
+ """
918
+ import contextlib
919
+ import io
914
920
  argv = meta.get("argv")
915
921
  if not isinstance(argv, list) or not argv or not all(isinstance(a, str) for a in argv):
916
922
  return "it is not a list of arguments"
917
923
  if argv[0] != "build":
918
924
  return f"it runs `{argv[0]}`, not `build`"
919
- out = next((argv[i + 1] for i, a in enumerate(argv[:-1]) if a in ("-o", "--out")), None)
920
- out = out or next((a.split("=", 1)[1] for a in argv if a.startswith("--out=")), None)
921
- if out is None:
925
+ try:
926
+ with contextlib.redirect_stderr(io.StringIO()) as err:
927
+ args = build_parser().parse_args(argv)
928
+ except SystemExit:
929
+ last = err.getvalue().strip().splitlines()
930
+ return f"`build` does not take it ({last[-1] if last else 'unparsable'})"
931
+ if args.command != "build":
932
+ return f"it runs `{args.command}`, not `build`"
933
+ if not args.out:
922
934
  return "it writes no graph file"
923
- cwd = meta.get("cwd") if isinstance(meta.get("cwd"), str) else os.getcwd()
924
- if (Path(cwd) / out).resolve() != Path(graph).resolve():
925
- return f"it writes {out!r}, not this graph"
935
+ cwd = meta.get("cwd")
936
+ if cwd is not None and not (isinstance(cwd, str) and os.path.isdir(cwd)):
937
+ return f"its working directory {cwd!r} is not a directory here"
938
+ if (Path(cwd or os.getcwd()) / args.out).resolve() != Path(graph).resolve():
939
+ return f"it writes {args.out!r}, not this graph"
926
940
  return None
927
941
 
928
942
 
@@ -56,8 +56,9 @@ def currency_line(root: Path, st: dict) -> str:
56
56
  # R1-C119: a fresh clone has no graph and `refresh` has no recipe to repeat — give the first build.
57
57
  from codemap.devkit import build_args
58
58
  cmd = " ".join(x for x in ("codemap build", st.get("package", "<package>"), build_args(st), "-o", rel) if x)
59
- return (f"absent ({rel} does not exist; build it once: `{cmd}` — after that the post-commit hook "
60
- "keeps it)")
59
+ keeps = ("after that the post-commit hook keeps it" if (st.get("options") or {}).get("hook", True)
60
+ else f"there is no post-commit hook here, so refresh it after changes: `codemap refresh {rel}`")
61
+ return f"absent ({rel} does not exist; build it once: `{cmd}` — {keeps})"
61
62
  meta = read_meta(str(gp)) or {}
62
63
  built = meta.get("built_at")
63
64
  when = f", built {_ago(built)}" if isinstance(built, (int, float)) else ""
@@ -54,7 +54,8 @@ def running_pin() -> list[str]:
54
54
  repository — a `codemap/` package committed there would be what runs.
55
55
  """
56
56
  argv0 = Path(sys.argv[0]) if sys.argv and sys.argv[0] else None
57
- if argv0 is not None and argv0.name == "codemap" and argv0.exists():
57
+ # R1-C133: a pin this codemap writes must pass the check `status` applies to it (a wrapper is not a script)
58
+ if argv0 is not None and argv0.name == "codemap" and argv0.is_file() and _console_script_problem(argv0) is None:
58
59
  # abspath, not resolve: `..` is folded, a venv's symlinked bin is kept as the user named it
59
60
  return [os.path.abspath(argv0)]
60
61
  return [sys.executable, "-I", "-m", "codemap"]
@@ -63,23 +64,73 @@ def running_pin() -> list[str]:
63
64
  _PYTHON = re.compile(r"python(\d+(\.\d+)*)?(\.exe)?")
64
65
 
65
66
 
66
- def _tracked(root: Path, path: Path) -> bool:
67
- """Is ``path`` a file the repository carries (so whoever pushed chose its content)?"""
67
+ def _inside(root: Path, path: str) -> Path | None:
68
+ """``path`` relative to ``root`` as written (``..`` folded, links not followed), or None when outside."""
69
+ p = Path(os.path.abspath(path))
70
+ for base in {Path(os.path.abspath(root)), root.resolve()}:
71
+ try:
72
+ return p.relative_to(base)
73
+ except ValueError:
74
+ continue
75
+ return None
76
+
77
+
78
+ def _carried(root: Path, path: str) -> str | None:
79
+ """Why ``path`` is a file the repository carries — so whoever pushed chose what runs — or None.
80
+
81
+ R1-C133: asked of the path as written *and* of each directory on it, before any link is followed: a tracked
82
+ link ``tools/codemap → /bin/sh`` resolves outside the root, and asking git about the resolved path said
83
+ "not ours". The resolved path is asked too (a link from outside into the repository).
84
+ """
85
+ rels = []
86
+ lexical = _inside(root, path)
87
+ if lexical is not None:
88
+ parts = lexical.parts
89
+ rels += [Path(*parts[:i]).as_posix() for i in range(1, len(parts) + 1)]
68
90
  try:
69
- rel = path.resolve().relative_to(root.resolve())
91
+ rels.append(Path(path).resolve().relative_to(root.resolve()).as_posix())
70
92
  except ValueError:
71
- return False
72
- r = subprocess.run(["git", "-C", str(root), "ls-files", "--error-unmatch", "--", str(rel)],
93
+ pass
94
+ if not rels:
95
+ return None
96
+ r = subprocess.run(["git", "--literal-pathspecs", "-C", str(root), "ls-files", "-s", "-z", "--", *rels],
73
97
  capture_output=True)
74
- return r.returncode == 0
98
+ if r.returncode != 0:
99
+ return "it is inside a directory that is not a git repository, so who wrote it cannot be told"
100
+ listed = {entry.split(b"\t", 1)[1].decode("utf-8", "replace") for entry in r.stdout.split(b"\0") if b"\t" in entry}
101
+ hit = next((rel for rel in rels if rel in listed), None)
102
+ if hit is None:
103
+ return None
104
+ if lexical is not None and hit == lexical.as_posix():
105
+ return "it is a file of this repository"
106
+ return f"`{hit}` on its way is carried by this repository"
107
+
108
+
109
+ #: R1-C133: what an installed console script for codemap holds (pip, pipx, uv write `from codemap.cli import main`)
110
+ _CONSOLE_MARK = b"codemap.cli"
111
+
112
+
113
+ def _console_script_problem(exe: Path) -> str | None:
114
+ """Is ``exe`` (followed to its target) a console script that starts codemap? Asked of the content, not the name."""
115
+ try:
116
+ with open(exe, "rb") as fh:
117
+ head = fh.read(4096 if exe.suffix.lower() != ".exe" else 8 << 20)
118
+ except OSError as exc:
119
+ return f"it cannot be read ({exc.strerror})"
120
+ if exe.suffix.lower() == ".exe":
121
+ ok = _CONSOLE_MARK in head # the launcher carries its script as a stored zip
122
+ else:
123
+ ok = head.startswith(b"#!") and _CONSOLE_MARK in head
124
+ return None if ok else "it is not a console script that starts codemap"
75
125
 
76
126
 
77
127
  def pin_problem(root: Path, pin: list[str] | None) -> str | None:
78
- """Why ``pin`` is not a codemap the devkit may run or write into the hook, or None (R1-C121).
128
+ """Why ``pin`` is not a codemap the devkit may run or write into the hook, or None (R1-C121, R1-C133).
79
129
 
80
130
  `.mcp.json` is a project file: the command in it is whatever the last push said. Accepted are only the
81
131
  shapes the devkit itself writes — the absolute path of a `codemap` console script, or an absolute python
82
- run as `-I -m codemap` — and never a file the repository carries.
132
+ run as `-I -m codemap` — never a file the repository carries, nor one reached through a directory or link
133
+ it carries; and a console script is accepted by what it holds, not by its name.
83
134
  """
84
135
  if not pin or not all(isinstance(a, str) and a for a in pin):
85
136
  return "no command"
@@ -96,8 +147,13 @@ def pin_problem(root: Path, pin: list[str] | None) -> str | None:
96
147
  return f"{shlex.join(pin)!r} is not `<codemap>` or `<python> -I -m codemap`"
97
148
  if not exe.is_file():
98
149
  return f"{pin[0]} does not exist"
99
- if _tracked(root, exe):
100
- return f"{pin[0]} is a file of this repository, not an installed codemap"
150
+ carried = _carried(root, pin[0])
151
+ if carried:
152
+ return f"{pin[0]}: {carried}, not an installed codemap"
153
+ if len(pin) == 1:
154
+ script = _console_script_problem(exe)
155
+ if script:
156
+ return f"{pin[0]}: {script}"
101
157
  return None
102
158
 
103
159
 
@@ -487,10 +543,13 @@ def init(root: Path, *, package: str, consumers: list[str], docs: list[str], age
487
543
  ok, err = _build_graph(root, st, pin)
488
544
  if not ok:
489
545
  notes.append(f"graph build FAILED — {err.splitlines()[-1] if err else 'no message'}")
490
- elif graph.is_file() and unfit != "there is no graph":
491
- notes.append(f"graph rebuilt ({unfit}; fast tier — the post-commit hook builds --deep)")
492
546
  else:
493
- notes.append("graph built (fast tier; the post-commit hook builds --deep)")
547
+ # The hook's --deep rebuild is promised only where there is a hook (tgsh-26, 23.11).
548
+ deep = ("the post-commit hook builds --deep" if hook
549
+ else "no hook: `codemap build … --deep` or `codemap refresh` by hand")
550
+ notes.append(f"graph rebuilt ({unfit}; fast tier — {deep})"
551
+ if graph.is_file() and unfit != "there is no graph"
552
+ else f"graph built (fast tier; {deep})")
494
553
  _contract(root, st, ratchet=ratchet, dry_run=dry_run, notes=notes)
495
554
  if any(o.key == "mcp" and o.status == "created" for o in outcomes):
496
555
  notes.append(".mcp.json names the codemap executable by its absolute path on this machine "
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.46
3
+ Version: 0.0.47
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
@@ -54,7 +54,7 @@ without a release.
54
54
 
55
55
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
56
56
 
57
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1476 tests with no failures on
57
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1499 tests with no failures on
58
58
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
59
59
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 32 ops (29 exposed
60
60
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -127,6 +127,9 @@ tests/test_r1c124_atomic_writes.py
127
127
  tests/test_r1c125_graph_trust.py
128
128
  tests/test_r1c126_scope_roles.py
129
129
  tests/test_r1c127_require_current.py
130
+ tests/test_r1c133_pin_links.py
131
+ tests/test_r1c134_refresh_recipe.py
132
+ tests/test_r1c135_advise_generations.py
130
133
  tests/test_r1c13_callgraph_accuracy.py
131
134
  tests/test_r1c13_grep_vs_graph.py
132
135
  tests/test_r1c16_semantic.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.46"
12
+ version = "0.0.47"
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
@@ -32,7 +32,7 @@ def _fake_codemap(where: Path) -> str:
32
32
  """An installed-looking `codemap` outside the repository (R1-C121 keeps only such a pin)."""
33
33
  where.mkdir(parents=True, exist_ok=True)
34
34
  exe = where / "codemap"
35
- exe.write_text("#!/bin/sh\necho codemap 0.0.0\n")
35
+ exe.write_text("#!/bin/sh\n# stands in for `from codemap.cli import main`\necho codemap 0.0.0\n")
36
36
  exe.chmod(0o755)
37
37
  return str(exe)
38
38
 
@@ -22,7 +22,7 @@ def _fake_codemap(where: Path) -> str:
22
22
  """An installed-looking `codemap` outside the repository (R1-C121 keeps only such a pin)."""
23
23
  where.mkdir(parents=True, exist_ok=True)
24
24
  exe = where / "codemap"
25
- exe.write_text("#!/bin/sh\necho codemap 0.0.0\n")
25
+ exe.write_text("#!/bin/sh\n# stands in for `from codemap.cli import main`\necho codemap 0.0.0\n")
26
26
  exe.chmod(0o755)
27
27
  return str(exe)
28
28
 
@@ -45,3 +45,13 @@ def test_e4_status_gives_the_first_build_command(tmp_path):
45
45
  st = {"package": "src/pkg", "consumers": ["tests"], "docs": ["docs"], "graph": ".codemap/graph.json"}
46
46
  line = currency_line(tmp_path, st)
47
47
  assert ("`codemap build src/pkg --consumer tests --docs docs --mode full -o .codemap/graph.json`" in line), line
48
+
49
+
50
+
51
+ def test_status_does_not_promise_a_hook_that_is_off(tmp_path):
52
+ """tgsh-26, 23.11: with `hook: false` the absent-graph line must not say the hook keeps the graph."""
53
+ st = {"package": "pkg", "consumers": [], "docs": [], "graph": ".codemap/graph.json", "options": {"hook": False}}
54
+ line = currency_line(tmp_path, st)
55
+ assert "post-commit hook keeps it" not in line and "`codemap refresh .codemap/graph.json`" in line
56
+ st["options"]["hook"] = True
57
+ assert "post-commit hook keeps it" in currency_line(tmp_path, st)
@@ -69,7 +69,7 @@ def test_e2_only_the_shapes_the_devkit_writes_are_accepted(tmp_path, pin, ok):
69
69
  bindir = tmp_path / "bin"
70
70
  bindir.mkdir()
71
71
  for name in ("codemap", "python3.12", "sh"):
72
- (bindir / name).write_text("#!/bin/sh\n")
72
+ (bindir / name).write_text("#!/bin/sh\nfrom codemap.cli import main\n")
73
73
  pin = [a.replace("{bin}", str(bindir)) for a in pin]
74
74
  assert (install.pin_problem(root, pin) is None) is ok, install.pin_problem(root, pin)
75
75
 
@@ -81,7 +81,7 @@ def test_e2_a_codemap_the_repository_carries_is_refused(tmp_path):
81
81
  subprocess.run(["git", "-C", str(root), "add", "tools/codemap"], check=True)
82
82
  assert "a file of this repository" in install.pin_problem(root, [str(root / "tools/codemap")])
83
83
  (root / ".venv/bin").mkdir(parents=True) # untracked venv inside the root: fine
84
- (root / ".venv/bin/codemap").write_text("#!/bin/sh\n")
84
+ (root / ".venv/bin/codemap").write_text("#!/bin/sh\nfrom codemap.cli import main\n")
85
85
  assert install.pin_problem(root, [str(root / ".venv/bin/codemap")]) is None
86
86
 
87
87
 
@@ -0,0 +1,138 @@
1
+ """R1-C133 — a pin reached through a link or directory the repository carries is not an installed codemap.
2
+
3
+ Follow-up audit FU-01. Expectations E1–E5 are in BACKLOG.md (R1-C133), written before the change; on 0.0.46 the
4
+ whole chain was reproduced here: `.mcp.json` → tracked link `tools/codemap → /bin/sh` → `update` wrote it into
5
+ the post-commit hook → the hook ran `sh build` in the root. Every attack uses a harmless marker file.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import os
12
+ import shutil
13
+ import subprocess
14
+ import time
15
+ from pathlib import Path
16
+
17
+ from codemap.devkit import install
18
+ from tests.test_r1c108_devkit import _fake_codemap, _repo
19
+ from tests.test_r1c121_devkit_trust import _installed, _tamper_mcp
20
+
21
+ SH = shutil.which("sh") or "/bin/sh"
22
+ SCRIPT = "#!/bin/sh\nfrom codemap.cli import main\n"
23
+
24
+
25
+ def _git_add(root: Path, *paths: str) -> None:
26
+ subprocess.run(["git", "-C", str(root), "add", "--", *paths], check=True)
27
+
28
+
29
+ def _run_hook(root: Path, timeout: float = 30) -> None:
30
+ """Run the installed post-commit hook and wait for its background loop to log one pass."""
31
+ log = root / ".codemap/rebuild.log"
32
+ subprocess.run(["bash", str(root / ".git/hooks/post-commit")], cwd=root, check=True)
33
+ end = time.monotonic() + timeout
34
+ while time.monotonic() < end and not (log.is_file() and log.read_text().strip()):
35
+ time.sleep(0.1)
36
+ assert log.is_file() and log.read_text().strip(), "the hook did not finish a pass"
37
+
38
+
39
+ def test_e1_a_tracked_link_named_codemap_is_refused_and_never_reaches_the_hook(tmp_path, monkeypatch, capsys):
40
+ root = _installed(tmp_path, monkeypatch)
41
+ monkeypatch.undo()
42
+ monkeypatch.setattr(install, "running_pin", lambda: [_fake_codemap(tmp_path / "bin")])
43
+ marker = tmp_path / "MARKER"
44
+ (root / "tools").mkdir()
45
+ os.symlink(SH, root / "tools/codemap")
46
+ (root / "build").write_text(f"touch {marker}\n")
47
+ _git_add(root, "tools/codemap", "build")
48
+ pin = str(root / "tools/codemap")
49
+ assert "a file of this repository" in (install.pin_problem(root, [pin]) or "")
50
+ _tamper_mcp(root, pin, [])
51
+ install.status(root)
52
+ install.update(root, force=False, repin=False, dry_run=False)
53
+ assert "was not run and is not kept" in capsys.readouterr().out
54
+ hook = (root / ".git/hooks/post-commit").read_text()
55
+ assert "tools/codemap" not in hook and f"C={tmp_path}/bin/codemap" in hook
56
+ _run_hook(root) # E6 of the audit: the hook itself, not only the check
57
+ assert not marker.exists(), "the post-commit hook ran a file the repository carries"
58
+
59
+
60
+ def test_e2_a_tracked_directory_link_on_the_way_is_refused(tmp_path):
61
+ root = _repo(tmp_path)
62
+ real = tmp_path / "elsewhere"
63
+ real.mkdir()
64
+ (real / "codemap").write_text(SCRIPT) # a genuine-looking codemap outside the repository
65
+ os.symlink(real, root / "tools")
66
+ _git_add(root, "tools")
67
+ problem = install.pin_problem(root, [str(root / "tools/codemap")])
68
+ assert problem and "`tools` on its way is carried by this repository" in problem, problem
69
+ assert install.pin_problem(root, [str(real / "codemap")]) is None # the same file, named directly
70
+
71
+
72
+ def test_e3_a_file_named_codemap_is_judged_by_what_it_holds(tmp_path):
73
+ root = _repo(tmp_path / "r")
74
+ outside = tmp_path / "bin"
75
+ outside.mkdir()
76
+ shutil.copy(SH, outside / "codemap")
77
+ problem = install.pin_problem(root, [str(outside / "codemap")])
78
+ assert problem and "not a console script that starts codemap" in problem, problem
79
+ os.symlink(SH, tmp_path / "codemap")
80
+ assert "not a console script" in (install.pin_problem(root, [str(tmp_path / "codemap")]) or "")
81
+
82
+
83
+ def test_e4_installed_codemaps_still_pass(tmp_path):
84
+ root = _repo(tmp_path / "r")
85
+ outside = tmp_path / "bin"
86
+ outside.mkdir()
87
+ (outside / "codemap").write_text(SCRIPT)
88
+ assert install.pin_problem(root, [str(outside / "codemap")]) is None
89
+ venv = root / ".venv/bin" # untracked, inside the root
90
+ venv.mkdir(parents=True)
91
+ (venv / "codemap").write_text(SCRIPT)
92
+ assert install.pin_problem(root, [str(venv / "codemap")]) is None
93
+ py = Path(shutil.which("python3") or "/usr/bin/python3").resolve()
94
+ os.symlink(py, venv / "python3") # a venv's python is a link out of the root
95
+ assert install.pin_problem(root, [str(venv / "python3"), "-I", "-m", "codemap"]) is None
96
+ real = Path(_fake_codemap(tmp_path / "fake"))
97
+ assert install.pin_problem(root, [str(real)]) is None
98
+ # the running codemap's own console script, when there is one, passes as it is
99
+ own = Path(shutil.which("codemap") or "")
100
+ if own.name == "codemap" and own.is_file():
101
+ assert install.pin_problem(root, [str(own)]) is None
102
+
103
+
104
+ def test_e5_outside_git_a_pin_inside_the_root_is_refused(tmp_path):
105
+ root = tmp_path / "plain"
106
+ (root / ".venv/bin").mkdir(parents=True)
107
+ (root / ".venv/bin/codemap").write_text(SCRIPT)
108
+ problem = install.pin_problem(root, [str(root / ".venv/bin/codemap")])
109
+ assert problem and "not a git repository" in problem, problem
110
+ outside = tmp_path / "bin"
111
+ outside.mkdir()
112
+ (outside / "codemap").write_text(SCRIPT)
113
+ assert install.pin_problem(root, [str(outside / "codemap")]) is None
114
+
115
+
116
+ def test_a_dotdot_spelling_does_not_hide_a_tracked_link(tmp_path):
117
+ root = _repo(tmp_path)
118
+ (root / "tools").mkdir()
119
+ os.symlink(SH, root / "tools/codemap")
120
+ _git_add(root, "tools/codemap")
121
+ sneaky = f"{root}/pkg/../tools/codemap"
122
+ assert "a file of this repository" in (install.pin_problem(root, [sneaky]) or "")
123
+ json.dumps(install.pin_problem(root, [sneaky]))
124
+
125
+
126
+ def test_the_pin_this_codemap_writes_passes_its_own_check(tmp_path, monkeypatch):
127
+ import sys
128
+ wrapper = tmp_path / "w" / "codemap"
129
+ wrapper.parent.mkdir()
130
+ wrapper.write_text('#!/bin/sh\nexec python3 -m codemap "$@"\n') # a wrapper: not a console script
131
+ monkeypatch.setattr(sys, "argv", [str(wrapper)])
132
+ assert install.running_pin()[1:] == ["-I", "-m", "codemap"]
133
+ script = tmp_path / "s" / "codemap"
134
+ script.parent.mkdir()
135
+ script.write_text(SCRIPT)
136
+ monkeypatch.setattr(sys, "argv", [str(script)])
137
+ assert install.running_pin() == [str(script)]
138
+ assert install.pin_problem(_repo(tmp_path), install.running_pin()) is None
@@ -0,0 +1,77 @@
1
+ """R1-C134 — `refresh` checks the recorded recipe the way `build` will read it.
2
+
3
+ Follow-up audit FU-02, plus two more shapes found here. Expectations E1–E7 are in BACKLOG.md (R1-C134), written
4
+ before the change; on 0.0.46 a repeated `-o`, an abbreviated `--ou`, an attached `-oX` and a recorded working
5
+ directory that is not there each made `codemap refresh` write a graph somewhere else.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import subprocess
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ import pytest
16
+
17
+ from codemap.cli import _recipe_problem
18
+
19
+
20
+ @pytest.fixture()
21
+ def built(tmp_path: Path) -> Path:
22
+ (tmp_path / "pkg").mkdir()
23
+ (tmp_path / "pkg/__init__.py").write_text("def f():\n return 1\n")
24
+ subprocess.run([sys.executable, "-m", "codemap", "build", "pkg", "-o", "graph.json"], cwd=tmp_path, check=True,
25
+ capture_output=True)
26
+ (tmp_path / "sentinel.json").write_text('{"keep": true}\n')
27
+ (tmp_path / "run").mkdir() # refresh is run from elsewhere
28
+ return tmp_path
29
+
30
+
31
+ def _refresh(root: Path, argv: list[str], cwd: str | None) -> tuple[subprocess.CompletedProcess, set[str], bytes]:
32
+ sidecar = root / "graph.json.meta.json"
33
+ meta = json.loads(sidecar.read_text())
34
+ meta["argv"], meta["cwd"] = argv, cwd
35
+ sidecar.write_text(json.dumps(meta))
36
+ graph = (root / "graph.json").read_bytes()
37
+ before = {str(p) for p in root.rglob("*")}
38
+ r = subprocess.run([sys.executable, "-m", "codemap", "refresh", str(root / "graph.json")], cwd=root / "run",
39
+ capture_output=True, text=True)
40
+ new = {str(p) for p in root.rglob("*")} - before
41
+ assert (root / "sentinel.json").read_text() == '{"keep": true}\n'
42
+ return r, new, graph
43
+
44
+
45
+ @pytest.mark.parametrize("label, tail", [
46
+ ("E1 repeated -o", ["-o", "graph.json", "-o", "sentinel.json"]),
47
+ ("E2 repeated --out=", ["--out=graph.json", "--out=sentinel.json"]),
48
+ ("E3 abbreviated --ou", ["-o", "graph.json", "--ou", "sentinel.json"]),
49
+ ("E3 attached -oX", ["-o", "graph.json", "-osentinel.json"]),
50
+ ("E3 mixed", ["--out=graph.json", "-o", "other.json"]),
51
+ ])
52
+ def test_e1_e3_the_check_reads_the_output_build_would_write(built, label, tail):
53
+ r, new, _ = _refresh(built, ["build", "pkg", *tail], str(built))
54
+ assert r.returncode != 0 and "not repeated" in r.stderr and "not this graph" in r.stderr, (label, r.stderr)
55
+ assert new == set(), (label, new)
56
+
57
+
58
+ def test_e4_a_recorded_working_directory_that_is_not_there_is_refused(built, tmp_path):
59
+ out = "../.." + str(built / "graph.json") # right only when counted from /nonexistent/cwd
60
+ r, new, _ = _refresh(built, ["build", str(built / "pkg"), "-o", out], "/nonexistent/cwd")
61
+ assert r.returncode != 0 and "is not a directory here" in r.stderr, r.stderr
62
+ assert new == set()
63
+
64
+
65
+ @pytest.mark.parametrize("tail", [["-o", "graph.json"], ["--out=graph.json"], ["--out", "graph.json"]])
66
+ def test_e5_an_ordinary_recipe_still_rebuilds(built, tail):
67
+ r, new, _ = _refresh(built, ["build", "pkg", *tail], str(built))
68
+ assert r.returncode == 0, r.stderr
69
+ assert new == set() and json.loads((built / "graph.json").read_text())["nodes"]
70
+
71
+
72
+ def test_e7_a_recipe_build_does_not_take_is_refused_by_name(tmp_path):
73
+ g = str(tmp_path / "g.json")
74
+ problem = _recipe_problem({"argv": ["build", "pkg", "-o", "g.json", "--bogus"], "cwd": str(tmp_path)}, g)
75
+ assert problem and problem.startswith("`build` does not take it") and "--bogus" in problem, problem
76
+ assert "usage:" not in problem
77
+ assert "no graph file" in _recipe_problem({"argv": ["build", "pkg"], "cwd": str(tmp_path)}, g)