#[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,
pub(crate) create_once_drifted: usize,
pub(crate) ephemeral_excluded: usize,
pub(crate) declared_user_owned: usize,
}
pub(crate) struct VerifyCoverageCounts {
pub(crate) create_once_unmarked: usize,
pub(crate) create_once_drifted: usize,
pub(crate) ephemeral_excluded: usize,
pub(crate) declared_user_owned: usize,
}
impl VerifyCoverage {
pub(crate) fn measure(
managed_paths: &std::collections::HashSet<std::path::PathBuf>,
marked_paths: &std::collections::HashSet<std::path::PathBuf>,
fresh_render_verified_paths: &std::collections::HashSet<std::path::PathBuf>,
scan: super::verify_scan::ScanCoverage,
counts: VerifyCoverageCounts,
) -> 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: counts.create_once_unmarked,
create_once_drifted: counts.create_once_drifted,
ephemeral_excluded: counts.ephemeral_excluded,
declared_user_owned: counts.declared_user_owned,
..Self::default()
};
for path in managed_paths {
if marked_paths.contains(path) || fresh_render_verified_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):".to_owned(),
format!(
" managed surface: {} path(s) this configuration would produce",
self.managed_total
),
format!(
" {} content-verified (alef marker on disk or bytes compared with this run's fresh render)",
self.managed_content_verified
),
format!(
" {} present but NOT content-verified (no readable marker and no successful fresh-render \
byte comparison: create-once seeds, user-owned files, or skipped formatter paths -- a \
present-but-wrong file passes)",
self.managed_present_only
),
];
if self.create_once_unmarked > 0 {
let settled = self.create_once_unmarked - self.create_once_drifted;
lines.push(format!(
" of which {settled} are create-once seeds with no marker that alef never \
re-attempts: written only when absent, so the missing marker is not drift \
(-vv lists them)"
));
if self.create_once_drifted > 0 {
lines.push(format!(
" and {} more that alef DOES re-render every run: on-disk content differs \
from what alef would write and the ownership guard refuses the write -- stale, \
not settled, named under the DRIFTED heading above",
self.create_once_drifted
));
}
}
lines.push(format!(
" {} absent (reported under the missing-file headings)",
self.managed_absent
));
if self.ephemeral_excluded > 0 {
lines.push(format!(
" of which {} are excluded from those headings by `[crates.verify].ignore_ephemeral` \
(declared ephemeral and never committed; still counted in the {} above)",
self.ephemeral_excluded, self.managed_absent
));
}
if self.declared_user_owned > 0 {
lines.push(format!(
" {} declared user-owned by `[workspace.ownership] user_owned` in alef.toml: not \
written, stamped or content-checked. Remove the pattern to hand a path back to alef \
(-vv lists them)",
self.declared_user_owned
));
}
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)",
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;