Skip to main content

fallow_engine/health/
pipeline.rs

1//! Health pipeline carrier types shared by the engine health executor.
2
3use std::path::PathBuf;
4
5use fallow_config::ResolvedConfig;
6use fallow_output::DiffIndex;
7use fallow_types::workspace::WorkspaceDiagnostic;
8use rustc_hash::{FxHashMap, FxHashSet};
9
10/// Discovery / parse inputs the CLI resolves before calling the engine.
11pub struct HealthPipelineInputs {
12    pub config: ResolvedConfig,
13    pub files: Vec<fallow_types::discover::DiscoveredFile>,
14    pub modules: Vec<fallow_types::extract::ModuleInfo>,
15    /// Pre-parse pipeline timings (config / discover / parse milliseconds).
16    pub config_ms: f64,
17    pub discover_ms: f64,
18    pub parse_ms: f64,
19    pub parse_cpu_ms: f64,
20    /// True when discover + parse were reused from the upstream check pass.
21    pub shared_parse: bool,
22    pub pre_computed_analysis: Option<crate::DeadCodeAnalysisArtifacts>,
23    pub workspace_diagnostics: Vec<WorkspaceDiagnostic>,
24}
25
26/// Scope inputs the CLI resolves before calling the engine.
27///
28/// The engine no longer fetches changed files, workspace roots, the shared diff
29/// index, or the CODEOWNERS-backed grouping resolver itself: those touch CLI
30/// state (the shared-diff `OnceLock`, CODEOWNERS parsing, workspace discovery
31/// error rendering), so the CLI resolves them and threads them in here.
32pub struct HealthScopeInputs<'a, R> {
33    pub changed_files: Option<FxHashSet<PathBuf>>,
34    pub diff_index: Option<&'a DiffIndex>,
35    pub ws_roots: Option<Vec<PathBuf>>,
36    pub group_resolver: Option<R>,
37}
38
39pub(super) struct HealthPipelineTimings {
40    pub(super) config: f64,
41    pub(super) discover: f64,
42    pub(super) parse: f64,
43    /// Summed parse CPU time across rayon workers; `0.0` when parse was reused.
44    pub(super) parse_cpu: f64,
45    /// True when discover + parse were reused from the upstream check pass.
46    pub(super) shared_parse: bool,
47}
48
49impl HealthPipelineTimings {
50    pub(super) fn into_base_input(self, complexity_ms: f64) -> HealthTimingBaseInput {
51        HealthTimingBaseInput {
52            config_ms: self.config,
53            discover_ms: self.discover,
54            parse_ms: self.parse,
55            parse_cpu_ms: self.parse_cpu,
56            complexity_ms,
57            shared_parse: self.shared_parse,
58        }
59    }
60}
61
62pub(super) struct HealthScope<'a, R> {
63    pub(super) max_cyclomatic: u16,
64    pub(super) max_cognitive: u16,
65    pub(super) max_crap: f64,
66    pub(super) enforce_crap: bool,
67    pub(super) ignore_set: globset::GlobSet,
68    pub(super) changed_files: Option<FxHashSet<PathBuf>>,
69    pub(super) diff_index: Option<&'a DiffIndex>,
70    pub(super) ws_roots: Option<Vec<PathBuf>>,
71    pub(super) group_resolver: Option<R>,
72    pub(super) file_paths: FxHashMap<crate::discover::FileId, &'a PathBuf>,
73}
74
75pub(super) struct HealthTimingBaseInput {
76    pub(super) config_ms: f64,
77    pub(super) discover_ms: f64,
78    pub(super) parse_ms: f64,
79    pub(super) parse_cpu_ms: f64,
80    pub(super) complexity_ms: f64,
81    pub(super) shared_parse: bool,
82}