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 SemanticCouplingOutcome, SemanticDeadCodeOutcome, SemanticInspectOutcome, TypeAwareError,
230 TypeAwareFileChanges, TypeAwareOutcome, TypeAwareSession, TypeAwareStatus,
231 discard_unverified_semantic_candidates, inspect_symbol as inspect_type_aware_symbol,
232 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)]
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 fn enable_cli_filter_flag(&mut self, flag: &str) {
588 match flag {
589 "--unused-files" => self.unused_files = true,
590 "--unused-exports" => self.unused_exports = true,
591 "--unused-types" => self.unused_types = true,
592 "--private-type-leaks" => self.private_type_leaks = true,
593 "--deprecated-exports-in-use" => self.deprecated_exports_in_use = true,
594 "--unused-deps" => self.unused_deps = true,
595 "--unused-enum-members" => self.unused_enum_members = true,
596 "--unused-class-members" => self.unused_class_members = true,
597 "--unused-store-members" => self.unused_store_members = true,
598 "--unprovided-injects" => self.unprovided_injects = true,
599 "--unrendered-components" => self.unrendered_components = true,
600 "--unused-component-props" => self.unused_component_props = true,
601 "--absent-component-props" => self.absent_component_props = true,
602 "--unused-component-emits" => self.unused_component_emits = true,
603 "--unused-component-inputs" => self.unused_component_inputs = true,
604 "--unused-component-outputs" => self.unused_component_outputs = true,
605 "--unused-svelte-events" => self.unused_svelte_events = true,
606 "--unused-effect-layers" => self.unused_effect_layers = true,
607 "--unused-tagged-errors" => self.unused_tagged_errors = true,
608 "--unproduced-catch-tags" => self.unproduced_catch_tags = true,
609 "--unused-server-actions" => self.unused_server_actions = true,
610 "--unused-load-data-keys" => self.unused_load_data_keys = true,
611 "--unresolved-imports" => self.unresolved_imports = true,
612 "--unlisted-deps" => self.unlisted_deps = true,
613 "--duplicate-exports" => self.duplicate_exports = true,
614 "--circular-deps" => self.circular_deps = true,
615 "--re-export-cycles" => self.re_export_cycles = true,
616 "--package-cycles" => self.package_cycles = true,
617 "--boundary-violations" => self.boundary_violations = true,
618 "--policy-violations" => self.policy_violations = true,
619 "--stale-suppressions" => self.stale_suppressions = true,
620 "--unused-catalog-entries" => self.unused_catalog_entries = true,
621 "--empty-catalog-groups" => self.empty_catalog_groups = true,
622 "--unresolved-catalog-references" => self.unresolved_catalog_references = true,
623 "--unused-dependency-overrides" => self.unused_dependency_overrides = true,
624 "--misconfigured-dependency-overrides" => {
625 self.misconfigured_dependency_overrides = true;
626 }
627 _ => unreachable!("registry emitted unsupported dead-code filter flag: {flag}"),
628 }
629 }
630}
631
632#[derive(Debug, Clone, Default)]
634pub struct DeadCodeOptions {
635 pub analysis: AnalysisOptions,
637 pub filters: DeadCodeFilters,
639 pub files: Vec<PathBuf>,
641 pub include_entry_exports: bool,
643 pub show_cascade: bool,
645 pub finding_ids: Vec<String>,
650}
651
652#[derive(Debug, Clone, Default)]
658pub struct ArchitectureOptions {
659 pub analysis: AnalysisOptions,
661 pub files: Vec<PathBuf>,
663 pub cycles: bool,
666 pub boundaries: bool,
668 pub policy: bool,
670}
671
672impl ArchitectureOptions {
673 #[must_use]
675 pub fn dead_code_filters(&self) -> DeadCodeFilters {
676 let all = !(self.cycles || self.boundaries || self.policy);
677 DeadCodeFilters {
678 circular_deps: self.cycles || all,
679 re_export_cycles: self.cycles || all,
680 package_cycles: self.cycles || all,
681 boundary_violations: self.boundaries || all,
682 policy_violations: self.policy || all,
683 ..DeadCodeFilters::default()
684 }
685 }
686
687 #[must_use]
689 pub fn dead_code_options(&self) -> DeadCodeOptions {
690 DeadCodeOptions {
691 analysis: self.analysis.clone(),
692 filters: self.dead_code_filters(),
693 files: self.files.clone(),
694 include_entry_exports: false,
695 show_cascade: false,
696 finding_ids: Vec::new(),
697 }
698 }
699}
700
701#[derive(Debug, Clone, Default)]
703pub struct AuditOptions {
704 pub analysis: AnalysisOptions,
706 pub base: Option<String>,
709 pub production: bool,
711 pub production_dead_code: Option<bool>,
713 pub production_health: Option<bool>,
715 pub production_dupes: Option<bool>,
718 pub dead_code: Option<bool>,
722 pub health: Option<bool>,
725 pub duplication: Option<bool>,
728 pub css: Option<bool>,
731 pub css_deep: Option<bool>,
734 pub gate: Option<fallow_config::AuditGate>,
737 pub worsened: Option<fallow_config::AuditWorsened>,
740 pub max_crap: Option<f64>,
742 pub coverage: Option<PathBuf>,
744 pub coverage_root: Option<PathBuf>,
746 pub include_entry_exports: bool,
748 pub show_cascade: bool,
750 pub runtime_coverage: Option<PathBuf>,
752 pub min_invocations_hot: u64,
754}
755
756#[derive(Debug, Clone)]
758pub struct CombinedOptions {
759 pub analysis: AnalysisOptions,
761 pub dead_code: bool,
763 pub duplication: bool,
765 pub health: bool,
767 pub include_entry_exports: bool,
769 pub show_cascade: bool,
771 pub duplication_options: DuplicationOptions,
773 pub health_options: ComplexityOptions,
775}
776
777impl Default for CombinedOptions {
778 fn default() -> Self {
779 Self {
780 analysis: AnalysisOptions::default(),
781 dead_code: true,
782 duplication: true,
783 health: true,
784 include_entry_exports: false,
785 show_cascade: false,
786 duplication_options: DuplicationOptions::default(),
787 health_options: ComplexityOptions::default(),
788 }
789 }
790}
791
792#[derive(Debug, Clone, Default)]
794pub struct DecisionSurfaceOptions {
795 pub analysis: AnalysisOptions,
797 pub base: Option<String>,
800 pub max_decisions: Option<usize>,
802}
803
804#[derive(Debug, Clone, Default)]
806pub struct FeatureFlagsOptions {
807 pub analysis: AnalysisOptions,
809 pub top: Option<usize>,
812 pub retirement: Option<FeatureFlagsRetirementOptions>,
814}
815
816#[derive(Debug, Clone, Default)]
819pub struct FeatureFlagsRetirementOptions {
820 pub flag_age: fallow_types::flag_retirement::FlagAgeMode,
822 pub flag_state: Option<std::path::PathBuf>,
824 pub reasons: Vec<fallow_types::flag_retirement::RetirementReason>,
826 pub sort: fallow_engine::flag_retirement::RetirementSort,
828 pub min_age_days: Option<u64>,
830 pub max_flag_age: Option<u64>,
832}
833
834#[derive(Debug, Clone, Copy, Default)]
836pub enum DuplicationMode {
837 Strict,
840 #[default]
842 Mild,
843 Weak,
845 Semantic,
848}
849
850#[derive(Debug, Clone, Default)]
852pub struct DuplicationOptions {
853 pub analysis: AnalysisOptions,
855 pub mode: Option<DuplicationMode>,
857 pub near: Option<bool>,
860 pub min_tokens: Option<usize>,
862 pub min_lines: Option<usize>,
864 pub min_occurrences: Option<usize>,
867 pub threshold: Option<f64>,
870 pub skip_local: Option<bool>,
873 pub ignore_symlinks: Option<bool>,
876 pub cross_language: Option<bool>,
878 pub ignore_imports: Option<bool>,
881 pub top: Option<usize>,
883 pub include_fragments: Option<bool>,
887}
888
889#[derive(Debug, Clone, Default)]
891pub struct SimilarCodeOptions {
892 pub analysis: AnalysisOptions,
894 pub threshold: Option<f64>,
896 pub min_lines: Option<usize>,
899 pub top: Option<usize>,
901 pub files: Vec<PathBuf>,
905 #[doc(hidden)]
910 pub adapter_provider_path: Option<PathBuf>,
911}
912
913#[derive(Debug, Clone)]
915pub struct SimilarCodeInspectOptions {
916 pub analysis: AnalysisOptions,
919 pub snapshot: fallow_output::SimilarCodeCandidateSnapshot,
921}
922
923#[derive(Debug, Clone, Default)]
925pub struct TraceExportOptions {
926 pub analysis: AnalysisOptions,
928 pub file: String,
930 pub export_name: String,
932}
933
934#[derive(Debug, Clone, Default)]
936pub struct TraceFileOptions {
937 pub analysis: AnalysisOptions,
939 pub file: String,
941}
942
943#[derive(Debug, Clone, Default)]
945pub struct TraceImportPathOptions {
946 pub analysis: AnalysisOptions,
948 pub from: String,
950 pub to: String,
952 pub eager_only: bool,
955}
956
957#[derive(Debug, Clone, Default)]
959pub struct TraceErrorOptions {
960 pub analysis: AnalysisOptions,
962 pub trace: String,
964 pub source: String,
966}
967
968#[derive(Debug, Clone, Default)]
970pub struct TraceDependencyOptions {
971 pub analysis: AnalysisOptions,
973 pub package_name: String,
975 pub usage: Option<DependencyUsageQuery>,
978}
979
980#[derive(Debug, Clone, PartialEq, Eq)]
982pub enum TraceCloneTarget {
983 Location {
985 file: String,
987 line: usize,
989 },
990 Fingerprint(String),
992}
993
994#[derive(Debug, Clone)]
996pub struct TraceCloneOptions {
997 pub duplication: DuplicationOptions,
999 pub target: TraceCloneTarget,
1001}
1002
1003#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1005pub enum ComplexitySort {
1006 #[default]
1008 Cyclomatic,
1009 Cognitive,
1011 Lines,
1013 Severity,
1015}
1016
1017#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1019pub enum OwnershipEmailMode {
1020 Raw,
1022 #[default]
1024 Handle,
1025 Anonymized,
1027 Hash,
1029}
1030
1031#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1033pub enum TargetEffort {
1034 Low,
1036 Medium,
1038 High,
1040}
1041
1042#[derive(Debug, Clone, Default)]
1044pub struct ComplexityOptions {
1045 pub analysis: AnalysisOptions,
1047 pub max_cyclomatic: Option<u16>,
1049 pub max_cognitive: Option<u16>,
1051 pub max_crap: Option<f64>,
1053 pub max_file_lines: Option<u32>,
1056 pub top: Option<usize>,
1058 pub sort: ComplexitySort,
1060 pub complexity_breakdown: bool,
1062 pub complexity: bool,
1064 pub file_scores: bool,
1066 pub coverage_gaps: bool,
1068 pub hotspots: bool,
1070 pub ownership: bool,
1072 pub ownership_emails: Option<OwnershipEmailMode>,
1074 pub targets: bool,
1076 pub css: bool,
1078 pub css_deep: bool,
1080 pub effort: Option<TargetEffort>,
1083 pub score: bool,
1085 pub since: Option<String>,
1087 pub min_commits: Option<u32>,
1089 pub coverage: Option<PathBuf>,
1091 pub coverage_root: Option<PathBuf>,
1093 pub coverage_relocated: bool,
1098}
1099
1100#[derive(Debug, Clone, Copy, Default, PartialEq)]
1102pub struct ComplexityThresholdOverrides {
1103 pub max_cyclomatic: Option<u16>,
1105 pub max_cognitive: Option<u16>,
1107 pub max_crap: Option<f64>,
1109 pub max_file_lines: Option<u32>,
1111}
1112
1113#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1115pub struct ComplexityCoverageInputs<'a> {
1116 pub coverage: Option<&'a Path>,
1118 pub coverage_root: Option<&'a Path>,
1120 pub coverage_relocated: bool,
1123}
1124
1125#[derive(Debug, Clone)]
1127pub struct HealthSectionOptions {
1128 pub output: fallow_types::output_format::OutputFormat,
1130 pub complexity: bool,
1132 pub file_scores: bool,
1134 pub coverage_gaps: bool,
1136 pub hotspots: bool,
1138 pub targets: bool,
1140 pub css: bool,
1142 pub score: bool,
1144 pub score_gate: bool,
1146 pub snapshot_requested: bool,
1148 pub trend: bool,
1150}
1151
1152#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1154pub struct DerivedHealthSections {
1155 pub any_section: bool,
1157 pub complexity: bool,
1159 pub file_scores: bool,
1161 pub coverage_gaps: bool,
1163 pub hotspots: bool,
1165 pub targets: bool,
1167 pub css: bool,
1169 pub score: bool,
1171 pub force_full: bool,
1173 pub score_only_output: bool,
1175}
1176
1177#[derive(Debug, Clone)]
1179pub struct ComplexitySectionOptions {
1180 pub complexity: bool,
1182 pub file_scores: bool,
1184 pub coverage_gaps: bool,
1186 pub hotspots: bool,
1188 pub ownership: bool,
1190 pub targets: bool,
1192 pub css: bool,
1194 pub score: bool,
1196}
1197
1198#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1200pub struct DerivedComplexityOptions {
1201 pub any_section: bool,
1203 pub complexity: bool,
1205 pub file_scores: bool,
1207 pub coverage_gaps: bool,
1209 pub hotspots: bool,
1211 pub ownership: bool,
1213 pub targets: bool,
1215 pub force_full: bool,
1217 pub score_only_output: bool,
1219 pub score: bool,
1221}
1222
1223#[derive(Debug, Clone, PartialEq)]
1225pub struct ComplexityRunOptions<'a> {
1226 pub thresholds: ComplexityThresholdOverrides,
1228 pub top: Option<usize>,
1230 pub sort: ComplexitySort,
1232 pub complexity_breakdown: bool,
1234 pub sections: DerivedComplexityOptions,
1236 pub ownership_emails: Option<OwnershipEmailMode>,
1238 pub effort: Option<TargetEffort>,
1240 pub css: bool,
1242 pub css_deep: bool,
1244 pub since: Option<&'a str>,
1246 pub min_commits: Option<u32>,
1248 pub coverage_inputs: ComplexityCoverageInputs<'a>,
1250}
1251
1252pub fn configure_global_analysis_pool(threads: usize) -> bool {
1261 fallow_engine::thread_pool::worker_pool_builder(threads)
1262 .build_global()
1263 .is_ok()
1264}
1265
1266#[must_use]
1268pub fn derive_health_sections(options: &HealthSectionOptions) -> DerivedHealthSections {
1269 let score = options.score
1270 || options.score_gate
1271 || options.trend
1272 || matches!(
1273 options.output,
1274 fallow_types::output_format::OutputFormat::Badge
1275 );
1276 let any_section = options.complexity
1277 || options.file_scores
1278 || options.coverage_gaps
1279 || options.hotspots
1280 || options.targets
1281 || score;
1282 let effective_score = if any_section { score } else { true } || options.snapshot_requested;
1283 let force_full = options.snapshot_requested || effective_score;
1284
1285 DerivedHealthSections {
1286 any_section,
1287 complexity: if any_section {
1288 options.complexity
1289 } else {
1290 true
1291 },
1292 file_scores: if any_section {
1293 options.file_scores
1294 } else {
1295 true
1296 } || force_full,
1297 coverage_gaps: if any_section {
1298 options.coverage_gaps
1299 } else {
1300 false
1301 },
1302 hotspots: if any_section { options.hotspots } else { true }
1303 || options.snapshot_requested
1304 || options.trend,
1305 targets: if any_section { options.targets } else { true },
1306 css: options.css,
1307 score: effective_score,
1308 force_full,
1309 score_only_output: is_health_score_only_output(options, score),
1310 }
1311}
1312
1313#[must_use]
1315pub fn derive_complexity_sections(options: &ComplexitySectionOptions) -> DerivedComplexityOptions {
1316 let requested_hotspots = options.hotspots || options.ownership;
1317 let sections = derive_health_sections(&HealthSectionOptions {
1318 output: fallow_types::output_format::OutputFormat::Human,
1319 complexity: options.complexity,
1320 file_scores: options.file_scores,
1321 coverage_gaps: options.coverage_gaps,
1322 hotspots: requested_hotspots,
1323 targets: options.targets,
1324 css: options.css,
1325 score: options.score,
1326 score_gate: false,
1327 snapshot_requested: false,
1328 trend: false,
1329 });
1330
1331 DerivedComplexityOptions {
1332 any_section: sections.any_section,
1333 complexity: sections.complexity,
1334 file_scores: sections.file_scores,
1335 coverage_gaps: sections.coverage_gaps,
1336 hotspots: sections.hotspots,
1337 ownership: options.ownership && sections.hotspots,
1338 targets: sections.targets,
1339 force_full: sections.force_full,
1340 score_only_output: sections.score_only_output,
1341 score: sections.score,
1342 }
1343}
1344
1345#[must_use]
1347pub fn derive_complexity_options(options: &ComplexityOptions) -> DerivedComplexityOptions {
1348 derive_complexity_sections(&complexity_section_options(options))
1349}
1350
1351#[must_use]
1353pub fn derive_complexity_run_options(options: &ComplexityOptions) -> ComplexityRunOptions<'_> {
1354 ComplexityRunOptions {
1355 thresholds: ComplexityThresholdOverrides {
1356 max_cyclomatic: options.max_cyclomatic,
1357 max_cognitive: options.max_cognitive,
1358 max_crap: options.max_crap,
1359 max_file_lines: options.max_file_lines,
1360 },
1361 top: options.top,
1362 sort: options.sort,
1363 complexity_breakdown: options.complexity_breakdown,
1364 sections: derive_complexity_options(options),
1365 ownership_emails: options.ownership_emails,
1366 effort: options.effort,
1367 css: options.css,
1368 css_deep: options.css_deep,
1369 since: options.since.as_deref(),
1370 min_commits: options.min_commits,
1371 coverage_inputs: ComplexityCoverageInputs {
1372 coverage: options.coverage.as_deref(),
1373 coverage_root: options.coverage_root.as_deref(),
1374 coverage_relocated: options.coverage_relocated,
1375 },
1376 }
1377}
1378
1379pub fn validate_complexity_options(options: &ComplexityOptions) -> Result<(), ProgrammaticError> {
1402 if let Some(path) = &options.coverage {
1403 let resolved = fallow_engine::health::scoring::resolve_relative_to_root(
1404 path,
1405 options.analysis.root.as_deref(),
1406 );
1407 if !resolved.exists() {
1408 return Err(ProgrammaticError::new(
1409 format!("coverage path does not exist: {}", resolved.display()),
1410 2,
1411 )
1412 .with_code("FALLOW_INVALID_COVERAGE_PATH")
1413 .with_context("health.coverage"));
1414 }
1415 }
1416 if let Err(message) =
1417 fallow_engine::health::validate_coverage_root_absolute(options.coverage_root.as_deref())
1418 {
1419 return Err(ProgrammaticError::new(message, 2)
1420 .with_code("FALLOW_INVALID_COVERAGE_ROOT")
1421 .with_context("health.coverage_root"));
1422 }
1423
1424 Ok(())
1425}
1426
1427fn complexity_section_options(options: &ComplexityOptions) -> ComplexitySectionOptions {
1428 let ownership = options.ownership || options.ownership_emails.is_some();
1429 let requested_targets = options.targets || options.effort.is_some();
1430 ComplexitySectionOptions {
1431 complexity: options.complexity,
1432 file_scores: options.file_scores,
1433 coverage_gaps: options.coverage_gaps,
1434 hotspots: options.hotspots,
1435 ownership,
1436 targets: requested_targets,
1437 css: options.css,
1438 score: options.score,
1439 }
1440}
1441
1442fn is_health_score_only_output(options: &HealthSectionOptions, score: bool) -> bool {
1443 score
1444 && !options.complexity
1445 && !options.file_scores
1446 && !options.coverage_gaps
1447 && !options.hotspots
1448 && !options.targets
1449 && !options.trend
1450}
1451
1452const fn thresholds_to_engine(
1453 thresholds: ComplexityThresholdOverrides,
1454) -> fallow_engine::health::HealthThresholdOverrides {
1455 fallow_engine::health::HealthThresholdOverrides {
1456 max_cyclomatic: thresholds.max_cyclomatic,
1457 max_cognitive: thresholds.max_cognitive,
1458 max_crap: thresholds.max_crap,
1459 max_file_lines: thresholds.max_file_lines,
1460 }
1461}
1462
1463const fn complexity_sort_to_engine(sort: ComplexitySort) -> fallow_engine::health::HealthSort {
1464 match sort {
1465 ComplexitySort::Severity => fallow_engine::health::HealthSort::Severity,
1466 ComplexitySort::Cyclomatic => fallow_engine::health::HealthSort::Cyclomatic,
1467 ComplexitySort::Cognitive => fallow_engine::health::HealthSort::Cognitive,
1468 ComplexitySort::Lines => fallow_engine::health::HealthSort::Lines,
1469 }
1470}
1471
1472const fn coverage_inputs_to_engine(
1473 coverage_inputs: ComplexityCoverageInputs<'_>,
1474) -> fallow_engine::health::HealthCoverageInputs<'_> {
1475 fallow_engine::health::HealthCoverageInputs {
1476 coverage: coverage_inputs.coverage,
1477 coverage_root: coverage_inputs.coverage_root,
1478 coverage_relocated: coverage_inputs.coverage_relocated,
1479 }
1480}
1481
1482const fn ownership_email_mode_to_config(mode: OwnershipEmailMode) -> EmailMode {
1483 match mode {
1484 OwnershipEmailMode::Raw => EmailMode::Raw,
1485 OwnershipEmailMode::Handle => EmailMode::Handle,
1486 OwnershipEmailMode::Anonymized => EmailMode::Anonymized,
1487 OwnershipEmailMode::Hash => EmailMode::Hash,
1488 }
1489}
1490
1491const fn target_effort_to_output(effort: TargetEffort) -> EffortEstimate {
1492 match effort {
1493 TargetEffort::Low => EffortEstimate::Low,
1494 TargetEffort::Medium => EffortEstimate::Medium,
1495 TargetEffort::High => EffortEstimate::High,
1496 }
1497}
1498
1499#[cfg(test)]
1500mod tests {
1501 use super::*;
1502
1503 #[test]
1504 fn duplication_defaults_match_cli_contract() {
1505 let options = DuplicationOptions::default();
1506 assert!(options.mode.is_none());
1507 assert!(options.min_tokens.is_none());
1508 assert!(options.min_lines.is_none());
1509 assert!(options.min_occurrences.is_none());
1510 }
1511
1512 #[test]
1513 fn programmatic_error_builder_keeps_optional_fields() {
1514 let error = ProgrammaticError::new("boom", 2)
1515 .with_code("FALLOW_TEST")
1516 .with_help("Try again")
1517 .with_context("analysis.root");
1518
1519 assert_eq!(error.message, "boom");
1520 assert_eq!(error.exit_code, 2);
1521 assert_eq!(error.code.as_deref(), Some("FALLOW_TEST"));
1522 assert_eq!(error.help.as_deref(), Some("Try again"));
1523 assert_eq!(error.context.as_deref(), Some("analysis.root"));
1524 }
1525
1526 #[test]
1527 fn dead_code_filters_accept_shared_registry_selectors() {
1528 for (selector, _) in fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS.iter() {
1529 let mut filters = DeadCodeFilters::default();
1530 assert!(
1531 filters.enable_registry_selector(selector),
1532 "{selector} should be accepted"
1533 );
1534 }
1535
1536 let mut filters = DeadCodeFilters::default();
1537 assert!(filters.enable_registry_selector("unused-files"));
1538 assert!(filters.unused_files);
1539 assert!(filters.enable_registry_selector("boundary-violations"));
1540 assert!(filters.boundary_violations);
1541 assert!(!filters.enable_registry_selector("not-a-real-selector"));
1542 }
1543
1544 #[test]
1545 fn default_complexity_options_match_programmatic_health_defaults() {
1546 let derived = derive_complexity_options(&ComplexityOptions::default());
1547
1548 assert!(!derived.any_section);
1549 assert!(derived.complexity);
1550 assert!(derived.file_scores);
1551 assert!(!derived.coverage_gaps);
1552 assert!(derived.hotspots);
1553 assert!(!derived.ownership);
1554 assert!(derived.targets);
1555 assert!(derived.force_full);
1556 assert!(!derived.score_only_output);
1557 assert!(derived.score);
1558 }
1559
1560 #[test]
1561 fn score_only_complexity_options_request_score_only_output() {
1562 let derived = derive_complexity_options(&ComplexityOptions {
1563 score: true,
1564 ..ComplexityOptions::default()
1565 });
1566
1567 assert!(derived.any_section);
1568 assert!(!derived.complexity);
1569 assert!(derived.file_scores);
1570 assert!(!derived.hotspots);
1571 assert!(!derived.targets);
1572 assert!(derived.force_full);
1573 assert!(derived.score_only_output);
1574 assert!(derived.score);
1575 }
1576
1577 #[test]
1578 fn ownership_implies_hotspots_when_requested() {
1579 let derived = derive_complexity_options(&ComplexityOptions {
1580 ownership: true,
1581 ..ComplexityOptions::default()
1582 });
1583
1584 assert!(derived.any_section);
1585 assert!(derived.hotspots);
1586 assert!(derived.ownership);
1587 assert!(!derived.targets);
1588 }
1589
1590 #[test]
1591 fn complexity_run_options_normalize_public_api_options() {
1592 let options = ComplexityOptions {
1593 max_cyclomatic: Some(42),
1594 max_cognitive: Some(21),
1595 max_crap: Some(18.5),
1596 top: Some(7),
1597 sort: ComplexitySort::Severity,
1598 complexity_breakdown: true,
1599 ownership_emails: Some(OwnershipEmailMode::Hash),
1600 effort: Some(TargetEffort::High),
1601 coverage: Some(PathBuf::from("coverage/coverage-final.json")),
1602 coverage_root: Some(PathBuf::from("/ci/workspace")),
1603 since: Some("30d".to_string()),
1604 min_commits: Some(4),
1605 ..ComplexityOptions::default()
1606 };
1607
1608 let run = derive_complexity_run_options(&options);
1609
1610 assert_eq!(run.thresholds.max_cyclomatic, Some(42));
1611 assert_eq!(run.thresholds.max_cognitive, Some(21));
1612 assert_eq!(run.thresholds.max_crap, Some(18.5));
1613 assert_eq!(run.top, Some(7));
1614 assert!(matches!(run.sort, ComplexitySort::Severity));
1615 assert!(run.complexity_breakdown);
1616 assert!(run.sections.hotspots);
1617 assert!(run.sections.ownership);
1618 assert!(run.sections.targets);
1619 assert!(matches!(
1620 run.ownership_emails,
1621 Some(OwnershipEmailMode::Hash)
1622 ));
1623 assert!(matches!(run.effort, Some(TargetEffort::High)));
1624 assert_eq!(run.since, Some("30d"));
1625 assert_eq!(run.min_commits, Some(4));
1626 assert_eq!(run.coverage_inputs.coverage, options.coverage.as_deref());
1627 assert_eq!(
1628 run.coverage_inputs.coverage_root,
1629 options.coverage_root.as_deref()
1630 );
1631 }
1632
1633 #[test]
1634 fn complexity_options_validation_accepts_existing_coverage_path_and_absolute_root() {
1635 let dir = tempfile::tempdir().expect("tempdir");
1636 let coverage = dir.path().join("coverage-final.json");
1637 std::fs::write(&coverage, "{}").expect("coverage fixture");
1638
1639 let result = validate_complexity_options(&ComplexityOptions {
1640 coverage: Some(coverage),
1641 coverage_root: Some(PathBuf::from("/ci/workspace")),
1642 ..ComplexityOptions::default()
1643 });
1644
1645 assert!(result.is_ok());
1646 }
1647
1648 #[test]
1649 fn complexity_options_validation_keeps_missing_coverage_error_contract() {
1650 let err = validate_complexity_options(&ComplexityOptions {
1651 coverage: Some(PathBuf::from("/missing/coverage-final.json")),
1652 ..ComplexityOptions::default()
1653 })
1654 .expect_err("missing coverage path should fail");
1655
1656 assert_eq!(err.exit_code, 2);
1657 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1658 assert_eq!(err.context.as_deref(), Some("health.coverage"));
1659 }
1660
1661 #[test]
1662 fn complexity_options_validation_keeps_relative_coverage_root_error_contract() {
1663 let err = validate_complexity_options(&ComplexityOptions {
1664 coverage_root: Some(PathBuf::from("coverage")),
1665 ..ComplexityOptions::default()
1666 })
1667 .expect_err("relative coverage root should fail");
1668
1669 assert_eq!(err.exit_code, 2);
1670 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_ROOT"));
1671 assert_eq!(err.context.as_deref(), Some("health.coverage_root"));
1672 }
1673
1674 #[test]
1678 fn complexity_options_validation_resolves_relative_coverage_against_root() {
1679 let dir = tempfile::tempdir().expect("tempdir");
1680 std::fs::create_dir_all(dir.path().join("artifacts")).expect("artifacts dir");
1681 std::fs::write(dir.path().join("artifacts/coverage-final.json"), "{}")
1682 .expect("coverage fixture");
1683 let relative = PathBuf::from("artifacts/coverage-final.json");
1684 assert!(
1685 !relative.exists(),
1686 "the fixture must not also exist under the test cwd"
1687 );
1688
1689 let result = validate_complexity_options(&ComplexityOptions {
1690 analysis: AnalysisOptions {
1691 root: Some(dir.path().to_path_buf()),
1692 ..AnalysisOptions::default()
1693 },
1694 coverage: Some(relative.clone()),
1695 ..ComplexityOptions::default()
1696 });
1697 assert!(result.is_ok(), "{result:?}");
1698
1699 let err = validate_complexity_options(&ComplexityOptions {
1700 analysis: AnalysisOptions {
1701 root: Some(dir.path().join("elsewhere")),
1702 ..AnalysisOptions::default()
1703 },
1704 coverage: Some(relative),
1705 ..ComplexityOptions::default()
1706 })
1707 .expect_err("the path does not exist under the other root");
1708 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1709 assert!(
1710 err.message.contains("elsewhere"),
1711 "the message names the resolved path: {}",
1712 err.message
1713 );
1714 }
1715
1716 #[test]
1717 fn default_health_sections_match_full_health_output() {
1718 let derived = derive_health_sections(&HealthSectionOptions {
1719 output: fallow_types::output_format::OutputFormat::Human,
1720 complexity: false,
1721 file_scores: false,
1722 coverage_gaps: false,
1723 hotspots: false,
1724 targets: false,
1725 css: false,
1726 score: false,
1727 score_gate: false,
1728 snapshot_requested: false,
1729 trend: false,
1730 });
1731
1732 assert!(!derived.any_section);
1733 assert!(derived.complexity);
1734 assert!(derived.file_scores);
1735 assert!(!derived.coverage_gaps);
1736 assert!(derived.hotspots);
1737 assert!(derived.targets);
1738 assert!(derived.score);
1739 assert!(derived.force_full);
1740 assert!(!derived.score_only_output);
1741 }
1742
1743 #[test]
1744 fn health_score_gate_requests_score_only_output() {
1745 let derived = derive_health_sections(&HealthSectionOptions {
1746 output: fallow_types::output_format::OutputFormat::Human,
1747 complexity: false,
1748 file_scores: false,
1749 coverage_gaps: false,
1750 hotspots: false,
1751 targets: false,
1752 css: false,
1753 score: false,
1754 score_gate: true,
1755 snapshot_requested: false,
1756 trend: false,
1757 });
1758
1759 assert!(derived.any_section);
1760 assert!(!derived.complexity);
1761 assert!(derived.file_scores);
1762 assert!(!derived.hotspots);
1763 assert!(!derived.targets);
1764 assert!(derived.score);
1765 assert!(derived.force_full);
1766 assert!(derived.score_only_output);
1767 }
1768
1769 #[test]
1770 fn health_snapshot_keeps_full_hidden_inputs_without_section_request() {
1771 let derived = derive_health_sections(&HealthSectionOptions {
1772 output: fallow_types::output_format::OutputFormat::Human,
1773 complexity: false,
1774 file_scores: false,
1775 coverage_gaps: false,
1776 hotspots: false,
1777 targets: false,
1778 css: true,
1779 score: false,
1780 score_gate: false,
1781 snapshot_requested: true,
1782 trend: false,
1783 });
1784
1785 assert!(!derived.any_section);
1786 assert!(derived.css);
1787 assert!(derived.file_scores);
1788 assert!(derived.hotspots);
1789 assert!(derived.score);
1790 assert!(derived.force_full);
1791 }
1792}