#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub(crate) struct VerifyCoverage {
pub(crate) managed_total: usize,
pub(crate) managed_content_verified: usize,
pub(crate) managed_present_only: usize,
pub(crate) managed_absent: usize,
pub(crate) marked_outside_surface: usize,
pub(crate) files_opened: usize,
pub(crate) files_unexamined: usize,
pub(crate) create_once_unmarked: usize,
}
impl VerifyCoverage {
pub(crate) fn measure(
managed_paths: &std::collections::HashSet<std::path::PathBuf>,
marked_paths: &std::collections::HashSet<std::path::PathBuf>,
scan: super::verify_scan::ScanCoverage,
create_once_unmarked: usize,
) -> Self {
let mut coverage = Self {
managed_total: managed_paths.len(),
marked_outside_surface: marked_paths.difference(managed_paths).count(),
files_opened: scan.opened,
files_unexamined: scan.unexamined,
create_once_unmarked,
..Self::default()
};
for path in managed_paths {
if marked_paths.contains(path) {
coverage.managed_content_verified += 1;
} else if path.exists() {
coverage.managed_present_only += 1;
} else {
coverage.managed_absent += 1;
}
}
coverage
}
pub(crate) fn report_lines(&self) -> Vec<String> {
let mut lines = vec![
"Verify coverage (what this run examined, so a green result is not read as more \
than it is):"
.to_owned(),
format!(
" managed surface: {} path(s) this configuration would produce",
self.managed_total
),
format!(
" {} content-verified (alef marker on disk, hashed against current generation inputs)",
self.managed_content_verified
),
format!(
" {} present but NOT content-verified (no readable marker: create-once seeds, formats \
that cannot carry one, paths proven by .alef-ownership.toml -- presence is the whole check, \
so a present-but-wrong file passes)",
self.managed_present_only
),
];
if self.create_once_unmarked > 0 {
lines.push(format!(
" of which {} are create-once seeds with no marker: alef writes each of these \
paths only when absent and never revisits it, so the missing marker is the \
documented user-owned steady state, not drift -- nothing needs adopting and no \
rerun changes this line (-vv lists them)",
self.create_once_unmarked
));
}
lines.push(format!(
" {} absent (reported under the missing-file headings)",
self.managed_absent
));
lines.push(format!(
" tree walk: {} file(s) opened, {} never examined (name and extension outside the \
ownership walk's scan set, or not readable as text -- nothing about their contents \
entered this result)",
self.files_opened, self.files_unexamined
));
if self.marked_outside_surface > 0 {
lines.push(format!(
" {} alef-marked file(s) on disk are not claimed by this run's managed surface \
(the orphan check reports whichever of them it can attribute to a dropped emit)",
self.marked_outside_surface
));
}
lines
}
}
#[cfg(test)]
mod tests;