1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//! Threshold evaluation and escalation rules for brain trait detection.
//!
//! Provides a pure evaluation function that classifies a trait as pass,
//! warn, or deny based on configurable thresholds applied to the two
//! brain trait signals (total method count, default method cognitive
//! complexity (CC) sum). Diagnostic formatting lives in the sibling
//! `diagnostic` module and is re-exported here for convenience.
//!
//! The warn rule is AND-based: both warn conditions must hold
//! simultaneously. The deny rule is OR-based: exceeding the method
//! count deny threshold triggers denial regardless of CC. Deny
//! supersedes warn.
//!
//! See `docs/brain-trust-lints-design.md` §`brain_trait` rule set for
//! the full design rationale.
use TraitMetrics;
pub use ;
// ---------------------------------------------------------------------------
// Disposition
// ---------------------------------------------------------------------------
/// Outcome of evaluating brain trait thresholds against measured metrics.
///
/// # Examples
///
/// ```
/// use whitaker_common::brain_trait_metrics::evaluation::BrainTraitDisposition;
///
/// let d = BrainTraitDisposition::Pass;
/// assert_ne!(d, BrainTraitDisposition::Warn);
/// ```
// ---------------------------------------------------------------------------
// Thresholds
// ---------------------------------------------------------------------------
/// Threshold configuration for brain trait evaluation.
///
/// The warn rule fires when ALL warn conditions hold simultaneously
/// (AND-based): total method count >= `methods_warn` AND default method
/// CC sum >= `default_cc_warn`. The deny rule fires when total method
/// count >= `methods_deny` (OR-based, independent of CC). Deny
/// supersedes warn.
///
/// Construct via [`BrainTraitThresholdsBuilder`].
///
/// # Examples
///
/// ```
/// use whitaker_common::brain_trait_metrics::evaluation::BrainTraitThresholdsBuilder;
///
/// let thresholds = BrainTraitThresholdsBuilder::new()
/// .methods_warn(25)
/// .build();
/// assert_eq!(thresholds.methods_warn(), 25);
/// ```
// ---------------------------------------------------------------------------
// Thresholds builder
// ---------------------------------------------------------------------------
const DEFAULT_METHODS_WARN: usize = 20;
const DEFAULT_METHODS_DENY: usize = 30;
const DEFAULT_CC_WARN: usize = 40;
/// Builder for [`BrainTraitThresholds`].
///
/// All fields default to the values specified in
/// `docs/brain-trust-lints-design.md` §`brain_trait` rule set.
///
/// # Examples
///
/// ```
/// use whitaker_common::brain_trait_metrics::evaluation::BrainTraitThresholdsBuilder;
///
/// let thresholds = BrainTraitThresholdsBuilder::new()
/// .methods_warn(25)
/// .default_cc_warn(50)
/// .build();
/// assert_eq!(thresholds.methods_warn(), 25);
/// assert_eq!(thresholds.default_cc_warn(), 50);
/// assert_eq!(thresholds.methods_deny(), 30); // unchanged default
/// ```
// ---------------------------------------------------------------------------
// Evaluation
// ---------------------------------------------------------------------------
/// Computes total method count (required + default), excluding
/// associated types and consts.
/// Returns `true` when the deny condition holds (OR-based).
/// Returns `true` when all warn conditions hold simultaneously (AND-based).
/// Evaluates brain trait thresholds against the given trait metrics.
///
/// Returns [`BrainTraitDisposition::Deny`] when the method count deny
/// threshold is reached (OR-based). Returns
/// [`BrainTraitDisposition::Warn`] when both the method count warn
/// threshold and the default method CC warn threshold are reached
/// simultaneously (AND-based). Returns
/// [`BrainTraitDisposition::Pass`] otherwise. Deny supersedes warn.
///
/// # Examples
///
/// ```
/// use whitaker_common::brain_trait_metrics::evaluation::{
/// BrainTraitThresholdsBuilder, evaluate_brain_trait,
/// };
/// use whitaker_common::brain_trait_metrics::TraitMetricsBuilder;
///
/// let thresholds = BrainTraitThresholdsBuilder::new().build();
/// let metrics = TraitMetricsBuilder::new("Safe").build();
/// let disposition = evaluate_brain_trait(&metrics, &thresholds);
/// assert_eq!(
/// disposition,
/// whitaker_common::brain_trait_metrics::evaluation::BrainTraitDisposition::Pass,
/// );
/// ```