1use std::path::Path;
4
5use fallow_output::{
6 CodeClimateIssue, CodeClimateIssueInput, CodeClimateSeverity, ComplexityViolation,
7 CoverageIntelligenceFinding, CoverageIntelligenceRecommendation, CoverageIntelligenceVerdict,
8 ExceededThreshold, FindingSeverity, HealthReport, HealthSummary, RuntimeCoverageFinding,
9 RuntimeCoverageVerdict, StylingFinding, StylingFindingSeverity, UntestedExportFinding,
10 UntestedFileFinding, build_codeclimate_issue, codeclimate_fingerprint_hash, normalize_uri,
11};
12use fallow_types::output_dead_code::EffectiveSeverity;
13
14struct HealthCodeClimateContext<'a> {
15 root: &'a Path,
16 summary: &'a HealthSummary,
20}
21
22impl HealthCodeClimateContext<'_> {
23 fn complexity_issue(&self, finding: &ComplexityViolation) -> CodeClimateIssue {
24 let path = codeclimate_path(&finding.path, self.root);
25 let check_name = complexity_check_name(finding);
26 let line_str = finding.line.to_string();
27 let fp = codeclimate_fingerprint_hash(&[check_name, &path, &line_str, &finding.name]);
28 build_codeclimate_issue(CodeClimateIssueInput {
29 check_name,
30 description: &self.complexity_description(finding),
31 severity: complexity_codeclimate_severity(finding),
32 category: "Complexity",
33 path: &path,
34 begin_line: Some(finding.line),
35 fingerprint: &fp,
36 })
37 }
38
39 fn styling_issue(&self, finding: &StylingFinding) -> CodeClimateIssue {
40 let path = codeclimate_path(Path::new(&finding.path), self.root);
41 let check_name = format!("fallow/{}", finding.code);
42 let description = format!("[{}] {}: {}", finding.code, finding.sub_kind, finding.value);
43 let line_str = finding.line.to_string();
44 let fp = codeclimate_fingerprint_hash(&[
45 &check_name,
46 &path,
47 &line_str,
48 &finding.sub_kind,
49 &finding.value,
50 ]);
51 build_codeclimate_issue(CodeClimateIssueInput {
52 check_name: &check_name,
53 description: &description,
54 severity: styling_finding_severity(finding.effective_severity),
55 category: "Style",
56 path: &path,
57 begin_line: Some(finding.line),
58 fingerprint: &fp,
59 })
60 }
61
62 fn complexity_description(&self, finding: &ComplexityViolation) -> String {
63 let thresholds = finding.resolved_thresholds(self.summary);
64 match finding.exceeded {
65 ExceededThreshold::Both => format!(
66 "'{}' has cyclomatic complexity {} (threshold: {}) and cognitive complexity {} (threshold: {})",
67 finding.name,
68 finding.cyclomatic,
69 thresholds.max_cyclomatic,
70 finding.cognitive,
71 thresholds.max_cognitive
72 ),
73 ExceededThreshold::Cyclomatic => format!(
74 "'{}' has cyclomatic complexity {} (threshold: {})",
75 finding.name, finding.cyclomatic, thresholds.max_cyclomatic
76 ),
77 ExceededThreshold::Cognitive => format!(
78 "'{}' has cognitive complexity {} (threshold: {})",
79 finding.name, finding.cognitive, thresholds.max_cognitive
80 ),
81 ExceededThreshold::Crap
82 | ExceededThreshold::CyclomaticCrap
83 | ExceededThreshold::CognitiveCrap
84 | ExceededThreshold::All => {
85 let crap = finding.crap.unwrap_or(0.0);
86 let coverage = finding
87 .coverage_pct
88 .map(|pct| format!(", coverage {pct:.0}%"))
89 .unwrap_or_default();
90 format!(
91 "'{}' has CRAP score {crap:.1} (threshold: {:.1}, cyclomatic {}{coverage})",
92 finding.name, thresholds.max_crap, finding.cyclomatic,
93 )
94 }
95 ExceededThreshold::FileLines => format!(
96 "File has {} lines (threshold: {})",
97 finding.line_count,
98 finding.max_file_lines.unwrap_or_default()
99 ),
100 }
101 }
102
103 fn runtime_coverage_issue(&self, finding: &RuntimeCoverageFinding) -> CodeClimateIssue {
104 let path = codeclimate_path(&finding.path, self.root);
105 let check_name = runtime_coverage_check_name(finding.verdict);
106 let invocations_hint = finding.invocations.map_or_else(
107 || "untracked".to_owned(),
108 |hits| format!("{hits} invocations"),
109 );
110 let description = format!(
111 "'{}' runtime coverage verdict: {} ({})",
112 finding.function,
113 finding.verdict.human_label(),
114 invocations_hint,
115 );
116 let fp = codeclimate_fingerprint_hash(&[
117 check_name,
118 &path,
119 &finding.line.to_string(),
120 &finding.function,
121 ]);
122 build_codeclimate_issue(CodeClimateIssueInput {
123 check_name,
124 description: &description,
125 severity: runtime_coverage_severity(finding.verdict),
126 category: "Bug Risk",
127 path: &path,
128 begin_line: Some(finding.line),
129 fingerprint: &fp,
130 })
131 }
132
133 fn coverage_intelligence_issue(
134 &self,
135 finding: &CoverageIntelligenceFinding,
136 ) -> Option<CodeClimateIssue> {
137 let severity = coverage_intelligence_severity(finding.verdict)?;
138 let path = codeclimate_path(&finding.path, self.root);
139 let check_name = coverage_intelligence_check_name(finding.recommendation);
140 let identity = finding.identity.as_deref().unwrap_or("code");
141 let description = format!(
142 "'{}' coverage intelligence verdict: {} ({})",
143 identity, finding.verdict, finding.recommendation,
144 );
145 let fp = codeclimate_fingerprint_hash(&[
146 check_name,
147 &path,
148 &finding.line.to_string(),
149 identity,
150 &finding.id,
151 ]);
152 Some(build_codeclimate_issue(CodeClimateIssueInput {
153 check_name,
154 description: &description,
155 severity,
156 category: "Bug Risk",
157 path: &path,
158 begin_line: Some(finding.line),
159 fingerprint: &fp,
160 }))
161 }
162
163 fn untested_file_issue(&self, item: &UntestedFileFinding) -> CodeClimateIssue {
164 let path = codeclimate_path(&item.file.path, self.root);
165 let description = format!(
166 "File is runtime-reachable but has no test dependency path ({} value export{})",
167 item.file.value_export_count,
168 if item.file.value_export_count == 1 {
169 ""
170 } else {
171 "s"
172 },
173 );
174 let fp = codeclimate_fingerprint_hash(&["fallow/untested-file", &path]);
175 build_codeclimate_issue(CodeClimateIssueInput {
176 check_name: "fallow/untested-file",
177 description: &description,
178 severity: CodeClimateSeverity::Minor,
179 category: "Coverage",
180 path: &path,
181 begin_line: None,
182 fingerprint: &fp,
183 })
184 }
185
186 fn untested_export_issue(&self, item: &UntestedExportFinding) -> CodeClimateIssue {
187 let path = codeclimate_path(&item.export.path, self.root);
188 let description = format!(
189 "Export '{}' is runtime-reachable but never referenced by test-reachable modules",
190 item.export.export_name
191 );
192 let line_str = item.export.line.to_string();
193 let fp = codeclimate_fingerprint_hash(&[
194 "fallow/untested-export",
195 &path,
196 &line_str,
197 &item.export.export_name,
198 ]);
199 build_codeclimate_issue(CodeClimateIssueInput {
200 check_name: "fallow/untested-export",
201 description: &description,
202 severity: CodeClimateSeverity::Minor,
203 category: "Coverage",
204 path: &path,
205 begin_line: Some(item.export.line),
206 fingerprint: &fp,
207 })
208 }
209}
210
211#[must_use]
213pub fn build_health_codeclimate(report: &HealthReport, root: &Path) -> Vec<CodeClimateIssue> {
214 let mut issues = Vec::new();
215 let ctx = HealthCodeClimateContext {
216 root,
217 summary: &report.summary,
218 };
219
220 for finding in &report.findings {
221 let mut issue = ctx.complexity_issue(finding);
222 if !finding.worsened_metrics.is_empty() {
225 let class =
226 if finding.attribution == Some(fallow_output::AuditFindingAttribution::Worsened) {
227 "worsened"
228 } else {
229 "introduced"
230 };
231 issue.description = format!(
232 "{} ({class} against the base: {})",
233 issue.description,
234 fallow_output::describe_worsened_metrics(&finding.worsened_metrics)
235 );
236 }
237 if finding.gate_exemption == Some(fallow_output::AuditGateExemption::TestFile) {
238 issue.description =
239 format!("{} (test file: audit does not gate it)", issue.description);
240 }
241 issue.audit = finding
242 .attribution
243 .map(|attribution| fallow_output::AuditReviewContext {
244 attribution,
245 gate_exemption: finding.gate_exemption,
246 gate: None,
247 });
248 issues.push(issue);
249 }
250 for finding in &report.styling_findings {
251 issues.push(ctx.styling_issue(finding));
252 }
253
254 if let Some(ref production) = report.runtime_coverage {
255 for finding in &production.findings {
256 issues.push(ctx.runtime_coverage_issue(finding));
257 }
258 }
259
260 if let Some(ref intelligence) = report.coverage_intelligence {
261 for finding in &intelligence.findings {
262 if let Some(issue) = ctx.coverage_intelligence_issue(finding) {
263 issues.push(issue);
264 }
265 }
266 }
267
268 if let Some(ref gaps) = report.coverage_gaps {
269 for item in &gaps.files {
270 issues.push(ctx.untested_file_issue(item));
271 }
272
273 for item in &gaps.exports {
274 issues.push(ctx.untested_export_issue(item));
275 }
276 }
277
278 issues
279}
280
281fn codeclimate_path(path: &Path, root: &Path) -> String {
282 normalize_uri(
283 &path
284 .strip_prefix(root)
285 .unwrap_or(path)
286 .display()
287 .to_string(),
288 )
289}
290
291const fn coverage_intelligence_check_name(
292 recommendation: CoverageIntelligenceRecommendation,
293) -> &'static str {
294 match recommendation {
295 CoverageIntelligenceRecommendation::AddTestOrSplitBeforeMerge => {
296 "fallow/coverage-intelligence-risky-change"
297 }
298 CoverageIntelligenceRecommendation::DeleteAfterConfirmingOwner => {
299 "fallow/coverage-intelligence-delete"
300 }
301 CoverageIntelligenceRecommendation::ReviewBeforeChanging => {
302 "fallow/coverage-intelligence-review"
303 }
304 CoverageIntelligenceRecommendation::RefactorCarefullyKeepBehavior => {
305 "fallow/coverage-intelligence-refactor"
306 }
307 }
308}
309
310const fn complexity_check_name(finding: &ComplexityViolation) -> &'static str {
311 match finding.exceeded {
312 ExceededThreshold::Both => "fallow/high-complexity",
313 ExceededThreshold::Cyclomatic => "fallow/high-cyclomatic-complexity",
314 ExceededThreshold::Cognitive => "fallow/high-cognitive-complexity",
315 ExceededThreshold::Crap
316 | ExceededThreshold::CyclomaticCrap
317 | ExceededThreshold::CognitiveCrap
318 | ExceededThreshold::All => "fallow/high-crap-score",
319 ExceededThreshold::FileLines => "fallow/long-file",
320 }
321}
322
323const fn complexity_codeclimate_severity(finding: &ComplexityViolation) -> CodeClimateSeverity {
330 match finding.effective_severity {
331 Some(EffectiveSeverity::Error) => CodeClimateSeverity::Major,
332 Some(EffectiveSeverity::Warn) => CodeClimateSeverity::Minor,
333 None => health_finding_severity(finding.severity),
334 }
335}
336
337const fn health_finding_severity(severity: FindingSeverity) -> CodeClimateSeverity {
338 match severity {
339 FindingSeverity::Critical => CodeClimateSeverity::Critical,
340 FindingSeverity::High => CodeClimateSeverity::Major,
341 FindingSeverity::Moderate => CodeClimateSeverity::Minor,
342 }
343}
344
345const fn styling_finding_severity(severity: StylingFindingSeverity) -> CodeClimateSeverity {
346 match severity {
347 StylingFindingSeverity::Error => CodeClimateSeverity::Major,
348 StylingFindingSeverity::Warn => CodeClimateSeverity::Minor,
349 }
350}
351
352const fn runtime_coverage_check_name(verdict: RuntimeCoverageVerdict) -> &'static str {
353 match verdict {
354 RuntimeCoverageVerdict::SafeToDelete => "fallow/runtime-safe-to-delete",
355 RuntimeCoverageVerdict::ReviewRequired => "fallow/runtime-review-required",
356 RuntimeCoverageVerdict::LowTraffic => "fallow/runtime-low-traffic",
357 RuntimeCoverageVerdict::CoverageUnavailable => "fallow/runtime-coverage-unavailable",
358 RuntimeCoverageVerdict::Active | RuntimeCoverageVerdict::Unknown => {
359 "fallow/runtime-coverage"
360 }
361 }
362}
363
364const fn runtime_coverage_severity(verdict: RuntimeCoverageVerdict) -> CodeClimateSeverity {
365 match verdict {
366 RuntimeCoverageVerdict::SafeToDelete => CodeClimateSeverity::Critical,
367 RuntimeCoverageVerdict::ReviewRequired => CodeClimateSeverity::Major,
368 _ => CodeClimateSeverity::Minor,
369 }
370}
371
372const fn coverage_intelligence_severity(
373 verdict: CoverageIntelligenceVerdict,
374) -> Option<CodeClimateSeverity> {
375 match verdict {
376 CoverageIntelligenceVerdict::RiskyChangeDetected
377 | CoverageIntelligenceVerdict::HighConfidenceDelete => Some(CodeClimateSeverity::Major),
378 CoverageIntelligenceVerdict::ReviewRequired
379 | CoverageIntelligenceVerdict::RefactorCarefully => Some(CodeClimateSeverity::Minor),
380 CoverageIntelligenceVerdict::Clean | CoverageIntelligenceVerdict::Unknown => None,
381 }
382}
383
384#[cfg(test)]
385mod tests {
386 use std::path::{Path, PathBuf};
387
388 use fallow_output::{
389 ComplexityViolation, ExceededThreshold, FindingSeverity, HealthReport, HealthSummary,
390 StylingFinding, StylingFindingSeverity,
391 };
392
393 use super::*;
394
395 #[test]
396 fn health_codeclimate_uses_relative_normalized_paths() {
397 let report = HealthReport {
398 summary: HealthSummary {
399 max_cyclomatic_threshold: 10,
400 max_cognitive_threshold: 8,
401 max_crap_threshold: 30.0,
402 ..HealthSummary::default()
403 },
404 findings: vec![
405 ComplexityViolation {
406 path: PathBuf::from("/root/app/[id]/page.tsx"),
407 name: "render".to_string(),
408 line: 7,
409 col: 0,
410 cyclomatic: 12,
411 standard_cyclomatic: None,
412 cognitive: 9,
413 line_count: 20,
414 param_count: 1,
415 react_hook_count: 0,
416 react_jsx_max_depth: 0,
417 react_prop_count: 0,
418 react_hook_profile: None,
419 exceeded: ExceededThreshold::Both,
420 effective_severity: None,
421 severity: FindingSeverity::High,
422 mutation: None,
423 coverage_pct: None,
424 crap: None,
425 coverage_tier: None,
426 coverage_source: None,
427 inherited_from: None,
428 component_rollup: None,
429 contributions: Vec::new(),
430 effective_thresholds: None,
431 threshold_source: None,
432 max_file_lines: None,
433 }
434 .into(),
435 ],
436 ..HealthReport::default()
437 };
438
439 let issues = build_health_codeclimate(&report, Path::new("/root"));
440
441 assert_eq!(issues.len(), 1);
442 let issue = &issues[0];
443 assert_eq!(issue.check_name, "fallow/high-complexity");
444 assert_eq!(issue.location.path, "app/%5Bid%5D/page.tsx");
445 assert_eq!(issue.location.lines.begin, 7);
446 assert_eq!(issue.severity, CodeClimateSeverity::Major);
447 }
448
449 #[test]
450 fn health_codeclimate_includes_styling_findings() {
451 let report = HealthReport {
452 styling_findings: vec![StylingFinding {
453 internal: fallow_output::StylingFindingInternal::default(),
454 code: "css-selector-complexity".to_string(),
455 sub_kind: "high-specificity".to_string(),
456 path: "src/styles.css".to_string(),
457 line: 4,
458 value: "#app .card .title".to_string(),
459 effective_severity: StylingFindingSeverity::Error,
460 blast_radius: None,
461 confidence: None,
462 agent_disposition: None,
463 nearest_token: None,
464 fix_hint: None,
465 actions: Vec::new(),
466 }],
467 ..HealthReport::default()
468 };
469
470 let issues = build_health_codeclimate(&report, Path::new("/root"));
471
472 assert_eq!(issues.len(), 1);
473 let issue = &issues[0];
474 assert_eq!(issue.check_name, "fallow/css-selector-complexity");
475 assert_eq!(issue.location.path, "src/styles.css");
476 assert_eq!(issue.location.lines.begin, 4);
477 assert_eq!(issue.severity, CodeClimateSeverity::Major);
478 }
479
480 fn crap_violation(
481 effective_thresholds: Option<fallow_output::HealthEffectiveThresholds>,
482 ) -> ComplexityViolation {
483 ComplexityViolation {
484 path: PathBuf::from("/root/src/Board.astro"),
485 name: "<template>".to_string(),
486 line: 6,
487 col: 3,
488 cyclomatic: 11,
489 standard_cyclomatic: None,
490 cognitive: 4,
491 line_count: 20,
492 param_count: 0,
493 react_hook_count: 0,
494 react_jsx_max_depth: 0,
495 react_prop_count: 0,
496 react_hook_profile: None,
497 exceeded: ExceededThreshold::Crap,
498 effective_severity: None,
499 severity: FindingSeverity::Critical,
500 mutation: None,
501 coverage_pct: None,
502 crap: Some(132.0),
503 coverage_tier: None,
504 coverage_source: None,
505 inherited_from: None,
506 component_rollup: None,
507 contributions: Vec::new(),
508 threshold_source: effective_thresholds
509 .map(|_| fallow_output::ThresholdSource::Override),
510 max_file_lines: None,
511 effective_thresholds,
512 }
513 }
514
515 fn crap_report(
516 effective_thresholds: Option<fallow_output::HealthEffectiveThresholds>,
517 ) -> HealthReport {
518 HealthReport {
519 summary: HealthSummary {
520 max_crap_threshold: 30.0,
521 ..HealthSummary::default()
522 },
523 findings: vec![crap_violation(effective_thresholds).into()],
524 ..HealthReport::default()
525 }
526 }
527
528 #[test]
532 fn codeclimate_description_uses_the_override_ceiling_not_the_global_one() {
533 let report = crap_report(Some(fallow_output::HealthEffectiveThresholds {
534 max_cyclomatic: 20,
535 max_cognitive: 15,
536 max_crap: 100.0,
537 max_unit_size: 60,
538 }));
539
540 let issues = build_health_codeclimate(&report, Path::new("/root"));
541
542 assert_eq!(issues.len(), 1);
543 assert!(
544 issues[0].description.contains("threshold: 100.0"),
545 "{}",
546 issues[0].description
547 );
548 assert!(
549 !issues[0].description.contains("threshold: 30.0"),
550 "{}",
551 issues[0].description
552 );
553 }
554
555 #[test]
556 fn codeclimate_description_falls_back_to_the_global_ceiling() {
557 let issues = build_health_codeclimate(&crap_report(None), Path::new("/root"));
558
559 assert_eq!(issues.len(), 1);
560 assert!(
561 issues[0].description.contains("threshold: 30.0"),
562 "{}",
563 issues[0].description
564 );
565 }
566
567 #[test]
568 fn health_severities_reach_serialized_codeclimate_issues() {
569 for (severity, expected) in [
570 (FindingSeverity::Critical, "critical"),
571 (FindingSeverity::High, "major"),
572 (FindingSeverity::Moderate, "minor"),
573 ] {
574 let mut violation = crap_violation(None);
575 violation.severity = severity;
576 let report = HealthReport {
577 findings: vec![violation.into()],
578 ..HealthReport::default()
579 };
580 let issues = fallow_output::codeclimate_issues_to_value(&build_health_codeclimate(
581 &report,
582 Path::new("/root"),
583 ));
584 let issues = issues
585 .as_array()
586 .expect("CodeClimate output must be an array");
587 assert_eq!(issues.len(), 1);
588 assert_eq!(issues[0]["severity"], expected);
589 assert_eq!(issues[0]["check_name"], "fallow/high-crap-score");
590 }
591 }
592
593 #[test]
594 fn runtime_verdicts_reach_serialized_codeclimate_issues() {
595 use fallow_output::{
596 RuntimeCoverageConfidence, RuntimeCoverageEvidence, RuntimeCoverageReport,
597 };
598
599 for (verdict, check_name, severity) in [
600 (
601 RuntimeCoverageVerdict::SafeToDelete,
602 "fallow/runtime-safe-to-delete",
603 "critical",
604 ),
605 (
606 RuntimeCoverageVerdict::ReviewRequired,
607 "fallow/runtime-review-required",
608 "major",
609 ),
610 (
611 RuntimeCoverageVerdict::LowTraffic,
612 "fallow/runtime-low-traffic",
613 "minor",
614 ),
615 (
616 RuntimeCoverageVerdict::CoverageUnavailable,
617 "fallow/runtime-coverage-unavailable",
618 "minor",
619 ),
620 (
621 RuntimeCoverageVerdict::Active,
622 "fallow/runtime-coverage",
623 "minor",
624 ),
625 (
626 RuntimeCoverageVerdict::Unknown,
627 "fallow/runtime-coverage",
628 "minor",
629 ),
630 ] {
631 let report = HealthReport {
632 runtime_coverage: Some(RuntimeCoverageReport {
633 findings: vec![RuntimeCoverageFinding {
634 cloud_context: None,
635 id: "runtime-fixture".to_string(),
636 stable_id: None,
637 source_hash: None,
638 path: PathBuf::from("/root/src/legacy.ts"),
639 function: "legacyHelper".to_string(),
640 line: 12,
641 verdict,
642 invocations: Some(0),
643 confidence: RuntimeCoverageConfidence::High,
644 evidence: RuntimeCoverageEvidence {
645 static_status: "unused".to_string(),
646 test_coverage: "not_covered".to_string(),
647 test_only_reference: None,
648 v8_tracking: "tracked".to_string(),
649 untracked_reason: None,
650 observation_days: 30,
651 deployments_observed: 3,
652 },
653 actions: Vec::new(),
654 discriminators: None,
655 }],
656 ..RuntimeCoverageReport::default()
657 }),
658 ..HealthReport::default()
659 };
660 let issues = fallow_output::codeclimate_issues_to_value(&build_health_codeclimate(
661 &report,
662 Path::new("/root"),
663 ));
664 let issues = issues
665 .as_array()
666 .expect("CodeClimate output must be an array");
667 assert_eq!(issues.len(), 1, "{verdict:?}");
668 assert_eq!(issues[0]["check_name"], check_name);
669 assert_eq!(issues[0]["severity"], severity);
670 assert_eq!(issues[0]["location"]["path"], "src/legacy.ts");
671 assert_eq!(issues[0]["location"]["lines"]["begin"], 12);
672 }
673 }
674
675 #[test]
676 fn coverage_intelligence_verdicts_and_recommendations_reach_serialized_issues() {
677 use fallow_output::{
678 CoverageIntelligenceConfidence, CoverageIntelligenceEvidence,
679 CoverageIntelligenceReport,
680 };
681
682 let recommendations = [
683 (
684 CoverageIntelligenceRecommendation::AddTestOrSplitBeforeMerge,
685 "fallow/coverage-intelligence-risky-change",
686 ),
687 (
688 CoverageIntelligenceRecommendation::DeleteAfterConfirmingOwner,
689 "fallow/coverage-intelligence-delete",
690 ),
691 (
692 CoverageIntelligenceRecommendation::ReviewBeforeChanging,
693 "fallow/coverage-intelligence-review",
694 ),
695 (
696 CoverageIntelligenceRecommendation::RefactorCarefullyKeepBehavior,
697 "fallow/coverage-intelligence-refactor",
698 ),
699 ];
700 for (verdict, severity) in [
701 (
702 CoverageIntelligenceVerdict::RiskyChangeDetected,
703 Some("major"),
704 ),
705 (
706 CoverageIntelligenceVerdict::HighConfidenceDelete,
707 Some("major"),
708 ),
709 (CoverageIntelligenceVerdict::ReviewRequired, Some("minor")),
710 (
711 CoverageIntelligenceVerdict::RefactorCarefully,
712 Some("minor"),
713 ),
714 (CoverageIntelligenceVerdict::Clean, None),
715 (CoverageIntelligenceVerdict::Unknown, None),
716 ] {
717 for (recommendation, check_name) in recommendations {
718 let report = HealthReport {
719 coverage_intelligence: Some(CoverageIntelligenceReport {
720 schema_version: fallow_output::CoverageIntelligenceSchemaVersion::default(),
721 verdict,
722 summary: fallow_output::CoverageIntelligenceSummary::default(),
723 findings: vec![CoverageIntelligenceFinding {
724 id: "coverage-fixture".to_string(),
725 path: PathBuf::from("/root/src/legacy.ts"),
726 identity: Some("legacyHelper".to_string()),
727 line: 12,
728 verdict,
729 signals: Vec::new(),
730 recommendation,
731 confidence: CoverageIntelligenceConfidence::High,
732 related_ids: Vec::new(),
733 evidence: CoverageIntelligenceEvidence::default(),
734 actions: Vec::new(),
735 }],
736 }),
737 ..HealthReport::default()
738 };
739 let issues = fallow_output::codeclimate_issues_to_value(&build_health_codeclimate(
740 &report,
741 Path::new("/root"),
742 ));
743 let issues = issues
744 .as_array()
745 .expect("CodeClimate output must be an array");
746 if let Some(severity) = severity {
747 assert_eq!(issues.len(), 1, "{verdict:?}");
748 assert_eq!(issues[0]["check_name"], check_name);
749 assert_eq!(issues[0]["severity"], severity);
750 assert_eq!(issues[0]["location"]["path"], "src/legacy.ts");
751 } else {
752 assert!(issues.is_empty(), "{verdict:?}");
753 }
754 }
755 }
756 }
757}