83 lines
2.7 KiB
Rust
83 lines
2.7 KiB
Rust
// file: crates/ksp-job-api/tests/dependency_boundary.rs
|
|
// version: 2
|
|
|
|
//! Dependency and runtime-neutrality canaries for the Job API foundation.
|
|
|
|
#[test]
|
|
fn pre_002_manifest_has_exact_core_only_dependency_graph() {
|
|
let manifest = include_str!("../Cargo.toml");
|
|
assert!(!manifest.contains("[features]"));
|
|
assert!(!manifest.contains("[dev-dependencies]"));
|
|
assert!(!manifest.contains("[build-dependencies]"));
|
|
assert_eq!(manifest.matches("[dependencies]").count(), 1);
|
|
let dependencies_tail = manifest.split("[dependencies]").nth(1);
|
|
assert!(dependencies_tail.is_some());
|
|
let dependencies_tail = match dependencies_tail {
|
|
std::option::Option::Some(value) => value,
|
|
std::option::Option::None => return,
|
|
};
|
|
let dependencies = match dependencies_tail.split("[lints]").next() {
|
|
std::option::Option::Some(value) => value,
|
|
std::option::Option::None => return,
|
|
};
|
|
assert_eq!(manifest_dependency_names(dependencies), std::vec!["ksp-core-lib"]);
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn pre_003_production_sources_forbid_runtime_domain_and_wire_dependencies() {
|
|
let sources = [
|
|
include_str!("../src/cancellation.rs"),
|
|
include_str!("../src/error.rs"),
|
|
include_str!("../src/identity.rs"),
|
|
include_str!("../src/lib.rs"),
|
|
include_str!("../src/lifecycle.rs"),
|
|
include_str!("../src/notification.rs"),
|
|
];
|
|
for source in sources {
|
|
for forbidden in [
|
|
"ksp_config_lib::",
|
|
"ksp_interface_lib::",
|
|
"ksp_logging_lib::",
|
|
"ksp_offchain_transport_lib::",
|
|
"ksp_onchain_transport_lib::",
|
|
"ksp_store_api::",
|
|
"ksp_store_lib::",
|
|
"ksp_worker",
|
|
"reqwest::",
|
|
"serde::",
|
|
"serde_json::",
|
|
"solana_",
|
|
"tauri::",
|
|
"tokio::",
|
|
"tonic::",
|
|
concat!("tracing", "::"),
|
|
] {
|
|
assert!(!source.contains(forbidden), "forbidden Job API dependency path detected: {forbidden}");
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
fn manifest_dependency_names(section: &str) -> std::vec::Vec<&str> {
|
|
let mut names = std::vec::Vec::new();
|
|
for line in section.lines() {
|
|
let content = match line.split('#').next() {
|
|
std::option::Option::Some(value) => value.trim(),
|
|
std::option::Option::None => continue,
|
|
};
|
|
if content.is_empty() {
|
|
continue;
|
|
}
|
|
let name = match content.split('=').next() {
|
|
std::option::Option::Some(value) => value.trim().trim_end_matches(".workspace"),
|
|
std::option::Option::None => continue,
|
|
};
|
|
if !name.is_empty() {
|
|
names.push(name);
|
|
}
|
|
}
|
|
names.sort_unstable();
|
|
return names;
|
|
}
|