dart-decimate 0.0.1

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 (188) hide show
  1. package/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
@@ -0,0 +1,522 @@
1
+ use serde_json::{Map, Value};
2
+
3
+ use super::cli_args::cli_args_for_tool;
4
+
5
+ #[test]
6
+ fn analyze_maps_read_only_parity_flags() -> Result<(), String> {
7
+ let args = arguments_json(
8
+ r#"{
9
+ "root": "/repo",
10
+ "config": "dart-decimate.json",
11
+ "entry": ["lib/main.dart"],
12
+ "dart_platform": "web",
13
+ "file": ["lib/src/a.dart"],
14
+ "changed_workspaces": "origin/main",
15
+ "changed_since": "HEAD~1",
16
+ "production": false,
17
+ "baseline": "baseline.json",
18
+ "regression_baseline": "regression.json",
19
+ "fail_on_regression": true,
20
+ "tolerance": "10%",
21
+ "include_entry_exports": true,
22
+ "private_type_leaks": true,
23
+ "boundary": ["lib/domain:lib/ui"],
24
+ "boundary_coverage": true,
25
+ "boundary_call": ["lib/domain:FirebaseRemoteConfig.*"],
26
+ "policy_pack": ["policy.json"],
27
+ "policy_violations": true,
28
+ "mode": "strict",
29
+ "min_tokens": 25,
30
+ "min_lines": 4,
31
+ "min_occurrences": 3,
32
+ "top": 5,
33
+ "threshold": 7.5,
34
+ "skip_local": true,
35
+ "no_ignore_imports": true,
36
+ "max_cyclomatic": 9,
37
+ "max_cognitive": 8,
38
+ "max_crap": 20,
39
+ "coverage": "lcov.info",
40
+ "runtime_coverage": "coverage.json",
41
+ "min_invocations_hot": 10,
42
+ "min_observation_volume": 20,
43
+ "low_traffic_threshold": 0.02,
44
+ "coverage_gaps": true,
45
+ "file_scores": true,
46
+ "hotspots": true,
47
+ "targets": true,
48
+ "ownership": true,
49
+ "complexity_breakdown": true,
50
+ "min_score": 70,
51
+ "issue_types": ["unused-files", "boundary-violations"]
52
+ }"#,
53
+ )?;
54
+
55
+ let cli = cli_args_for_tool("analyze", &args)?;
56
+
57
+ assert_eq!(cli[..4], ["dart-decimate", "check", "--format", "json"]);
58
+ assert_pair(&cli, "--root", "/repo");
59
+ assert_pair(&cli, "--entry", "lib/main.dart");
60
+ assert_pair(&cli, "--dart-platform", "web");
61
+ assert_pair(&cli, "--file", "lib/src/a.dart");
62
+ assert_pair(&cli, "--changed-workspaces", "origin/main");
63
+ assert_pair(&cli, "--changed-since", "HEAD~1");
64
+ assert_flag(&cli, "--no-production");
65
+ assert_pair(&cli, "--baseline", "baseline.json");
66
+ assert_pair(&cli, "--regression-baseline", "regression.json");
67
+ assert_flag(&cli, "--fail-on-regression");
68
+ assert_pair(&cli, "--tolerance", "10%");
69
+ assert_flag(&cli, "--include-entry-exports");
70
+ assert_flag(&cli, "--private-type-leaks");
71
+ assert_pair(&cli, "--boundary", "lib/domain:lib/ui");
72
+ assert_flag(&cli, "--boundary-coverage");
73
+ assert_pair(&cli, "--boundary-call", "lib/domain:FirebaseRemoteConfig.*");
74
+ assert_pair(&cli, "--policy-pack", "policy.json");
75
+ assert_flag(&cli, "--policy-violations");
76
+ assert_pair(&cli, "--mode", "strict");
77
+ assert_pair(&cli, "--min-tokens", "25");
78
+ assert_pair(&cli, "--min-lines", "4");
79
+ assert_pair(&cli, "--min-occurrences", "3");
80
+ assert_pair(&cli, "--top", "5");
81
+ assert_pair(&cli, "--threshold", "7.5");
82
+ assert_flag(&cli, "--skip-local");
83
+ assert_flag(&cli, "--no-ignore-imports");
84
+ assert_pair(&cli, "--max-cyclomatic", "9");
85
+ assert_pair(&cli, "--max-cognitive", "8");
86
+ assert_pair(&cli, "--max-crap", "20");
87
+ assert_pair(&cli, "--coverage", "lcov.info");
88
+ assert_pair(&cli, "--runtime-coverage", "coverage.json");
89
+ assert_pair(&cli, "--min-invocations-hot", "10");
90
+ assert_pair(&cli, "--min-observation-volume", "20");
91
+ assert_pair(&cli, "--low-traffic-threshold", "0.02");
92
+ assert_flag(&cli, "--coverage-gaps");
93
+ assert_flag(&cli, "--file-scores");
94
+ assert_flag(&cli, "--hotspots");
95
+ assert_flag(&cli, "--targets");
96
+ assert_flag(&cli, "--ownership");
97
+ assert_flag(&cli, "--complexity-breakdown");
98
+ assert_pair(&cli, "--min-score", "70");
99
+ assert_flag(&cli, "--unused-files");
100
+ assert_flag(&cli, "--boundary-violations");
101
+
102
+ Ok(())
103
+ }
104
+
105
+ #[test]
106
+ fn security_candidates_map_gate_and_ci_flags() -> Result<(), String> {
107
+ let args = arguments_json(
108
+ r#"{
109
+ "root": "/repo",
110
+ "entry": ["lib/main.dart"],
111
+ "file": ["lib/auth.dart"],
112
+ "paths": ["lib/trace.dart"],
113
+ "workspace": ["app"],
114
+ "changed_since": "HEAD~1",
115
+ "production": true,
116
+ "baseline": "security-baseline.json",
117
+ "top": 3,
118
+ "surface": true,
119
+ "gate": "newly-reachable",
120
+ "diff_file": "changes.patch",
121
+ "fail_on_issues": true,
122
+ "summary": true
123
+ }"#,
124
+ )?;
125
+
126
+ let cli = cli_args_for_tool("security_candidates", &args)?;
127
+
128
+ assert_eq!(cli[..4], ["dart-decimate", "security", "--format", "json"]);
129
+ assert_pair(&cli, "--entry", "lib/main.dart");
130
+ assert_pair(&cli, "--file", "lib/auth.dart");
131
+ assert_pair(&cli, "--file", "lib/trace.dart");
132
+ assert_pair(&cli, "--workspace", "app");
133
+ assert_pair(&cli, "--changed-since", "HEAD~1");
134
+ assert_flag(&cli, "--production");
135
+ assert_pair(&cli, "--baseline", "security-baseline.json");
136
+ assert_pair(&cli, "--top", "3");
137
+ assert_flag(&cli, "--surface");
138
+ assert_pair(&cli, "--gate", "newly-reachable");
139
+ assert_pair(&cli, "--diff-file", "changes.patch");
140
+ assert_flag(&cli, "--fail-on-issues");
141
+ assert_flag(&cli, "--summary");
142
+
143
+ Ok(())
144
+ }
145
+
146
+ #[test]
147
+ fn inspect_target_maps_production_scope() -> Result<(), String> {
148
+ let args = arguments_json(
149
+ r#"{
150
+ "target": { "type": "file", "file": "lib/main.dart" },
151
+ "production": false
152
+ }"#,
153
+ )?;
154
+
155
+ let cli = cli_args_for_tool("inspect_target", &args)?;
156
+
157
+ assert_eq!(cli[..4], ["dart-decimate", "inspect", "--format", "json"]);
158
+ assert_pair(&cli, "--file", "lib/main.dart");
159
+ assert_flag(&cli, "--no-production");
160
+ Ok(())
161
+ }
162
+
163
+ #[test]
164
+ fn trace_clone_maps_selector_and_duplicate_options() -> Result<(), String> {
165
+ let by_file = cli_args_for_tool(
166
+ "trace_clone",
167
+ &arguments_json(
168
+ r#"{
169
+ "file": "lib/a.dart",
170
+ "line": 12,
171
+ "mode": "semantic",
172
+ "min_tokens": 25,
173
+ "min_lines": 4,
174
+ "min_occurrences": 3,
175
+ "top": 2,
176
+ "threshold": 6,
177
+ "skip_local": true,
178
+ "ignore_imports": true
179
+ }"#,
180
+ )?,
181
+ )?;
182
+ let by_fingerprint = cli_args_for_tool(
183
+ "trace_clone",
184
+ &arguments_json(r#"{ "fingerprint": "dup:abc123", "no_ignore_imports": true }"#)?,
185
+ )?;
186
+
187
+ assert_eq!(
188
+ by_file[..4],
189
+ ["dart-decimate", "trace-clone", "--format", "json"]
190
+ );
191
+ assert_pair(&by_file, "--fingerprint", "lib/a.dart:12");
192
+ assert_pair(&by_file, "--mode", "semantic");
193
+ assert_pair(&by_file, "--min-tokens", "25");
194
+ assert_pair(&by_file, "--min-lines", "4");
195
+ assert_pair(&by_file, "--min-occurrences", "3");
196
+ assert_pair(&by_file, "--top", "2");
197
+ assert_pair(&by_file, "--threshold", "6");
198
+ assert_flag(&by_file, "--skip-local");
199
+ assert_flag(&by_file, "--ignore-imports");
200
+
201
+ assert_pair(&by_fingerprint, "--fingerprint", "dup:abc123");
202
+ assert_flag(&by_fingerprint, "--no-ignore-imports");
203
+ Ok(())
204
+ }
205
+
206
+ #[test]
207
+ fn duplicate_tools_reject_cross_language() -> Result<(), String> {
208
+ let error = match cli_args_for_tool(
209
+ "find_dupes",
210
+ &arguments_json(r#"{ "cross_language": true }"#)?,
211
+ ) {
212
+ Ok(cli) => return Err(format!("cross_language should be rejected, got {cli:?}")),
213
+ Err(error) => error,
214
+ };
215
+
216
+ assert_eq!(
217
+ error,
218
+ "cross_language is not supported for Dart-only analysis"
219
+ );
220
+ Ok(())
221
+ }
222
+
223
+ #[test]
224
+ fn trace_clone_rejects_ambiguous_or_invalid_location() -> Result<(), String> {
225
+ let ambiguous = cli_args_for_tool(
226
+ "trace_clone",
227
+ &arguments_json(r#"{ "fingerprint": "dup:abc123", "file": "lib/a.dart", "line": 3 }"#)?,
228
+ )
229
+ .err()
230
+ .ok_or_else(|| "expected ambiguous selector rejection".to_owned())?;
231
+ let invalid_line = cli_args_for_tool(
232
+ "trace_clone",
233
+ &arguments_json(r#"{ "file": "lib/a.dart", "line": 0 }"#)?,
234
+ )
235
+ .err()
236
+ .ok_or_else(|| "expected invalid line rejection".to_owned())?;
237
+
238
+ assert_eq!(
239
+ ambiguous,
240
+ "trace_clone accepts either fingerprint or file and line"
241
+ );
242
+ assert_eq!(invalid_line, "trace_clone line must be a positive integer");
243
+ Ok(())
244
+ }
245
+
246
+ #[test]
247
+ fn fallow_explain_alias_maps_to_dart_decimate_explain() -> Result<(), String> {
248
+ let cli = cli_args_for_tool(
249
+ "fallow_explain",
250
+ &arguments_json(r#"{ "rule_id": "fallow/code-duplication" }"#)?,
251
+ )?;
252
+ let error = cli_args_for_tool("fallow_explain", &Map::new())
253
+ .err()
254
+ .ok_or_else(|| "expected issue_type rejection".to_owned())?;
255
+
256
+ assert_eq!(
257
+ cli,
258
+ [
259
+ "dart-decimate",
260
+ "explain",
261
+ "fallow/code-duplication",
262
+ "--format",
263
+ "json"
264
+ ]
265
+ );
266
+ assert_eq!(error, "fallow_explain requires issue_type");
267
+ Ok(())
268
+ }
269
+
270
+ #[test]
271
+ fn changed_and_boundary_tools_map_direct_fallow_aliases() -> Result<(), String> {
272
+ let changed = cli_args_for_tool(
273
+ "check_changed",
274
+ &arguments_json(
275
+ r#"{
276
+ "root": "/repo",
277
+ "since": "origin/main",
278
+ "baseline": "baseline.json",
279
+ "fail_on_regression": true,
280
+ "production": false
281
+ }"#,
282
+ )?,
283
+ )?;
284
+ let boundaries = cli_args_for_tool(
285
+ "list_boundaries",
286
+ &arguments_json(
287
+ r#"{
288
+ "root": "/repo",
289
+ "workspace": ["app"],
290
+ "production": true
291
+ }"#,
292
+ )?,
293
+ )?;
294
+
295
+ assert_eq!(changed[..4], ["dart-decimate", "check", "--format", "json"]);
296
+ assert_pair(&changed, "--root", "/repo");
297
+ assert_pair(&changed, "--changed-since", "origin/main");
298
+ assert_pair(&changed, "--baseline", "baseline.json");
299
+ assert_flag(&changed, "--fail-on-regression");
300
+ assert_flag(&changed, "--no-production");
301
+
302
+ assert_eq!(
303
+ boundaries[..4],
304
+ ["dart-decimate", "list", "--format", "json"]
305
+ );
306
+ assert_pair(&boundaries, "--root", "/repo");
307
+ assert_pair(&boundaries, "--workspace", "app");
308
+ assert_flag(&boundaries, "--production");
309
+ assert_flag(&boundaries, "--boundaries");
310
+
311
+ Ok(())
312
+ }
313
+
314
+ #[test]
315
+ fn check_changed_accepts_changed_since_alias() -> Result<(), String> {
316
+ let cli = cli_args_for_tool(
317
+ "check_changed",
318
+ &arguments_json(r#"{ "changed_since": "HEAD~1" }"#)?,
319
+ )?;
320
+
321
+ assert_pair(&cli, "--changed-since", "HEAD~1");
322
+ Ok(())
323
+ }
324
+
325
+ #[test]
326
+ fn runtime_coverage_tools_map_fallow_coverage_param() -> Result<(), String> {
327
+ let args = arguments_json(
328
+ r#"{
329
+ "root": "/repo",
330
+ "config": "dart-decimate.json",
331
+ "coverage": "coverage/coverage-final.json",
332
+ "min_invocations_hot": 25,
333
+ "min_observation_volume": 100,
334
+ "low_traffic_threshold": 0.05,
335
+ "top": 7,
336
+ "repo": "owner/repo"
337
+ }"#,
338
+ )?;
339
+
340
+ let cli = cli_args_for_tool("get_hot_paths", &args)?;
341
+
342
+ assert_eq!(
343
+ cli[..5],
344
+ ["dart-decimate", "coverage", "analyze", "--format", "json"]
345
+ );
346
+ assert_pair(&cli, "--root", "/repo");
347
+ assert_pair(&cli, "--config", "dart-decimate.json");
348
+ assert_pair(&cli, "--runtime-coverage", "coverage/coverage-final.json");
349
+ assert_pair(&cli, "--min-invocations-hot", "25");
350
+ assert_pair(&cli, "--min-observation-volume", "100");
351
+ assert_pair(&cli, "--low-traffic-threshold", "0.05");
352
+ assert_pair(&cli, "--top", "7");
353
+ assert_pair(&cli, "--repo", "owner/repo");
354
+
355
+ Ok(())
356
+ }
357
+
358
+ #[test]
359
+ fn impact_tools_map_read_only_reports() -> Result<(), String> {
360
+ let impact = cli_args_for_tool("impact", &arguments_json(r#"{ "root": "/repo" }"#)?)?;
361
+ let impact_all = cli_args_for_tool(
362
+ "impact_all",
363
+ &arguments_json(r#"{ "sort": "surfaced", "limit": 5 }"#)?,
364
+ )?;
365
+
366
+ assert_eq!(
367
+ impact,
368
+ [
369
+ "dart-decimate",
370
+ "impact",
371
+ "--format",
372
+ "json",
373
+ "--quiet",
374
+ "--root",
375
+ "/repo"
376
+ ]
377
+ );
378
+ assert_eq!(
379
+ impact_all,
380
+ [
381
+ "dart-decimate",
382
+ "impact",
383
+ "--format",
384
+ "json",
385
+ "--quiet",
386
+ "--all",
387
+ "--sort",
388
+ "surfaced",
389
+ "--limit",
390
+ "5"
391
+ ]
392
+ );
393
+
394
+ Ok(())
395
+ }
396
+
397
+ #[test]
398
+ fn fix_tools_map_preview_and_confirmed_apply() -> Result<(), String> {
399
+ let preview_args = arguments_json(
400
+ r#"{
401
+ "root": "/repo",
402
+ "entry": ["lib/main.dart"],
403
+ "file": ["lib/dead.dart"],
404
+ "production": true,
405
+ "action": ["delete-file"],
406
+ "no_create_config": true
407
+ }"#,
408
+ )?;
409
+ let apply_args = arguments_json(
410
+ r#"{
411
+ "root": "/repo",
412
+ "entry": ["lib/main.dart"],
413
+ "action": ["delete-file"],
414
+ "yes": true
415
+ }"#,
416
+ )?;
417
+
418
+ let preview = cli_args_for_tool("fix_preview", &preview_args)?;
419
+ let apply = cli_args_for_tool("fix_apply", &apply_args)?;
420
+
421
+ assert_eq!(preview[..4], ["dart-decimate", "fix", "--format", "json"]);
422
+ assert_pair(&preview, "--root", "/repo");
423
+ assert_pair(&preview, "--entry", "lib/main.dart");
424
+ assert_pair(&preview, "--file", "lib/dead.dart");
425
+ assert_flag(&preview, "--production");
426
+ assert_pair(&preview, "--action", "delete-file");
427
+ assert_flag(&preview, "--dry-run");
428
+
429
+ assert_eq!(apply[..4], ["dart-decimate", "fix", "--format", "json"]);
430
+ assert_pair(&apply, "--root", "/repo");
431
+ assert_pair(&apply, "--entry", "lib/main.dart");
432
+ assert_pair(&apply, "--action", "delete-file");
433
+ assert_flag(&apply, "--yes");
434
+
435
+ Ok(())
436
+ }
437
+
438
+ #[test]
439
+ fn fix_apply_requires_explicit_yes_true() -> Result<(), String> {
440
+ let error = cli_args_for_tool(
441
+ "fix_apply",
442
+ &arguments_json(r#"{ "root": "/repo", "yes": false }"#)?,
443
+ )
444
+ .err()
445
+ .ok_or_else(|| "expected yes rejection".to_owned())?;
446
+
447
+ assert_eq!(error, "fix_apply requires yes: true");
448
+ Ok(())
449
+ }
450
+
451
+ #[test]
452
+ fn audit_maps_baselines_and_analysis_knobs() -> Result<(), String> {
453
+ let args = arguments_json(
454
+ r#"{
455
+ "base": "origin/main",
456
+ "gate": "new-only",
457
+ "dead_code_baseline": "dead.json",
458
+ "health_baseline": "health.json",
459
+ "dupes_baseline": "dupes.json",
460
+ "private_type_leaks": true,
461
+ "boundary": ["lib/domain:lib/ui"],
462
+ "min_score": 75,
463
+ "brief": true,
464
+ "max_decisions": 7
465
+ }"#,
466
+ )?;
467
+
468
+ let cli = cli_args_for_tool("audit", &args)?;
469
+
470
+ assert_eq!(cli[..4], ["dart-decimate", "audit", "--format", "json"]);
471
+ assert_pair(&cli, "--base", "origin/main");
472
+ assert_pair(&cli, "--gate", "new-only");
473
+ assert_pair(&cli, "--dead-code-baseline", "dead.json");
474
+ assert_pair(&cli, "--health-baseline", "health.json");
475
+ assert_pair(&cli, "--dupes-baseline", "dupes.json");
476
+ assert_flag(&cli, "--private-type-leaks");
477
+ assert_pair(&cli, "--boundary", "lib/domain:lib/ui");
478
+ assert_pair(&cli, "--min-score", "75");
479
+ assert_flag(&cli, "--brief");
480
+ assert_pair(&cli, "--max-decisions", "7");
481
+
482
+ Ok(())
483
+ }
484
+
485
+ #[test]
486
+ fn read_only_mcp_tools_reject_write_flags() -> Result<(), String> {
487
+ let args = arguments_json(r#"{ "save_baseline": "baseline.json" }"#)?;
488
+
489
+ let error = cli_args_for_tool("analyze", &args)
490
+ .err()
491
+ .ok_or_else(|| "expected save_baseline rejection".to_owned())?;
492
+
493
+ assert!(error.contains("does not accept argument save_baseline"));
494
+ Ok(())
495
+ }
496
+
497
+ fn arguments(value: &Value) -> Result<Map<String, Value>, String> {
498
+ value
499
+ .as_object()
500
+ .cloned()
501
+ .ok_or_else(|| "test arguments must be an object".to_owned())
502
+ }
503
+
504
+ fn arguments_json(source: &str) -> Result<Map<String, Value>, String> {
505
+ let value = serde_json::from_str::<Value>(source).map_err(|error| error.to_string())?;
506
+ arguments(&value)
507
+ }
508
+
509
+ fn assert_flag(cli: &[String], flag: &str) {
510
+ assert!(
511
+ cli.iter().any(|arg| arg == flag),
512
+ "expected {flag} in {cli:?}"
513
+ );
514
+ }
515
+
516
+ fn assert_pair(cli: &[String], flag: &str, value: &str) {
517
+ assert!(
518
+ cli.windows(2)
519
+ .any(|pair| pair[0] == flag && pair[1] == value),
520
+ "expected {flag} {value} in {cli:?}"
521
+ );
522
+ }