Skip to main content

fallow_api/
grouped_output.rs

1//! Shared grouped-output builders for programmatic and CLI consumers.
2
3use std::collections::BTreeMap;
4use std::path::Path;
5
6use fallow_engine::duplicates::CloneFingerprintSet;
7use fallow_types::duplicates::{CloneGroup, DuplicationReport};
8use fallow_types::results::AnalysisResults;
9use rustc_hash::{FxHashMap, FxHashSet};
10
11use crate::{
12    AttributedCloneGroup, AttributedCloneGroupFinding, AttributedInstance, CloneFamilyFinding,
13    DuplicationGroup, DuplicationGrouping,
14};
15
16/// Canonical label for issues that cannot be attributed to a group.
17pub const UNOWNED_GROUP_LABEL: &str = "(unowned)";
18
19/// The group header part that names the opt-in component health signals of
20/// `results`, such as `; 3 health signals: 3 duplicate prop shapes`. Empty when
21/// there are none. Advisory signals do not count toward `total_issues`, so a group
22/// header names them next to the issue count. The human and markdown grouped
23/// reports share this text.
24#[must_use]
25pub fn health_signal_header_part(results: &AnalysisResults) -> String {
26    let kinds = [
27        (
28            results.prop_drilling_chains.len() - results.enforced_prop_drilling_count(),
29            "prop drilling chain",
30        ),
31        (
32            results.thin_wrappers.len() - results.enforced_thin_wrapper_count(),
33            "thin wrapper",
34        ),
35        (
36            results.duplicate_prop_shapes.len() - results.enforced_duplicate_prop_shape_count(),
37            "duplicate prop shape",
38        ),
39    ];
40    let count: usize = kinds.iter().map(|(n, _)| n).sum();
41    if count == 0 {
42        return String::new();
43    }
44    let parts: Vec<String> = kinds
45        .iter()
46        .filter(|(n, _)| *n > 0)
47        .map(|(n, label)| format!("{n} {label}{}", plural_suffix(*n)))
48        .collect();
49    format!(
50        "; {count} health signal{}: {}",
51        plural_suffix(count),
52        parts.join(", ")
53    )
54}
55
56const fn plural_suffix(count: usize) -> &'static str {
57    if count == 1 { "" } else { "s" }
58}
59
60/// A single grouped dead-code analysis bucket.
61pub struct ResultGroup {
62    /// Group label such as owner, directory, package, or section.
63    pub key: String,
64    /// Section default owners for section grouping.
65    ///
66    /// `None` for grouping modes without owner metadata. `Some(vec![])` for
67    /// groups that have no section owners.
68    pub owners: Option<Vec<String>>,
69    /// Issues belonging to this group.
70    pub results: AnalysisResults,
71}
72
73/// Partition analysis results into groups using caller-provided path resolvers.
74///
75/// The caller owns all environment-specific context, such as CODEOWNERS,
76/// package discovery, root-relative path normalization, or section metadata.
77#[must_use]
78pub fn group_analysis_results_with<F, O>(
79    results: &AnalysisResults,
80    mut key_for_path: F,
81    mut owners_for_path: O,
82    include_owners: bool,
83) -> Vec<ResultGroup>
84where
85    F: FnMut(&Path) -> String,
86    O: FnMut(&Path) -> Option<Vec<String>>,
87{
88    let mut group_owners: FxHashMap<String, Vec<String>> = FxHashMap::default();
89    let mut builder = GroupingBuilder::new(|path: &Path| {
90        let key = key_for_path(path);
91        if include_owners && !group_owners.contains_key(&key) {
92            let owners = owners_for_path(path).unwrap_or_default();
93            group_owners.insert(key.clone(), owners);
94        }
95        key
96    });
97    builder.group_symbol_issues(results);
98    builder.group_dependency_issues(results);
99    builder.group_relationship_issues(results);
100    builder.group_workspace_config_issues(results);
101    builder.group_component_health_issues(results);
102
103    finalize_groups(builder.into_groups(), group_owners, include_owners)
104}
105
106struct GroupingBuilder<F> {
107    groups: FxHashMap<String, AnalysisResults>,
108    key_for: F,
109}
110
111impl<F> GroupingBuilder<F>
112where
113    F: FnMut(&Path) -> String,
114{
115    fn new(key_for: F) -> Self {
116        Self {
117            groups: FxHashMap::default(),
118            key_for,
119        }
120    }
121
122    fn entry_for_path(&mut self, path: &Path) -> &mut AnalysisResults {
123        let key = (self.key_for)(path);
124        self.groups.entry(key).or_default()
125    }
126
127    fn entry_for_key(&mut self, key: String) -> &mut AnalysisResults {
128        self.groups.entry(key).or_default()
129    }
130
131    fn into_groups(self) -> FxHashMap<String, AnalysisResults> {
132        self.groups
133    }
134
135    fn group_symbol_issues(&mut self, results: &AnalysisResults) {
136        for item in &results.unused_files {
137            self.entry_for_path(&item.file.path)
138                .unused_files
139                .push(item.clone());
140        }
141        for item in &results.unused_exports {
142            self.entry_for_path(&item.export.path)
143                .unused_exports
144                .push(item.clone());
145        }
146        for item in &results.unused_types {
147            self.entry_for_path(&item.export.path)
148                .unused_types
149                .push(item.clone());
150        }
151        for item in &results.private_type_leaks {
152            self.entry_for_path(&item.leak.path)
153                .private_type_leaks
154                .push(item.clone());
155        }
156        for item in &results.deprecated_exports_in_use {
157            self.entry_for_path(&item.export.path)
158                .deprecated_exports_in_use
159                .push(item.clone());
160        }
161        for item in &results.unused_enum_members {
162            self.entry_for_path(&item.member.path)
163                .unused_enum_members
164                .push(item.clone());
165        }
166        for item in &results.unused_class_members {
167            self.entry_for_path(&item.member.path)
168                .unused_class_members
169                .push(item.clone());
170        }
171        for item in &results.unused_store_members {
172            self.entry_for_path(&item.member.path)
173                .unused_store_members
174                .push(item.clone());
175        }
176        for item in &results.unused_namespace_members {
177            self.entry_for_path(&item.member.path)
178                .unused_namespace_members
179                .push(item.clone());
180        }
181        for item in &results.unused_protected_class_members {
182            self.entry_for_path(&item.member.path)
183                .unused_protected_class_members
184                .push(item.clone());
185        }
186        for item in &results.namespace_escapes {
187            self.entry_for_path(&item.escape.path)
188                .namespace_escapes
189                .push(item.clone());
190        }
191        for item in &results.test_only_exports {
192            self.entry_for_path(&item.export.path)
193                .test_only_exports
194                .push(item.clone());
195        }
196        for item in &results.unresolved_imports {
197            self.entry_for_path(&item.import.path)
198                .unresolved_imports
199                .push(item.clone());
200        }
201    }
202
203    fn group_dependency_issues(&mut self, results: &AnalysisResults) {
204        for item in &results.unused_dependencies {
205            self.entry_for_path(&item.dep.path)
206                .unused_dependencies
207                .push(item.clone());
208        }
209        for item in &results.unused_dev_dependencies {
210            self.entry_for_path(&item.dep.path)
211                .unused_dev_dependencies
212                .push(item.clone());
213        }
214        for item in &results.unused_optional_dependencies {
215            self.entry_for_path(&item.dep.path)
216                .unused_optional_dependencies
217                .push(item.clone());
218        }
219        for item in &results.type_only_dependencies {
220            self.entry_for_path(&item.dep.path)
221                .type_only_dependencies
222                .push(item.clone());
223        }
224        for item in &results.test_only_dependencies {
225            self.entry_for_path(&item.dep.path)
226                .test_only_dependencies
227                .push(item.clone());
228        }
229        for item in &results.dev_dependencies_in_production {
230            self.entry_for_path(&item.dep.path)
231                .dev_dependencies_in_production
232                .push(item.clone());
233        }
234
235        for item in &results.unlisted_dependencies {
236            let key = item.dep.imported_from.first().map_or_else(
237                || UNOWNED_GROUP_LABEL.to_string(),
238                |site| (self.key_for)(&site.path),
239            );
240            self.entry_for_key(key)
241                .unlisted_dependencies
242                .push(item.clone());
243        }
244        for item in &results.unlisted_binaries {
245            let key = item.binary.used_in.first().map_or_else(
246                || UNOWNED_GROUP_LABEL.to_string(),
247                |site| (self.key_for)(&site.path),
248            );
249            self.entry_for_key(key).unlisted_binaries.push(item.clone());
250        }
251        for item in &results.duplicate_exports {
252            let key = item.export.locations.first().map_or_else(
253                || UNOWNED_GROUP_LABEL.to_string(),
254                |loc| (self.key_for)(&loc.path),
255            );
256            self.entry_for_key(key).duplicate_exports.push(item.clone());
257        }
258    }
259
260    fn group_relationship_issues(&mut self, results: &AnalysisResults) {
261        self.group_structure_issues(results);
262        self.group_framework_boundary_issues(results);
263        self.group_component_contract_issues(results);
264    }
265
266    fn group_structure_issues(&mut self, results: &AnalysisResults) {
267        for item in &results.circular_dependencies {
268            let key = item
269                .cycle
270                .files
271                .first()
272                .map_or_else(|| UNOWNED_GROUP_LABEL.to_string(), |f| (self.key_for)(f));
273            self.entry_for_key(key)
274                .circular_dependencies
275                .push(item.clone());
276        }
277        for item in &results.re_export_cycles {
278            let key = item
279                .cycle
280                .files
281                .first()
282                .map_or_else(|| UNOWNED_GROUP_LABEL.to_string(), |f| (self.key_for)(f));
283            self.entry_for_key(key).re_export_cycles.push(item.clone());
284        }
285        // The first example import file owns a package cycle, the same file
286        // that workspace scope and per-file severity use.
287        for item in &results.package_cycles {
288            let key = item.cycle.edges.first().map_or_else(
289                || UNOWNED_GROUP_LABEL.to_string(),
290                |edge| (self.key_for)(&edge.path),
291            );
292            self.entry_for_key(key).package_cycles.push(item.clone());
293        }
294        for item in &results.boundary_violations {
295            self.entry_for_path(&item.violation.from_path)
296                .boundary_violations
297                .push(item.clone());
298        }
299        for item in &results.boundary_coverage_violations {
300            self.entry_for_path(&item.violation.path)
301                .boundary_coverage_violations
302                .push(item.clone());
303        }
304        for item in &results.boundary_call_violations {
305            self.entry_for_path(&item.violation.path)
306                .boundary_call_violations
307                .push(item.clone());
308        }
309        for item in &results.policy_violations {
310            self.entry_for_path(&item.violation.path)
311                .policy_violations
312                .push(item.clone());
313        }
314    }
315
316    fn group_framework_boundary_issues(&mut self, results: &AnalysisResults) {
317        for item in &results.invalid_client_exports {
318            self.entry_for_path(&item.export.path)
319                .invalid_client_exports
320                .push(item.clone());
321        }
322        for item in &results.mixed_client_server_barrels {
323            self.entry_for_path(&item.barrel.path)
324                .mixed_client_server_barrels
325                .push(item.clone());
326        }
327        for item in &results.misplaced_directives {
328            self.entry_for_path(&item.directive_site.path)
329                .misplaced_directives
330                .push(item.clone());
331        }
332        for item in &results.unprovided_injects {
333            self.entry_for_path(&item.inject.path)
334                .unprovided_injects
335                .push(item.clone());
336        }
337        for item in &results.unrendered_components {
338            self.entry_for_path(&item.component.path)
339                .unrendered_components
340                .push(item.clone());
341        }
342        for item in &results.route_collisions {
343            self.entry_for_path(&item.collision.path)
344                .route_collisions
345                .push(item.clone());
346        }
347        for item in &results.dynamic_segment_name_conflicts {
348            self.entry_for_path(&item.conflict.path)
349                .dynamic_segment_name_conflicts
350                .push(item.clone());
351        }
352    }
353
354    fn group_component_contract_issues(&mut self, results: &AnalysisResults) {
355        for item in &results.unused_component_props {
356            self.entry_for_path(&item.prop.path)
357                .unused_component_props
358                .push(item.clone());
359        }
360        for item in &results.constant_parameters {
361            self.entry_for_path(&item.parameter.path)
362                .constant_parameters
363                .push(item.clone());
364        }
365        for item in &results.absent_component_props {
366            self.entry_for_path(&item.prop.path)
367                .absent_component_props
368                .push(item.clone());
369        }
370        for item in &results.unused_component_emits {
371            self.entry_for_path(&item.emit.path)
372                .unused_component_emits
373                .push(item.clone());
374        }
375        for item in &results.unused_component_inputs {
376            self.entry_for_path(&item.input.path)
377                .unused_component_inputs
378                .push(item.clone());
379        }
380        for item in &results.unused_component_outputs {
381            self.entry_for_path(&item.output.path)
382                .unused_component_outputs
383                .push(item.clone());
384        }
385        for item in &results.unused_svelte_events {
386            self.entry_for_path(&item.event.path)
387                .unused_svelte_events
388                .push(item.clone());
389        }
390        for item in &results.duplicate_export_aliases {
391            self.entry_for_path(&item.alias.path)
392                .duplicate_export_aliases
393                .push(item.clone());
394        }
395        for item in &results.unused_effect_layers {
396            self.entry_for_path(&item.layer.path)
397                .unused_effect_layers
398                .push(item.clone());
399        }
400        for item in &results.unused_tagged_errors {
401            self.entry_for_path(&item.error.path)
402                .unused_tagged_errors
403                .push(item.clone());
404        }
405        for item in &results.unproduced_catch_tags {
406            self.entry_for_path(&item.catch_tag.path)
407                .unproduced_catch_tags
408                .push(item.clone());
409        }
410        for item in &results.unused_server_actions {
411            self.entry_for_path(&item.action.path)
412                .unused_server_actions
413                .push(item.clone());
414        }
415        for item in &results.unused_load_data_keys {
416            self.entry_for_path(&item.key.path)
417                .unused_load_data_keys
418                .push(item.clone());
419        }
420        for item in &results.stale_suppressions {
421            self.entry_for_path(&item.path)
422                .stale_suppressions
423                .push(item.clone());
424        }
425    }
426
427    fn group_workspace_config_issues(&mut self, results: &AnalysisResults) {
428        for item in &results.unused_catalog_entries {
429            self.entry_for_path(&item.entry.path)
430                .unused_catalog_entries
431                .push(item.clone());
432        }
433        for item in &results.empty_catalog_groups {
434            self.entry_for_path(&item.group.path)
435                .empty_catalog_groups
436                .push(item.clone());
437        }
438        for item in &results.unresolved_catalog_references {
439            self.entry_for_path(&item.reference.path)
440                .unresolved_catalog_references
441                .push(item.clone());
442        }
443        for item in &results.unused_dependency_overrides {
444            self.entry_for_path(&item.entry.path)
445                .unused_dependency_overrides
446                .push(item.clone());
447        }
448        for item in &results.misconfigured_dependency_overrides {
449            self.entry_for_path(&item.entry.path)
450                .misconfigured_dependency_overrides
451                .push(item.clone());
452        }
453    }
454
455    /// Group the opt-in component health signals. Advisory signals do not count toward
456    /// `total_issues`, but the flat report lists them, so the groups must too.
457    fn group_component_health_issues(&mut self, results: &AnalysisResults) {
458        // The first hop owns the drilled prop and anchors the finding, the
459        // same file that suppression and CI annotations use.
460        for item in &results.prop_drilling_chains {
461            let key = item.chain.hops.first().map_or_else(
462                || UNOWNED_GROUP_LABEL.to_string(),
463                |hop| (self.key_for)(&hop.file),
464            );
465            self.entry_for_key(key)
466                .prop_drilling_chains
467                .push(item.clone());
468        }
469        for item in &results.thin_wrappers {
470            self.entry_for_path(&item.wrapper.file)
471                .thin_wrappers
472                .push(item.clone());
473        }
474        for item in &results.duplicate_prop_shapes {
475            self.entry_for_path(&item.shape.file)
476                .duplicate_prop_shapes
477                .push(item.clone());
478        }
479    }
480}
481
482fn finalize_groups(
483    groups: FxHashMap<String, AnalysisResults>,
484    mut group_owners: FxHashMap<String, Vec<String>>,
485    include_owners: bool,
486) -> Vec<ResultGroup> {
487    let mut sorted: Vec<_> = groups
488        .into_iter()
489        .map(|(key, results)| {
490            let owners = if include_owners {
491                Some(group_owners.remove(&key).unwrap_or_default())
492            } else {
493                None
494            };
495            ResultGroup {
496                key,
497                owners,
498                results,
499            }
500        })
501        .collect();
502    sorted.sort_by(|a, b| {
503        let a_unowned = a.key == UNOWNED_GROUP_LABEL;
504        let b_unowned = b.key == UNOWNED_GROUP_LABEL;
505        match (a_unowned, b_unowned) {
506            (true, false) => std::cmp::Ordering::Greater,
507            (false, true) => std::cmp::Ordering::Less,
508            _ => b
509                .results
510                .total_issues()
511                .cmp(&a.results.total_issues())
512                .then_with(|| a.key.cmp(&b.key)),
513        }
514    });
515    sorted
516}
517
518/// Return the majority owner for a clone group using caller-provided path attribution.
519#[must_use]
520pub fn largest_clone_group_owner_with<F>(group: &CloneGroup, mut key_for_path: F) -> String
521where
522    F: FnMut(&Path) -> String,
523{
524    let mut counts: BTreeMap<String, u32> = BTreeMap::new();
525    for instance in &group.instances {
526        let key = key_for_path(&instance.file);
527        *counts.entry(key).or_insert(0) += 1;
528    }
529    if counts.is_empty() {
530        return UNOWNED_GROUP_LABEL.to_string();
531    }
532    let mut best_key: Option<String> = None;
533    let mut best_count: u32 = 0;
534    for (key, count) in counts {
535        if best_key.is_none() || count > best_count {
536            best_count = count;
537            best_key = Some(key);
538        }
539    }
540    best_key.unwrap_or_else(|| UNOWNED_GROUP_LABEL.to_string())
541}
542
543/// Build grouped duplication output using caller-provided path attribution.
544#[must_use]
545pub fn build_duplication_grouping_with<F>(
546    report: &DuplicationReport,
547    mode: &'static str,
548    mut key_for_path: F,
549) -> DuplicationGrouping
550where
551    F: FnMut(&Path) -> String,
552{
553    let fingerprints = CloneFingerprintSet::from_groups(&report.clone_groups);
554    let buckets = build_attributed_clone_buckets(report, &mut key_for_path);
555    let mut groups: Vec<DuplicationGroup> = buckets
556        .into_iter()
557        .map(|(key, groups)| duplication_group(key, groups, report, &fingerprints))
558        .collect();
559    sort_duplication_groups(&mut groups);
560
561    DuplicationGrouping { mode, groups }
562}
563
564fn build_attributed_clone_buckets<F>(
565    report: &DuplicationReport,
566    key_for_path: &mut F,
567) -> BTreeMap<String, Vec<AttributedCloneGroup>>
568where
569    F: FnMut(&Path) -> String,
570{
571    let mut buckets: BTreeMap<String, Vec<AttributedCloneGroup>> = BTreeMap::new();
572    for group in &report.clone_groups {
573        let attributed = attributed_clone_group(group, key_for_path);
574        buckets
575            .entry(attributed.primary_owner.clone())
576            .or_default()
577            .push(attributed);
578    }
579    buckets
580}
581
582fn attributed_clone_group<F>(group: &CloneGroup, key_for_path: &mut F) -> AttributedCloneGroup
583where
584    F: FnMut(&Path) -> String,
585{
586    let primary_owner = largest_clone_group_owner_with(group, &mut *key_for_path);
587    let instances = group
588        .instances
589        .iter()
590        .map(|instance| AttributedInstance {
591            owner: key_for_path(&instance.file),
592            instance: instance.clone(),
593        })
594        .collect();
595    AttributedCloneGroup {
596        primary_owner,
597        token_count: group.token_count,
598        line_count: group.line_count,
599        similarity: group.similarity,
600        instances,
601    }
602}
603
604fn duplication_group(
605    key: String,
606    attributed_groups: Vec<AttributedCloneGroup>,
607    report: &DuplicationReport,
608    fingerprints: &CloneFingerprintSet,
609) -> DuplicationGroup {
610    let clone_families = clone_families_for_bucket(&attributed_groups, report, fingerprints);
611    let mut coverage = fallow_engine::duplicates::CloneCoverage::default();
612    for group in &attributed_groups {
613        coverage.add_group(
614            group
615                .instances
616                .iter()
617                .map(|attributed| &attributed.instance),
618            group.token_count,
619        );
620    }
621    // Filtering and bounded-work counters are report-scoped and cannot be
622    // attributed reliably to one grouped bucket.
623    let stats = coverage.into_stats(
624        fallow_engine::duplicates::CorpusTotals::of(&report.stats),
625        fallow_engine::duplicates::CarriedCounters {
626            clone_families: clone_families.len(),
627            ..Default::default()
628        },
629    );
630    let clone_groups = attributed_groups
631        .into_iter()
632        .map(|group| {
633            let fingerprint = group.fingerprint(fingerprints);
634            AttributedCloneGroupFinding::with_fingerprint(group, fingerprint)
635        })
636        .collect();
637
638    DuplicationGroup {
639        key,
640        stats,
641        clone_groups,
642        clone_families,
643    }
644}
645
646fn clone_families_for_bucket(
647    attributed_groups: &[AttributedCloneGroup],
648    report: &DuplicationReport,
649    fingerprints: &CloneFingerprintSet,
650) -> Vec<CloneFamilyFinding> {
651    let bucket_files: FxHashSet<&Path> = attributed_groups
652        .iter()
653        .flat_map(|group| group.instances.iter().map(|i| i.instance.file.as_path()))
654        .collect();
655
656    report
657        .clone_families
658        .iter()
659        .filter(|family| {
660            family
661                .files
662                .iter()
663                .any(|path| bucket_files.contains(path.as_path()))
664        })
665        .map(|family| CloneFamilyFinding::with_fingerprints(family.clone(), fingerprints))
666        .collect()
667}
668
669fn sort_duplication_groups(groups: &mut [DuplicationGroup]) {
670    groups.sort_by(|a, b| {
671        let a_unowned = a.key == UNOWNED_GROUP_LABEL;
672        let b_unowned = b.key == UNOWNED_GROUP_LABEL;
673        match (a_unowned, b_unowned) {
674            (true, false) => std::cmp::Ordering::Greater,
675            (false, true) => std::cmp::Ordering::Less,
676            _ => b
677                .clone_groups
678                .len()
679                .cmp(&a.clone_groups.len())
680                .then_with(|| a.key.cmp(&b.key)),
681        }
682    });
683}
684
685#[cfg(test)]
686mod tests {
687    use super::*;
688
689    /// Group by the full file path, so every finding anchor gets its own group.
690    fn group_by_path(results: &AnalysisResults) -> Vec<ResultGroup> {
691        group_analysis_results_with(
692            results,
693            |path: &Path| path.to_string_lossy().into_owned(),
694            |_: &Path| None,
695            false,
696        )
697    }
698
699    /// The length of each serialized issue list of `results`, by key.
700    fn list_lengths(results: &AnalysisResults) -> BTreeMap<String, usize> {
701        let value = serde_json::to_value(results).expect("serialize results");
702        value
703            .as_object()
704            .expect("results object")
705            .iter()
706            .filter_map(|(key, value)| value.as_array().map(|items| (key.clone(), items.len())))
707            .collect()
708    }
709
710    #[test]
711    fn every_issue_list_is_grouped() {
712        // The fixture names every field, so a new field must get a value there.
713        let source = crate::editor::tests::merge_test_source_with_all_fields();
714
715        let expected = list_lengths(&source);
716        for (key, len) in &expected {
717            assert!(
718                *len > 0,
719                "the fixture must fill `{key}` so this guard checks its grouping"
720            );
721        }
722
723        let groups = group_by_path(&source);
724        let mut grouped: BTreeMap<String, usize> = BTreeMap::new();
725        for group in &groups {
726            for (key, len) in list_lengths(&group.results) {
727                *grouped.entry(key).or_insert(0) += len;
728            }
729        }
730        for (key, len) in &expected {
731            assert_eq!(
732                grouped.get(key).copied().unwrap_or(0),
733                *len,
734                "--group-by drops `{key}` findings: add them to `GroupingBuilder`"
735            );
736        }
737
738        let grouped_total: usize = groups.iter().map(|g| g.results.total_issues()).sum();
739        assert_eq!(grouped_total, source.total_issues());
740    }
741
742    #[test]
743    fn prop_drilling_chain_without_hops_is_unowned() {
744        let mut source = crate::editor::tests::merge_test_source_with_all_fields();
745        let mut chain = source.prop_drilling_chains.remove(0);
746        chain.chain.hops.clear();
747        let mut results = AnalysisResults::default();
748        results.prop_drilling_chains.push(chain);
749
750        let groups = group_by_path(&results);
751        assert_eq!(groups.len(), 1);
752        assert_eq!(groups[0].key, UNOWNED_GROUP_LABEL);
753        assert_eq!(groups[0].results.prop_drilling_chains.len(), 1);
754    }
755
756    #[test]
757    fn health_signal_header_part_names_each_signal_type() {
758        let source = crate::editor::tests::merge_test_source_with_all_fields();
759        let mut results = AnalysisResults::default();
760        assert_eq!(health_signal_header_part(&results), "");
761
762        results
763            .prop_drilling_chains
764            .push(source.prop_drilling_chains[0].clone());
765        results.thin_wrappers.push(source.thin_wrappers[0].clone());
766        results.thin_wrappers.push(source.thin_wrappers[0].clone());
767        assert_eq!(
768            health_signal_header_part(&results),
769            "; 3 health signals: 1 prop drilling chain, 2 thin wrappers"
770        );
771
772        let mut single = AnalysisResults::default();
773        single
774            .duplicate_prop_shapes
775            .push(source.duplicate_prop_shapes[0].clone());
776        assert_eq!(
777            health_signal_header_part(&single),
778            "; 1 health signal: 1 duplicate prop shape"
779        );
780    }
781}