1#![warn(missing_docs)]
16#![cfg_attr(
17 test,
18 allow(
19 clippy::expect_used,
20 reason = "tests use expect to keep fixture setup concise"
21 )
22)]
23
24use std::path::{Path, PathBuf};
25use std::sync::Arc;
26use std::sync::atomic::AtomicBool;
27
28use fallow_config::EmailMode;
29use fallow_output::EffortEstimate;
30use serde::Serialize;
31
32mod analysis_context;
33mod audit_complexity;
34pub mod audit_keys;
38pub mod audit_output;
39pub mod audit_run;
40pub mod combined_output;
41pub mod compact_output;
44pub mod coverage;
45pub mod dead_code_codeclimate;
46pub mod dead_code_sarif;
47pub mod decision_surface;
48pub mod dependency_deltas;
49pub mod diff_risk;
50pub mod doctor;
51pub mod dupes_output;
52pub mod editor;
53pub mod explain;
54pub mod grouped_output;
55pub mod health_codeclimate;
56mod health_groups_markdown;
57pub mod json_output;
58pub mod list_output;
59mod list_runtime;
60pub mod markdown_output;
63pub mod mutation;
64mod next_steps;
65pub mod output_contracts;
66pub mod ownership;
67pub mod review_deltas;
68pub mod routing;
69pub mod runtime;
70mod runtime_json;
71mod runtime_output;
72pub mod sarif_output;
73pub mod schemas;
76pub mod security_output;
77pub mod similar_code;
79mod type_aware;
80pub use analysis_context::{ProgrammaticAnalysisContext, resolve_programmatic_analysis_context};
81pub use audit_output::{
82 AuditAttribution, AuditCodeClimateOutputInput, AuditJsonHeaderInput, AuditJsonOutputInput,
83 AuditSarifOutputInput, AuditSummary, AuditVerdict, attach_audit_diff_risk_attribution,
84 attach_audit_duplication_demotion_attribution, attach_audit_styling_attribution,
85 attach_audit_wire_attribution, build_audit_codeclimate, build_audit_codeclimate_issues,
86 build_audit_header_json, build_audit_header_map, build_audit_sarif,
87 build_diff_risk_codeclimate, build_review_brief_header, serialize_audit_json,
88};
89pub use combined_output::{
90 CombinedCheckJsonSection, CombinedJsonOutputInput, serialize_combined_dupes_json,
91 serialize_combined_health_json, serialize_combined_json,
92};
93pub use compact_output::{
94 build_compact_lines, build_diff_risk_compact_lines, build_duplication_compact_lines,
95 build_grouped_compact_lines, build_health_compact_lines,
96};
97pub use coverage::{
98 CoverageInputError, CoverageInputSource, CoverageInputs, resolve_coverage_inputs,
99};
100pub use dead_code_codeclimate::build_codeclimate;
101pub use dead_code_sarif::build_sarif;
102pub use doctor::{DoctorOptions, run_doctor, run_doctor_with_cache_dir};
103pub use dupes_output::{
104 AttributedCloneGroup, AttributedCloneGroupFinding, AttributedInstance, CloneDemotionReason,
105 CloneFamilyFinding, CloneGroupFinding, CombinedDupesSection, DupesReportPayload,
106 DuplicationGroup, DuplicationGrouping, build_duplication_codeclimate,
107 set_duplication_audit_attribution,
108};
109pub use editor::{
110 ChangedFilesError, EditorAnalysisOutput, EditorAnalysisResults, EditorAnalysisSession,
111 EditorCloneFamily, EditorCloneFingerprintSet, EditorCloneGroup, EditorCloneInstance,
112 EditorDeadCodeAnalysisOutput, EditorDuplicationReport, EditorDuplicationStats,
113 EditorInlineComplexityExceeded, EditorInlineComplexityFinding, EditorMirroredDirectory,
114 EditorProjectAnalysisOutput, EditorRefactoringKind, EditorRefactoringSuggestion,
115 EditorSessionParseCounts, collect_inline_complexity, editor_duplicates, editor_extract,
116 editor_results, editor_security, editor_suppress, filter_inline_complexity_by_change_scope,
117 filter_inline_complexity_by_changed_files, resolve_git_toplevel,
118 try_get_changed_files_with_toplevel,
119};
120pub use explain::{
121 AUDIT_RULES, CHECK_RULES, DUPES_RULES, FLAGS_RULES, HEALTH_RULES, MUTATION_RULES, RuleDef,
122 RuleGuide, SECURITY_RULES, all_rules, bare_rule_id, coverage_analyze_meta, coverage_setup_meta,
123 explain_issue_type, rule_by_id, rule_by_token, rule_command, rule_docs_url, rule_guide,
124 rule_severity_key, security_meta, serialize_explain_programmatic_json, unknown_explain_error,
125};
126pub use fallow_config::levenshtein::closest_match;
127pub use fallow_config::{AuditGate, AuditWorsened, HealthConfig, TypeAwareRequire};
128pub use fallow_engine::change_scope::{
131 ChangeScope, ChangeScopeOwner, ChangeScopeRequest, first_package_baselines,
132 package_baseline_statuses,
133};
134pub use fallow_engine::package_baselines::{PackageBaselineError, PackageChangeScope};
136pub use fallow_engine::thread_pool::{WORKER_STACK_SIZE, register_thread_stack};
143pub use fallow_engine::warm_parse;
149pub use fallow_output::PackageBaselineStatus;
151pub use fallow_output::serialize_similar_code_json_output;
152pub use fallow_types::trace::{
153 CloneTrace, DependencyTrace, ExportReference, ExportTrace, FileTrace, ReExportChain,
154 TracedCloneGroup, TracedExport, TracedReExport,
155};
156pub use fallow_types::trace_usage::{
157 DependencyUsage, DependencyUsageQuery, SitePageRequest, UsageQueryError,
158};
159pub use grouped_output::{
160 ResultGroup, UNOWNED_GROUP_LABEL, build_duplication_grouping_with, group_analysis_results_with,
161 health_signal_header_part, largest_clone_group_owner_with,
162};
163pub use health_codeclimate::build_health_codeclimate;
164pub use health_groups_markdown::build_health_groups_markdown;
165pub use json_output::{
166 CheckJsonExtraOutputs, CheckJsonOutputInput, CheckJsonPayloadInput, DuplicationJsonOutputInput,
167 GroupedCheckJsonOutputInput, GroupedDuplicationJsonOutputInput, serialize_check_json,
168 serialize_check_json_payload, serialize_duplication_json, serialize_grouped_check_json,
169 serialize_grouped_duplication_json,
170};
171pub use list_output::{
172 ListJsonEnvelope, ListJsonOutputInput, build_list_json_output, serialize_list_json_output,
173};
174pub use list_runtime::{
175 BoundaryData, ListBoundariesOptions, ListBoundariesProgrammaticOutput, LogicalGroupInfo,
176 ProjectInfoOptions, ProjectInfoProgrammaticOutput, RuleInfo, ZoneInfo, boundary_data_to_output,
177 compute_boundary_data, run_list_boundaries, run_project_info,
178 serialize_list_boundaries_programmatic_json, serialize_project_info_programmatic_json,
179};
180pub use markdown_output::{
181 ComplexityListing, build_diff_risk_markdown, build_duplication_markdown,
182 build_grouped_markdown, build_health_markdown, build_markdown, build_walkthrough_markdown,
183};
184pub use mutation::{
185 MutationProgress, MutationProgressSink, MutationRunOptions, MutationRunScope,
186 apply_mutation_verdicts, validate_mutation_verdicts,
187};
188pub use output_contracts::{
189 AuditOutput, BoundariesListLogicalGroup, BoundariesListRule, BoundariesListZone,
190 BoundariesListing, CombinedOutput, FallowOutput, ImpactOutput, ListBoundariesOutput,
191 ListEntryPointOutput, ListOutput, ListPluginOutput, ReviewBriefWireOutput, SecurityGate,
192 SecurityOutput, SecurityOutputConfig, SecuritySummaryOutput, SimilarCodeCandidateSnapshot,
193 SimilarCodeOutput, TraceOutput, WorkspacesOutput,
194};
195pub use runtime::TYPE_AWARE_CONFIG_UNSUPPORTED;
196pub use runtime::{
197 AUDIT_CONFIG_BASELINE_UNSUPPORTED, ArchitectureOutput, ArchitectureProgrammaticOutput,
198 AuditProgrammaticKeySnapshot, AuditProgrammaticOutput, BoundaryViolationsOutput,
199 BoundaryViolationsProgrammaticOutput, CircularDependenciesOutput,
200 CircularDependenciesProgrammaticOutput, CombinedProgrammaticOutput, DeadCodeOutput,
201 DeadCodeProgrammaticOutput, DecisionSurfaceProgrammaticOutput, DuplicationOutput,
202 DuplicationProgrammaticOutput, EngineHealthRunner, FeatureFlagsOutput,
203 FeatureFlagsProgrammaticOutput, HealthJsonReportInput, HealthProgrammaticOutput,
204 ProgrammaticHealthAnalysis, ProgrammaticHealthNextStepFacts, ProgrammaticHealthRun,
205 ProgrammaticHealthRunner, TraceClassMemberOutput, TraceCloneBenchmarkResult, TraceCloneOutput,
206 TraceCloneProgrammaticOutput, TraceDependencyOutput, TraceDependencyProgrammaticOutput,
207 TraceErrorOutput, TraceErrorProgrammaticOutput, TraceExportOutput,
208 TraceExportProgrammaticOutput, TraceExportTargetOutput, TraceFileOutput,
209 TraceFileProgrammaticOutput, TraceImportPathOutput, TraceImportPathProgrammaticOutput,
210 benchmark_trace_clone_compact_json, benchmark_trace_graph_family_compact_json,
211 inspect_similar_code, load_health_config, parse_similar_code_candidate_snapshot, plan_mutation,
212 review_similar_code, run_architecture, run_audit, run_boundary_violations,
213 run_circular_dependencies, run_combined, run_complexity_with_runner, run_dead_code,
214 run_dead_code_with_baseline, run_decision_surface, run_duplication, run_feature_flags,
215 run_health, run_health_with_runner, run_mutation, run_mutation_with_progress, run_similar_code,
216 run_trace_clone, run_trace_dependency, run_trace_error, run_trace_export, run_trace_file,
217 run_trace_import_path, select_similar_code_candidate_snapshot, serialize_health_report_json,
218};
219pub use runtime_json::{
220 serialize_architecture_programmatic_json, serialize_audit_programmatic_json,
221 serialize_boundary_violations_programmatic_json,
222 serialize_circular_dependencies_programmatic_json, serialize_combined_programmatic_json,
223 serialize_dead_code_programmatic_json, serialize_decision_surface_programmatic_json,
224 serialize_duplication_programmatic_json, serialize_feature_flags_programmatic_json,
225 serialize_health_programmatic_json, serialize_trace_clone_programmatic_json,
226 serialize_trace_dependency_programmatic_json, serialize_trace_error_programmatic_json,
227 serialize_trace_export_programmatic_json, serialize_trace_file_programmatic_json,
228 serialize_trace_import_path_programmatic_json,
229};
230pub use sarif_output::{
231 annotate_sarif_results, build_duplication_sarif, build_grouped_duplication_sarif,
232 build_health_sarif,
233};
234pub use security_output::SecurityGateMode;
235pub use type_aware::{
236 DEFAULT_BACKEND_FAMILY as DEFAULT_TYPE_AWARE_BACKEND_FAMILY, SemanticCouplingOutcome,
237 SemanticDeadCodeOutcome, SemanticInspectOutcome, TypeAwareError, TypeAwareFileChanges,
238 TypeAwareOutcome, TypeAwareSession, TypeAwareStatus, discard_unverified_semantic_candidates,
239 inspect_symbol as inspect_type_aware_symbol, merge_type_aware_meta,
240 refine_configured_dead_code_results as refine_type_aware_results_with_config,
241 shutdown_type_aware_sidecars, status as type_aware_status,
242 symbol_impact as run_type_aware_symbol_impact, symbol_impact as type_aware_symbol_impact,
243 terminate_active_type_aware_sidecars, trace_symbol as run_type_aware_symbol_trace,
244 trace_symbol as trace_type_aware_symbol, type_coupling as analyze_type_coupling,
245};
246
247pub const COMMON_ANALYSIS_OPTION_FLAGS: &[&str] = &[
254 "root",
255 "config",
256 "no-cache",
257 "threads",
258 "changed-since",
259 "diff-file",
260 "production",
261 "workspace",
262 "changed-workspaces",
263 "explain",
264 "allow-remote-extends",
265];
266
267#[derive(Debug, Clone, Serialize)]
269pub struct ProgrammaticError {
270 pub message: String,
272 pub exit_code: u8,
274 pub code: Option<String>,
276 pub help: Option<String>,
278 pub context: Option<String>,
280}
281
282impl ProgrammaticError {
283 #[must_use]
286 pub fn new(message: impl Into<String>, exit_code: u8) -> Self {
287 Self {
288 message: message.into(),
289 exit_code,
290 code: None,
291 help: None,
292 context: None,
293 }
294 }
295
296 #[must_use]
298 pub fn with_help(mut self, help: impl Into<String>) -> Self {
299 self.help = Some(help.into());
300 self
301 }
302
303 #[must_use]
306 pub fn with_code(mut self, code: impl Into<String>) -> Self {
307 self.code = Some(code.into());
308 self
309 }
310
311 #[must_use]
314 pub fn with_context(mut self, context: impl Into<String>) -> Self {
315 self.context = Some(context.into());
316 self
317 }
318}
319
320impl std::fmt::Display for ProgrammaticError {
321 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
322 write!(f, "{}", self.message)
323 }
324}
325
326impl std::error::Error for ProgrammaticError {}
327
328#[derive(Debug, Clone, Default)]
330pub struct AnalysisOptions {
331 pub root: Option<PathBuf>,
334 pub config_path: Option<PathBuf>,
336 pub allow_remote_extends: bool,
338 pub no_cache: bool,
340 pub threads: Option<usize>,
342 pub diff_file: Option<PathBuf>,
354 pub ambient_diff_file: Option<PathBuf>,
362 pub production: bool,
365 pub production_override: Option<bool>,
368 pub changed_since: Option<String>,
373 pub ambient_changed_since: Option<String>,
381 pub no_package_baselines: bool,
385 pub workspace: Option<Vec<String>>,
387 pub changed_workspaces: Option<String>,
389 pub explain: bool,
391 pub type_aware: TypeAwareOptions,
394 pub cancellation: Option<Arc<AtomicBool>>,
424}
425
426#[derive(Debug, Clone, Default, PartialEq, Eq)]
428pub struct TypeAwareOptions {
429 pub enabled: Option<bool>,
436 pub projects: Vec<PathBuf>,
439 pub require: fallow_config::TypeAwareRequire,
441}
442
443impl TypeAwareOptions {
444 #[must_use]
446 pub const fn requested(&self) -> bool {
447 matches!(self.enabled, Some(true))
448 }
449}
450
451#[derive(Debug, Clone, Default, PartialEq, Eq)]
456pub struct DeadCodeFilters {
457 pub unused_files: bool,
459 pub unused_exports: bool,
461 pub unused_deps: bool,
463 pub unused_types: bool,
465 pub private_type_leaks: bool,
467 pub deprecated_exports_in_use: bool,
469 pub unused_enum_members: bool,
471 pub unused_class_members: bool,
473 pub unused_namespace_members: bool,
475 pub unused_store_members: bool,
477 pub unprovided_injects: bool,
479 pub unrendered_components: bool,
481 pub unused_component_props: bool,
483 pub absent_component_props: bool,
485 pub unused_component_emits: bool,
487 pub unused_component_inputs: bool,
489 pub unused_component_outputs: bool,
491 pub unused_svelte_events: bool,
493 pub unused_effect_layers: bool,
495 pub unused_tagged_errors: bool,
497 pub unproduced_catch_tags: bool,
499 pub unused_server_actions: bool,
501 pub unused_load_data_keys: bool,
503 pub unresolved_imports: bool,
505 pub unlisted_deps: bool,
507 pub unlisted_binaries: bool,
509 pub duplicate_exports: bool,
511 pub duplicate_export_aliases: bool,
513 pub circular_deps: bool,
515 pub re_export_cycles: bool,
517 pub package_cycles: bool,
519 pub boundary_violations: bool,
521 pub policy_violations: bool,
523 pub stale_suppressions: bool,
525 pub unused_catalog_entries: bool,
527 pub empty_catalog_groups: bool,
529 pub unresolved_catalog_references: bool,
531 pub unused_dependency_overrides: bool,
533 pub misconfigured_dependency_overrides: bool,
535}
536
537impl DeadCodeFilters {
538 pub(crate) fn reports_dependency_findings(&self) -> bool {
542 !self.any_active() || self.unused_deps || self.unlisted_deps
543 }
544
545 fn any_active(&self) -> bool {
546 self.unused_files
547 || self.unused_exports
548 || self.unused_deps
549 || self.unused_types
550 || self.private_type_leaks
551 || self.deprecated_exports_in_use
552 || self.unused_enum_members
553 || self.unused_class_members
554 || self.unused_namespace_members
555 || self.unused_store_members
556 || self.unprovided_injects
557 || self.unrendered_components
558 || self.unused_component_props
559 || self.absent_component_props
560 || self.unused_component_emits
561 || self.unused_component_inputs
562 || self.unused_component_outputs
563 || self.unused_svelte_events
564 || self.unused_effect_layers
565 || self.unused_tagged_errors
566 || self.unproduced_catch_tags
567 || self.unused_server_actions
568 || self.unused_load_data_keys
569 || self.unresolved_imports
570 || self.unlisted_deps
571 || self.unlisted_binaries
572 || self.duplicate_exports
573 || self.duplicate_export_aliases
574 || self.circular_deps
575 || self.re_export_cycles
576 || self.package_cycles
577 || self.boundary_violations
578 || self.policy_violations
579 || self.stale_suppressions
580 || self.unused_catalog_entries
581 || self.empty_catalog_groups
582 || self.unresolved_catalog_references
583 || self.unused_dependency_overrides
584 || self.misconfigured_dependency_overrides
585 }
586
587 pub fn enable_registry_selector(&mut self, selector: &str) -> bool {
593 let Some(flag) = fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS
594 .iter()
595 .find_map(|&(name, flag)| (name == selector).then_some(flag))
596 else {
597 return false;
598 };
599 self.enable_cli_filter_flag(flag);
600 true
601 }
602
603 pub(crate) fn requested_flags(&self) -> Vec<&'static str> {
605 fallow_engine::requested_rule_off::explicit_filter_flags(|flag| {
606 let mut enabled = self.clone();
607 enabled.enable_cli_filter_flag(flag);
608 enabled == *self
609 })
610 }
611
612 fn enable_cli_filter_flag(&mut self, flag: &str) {
613 match flag {
614 "--unused-files" => self.unused_files = true,
615 "--unused-exports" => self.unused_exports = true,
616 "--unused-types" => self.unused_types = true,
617 "--private-type-leaks" => self.private_type_leaks = true,
618 "--deprecated-exports-in-use" => self.deprecated_exports_in_use = true,
619 "--unused-deps" => self.unused_deps = true,
620 "--unused-enum-members" => self.unused_enum_members = true,
621 "--unused-class-members" => self.unused_class_members = true,
622 "--unused-namespace-members" => self.unused_namespace_members = true,
623 "--unused-store-members" => self.unused_store_members = true,
624 "--unprovided-injects" => self.unprovided_injects = true,
625 "--unrendered-components" => self.unrendered_components = true,
626 "--unused-component-props" => self.unused_component_props = true,
627 "--absent-component-props" => self.absent_component_props = true,
628 "--unused-component-emits" => self.unused_component_emits = true,
629 "--unused-component-inputs" => self.unused_component_inputs = true,
630 "--unused-component-outputs" => self.unused_component_outputs = true,
631 "--unused-svelte-events" => self.unused_svelte_events = true,
632 "--unused-effect-layers" => self.unused_effect_layers = true,
633 "--unused-tagged-errors" => self.unused_tagged_errors = true,
634 "--unproduced-catch-tags" => self.unproduced_catch_tags = true,
635 "--unused-server-actions" => self.unused_server_actions = true,
636 "--unused-load-data-keys" => self.unused_load_data_keys = true,
637 "--unresolved-imports" => self.unresolved_imports = true,
638 "--unlisted-deps" => self.unlisted_deps = true,
639 "--unlisted-binaries" => self.unlisted_binaries = true,
640 "--duplicate-exports" => self.duplicate_exports = true,
641 "--duplicate-export-aliases" => self.duplicate_export_aliases = true,
642 "--circular-deps" => self.circular_deps = true,
643 "--re-export-cycles" => self.re_export_cycles = true,
644 "--package-cycles" => self.package_cycles = true,
645 "--boundary-violations" => self.boundary_violations = true,
646 "--policy-violations" => self.policy_violations = true,
647 "--stale-suppressions" => self.stale_suppressions = true,
648 "--unused-catalog-entries" => self.unused_catalog_entries = true,
649 "--empty-catalog-groups" => self.empty_catalog_groups = true,
650 "--unresolved-catalog-references" => self.unresolved_catalog_references = true,
651 "--unused-dependency-overrides" => self.unused_dependency_overrides = true,
652 "--misconfigured-dependency-overrides" => {
653 self.misconfigured_dependency_overrides = true;
654 }
655 _ => unreachable!("registry emitted unsupported dead-code filter flag: {flag}"),
656 }
657 }
658}
659
660#[derive(Debug, Clone, Default)]
662pub struct DeadCodeOptions {
663 pub analysis: AnalysisOptions,
665 pub filters: DeadCodeFilters,
667 pub files: Vec<PathBuf>,
669 pub include_entry_exports: bool,
671 pub show_cascade: bool,
673 pub finding_ids: Vec<String>,
678}
679
680#[derive(Debug, Clone, Default)]
686pub struct ArchitectureOptions {
687 pub analysis: AnalysisOptions,
689 pub files: Vec<PathBuf>,
691 pub cycles: bool,
694 pub boundaries: bool,
696 pub policy: bool,
698}
699
700impl ArchitectureOptions {
701 #[must_use]
703 pub fn dead_code_filters(&self) -> DeadCodeFilters {
704 let all = !(self.cycles || self.boundaries || self.policy);
705 DeadCodeFilters {
706 circular_deps: self.cycles || all,
707 re_export_cycles: self.cycles || all,
708 package_cycles: self.cycles || all,
709 boundary_violations: self.boundaries || all,
710 policy_violations: self.policy || all,
711 ..DeadCodeFilters::default()
712 }
713 }
714
715 pub(crate) fn requested_flags(&self) -> Vec<&'static str> {
718 fallow_engine::requested_rule_off::architecture_requested_flags(
719 self.cycles,
720 self.boundaries,
721 self.policy,
722 )
723 }
724
725 #[must_use]
727 pub fn dead_code_options(&self) -> DeadCodeOptions {
728 DeadCodeOptions {
729 analysis: self.analysis.clone(),
730 filters: self.dead_code_filters(),
731 files: self.files.clone(),
732 include_entry_exports: false,
733 show_cascade: false,
734 finding_ids: Vec::new(),
735 }
736 }
737}
738
739#[derive(Debug, Clone, Default)]
741pub struct AuditOptions {
742 pub analysis: AnalysisOptions,
744 pub base: Option<String>,
747 pub production: bool,
749 pub production_dead_code: Option<bool>,
751 pub production_health: Option<bool>,
753 pub production_dupes: Option<bool>,
756 pub dead_code: Option<bool>,
760 pub health: Option<bool>,
763 pub duplication: Option<bool>,
766 pub css: Option<bool>,
769 pub css_deep: Option<bool>,
772 pub gate: Option<fallow_config::AuditGate>,
775 pub worsened: Option<fallow_config::AuditWorsened>,
778 pub max_crap: Option<f64>,
780 pub coverage: Option<PathBuf>,
782 pub coverage_root: Option<PathBuf>,
784 pub include_entry_exports: bool,
786 pub show_cascade: bool,
788 pub runtime_coverage: Option<PathBuf>,
790 pub min_invocations_hot: u64,
792}
793
794#[derive(Debug, Clone)]
796pub struct CombinedOptions {
797 pub analysis: AnalysisOptions,
799 pub dead_code: bool,
801 pub duplication: bool,
803 pub health: bool,
805 pub include_entry_exports: bool,
807 pub show_cascade: bool,
809 pub duplication_options: DuplicationOptions,
811 pub health_options: ComplexityOptions,
813}
814
815impl Default for CombinedOptions {
816 fn default() -> Self {
817 Self {
818 analysis: AnalysisOptions::default(),
819 dead_code: true,
820 duplication: true,
821 health: true,
822 include_entry_exports: false,
823 show_cascade: false,
824 duplication_options: DuplicationOptions::default(),
825 health_options: ComplexityOptions::default(),
826 }
827 }
828}
829
830#[derive(Debug, Clone, Default)]
832pub struct DecisionSurfaceOptions {
833 pub analysis: AnalysisOptions,
835 pub base: Option<String>,
838 pub max_decisions: Option<usize>,
840}
841
842#[derive(Debug, Clone, Default)]
844pub struct FeatureFlagsOptions {
845 pub analysis: AnalysisOptions,
847 pub top: Option<usize>,
850 pub retirement: Option<FeatureFlagsRetirementOptions>,
852}
853
854#[derive(Debug, Clone, Default)]
857pub struct FeatureFlagsRetirementOptions {
858 pub flag_age: fallow_types::flag_retirement::FlagAgeMode,
860 pub flag_state: Option<std::path::PathBuf>,
862 pub reasons: Vec<fallow_types::flag_retirement::RetirementReason>,
864 pub sort: fallow_engine::flag_retirement::RetirementSort,
866 pub min_age_days: Option<u64>,
868 pub max_flag_age: Option<u64>,
870}
871
872#[derive(Debug, Clone, Copy, Default)]
874pub enum DuplicationMode {
875 Strict,
878 #[default]
880 Mild,
881 Weak,
883 Semantic,
886}
887
888#[derive(Debug, Clone, Default)]
890pub struct DuplicationOptions {
891 pub analysis: AnalysisOptions,
893 pub mode: Option<DuplicationMode>,
895 pub near: Option<bool>,
898 pub min_tokens: Option<usize>,
900 pub min_lines: Option<usize>,
902 pub min_occurrences: Option<usize>,
905 pub threshold: Option<f64>,
908 pub skip_local: Option<bool>,
911 pub ignore_symlinks: Option<bool>,
914 pub cross_language: Option<bool>,
916 pub ignore_imports: Option<bool>,
919 pub top: Option<usize>,
921 pub include_fragments: Option<bool>,
925}
926
927#[derive(Debug, Clone, Default)]
929pub struct SimilarCodeOptions {
930 pub analysis: AnalysisOptions,
932 pub threshold: Option<f64>,
934 pub min_lines: Option<usize>,
937 pub top: Option<usize>,
939 pub files: Vec<PathBuf>,
943 #[doc(hidden)]
948 pub adapter_provider_path: Option<PathBuf>,
949}
950
951#[derive(Debug, Clone)]
953pub struct SimilarCodeInspectOptions {
954 pub analysis: AnalysisOptions,
957 pub snapshot: fallow_output::SimilarCodeCandidateSnapshot,
959}
960
961#[derive(Debug, Clone, Default)]
963pub struct TraceExportOptions {
964 pub analysis: AnalysisOptions,
966 pub file: String,
968 pub export_name: String,
970}
971
972#[derive(Debug, Clone, Default)]
974pub struct TraceFileOptions {
975 pub analysis: AnalysisOptions,
977 pub file: String,
979}
980
981#[derive(Debug, Clone, Default)]
983pub struct TraceImportPathOptions {
984 pub analysis: AnalysisOptions,
986 pub from: String,
988 pub to: String,
990 pub eager_only: bool,
993}
994
995#[derive(Debug, Clone, Default)]
997pub struct TraceErrorOptions {
998 pub analysis: AnalysisOptions,
1000 pub trace: String,
1002 pub source: String,
1004}
1005
1006#[derive(Debug, Clone, Default)]
1008pub struct TraceDependencyOptions {
1009 pub analysis: AnalysisOptions,
1011 pub package_name: String,
1013 pub usage: Option<DependencyUsageQuery>,
1016}
1017
1018#[derive(Debug, Clone, PartialEq, Eq)]
1020pub enum TraceCloneTarget {
1021 Location {
1023 file: String,
1025 line: usize,
1027 },
1028 Fingerprint(String),
1030}
1031
1032#[derive(Debug, Clone)]
1034pub struct TraceCloneOptions {
1035 pub duplication: DuplicationOptions,
1037 pub target: TraceCloneTarget,
1039}
1040
1041#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1043pub enum ComplexitySort {
1044 #[default]
1046 Cyclomatic,
1047 Cognitive,
1049 Lines,
1051 Severity,
1053}
1054
1055#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1057pub enum OwnershipEmailMode {
1058 Raw,
1060 #[default]
1062 Handle,
1063 Anonymized,
1065 Hash,
1067}
1068
1069#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1071pub enum TargetEffort {
1072 Low,
1074 Medium,
1076 High,
1078}
1079
1080#[derive(Debug, Clone, Default)]
1082pub struct ComplexityOptions {
1083 pub analysis: AnalysisOptions,
1085 pub max_cyclomatic: Option<u16>,
1087 pub max_cognitive: Option<u16>,
1089 pub max_crap: Option<f64>,
1091 pub max_file_lines: Option<u32>,
1094 pub top: Option<usize>,
1096 pub sort: ComplexitySort,
1098 pub complexity_breakdown: bool,
1100 pub complexity: bool,
1102 pub file_scores: bool,
1104 pub coverage_gaps: bool,
1106 pub hotspots: bool,
1108 pub ownership: bool,
1110 pub ownership_emails: Option<OwnershipEmailMode>,
1112 pub targets: bool,
1114 pub css: bool,
1116 pub css_deep: bool,
1118 pub effort: Option<TargetEffort>,
1121 pub score: bool,
1123 pub since: Option<String>,
1125 pub min_commits: Option<u32>,
1127 pub coverage: Option<PathBuf>,
1129 pub coverage_root: Option<PathBuf>,
1131 pub coverage_relocated: bool,
1136}
1137
1138#[derive(Debug, Clone, Copy, Default, PartialEq)]
1140pub struct ComplexityThresholdOverrides {
1141 pub max_cyclomatic: Option<u16>,
1143 pub max_cognitive: Option<u16>,
1145 pub max_crap: Option<f64>,
1147 pub max_file_lines: Option<u32>,
1149}
1150
1151#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1153pub struct ComplexityCoverageInputs<'a> {
1154 pub coverage: Option<&'a Path>,
1156 pub coverage_root: Option<&'a Path>,
1158 pub coverage_relocated: bool,
1161}
1162
1163#[derive(Debug, Clone)]
1165pub struct HealthSectionOptions {
1166 pub output: fallow_types::output_format::OutputFormat,
1168 pub complexity: bool,
1170 pub file_scores: bool,
1172 pub coverage_gaps: bool,
1174 pub hotspots: bool,
1176 pub targets: bool,
1178 pub css: bool,
1180 pub score: bool,
1182 pub score_gate: bool,
1184 pub snapshot_requested: bool,
1186 pub trend: bool,
1188}
1189
1190#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1192pub struct DerivedHealthSections {
1193 pub any_section: bool,
1195 pub complexity: bool,
1197 pub file_scores: bool,
1199 pub coverage_gaps: bool,
1201 pub hotspots: bool,
1203 pub targets: bool,
1205 pub css: bool,
1207 pub score: bool,
1209 pub force_full: bool,
1211 pub score_only_output: bool,
1213}
1214
1215#[derive(Debug, Clone)]
1217pub struct ComplexitySectionOptions {
1218 pub complexity: bool,
1220 pub file_scores: bool,
1222 pub coverage_gaps: bool,
1224 pub hotspots: bool,
1226 pub ownership: bool,
1228 pub targets: bool,
1230 pub css: bool,
1232 pub score: bool,
1234}
1235
1236#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1238pub struct DerivedComplexityOptions {
1239 pub any_section: bool,
1241 pub complexity: bool,
1243 pub file_scores: bool,
1245 pub coverage_gaps: bool,
1247 pub hotspots: bool,
1249 pub ownership: bool,
1251 pub targets: bool,
1253 pub force_full: bool,
1255 pub score_only_output: bool,
1257 pub score: bool,
1259}
1260
1261#[derive(Debug, Clone, PartialEq)]
1263pub struct ComplexityRunOptions<'a> {
1264 pub thresholds: ComplexityThresholdOverrides,
1266 pub top: Option<usize>,
1268 pub sort: ComplexitySort,
1270 pub complexity_breakdown: bool,
1272 pub sections: DerivedComplexityOptions,
1274 pub ownership_emails: Option<OwnershipEmailMode>,
1276 pub effort: Option<TargetEffort>,
1278 pub css: bool,
1280 pub css_deep: bool,
1282 pub since: Option<&'a str>,
1284 pub min_commits: Option<u32>,
1286 pub coverage_inputs: ComplexityCoverageInputs<'a>,
1288}
1289
1290pub fn configure_global_analysis_pool(threads: usize) -> bool {
1299 fallow_engine::thread_pool::worker_pool_builder(threads)
1300 .build_global()
1301 .is_ok()
1302}
1303
1304#[must_use]
1306pub fn derive_health_sections(options: &HealthSectionOptions) -> DerivedHealthSections {
1307 let score = options.score
1308 || options.score_gate
1309 || options.trend
1310 || matches!(
1311 options.output,
1312 fallow_types::output_format::OutputFormat::Badge
1313 );
1314 let any_section = options.complexity
1315 || options.file_scores
1316 || options.coverage_gaps
1317 || options.hotspots
1318 || options.targets
1319 || score;
1320 let effective_score = if any_section { score } else { true } || options.snapshot_requested;
1321 let force_full = options.snapshot_requested || effective_score;
1322
1323 DerivedHealthSections {
1324 any_section,
1325 complexity: if any_section {
1326 options.complexity
1327 } else {
1328 true
1329 },
1330 file_scores: if any_section {
1331 options.file_scores
1332 } else {
1333 true
1334 } || force_full,
1335 coverage_gaps: if any_section {
1336 options.coverage_gaps
1337 } else {
1338 false
1339 },
1340 hotspots: if any_section { options.hotspots } else { true }
1341 || options.snapshot_requested
1342 || options.trend,
1343 targets: if any_section { options.targets } else { true },
1344 css: options.css,
1345 score: effective_score,
1346 force_full,
1347 score_only_output: is_health_score_only_output(options, score),
1348 }
1349}
1350
1351#[must_use]
1353pub fn derive_complexity_sections(options: &ComplexitySectionOptions) -> DerivedComplexityOptions {
1354 let requested_hotspots = options.hotspots || options.ownership;
1355 let sections = derive_health_sections(&HealthSectionOptions {
1356 output: fallow_types::output_format::OutputFormat::Human,
1357 complexity: options.complexity,
1358 file_scores: options.file_scores,
1359 coverage_gaps: options.coverage_gaps,
1360 hotspots: requested_hotspots,
1361 targets: options.targets,
1362 css: options.css,
1363 score: options.score,
1364 score_gate: false,
1365 snapshot_requested: false,
1366 trend: false,
1367 });
1368
1369 DerivedComplexityOptions {
1370 any_section: sections.any_section,
1371 complexity: sections.complexity,
1372 file_scores: sections.file_scores,
1373 coverage_gaps: sections.coverage_gaps,
1374 hotspots: sections.hotspots,
1375 ownership: options.ownership && sections.hotspots,
1376 targets: sections.targets,
1377 force_full: sections.force_full,
1378 score_only_output: sections.score_only_output,
1379 score: sections.score,
1380 }
1381}
1382
1383#[must_use]
1385pub fn derive_complexity_options(options: &ComplexityOptions) -> DerivedComplexityOptions {
1386 derive_complexity_sections(&complexity_section_options(options))
1387}
1388
1389#[must_use]
1391pub fn derive_complexity_run_options(options: &ComplexityOptions) -> ComplexityRunOptions<'_> {
1392 ComplexityRunOptions {
1393 thresholds: ComplexityThresholdOverrides {
1394 max_cyclomatic: options.max_cyclomatic,
1395 max_cognitive: options.max_cognitive,
1396 max_crap: options.max_crap,
1397 max_file_lines: options.max_file_lines,
1398 },
1399 top: options.top,
1400 sort: options.sort,
1401 complexity_breakdown: options.complexity_breakdown,
1402 sections: derive_complexity_options(options),
1403 ownership_emails: options.ownership_emails,
1404 effort: options.effort,
1405 css: options.css,
1406 css_deep: options.css_deep,
1407 since: options.since.as_deref(),
1408 min_commits: options.min_commits,
1409 coverage_inputs: ComplexityCoverageInputs {
1410 coverage: options.coverage.as_deref(),
1411 coverage_root: options.coverage_root.as_deref(),
1412 coverage_relocated: options.coverage_relocated,
1413 },
1414 }
1415}
1416
1417pub fn validate_complexity_options(options: &ComplexityOptions) -> Result<(), ProgrammaticError> {
1440 if let Some(path) = &options.coverage {
1441 let resolved = fallow_engine::health::scoring::resolve_relative_to_root(
1442 path,
1443 options.analysis.root.as_deref(),
1444 );
1445 if !resolved.exists() {
1446 return Err(ProgrammaticError::new(
1447 format!("coverage path does not exist: {}", resolved.display()),
1448 2,
1449 )
1450 .with_code("FALLOW_INVALID_COVERAGE_PATH")
1451 .with_context("health.coverage"));
1452 }
1453 }
1454 if let Err(message) =
1455 fallow_engine::health::validate_coverage_root_absolute(options.coverage_root.as_deref())
1456 {
1457 return Err(ProgrammaticError::new(message, 2)
1458 .with_code("FALLOW_INVALID_COVERAGE_ROOT")
1459 .with_context("health.coverage_root"));
1460 }
1461
1462 Ok(())
1463}
1464
1465fn complexity_section_options(options: &ComplexityOptions) -> ComplexitySectionOptions {
1466 let ownership = options.ownership || options.ownership_emails.is_some();
1467 let requested_targets = options.targets || options.effort.is_some();
1468 ComplexitySectionOptions {
1469 complexity: options.complexity,
1470 file_scores: options.file_scores,
1471 coverage_gaps: options.coverage_gaps,
1472 hotspots: options.hotspots,
1473 ownership,
1474 targets: requested_targets,
1475 css: options.css,
1476 score: options.score,
1477 }
1478}
1479
1480fn is_health_score_only_output(options: &HealthSectionOptions, score: bool) -> bool {
1481 score
1482 && !options.complexity
1483 && !options.file_scores
1484 && !options.coverage_gaps
1485 && !options.hotspots
1486 && !options.targets
1487 && !options.trend
1488}
1489
1490const fn thresholds_to_engine(
1491 thresholds: ComplexityThresholdOverrides,
1492) -> fallow_engine::health::HealthThresholdOverrides {
1493 fallow_engine::health::HealthThresholdOverrides {
1494 max_cyclomatic: thresholds.max_cyclomatic,
1495 max_cognitive: thresholds.max_cognitive,
1496 max_crap: thresholds.max_crap,
1497 max_file_lines: thresholds.max_file_lines,
1498 }
1499}
1500
1501const fn complexity_sort_to_engine(sort: ComplexitySort) -> fallow_engine::health::HealthSort {
1502 match sort {
1503 ComplexitySort::Severity => fallow_engine::health::HealthSort::Severity,
1504 ComplexitySort::Cyclomatic => fallow_engine::health::HealthSort::Cyclomatic,
1505 ComplexitySort::Cognitive => fallow_engine::health::HealthSort::Cognitive,
1506 ComplexitySort::Lines => fallow_engine::health::HealthSort::Lines,
1507 }
1508}
1509
1510const fn coverage_inputs_to_engine(
1511 coverage_inputs: ComplexityCoverageInputs<'_>,
1512) -> fallow_engine::health::HealthCoverageInputs<'_> {
1513 fallow_engine::health::HealthCoverageInputs {
1514 coverage: coverage_inputs.coverage,
1515 coverage_root: coverage_inputs.coverage_root,
1516 coverage_relocated: coverage_inputs.coverage_relocated,
1517 }
1518}
1519
1520const fn ownership_email_mode_to_config(mode: OwnershipEmailMode) -> EmailMode {
1521 match mode {
1522 OwnershipEmailMode::Raw => EmailMode::Raw,
1523 OwnershipEmailMode::Handle => EmailMode::Handle,
1524 OwnershipEmailMode::Anonymized => EmailMode::Anonymized,
1525 OwnershipEmailMode::Hash => EmailMode::Hash,
1526 }
1527}
1528
1529const fn target_effort_to_output(effort: TargetEffort) -> EffortEstimate {
1530 match effort {
1531 TargetEffort::Low => EffortEstimate::Low,
1532 TargetEffort::Medium => EffortEstimate::Medium,
1533 TargetEffort::High => EffortEstimate::High,
1534 }
1535}
1536
1537#[cfg(test)]
1538mod tests {
1539 use super::*;
1540
1541 #[test]
1542 fn duplication_defaults_match_cli_contract() {
1543 let options = DuplicationOptions::default();
1544 assert!(options.mode.is_none());
1545 assert!(options.min_tokens.is_none());
1546 assert!(options.min_lines.is_none());
1547 assert!(options.min_occurrences.is_none());
1548 }
1549
1550 #[test]
1551 fn programmatic_error_builder_keeps_optional_fields() {
1552 let error = ProgrammaticError::new("boom", 2)
1553 .with_code("FALLOW_TEST")
1554 .with_help("Try again")
1555 .with_context("analysis.root");
1556
1557 assert_eq!(error.message, "boom");
1558 assert_eq!(error.exit_code, 2);
1559 assert_eq!(error.code.as_deref(), Some("FALLOW_TEST"));
1560 assert_eq!(error.help.as_deref(), Some("Try again"));
1561 assert_eq!(error.context.as_deref(), Some("analysis.root"));
1562 }
1563
1564 #[test]
1565 fn dead_code_filters_accept_shared_registry_selectors() {
1566 for (selector, _) in fallow_types::issue_meta::MCP_ISSUE_TYPE_FLAGS.iter() {
1567 let mut filters = DeadCodeFilters::default();
1568 assert!(
1569 filters.enable_registry_selector(selector),
1570 "{selector} should be accepted"
1571 );
1572 }
1573
1574 let mut filters = DeadCodeFilters::default();
1575 assert!(filters.enable_registry_selector("unused-files"));
1576 assert!(filters.unused_files);
1577 assert!(filters.enable_registry_selector("boundary-violations"));
1578 assert!(filters.boundary_violations);
1579 assert!(!filters.enable_registry_selector("not-a-real-selector"));
1580 }
1581
1582 #[test]
1583 fn default_complexity_options_match_programmatic_health_defaults() {
1584 let derived = derive_complexity_options(&ComplexityOptions::default());
1585
1586 assert!(!derived.any_section);
1587 assert!(derived.complexity);
1588 assert!(derived.file_scores);
1589 assert!(!derived.coverage_gaps);
1590 assert!(derived.hotspots);
1591 assert!(!derived.ownership);
1592 assert!(derived.targets);
1593 assert!(derived.force_full);
1594 assert!(!derived.score_only_output);
1595 assert!(derived.score);
1596 }
1597
1598 #[test]
1599 fn score_only_complexity_options_request_score_only_output() {
1600 let derived = derive_complexity_options(&ComplexityOptions {
1601 score: true,
1602 ..ComplexityOptions::default()
1603 });
1604
1605 assert!(derived.any_section);
1606 assert!(!derived.complexity);
1607 assert!(derived.file_scores);
1608 assert!(!derived.hotspots);
1609 assert!(!derived.targets);
1610 assert!(derived.force_full);
1611 assert!(derived.score_only_output);
1612 assert!(derived.score);
1613 }
1614
1615 #[test]
1616 fn ownership_implies_hotspots_when_requested() {
1617 let derived = derive_complexity_options(&ComplexityOptions {
1618 ownership: true,
1619 ..ComplexityOptions::default()
1620 });
1621
1622 assert!(derived.any_section);
1623 assert!(derived.hotspots);
1624 assert!(derived.ownership);
1625 assert!(!derived.targets);
1626 }
1627
1628 #[test]
1629 fn complexity_run_options_normalize_public_api_options() {
1630 let options = ComplexityOptions {
1631 max_cyclomatic: Some(42),
1632 max_cognitive: Some(21),
1633 max_crap: Some(18.5),
1634 top: Some(7),
1635 sort: ComplexitySort::Severity,
1636 complexity_breakdown: true,
1637 ownership_emails: Some(OwnershipEmailMode::Hash),
1638 effort: Some(TargetEffort::High),
1639 coverage: Some(PathBuf::from("coverage/coverage-final.json")),
1640 coverage_root: Some(PathBuf::from("/ci/workspace")),
1641 since: Some("30d".to_string()),
1642 min_commits: Some(4),
1643 ..ComplexityOptions::default()
1644 };
1645
1646 let run = derive_complexity_run_options(&options);
1647
1648 assert_eq!(run.thresholds.max_cyclomatic, Some(42));
1649 assert_eq!(run.thresholds.max_cognitive, Some(21));
1650 assert_eq!(run.thresholds.max_crap, Some(18.5));
1651 assert_eq!(run.top, Some(7));
1652 assert!(matches!(run.sort, ComplexitySort::Severity));
1653 assert!(run.complexity_breakdown);
1654 assert!(run.sections.hotspots);
1655 assert!(run.sections.ownership);
1656 assert!(run.sections.targets);
1657 assert!(matches!(
1658 run.ownership_emails,
1659 Some(OwnershipEmailMode::Hash)
1660 ));
1661 assert!(matches!(run.effort, Some(TargetEffort::High)));
1662 assert_eq!(run.since, Some("30d"));
1663 assert_eq!(run.min_commits, Some(4));
1664 assert_eq!(run.coverage_inputs.coverage, options.coverage.as_deref());
1665 assert_eq!(
1666 run.coverage_inputs.coverage_root,
1667 options.coverage_root.as_deref()
1668 );
1669 }
1670
1671 #[test]
1672 fn complexity_options_validation_accepts_existing_coverage_path_and_absolute_root() {
1673 let dir = tempfile::tempdir().expect("tempdir");
1674 let coverage = dir.path().join("coverage-final.json");
1675 std::fs::write(&coverage, "{}").expect("coverage fixture");
1676
1677 let result = validate_complexity_options(&ComplexityOptions {
1678 coverage: Some(coverage),
1679 coverage_root: Some(PathBuf::from("/ci/workspace")),
1680 ..ComplexityOptions::default()
1681 });
1682
1683 assert!(result.is_ok());
1684 }
1685
1686 #[test]
1687 fn complexity_options_validation_keeps_missing_coverage_error_contract() {
1688 let err = validate_complexity_options(&ComplexityOptions {
1689 coverage: Some(PathBuf::from("/missing/coverage-final.json")),
1690 ..ComplexityOptions::default()
1691 })
1692 .expect_err("missing coverage path should fail");
1693
1694 assert_eq!(err.exit_code, 2);
1695 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1696 assert_eq!(err.context.as_deref(), Some("health.coverage"));
1697 }
1698
1699 #[test]
1700 fn complexity_options_validation_keeps_relative_coverage_root_error_contract() {
1701 let err = validate_complexity_options(&ComplexityOptions {
1702 coverage_root: Some(PathBuf::from("coverage")),
1703 ..ComplexityOptions::default()
1704 })
1705 .expect_err("relative coverage root should fail");
1706
1707 assert_eq!(err.exit_code, 2);
1708 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_ROOT"));
1709 assert_eq!(err.context.as_deref(), Some("health.coverage_root"));
1710 }
1711
1712 #[test]
1716 fn complexity_options_validation_resolves_relative_coverage_against_root() {
1717 let dir = tempfile::tempdir().expect("tempdir");
1718 std::fs::create_dir_all(dir.path().join("artifacts")).expect("artifacts dir");
1719 std::fs::write(dir.path().join("artifacts/coverage-final.json"), "{}")
1720 .expect("coverage fixture");
1721 let relative = PathBuf::from("artifacts/coverage-final.json");
1722 assert!(
1723 !relative.exists(),
1724 "the fixture must not also exist under the test cwd"
1725 );
1726
1727 let result = validate_complexity_options(&ComplexityOptions {
1728 analysis: AnalysisOptions {
1729 root: Some(dir.path().to_path_buf()),
1730 ..AnalysisOptions::default()
1731 },
1732 coverage: Some(relative.clone()),
1733 ..ComplexityOptions::default()
1734 });
1735 assert!(result.is_ok(), "{result:?}");
1736
1737 let err = validate_complexity_options(&ComplexityOptions {
1738 analysis: AnalysisOptions {
1739 root: Some(dir.path().join("elsewhere")),
1740 ..AnalysisOptions::default()
1741 },
1742 coverage: Some(relative),
1743 ..ComplexityOptions::default()
1744 })
1745 .expect_err("the path does not exist under the other root");
1746 assert_eq!(err.code.as_deref(), Some("FALLOW_INVALID_COVERAGE_PATH"));
1747 assert!(
1748 err.message.contains("elsewhere"),
1749 "the message names the resolved path: {}",
1750 err.message
1751 );
1752 }
1753
1754 #[test]
1755 fn default_health_sections_match_full_health_output() {
1756 let derived = derive_health_sections(&HealthSectionOptions {
1757 output: fallow_types::output_format::OutputFormat::Human,
1758 complexity: false,
1759 file_scores: false,
1760 coverage_gaps: false,
1761 hotspots: false,
1762 targets: false,
1763 css: false,
1764 score: false,
1765 score_gate: false,
1766 snapshot_requested: false,
1767 trend: false,
1768 });
1769
1770 assert!(!derived.any_section);
1771 assert!(derived.complexity);
1772 assert!(derived.file_scores);
1773 assert!(!derived.coverage_gaps);
1774 assert!(derived.hotspots);
1775 assert!(derived.targets);
1776 assert!(derived.score);
1777 assert!(derived.force_full);
1778 assert!(!derived.score_only_output);
1779 }
1780
1781 #[test]
1782 fn health_score_gate_requests_score_only_output() {
1783 let derived = derive_health_sections(&HealthSectionOptions {
1784 output: fallow_types::output_format::OutputFormat::Human,
1785 complexity: false,
1786 file_scores: false,
1787 coverage_gaps: false,
1788 hotspots: false,
1789 targets: false,
1790 css: false,
1791 score: false,
1792 score_gate: true,
1793 snapshot_requested: false,
1794 trend: false,
1795 });
1796
1797 assert!(derived.any_section);
1798 assert!(!derived.complexity);
1799 assert!(derived.file_scores);
1800 assert!(!derived.hotspots);
1801 assert!(!derived.targets);
1802 assert!(derived.score);
1803 assert!(derived.force_full);
1804 assert!(derived.score_only_output);
1805 }
1806
1807 #[test]
1808 fn health_snapshot_keeps_full_hidden_inputs_without_section_request() {
1809 let derived = derive_health_sections(&HealthSectionOptions {
1810 output: fallow_types::output_format::OutputFormat::Human,
1811 complexity: false,
1812 file_scores: false,
1813 coverage_gaps: false,
1814 hotspots: false,
1815 targets: false,
1816 css: true,
1817 score: false,
1818 score_gate: false,
1819 snapshot_requested: true,
1820 trend: false,
1821 });
1822
1823 assert!(!derived.any_section);
1824 assert!(derived.css);
1825 assert!(derived.file_scores);
1826 assert!(derived.hotspots);
1827 assert!(derived.score);
1828 assert!(derived.force_full);
1829 }
1830}