mulle-roam-code 0.0.1__py3-none-any.whl

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 (257) hide show
  1. mulle_roam_code-0.0.1.dist-info/METADATA +1590 -0
  2. mulle_roam_code-0.0.1.dist-info/RECORD +257 -0
  3. mulle_roam_code-0.0.1.dist-info/WHEEL +5 -0
  4. mulle_roam_code-0.0.1.dist-info/entry_points.txt +3 -0
  5. mulle_roam_code-0.0.1.dist-info/licenses/LICENSE +21 -0
  6. mulle_roam_code-0.0.1.dist-info/top_level.txt +1 -0
  7. roam/__init__.py +8 -0
  8. roam/__main__.py +5 -0
  9. roam/analysis/__init__.py +1 -0
  10. roam/analysis/effects.py +639 -0
  11. roam/analysis/taint.py +689 -0
  12. roam/api.py +238 -0
  13. roam/bridges/__init__.py +3 -0
  14. roam/bridges/base.py +49 -0
  15. roam/bridges/bridge_config.py +218 -0
  16. roam/bridges/bridge_protobuf.py +352 -0
  17. roam/bridges/bridge_rest_api.py +242 -0
  18. roam/bridges/bridge_salesforce.py +198 -0
  19. roam/bridges/bridge_template.py +247 -0
  20. roam/bridges/registry.py +51 -0
  21. roam/catalog/__init__.py +0 -0
  22. roam/catalog/detectors.py +2242 -0
  23. roam/catalog/fixes.py +86 -0
  24. roam/catalog/smells.py +599 -0
  25. roam/catalog/tasks.py +1260 -0
  26. roam/cli.py +548 -0
  27. roam/commands/__init__.py +0 -0
  28. roam/commands/changed_files.py +139 -0
  29. roam/commands/cmd_adversarial.py +699 -0
  30. roam/commands/cmd_affected.py +432 -0
  31. roam/commands/cmd_affected_tests.py +375 -0
  32. roam/commands/cmd_agent_context.py +168 -0
  33. roam/commands/cmd_agent_export.py +890 -0
  34. roam/commands/cmd_agent_plan.py +315 -0
  35. roam/commands/cmd_ai_ratio.py +765 -0
  36. roam/commands/cmd_ai_readiness.py +775 -0
  37. roam/commands/cmd_alerts.py +409 -0
  38. roam/commands/cmd_annotate.py +210 -0
  39. roam/commands/cmd_api_changes.py +796 -0
  40. roam/commands/cmd_api_drift.py +781 -0
  41. roam/commands/cmd_attest.py +913 -0
  42. roam/commands/cmd_auth_gaps.py +799 -0
  43. roam/commands/cmd_bisect.py +216 -0
  44. roam/commands/cmd_breaking.py +464 -0
  45. roam/commands/cmd_budget.py +413 -0
  46. roam/commands/cmd_bus_factor.py +403 -0
  47. roam/commands/cmd_capsule.py +275 -0
  48. roam/commands/cmd_check_rules.py +574 -0
  49. roam/commands/cmd_clean.py +147 -0
  50. roam/commands/cmd_closure.py +294 -0
  51. roam/commands/cmd_clusters.py +457 -0
  52. roam/commands/cmd_codeowners.py +600 -0
  53. roam/commands/cmd_complexity.py +364 -0
  54. roam/commands/cmd_config.py +310 -0
  55. roam/commands/cmd_context.py +1151 -0
  56. roam/commands/cmd_conventions.py +697 -0
  57. roam/commands/cmd_coupling.py +462 -0
  58. roam/commands/cmd_coverage_gaps.py +638 -0
  59. roam/commands/cmd_cut.py +235 -0
  60. roam/commands/cmd_dark_matter.py +127 -0
  61. roam/commands/cmd_dashboard.py +365 -0
  62. roam/commands/cmd_dead.py +1585 -0
  63. roam/commands/cmd_debt.py +731 -0
  64. roam/commands/cmd_deps.py +121 -0
  65. roam/commands/cmd_describe.py +959 -0
  66. roam/commands/cmd_dev_profile.py +580 -0
  67. roam/commands/cmd_diagnose.py +377 -0
  68. roam/commands/cmd_diff.py +633 -0
  69. roam/commands/cmd_digest.py +214 -0
  70. roam/commands/cmd_doc_staleness.py +334 -0
  71. roam/commands/cmd_docs_coverage.py +193 -0
  72. roam/commands/cmd_doctor.py +319 -0
  73. roam/commands/cmd_drift.py +377 -0
  74. roam/commands/cmd_duplicates.py +559 -0
  75. roam/commands/cmd_effects.py +362 -0
  76. roam/commands/cmd_endpoints.py +768 -0
  77. roam/commands/cmd_entry_points.py +358 -0
  78. roam/commands/cmd_fan.py +311 -0
  79. roam/commands/cmd_file.py +334 -0
  80. roam/commands/cmd_fingerprint.py +172 -0
  81. roam/commands/cmd_fitness.py +723 -0
  82. roam/commands/cmd_fn_coupling.py +295 -0
  83. roam/commands/cmd_forecast.py +366 -0
  84. roam/commands/cmd_grep.py +282 -0
  85. roam/commands/cmd_guard.py +434 -0
  86. roam/commands/cmd_health.py +922 -0
  87. roam/commands/cmd_hooks.py +458 -0
  88. roam/commands/cmd_hotspots.py +606 -0
  89. roam/commands/cmd_impact.py +228 -0
  90. roam/commands/cmd_index.py +102 -0
  91. roam/commands/cmd_ingest_trace.py +143 -0
  92. roam/commands/cmd_init.py +166 -0
  93. roam/commands/cmd_intent.py +459 -0
  94. roam/commands/cmd_invariants.py +301 -0
  95. roam/commands/cmd_layers.py +387 -0
  96. roam/commands/cmd_map.py +275 -0
  97. roam/commands/cmd_math.py +213 -0
  98. roam/commands/cmd_mcp_setup.py +135 -0
  99. roam/commands/cmd_metrics.py +663 -0
  100. roam/commands/cmd_migration_safety.py +712 -0
  101. roam/commands/cmd_minimap.py +519 -0
  102. roam/commands/cmd_missing_index.py +885 -0
  103. roam/commands/cmd_module.py +204 -0
  104. roam/commands/cmd_mutate.py +400 -0
  105. roam/commands/cmd_n1.py +967 -0
  106. roam/commands/cmd_onboard.py +740 -0
  107. roam/commands/cmd_orchestrate.py +180 -0
  108. roam/commands/cmd_orphan_routes.py +754 -0
  109. roam/commands/cmd_over_fetch.py +633 -0
  110. roam/commands/cmd_owner.py +299 -0
  111. roam/commands/cmd_partition.py +714 -0
  112. roam/commands/cmd_path_coverage.py +564 -0
  113. roam/commands/cmd_patterns.py +689 -0
  114. roam/commands/cmd_plan.py +616 -0
  115. roam/commands/cmd_plan_refactor.py +432 -0
  116. roam/commands/cmd_pr_diff.py +292 -0
  117. roam/commands/cmd_pr_risk.py +677 -0
  118. roam/commands/cmd_preflight.py +706 -0
  119. roam/commands/cmd_relate.py +405 -0
  120. roam/commands/cmd_report.py +304 -0
  121. roam/commands/cmd_reset.py +117 -0
  122. roam/commands/cmd_risk.py +533 -0
  123. roam/commands/cmd_rules.py +319 -0
  124. roam/commands/cmd_safe_delete.py +224 -0
  125. roam/commands/cmd_safe_zones.py +295 -0
  126. roam/commands/cmd_schema.py +166 -0
  127. roam/commands/cmd_search.py +295 -0
  128. roam/commands/cmd_search_semantic.py +101 -0
  129. roam/commands/cmd_secrets.py +636 -0
  130. roam/commands/cmd_semantic_diff.py +538 -0
  131. roam/commands/cmd_simulate.py +296 -0
  132. roam/commands/cmd_simulate_departure.py +632 -0
  133. roam/commands/cmd_sketch.py +160 -0
  134. roam/commands/cmd_smells.py +179 -0
  135. roam/commands/cmd_snapshot.py +50 -0
  136. roam/commands/cmd_spectral.py +183 -0
  137. roam/commands/cmd_split.py +432 -0
  138. roam/commands/cmd_suggest_refactoring.py +486 -0
  139. roam/commands/cmd_suggest_reviewers.py +491 -0
  140. roam/commands/cmd_supply_chain.py +831 -0
  141. roam/commands/cmd_symbol.py +135 -0
  142. roam/commands/cmd_syntax_check.py +301 -0
  143. roam/commands/cmd_test_gaps.py +574 -0
  144. roam/commands/cmd_testmap.py +308 -0
  145. roam/commands/cmd_tour.py +377 -0
  146. roam/commands/cmd_trace.py +304 -0
  147. roam/commands/cmd_trend.py +461 -0
  148. roam/commands/cmd_trends.py +929 -0
  149. roam/commands/cmd_understand.py +763 -0
  150. roam/commands/cmd_uses.py +170 -0
  151. roam/commands/cmd_verify.py +812 -0
  152. roam/commands/cmd_verify_imports.py +435 -0
  153. roam/commands/cmd_vibe_check.py +932 -0
  154. roam/commands/cmd_visualize.py +361 -0
  155. roam/commands/cmd_vuln_map.py +139 -0
  156. roam/commands/cmd_vuln_reach.py +289 -0
  157. roam/commands/cmd_vulns.py +414 -0
  158. roam/commands/cmd_watch.py +759 -0
  159. roam/commands/cmd_weather.py +118 -0
  160. roam/commands/cmd_why.py +325 -0
  161. roam/commands/cmd_ws.py +755 -0
  162. roam/commands/cmd_xlang.py +170 -0
  163. roam/commands/context_helpers.py +1137 -0
  164. roam/commands/gate_presets.py +222 -0
  165. roam/commands/graph_helpers.py +93 -0
  166. roam/commands/metrics_history.py +298 -0
  167. roam/commands/next_steps.py +107 -0
  168. roam/commands/resolve.py +302 -0
  169. roam/competitor_site_data.py +2229 -0
  170. roam/coverage_reports.py +462 -0
  171. roam/db/__init__.py +0 -0
  172. roam/db/connection.py +359 -0
  173. roam/db/queries.py +151 -0
  174. roam/db/schema.py +335 -0
  175. roam/exit_codes.py +100 -0
  176. roam/graph/__init__.py +43 -0
  177. roam/graph/anomaly.py +493 -0
  178. roam/graph/builder.py +61 -0
  179. roam/graph/clusters.py +286 -0
  180. roam/graph/cycles.py +210 -0
  181. roam/graph/dark_matter.py +207 -0
  182. roam/graph/diff.py +467 -0
  183. roam/graph/fingerprint.py +297 -0
  184. roam/graph/layers.py +134 -0
  185. roam/graph/pagerank.py +171 -0
  186. roam/graph/partition.py +437 -0
  187. roam/graph/pathfinding.py +119 -0
  188. roam/graph/propagation.py +208 -0
  189. roam/graph/simulate.py +286 -0
  190. roam/graph/spectral.py +260 -0
  191. roam/index/__init__.py +5 -0
  192. roam/index/complexity.py +1108 -0
  193. roam/index/discovery.py +338 -0
  194. roam/index/file_roles.py +586 -0
  195. roam/index/git_stats.py +577 -0
  196. roam/index/incremental.py +75 -0
  197. roam/index/indexer.py +1191 -0
  198. roam/index/parser.py +461 -0
  199. roam/index/relations.py +537 -0
  200. roam/index/symbols.py +71 -0
  201. roam/index/test_conventions.py +508 -0
  202. roam/languages/__init__.py +21 -0
  203. roam/languages/apex_lang.py +241 -0
  204. roam/languages/aura_lang.py +228 -0
  205. roam/languages/base.py +111 -0
  206. roam/languages/c_lang.py +458 -0
  207. roam/languages/csharp_lang.py +1215 -0
  208. roam/languages/foxpro_lang.py +1554 -0
  209. roam/languages/generic_lang.py +702 -0
  210. roam/languages/go_lang.py +392 -0
  211. roam/languages/hcl_lang.py +398 -0
  212. roam/languages/java_lang.py +418 -0
  213. roam/languages/javascript_lang.py +799 -0
  214. roam/languages/kotlin_lang.py +147 -0
  215. roam/languages/objc_lang.py +401 -0
  216. roam/languages/php_lang.py +696 -0
  217. roam/languages/python_lang.py +850 -0
  218. roam/languages/registry.py +283 -0
  219. roam/languages/ruby_lang.py +429 -0
  220. roam/languages/rust_lang.py +545 -0
  221. roam/languages/sfxml_lang.py +276 -0
  222. roam/languages/swift_lang.py +173 -0
  223. roam/languages/typescript_lang.py +323 -0
  224. roam/languages/visualforce_lang.py +151 -0
  225. roam/languages/yaml_lang.py +566 -0
  226. roam/mcp_server.py +4794 -0
  227. roam/output/__init__.py +0 -0
  228. roam/output/formatter.py +557 -0
  229. roam/output/mermaid.py +62 -0
  230. roam/output/sarif.py +897 -0
  231. roam/output/schema_registry.py +57 -0
  232. roam/plugins.py +208 -0
  233. roam/refactor/__init__.py +0 -0
  234. roam/refactor/codegen.py +106 -0
  235. roam/refactor/transforms.py +711 -0
  236. roam/rules/__init__.py +0 -0
  237. roam/rules/ast_match.py +238 -0
  238. roam/rules/builtin.py +617 -0
  239. roam/rules/dataflow.py +515 -0
  240. roam/rules/engine.py +943 -0
  241. roam/runtime/__init__.py +3 -0
  242. roam/runtime/hotspots.py +138 -0
  243. roam/runtime/trace_ingest.py +535 -0
  244. roam/search/__init__.py +1 -0
  245. roam/search/framework_packs.py +673 -0
  246. roam/search/index_embeddings.py +732 -0
  247. roam/search/onnx_embeddings.py +233 -0
  248. roam/search/tfidf.py +355 -0
  249. roam/security/__init__.py +1 -0
  250. roam/security/vuln_reach.py +246 -0
  251. roam/security/vuln_store.py +334 -0
  252. roam/surface_counts.py +158 -0
  253. roam/workspace/__init__.py +3 -0
  254. roam/workspace/aggregator.py +426 -0
  255. roam/workspace/api_scanner.py +538 -0
  256. roam/workspace/config.py +95 -0
  257. roam/workspace/db.py +136 -0
@@ -0,0 +1,508 @@
1
+ """Pluggable test naming convention adapters.
2
+
3
+ Each adapter maps source files → expected test file paths and vice versa,
4
+ based on language/framework conventions.
5
+
6
+ Supported conventions:
7
+ - Python: test_*.py / *_test.py in tests/ or same directory
8
+ - Go: *_test.go colocated with source
9
+ - JavaScript/TypeScript: *.test.{js,ts,jsx,tsx} / *.spec.{js,ts,jsx,tsx}
10
+ - Java: src/test/java mirrors src/main/java, *Test.java
11
+ - Rust: inline #[test] mod + tests/ directory
12
+ - Ruby: spec/*_spec.rb mirrors lib/
13
+ - Salesforce Apex: *Test.cls, *_Test.cls
14
+ - C#: separate test projects (*.Tests, *.UnitTests, etc.)
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import os
20
+ import re
21
+ from abc import ABC, abstractmethod
22
+
23
+
24
+ class TestConvention(ABC):
25
+ """Base class for test naming conventions."""
26
+
27
+ @property
28
+ @abstractmethod
29
+ def name(self) -> str:
30
+ """Convention name (e.g. 'python', 'go', 'java-maven')."""
31
+
32
+ @property
33
+ @abstractmethod
34
+ def languages(self) -> frozenset[str]:
35
+ """Languages this convention applies to."""
36
+
37
+ @abstractmethod
38
+ def source_to_test_paths(self, source_path: str) -> list[str]:
39
+ """Given a source file, return candidate test file paths."""
40
+
41
+ @abstractmethod
42
+ def test_to_source_paths(self, test_path: str) -> list[str]:
43
+ """Given a test file, return candidate source file paths."""
44
+
45
+ @abstractmethod
46
+ def is_test_file(self, path: str) -> bool:
47
+ """Check if a path is a test file under this convention."""
48
+
49
+
50
+ class PythonConvention(TestConvention):
51
+ @property
52
+ def name(self):
53
+ return "python"
54
+
55
+ @property
56
+ def languages(self):
57
+ return frozenset({"python"})
58
+
59
+ def source_to_test_paths(self, source_path):
60
+ p = source_path.replace("\\", "/")
61
+ base = os.path.basename(p)
62
+ name = os.path.splitext(base)[0]
63
+ dir_part = os.path.dirname(p)
64
+
65
+ candidates = []
66
+ # test_<name>.py in tests/ directory
67
+ candidates.append(f"tests/test_{name}.py")
68
+ # test_<name>.py colocated
69
+ if dir_part:
70
+ candidates.append(f"{dir_part}/test_{name}.py")
71
+ else:
72
+ candidates.append(f"test_{name}.py")
73
+ # <name>_test.py colocated
74
+ if dir_part:
75
+ candidates.append(f"{dir_part}/{name}_test.py")
76
+ else:
77
+ candidates.append(f"{name}_test.py")
78
+ # tests/ subdir matching source layout
79
+ if dir_part:
80
+ candidates.append(f"tests/{dir_part}/test_{name}.py")
81
+ return candidates
82
+
83
+ def test_to_source_paths(self, test_path):
84
+ p = test_path.replace("\\", "/")
85
+ base = os.path.basename(p)
86
+ name = os.path.splitext(base)[0]
87
+ dir_part = os.path.dirname(p)
88
+
89
+ candidates = []
90
+ # test_foo.py -> foo.py
91
+ if name.startswith("test_"):
92
+ src_name = name[5:]
93
+ elif name.endswith("_test"):
94
+ src_name = name[:-5]
95
+ else:
96
+ return []
97
+
98
+ candidates.append(f"src/{src_name}.py")
99
+ candidates.append(f"{src_name}.py")
100
+ if dir_part and dir_part != "tests":
101
+ candidates.append(f"{dir_part}/{src_name}.py")
102
+ # Strip tests/ prefix to find source
103
+ if dir_part.startswith("tests/"):
104
+ src_dir = dir_part[6:]
105
+ candidates.append(f"{src_dir}/{src_name}.py")
106
+ candidates.append(f"src/{src_dir}/{src_name}.py")
107
+ return candidates
108
+
109
+ def is_test_file(self, path):
110
+ base = os.path.basename(path)
111
+ return (
112
+ (base.startswith("test_") and base.endswith(".py"))
113
+ or (base.endswith("_test.py"))
114
+ or (base == "conftest.py")
115
+ )
116
+
117
+
118
+ class GoConvention(TestConvention):
119
+ @property
120
+ def name(self):
121
+ return "go"
122
+
123
+ @property
124
+ def languages(self):
125
+ return frozenset({"go"})
126
+
127
+ def source_to_test_paths(self, source_path):
128
+ p = source_path.replace("\\", "/")
129
+ if p.endswith("_test.go"):
130
+ return []
131
+ name = os.path.splitext(p)[0]
132
+ return [f"{name}_test.go"]
133
+
134
+ def test_to_source_paths(self, test_path):
135
+ p = test_path.replace("\\", "/")
136
+ if not p.endswith("_test.go"):
137
+ return []
138
+ return [p.replace("_test.go", ".go")]
139
+
140
+ def is_test_file(self, path):
141
+ return path.replace("\\", "/").endswith("_test.go")
142
+
143
+
144
+ class JavaScriptConvention(TestConvention):
145
+ @property
146
+ def name(self):
147
+ return "javascript"
148
+
149
+ @property
150
+ def languages(self):
151
+ return frozenset({"javascript", "typescript"})
152
+
153
+ _TEST_PATTERN = re.compile(r"^.*\.(test|spec)\.[jt]sx?$")
154
+
155
+ def source_to_test_paths(self, source_path):
156
+ p = source_path.replace("\\", "/")
157
+ base = os.path.basename(p)
158
+ name, ext = os.path.splitext(base)
159
+ if self._TEST_PATTERN.match(base):
160
+ return []
161
+ dir_part = os.path.dirname(p)
162
+ candidates = []
163
+ for suffix in [".test", ".spec"]:
164
+ test_name = f"{name}{suffix}{ext}"
165
+ if dir_part:
166
+ candidates.append(f"{dir_part}/{test_name}")
167
+ candidates.append(f"{dir_part}/__tests__/{test_name}")
168
+ else:
169
+ candidates.append(test_name)
170
+ candidates.append(f"__tests__/{test_name}")
171
+ return candidates
172
+
173
+ def test_to_source_paths(self, test_path):
174
+ p = test_path.replace("\\", "/")
175
+ base = os.path.basename(p)
176
+ m = re.match(r"^(.*)\.(test|spec)(\.[jt]sx?)$", base)
177
+ if not m:
178
+ return []
179
+ name, _, ext = m.groups()
180
+ dir_part = os.path.dirname(p)
181
+ candidates = []
182
+ src_name = f"{name}{ext}"
183
+ if "__tests__" in dir_part:
184
+ parent = dir_part.replace("__tests__/", "").replace("/__tests__", "")
185
+ candidates.append(f"{parent}/{src_name}" if parent else src_name)
186
+ if dir_part:
187
+ candidates.append(f"{dir_part}/{src_name}")
188
+ candidates.append(f"src/{src_name}")
189
+ return candidates
190
+
191
+ def is_test_file(self, path):
192
+ return bool(self._TEST_PATTERN.match(os.path.basename(path)))
193
+
194
+
195
+ class JavaMavenConvention(TestConvention):
196
+ @property
197
+ def name(self):
198
+ return "java-maven"
199
+
200
+ @property
201
+ def languages(self):
202
+ return frozenset({"java"})
203
+
204
+ def source_to_test_paths(self, source_path):
205
+ p = source_path.replace("\\", "/")
206
+ if "src/test/" in p:
207
+ return []
208
+ test_path = p.replace("src/main/", "src/test/")
209
+ test_name = os.path.splitext(test_path)[0]
210
+ return [f"{test_name}Test.java", f"{test_name}Tests.java"]
211
+
212
+ def test_to_source_paths(self, test_path):
213
+ p = test_path.replace("\\", "/")
214
+ if "src/test/" not in p:
215
+ return []
216
+ base = os.path.splitext(os.path.basename(p))[0]
217
+ if base.endswith("Tests"):
218
+ src_name = base[:-5]
219
+ elif base.endswith("Test"):
220
+ src_name = base[:-4]
221
+ else:
222
+ return []
223
+ src_path = p.replace("src/test/", "src/main/")
224
+ src_dir = os.path.dirname(src_path)
225
+ return [f"{src_dir}/{src_name}.java"]
226
+
227
+ def is_test_file(self, path):
228
+ base = os.path.basename(path)
229
+ return (base.endswith("Test.java") or base.endswith("Tests.java")) and "src/test/" in path.replace("\\", "/")
230
+
231
+
232
+ class RubyConvention(TestConvention):
233
+ @property
234
+ def name(self):
235
+ return "ruby"
236
+
237
+ @property
238
+ def languages(self):
239
+ return frozenset({"ruby"})
240
+
241
+ def source_to_test_paths(self, source_path):
242
+ p = source_path.replace("\\", "/")
243
+ name = os.path.splitext(os.path.basename(p))[0]
244
+ dir_part = os.path.dirname(p)
245
+ spec_dir = dir_part.replace("lib/", "spec/") if "lib/" in dir_part else f"spec/{dir_part}"
246
+ return [f"{spec_dir}/{name}_spec.rb"]
247
+
248
+ def test_to_source_paths(self, test_path):
249
+ p = test_path.replace("\\", "/")
250
+ base = os.path.basename(p)
251
+ if not base.endswith("_spec.rb"):
252
+ return []
253
+ name = base[:-8] # remove _spec.rb
254
+ dir_part = os.path.dirname(p)
255
+ src_dir = dir_part.replace("spec/", "lib/") if "spec/" in dir_part else dir_part
256
+ return [f"{src_dir}/{name}.rb"]
257
+
258
+ def is_test_file(self, path):
259
+ return path.replace("\\", "/").endswith("_spec.rb")
260
+
261
+
262
+ class ApexConvention(TestConvention):
263
+ @property
264
+ def name(self):
265
+ return "apex"
266
+
267
+ @property
268
+ def languages(self):
269
+ return frozenset({"apex"})
270
+
271
+ def source_to_test_paths(self, source_path):
272
+ p = source_path.replace("\\", "/")
273
+ name = os.path.splitext(os.path.basename(p))[0]
274
+ if name.endswith("Test") or name.endswith("_Test"):
275
+ return []
276
+ dir_part = os.path.dirname(p)
277
+ prefix = f"{dir_part}/" if dir_part else ""
278
+ return [f"{prefix}{name}Test.cls", f"{prefix}{name}_Test.cls"]
279
+
280
+ def test_to_source_paths(self, test_path):
281
+ p = test_path.replace("\\", "/")
282
+ name = os.path.splitext(os.path.basename(p))[0]
283
+ dir_part = os.path.dirname(p)
284
+ prefix = f"{dir_part}/" if dir_part else ""
285
+ if name.endswith("_Test"):
286
+ return [f"{prefix}{name[:-5]}.cls"]
287
+ if name.endswith("Test"):
288
+ return [f"{prefix}{name[:-4]}.cls"]
289
+ return []
290
+
291
+ def is_test_file(self, path):
292
+ base = os.path.splitext(os.path.basename(path))[0]
293
+ return base.endswith("Test") or base.endswith("_Test")
294
+
295
+
296
+ class CSharpConvention(TestConvention):
297
+ @property
298
+ def name(self):
299
+ return "csharp"
300
+
301
+ @property
302
+ def languages(self):
303
+ return frozenset({"c_sharp", "csharp", "c#"})
304
+
305
+ def source_to_test_paths(self, source_path):
306
+ """Map C# source files to potential test file paths.
307
+
308
+ Common patterns:
309
+ - src/MyProject/Services/UserService.cs -> tests/MyProject.Tests/Services/UserServiceTests.cs
310
+ - src/MyProject/UserService.cs -> tests/MyProject.Tests/UserServiceTest.cs
311
+ - MyProject/UserService.cs -> MyProject.Tests/UserServiceTests.cs
312
+ """
313
+ p = source_path.replace("\\", "/")
314
+ base = os.path.basename(p)
315
+ name = os.path.splitext(base)[0]
316
+
317
+ # skip if already a test file
318
+ if name.endswith("Test") or name.endswith("Tests"):
319
+ return []
320
+
321
+ candidates = []
322
+ dir_part = os.path.dirname(p)
323
+
324
+ # extract the relative path within the project
325
+ # handle patterns like: src/ProjectName/Subdir/File.cs
326
+ parts = dir_part.split("/") if dir_part else []
327
+
328
+ # try to find project name (usually after src/ or first directory)
329
+ project_name = None
330
+ relative_subdir = ""
331
+
332
+ if "src" in parts:
333
+ src_idx = parts.index("src")
334
+ if src_idx + 1 < len(parts):
335
+ project_name = parts[src_idx + 1]
336
+ if src_idx + 2 < len(parts):
337
+ relative_subdir = "/".join(parts[src_idx + 2 :])
338
+ elif len(parts) > 0:
339
+ # no src/ dir, first part might be project name
340
+ project_name = parts[0]
341
+ if len(parts) > 1:
342
+ relative_subdir = "/".join(parts[1:])
343
+
344
+ # generate test file candidates
345
+ for test_suffix in ["Tests", "Test"]:
346
+ test_name = f"{name}{test_suffix}.cs"
347
+
348
+ if project_name:
349
+ # pattern: tests/ProjectName.Tests/Subdir/FileTests.cs
350
+ for test_project_suffix in [".Tests", ".UnitTests", ".IntegrationTests"]:
351
+ test_project = f"{project_name}{test_project_suffix}"
352
+ if relative_subdir:
353
+ candidates.append(f"tests/{test_project}/{relative_subdir}/{test_name}")
354
+ candidates.append(f"test/{test_project}/{relative_subdir}/{test_name}")
355
+ else:
356
+ candidates.append(f"tests/{test_project}/{test_name}")
357
+ candidates.append(f"test/{test_project}/{test_name}")
358
+
359
+ # pattern: ProjectName.Tests/Subdir/FileTests.cs (sibling test project)
360
+ for test_project_suffix in [".Tests", ".UnitTests", ".IntegrationTests"]:
361
+ test_project = f"{project_name}{test_project_suffix}"
362
+ if relative_subdir:
363
+ candidates.append(f"{test_project}/{relative_subdir}/{test_name}")
364
+ else:
365
+ candidates.append(f"{test_project}/{test_name}")
366
+ else:
367
+ # fallback: just try tests/ directory with same structure
368
+ if dir_part:
369
+ candidates.append(f"tests/{dir_part}/{test_name}")
370
+ candidates.append(f"test/{dir_part}/{test_name}")
371
+ else:
372
+ candidates.append(f"tests/{test_name}")
373
+ candidates.append(f"test/{test_name}")
374
+
375
+ return candidates
376
+
377
+ def test_to_source_paths(self, test_path):
378
+ """Map C# test files to potential source file paths."""
379
+ p = test_path.replace("\\", "/")
380
+ base = os.path.basename(p)
381
+ name = os.path.splitext(base)[0]
382
+
383
+ # strip test suffix
384
+ src_name = None
385
+ if name.endswith("Tests"):
386
+ src_name = name[:-5]
387
+ elif name.endswith("Test"):
388
+ src_name = name[:-4]
389
+ else:
390
+ return []
391
+
392
+ candidates = []
393
+ dir_part = os.path.dirname(p)
394
+ parts = dir_part.split("/") if dir_part else []
395
+
396
+ # find the test project directory and extract relative subdir
397
+ project_name = None
398
+ relative_subdir = ""
399
+
400
+ # look for test project patterns: tests/ProjectName.Tests/Subdir or ProjectName.Tests/Subdir
401
+ for i, part in enumerate(parts):
402
+ if part.endswith(".Tests") or part.endswith(".UnitTests") or part.endswith(".IntegrationTests"):
403
+ # found test project
404
+ if part.endswith(".Tests"):
405
+ project_name = part[:-6]
406
+ elif part.endswith(".UnitTests"):
407
+ project_name = part[:-10]
408
+ elif part.endswith(".IntegrationTests"):
409
+ project_name = part[:-17]
410
+
411
+ # everything after the test project is the relative subdir
412
+ if i + 1 < len(parts):
413
+ relative_subdir = "/".join(parts[i + 1 :])
414
+ break
415
+
416
+ src_file = f"{src_name}.cs"
417
+
418
+ if project_name:
419
+ # pattern: tests/ProjectName.Tests/Subdir -> src/ProjectName/Subdir
420
+ if relative_subdir:
421
+ candidates.append(f"src/{project_name}/{relative_subdir}/{src_file}")
422
+ candidates.append(f"{project_name}/{relative_subdir}/{src_file}")
423
+ else:
424
+ candidates.append(f"src/{project_name}/{src_file}")
425
+ candidates.append(f"{project_name}/{src_file}")
426
+ else:
427
+ # fallback: remove tests/ prefix if present
428
+ if parts and parts[0] in ("tests", "test"):
429
+ if len(parts) > 1:
430
+ src_dir = "/".join(parts[1:])
431
+ candidates.append(f"src/{src_dir}/{src_file}")
432
+ candidates.append(f"{src_dir}/{src_file}")
433
+ else:
434
+ candidates.append(f"src/{src_file}")
435
+ elif dir_part:
436
+ candidates.append(f"{dir_part}/{src_file}")
437
+
438
+ return candidates
439
+
440
+ def is_test_file(self, path):
441
+ base = os.path.basename(path)
442
+ name = os.path.splitext(base)[0]
443
+ # check both filename pattern and directory pattern
444
+ has_test_suffix = name.endswith("Test") or name.endswith("Tests")
445
+ p = path.replace("\\", "/")
446
+ in_test_dir = "/tests/" in p or "/test/" in p or p.startswith("tests/") or p.startswith("test/")
447
+ in_test_project = ".Tests/" in p or ".UnitTests/" in p or ".IntegrationTests/" in p
448
+ return has_test_suffix and (in_test_dir or in_test_project)
449
+
450
+
451
+ # ---------------------------------------------------------------------------
452
+ # Registry
453
+ # ---------------------------------------------------------------------------
454
+
455
+ _ALL_CONVENTIONS: list[TestConvention] = [
456
+ PythonConvention(),
457
+ GoConvention(),
458
+ JavaScriptConvention(),
459
+ JavaMavenConvention(),
460
+ RubyConvention(),
461
+ ApexConvention(),
462
+ CSharpConvention(),
463
+ ]
464
+
465
+
466
+ def get_conventions() -> list[TestConvention]:
467
+ """Return all registered test conventions."""
468
+ return list(_ALL_CONVENTIONS)
469
+
470
+
471
+ def get_convention_for_language(language: str) -> TestConvention | None:
472
+ """Return the convention matching a language, or None."""
473
+ for conv in _ALL_CONVENTIONS:
474
+ if language in conv.languages:
475
+ return conv
476
+ return None
477
+
478
+
479
+ def find_test_candidates(source_path: str, language: str | None = None) -> list[str]:
480
+ """Return candidate test file paths for a source file.
481
+
482
+ If language is provided, uses only that convention.
483
+ Otherwise tries all conventions and returns merged results.
484
+ """
485
+ if language:
486
+ conv = get_convention_for_language(language)
487
+ if conv:
488
+ return conv.source_to_test_paths(source_path)
489
+ return []
490
+
491
+ candidates = []
492
+ for conv in _ALL_CONVENTIONS:
493
+ candidates.extend(conv.source_to_test_paths(source_path))
494
+ return list(dict.fromkeys(candidates)) # dedupe preserving order
495
+
496
+
497
+ def find_source_candidates(test_path: str, language: str | None = None) -> list[str]:
498
+ """Return candidate source file paths for a test file."""
499
+ if language:
500
+ conv = get_convention_for_language(language)
501
+ if conv:
502
+ return conv.test_to_source_paths(test_path)
503
+ return []
504
+
505
+ candidates = []
506
+ for conv in _ALL_CONVENTIONS:
507
+ candidates.extend(conv.test_to_source_paths(test_path))
508
+ return list(dict.fromkeys(candidates))
@@ -0,0 +1,21 @@
1
+ """Language detection, grammar loading, and symbol extraction."""
2
+
3
+ from .base import LanguageExtractor
4
+ from .registry import (
5
+ get_extractor,
6
+ get_extractor_for_file,
7
+ get_language_for_file,
8
+ get_supported_extensions,
9
+ get_supported_languages,
10
+ get_ts_language,
11
+ )
12
+
13
+ __all__ = [
14
+ "LanguageExtractor",
15
+ "get_extractor",
16
+ "get_extractor_for_file",
17
+ "get_language_for_file",
18
+ "get_supported_extensions",
19
+ "get_supported_languages",
20
+ "get_ts_language",
21
+ ]