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_namespace_members: bool,
468 pub unused_store_members: bool,
470 pub unprovided_injects: bool,
472 pub unrendered_components: bool,
474 pub unused_component_props: bool,
476 pub absent_component_props: bool,
478 pub unused_component_emits: bool,
480 pub unused_component_inputs: bool,
482 pub unused_component_outputs: bool,
484 pub unused_svelte_events: bool,
486 pub unused_effect_layers: bool,
488 pub unused_tagged_errors: bool,
490 pub unproduced_catch_tags: bool,
492 pub unused_server_actions: bool,
494 pub unused_load_data_keys: bool,
496 pub unresolved_imports: bool,
498 pub unlisted_deps: bool,
500 pub unlisted_binaries: bool,
502 pub duplicate_exports: bool,
504 pub duplicate_export_aliases: bool,
506 pub circular_deps: bool,
508 pub re_export_cycles: bool,
510 pub package_cycles: bool,
512 pub boundary_violations: bool,
514 pub policy_violations: bool,
516 pub stale_suppressions: bool,
518 pub unused_catalog_entries: bool,
520 pub empty_catalog_groups: bool,
522 pub unresolved_catalog_references: bool,
524 pub unused_dependency_overrides: bool,
526 pub misconfigured_dependency_overrides: bool,
528}
529
530impl DeadCodeFilters {
531 pub(crate) fn reports_dependency_findings(&self) -> bool {
535 !self.any_active() || self.unused_deps || self.unlisted_deps
536 }
537
538 fn any_active(&self) -> bool {
539 self.unused_files
540 || self.unused_exports
541 || self.unused_deps
542 || self.unused_types
543 || self.private_type_leaks
544 || self.deprecated_exports_in_use
545 || self.unused_enum_members
546 || self.unused_class_members
547 || self.unused_namespace_members
548 || self.unused_store_members
549 || self.unprovided_injects
550 || self.unrendered_components
551 || self.unused_component_props
552 || self.absent_component_props
553 || self.unused_component_emits
554 || self.unused_component_inputs
555 || self.unused_component_outputs
556 || self.unused_svelte_events
557 || self.unused_effect_layers
558 || self.unused_tagged_errors
559 || self.unproduced_catch_tags
560 || self.unused_server_actions
561 || self.unused_load_data_keys
562 || self.unresolved_imports
563 || self.unlisted_deps
564 || self.unlisted_binaries
565 || self.duplicate_exports
566 || self.duplicate_export_aliases
567 || self.circular_deps
568 || self.re_export_cycles
569 || self.package_cycles
570 || self.boundary_violations
571 || self.policy_violations
572 || self.stale_suppressions
573 || self.unused_catalog_entries
574 || self.empty_catalog_groups
575 || self.unresolved_catalog_references
576 || self.unused_dependency_overrides
577 || self.misconfigured_dependency_overrides
578 }
579
580 pub fn enable_registry_selector(&mut self, selector: &str) -> bool {
586 let Some(flag) = fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS
587 .iter()
588 .find_map(|&(name, flag)| (name == selector).then_some(flag))
589 else {
590 return false;
591 };
592 self.enable_cli_filter_flag(flag);
593 true
594 }
595
596 pub(crate) fn requested_flags(&self) -> Vec<&'static str> {
598 fallow_engine::requested_rule_off::explicit_filter_flags(|flag| {
599 let mut enabled = self.clone();
600 enabled.enable_cli_filter_flag(flag);
601 enabled == *self
602 })
603 }
604
605 fn enable_cli_filter_flag(&mut self, flag: &str) {
606 match flag {
607 "--unused-files" => self.unused_files = true,
608 "--unused-exports" => self.unused_exports = true,
609 "--unused-types" => self.unused_types = true,
610 "--private-type-leaks" => self.private_type_leaks = true,
611 "--deprecated-exports-in-use" => self.deprecated_exports_in_use = true,
612 "--unused-deps" => self.unused_deps = true,
613 "--unused-enum-members" => self.unused_enum_members = true,
614 "--unused-class-members" => self.unused_class_members = true,
615 "--unused-namespace-members" => self.unused_namespace_members = true,
616 "--unused-store-members" => self.unused_store_members = true,
617 "--unprovided-injects" => self.unprovided_injects = true,
618 "--unrendered-components" => self.unrendered_components = true,
619 "--unused-component-props" => self.unused_component_props = true,
620 "--absent-component-props" => self.absent_component_props = true,
621 "--unused-component-emits" => self.unused_component_emits = true,
622 "--unused-component-inputs" => self.unused_component_inputs = true,
623 "--unused-component-outputs" => self.unused_component_outputs = true,
624 "--unused-svelte-events" => self.unused_svelte_events = true,
625 "--unused-effect-layers" => self.unused_effect_layers = true,
626 "--unused-tagged-errors" => self.unused_tagged_errors = true,
627 "--unproduced-catch-tags" => self.unproduced_catch_tags = true,
628 "--unused-server-actions" => self.unused_server_actions = true,
629 "--unused-load-data-keys" => self.unused_load_data_keys = true,
630 "--unresolved-imports" => self.unresolved_imports = true,
631 "--unlisted-deps" => self.unlisted_deps = true,
632 "--unlisted-binaries" => self.unlisted_binaries = true,
633 "--duplicate-exports" => self.duplicate_exports = true,
634 "--duplicate-export-aliases" => self.duplicate_export_aliases = true,
635 "--circular-deps" => self.circular_deps = true,
636 "--re-export-cycles" => self.re_export_cycles = true,
637 "--package-cycles" => self.package_cycles = true,
638 "--boundary-violations" => self.boundary_violations = true,
639 "--policy-violations" => self.policy_violations = true,
640 "--stale-suppressions" => self.stale_suppressions = true,
641 "--unused-catalog-entries" => self.unused_catalog_entries = true,
642 "--empty-catalog-groups" => self.empty_catalog_groups = true,
643 "--unresolved-catalog-references" => self.unresolved_catalog_references = true,
644 "--unused-dependency-overrides" => self.unused_dependency_overrides = true,
645 "--misconfigured-dependency-overrides" => {
646 self.misconfigured_dependency_overrides = true;
647 }
648 _ => unreachable!("registry emitted unsupported dead-code filter flag: {flag}"),
649 }
650 }
651}
652
653#[derive(Debug, Clone, Default)]
655pub struct DeadCodeOptions {
656 pub analysis: AnalysisOptions,
658 pub filters: DeadCodeFilters,
660 pub files: Vec<PathBuf>,
662 pub include_entry_exports: bool,
664 pub show_cascade: bool,
666 pub finding_ids: Vec<String>,
671}
672
673#[derive(Debug, Clone, Default)]
679pub struct ArchitectureOptions {
680 pub analysis: AnalysisOptions,
682 pub files: Vec<PathBuf>,
684 pub cycles: bool,
687 pub boundaries: bool,
689 pub policy: bool,
691}
692
693impl ArchitectureOptions {
694 #[must_use]
696 pub fn dead_code_filters(&self) -> DeadCodeFilters {
697 let all = !(self.cycles || self.boundaries || self.policy);
698 DeadCodeFilters {
699 circular_deps: self.cycles || all,
700 re_export_cycles: self.cycles || all,
701 package_cycles: self.cycles || all,
702 boundary_violations: self.boundaries || all,
703 policy_violations: self.policy || all,
704 ..DeadCodeFilters::default()
705 }
706 }
707
708 pub(crate) fn requested_flags(&self) -> Vec<&'static str> {
711 fallow_engine::requested_rule_off::architecture_requested_flags(
712 self.cycles,
713 self.boundaries,
714 self.policy,
715 )
716 }
717
718 #[must_use]
720 pub fn dead_code_options(&self) -> DeadCodeOptions {
721 DeadCodeOptions {
722 analysis: self.analysis.clone(),
723 filters: self.dead_code_filters(),
724 files: self.files.clone(),
725 include_entry_exports: false,
726 show_cascade: false,
727 finding_ids: Vec::new(),
728 }
729 }
730}
731
732#[derive(Debug, Clone, Default)]
734pub struct AuditOptions {
735 pub analysis: AnalysisOptions,
737 pub base: Option<String>,
740 pub production: bool,
742 pub production_dead_code: Option<bool>,
744 pub production_health: Option<bool>,
746 pub production_dupes: Option<bool>,
749 pub dead_code: Option<bool>,
753 pub health: Option<bool>,
756 pub duplication: Option<bool>,
759 pub css: Option<bool>,
762 pub css_deep: Option<bool>,
765 pub gate: Option<fallow_config::AuditGate>,
768 pub worsened: Option<fallow_config::AuditWorsened>,
771 pub max_crap: Option<f64>,
773 pub coverage: Option<PathBuf>,
775 pub coverage_root: Option<PathBuf>,
777 pub include_entry_exports: bool,
779 pub show_cascade: bool,
781 pub runtime_coverage: Option<PathBuf>,
783 pub min_invocations_hot: u64,
785}
786
787#[derive(Debug, Clone)]
789pub struct CombinedOptions {
790 pub analysis: AnalysisOptions,
792 pub dead_code: bool,
794 pub duplication: bool,
796 pub health: bool,
798 pub include_entry_exports: bool,
800 pub show_cascade: bool,
802 pub duplication_options: DuplicationOptions,
804 pub health_options: ComplexityOptions,
806}
807
808impl Default for CombinedOptions {
809 fn default() -> Self {
810 Self {
811 analysis: AnalysisOptions::default(),
812 dead_code: true,
813 duplication: true,
814 health: true,
815 include_entry_exports: false,
816 show_cascade: false,
817 duplication_options: DuplicationOptions::default(),
818 health_options: ComplexityOptions::default(),
819 }
820 }
821}
822
823#[derive(Debug, Clone, Default)]
825pub struct DecisionSurfaceOptions {
826 pub analysis: AnalysisOptions,
828 pub base: Option<String>,
831 pub max_decisions: Option<usize>,
833}
834
835#[derive(Debug, Clone, Default)]
837pub struct FeatureFlagsOptions {
838 pub analysis: AnalysisOptions,
840 pub top: Option<usize>,
843 pub retirement: Option<FeatureFlagsRetirementOptions>,
845}
846
847#[derive(Debug, Clone, Default)]
850pub struct FeatureFlagsRetirementOptions {
851 pub flag_age: fallow_types::flag_retirement::FlagAgeMode,
853 pub flag_state: Option<std::path::PathBuf>,
855 pub reasons: Vec<fallow_types::flag_retirement::RetirementReason>,
857 pub sort: fallow_engine::flag_retirement::RetirementSort,
859 pub min_age_days: Option<u64>,
861 pub max_flag_age: Option<u64>,
863}
864
865#[derive(Debug, Clone, Copy, Default)]
867pub enum DuplicationMode {
868 Strict,
871 #[default]
873 Mild,
874 Weak,
876 Semantic,
879}
880
881#[derive(Debug, Clone, Default)]
883pub struct DuplicationOptions {
884 pub analysis: AnalysisOptions,
886 pub mode: Option<DuplicationMode>,
888 pub near: Option<bool>,
891 pub min_tokens: Option<usize>,
893 pub min_lines: Option<usize>,
895 pub min_occurrences: Option<usize>,
898 pub threshold: Option<f64>,
901 pub skip_local: Option<bool>,
904 pub ignore_symlinks: Option<bool>,
907 pub cross_language: Option<bool>,
909 pub ignore_imports: Option<bool>,
912 pub top: Option<usize>,
914 pub include_fragments: Option<bool>,
918}
919
920#[derive(Debug, Clone, Default)]
922pub struct SimilarCodeOptions {
923 pub analysis: AnalysisOptions,
925 pub threshold: Option<f64>,
927 pub min_lines: Option<usize>,
930 pub top: Option<usize>,
932 pub files: Vec<PathBuf>,
936 #[doc(hidden)]
941 pub adapter_provider_path: Option<PathBuf>,
942}
943
944#[derive(Debug, Clone)]
946pub struct SimilarCodeInspectOptions {
947 pub analysis: AnalysisOptions,
950 pub snapshot: fallow_output::SimilarCodeCandidateSnapshot,
952}
953
954#[derive(Debug, Clone, Default)]
956pub struct TraceExportOptions {
957 pub analysis: AnalysisOptions,
959 pub file: String,
961 pub export_name: String,
963}
964
965#[derive(Debug, Clone, Default)]
967pub struct TraceFileOptions {
968 pub analysis: AnalysisOptions,
970 pub file: String,
972}
973
974#[derive(Debug, Clone, Default)]
976pub struct TraceImportPathOptions {
977 pub analysis: AnalysisOptions,
979 pub from: String,
981 pub to: String,
983 pub eager_only: bool,
986}
987
988#[derive(Debug, Clone, Default)]
990pub struct TraceErrorOptions {
991 pub analysis: AnalysisOptions,
993 pub trace: String,
995 pub source: String,
997}
998
999#[derive(Debug, Clone, Default)]
1001pub struct TraceDependencyOptions {
1002 pub analysis: AnalysisOptions,
1004 pub package_name: String,
1006 pub usage: Option<DependencyUsageQuery>,
1009}
1010
1011#[derive(Debug, Clone, PartialEq, Eq)]
1013pub enum TraceCloneTarget {
1014 Location {
1016 file: String,
1018 line: usize,
1020 },
1021 Fingerprint(String),
1023}
1024
1025#[derive(Debug, Clone)]
1027pub struct TraceCloneOptions {
1028 pub duplication: DuplicationOptions,
1030 pub target: TraceCloneTarget,
1032}
1033
1034#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1036pub enum ComplexitySort {
1037 #[default]
1039 Cyclomatic,
1040 Cognitive,
1042 Lines,
1044 Severity,
1046}
1047
1048#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1050pub enum OwnershipEmailMode {
1051 Raw,
1053 #[default]
1055 Handle,
1056 Anonymized,
1058 Hash,
1060}
1061
1062#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1064pub enum TargetEffort {
1065 Low,
1067 Medium,
1069 High,
1071}
1072
1073#[derive(Debug, Clone, Default)]
1075pub struct ComplexityOptions {
1076 pub analysis: AnalysisOptions,
1078 pub max_cyclomatic: Option<u16>,
1080 pub max_cognitive: Option<u16>,
1082 pub max_crap: Option<f64>,
1084 pub max_file_lines: Option<u32>,
1087 pub top: Option<usize>,
1089 pub sort: ComplexitySort,
1091 pub complexity_breakdown: bool,
1093 pub complexity: bool,
1095 pub file_scores: bool,
1097 pub coverage_gaps: bool,
1099 pub hotspots: bool,
1101 pub ownership: bool,
1103 pub ownership_emails: Option<OwnershipEmailMode>,
1105 pub targets: bool,
1107 pub css: bool,
1109 pub css_deep: bool,
1111 pub effort: Option<TargetEffort>,
1114 pub score: bool,
1116 pub since: Option<String>,
1118 pub min_commits: Option<u32>,
1120 pub coverage: Option<PathBuf>,
1122 pub coverage_root: Option<PathBuf>,
1124 pub coverage_relocated: bool,
1129}
1130
1131#[derive(Debug, Clone, Copy, Default, PartialEq)]
1133pub struct ComplexityThresholdOverrides {
1134 pub max_cyclomatic: Option<u16>,
1136 pub max_cognitive: Option<u16>,
1138 pub max_crap: Option<f64>,
1140 pub max_file_lines: Option<u32>,
1142}
1143
1144#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1146pub struct ComplexityCoverageInputs<'a> {
1147 pub coverage: Option<&'a Path>,
1149 pub coverage_root: Option<&'a Path>,
1151 pub coverage_relocated: bool,
1154}
1155
1156#[derive(Debug, Clone)]
1158pub struct HealthSectionOptions {
1159 pub output: fallow_types::output_format::OutputFormat,
1161 pub complexity: bool,
1163 pub file_scores: bool,
1165 pub coverage_gaps: bool,
1167 pub hotspots: bool,
1169 pub targets: bool,
1171 pub css: bool,
1173 pub score: bool,
1175 pub score_gate: bool,
1177 pub snapshot_requested: bool,
1179 pub trend: bool,
1181}
1182
1183#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1185pub struct DerivedHealthSections {
1186 pub any_section: bool,
1188 pub complexity: bool,
1190 pub file_scores: bool,
1192 pub coverage_gaps: bool,
1194 pub hotspots: bool,
1196 pub targets: bool,
1198 pub css: bool,
1200 pub score: bool,
1202 pub force_full: bool,
1204 pub score_only_output: bool,
1206}
1207
1208#[derive(Debug, Clone)]
1210pub struct ComplexitySectionOptions {
1211 pub complexity: bool,
1213 pub file_scores: bool,
1215 pub coverage_gaps: bool,
1217 pub hotspots: bool,
1219 pub ownership: bool,
1221 pub targets: bool,
1223 pub css: bool,
1225 pub score: bool,
1227}
1228
1229#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1231pub struct DerivedComplexityOptions {
1232 pub any_section: bool,
1234 pub complexity: bool,
1236 pub file_scores: bool,
1238 pub coverage_gaps: bool,
1240 pub hotspots: bool,
1242 pub ownership: bool,
1244 pub targets: bool,
1246 pub force_full: bool,
1248 pub score_only_output: bool,
1250 pub score: bool,
1252}
1253
1254#[derive(Debug, Clone, PartialEq)]
1256pub struct ComplexityRunOptions<'a> {
1257 pub thresholds: ComplexityThresholdOverrides,
1259 pub top: Option<usize>,
1261 pub sort: ComplexitySort,
1263 pub complexity_breakdown: bool,
1265 pub sections: DerivedComplexityOptions,
1267 pub ownership_emails: Option<OwnershipEmailMode>,
1269 pub effort: Option<TargetEffort>,
1271 pub css: bool,
1273 pub css_deep: bool,
1275 pub since: Option<&'a str>,
1277 pub min_commits: Option<u32>,
1279 pub coverage_inputs: ComplexityCoverageInputs<'a>,
1281}
1282
1283pub fn configure_global_analysis_pool(threads: usize) -> bool {
1292 fallow_engine::thread_pool::worker_pool_builder(threads)
1293 .build_global()
1294 .is_ok()
1295}
1296
1297#[must_use]
1299pub fn derive_health_sections(options: &HealthSectionOptions) -> DerivedHealthSections {
1300 let score = options.score
1301 || options.score_gate
1302 || options.trend
1303 || matches!(
1304 options.output,
1305 fallow_types::output_format::OutputFormat::Badge
1306 );
1307 let any_section = options.complexity
1308 || options.file_scores
1309 || options.coverage_gaps
1310 || options.hotspots
1311 || options.targets
1312 || score;
1313 let effective_score = if any_section { score } else { true } || options.snapshot_requested;
1314 let force_full = options.snapshot_requested || effective_score;
1315
1316 DerivedHealthSections {
1317 any_section,
1318 complexity: if any_section {
1319 options.complexity
1320 } else {
1321 true
1322 },
1323 file_scores: if any_section {
1324 options.file_scores
1325 } else {
1326 true
1327 } || force_full,
1328 coverage_gaps: if any_section {
1329 options.coverage_gaps
1330 } else {
1331 false
1332 },
1333 hotspots: if any_section { options.hotspots } else { true }
1334 || options.snapshot_requested
1335 || options.trend,
1336 targets: if any_section { options.targets } else { true },
1337 css: options.css,
1338 score: effective_score,
1339 force_full,
1340 score_only_output: is_health_score_only_output(options, score),
1341 }
1342}
1343
1344#[must_use]
1346pub fn derive_complexity_sections(options: &ComplexitySectionOptions) -> DerivedComplexityOptions {
1347 let requested_hotspots = options.hotspots || options.ownership;
1348 let sections = derive_health_sections(&HealthSectionOptions {
1349 output: fallow_types::output_format::OutputFormat::Human,
1350 complexity: options.complexity,
1351 file_scores: options.file_scores,
1352 coverage_gaps: options.coverage_gaps,
1353 hotspots: requested_hotspots,
1354 targets: options.targets,
1355 css: options.css,
1356 score: options.score,
1357 score_gate: false,
1358 snapshot_requested: false,
1359 trend: false,
1360 });
1361
1362 DerivedComplexityOptions {
1363 any_section: sections.any_section,
1364 complexity: sections.complexity,
1365 file_scores: sections.file_scores,
1366 coverage_gaps: sections.coverage_gaps,
1367 hotspots: sections.hotspots,
1368 ownership: options.ownership && sections.hotspots,
1369 targets: sections.targets,
1370 force_full: sections.force_full,
1371 score_only_output: sections.score_only_output,
1372 score: sections.score,
1373 }
1374}
1375
1376#[must_use]
1378pub fn derive_complexity_options(options: &ComplexityOptions) -> DerivedComplexityOptions {
1379 derive_complexity_sections(&complexity_section_options(options))
1380}
1381
1382#[must_use]
1384pub fn derive_complexity_run_options(options: &ComplexityOptions) -> ComplexityRunOptions<'_> {
1385 ComplexityRunOptions {
1386 thresholds: ComplexityThresholdOverrides {
1387 max_cyclomatic: options.max_cyclomatic,
1388 max_cognitive: options.max_cognitive,
1389 max_crap: options.max_crap,
1390 max_file_lines: options.max_file_lines,
1391 },
1392 top: options.top,
1393 sort: options.sort,
1394 complexity_breakdown: options.complexity_breakdown,
1395 sections: derive_complexity_options(options),
1396 ownership_emails: options.ownership_emails,
1397 effort: options.effort,
1398 css: options.css,
1399 css_deep: options.css_deep,
1400 since: options.since.as_deref(),
1401 min_commits: options.min_commits,
1402 coverage_inputs: ComplexityCoverageInputs {
1403 coverage: options.coverage.as_deref(),
1404 coverage_root: options.coverage_root.as_deref(),
1405 coverage_relocated: options.coverage_relocated,
1406 },
1407 }
1408}
1409
1410pub fn validate_complexity_options(options: &ComplexityOptions) -> Result<(), ProgrammaticError> {
1433 if let Some(path) = &options.coverage {
1434 let resolved = fallow_engine::health::scoring::resolve_relative_to_root(
1435 path,
1436 options.analysis.root.as_deref(),
1437 );
1438 if !resolved.exists() {
1439 return Err(ProgrammaticError::new(
1440 format!("coverage path does not exist: {}", resolved.display()),
1441 2,
1442 )
1443 .with_code("FALLOW_INVALID_COVERAGE_PATH")
1444 .with_context("health.coverage"));
1445 }
1446 }
1447 if let Err(message) =
1448 fallow_engine::health::validate_coverage_root_absolute(options.coverage_root.as_deref())
1449 {
1450 return Err(ProgrammaticError::new(message, 2)
1451 .with_code("FALLOW_INVALID_COVERAGE_ROOT")
1452 .with_context("health.coverage_root"));
1453 }
1454
1455 Ok(())
1456}
1457
1458fn complexity_section_options(options: &ComplexityOptions) -> ComplexitySectionOptions {
1459 let ownership = options.ownership || options.ownership_emails.is_some();
1460 let requested_targets = options.targets || options.effort.is_some();
1461 ComplexitySectionOptions {
1462 complexity: options.complexity,
1463 file_scores: options.file_scores,
1464 coverage_gaps: options.coverage_gaps,
1465 hotspots: options.hotspots,
1466 ownership,
1467 targets: requested_targets,
1468 css: options.css,
1469 score: options.score,
1470 }
1471}
1472
1473fn is_health_score_only_output(options: &HealthSectionOptions, score: bool) -> bool {
1474 score
1475 && !options.complexity
1476 && !options.file_scores
1477 && !options.coverage_gaps
1478 && !options.hotspots
1479 && !options.targets
1480 && !options.trend
1481}
1482
1483const fn thresholds_to_engine(
1484 thresholds: ComplexityThresholdOverrides,
1485) -> fallow_engine::health::HealthThresholdOverrides {
1486 fallow_engine::health::HealthThresholdOverrides {
1487 max_cyclomatic: thresholds.max_cyclomatic,
1488 max_cognitive: thresholds.max_cognitive,
1489 max_crap: thresholds.max_crap,
1490 max_file_lines: thresholds.max_file_lines,
1491 }
1492}
1493
1494const fn complexity_sort_to_engine(sort: ComplexitySort) -> fallow_engine::health::HealthSort {
1495 match sort {
1496 ComplexitySort::Severity => fallow_engine::health::HealthSort::Severity,
1497 ComplexitySort::Cyclomatic => fallow_engine::health::HealthSort::Cyclomatic,
1498 ComplexitySort::Cognitive => fallow_engine::health::HealthSort::Cognitive,
1499 ComplexitySort::Lines => fallow_engine::health::HealthSort::Lines,
1500 }
1501}
1502
1503const fn coverage_inputs_to_engine(
1504 coverage_inputs: ComplexityCoverageInputs<'_>,
1505) -> fallow_engine::health::HealthCoverageInputs<'_> {
1506 fallow_engine::health::HealthCoverageInputs {
1507 coverage: coverage_inputs.coverage,
1508 coverage_root: coverage_inputs.coverage_root,
1509 coverage_relocated: coverage_inputs.coverage_relocated,
1510 }
1511}
1512
1513const fn ownership_email_mode_to_config(mode: OwnershipEmailMode) -> EmailMode {
1514 match mode {
1515 OwnershipEmailMode::Raw => EmailMode::Raw,
1516 OwnershipEmailMode::Handle => EmailMode::Handle,
1517 OwnershipEmailMode::Anonymized => EmailMode::Anonymized,
1518 OwnershipEmailMode::Hash => EmailMode::Hash,
1519 }
1520}
1521
1522const fn target_effort_to_output(effort: TargetEffort) -> EffortEstimate {
1523 match effort {
1524 TargetEffort::Low => EffortEstimate::Low,
1525 TargetEffort::Medium => EffortEstimate::Medium,
1526 TargetEffort::High => EffortEstimate::High,
1527 }
1528}
1529
1530#[cfg(test)]
1531mod tests {
1532 use super::*;
1533
1534 #[test]
1535 fn duplication_defaults_match_cli_contract() {
1536 let options = DuplicationOptions::default();
1537 assert!(options.mode.is_none());
1538 assert!(options.min_tokens.is_none());
1539 assert!(options.min_lines.is_none());
1540 assert!(options.min_occurrences.is_none());
1541 }
1542
1543 #[test]
1544 fn programmatic_error_builder_keeps_optional_fields() {
1545 let error = ProgrammaticError::new("boom", 2)
1546 .with_code("FALLOW_TEST")
1547 .with_help("Try again")
1548 .with_context("analysis.root");
1549
1550 assert_eq!(error.message, "boom");
1551 assert_eq!(error.exit_code, 2);
1552 assert_eq!(error.code.as_deref(), Some("FALLOW_TEST"));
1553 assert_eq!(error.help.as_deref(), Some("Try again"));
1554 assert_eq!(error.context.as_deref(), Some("analysis.root"));
1555 }
1556
1557 #[test]
1558 fn dead_code_filters_accept_shared_registry_selectors() {
1559 for (selector, _) in fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS.iter() {
1560 let mut filters = DeadCodeFilters::default();
1561 assert!(
1562 filters.enable_registry_selector(selector),
1563 "{selector} should be accepted"
1564 );
1565 }
1566
1567 let mut filters = DeadCodeFilters::default();
1568 assert!(filters.enable_registry_selector("unused-files"));
1569 assert!(filters.unused_files);
1570 assert!(filters.enable_registry_selector("boundary-violations"));
1571 assert!(filters.boundary_violations);
1572 assert!(!filters.enable_registry_selector("not-a-real-selector"));
1573 }
1574
1575 #[test]
1576 fn default_complexity_options_match_programmatic_health_defaults() {
1577 let derived = derive_complexity_options(&ComplexityOptions::default());
1578
1579 assert!(!derived.any_section);
1580 assert!(derived.complexity);
1581 assert!(derived.file_scores);
1582 assert!(!derived.coverage_gaps);
1583 assert!(derived.hotspots);
1584 assert!(!derived.ownership);
1585 assert!(derived.targets);
1586 assert!(derived.force_full);
1587 assert!(!derived.score_only_output);
1588 assert!(derived.score);
1589 }
1590
1591 #[test]
1592 fn score_only_complexity_options_request_score_only_output() {
1593 let derived = derive_complexity_options(&ComplexityOptions {
1594 score: true,
1595 ..ComplexityOptions::default()
1596 });
1597
1598 assert!(derived.any_section);
1599 assert!(!derived.complexity);
1600 assert!(derived.file_scores);
1601 assert!(!derived.hotspots);
1602 assert!(!derived.targets);
1603 assert!(derived.force_full);
1604 assert!(derived.score_only_output);
1605 assert!(derived.score);
1606 }
1607
1608 #[test]
1609 fn ownership_implies_hotspots_when_requested() {
1610 let derived = derive_complexity_options(&ComplexityOptions {
1611 ownership: true,
1612 ..ComplexityOptions::default()
1613 });
1614
1615 assert!(derived.any_section);
1616 assert!(derived.hotspots);
1617 assert!(derived.ownership);
1618 assert!(!derived.targets);
1619 }
1620
1621 #[test]
1622 fn complexity_run_options_normalize_public_api_options() {
1623 let options = ComplexityOptions {
1624 max_cyclomatic: Some(42),
1625 max_cognitive: Some(21),
1626 max_crap: Some(18.5),
1627 top: Some(7),
1628 sort: ComplexitySort::Severity,
1629 complexity_breakdown: true,
1630 ownership_emails: Some(OwnershipEmailMode::Hash),
1631 effort: Some(TargetEffort::High),
1632 coverage: Some(PathBuf::from("coverage/coverage-final.json")),
1633 coverage_root: Some(PathBuf::from("/ci/workspace")),
1634 since: Some("30d".to_string()),
1635 min_commits: Some(4),
1636 ..ComplexityOptions::default()
1637 };
1638
1639 let run = derive_complexity_run_options(&options);
1640
1641 assert_eq!(run.thresholds.max_cyclomatic, Some(42));
1642 assert_eq!(run.thresholds.max_cognitive, Some(21));
1643 assert_eq!(run.thresholds.max_crap, Some(18.5));
1644 assert_eq!(run.top, Some(7));
1645 assert!(matches!(run.sort, ComplexitySort::Severity));
1646 assert!(run.complexity_breakdown);
1647 assert!(run.sections.hotspots);
1648 assert!(run.sections.ownership);
1649 assert!(run.sections.targets);
1650 assert!(matches!(
1651 run.ownership_emails,
1652 Some(OwnershipEmailMode::Hash)
1653 ));
1654 assert!(matches!(run.effort, Some(TargetEffort::High)));
1655 assert_eq!(run.since, Some("30d"));
1656 assert_eq!(run.min_commits, Some(4));
1657 assert_eq!(run.coverage_inputs.coverage, options.coverage.as_deref());
1658 assert_eq!(
1659 run.coverage_inputs.coverage_root,
1660 options.coverage_root.as_deref()
1661 );
1662 }
1663
1664 #[test]
1665 fn complexity_options_validation_accepts_existing_coverage_path_and_absolute_root() {
1666 let dir = tempfile::tempdir().expect("tempdir");
1667 let coverage = dir.path().join("coverage-final.json");
1668 std::fs::write(&coverage, "{}").expect("coverage fixture");
1669
1670 let result = validate_complexity_options(&ComplexityOptions {
1671 coverage: Some(coverage),
1672 coverage_root: Some(PathBuf::from("/ci/workspace")),
1673 ..ComplexityOptions::default()
1674 });
1675
1676 assert!(result.is_ok());
1677 }
1678
1679 #[test]
1680 fn complexity_options_validation_keeps_missing_coverage_error_contract() {
1681 let err = validate_complexity_options(&ComplexityOptions {
1682 coverage: Some(PathBuf::from("/missing/coverage-final.json")),
1683 ..ComplexityOptions::default()
1684 })
1685 .expect_err("missing coverage path should fail");
1686
1687 assert_eq!(err.exit_code, 2);
1688 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1689 assert_eq!(err.context.as_deref(), Some("health.coverage"));
1690 }
1691
1692 #[test]
1693 fn complexity_options_validation_keeps_relative_coverage_root_error_contract() {
1694 let err = validate_complexity_options(&ComplexityOptions {
1695 coverage_root: Some(PathBuf::from("coverage")),
1696 ..ComplexityOptions::default()
1697 })
1698 .expect_err("relative coverage root should fail");
1699
1700 assert_eq!(err.exit_code, 2);
1701 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_ROOT"));
1702 assert_eq!(err.context.as_deref(), Some("health.coverage_root"));
1703 }
1704
1705 #[test]
1709 fn complexity_options_validation_resolves_relative_coverage_against_root() {
1710 let dir = tempfile::tempdir().expect("tempdir");
1711 std::fs::create_dir_all(dir.path().join("artifacts")).expect("artifacts dir");
1712 std::fs::write(dir.path().join("artifacts/coverage-final.json"), "{}")
1713 .expect("coverage fixture");
1714 let relative = PathBuf::from("artifacts/coverage-final.json");
1715 assert!(
1716 !relative.exists(),
1717 "the fixture must not also exist under the test cwd"
1718 );
1719
1720 let result = validate_complexity_options(&ComplexityOptions {
1721 analysis: AnalysisOptions {
1722 root: Some(dir.path().to_path_buf()),
1723 ..AnalysisOptions::default()
1724 },
1725 coverage: Some(relative.clone()),
1726 ..ComplexityOptions::default()
1727 });
1728 assert!(result.is_ok(), "{result:?}");
1729
1730 let err = validate_complexity_options(&ComplexityOptions {
1731 analysis: AnalysisOptions {
1732 root: Some(dir.path().join("elsewhere")),
1733 ..AnalysisOptions::default()
1734 },
1735 coverage: Some(relative),
1736 ..ComplexityOptions::default()
1737 })
1738 .expect_err("the path does not exist under the other root");
1739 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1740 assert!(
1741 err.message.contains("elsewhere"),
1742 "the message names the resolved path: {}",
1743 err.message
1744 );
1745 }
1746
1747 #[test]
1748 fn default_health_sections_match_full_health_output() {
1749 let derived = derive_health_sections(&HealthSectionOptions {
1750 output: fallow_types::output_format::OutputFormat::Human,
1751 complexity: false,
1752 file_scores: false,
1753 coverage_gaps: false,
1754 hotspots: false,
1755 targets: false,
1756 css: false,
1757 score: false,
1758 score_gate: false,
1759 snapshot_requested: false,
1760 trend: false,
1761 });
1762
1763 assert!(!derived.any_section);
1764 assert!(derived.complexity);
1765 assert!(derived.file_scores);
1766 assert!(!derived.coverage_gaps);
1767 assert!(derived.hotspots);
1768 assert!(derived.targets);
1769 assert!(derived.score);
1770 assert!(derived.force_full);
1771 assert!(!derived.score_only_output);
1772 }
1773
1774 #[test]
1775 fn health_score_gate_requests_score_only_output() {
1776 let derived = derive_health_sections(&HealthSectionOptions {
1777 output: fallow_types::output_format::OutputFormat::Human,
1778 complexity: false,
1779 file_scores: false,
1780 coverage_gaps: false,
1781 hotspots: false,
1782 targets: false,
1783 css: false,
1784 score: false,
1785 score_gate: true,
1786 snapshot_requested: false,
1787 trend: false,
1788 });
1789
1790 assert!(derived.any_section);
1791 assert!(!derived.complexity);
1792 assert!(derived.file_scores);
1793 assert!(!derived.hotspots);
1794 assert!(!derived.targets);
1795 assert!(derived.score);
1796 assert!(derived.force_full);
1797 assert!(derived.score_only_output);
1798 }
1799
1800 #[test]
1801 fn health_snapshot_keeps_full_hidden_inputs_without_section_request() {
1802 let derived = derive_health_sections(&HealthSectionOptions {
1803 output: fallow_types::output_format::OutputFormat::Human,
1804 complexity: false,
1805 file_scores: false,
1806 coverage_gaps: false,
1807 hotspots: false,
1808 targets: false,
1809 css: true,
1810 score: false,
1811 score_gate: false,
1812 snapshot_requested: true,
1813 trend: false,
1814 });
1815
1816 assert!(!derived.any_section);
1817 assert!(derived.css);
1818 assert!(derived.file_scores);
1819 assert!(derived.hotspots);
1820 assert!(derived.score);
1821 assert!(derived.force_full);
1822 }
1823}