use super::super::*;
use crate::orchestration::{pop_execution_policy, push_execution_policy};
#[test]
fn an_active_overlay_absorbs_mutations_but_not_pass_through_reads() {
use crate::testbench::overlay_fs::{install_overlay, OverlayFs};
use std::sync::Arc;
let tmp = tempfile::tempdir().unwrap();
let workspace = tmp.path().join("workspace");
let overlay_root = tmp.path().join("fixture");
std::fs::create_dir_all(&workspace).unwrap();
std::fs::create_dir_all(&overlay_root).unwrap();
let on_disk = overlay_root.join("tracked.txt");
std::fs::write(&on_disk, b"real bytes").unwrap();
let overlay = Arc::new(OverlayFs::rooted_at(&overlay_root));
let _overlay_guard = install_overlay(Arc::clone(&overlay));
push_execution_policy(CapabilityPolicy {
sandbox_profile: SandboxProfile::Worktree,
workspace_roots: vec![workspace.to_string_lossy().into_owned()],
..CapabilityPolicy::default()
});
let virtual_path = overlay_root.join("new.txt");
assert!(
check_fs_path_scope(&virtual_path, FsAccess::Write).is_ok(),
"an overlay write never reaches disk, so scope must not reject it"
);
assert!(
check_fs_path_scope(&on_disk, FsAccess::Delete).is_ok(),
"an overlay delete is recorded in the layer, not applied to disk"
);
assert!(
check_fs_path_scope(&on_disk, FsAccess::Read).is_err(),
"a pass-through read is not absorbed and must stay gated"
);
overlay.write(&virtual_path, b"alpha").unwrap();
assert!(
check_fs_path_scope(&virtual_path, FsAccess::Read).is_ok(),
"reading a path the layer holds never touches the filesystem"
);
let elsewhere = tmp.path().join("elsewhere/secret");
assert!(
check_fs_path_scope(&elsewhere, FsAccess::Write).is_err(),
"the carve-out is bounded by the overlay root"
);
pop_execution_policy();
}