@lamentis/naome 1.3.11 → 1.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +2 -2
- package/crates/naome-cli/Cargo.toml +1 -1
- package/crates/naome-cli/src/architecture_commands.rs +2 -6
- package/crates/naome-cli/tests/architecture_cli.rs +60 -0
- package/crates/naome-core/Cargo.toml +1 -1
- package/crates/naome-core/src/architecture/config/parser/sections.rs +44 -1
- package/crates/naome-core/src/architecture/config/parser.rs +1 -0
- package/crates/naome-core/src/architecture/config.rs +35 -0
- package/crates/naome-core/src/architecture/output.rs +15 -1
- package/crates/naome-core/src/architecture/rules/budgets.rs +179 -0
- package/crates/naome-core/src/architecture/rules/context.rs +138 -0
- package/crates/naome-core/src/architecture/rules/cycles.rs +39 -0
- package/crates/naome-core/src/architecture/rules/external.rs +244 -0
- package/crates/naome-core/src/architecture/rules/graph.rs +177 -0
- package/crates/naome-core/src/architecture/rules/transitive.rs +89 -0
- package/crates/naome-core/src/architecture/rules.rs +13 -39
- package/crates/naome-core/src/architecture/scan/graph_builder.rs +130 -30
- package/crates/naome-core/src/architecture/scan/imports/extractors/swift.rs +48 -0
- package/crates/naome-core/src/architecture/scan/imports/extractors.rs +7 -7
- package/crates/naome-core/src/architecture/scan/imports/resolver.rs +44 -22
- package/crates/naome-core/src/architecture/scan/imports.rs +17 -0
- package/crates/naome-core/src/architecture/scan/manifest/common.rs +102 -0
- package/crates/naome-core/src/architecture/scan/manifest/parsers/json.rs +46 -0
- package/crates/naome-core/src/architecture/scan/manifest/parsers/other.rs +280 -0
- package/crates/naome-core/src/architecture/scan/manifest/parsers/toml.rs +184 -0
- package/crates/naome-core/src/architecture/scan/manifest/parsers.rs +3 -0
- package/crates/naome-core/src/architecture/scan/manifest.rs +33 -0
- package/crates/naome-core/src/architecture/scan.rs +27 -1
- package/crates/naome-core/src/architecture.rs +1 -1
- package/crates/naome-core/src/lib.rs +1 -0
- package/crates/naome-core/tests/architecture.rs +53 -85
- package/crates/naome-core/tests/architecture_manifests.rs +289 -0
- package/crates/naome-core/tests/architecture_rules.rs +498 -0
- package/crates/naome-core/tests/architecture_support/mod.rs +80 -0
- package/crates/naome-core/tests/architecture_swift.rs +111 -0
- package/installer/harness-files.js +3 -3
- package/native/darwin-arm64/naome +0 -0
- package/native/linux-x64/naome +0 -0
- package/package.json +1 -1
- package/templates/naome-root/.naome/manifest.json +2 -2
- package/templates/naome-root/docs/naome/architecture-fitness.md +61 -8
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
use crate::architecture::output::ArchitectureViolation;
|
|
2
|
+
use crate::architecture::scan::{ArchitectureScanReport, ImportTarget};
|
|
3
|
+
use crate::paths;
|
|
4
|
+
|
|
5
|
+
pub(super) fn validate_external_dependency_policy(
|
|
6
|
+
scan: &ArchitectureScanReport,
|
|
7
|
+
violations: &mut Vec<ArchitectureViolation>,
|
|
8
|
+
rules_executed: &mut Vec<String>,
|
|
9
|
+
) {
|
|
10
|
+
let rule = scan.config.rule("external_dependency_policy");
|
|
11
|
+
if !rule.enabled {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
rules_executed.push("arch.external_dependency_policy".to_string());
|
|
15
|
+
for fact in scan.file_facts.values() {
|
|
16
|
+
let owners = fact
|
|
17
|
+
.layers
|
|
18
|
+
.iter()
|
|
19
|
+
.chain(fact.contexts.iter())
|
|
20
|
+
.collect::<Vec<_>>();
|
|
21
|
+
for import in &fact.imports {
|
|
22
|
+
let ImportTarget::ExternalDependency(package) = &import.target else {
|
|
23
|
+
continue;
|
|
24
|
+
};
|
|
25
|
+
if is_standard_library_dependency(fact.language.as_deref(), package) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
for owner in &owners {
|
|
29
|
+
let Some(policy) = scan.config.external_dependencies.get(*owner) else {
|
|
30
|
+
continue;
|
|
31
|
+
};
|
|
32
|
+
if paths::matches_any(package, &policy.allow) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
violations.push(ArchitectureViolation {
|
|
36
|
+
id: "arch.external_dependency_policy".to_string(),
|
|
37
|
+
severity: rule.severity,
|
|
38
|
+
violation_type: "external_dependency_policy".to_string(),
|
|
39
|
+
message: format!(
|
|
40
|
+
"{} in {} imports external dependency {} without policy allowance.",
|
|
41
|
+
fact.path, owner, package
|
|
42
|
+
),
|
|
43
|
+
from: Some(format!("file:{}", fact.path)),
|
|
44
|
+
to: Some(format!("external:{package}")),
|
|
45
|
+
path: Some(fact.path.clone()),
|
|
46
|
+
source_range: import.source_range.clone(),
|
|
47
|
+
suggestion: format!(
|
|
48
|
+
"Move {} behind an allowed adapter or add it to external_dependencies.{}.allow with intent.",
|
|
49
|
+
package, owner
|
|
50
|
+
),
|
|
51
|
+
agent_instruction: format!(
|
|
52
|
+
"Do not import external dependency {} from {}; use an allowed boundary.",
|
|
53
|
+
package, owner
|
|
54
|
+
),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fn is_standard_library_dependency(language: Option<&str>, package: &str) -> bool {
|
|
62
|
+
let root = package
|
|
63
|
+
.strip_prefix("node:")
|
|
64
|
+
.unwrap_or(package)
|
|
65
|
+
.split(['/', '.', ':'])
|
|
66
|
+
.next()
|
|
67
|
+
.unwrap_or(package);
|
|
68
|
+
match language {
|
|
69
|
+
Some("go") => !package
|
|
70
|
+
.split('/')
|
|
71
|
+
.next()
|
|
72
|
+
.is_some_and(|prefix| prefix.contains('.')),
|
|
73
|
+
Some("javascript") | Some("typescript") => NODE_BUILTINS.contains(&root),
|
|
74
|
+
Some("python") => PYTHON_STDLIB.contains(&root),
|
|
75
|
+
Some("rust") => matches!(root, "std" | "core" | "alloc" | "proc_macro" | "test"),
|
|
76
|
+
Some("swift") => SWIFT_APPLE_FRAMEWORKS.contains(&root),
|
|
77
|
+
_ => false,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const NODE_BUILTINS: &[&str] = &[
|
|
82
|
+
"assert",
|
|
83
|
+
"async_hooks",
|
|
84
|
+
"buffer",
|
|
85
|
+
"child_process",
|
|
86
|
+
"cluster",
|
|
87
|
+
"console",
|
|
88
|
+
"constants",
|
|
89
|
+
"crypto",
|
|
90
|
+
"diagnostics_channel",
|
|
91
|
+
"dns",
|
|
92
|
+
"domain",
|
|
93
|
+
"events",
|
|
94
|
+
"fs",
|
|
95
|
+
"http",
|
|
96
|
+
"http2",
|
|
97
|
+
"https",
|
|
98
|
+
"inspector",
|
|
99
|
+
"module",
|
|
100
|
+
"net",
|
|
101
|
+
"os",
|
|
102
|
+
"path",
|
|
103
|
+
"perf_hooks",
|
|
104
|
+
"process",
|
|
105
|
+
"punycode",
|
|
106
|
+
"querystring",
|
|
107
|
+
"readline",
|
|
108
|
+
"repl",
|
|
109
|
+
"stream",
|
|
110
|
+
"string_decoder",
|
|
111
|
+
"timers",
|
|
112
|
+
"tls",
|
|
113
|
+
"trace_events",
|
|
114
|
+
"tty",
|
|
115
|
+
"url",
|
|
116
|
+
"util",
|
|
117
|
+
"v8",
|
|
118
|
+
"vm",
|
|
119
|
+
"wasi",
|
|
120
|
+
"worker_threads",
|
|
121
|
+
"zlib",
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
const PYTHON_STDLIB: &[&str] = &[
|
|
125
|
+
"abc",
|
|
126
|
+
"argparse",
|
|
127
|
+
"array",
|
|
128
|
+
"ast",
|
|
129
|
+
"asyncio",
|
|
130
|
+
"base64",
|
|
131
|
+
"bisect",
|
|
132
|
+
"calendar",
|
|
133
|
+
"collections",
|
|
134
|
+
"concurrent",
|
|
135
|
+
"contextlib",
|
|
136
|
+
"copy",
|
|
137
|
+
"csv",
|
|
138
|
+
"dataclasses",
|
|
139
|
+
"datetime",
|
|
140
|
+
"decimal",
|
|
141
|
+
"email",
|
|
142
|
+
"enum",
|
|
143
|
+
"functools",
|
|
144
|
+
"glob",
|
|
145
|
+
"gzip",
|
|
146
|
+
"hashlib",
|
|
147
|
+
"heapq",
|
|
148
|
+
"hmac",
|
|
149
|
+
"html",
|
|
150
|
+
"http",
|
|
151
|
+
"importlib",
|
|
152
|
+
"inspect",
|
|
153
|
+
"io",
|
|
154
|
+
"itertools",
|
|
155
|
+
"json",
|
|
156
|
+
"logging",
|
|
157
|
+
"math",
|
|
158
|
+
"multiprocessing",
|
|
159
|
+
"operator",
|
|
160
|
+
"os",
|
|
161
|
+
"pathlib",
|
|
162
|
+
"pickle",
|
|
163
|
+
"platform",
|
|
164
|
+
"queue",
|
|
165
|
+
"random",
|
|
166
|
+
"re",
|
|
167
|
+
"shlex",
|
|
168
|
+
"shutil",
|
|
169
|
+
"signal",
|
|
170
|
+
"socket",
|
|
171
|
+
"sqlite3",
|
|
172
|
+
"statistics",
|
|
173
|
+
"string",
|
|
174
|
+
"subprocess",
|
|
175
|
+
"sys",
|
|
176
|
+
"tempfile",
|
|
177
|
+
"threading",
|
|
178
|
+
"time",
|
|
179
|
+
"traceback",
|
|
180
|
+
"typing",
|
|
181
|
+
"unittest",
|
|
182
|
+
"urllib",
|
|
183
|
+
"uuid",
|
|
184
|
+
"xml",
|
|
185
|
+
"zipfile",
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const SWIFT_APPLE_FRAMEWORKS: &[&str] = &[
|
|
189
|
+
"Accelerate",
|
|
190
|
+
"AppIntents",
|
|
191
|
+
"AppKit",
|
|
192
|
+
"ARKit",
|
|
193
|
+
"AVFoundation",
|
|
194
|
+
"CloudKit",
|
|
195
|
+
"Combine",
|
|
196
|
+
"CoreData",
|
|
197
|
+
"CoreFoundation",
|
|
198
|
+
"CoreBluetooth",
|
|
199
|
+
"CoreGraphics",
|
|
200
|
+
"CoreImage",
|
|
201
|
+
"CoreLocation",
|
|
202
|
+
"CoreML",
|
|
203
|
+
"CoreMotion",
|
|
204
|
+
"CoreNFC",
|
|
205
|
+
"CoreSpotlight",
|
|
206
|
+
"CoreTelephony",
|
|
207
|
+
"CoreText",
|
|
208
|
+
"CryptoKit",
|
|
209
|
+
"Dispatch",
|
|
210
|
+
"EventKit",
|
|
211
|
+
"Foundation",
|
|
212
|
+
"GameKit",
|
|
213
|
+
"HealthKit",
|
|
214
|
+
"LocalAuthentication",
|
|
215
|
+
"MapKit",
|
|
216
|
+
"MessageUI",
|
|
217
|
+
"Metal",
|
|
218
|
+
"MetalKit",
|
|
219
|
+
"NaturalLanguage",
|
|
220
|
+
"Network",
|
|
221
|
+
"Observation",
|
|
222
|
+
"PassKit",
|
|
223
|
+
"PencilKit",
|
|
224
|
+
"Photos",
|
|
225
|
+
"QuartzCore",
|
|
226
|
+
"RealityKit",
|
|
227
|
+
"SafariServices",
|
|
228
|
+
"SceneKit",
|
|
229
|
+
"Security",
|
|
230
|
+
"SpriteKit",
|
|
231
|
+
"StoreKit",
|
|
232
|
+
"Swift",
|
|
233
|
+
"SwiftData",
|
|
234
|
+
"SwiftUI",
|
|
235
|
+
"ThreadNetwork",
|
|
236
|
+
"UIKit",
|
|
237
|
+
"UniformTypeIdentifiers",
|
|
238
|
+
"UserNotifications",
|
|
239
|
+
"Vision",
|
|
240
|
+
"WatchKit",
|
|
241
|
+
"WebKit",
|
|
242
|
+
"WidgetKit",
|
|
243
|
+
"XCTest",
|
|
244
|
+
];
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
|
|
3
|
+
use crate::architecture::model::ArchitectureEdgeKind;
|
|
4
|
+
use crate::architecture::scan::ArchitectureScanReport;
|
|
5
|
+
|
|
6
|
+
#[derive(Debug, Clone)]
|
|
7
|
+
pub(super) struct ImportEdge<'a> {
|
|
8
|
+
pub(super) from_path: &'a str,
|
|
9
|
+
pub(super) to_path: &'a str,
|
|
10
|
+
pub(super) edge_index: usize,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pub(super) fn file_import_edges(scan: &ArchitectureScanReport) -> Vec<ImportEdge<'_>> {
|
|
14
|
+
scan.graph
|
|
15
|
+
.edges
|
|
16
|
+
.iter()
|
|
17
|
+
.enumerate()
|
|
18
|
+
.filter_map(|(edge_index, edge)| {
|
|
19
|
+
(edge.kind == ArchitectureEdgeKind::Imports)
|
|
20
|
+
.then(|| {
|
|
21
|
+
Some(ImportEdge {
|
|
22
|
+
from_path: edge.from.strip_prefix("file:")?,
|
|
23
|
+
to_path: edge.to.strip_prefix("file:")?,
|
|
24
|
+
edge_index,
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
.flatten()
|
|
28
|
+
})
|
|
29
|
+
.collect()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub(super) fn file_import_adjacency(
|
|
33
|
+
scan: &ArchitectureScanReport,
|
|
34
|
+
) -> BTreeMap<String, Vec<String>> {
|
|
35
|
+
file_adjacency(file_import_edges(scan).into_iter())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
pub(super) fn file_cycle_adjacency(scan: &ArchitectureScanReport) -> BTreeMap<String, Vec<String>> {
|
|
39
|
+
file_adjacency(
|
|
40
|
+
file_import_edges(scan)
|
|
41
|
+
.into_iter()
|
|
42
|
+
.filter(|edge| is_cycle_dependency(scan, edge)),
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fn file_adjacency<'a>(
|
|
47
|
+
edges: impl Iterator<Item = ImportEdge<'a>>,
|
|
48
|
+
) -> BTreeMap<String, Vec<String>> {
|
|
49
|
+
let mut adjacency = BTreeMap::<String, BTreeSet<String>>::new();
|
|
50
|
+
for edge in edges {
|
|
51
|
+
adjacency
|
|
52
|
+
.entry(edge.from_path.to_string())
|
|
53
|
+
.or_default()
|
|
54
|
+
.insert(edge.to_path.to_string());
|
|
55
|
+
}
|
|
56
|
+
adjacency
|
|
57
|
+
.into_iter()
|
|
58
|
+
.map(|(from, targets)| (from, targets.into_iter().collect()))
|
|
59
|
+
.collect()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn is_cycle_dependency(scan: &ArchitectureScanReport, edge: &ImportEdge<'_>) -> bool {
|
|
63
|
+
let graph_edge = &scan.graph.edges[edge.edge_index];
|
|
64
|
+
if graph_edge.metadata.language.as_deref() != Some("rust") {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
let specifier = graph_edge
|
|
68
|
+
.metadata
|
|
69
|
+
.raw_origin
|
|
70
|
+
.get("specifier")
|
|
71
|
+
.and_then(serde_json::Value::as_str)
|
|
72
|
+
.unwrap_or_default();
|
|
73
|
+
!is_rust_module_cycle_exempt(edge.from_path, edge.to_path, specifier)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fn is_rust_module_cycle_exempt(from_path: &str, to_path: &str, specifier: &str) -> bool {
|
|
77
|
+
if !is_rust_module_family_reference(specifier) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
is_rust_parent_child_module_family(from_path, to_path)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fn is_rust_module_family_reference(specifier: &str) -> bool {
|
|
84
|
+
specifier.starts_with("self::")
|
|
85
|
+
|| specifier.starts_with("super::")
|
|
86
|
+
|| specifier.starts_with("crate::")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn is_rust_parent_child_module_family(from_path: &str, to_path: &str) -> bool {
|
|
90
|
+
let Some(from_module) = rust_module_id(from_path) else {
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
let Some(to_module) = rust_module_id(to_path) else {
|
|
94
|
+
return false;
|
|
95
|
+
};
|
|
96
|
+
if from_module == to_module {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
from_module
|
|
100
|
+
.strip_prefix(&to_module)
|
|
101
|
+
.is_some_and(|suffix| suffix.starts_with('/'))
|
|
102
|
+
|| to_module
|
|
103
|
+
.strip_prefix(&from_module)
|
|
104
|
+
.is_some_and(|suffix| suffix.starts_with('/'))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fn rust_module_id(path: &str) -> Option<String> {
|
|
108
|
+
path.strip_suffix("/mod.rs")
|
|
109
|
+
.map(ToString::to_string)
|
|
110
|
+
.or_else(|| path.strip_suffix(".rs").map(ToString::to_string))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
pub(super) fn strongly_connected_components(
|
|
114
|
+
adjacency: &BTreeMap<String, Vec<String>>,
|
|
115
|
+
) -> Vec<Vec<String>> {
|
|
116
|
+
let mut state = TarjanState::default();
|
|
117
|
+
for node in adjacency.keys() {
|
|
118
|
+
if !state.indices.contains_key(node) {
|
|
119
|
+
strong_connect(node, adjacency, &mut state);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
state
|
|
123
|
+
.components
|
|
124
|
+
.into_iter()
|
|
125
|
+
.filter(|component| {
|
|
126
|
+
component.len() > 1
|
|
127
|
+
|| component.first().is_some_and(|node| {
|
|
128
|
+
adjacency
|
|
129
|
+
.get(node)
|
|
130
|
+
.is_some_and(|targets| targets.contains(node))
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
.collect()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#[derive(Default)]
|
|
137
|
+
struct TarjanState {
|
|
138
|
+
next_index: usize,
|
|
139
|
+
stack: Vec<String>,
|
|
140
|
+
on_stack: BTreeSet<String>,
|
|
141
|
+
indices: BTreeMap<String, usize>,
|
|
142
|
+
lowlinks: BTreeMap<String, usize>,
|
|
143
|
+
components: Vec<Vec<String>>,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fn strong_connect(node: &str, adjacency: &BTreeMap<String, Vec<String>>, state: &mut TarjanState) {
|
|
147
|
+
let index = state.next_index;
|
|
148
|
+
state.next_index += 1;
|
|
149
|
+
state.indices.insert(node.to_string(), index);
|
|
150
|
+
state.lowlinks.insert(node.to_string(), index);
|
|
151
|
+
state.stack.push(node.to_string());
|
|
152
|
+
state.on_stack.insert(node.to_string());
|
|
153
|
+
|
|
154
|
+
for target in adjacency.get(node).into_iter().flatten() {
|
|
155
|
+
if !state.indices.contains_key(target) {
|
|
156
|
+
strong_connect(target, adjacency, state);
|
|
157
|
+
let lowlink = state.lowlinks[node].min(state.lowlinks[target]);
|
|
158
|
+
state.lowlinks.insert(node.to_string(), lowlink);
|
|
159
|
+
} else if state.on_stack.contains(target) {
|
|
160
|
+
let lowlink = state.lowlinks[node].min(state.indices[target]);
|
|
161
|
+
state.lowlinks.insert(node.to_string(), lowlink);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if state.lowlinks[node] == state.indices[node] {
|
|
166
|
+
let mut component = Vec::new();
|
|
167
|
+
while let Some(member) = state.stack.pop() {
|
|
168
|
+
state.on_stack.remove(&member);
|
|
169
|
+
component.push(member.clone());
|
|
170
|
+
if member == node {
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
component.sort();
|
|
175
|
+
state.components.push(component);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
|
2
|
+
|
|
3
|
+
use crate::architecture::output::ArchitectureViolation;
|
|
4
|
+
use crate::architecture::scan::ArchitectureScanReport;
|
|
5
|
+
|
|
6
|
+
use super::graph;
|
|
7
|
+
|
|
8
|
+
pub(super) fn validate_transitive_layer_dependencies(
|
|
9
|
+
scan: &ArchitectureScanReport,
|
|
10
|
+
violations: &mut Vec<ArchitectureViolation>,
|
|
11
|
+
rules_executed: &mut Vec<String>,
|
|
12
|
+
) {
|
|
13
|
+
let rule = scan
|
|
14
|
+
.config
|
|
15
|
+
.rule("no_transitive_forbidden_layer_dependencies");
|
|
16
|
+
if !rule.enabled {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
rules_executed.push("arch.no_transitive_forbidden_layer_dependencies".to_string());
|
|
20
|
+
let adjacency = graph::file_import_adjacency(scan);
|
|
21
|
+
for (from_path, from_fact) in &scan.file_facts {
|
|
22
|
+
for from_layer in &from_fact.layers {
|
|
23
|
+
let Some((target_path, target_layers)) =
|
|
24
|
+
first_forbidden_target(scan, &adjacency, from_path, from_layer)
|
|
25
|
+
else {
|
|
26
|
+
continue;
|
|
27
|
+
};
|
|
28
|
+
violations.push(ArchitectureViolation {
|
|
29
|
+
id: "arch.no_transitive_forbidden_layer_dependencies".to_string(),
|
|
30
|
+
severity: rule.severity,
|
|
31
|
+
violation_type: "transitive_forbidden_dependency".to_string(),
|
|
32
|
+
message: format!(
|
|
33
|
+
"{from_path} in layer {from_layer} transitively reaches {target_path} in forbidden layer {target_layers}."
|
|
34
|
+
),
|
|
35
|
+
from: Some(format!("file:{from_path}")),
|
|
36
|
+
to: Some(format!("file:{target_path}")),
|
|
37
|
+
path: Some(from_path.clone()),
|
|
38
|
+
source_range: None,
|
|
39
|
+
suggestion: "Remove the indirect dependency chain or introduce an allowed boundary."
|
|
40
|
+
.to_string(),
|
|
41
|
+
agent_instruction:
|
|
42
|
+
"Do not reach forbidden layers indirectly; move the dependency behind an allowed interface."
|
|
43
|
+
.to_string(),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn first_forbidden_target(
|
|
50
|
+
scan: &ArchitectureScanReport,
|
|
51
|
+
adjacency: &BTreeMap<String, Vec<String>>,
|
|
52
|
+
from_path: &str,
|
|
53
|
+
from_layer: &str,
|
|
54
|
+
) -> Option<(String, String)> {
|
|
55
|
+
let mut queue = VecDeque::new();
|
|
56
|
+
let mut visited = BTreeSet::new();
|
|
57
|
+
for target in adjacency.get(from_path).into_iter().flatten() {
|
|
58
|
+
queue.push_back((target.clone(), 1usize));
|
|
59
|
+
}
|
|
60
|
+
while let Some((path, depth)) = queue.pop_front() {
|
|
61
|
+
if !visited.insert(path.clone()) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if depth > 1 {
|
|
65
|
+
let Some(fact) = scan.file_facts.get(&path) else {
|
|
66
|
+
continue;
|
|
67
|
+
};
|
|
68
|
+
if !fact.layers.is_empty() && !layer_allowed(scan, from_layer, &fact.layers) {
|
|
69
|
+
return Some((path, fact.layers.join(", ")));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for target in adjacency.get(&path).into_iter().flatten() {
|
|
73
|
+
queue.push_back((target.clone(), depth + 1));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
None
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fn layer_allowed(scan: &ArchitectureScanReport, from_layer: &str, targets: &[String]) -> bool {
|
|
80
|
+
let allowed = scan
|
|
81
|
+
.config
|
|
82
|
+
.allowed_dependencies
|
|
83
|
+
.get(from_layer)
|
|
84
|
+
.map(Vec::as_slice)
|
|
85
|
+
.unwrap_or(&[]);
|
|
86
|
+
targets
|
|
87
|
+
.iter()
|
|
88
|
+
.any(|to_layer| from_layer == to_layer || allowed.contains(to_layer))
|
|
89
|
+
}
|
|
@@ -7,13 +7,25 @@ use super::output::{
|
|
|
7
7
|
use super::scan::ArchitectureScanReport;
|
|
8
8
|
use crate::architecture::model::ArchitectureEdgeKind;
|
|
9
9
|
|
|
10
|
+
mod budgets;
|
|
11
|
+
mod context;
|
|
12
|
+
mod cycles;
|
|
13
|
+
mod external;
|
|
14
|
+
mod graph;
|
|
15
|
+
mod transitive;
|
|
16
|
+
|
|
10
17
|
pub fn validate_scan(scan: ArchitectureScanReport) -> ArchitectureValidation {
|
|
11
18
|
let mut violations = Vec::new();
|
|
12
19
|
let mut rules_executed = Vec::new();
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
budgets::validate_file_size_budget(&scan, &mut violations, &mut rules_executed);
|
|
15
22
|
validate_generated_manual_boundary(&scan, &mut violations, &mut rules_executed);
|
|
16
23
|
validate_forbidden_layer_dependencies(&scan, &mut violations, &mut rules_executed);
|
|
24
|
+
context::validate_context_rules(&scan, &mut violations, &mut rules_executed);
|
|
25
|
+
cycles::validate_cycles(&scan, &mut violations, &mut rules_executed);
|
|
26
|
+
transitive::validate_transitive_layer_dependencies(&scan, &mut violations, &mut rules_executed);
|
|
27
|
+
budgets::validate_dependency_budgets(&scan, &mut violations, &mut rules_executed);
|
|
28
|
+
external::validate_external_dependency_policy(&scan, &mut violations, &mut rules_executed);
|
|
17
29
|
|
|
18
30
|
violations.sort_by(|left, right| {
|
|
19
31
|
(
|
|
@@ -118,44 +130,6 @@ fn validate_forbidden_layer_dependencies(
|
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
132
|
|
|
121
|
-
fn validate_max_file_lines(
|
|
122
|
-
scan: &ArchitectureScanReport,
|
|
123
|
-
violations: &mut Vec<ArchitectureViolation>,
|
|
124
|
-
rules_executed: &mut Vec<String>,
|
|
125
|
-
) {
|
|
126
|
-
let rule = scan.config.rule("max_file_lines");
|
|
127
|
-
if !rule.enabled {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
rules_executed.push("arch.max_file_lines".to_string());
|
|
131
|
-
let Some(limit) = rule.value else {
|
|
132
|
-
return;
|
|
133
|
-
};
|
|
134
|
-
for fact in scan.file_facts.values() {
|
|
135
|
-
if fact.line_count <= limit {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
violations.push(ArchitectureViolation {
|
|
139
|
-
id: "arch.max_file_lines".to_string(),
|
|
140
|
-
severity: rule.severity,
|
|
141
|
-
violation_type: "file_size_budget".to_string(),
|
|
142
|
-
message: format!(
|
|
143
|
-
"{} has {} lines, exceeding the configured budget of {}.",
|
|
144
|
-
fact.path, fact.line_count, limit
|
|
145
|
-
),
|
|
146
|
-
from: Some(format!("file:{}", fact.path)),
|
|
147
|
-
to: None,
|
|
148
|
-
path: Some(fact.path.clone()),
|
|
149
|
-
source_range: None,
|
|
150
|
-
suggestion: "Split the file into cohesive modules or move generated content behind an explicit ignore rule.".to_string(),
|
|
151
|
-
agent_instruction: format!(
|
|
152
|
-
"Reduce {} below {} lines or add a justified generated-code ignore rule if it is not manually owned.",
|
|
153
|
-
fact.path, limit
|
|
154
|
-
),
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
133
|
fn validate_generated_manual_boundary(
|
|
160
134
|
scan: &ArchitectureScanReport,
|
|
161
135
|
violations: &mut Vec<ArchitectureViolation>,
|