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
//! Shared dependency and purity types for function debt items
//!
//! Provides structures for tracking function-level dependencies (upstream/downstream)
//! and purity analysis results.
use serde::{Deserialize, Serialize};
/// Dependency information for function debt items
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Dependencies {
pub upstream_count: usize,
pub downstream_count: usize,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub upstream_callers: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub downstream_callees: Vec<String>,
/// Blast radius: upstream + downstream (impact of changes)
#[serde(default, skip_serializing_if = "is_zero")]
pub blast_radius: usize,
/// Whether this function is on a critical path (high upstream or downstream)
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub critical_path: bool,
/// Coupling classification: "Stable Core", "Leaf Module", "Hub", "Connector"
#[serde(skip_serializing_if = "Option::is_none")]
pub coupling_classification: Option<String>,
/// Instability metric: Ce/(Ca+Ce) where Ce=downstream, Ca=upstream (0.0-1.0)
#[serde(skip_serializing_if = "Option::is_none")]
pub instability: Option<f64>,
// Spec 267: Separate test vs production callers for accurate blast radius
/// Production upstream callers (excludes test functions)
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub upstream_production_callers: Vec<String>,
/// Test upstream callers (test functions, test helpers, mocks, fixtures)
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub upstream_test_callers: Vec<String>,
/// Count of production upstream callers (Spec 267)
#[serde(default, skip_serializing_if = "is_zero")]
pub production_upstream_count: usize,
/// Count of test upstream callers (Spec 267)
#[serde(default, skip_serializing_if = "is_zero")]
pub test_upstream_count: usize,
/// Production-only blast radius: production_upstream_count + downstream_count (Spec 267)
/// This is the true change risk metric - test callers don't increase change risk.
#[serde(default, skip_serializing_if = "is_zero")]
pub production_blast_radius: usize,
}
fn is_zero(val: &usize) -> bool {
*val == 0
}
/// Purity analysis results
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PurityAnalysis {
pub is_pure: bool,
pub confidence: f32,
/// Purity level: "StrictlyPure", "LocallyPure", "ReadOnly", "Impure"
#[serde(skip_serializing_if = "Option::is_none")]
pub purity_level: Option<String>,
/// Reasons why the function is not strictly pure
#[serde(skip_serializing_if = "Option::is_none")]
pub side_effects: Option<Vec<String>>,
}