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.unresolved_imports {
192            self.entry_for_path(&item.import.path)
193                .unresolved_imports
194                .push(item.clone());
195        }
196    }
197
198    fn group_dependency_issues(&mut self, results: &AnalysisResults) {
199        for item in &results.unused_dependencies {
200            self.entry_for_path(&item.dep.path)
201                .unused_dependencies
202                .push(item.clone());
203        }
204        for item in &results.unused_dev_dependencies {
205            self.entry_for_path(&item.dep.path)
206                .unused_dev_dependencies
207                .push(item.clone());
208        }
209        for item in &results.unused_optional_dependencies {
210            self.entry_for_path(&item.dep.path)
211                .unused_optional_dependencies
212                .push(item.clone());
213        }
214        for item in &results.type_only_dependencies {
215            self.entry_for_path(&item.dep.path)
216                .type_only_dependencies
217                .push(item.clone());
218        }
219        for item in &results.test_only_dependencies {
220            self.entry_for_path(&item.dep.path)
221                .test_only_dependencies
222                .push(item.clone());
223        }
224        for item in &results.dev_dependencies_in_production {
225            self.entry_for_path(&item.dep.path)
226                .dev_dependencies_in_production
227                .push(item.clone());
228        }
229
230        for item in &results.unlisted_dependencies {
231            let key = item.dep.imported_from.first().map_or_else(
232                || UNOWNED_GROUP_LABEL.to_string(),
233                |site| (self.key_for)(&site.path),
234            );
235            self.entry_for_key(key)
236                .unlisted_dependencies
237                .push(item.clone());
238        }
239        for item in &results.unlisted_binaries {
240            let key = item.binary.used_in.first().map_or_else(
241                || UNOWNED_GROUP_LABEL.to_string(),
242                |site| (self.key_for)(&site.path),
243            );
244            self.entry_for_key(key).unlisted_binaries.push(item.clone());
245        }
246        for item in &results.duplicate_exports {
247            let key = item.export.locations.first().map_or_else(
248                || UNOWNED_GROUP_LABEL.to_string(),
249                |loc| (self.key_for)(&loc.path),
250            );
251            self.entry_for_key(key).duplicate_exports.push(item.clone());
252        }
253    }
254
255    fn group_relationship_issues(&mut self, results: &AnalysisResults) {
256        self.group_structure_issues(results);
257        self.group_framework_boundary_issues(results);
258        self.group_component_contract_issues(results);
259    }
260
261    fn group_structure_issues(&mut self, results: &AnalysisResults) {
262        for item in &results.circular_dependencies {
263            let key = item
264                .cycle
265                .files
266                .first()
267                .map_or_else(|| UNOWNED_GROUP_LABEL.to_string(), |f| (self.key_for)(f));
268            self.entry_for_key(key)
269                .circular_dependencies
270                .push(item.clone());
271        }
272        for item in &results.re_export_cycles {
273            let key = item
274                .cycle
275                .files
276                .first()
277                .map_or_else(|| UNOWNED_GROUP_LABEL.to_string(), |f| (self.key_for)(f));
278            self.entry_for_key(key).re_export_cycles.push(item.clone());
279        }
280        // The first example import file owns a package cycle, the same file
281        // that workspace scope and per-file severity use.
282        for item in &results.package_cycles {
283            let key = item.cycle.edges.first().map_or_else(
284                || UNOWNED_GROUP_LABEL.to_string(),
285                |edge| (self.key_for)(&edge.path),
286            );
287            self.entry_for_key(key).package_cycles.push(item.clone());
288        }
289        for item in &results.boundary_violations {
290            self.entry_for_path(&item.violation.from_path)
291                .boundary_violations
292                .push(item.clone());
293        }
294        for item in &results.boundary_coverage_violations {
295            self.entry_for_path(&item.violation.path)
296                .boundary_coverage_violations
297                .push(item.clone());
298        }
299        for item in &results.boundary_call_violations {
300            self.entry_for_path(&item.violation.path)
301                .boundary_call_violations
302                .push(item.clone());
303        }
304        for item in &results.policy_violations {
305            self.entry_for_path(&item.violation.path)
306                .policy_violations
307                .push(item.clone());
308        }
309    }
310
311    fn group_framework_boundary_issues(&mut self, results: &AnalysisResults) {
312        for item in &results.invalid_client_exports {
313            self.entry_for_path(&item.export.path)
314                .invalid_client_exports
315                .push(item.clone());
316        }
317        for item in &results.mixed_client_server_barrels {
318            self.entry_for_path(&item.barrel.path)
319                .mixed_client_server_barrels
320                .push(item.clone());
321        }
322        for item in &results.misplaced_directives {
323            self.entry_for_path(&item.directive_site.path)
324                .misplaced_directives
325                .push(item.clone());
326        }
327        for item in &results.unprovided_injects {
328            self.entry_for_path(&item.inject.path)
329                .unprovided_injects
330                .push(item.clone());
331        }
332        for item in &results.unrendered_components {
333            self.entry_for_path(&item.component.path)
334                .unrendered_components
335                .push(item.clone());
336        }
337        for item in &results.route_collisions {
338            self.entry_for_path(&item.collision.path)
339                .route_collisions
340                .push(item.clone());
341        }
342        for item in &results.dynamic_segment_name_conflicts {
343            self.entry_for_path(&item.conflict.path)
344                .dynamic_segment_name_conflicts
345                .push(item.clone());
346        }
347    }
348
349    fn group_component_contract_issues(&mut self, results: &AnalysisResults) {
350        for item in &results.unused_component_props {
351            self.entry_for_path(&item.prop.path)
352                .unused_component_props
353                .push(item.clone());
354        }
355        for item in &results.constant_parameters {
356            self.entry_for_path(&item.parameter.path)
357                .constant_parameters
358                .push(item.clone());
359        }
360        for item in &results.absent_component_props {
361            self.entry_for_path(&item.prop.path)
362                .absent_component_props
363                .push(item.clone());
364        }
365        for item in &results.unused_component_emits {
366            self.entry_for_path(&item.emit.path)
367                .unused_component_emits
368                .push(item.clone());
369        }
370        for item in &results.unused_component_inputs {
371            self.entry_for_path(&item.input.path)
372                .unused_component_inputs
373                .push(item.clone());
374        }
375        for item in &results.unused_component_outputs {
376            self.entry_for_path(&item.output.path)
377                .unused_component_outputs
378                .push(item.clone());
379        }
380        for item in &results.unused_svelte_events {
381            self.entry_for_path(&item.event.path)
382                .unused_svelte_events
383                .push(item.clone());
384        }
385        for item in &results.duplicate_export_aliases {
386            self.entry_for_path(&item.alias.path)
387                .duplicate_export_aliases
388                .push(item.clone());
389        }
390        for item in &results.unused_effect_layers {
391            self.entry_for_path(&item.layer.path)
392                .unused_effect_layers
393                .push(item.clone());
394        }
395        for item in &results.unused_tagged_errors {
396            self.entry_for_path(&item.error.path)
397                .unused_tagged_errors
398                .push(item.clone());
399        }
400        for item in &results.unproduced_catch_tags {
401            self.entry_for_path(&item.catch_tag.path)
402                .unproduced_catch_tags
403                .push(item.clone());
404        }
405        for item in &results.unused_server_actions {
406            self.entry_for_path(&item.action.path)
407                .unused_server_actions
408                .push(item.clone());
409        }
410        for item in &results.unused_load_data_keys {
411            self.entry_for_path(&item.key.path)
412                .unused_load_data_keys
413                .push(item.clone());
414        }
415        for item in &results.stale_suppressions {
416            self.entry_for_path(&item.path)
417                .stale_suppressions
418                .push(item.clone());
419        }
420    }
421
422    fn group_workspace_config_issues(&mut self, results: &AnalysisResults) {
423        for item in &results.unused_catalog_entries {
424            self.entry_for_path(&item.entry.path)
425                .unused_catalog_entries
426                .push(item.clone());
427        }
428        for item in &results.empty_catalog_groups {
429            self.entry_for_path(&item.group.path)
430                .empty_catalog_groups
431                .push(item.clone());
432        }
433        for item in &results.unresolved_catalog_references {
434            self.entry_for_path(&item.reference.path)
435                .unresolved_catalog_references
436                .push(item.clone());
437        }
438        for item in &results.unused_dependency_overrides {
439            self.entry_for_path(&item.entry.path)
440                .unused_dependency_overrides
441                .push(item.clone());
442        }
443        for item in &results.misconfigured_dependency_overrides {
444            self.entry_for_path(&item.entry.path)
445                .misconfigured_dependency_overrides
446                .push(item.clone());
447        }
448    }
449
450    /// Group the opt-in component health signals. Advisory signals do not count toward
451    /// `total_issues`, but the flat report lists them, so the groups must too.
452    fn group_component_health_issues(&mut self, results: &AnalysisResults) {
453        // The first hop owns the drilled prop and anchors the finding, the
454        // same file that suppression and CI annotations use.
455        for item in &results.prop_drilling_chains {
456            let key = item.chain.hops.first().map_or_else(
457                || UNOWNED_GROUP_LABEL.to_string(),
458                |hop| (self.key_for)(&hop.file),
459            );
460            self.entry_for_key(key)
461                .prop_drilling_chains
462                .push(item.clone());
463        }
464        for item in &results.thin_wrappers {
465            self.entry_for_path(&item.wrapper.file)
466                .thin_wrappers
467                .push(item.clone());
468        }
469        for item in &results.duplicate_prop_shapes {
470            self.entry_for_path(&item.shape.file)
471                .duplicate_prop_shapes
472                .push(item.clone());
473        }
474    }
475}
476
477fn finalize_groups(
478    groups: FxHashMap<String, AnalysisResults>,
479    mut group_owners: FxHashMap<String, Vec<String>>,
480    include_owners: bool,
481) -> Vec<ResultGroup> {
482    let mut sorted: Vec<_> = groups
483        .into_iter()
484        .map(|(key, results)| {
485            let owners = if include_owners {
486                Some(group_owners.remove(&key).unwrap_or_default())
487            } else {
488                None
489            };
490            ResultGroup {
491                key,
492                owners,
493                results,
494            }
495        })
496        .collect();
497    sorted.sort_by(|a, b| {
498        let a_unowned = a.key == UNOWNED_GROUP_LABEL;
499        let b_unowned = b.key == UNOWNED_GROUP_LABEL;
500        match (a_unowned, b_unowned) {
501            (true, false) => std::cmp::Ordering::Greater,
502            (false, true) => std::cmp::Ordering::Less,
503            _ => b
504                .results
505                .total_issues()
506                .cmp(&a.results.total_issues())
507                .then_with(|| a.key.cmp(&b.key)),
508        }
509    });
510    sorted
511}
512
513/// Return the majority owner for a clone group using caller-provided path attribution.
514#[must_use]
515pub fn largest_clone_group_owner_with<F>(group: &CloneGroup, mut key_for_path: F) -> String
516where
517    F: FnMut(&Path) -> String,
518{
519    let mut counts: BTreeMap<String, u32> = BTreeMap::new();
520    for instance in &group.instances {
521        let key = key_for_path(&instance.file);
522        *counts.entry(key).or_insert(0) += 1;
523    }
524    if counts.is_empty() {
525        return UNOWNED_GROUP_LABEL.to_string();
526    }
527    let mut best_key: Option<String> = None;
528    let mut best_count: u32 = 0;
529    for (key, count) in counts {
530        if best_key.is_none() || count > best_count {
531            best_count = count;
532            best_key = Some(key);
533        }
534    }
535    best_key.unwrap_or_else(|| UNOWNED_GROUP_LABEL.to_string())
536}
537
538/// Build grouped duplication output using caller-provided path attribution.
539#[must_use]
540pub fn build_duplication_grouping_with<F>(
541    report: &DuplicationReport,
542    mode: &'static str,
543    mut key_for_path: F,
544) -> DuplicationGrouping
545where
546    F: FnMut(&Path) -> String,
547{
548    let fingerprints = CloneFingerprintSet::from_groups(&report.clone_groups);
549    let buckets = build_attributed_clone_buckets(report, &mut key_for_path);
550    let mut groups: Vec<DuplicationGroup> = buckets
551        .into_iter()
552        .map(|(key, groups)| duplication_group(key, groups, report, &fingerprints))
553        .collect();
554    sort_duplication_groups(&mut groups);
555
556    DuplicationGrouping { mode, groups }
557}
558
559fn build_attributed_clone_buckets<F>(
560    report: &DuplicationReport,
561    key_for_path: &mut F,
562) -> BTreeMap<String, Vec<AttributedCloneGroup>>
563where
564    F: FnMut(&Path) -> String,
565{
566    let mut buckets: BTreeMap<String, Vec<AttributedCloneGroup>> = BTreeMap::new();
567    for group in &report.clone_groups {
568        let attributed = attributed_clone_group(group, key_for_path);
569        buckets
570            .entry(attributed.primary_owner.clone())
571            .or_default()
572            .push(attributed);
573    }
574    buckets
575}
576
577fn attributed_clone_group<F>(group: &CloneGroup, key_for_path: &mut F) -> AttributedCloneGroup
578where
579    F: FnMut(&Path) -> String,
580{
581    let primary_owner = largest_clone_group_owner_with(group, &mut *key_for_path);
582    let instances = group
583        .instances
584        .iter()
585        .map(|instance| AttributedInstance {
586            owner: key_for_path(&instance.file),
587            instance: instance.clone(),
588        })
589        .collect();
590    AttributedCloneGroup {
591        primary_owner,
592        token_count: group.token_count,
593        line_count: group.line_count,
594        similarity: group.similarity,
595        instances,
596    }
597}
598
599fn duplication_group(
600    key: String,
601    attributed_groups: Vec<AttributedCloneGroup>,
602    report: &DuplicationReport,
603    fingerprints: &CloneFingerprintSet,
604) -> DuplicationGroup {
605    let clone_families = clone_families_for_bucket(&attributed_groups, report, fingerprints);
606    let mut coverage = fallow_engine::duplicates::CloneCoverage::default();
607    for group in &attributed_groups {
608        coverage.add_group(
609            group
610                .instances
611                .iter()
612                .map(|attributed| &attributed.instance),
613            group.token_count,
614        );
615    }
616    // Filtering and bounded-work counters are report-scoped and cannot be
617    // attributed reliably to one grouped bucket.
618    let stats = coverage.into_stats(
619        fallow_engine::duplicates::CorpusTotals::of(&report.stats),
620        fallow_engine::duplicates::CarriedCounters {
621            clone_families: clone_families.len(),
622            ..Default::default()
623        },
624    );
625    let clone_groups = attributed_groups
626        .into_iter()
627        .map(|group| {
628            let fingerprint = group.fingerprint(fingerprints);
629            AttributedCloneGroupFinding::with_fingerprint(group, fingerprint)
630        })
631        .collect();
632
633    DuplicationGroup {
634        key,
635        stats,
636        clone_groups,
637        clone_families,
638    }
639}
640
641fn clone_families_for_bucket(
642    attributed_groups: &[AttributedCloneGroup],
643    report: &DuplicationReport,
644    fingerprints: &CloneFingerprintSet,
645) -> Vec<CloneFamilyFinding> {
646    let bucket_files: FxHashSet<&Path> = attributed_groups
647        .iter()
648        .flat_map(|group| group.instances.iter().map(|i| i.instance.file.as_path()))
649        .collect();
650
651    report
652        .clone_families
653        .iter()
654        .filter(|family| {
655            family
656                .files
657                .iter()
658                .any(|path| bucket_files.contains(path.as_path()))
659        })
660        .map(|family| CloneFamilyFinding::with_fingerprints(family.clone(), fingerprints))
661        .collect()
662}
663
664fn sort_duplication_groups(groups: &mut [DuplicationGroup]) {
665    groups.sort_by(|a, b| {
666        let a_unowned = a.key == UNOWNED_GROUP_LABEL;
667        let b_unowned = b.key == UNOWNED_GROUP_LABEL;
668        match (a_unowned, b_unowned) {
669            (true, false) => std::cmp::Ordering::Greater,
670            (false, true) => std::cmp::Ordering::Less,
671            _ => b
672                .clone_groups
673                .len()
674                .cmp(&a.clone_groups.len())
675                .then_with(|| a.key.cmp(&b.key)),
676        }
677    });
678}
679
680#[cfg(test)]
681mod tests {
682    use super::*;
683
684    /// Group by the full file path, so every finding anchor gets its own group.
685    fn group_by_path(results: &AnalysisResults) -> Vec<ResultGroup> {
686        group_analysis_results_with(
687            results,
688            |path: &Path| path.to_string_lossy().into_owned(),
689            |_: &Path| None,
690            false,
691        )
692    }
693
694    /// The length of each serialized issue list of `results`, by key.
695    fn list_lengths(results: &AnalysisResults) -> BTreeMap<String, usize> {
696        let value = serde_json::to_value(results).expect("serialize results");
697        value
698            .as_object()
699            .expect("results object")
700            .iter()
701            .filter_map(|(key, value)| value.as_array().map(|items| (key.clone(), items.len())))
702            .collect()
703    }
704
705    #[test]
706    fn every_issue_list_is_grouped() {
707        // The fixture names every field, so a new field must get a value there.
708        let source = crate::editor::tests::merge_test_source_with_all_fields();
709
710        let expected = list_lengths(&source);
711        for (key, len) in &expected {
712            assert!(
713                *len > 0,
714                "the fixture must fill `{key}` so this guard checks its grouping"
715            );
716        }
717
718        let groups = group_by_path(&source);
719        let mut grouped: BTreeMap<String, usize> = BTreeMap::new();
720        for group in &groups {
721            for (key, len) in list_lengths(&group.results) {
722                *grouped.entry(key).or_insert(0) += len;
723            }
724        }
725        for (key, len) in &expected {
726            assert_eq!(
727                grouped.get(key).copied().unwrap_or(0),
728                *len,
729                "--group-by drops `{key}` findings: add them to `GroupingBuilder`"
730            );
731        }
732
733        let grouped_total: usize = groups.iter().map(|g| g.results.total_issues()).sum();
734        assert_eq!(grouped_total, source.total_issues());
735    }
736
737    #[test]
738    fn prop_drilling_chain_without_hops_is_unowned() {
739        let mut source = crate::editor::tests::merge_test_source_with_all_fields();
740        let mut chain = source.prop_drilling_chains.remove(0);
741        chain.chain.hops.clear();
742        let mut results = AnalysisResults::default();
743        results.prop_drilling_chains.push(chain);
744
745        let groups = group_by_path(&results);
746        assert_eq!(groups.len(), 1);
747        assert_eq!(groups[0].key, UNOWNED_GROUP_LABEL);
748        assert_eq!(groups[0].results.prop_drilling_chains.len(), 1);
749    }
750
751    #[test]
752    fn health_signal_header_part_names_each_signal_type() {
753        let source = crate::editor::tests::merge_test_source_with_all_fields();
754        let mut results = AnalysisResults::default();
755        assert_eq!(health_signal_header_part(&results), "");
756
757        results
758            .prop_drilling_chains
759            .push(source.prop_drilling_chains[0].clone());
760        results.thin_wrappers.push(source.thin_wrappers[0].clone());
761        results.thin_wrappers.push(source.thin_wrappers[0].clone());
762        assert_eq!(
763            health_signal_header_part(&results),
764            "; 3 health signals: 1 prop drilling chain, 2 thin wrappers"
765        );
766
767        let mut single = AnalysisResults::default();
768        single
769            .duplicate_prop_shapes
770            .push(source.duplicate_prop_shapes[0].clone());
771        assert_eq!(
772            health_signal_header_part(&single),
773            "; 1 health signal: 1 duplicate prop shape"
774        );
775    }
776}