1#![warn(missing_docs)]
10#![cfg_attr(
11 test,
12 allow(
13 clippy::expect_used,
14 reason = "tests use expect to keep fixture setup concise"
15 )
16)]
17
18use std::path::{Path, PathBuf};
19use std::sync::Arc;
20use std::sync::atomic::AtomicBool;
21
22use fallow_config::EmailMode;
23use fallow_output::EffortEstimate;
24use serde::Serialize;
25
26mod analysis_context;
27mod audit_complexity;
28pub mod audit_keys;
32pub mod audit_output;
33pub mod audit_run;
34pub mod combined_output;
35pub mod compact_output;
38pub mod coverage;
39pub mod dead_code_codeclimate;
40pub mod dead_code_sarif;
41pub mod decision_surface;
42pub mod dependency_deltas;
43pub mod diff_risk;
44pub mod doctor;
45pub mod dupes_output;
46pub mod editor;
47pub mod explain;
48pub mod grouped_output;
49pub mod health_codeclimate;
50mod health_groups_markdown;
51pub mod json_output;
52pub mod list_output;
53mod list_runtime;
54pub mod markdown_output;
57pub mod mutation;
58mod next_steps;
59pub mod output_contracts;
60pub mod ownership;
61pub mod review_deltas;
62pub mod routing;
63pub mod runtime;
64mod runtime_json;
65mod runtime_output;
66pub mod sarif_output;
67pub mod schemas;
70pub mod security_output;
71pub mod similar_code;
73mod type_aware;
74pub use analysis_context::{ProgrammaticAnalysisContext, resolve_programmatic_analysis_context};
75pub use audit_output::{
76 AuditAttribution, AuditCodeClimateOutputInput, AuditJsonHeaderInput, AuditJsonOutputInput,
77 AuditSarifOutputInput, AuditSummary, AuditVerdict, attach_audit_diff_risk_attribution,
78 attach_audit_duplication_demotion_attribution, attach_audit_styling_attribution,
79 attach_audit_wire_attribution, build_audit_codeclimate, build_audit_codeclimate_issues,
80 build_audit_header_json, build_audit_header_map, build_audit_sarif,
81 build_diff_risk_codeclimate, build_review_brief_header, serialize_audit_json,
82};
83pub use combined_output::{
84 CombinedCheckJsonSection, CombinedJsonOutputInput, serialize_combined_dupes_json,
85 serialize_combined_health_json, serialize_combined_json,
86};
87pub use compact_output::{
88 build_compact_lines, build_diff_risk_compact_lines, build_duplication_compact_lines,
89 build_grouped_compact_lines, build_health_compact_lines,
90};
91pub use coverage::{
92 CoverageInputError, CoverageInputSource, CoverageInputs, resolve_coverage_inputs,
93};
94pub use dead_code_codeclimate::build_codeclimate;
95pub use dead_code_sarif::build_sarif;
96pub use doctor::{DoctorOptions, run_doctor, run_doctor_with_cache_dir};
97pub use dupes_output::{
98 AttributedCloneGroup, AttributedCloneGroupFinding, AttributedInstance, CloneDemotionReason,
99 CloneFamilyFinding, CloneGroupFinding, CombinedDupesSection, DupesReportPayload,
100 DuplicationGroup, DuplicationGrouping, build_duplication_codeclimate,
101};
102pub use editor::{
103 ChangedFilesError, EditorAnalysisOutput, EditorAnalysisResults, EditorAnalysisSession,
104 EditorCloneFamily, EditorCloneFingerprintSet, EditorCloneGroup, EditorCloneInstance,
105 EditorDeadCodeAnalysisOutput, EditorDuplicationReport, EditorDuplicationStats,
106 EditorInlineComplexityExceeded, EditorInlineComplexityFinding, EditorMirroredDirectory,
107 EditorProjectAnalysisOutput, EditorRefactoringKind, EditorRefactoringSuggestion,
108 EditorSessionParseCounts, collect_inline_complexity, editor_duplicates, editor_extract,
109 editor_results, editor_security, editor_suppress, filter_inline_complexity_by_change_scope,
110 filter_inline_complexity_by_changed_files, resolve_git_toplevel,
111 try_get_changed_files_with_toplevel,
112};
113pub use explain::{
114 AUDIT_RULES, CHECK_RULES, DUPES_RULES, FLAGS_RULES, HEALTH_RULES, RuleDef, RuleGuide,
115 SECURITY_RULES, all_rules, bare_rule_id, coverage_analyze_meta, coverage_setup_meta,
116 explain_issue_type, rule_by_id, rule_by_token, rule_command, rule_docs_url, rule_guide,
117 rule_severity_key, security_meta, serialize_explain_programmatic_json, unknown_explain_error,
118};
119pub use fallow_config::levenshtein::closest_match;
120pub use fallow_config::{AuditGate, AuditWorsened, HealthConfig, TypeAwareRequire};
121pub use fallow_engine::change_scope::{
124 ChangeScope, ChangeScopeOwner, ChangeScopeRequest, first_package_baselines,
125 package_baseline_statuses,
126};
127pub use fallow_engine::package_baselines::{PackageBaselineError, PackageChangeScope};
129pub use fallow_engine::thread_pool::{WORKER_STACK_SIZE, register_thread_stack};
136pub use fallow_engine::warm_parse;
142pub use fallow_output::PackageBaselineStatus;
144pub use fallow_output::serialize_similar_code_json_output;
145pub use fallow_types::trace::{
146 CloneTrace, DependencyTrace, ExportReference, ExportTrace, FileTrace, ReExportChain,
147 TracedCloneGroup, TracedExport, TracedReExport,
148};
149pub use fallow_types::trace_usage::{
150 DependencyUsage, DependencyUsageQuery, SitePageRequest, UsageQueryError,
151};
152pub use grouped_output::{
153 ResultGroup, UNOWNED_GROUP_LABEL, build_duplication_grouping_with, group_analysis_results_with,
154 health_signal_header_part, largest_clone_group_owner_with,
155};
156pub use health_codeclimate::build_health_codeclimate;
157pub use health_groups_markdown::build_health_groups_markdown;
158pub use json_output::{
159 CheckJsonExtraOutputs, CheckJsonOutputInput, CheckJsonPayloadInput, DuplicationJsonOutputInput,
160 GroupedCheckJsonOutputInput, GroupedDuplicationJsonOutputInput, serialize_check_json,
161 serialize_check_json_payload, serialize_duplication_json, serialize_grouped_check_json,
162 serialize_grouped_duplication_json,
163};
164pub use list_output::{
165 ListJsonEnvelope, ListJsonOutputInput, build_list_json_output, serialize_list_json_output,
166};
167pub use list_runtime::{
168 BoundaryData, ListBoundariesOptions, ListBoundariesProgrammaticOutput, LogicalGroupInfo,
169 ProjectInfoOptions, ProjectInfoProgrammaticOutput, RuleInfo, ZoneInfo, boundary_data_to_output,
170 compute_boundary_data, run_list_boundaries, run_project_info,
171 serialize_list_boundaries_programmatic_json, serialize_project_info_programmatic_json,
172};
173pub use markdown_output::{
174 ComplexityListing, build_diff_risk_markdown, build_duplication_markdown,
175 build_grouped_markdown, build_health_markdown, build_markdown, build_walkthrough_markdown,
176};
177pub use mutation::{
178 MutationProgress, MutationProgressSink, MutationRunOptions, MutationRunScope,
179 apply_mutation_verdicts, validate_mutation_verdicts,
180};
181pub use output_contracts::{
182 AuditOutput, BoundariesListLogicalGroup, BoundariesListRule, BoundariesListZone,
183 BoundariesListing, CombinedOutput, FallowOutput, ImpactOutput, ListBoundariesOutput,
184 ListEntryPointOutput, ListOutput, ListPluginOutput, ReviewBriefWireOutput, SecurityGate,
185 SecurityOutput, SecurityOutputConfig, SecuritySummaryOutput, SimilarCodeCandidateSnapshot,
186 SimilarCodeOutput, TraceOutput, WorkspacesOutput,
187};
188pub use runtime::TYPE_AWARE_CONFIG_UNSUPPORTED;
189pub use runtime::{
190 AUDIT_CONFIG_BASELINE_UNSUPPORTED, ArchitectureOutput, ArchitectureProgrammaticOutput,
191 AuditProgrammaticKeySnapshot, AuditProgrammaticOutput, BoundaryViolationsOutput,
192 BoundaryViolationsProgrammaticOutput, CircularDependenciesOutput,
193 CircularDependenciesProgrammaticOutput, CombinedProgrammaticOutput, DeadCodeOutput,
194 DeadCodeProgrammaticOutput, DecisionSurfaceProgrammaticOutput, DuplicationOutput,
195 DuplicationProgrammaticOutput, EngineHealthRunner, FeatureFlagsOutput,
196 FeatureFlagsProgrammaticOutput, HealthJsonReportInput, HealthProgrammaticOutput,
197 ProgrammaticHealthAnalysis, ProgrammaticHealthNextStepFacts, ProgrammaticHealthRun,
198 ProgrammaticHealthRunner, TraceClassMemberOutput, TraceCloneBenchmarkResult, TraceCloneOutput,
199 TraceCloneProgrammaticOutput, TraceDependencyOutput, TraceDependencyProgrammaticOutput,
200 TraceErrorOutput, TraceErrorProgrammaticOutput, TraceExportOutput,
201 TraceExportProgrammaticOutput, TraceExportTargetOutput, TraceFileOutput,
202 TraceFileProgrammaticOutput, TraceImportPathOutput, TraceImportPathProgrammaticOutput,
203 benchmark_trace_clone_compact_json, benchmark_trace_graph_family_compact_json,
204 inspect_similar_code, load_health_config, parse_similar_code_candidate_snapshot, plan_mutation,
205 review_similar_code, run_architecture, run_audit, run_boundary_violations,
206 run_circular_dependencies, run_combined, run_complexity_with_runner, run_dead_code,
207 run_dead_code_with_baseline, run_decision_surface, run_duplication, run_feature_flags,
208 run_health, run_health_with_runner, run_mutation, run_mutation_with_progress, run_similar_code,
209 run_trace_clone, run_trace_dependency, run_trace_error, run_trace_export, run_trace_file,
210 run_trace_import_path, select_similar_code_candidate_snapshot, serialize_health_report_json,
211};
212pub use runtime_json::{
213 serialize_architecture_programmatic_json, serialize_audit_programmatic_json,
214 serialize_boundary_violations_programmatic_json,
215 serialize_circular_dependencies_programmatic_json, serialize_combined_programmatic_json,
216 serialize_dead_code_programmatic_json, serialize_decision_surface_programmatic_json,
217 serialize_duplication_programmatic_json, serialize_feature_flags_programmatic_json,
218 serialize_health_programmatic_json, serialize_trace_clone_programmatic_json,
219 serialize_trace_dependency_programmatic_json, serialize_trace_error_programmatic_json,
220 serialize_trace_export_programmatic_json, serialize_trace_file_programmatic_json,
221 serialize_trace_import_path_programmatic_json,
222};
223pub use sarif_output::{
224 annotate_sarif_results, build_duplication_sarif, build_grouped_duplication_sarif,
225 build_health_sarif,
226};
227pub use security_output::SecurityGateMode;
228pub use type_aware::{
229 DEFAULT_BACKEND_FAMILY as DEFAULT_TYPE_AWARE_BACKEND_FAMILY, SemanticCouplingOutcome,
230 SemanticDeadCodeOutcome, SemanticInspectOutcome, TypeAwareError, TypeAwareFileChanges,
231 TypeAwareOutcome, TypeAwareSession, TypeAwareStatus, discard_unverified_semantic_candidates,
232 inspect_symbol as inspect_type_aware_symbol, merge_type_aware_meta,
233 refine_configured_dead_code_results as refine_type_aware_results_with_config,
234 shutdown_type_aware_sidecars, status as type_aware_status,
235 symbol_impact as run_type_aware_symbol_impact, symbol_impact as type_aware_symbol_impact,
236 terminate_active_type_aware_sidecars, trace_symbol as run_type_aware_symbol_trace,
237 trace_symbol as trace_type_aware_symbol, type_coupling as analyze_type_coupling,
238};
239
240pub const COMMON_ANALYSIS_OPTION_FLAGS: &[&str] = &[
247 "root",
248 "config",
249 "no-cache",
250 "threads",
251 "changed-since",
252 "diff-file",
253 "production",
254 "workspace",
255 "changed-workspaces",
256 "explain",
257 "allow-remote-extends",
258];
259
260#[derive(Debug, Clone, Serialize)]
262pub struct ProgrammaticError {
263 pub message: String,
265 pub exit_code: u8,
267 pub code: Option<String>,
269 pub help: Option<String>,
271 pub context: Option<String>,
273}
274
275impl ProgrammaticError {
276 #[must_use]
279 pub fn new(message: impl Into<String>, exit_code: u8) -> Self {
280 Self {
281 message: message.into(),
282 exit_code,
283 code: None,
284 help: None,
285 context: None,
286 }
287 }
288
289 #[must_use]
291 pub fn with_help(mut self, help: impl Into<String>) -> Self {
292 self.help = Some(help.into());
293 self
294 }
295
296 #[must_use]
299 pub fn with_code(mut self, code: impl Into<String>) -> Self {
300 self.code = Some(code.into());
301 self
302 }
303
304 #[must_use]
307 pub fn with_context(mut self, context: impl Into<String>) -> Self {
308 self.context = Some(context.into());
309 self
310 }
311}
312
313impl std::fmt::Display for ProgrammaticError {
314 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
315 write!(f, "{}", self.message)
316 }
317}
318
319impl std::error::Error for ProgrammaticError {}
320
321#[derive(Debug, Clone, Default)]
323pub struct AnalysisOptions {
324 pub root: Option<PathBuf>,
327 pub config_path: Option<PathBuf>,
329 pub allow_remote_extends: bool,
331 pub no_cache: bool,
333 pub threads: Option<usize>,
335 pub diff_file: Option<PathBuf>,
347 pub ambient_diff_file: Option<PathBuf>,
355 pub production: bool,
358 pub production_override: Option<bool>,
361 pub changed_since: Option<String>,
366 pub ambient_changed_since: Option<String>,
374 pub no_package_baselines: bool,
378 pub workspace: Option<Vec<String>>,
380 pub changed_workspaces: Option<String>,
382 pub explain: bool,
384 pub type_aware: TypeAwareOptions,
387 pub cancellation: Option<Arc<AtomicBool>>,
417}
418
419#[derive(Debug, Clone, Default, PartialEq, Eq)]
421pub struct TypeAwareOptions {
422 pub enabled: Option<bool>,
429 pub projects: Vec<PathBuf>,
432 pub require: fallow_config::TypeAwareRequire,
434}
435
436impl TypeAwareOptions {
437 #[must_use]
439 pub const fn requested(&self) -> bool {
440 matches!(self.enabled, Some(true))
441 }
442}
443
444#[derive(Debug, Clone, Default, PartialEq, Eq)]
449pub struct DeadCodeFilters {
450 pub unused_files: bool,
452 pub unused_exports: bool,
454 pub unused_deps: bool,
456 pub unused_types: bool,
458 pub private_type_leaks: bool,
460 pub deprecated_exports_in_use: bool,
462 pub unused_enum_members: bool,
464 pub unused_class_members: bool,
466 pub unused_store_members: bool,
468 pub unprovided_injects: bool,
470 pub unrendered_components: bool,
472 pub unused_component_props: bool,
474 pub absent_component_props: bool,
476 pub unused_component_emits: bool,
478 pub unused_component_inputs: bool,
480 pub unused_component_outputs: bool,
482 pub unused_svelte_events: bool,
484 pub unused_effect_layers: bool,
486 pub unused_tagged_errors: bool,
488 pub unproduced_catch_tags: bool,
490 pub unused_server_actions: bool,
492 pub unused_load_data_keys: bool,
494 pub unresolved_imports: bool,
496 pub unlisted_deps: bool,
498 pub duplicate_exports: bool,
500 pub circular_deps: bool,
502 pub re_export_cycles: bool,
504 pub package_cycles: bool,
506 pub boundary_violations: bool,
508 pub policy_violations: bool,
510 pub stale_suppressions: bool,
512 pub unused_catalog_entries: bool,
514 pub empty_catalog_groups: bool,
516 pub unresolved_catalog_references: bool,
518 pub unused_dependency_overrides: bool,
520 pub misconfigured_dependency_overrides: bool,
522}
523
524impl DeadCodeFilters {
525 pub(crate) fn reports_dependency_findings(&self) -> bool {
529 !self.any_active() || self.unused_deps || self.unlisted_deps
530 }
531
532 fn any_active(&self) -> bool {
533 self.unused_files
534 || self.unused_exports
535 || self.unused_deps
536 || self.unused_types
537 || self.private_type_leaks
538 || self.deprecated_exports_in_use
539 || self.unused_enum_members
540 || self.unused_class_members
541 || self.unused_store_members
542 || self.unprovided_injects
543 || self.unrendered_components
544 || self.unused_component_props
545 || self.absent_component_props
546 || self.unused_component_emits
547 || self.unused_component_inputs
548 || self.unused_component_outputs
549 || self.unused_svelte_events
550 || self.unused_effect_layers
551 || self.unused_tagged_errors
552 || self.unproduced_catch_tags
553 || self.unused_server_actions
554 || self.unused_load_data_keys
555 || self.unresolved_imports
556 || self.unlisted_deps
557 || self.duplicate_exports
558 || self.circular_deps
559 || self.re_export_cycles
560 || self.package_cycles
561 || self.boundary_violations
562 || self.policy_violations
563 || self.stale_suppressions
564 || self.unused_catalog_entries
565 || self.empty_catalog_groups
566 || self.unresolved_catalog_references
567 || self.unused_dependency_overrides
568 || self.misconfigured_dependency_overrides
569 }
570
571 pub fn enable_registry_selector(&mut self, selector: &str) -> bool {
577 let Some(flag) = fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS
578 .iter()
579 .find_map(|&(name, flag)| (name == selector).then_some(flag))
580 else {
581 return false;
582 };
583 self.enable_cli_filter_flag(flag);
584 true
585 }
586
587 pub(crate) fn requested_flags(&self) -> Vec<&'static str> {
589 fallow_engine::requested_rule_off::explicit_filter_flags(|flag| {
590 let mut enabled = self.clone();
591 enabled.enable_cli_filter_flag(flag);
592 enabled == *self
593 })
594 }
595
596 fn enable_cli_filter_flag(&mut self, flag: &str) {
597 match flag {
598 "--unused-files" => self.unused_files = true,
599 "--unused-exports" => self.unused_exports = true,
600 "--unused-types" => self.unused_types = true,
601 "--private-type-leaks" => self.private_type_leaks = true,
602 "--deprecated-exports-in-use" => self.deprecated_exports_in_use = true,
603 "--unused-deps" => self.unused_deps = true,
604 "--unused-enum-members" => self.unused_enum_members = true,
605 "--unused-class-members" => self.unused_class_members = true,
606 "--unused-store-members" => self.unused_store_members = true,
607 "--unprovided-injects" => self.unprovided_injects = true,
608 "--unrendered-components" => self.unrendered_components = true,
609 "--unused-component-props" => self.unused_component_props = true,
610 "--absent-component-props" => self.absent_component_props = true,
611 "--unused-component-emits" => self.unused_component_emits = true,
612 "--unused-component-inputs" => self.unused_component_inputs = true,
613 "--unused-component-outputs" => self.unused_component_outputs = true,
614 "--unused-svelte-events" => self.unused_svelte_events = true,
615 "--unused-effect-layers" => self.unused_effect_layers = true,
616 "--unused-tagged-errors" => self.unused_tagged_errors = true,
617 "--unproduced-catch-tags" => self.unproduced_catch_tags = true,
618 "--unused-server-actions" => self.unused_server_actions = true,
619 "--unused-load-data-keys" => self.unused_load_data_keys = true,
620 "--unresolved-imports" => self.unresolved_imports = true,
621 "--unlisted-deps" => self.unlisted_deps = true,
622 "--duplicate-exports" => self.duplicate_exports = true,
623 "--circular-deps" => self.circular_deps = true,
624 "--re-export-cycles" => self.re_export_cycles = true,
625 "--package-cycles" => self.package_cycles = true,
626 "--boundary-violations" => self.boundary_violations = true,
627 "--policy-violations" => self.policy_violations = true,
628 "--stale-suppressions" => self.stale_suppressions = true,
629 "--unused-catalog-entries" => self.unused_catalog_entries = true,
630 "--empty-catalog-groups" => self.empty_catalog_groups = true,
631 "--unresolved-catalog-references" => self.unresolved_catalog_references = true,
632 "--unused-dependency-overrides" => self.unused_dependency_overrides = true,
633 "--misconfigured-dependency-overrides" => {
634 self.misconfigured_dependency_overrides = true;
635 }
636 _ => unreachable!("registry emitted unsupported dead-code filter flag: {flag}"),
637 }
638 }
639}
640
641#[derive(Debug, Clone, Default)]
643pub struct DeadCodeOptions {
644 pub analysis: AnalysisOptions,
646 pub filters: DeadCodeFilters,
648 pub files: Vec<PathBuf>,
650 pub include_entry_exports: bool,
652 pub show_cascade: bool,
654 pub finding_ids: Vec<String>,
659}
660
661#[derive(Debug, Clone, Default)]
667pub struct ArchitectureOptions {
668 pub analysis: AnalysisOptions,
670 pub files: Vec<PathBuf>,
672 pub cycles: bool,
675 pub boundaries: bool,
677 pub policy: bool,
679}
680
681impl ArchitectureOptions {
682 #[must_use]
684 pub fn dead_code_filters(&self) -> DeadCodeFilters {
685 let all = !(self.cycles || self.boundaries || self.policy);
686 DeadCodeFilters {
687 circular_deps: self.cycles || all,
688 re_export_cycles: self.cycles || all,
689 package_cycles: self.cycles || all,
690 boundary_violations: self.boundaries || all,
691 policy_violations: self.policy || all,
692 ..DeadCodeFilters::default()
693 }
694 }
695
696 pub(crate) fn requested_flags(&self) -> Vec<&'static str> {
699 fallow_engine::requested_rule_off::architecture_requested_flags(
700 self.cycles,
701 self.boundaries,
702 self.policy,
703 )
704 }
705
706 #[must_use]
708 pub fn dead_code_options(&self) -> DeadCodeOptions {
709 DeadCodeOptions {
710 analysis: self.analysis.clone(),
711 filters: self.dead_code_filters(),
712 files: self.files.clone(),
713 include_entry_exports: false,
714 show_cascade: false,
715 finding_ids: Vec::new(),
716 }
717 }
718}
719
720#[derive(Debug, Clone, Default)]
722pub struct AuditOptions {
723 pub analysis: AnalysisOptions,
725 pub base: Option<String>,
728 pub production: bool,
730 pub production_dead_code: Option<bool>,
732 pub production_health: Option<bool>,
734 pub production_dupes: Option<bool>,
737 pub dead_code: Option<bool>,
741 pub health: Option<bool>,
744 pub duplication: Option<bool>,
747 pub css: Option<bool>,
750 pub css_deep: Option<bool>,
753 pub gate: Option<fallow_config::AuditGate>,
756 pub worsened: Option<fallow_config::AuditWorsened>,
759 pub max_crap: Option<f64>,
761 pub coverage: Option<PathBuf>,
763 pub coverage_root: Option<PathBuf>,
765 pub include_entry_exports: bool,
767 pub show_cascade: bool,
769 pub runtime_coverage: Option<PathBuf>,
771 pub min_invocations_hot: u64,
773}
774
775#[derive(Debug, Clone)]
777pub struct CombinedOptions {
778 pub analysis: AnalysisOptions,
780 pub dead_code: bool,
782 pub duplication: bool,
784 pub health: bool,
786 pub include_entry_exports: bool,
788 pub show_cascade: bool,
790 pub duplication_options: DuplicationOptions,
792 pub health_options: ComplexityOptions,
794}
795
796impl Default for CombinedOptions {
797 fn default() -> Self {
798 Self {
799 analysis: AnalysisOptions::default(),
800 dead_code: true,
801 duplication: true,
802 health: true,
803 include_entry_exports: false,
804 show_cascade: false,
805 duplication_options: DuplicationOptions::default(),
806 health_options: ComplexityOptions::default(),
807 }
808 }
809}
810
811#[derive(Debug, Clone, Default)]
813pub struct DecisionSurfaceOptions {
814 pub analysis: AnalysisOptions,
816 pub base: Option<String>,
819 pub max_decisions: Option<usize>,
821}
822
823#[derive(Debug, Clone, Default)]
825pub struct FeatureFlagsOptions {
826 pub analysis: AnalysisOptions,
828 pub top: Option<usize>,
831 pub retirement: Option<FeatureFlagsRetirementOptions>,
833}
834
835#[derive(Debug, Clone, Default)]
838pub struct FeatureFlagsRetirementOptions {
839 pub flag_age: fallow_types::flag_retirement::FlagAgeMode,
841 pub flag_state: Option<std::path::PathBuf>,
843 pub reasons: Vec<fallow_types::flag_retirement::RetirementReason>,
845 pub sort: fallow_engine::flag_retirement::RetirementSort,
847 pub min_age_days: Option<u64>,
849 pub max_flag_age: Option<u64>,
851}
852
853#[derive(Debug, Clone, Copy, Default)]
855pub enum DuplicationMode {
856 Strict,
859 #[default]
861 Mild,
862 Weak,
864 Semantic,
867}
868
869#[derive(Debug, Clone, Default)]
871pub struct DuplicationOptions {
872 pub analysis: AnalysisOptions,
874 pub mode: Option<DuplicationMode>,
876 pub near: Option<bool>,
879 pub min_tokens: Option<usize>,
881 pub min_lines: Option<usize>,
883 pub min_occurrences: Option<usize>,
886 pub threshold: Option<f64>,
889 pub skip_local: Option<bool>,
892 pub ignore_symlinks: Option<bool>,
895 pub cross_language: Option<bool>,
897 pub ignore_imports: Option<bool>,
900 pub top: Option<usize>,
902 pub include_fragments: Option<bool>,
906}
907
908#[derive(Debug, Clone, Default)]
910pub struct SimilarCodeOptions {
911 pub analysis: AnalysisOptions,
913 pub threshold: Option<f64>,
915 pub min_lines: Option<usize>,
918 pub top: Option<usize>,
920 pub files: Vec<PathBuf>,
924 #[doc(hidden)]
929 pub adapter_provider_path: Option<PathBuf>,
930}
931
932#[derive(Debug, Clone)]
934pub struct SimilarCodeInspectOptions {
935 pub analysis: AnalysisOptions,
938 pub snapshot: fallow_output::SimilarCodeCandidateSnapshot,
940}
941
942#[derive(Debug, Clone, Default)]
944pub struct TraceExportOptions {
945 pub analysis: AnalysisOptions,
947 pub file: String,
949 pub export_name: String,
951}
952
953#[derive(Debug, Clone, Default)]
955pub struct TraceFileOptions {
956 pub analysis: AnalysisOptions,
958 pub file: String,
960}
961
962#[derive(Debug, Clone, Default)]
964pub struct TraceImportPathOptions {
965 pub analysis: AnalysisOptions,
967 pub from: String,
969 pub to: String,
971 pub eager_only: bool,
974}
975
976#[derive(Debug, Clone, Default)]
978pub struct TraceErrorOptions {
979 pub analysis: AnalysisOptions,
981 pub trace: String,
983 pub source: String,
985}
986
987#[derive(Debug, Clone, Default)]
989pub struct TraceDependencyOptions {
990 pub analysis: AnalysisOptions,
992 pub package_name: String,
994 pub usage: Option<DependencyUsageQuery>,
997}
998
999#[derive(Debug, Clone, PartialEq, Eq)]
1001pub enum TraceCloneTarget {
1002 Location {
1004 file: String,
1006 line: usize,
1008 },
1009 Fingerprint(String),
1011}
1012
1013#[derive(Debug, Clone)]
1015pub struct TraceCloneOptions {
1016 pub duplication: DuplicationOptions,
1018 pub target: TraceCloneTarget,
1020}
1021
1022#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1024pub enum ComplexitySort {
1025 #[default]
1027 Cyclomatic,
1028 Cognitive,
1030 Lines,
1032 Severity,
1034}
1035
1036#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1038pub enum OwnershipEmailMode {
1039 Raw,
1041 #[default]
1043 Handle,
1044 Anonymized,
1046 Hash,
1048}
1049
1050#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1052pub enum TargetEffort {
1053 Low,
1055 Medium,
1057 High,
1059}
1060
1061#[derive(Debug, Clone, Default)]
1063pub struct ComplexityOptions {
1064 pub analysis: AnalysisOptions,
1066 pub max_cyclomatic: Option<u16>,
1068 pub max_cognitive: Option<u16>,
1070 pub max_crap: Option<f64>,
1072 pub max_file_lines: Option<u32>,
1075 pub top: Option<usize>,
1077 pub sort: ComplexitySort,
1079 pub complexity_breakdown: bool,
1081 pub complexity: bool,
1083 pub file_scores: bool,
1085 pub coverage_gaps: bool,
1087 pub hotspots: bool,
1089 pub ownership: bool,
1091 pub ownership_emails: Option<OwnershipEmailMode>,
1093 pub targets: bool,
1095 pub css: bool,
1097 pub css_deep: bool,
1099 pub effort: Option<TargetEffort>,
1102 pub score: bool,
1104 pub since: Option<String>,
1106 pub min_commits: Option<u32>,
1108 pub coverage: Option<PathBuf>,
1110 pub coverage_root: Option<PathBuf>,
1112 pub coverage_relocated: bool,
1117}
1118
1119#[derive(Debug, Clone, Copy, Default, PartialEq)]
1121pub struct ComplexityThresholdOverrides {
1122 pub max_cyclomatic: Option<u16>,
1124 pub max_cognitive: Option<u16>,
1126 pub max_crap: Option<f64>,
1128 pub max_file_lines: Option<u32>,
1130}
1131
1132#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1134pub struct ComplexityCoverageInputs<'a> {
1135 pub coverage: Option<&'a Path>,
1137 pub coverage_root: Option<&'a Path>,
1139 pub coverage_relocated: bool,
1142}
1143
1144#[derive(Debug, Clone)]
1146pub struct HealthSectionOptions {
1147 pub output: fallow_types::output_format::OutputFormat,
1149 pub complexity: bool,
1151 pub file_scores: bool,
1153 pub coverage_gaps: bool,
1155 pub hotspots: bool,
1157 pub targets: bool,
1159 pub css: bool,
1161 pub score: bool,
1163 pub score_gate: bool,
1165 pub snapshot_requested: bool,
1167 pub trend: bool,
1169}
1170
1171#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1173pub struct DerivedHealthSections {
1174 pub any_section: bool,
1176 pub complexity: bool,
1178 pub file_scores: bool,
1180 pub coverage_gaps: bool,
1182 pub hotspots: bool,
1184 pub targets: bool,
1186 pub css: bool,
1188 pub score: bool,
1190 pub force_full: bool,
1192 pub score_only_output: bool,
1194}
1195
1196#[derive(Debug, Clone)]
1198pub struct ComplexitySectionOptions {
1199 pub complexity: bool,
1201 pub file_scores: bool,
1203 pub coverage_gaps: bool,
1205 pub hotspots: bool,
1207 pub ownership: bool,
1209 pub targets: bool,
1211 pub css: bool,
1213 pub score: bool,
1215}
1216
1217#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1219pub struct DerivedComplexityOptions {
1220 pub any_section: bool,
1222 pub complexity: bool,
1224 pub file_scores: bool,
1226 pub coverage_gaps: bool,
1228 pub hotspots: bool,
1230 pub ownership: bool,
1232 pub targets: bool,
1234 pub force_full: bool,
1236 pub score_only_output: bool,
1238 pub score: bool,
1240}
1241
1242#[derive(Debug, Clone, PartialEq)]
1244pub struct ComplexityRunOptions<'a> {
1245 pub thresholds: ComplexityThresholdOverrides,
1247 pub top: Option<usize>,
1249 pub sort: ComplexitySort,
1251 pub complexity_breakdown: bool,
1253 pub sections: DerivedComplexityOptions,
1255 pub ownership_emails: Option<OwnershipEmailMode>,
1257 pub effort: Option<TargetEffort>,
1259 pub css: bool,
1261 pub css_deep: bool,
1263 pub since: Option<&'a str>,
1265 pub min_commits: Option<u32>,
1267 pub coverage_inputs: ComplexityCoverageInputs<'a>,
1269}
1270
1271pub fn configure_global_analysis_pool(threads: usize) -> bool {
1280 fallow_engine::thread_pool::worker_pool_builder(threads)
1281 .build_global()
1282 .is_ok()
1283}
1284
1285#[must_use]
1287pub fn derive_health_sections(options: &HealthSectionOptions) -> DerivedHealthSections {
1288 let score = options.score
1289 || options.score_gate
1290 || options.trend
1291 || matches!(
1292 options.output,
1293 fallow_types::output_format::OutputFormat::Badge
1294 );
1295 let any_section = options.complexity
1296 || options.file_scores
1297 || options.coverage_gaps
1298 || options.hotspots
1299 || options.targets
1300 || score;
1301 let effective_score = if any_section { score } else { true } || options.snapshot_requested;
1302 let force_full = options.snapshot_requested || effective_score;
1303
1304 DerivedHealthSections {
1305 any_section,
1306 complexity: if any_section {
1307 options.complexity
1308 } else {
1309 true
1310 },
1311 file_scores: if any_section {
1312 options.file_scores
1313 } else {
1314 true
1315 } || force_full,
1316 coverage_gaps: if any_section {
1317 options.coverage_gaps
1318 } else {
1319 false
1320 },
1321 hotspots: if any_section { options.hotspots } else { true }
1322 || options.snapshot_requested
1323 || options.trend,
1324 targets: if any_section { options.targets } else { true },
1325 css: options.css,
1326 score: effective_score,
1327 force_full,
1328 score_only_output: is_health_score_only_output(options, score),
1329 }
1330}
1331
1332#[must_use]
1334pub fn derive_complexity_sections(options: &ComplexitySectionOptions) -> DerivedComplexityOptions {
1335 let requested_hotspots = options.hotspots || options.ownership;
1336 let sections = derive_health_sections(&HealthSectionOptions {
1337 output: fallow_types::output_format::OutputFormat::Human,
1338 complexity: options.complexity,
1339 file_scores: options.file_scores,
1340 coverage_gaps: options.coverage_gaps,
1341 hotspots: requested_hotspots,
1342 targets: options.targets,
1343 css: options.css,
1344 score: options.score,
1345 score_gate: false,
1346 snapshot_requested: false,
1347 trend: false,
1348 });
1349
1350 DerivedComplexityOptions {
1351 any_section: sections.any_section,
1352 complexity: sections.complexity,
1353 file_scores: sections.file_scores,
1354 coverage_gaps: sections.coverage_gaps,
1355 hotspots: sections.hotspots,
1356 ownership: options.ownership && sections.hotspots,
1357 targets: sections.targets,
1358 force_full: sections.force_full,
1359 score_only_output: sections.score_only_output,
1360 score: sections.score,
1361 }
1362}
1363
1364#[must_use]
1366pub fn derive_complexity_options(options: &ComplexityOptions) -> DerivedComplexityOptions {
1367 derive_complexity_sections(&complexity_section_options(options))
1368}
1369
1370#[must_use]
1372pub fn derive_complexity_run_options(options: &ComplexityOptions) -> ComplexityRunOptions<'_> {
1373 ComplexityRunOptions {
1374 thresholds: ComplexityThresholdOverrides {
1375 max_cyclomatic: options.max_cyclomatic,
1376 max_cognitive: options.max_cognitive,
1377 max_crap: options.max_crap,
1378 max_file_lines: options.max_file_lines,
1379 },
1380 top: options.top,
1381 sort: options.sort,
1382 complexity_breakdown: options.complexity_breakdown,
1383 sections: derive_complexity_options(options),
1384 ownership_emails: options.ownership_emails,
1385 effort: options.effort,
1386 css: options.css,
1387 css_deep: options.css_deep,
1388 since: options.since.as_deref(),
1389 min_commits: options.min_commits,
1390 coverage_inputs: ComplexityCoverageInputs {
1391 coverage: options.coverage.as_deref(),
1392 coverage_root: options.coverage_root.as_deref(),
1393 coverage_relocated: options.coverage_relocated,
1394 },
1395 }
1396}
1397
1398pub fn validate_complexity_options(options: &ComplexityOptions) -> Result<(), ProgrammaticError> {
1421 if let Some(path) = &options.coverage {
1422 let resolved = fallow_engine::health::scoring::resolve_relative_to_root(
1423 path,
1424 options.analysis.root.as_deref(),
1425 );
1426 if !resolved.exists() {
1427 return Err(ProgrammaticError::new(
1428 format!("coverage path does not exist: {}", resolved.display()),
1429 2,
1430 )
1431 .with_code("FALLOW_INVALID_COVERAGE_PATH")
1432 .with_context("health.coverage"));
1433 }
1434 }
1435 if let Err(message) =
1436 fallow_engine::health::validate_coverage_root_absolute(options.coverage_root.as_deref())
1437 {
1438 return Err(ProgrammaticError::new(message, 2)
1439 .with_code("FALLOW_INVALID_COVERAGE_ROOT")
1440 .with_context("health.coverage_root"));
1441 }
1442
1443 Ok(())
1444}
1445
1446fn complexity_section_options(options: &ComplexityOptions) -> ComplexitySectionOptions {
1447 let ownership = options.ownership || options.ownership_emails.is_some();
1448 let requested_targets = options.targets || options.effort.is_some();
1449 ComplexitySectionOptions {
1450 complexity: options.complexity,
1451 file_scores: options.file_scores,
1452 coverage_gaps: options.coverage_gaps,
1453 hotspots: options.hotspots,
1454 ownership,
1455 targets: requested_targets,
1456 css: options.css,
1457 score: options.score,
1458 }
1459}
1460
1461fn is_health_score_only_output(options: &HealthSectionOptions, score: bool) -> bool {
1462 score
1463 && !options.complexity
1464 && !options.file_scores
1465 && !options.coverage_gaps
1466 && !options.hotspots
1467 && !options.targets
1468 && !options.trend
1469}
1470
1471const fn thresholds_to_engine(
1472 thresholds: ComplexityThresholdOverrides,
1473) -> fallow_engine::health::HealthThresholdOverrides {
1474 fallow_engine::health::HealthThresholdOverrides {
1475 max_cyclomatic: thresholds.max_cyclomatic,
1476 max_cognitive: thresholds.max_cognitive,
1477 max_crap: thresholds.max_crap,
1478 max_file_lines: thresholds.max_file_lines,
1479 }
1480}
1481
1482const fn complexity_sort_to_engine(sort: ComplexitySort) -> fallow_engine::health::HealthSort {
1483 match sort {
1484 ComplexitySort::Severity => fallow_engine::health::HealthSort::Severity,
1485 ComplexitySort::Cyclomatic => fallow_engine::health::HealthSort::Cyclomatic,
1486 ComplexitySort::Cognitive => fallow_engine::health::HealthSort::Cognitive,
1487 ComplexitySort::Lines => fallow_engine::health::HealthSort::Lines,
1488 }
1489}
1490
1491const fn coverage_inputs_to_engine(
1492 coverage_inputs: ComplexityCoverageInputs<'_>,
1493) -> fallow_engine::health::HealthCoverageInputs<'_> {
1494 fallow_engine::health::HealthCoverageInputs {
1495 coverage: coverage_inputs.coverage,
1496 coverage_root: coverage_inputs.coverage_root,
1497 coverage_relocated: coverage_inputs.coverage_relocated,
1498 }
1499}
1500
1501const fn ownership_email_mode_to_config(mode: OwnershipEmailMode) -> EmailMode {
1502 match mode {
1503 OwnershipEmailMode::Raw => EmailMode::Raw,
1504 OwnershipEmailMode::Handle => EmailMode::Handle,
1505 OwnershipEmailMode::Anonymized => EmailMode::Anonymized,
1506 OwnershipEmailMode::Hash => EmailMode::Hash,
1507 }
1508}
1509
1510const fn target_effort_to_output(effort: TargetEffort) -> EffortEstimate {
1511 match effort {
1512 TargetEffort::Low => EffortEstimate::Low,
1513 TargetEffort::Medium => EffortEstimate::Medium,
1514 TargetEffort::High => EffortEstimate::High,
1515 }
1516}
1517
1518#[cfg(test)]
1519mod tests {
1520 use super::*;
1521
1522 #[test]
1523 fn duplication_defaults_match_cli_contract() {
1524 let options = DuplicationOptions::default();
1525 assert!(options.mode.is_none());
1526 assert!(options.min_tokens.is_none());
1527 assert!(options.min_lines.is_none());
1528 assert!(options.min_occurrences.is_none());
1529 }
1530
1531 #[test]
1532 fn programmatic_error_builder_keeps_optional_fields() {
1533 let error = ProgrammaticError::new("boom", 2)
1534 .with_code("FALLOW_TEST")
1535 .with_help("Try again")
1536 .with_context("analysis.root");
1537
1538 assert_eq!(error.message, "boom");
1539 assert_eq!(error.exit_code, 2);
1540 assert_eq!(error.code.as_deref(), Some("FALLOW_TEST"));
1541 assert_eq!(error.help.as_deref(), Some("Try again"));
1542 assert_eq!(error.context.as_deref(), Some("analysis.root"));
1543 }
1544
1545 #[test]
1546 fn dead_code_filters_accept_shared_registry_selectors() {
1547 for (selector, _) in fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS.iter() {
1548 let mut filters = DeadCodeFilters::default();
1549 assert!(
1550 filters.enable_registry_selector(selector),
1551 "{selector} should be accepted"
1552 );
1553 }
1554
1555 let mut filters = DeadCodeFilters::default();
1556 assert!(filters.enable_registry_selector("unused-files"));
1557 assert!(filters.unused_files);
1558 assert!(filters.enable_registry_selector("boundary-violations"));
1559 assert!(filters.boundary_violations);
1560 assert!(!filters.enable_registry_selector("not-a-real-selector"));
1561 }
1562
1563 #[test]
1564 fn default_complexity_options_match_programmatic_health_defaults() {
1565 let derived = derive_complexity_options(&ComplexityOptions::default());
1566
1567 assert!(!derived.any_section);
1568 assert!(derived.complexity);
1569 assert!(derived.file_scores);
1570 assert!(!derived.coverage_gaps);
1571 assert!(derived.hotspots);
1572 assert!(!derived.ownership);
1573 assert!(derived.targets);
1574 assert!(derived.force_full);
1575 assert!(!derived.score_only_output);
1576 assert!(derived.score);
1577 }
1578
1579 #[test]
1580 fn score_only_complexity_options_request_score_only_output() {
1581 let derived = derive_complexity_options(&ComplexityOptions {
1582 score: true,
1583 ..ComplexityOptions::default()
1584 });
1585
1586 assert!(derived.any_section);
1587 assert!(!derived.complexity);
1588 assert!(derived.file_scores);
1589 assert!(!derived.hotspots);
1590 assert!(!derived.targets);
1591 assert!(derived.force_full);
1592 assert!(derived.score_only_output);
1593 assert!(derived.score);
1594 }
1595
1596 #[test]
1597 fn ownership_implies_hotspots_when_requested() {
1598 let derived = derive_complexity_options(&ComplexityOptions {
1599 ownership: true,
1600 ..ComplexityOptions::default()
1601 });
1602
1603 assert!(derived.any_section);
1604 assert!(derived.hotspots);
1605 assert!(derived.ownership);
1606 assert!(!derived.targets);
1607 }
1608
1609 #[test]
1610 fn complexity_run_options_normalize_public_api_options() {
1611 let options = ComplexityOptions {
1612 max_cyclomatic: Some(42),
1613 max_cognitive: Some(21),
1614 max_crap: Some(18.5),
1615 top: Some(7),
1616 sort: ComplexitySort::Severity,
1617 complexity_breakdown: true,
1618 ownership_emails: Some(OwnershipEmailMode::Hash),
1619 effort: Some(TargetEffort::High),
1620 coverage: Some(PathBuf::from("coverage/coverage-final.json")),
1621 coverage_root: Some(PathBuf::from("/ci/workspace")),
1622 since: Some("30d".to_string()),
1623 min_commits: Some(4),
1624 ..ComplexityOptions::default()
1625 };
1626
1627 let run = derive_complexity_run_options(&options);
1628
1629 assert_eq!(run.thresholds.max_cyclomatic, Some(42));
1630 assert_eq!(run.thresholds.max_cognitive, Some(21));
1631 assert_eq!(run.thresholds.max_crap, Some(18.5));
1632 assert_eq!(run.top, Some(7));
1633 assert!(matches!(run.sort, ComplexitySort::Severity));
1634 assert!(run.complexity_breakdown);
1635 assert!(run.sections.hotspots);
1636 assert!(run.sections.ownership);
1637 assert!(run.sections.targets);
1638 assert!(matches!(
1639 run.ownership_emails,
1640 Some(OwnershipEmailMode::Hash)
1641 ));
1642 assert!(matches!(run.effort, Some(TargetEffort::High)));
1643 assert_eq!(run.since, Some("30d"));
1644 assert_eq!(run.min_commits, Some(4));
1645 assert_eq!(run.coverage_inputs.coverage, options.coverage.as_deref());
1646 assert_eq!(
1647 run.coverage_inputs.coverage_root,
1648 options.coverage_root.as_deref()
1649 );
1650 }
1651
1652 #[test]
1653 fn complexity_options_validation_accepts_existing_coverage_path_and_absolute_root() {
1654 let dir = tempfile::tempdir().expect("tempdir");
1655 let coverage = dir.path().join("coverage-final.json");
1656 std::fs::write(&coverage, "{}").expect("coverage fixture");
1657
1658 let result = validate_complexity_options(&ComplexityOptions {
1659 coverage: Some(coverage),
1660 coverage_root: Some(PathBuf::from("/ci/workspace")),
1661 ..ComplexityOptions::default()
1662 });
1663
1664 assert!(result.is_ok());
1665 }
1666
1667 #[test]
1668 fn complexity_options_validation_keeps_missing_coverage_error_contract() {
1669 let err = validate_complexity_options(&ComplexityOptions {
1670 coverage: Some(PathBuf::from("/missing/coverage-final.json")),
1671 ..ComplexityOptions::default()
1672 })
1673 .expect_err("missing coverage path should fail");
1674
1675 assert_eq!(err.exit_code, 2);
1676 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1677 assert_eq!(err.context.as_deref(), Some("health.coverage"));
1678 }
1679
1680 #[test]
1681 fn complexity_options_validation_keeps_relative_coverage_root_error_contract() {
1682 let err = validate_complexity_options(&ComplexityOptions {
1683 coverage_root: Some(PathBuf::from("coverage")),
1684 ..ComplexityOptions::default()
1685 })
1686 .expect_err("relative coverage root should fail");
1687
1688 assert_eq!(err.exit_code, 2);
1689 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_ROOT"));
1690 assert_eq!(err.context.as_deref(), Some("health.coverage_root"));
1691 }
1692
1693 #[test]
1697 fn complexity_options_validation_resolves_relative_coverage_against_root() {
1698 let dir = tempfile::tempdir().expect("tempdir");
1699 std::fs::create_dir_all(dir.path().join("artifacts")).expect("artifacts dir");
1700 std::fs::write(dir.path().join("artifacts/coverage-final.json"), "{}")
1701 .expect("coverage fixture");
1702 let relative = PathBuf::from("artifacts/coverage-final.json");
1703 assert!(
1704 !relative.exists(),
1705 "the fixture must not also exist under the test cwd"
1706 );
1707
1708 let result = validate_complexity_options(&ComplexityOptions {
1709 analysis: AnalysisOptions {
1710 root: Some(dir.path().to_path_buf()),
1711 ..AnalysisOptions::default()
1712 },
1713 coverage: Some(relative.clone()),
1714 ..ComplexityOptions::default()
1715 });
1716 assert!(result.is_ok(), "{result:?}");
1717
1718 let err = validate_complexity_options(&ComplexityOptions {
1719 analysis: AnalysisOptions {
1720 root: Some(dir.path().join("elsewhere")),
1721 ..AnalysisOptions::default()
1722 },
1723 coverage: Some(relative),
1724 ..ComplexityOptions::default()
1725 })
1726 .expect_err("the path does not exist under the other root");
1727 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1728 assert!(
1729 err.message.contains("elsewhere"),
1730 "the message names the resolved path: {}",
1731 err.message
1732 );
1733 }
1734
1735 #[test]
1736 fn default_health_sections_match_full_health_output() {
1737 let derived = derive_health_sections(&HealthSectionOptions {
1738 output: fallow_types::output_format::OutputFormat::Human,
1739 complexity: false,
1740 file_scores: false,
1741 coverage_gaps: false,
1742 hotspots: false,
1743 targets: false,
1744 css: false,
1745 score: false,
1746 score_gate: false,
1747 snapshot_requested: false,
1748 trend: false,
1749 });
1750
1751 assert!(!derived.any_section);
1752 assert!(derived.complexity);
1753 assert!(derived.file_scores);
1754 assert!(!derived.coverage_gaps);
1755 assert!(derived.hotspots);
1756 assert!(derived.targets);
1757 assert!(derived.score);
1758 assert!(derived.force_full);
1759 assert!(!derived.score_only_output);
1760 }
1761
1762 #[test]
1763 fn health_score_gate_requests_score_only_output() {
1764 let derived = derive_health_sections(&HealthSectionOptions {
1765 output: fallow_types::output_format::OutputFormat::Human,
1766 complexity: false,
1767 file_scores: false,
1768 coverage_gaps: false,
1769 hotspots: false,
1770 targets: false,
1771 css: false,
1772 score: false,
1773 score_gate: true,
1774 snapshot_requested: false,
1775 trend: false,
1776 });
1777
1778 assert!(derived.any_section);
1779 assert!(!derived.complexity);
1780 assert!(derived.file_scores);
1781 assert!(!derived.hotspots);
1782 assert!(!derived.targets);
1783 assert!(derived.score);
1784 assert!(derived.force_full);
1785 assert!(derived.score_only_output);
1786 }
1787
1788 #[test]
1789 fn health_snapshot_keeps_full_hidden_inputs_without_section_request() {
1790 let derived = derive_health_sections(&HealthSectionOptions {
1791 output: fallow_types::output_format::OutputFormat::Human,
1792 complexity: false,
1793 file_scores: false,
1794 coverage_gaps: false,
1795 hotspots: false,
1796 targets: false,
1797 css: true,
1798 score: false,
1799 score_gate: false,
1800 snapshot_requested: true,
1801 trend: false,
1802 });
1803
1804 assert!(!derived.any_section);
1805 assert!(derived.css);
1806 assert!(derived.file_scores);
1807 assert!(derived.hotspots);
1808 assert!(derived.score);
1809 assert!(derived.force_full);
1810 }
1811}