Lines
95.65 %
Functions
50 %
Branches
100 %
//! The trigger host's invariant: it links nothing of the RPC registry, so no
//! script it runs can resolve a name.
use std::collections::HashSet;
use scripting::ScriptExecutor;
use super::{Finding, Subject};
use crate::natives::all_compiler_specs;
fn finding(reason: String) -> Finding {
Finding {
user: None,
subject: Subject::TriggerHost,
reason,
}
/// The number of imports the trigger linker binds, and a finding for each that
/// is also a native of the RPC registry.
pub(super) fn check() -> (usize, Vec<Finding>) {
match ScriptExecutor::try_new().and_then(|executor| executor.linked_imports()) {
Ok(imports) => (imports.len(), offenders(&imports, ®istry())),
Err(err) => (0, vec![finding(format!("cannot list the imports: {err}"))]),
fn registry() -> HashSet<(String, String)> {
all_compiler_specs()
.into_iter()
.map(|spec| (spec.import_module, spec.import_name))
.collect()
fn offenders(imports: &[(String, String)], registry: &HashSet<(String, String)>) -> Vec<Finding> {
imports
.iter()
.filter(|import| registry.contains(*import))
.map(|(module, name)| finding(format!("links the registry native {module}.{name}")))
#[cfg(test)]
mod tests;