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,469 @@
1
+ use std::fmt::Write as _;
2
+ use std::fs;
3
+ use std::io;
4
+ use std::path::{Path, PathBuf};
5
+
6
+ use serde::{Deserialize, Serialize};
7
+
8
+ use crate::output::JsonRuntimeCoverage;
9
+ use crate::{DartFile, ScannedProject};
10
+
11
+ /// Stable schema version for focused runtime coverage analysis.
12
+ pub const COVERAGE_ANALYSIS_SCHEMA_VERSION: &str = "dart-decimate.coverage.v1";
13
+
14
+ /// Focused runtime coverage analysis output.
15
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16
+ pub struct CoverageAnalysisReport {
17
+ /// Schema identifier.
18
+ pub schema_version: String,
19
+ /// Typed envelope discriminator.
20
+ pub kind: String,
21
+ /// Tool name.
22
+ pub tool: String,
23
+ /// Command that produced this report.
24
+ pub command: String,
25
+ /// Runtime coverage intelligence.
26
+ pub runtime_coverage: JsonRuntimeCoverage,
27
+ }
28
+
29
+ /// Runtime coverage setup report.
30
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31
+ pub struct CoverageSetupReport {
32
+ /// Schema identifier.
33
+ pub schema_version: String,
34
+ /// Typed envelope discriminator.
35
+ pub kind: String,
36
+ /// Tool name.
37
+ pub tool: String,
38
+ /// Command that produced this report.
39
+ pub command: String,
40
+ /// Project root.
41
+ pub root: PathBuf,
42
+ /// Whether setup writes were accepted with `--yes`.
43
+ pub applied: bool,
44
+ /// Whether setup ran in non-interactive mode.
45
+ pub non_interactive: bool,
46
+ /// Project coverage setup summary.
47
+ pub summary: CoverageSetupSummary,
48
+ /// Files created or planned by setup.
49
+ pub files: Vec<CoverageSetupFile>,
50
+ /// Runtime coverage capture commands for agents.
51
+ pub capture_commands: Vec<String>,
52
+ /// Suggested follow-up commands.
53
+ pub next_steps: Vec<String>,
54
+ /// Non-fatal setup warnings.
55
+ pub warnings: Vec<String>,
56
+ }
57
+
58
+ /// Runtime coverage setup summary.
59
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
60
+ pub struct CoverageSetupSummary {
61
+ /// Whether `pubspec.yaml` exists at the root.
62
+ pub pubspec: bool,
63
+ /// Whether the root looks like a Flutter project.
64
+ pub flutter: bool,
65
+ /// Parsed Dart file count.
66
+ pub dart_files: usize,
67
+ /// Coverage config state.
68
+ pub config: CoverageSetupConfigSummary,
69
+ }
70
+
71
+ /// Runtime coverage setup config state.
72
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
73
+ pub struct CoverageSetupConfigSummary {
74
+ /// Whether Dart Decimate config already existed.
75
+ pub exists: bool,
76
+ /// Whether loaded config already points at coverage input.
77
+ pub coverage_configured: bool,
78
+ }
79
+
80
+ /// Runtime coverage setup file status.
81
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
82
+ pub struct CoverageSetupFile {
83
+ /// Path relative to the project root.
84
+ pub path: String,
85
+ /// File kind.
86
+ pub kind: String,
87
+ /// Action performed or planned.
88
+ pub action: CoverageSetupFileAction,
89
+ /// Agent-readable reason.
90
+ pub reason: String,
91
+ }
92
+
93
+ /// Runtime coverage setup file action.
94
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
95
+ #[serde(rename_all = "kebab-case")]
96
+ pub enum CoverageSetupFileAction {
97
+ /// File would be created if `--yes` is passed.
98
+ WouldCreate,
99
+ /// File was created.
100
+ Created,
101
+ /// File already existed or no write was needed.
102
+ Unchanged,
103
+ }
104
+
105
+ /// Offline coverage upload or inventory report.
106
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107
+ pub struct CoverageUploadReport {
108
+ /// Schema identifier.
109
+ pub schema_version: String,
110
+ /// Typed envelope discriminator.
111
+ pub kind: String,
112
+ /// Tool name.
113
+ pub tool: String,
114
+ /// Command that produced this report.
115
+ pub command: String,
116
+ /// Project root.
117
+ pub root: PathBuf,
118
+ /// Dry-run mode. Upload commands are offline-only until cloud support lands.
119
+ pub dry_run: bool,
120
+ /// Target repository, when supplied.
121
+ pub repo: Option<String>,
122
+ /// Git commit SHA, when supplied.
123
+ pub git_sha: Option<String>,
124
+ /// Whether uploaded paths would be stripped to root-relative paths.
125
+ pub strip_path: bool,
126
+ /// Upload inventory summary.
127
+ pub summary: CoverageUploadSummary,
128
+ /// Files included in the dry-run packet.
129
+ pub files: Vec<CoverageUploadFile>,
130
+ /// Non-mutating actions an agent can take next.
131
+ pub actions: Vec<String>,
132
+ /// Non-fatal warnings.
133
+ pub warnings: Vec<String>,
134
+ }
135
+
136
+ /// Upload inventory summary.
137
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
138
+ pub struct CoverageUploadSummary {
139
+ /// Upload packet mode.
140
+ pub mode: String,
141
+ /// File count.
142
+ pub files: usize,
143
+ /// Total bytes across packet files.
144
+ pub bytes: u64,
145
+ }
146
+
147
+ /// Upload inventory file row.
148
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149
+ pub struct CoverageUploadFile {
150
+ /// Root-relative path when possible.
151
+ pub path: String,
152
+ /// File kind.
153
+ pub kind: String,
154
+ /// File size in bytes.
155
+ pub bytes: u64,
156
+ /// Runtime source-map resolution status for agent confidence.
157
+ pub resolution_status: String,
158
+ /// Runtime source-map mapping quality for agent confidence.
159
+ pub mapping_quality: String,
160
+ }
161
+
162
+ /// Build a focused runtime coverage report.
163
+ #[must_use]
164
+ pub fn coverage_analysis_report(runtime_coverage: JsonRuntimeCoverage) -> CoverageAnalysisReport {
165
+ CoverageAnalysisReport {
166
+ schema_version: COVERAGE_ANALYSIS_SCHEMA_VERSION.to_owned(),
167
+ kind: "runtime-coverage".to_owned(),
168
+ tool: "dart-decimate".to_owned(),
169
+ command: "coverage analyze".to_owned(),
170
+ runtime_coverage,
171
+ }
172
+ }
173
+
174
+ /// Build or apply an offline runtime coverage setup report.
175
+ ///
176
+ /// # Errors
177
+ ///
178
+ /// Returns an IO error if `apply` is true and the setup config cannot be
179
+ /// written.
180
+ pub fn coverage_setup_report(
181
+ project: &ScannedProject,
182
+ apply: bool,
183
+ non_interactive: bool,
184
+ coverage_configured: bool,
185
+ ) -> io::Result<CoverageSetupReport> {
186
+ let root = &project.root;
187
+ let config_path = root.join(".dart-decimaterc");
188
+ let config_exists = config_path.exists();
189
+ let action = if config_exists {
190
+ CoverageSetupFileAction::Unchanged
191
+ } else if apply {
192
+ fs::write(&config_path, COVERAGE_CONFIG)?;
193
+ CoverageSetupFileAction::Created
194
+ } else {
195
+ CoverageSetupFileAction::WouldCreate
196
+ };
197
+ let pubspec = fs::read_to_string(root.join("pubspec.yaml")).ok();
198
+ let flutter = pubspec.as_deref().is_some_and(is_flutter_pubspec);
199
+ let mut warnings = Vec::new();
200
+ if pubspec
201
+ .as_ref()
202
+ .is_none_or(|source| source.trim().is_empty())
203
+ {
204
+ warnings.push("pubspec.yaml was not found at the project root".to_owned());
205
+ }
206
+ if !flutter {
207
+ warnings
208
+ .push("Flutter was not detected; Dart VM coverage input is still supported".to_owned());
209
+ }
210
+
211
+ Ok(CoverageSetupReport {
212
+ schema_version: COVERAGE_ANALYSIS_SCHEMA_VERSION.to_owned(),
213
+ kind: "coverage-setup".to_owned(),
214
+ tool: "dart-decimate".to_owned(),
215
+ command: "coverage setup".to_owned(),
216
+ root: root.clone(),
217
+ applied: apply,
218
+ non_interactive,
219
+ summary: CoverageSetupSummary {
220
+ pubspec: pubspec.is_some(),
221
+ flutter,
222
+ dart_files: project.files.len(),
223
+ config: CoverageSetupConfigSummary {
224
+ exists: config_exists,
225
+ coverage_configured,
226
+ },
227
+ },
228
+ files: vec![CoverageSetupFile {
229
+ path: ".dart-decimaterc".to_owned(),
230
+ kind: "config".to_owned(),
231
+ action,
232
+ reason: setup_file_reason(action).to_owned(),
233
+ }],
234
+ capture_commands: coverage_capture_commands(flutter),
235
+ next_steps: vec![
236
+ "dart-decimate health . --coverage coverage/lcov.info --coverage-gaps --format json"
237
+ .to_owned(),
238
+ "dart-decimate coverage analyze . --runtime-coverage coverage/coverage-final.json --format json"
239
+ .to_owned(),
240
+ ],
241
+ warnings,
242
+ })
243
+ }
244
+
245
+ /// Build a local source inventory upload dry-run report.
246
+ #[must_use]
247
+ pub fn coverage_inventory_upload_report(
248
+ project: &ScannedProject,
249
+ repo: Option<String>,
250
+ dry_run: bool,
251
+ ) -> CoverageUploadReport {
252
+ let files = project
253
+ .files
254
+ .iter()
255
+ .filter(|file| production_source_file(&project.root, file))
256
+ .map(|file| {
257
+ upload_file(
258
+ &project.root,
259
+ &file.path,
260
+ "dart-source",
261
+ "resolved",
262
+ "high",
263
+ true,
264
+ )
265
+ })
266
+ .collect::<Vec<_>>();
267
+ upload_report(UploadReportInput {
268
+ root: &project.root,
269
+ kind: "coverage-upload-inventory",
270
+ command: "coverage upload-inventory",
271
+ mode: "inventory",
272
+ dry_run,
273
+ repo,
274
+ git_sha: None,
275
+ strip_path: true,
276
+ files,
277
+ })
278
+ }
279
+
280
+ /// Build a local source-map upload dry-run report.
281
+ ///
282
+ /// # Errors
283
+ ///
284
+ /// Returns an IO error when the source-map directory cannot be read.
285
+ pub fn coverage_source_maps_upload_report(
286
+ root: &Path,
287
+ dir: &Path,
288
+ repo: String,
289
+ git_sha: String,
290
+ strip_path: bool,
291
+ dry_run: bool,
292
+ ) -> io::Result<CoverageUploadReport> {
293
+ let mut paths = Vec::new();
294
+ collect_source_maps(dir, &mut paths)?;
295
+ paths.sort();
296
+ let files = paths
297
+ .iter()
298
+ .map(|path| upload_file(root, path, "source-map", "resolved", "high", strip_path))
299
+ .collect::<Vec<_>>();
300
+ Ok(upload_report(UploadReportInput {
301
+ root,
302
+ kind: "coverage-upload-source-maps",
303
+ command: "coverage upload-source-maps",
304
+ mode: "source-maps",
305
+ dry_run,
306
+ repo: Some(repo),
307
+ git_sha: Some(git_sha),
308
+ strip_path,
309
+ files,
310
+ }))
311
+ }
312
+
313
+ /// Render a concise human runtime coverage report.
314
+ #[must_use]
315
+ pub fn render_coverage_analysis_report(report: &CoverageAnalysisReport) -> String {
316
+ let summary = &report.runtime_coverage.summary;
317
+ format!(
318
+ "Runtime coverage: {} observed files, {} invocations, {} hot paths, {} findings\n",
319
+ summary.observed_files, summary.total_invocations, summary.hot_paths, summary.findings
320
+ )
321
+ }
322
+
323
+ /// Render a concise human setup report.
324
+ #[must_use]
325
+ pub fn render_coverage_setup_report(report: &CoverageSetupReport) -> String {
326
+ let mut output = format!(
327
+ "Coverage setup: {} Dart files, flutter={}, applied={}\n",
328
+ report.summary.dart_files, report.summary.flutter, report.applied
329
+ );
330
+ for file in &report.files {
331
+ let _ = writeln!(output, "{}: {:?}", file.path, file.action);
332
+ }
333
+ output
334
+ }
335
+
336
+ /// Render a concise human upload dry-run report.
337
+ #[must_use]
338
+ pub fn render_coverage_upload_report(report: &CoverageUploadReport) -> String {
339
+ format!(
340
+ "{}: {} files, {} bytes, dry_run={}\n",
341
+ report.command, report.summary.files, report.summary.bytes, report.dry_run
342
+ )
343
+ }
344
+
345
+ struct UploadReportInput<'a> {
346
+ root: &'a Path,
347
+ kind: &'a str,
348
+ command: &'a str,
349
+ mode: &'a str,
350
+ dry_run: bool,
351
+ repo: Option<String>,
352
+ git_sha: Option<String>,
353
+ strip_path: bool,
354
+ files: Vec<CoverageUploadFile>,
355
+ }
356
+
357
+ fn upload_report(input: UploadReportInput<'_>) -> CoverageUploadReport {
358
+ let bytes = input.files.iter().map(|file| file.bytes).sum();
359
+ CoverageUploadReport {
360
+ schema_version: COVERAGE_ANALYSIS_SCHEMA_VERSION.to_owned(),
361
+ kind: input.kind.to_owned(),
362
+ tool: "dart-decimate".to_owned(),
363
+ command: input.command.to_owned(),
364
+ root: input.root.to_path_buf(),
365
+ dry_run: input.dry_run,
366
+ repo: input.repo,
367
+ git_sha: input.git_sha,
368
+ strip_path: input.strip_path,
369
+ summary: CoverageUploadSummary {
370
+ mode: input.mode.to_owned(),
371
+ files: input.files.len(),
372
+ bytes,
373
+ },
374
+ files: input.files,
375
+ actions: vec![
376
+ "review dry-run packet before enabling hosted runtime coverage".to_owned(),
377
+ "run dart-decimate coverage analyze with a local --runtime-coverage file for immediate evidence"
378
+ .to_owned(),
379
+ ],
380
+ warnings: Vec::new(),
381
+ }
382
+ }
383
+
384
+ fn upload_file(
385
+ root: &Path,
386
+ path: &Path,
387
+ kind: &str,
388
+ resolution_status: &str,
389
+ mapping_quality: &str,
390
+ strip_path: bool,
391
+ ) -> CoverageUploadFile {
392
+ CoverageUploadFile {
393
+ path: if strip_path {
394
+ display_path(root, path)
395
+ } else {
396
+ path.to_string_lossy().replace('\\', "/")
397
+ },
398
+ kind: kind.to_owned(),
399
+ bytes: fs::metadata(path).map_or(0, |metadata| metadata.len()),
400
+ resolution_status: resolution_status.to_owned(),
401
+ mapping_quality: mapping_quality.to_owned(),
402
+ }
403
+ }
404
+
405
+ fn collect_source_maps(dir: &Path, paths: &mut Vec<PathBuf>) -> io::Result<()> {
406
+ for entry in fs::read_dir(dir)? {
407
+ let entry = entry?;
408
+ let path = entry.path();
409
+ let file_type = entry.file_type()?;
410
+ if file_type.is_dir() {
411
+ collect_source_maps(&path, paths)?;
412
+ } else if file_type.is_file() && path.extension().is_some_and(|ext| ext == "map") {
413
+ paths.push(path);
414
+ }
415
+ }
416
+ Ok(())
417
+ }
418
+
419
+ fn production_source_file(root: &Path, file: &DartFile) -> bool {
420
+ let path = display_path(root, &file.path);
421
+ !path.starts_with("test/") && !path.ends_with("_test.dart")
422
+ }
423
+
424
+ fn coverage_capture_commands(flutter: bool) -> Vec<String> {
425
+ let mut commands = Vec::new();
426
+ if flutter {
427
+ commands.push("flutter test --coverage".to_owned());
428
+ }
429
+ commands.push("dart run coverage:test_with_coverage".to_owned());
430
+ commands.push(
431
+ "dart-decimate coverage analyze . --runtime-coverage coverage/coverage-final.json --format json"
432
+ .to_owned(),
433
+ );
434
+ commands
435
+ }
436
+
437
+ fn setup_file_reason(action: CoverageSetupFileAction) -> &'static str {
438
+ match action {
439
+ CoverageSetupFileAction::WouldCreate => {
440
+ "pass --yes to create coverage defaults without prompting"
441
+ }
442
+ CoverageSetupFileAction::Created => {
443
+ "created coverage defaults for LCOV and runtime coverage inputs"
444
+ }
445
+ CoverageSetupFileAction::Unchanged => {
446
+ "existing config was left unchanged; merge coverage defaults manually if needed"
447
+ }
448
+ }
449
+ }
450
+
451
+ fn is_flutter_pubspec(source: &str) -> bool {
452
+ source.contains("sdk: flutter") || source.contains("\nflutter:")
453
+ }
454
+
455
+ fn display_path(root: &Path, path: &Path) -> String {
456
+ path.strip_prefix(root)
457
+ .unwrap_or(path)
458
+ .to_string_lossy()
459
+ .replace('\\', "/")
460
+ }
461
+
462
+ const COVERAGE_CONFIG: &str = r#"{
463
+ "health": {
464
+ "coverage_path": "coverage/lcov.info",
465
+ "coverage_gaps": true,
466
+ "runtime_coverage": "coverage/coverage-final.json"
467
+ }
468
+ }
469
+ "#;