Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/openhuman-core/src/security/live_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ pub fn generation() -> u64 {
/// Rebuild the policy from `autonomy_config` against the stored workspace dir
/// and swap it in, bumping the generation counter. No-op if nothing has been
/// installed yet (e.g. a CLI invocation that never started a session runtime).
/// A test thread holding an `install_scoped` policy owns its policy, so its
/// reloads never reach the process-global one that sibling tests read.
pub fn reload_from(autonomy_config: &crate::config::AutonomyConfig) {
#[cfg(test)]
if TEST_POLICY_OVERRIDE.with(|current| current.borrow().is_some()) {
tracing::trace!("[security:live_policy] reload skipped for scoped test policy");
return;
}
Comment thread
M3gA-Mind marked this conversation as resolved.
Resolved
let Some(state) = STATE.get() else {
return;
};
Expand Down
34 changes: 34 additions & 0 deletions crates/openhuman-core/src/security/live_policy_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,40 @@ fn scoped_policy_is_thread_local_and_restored() {
);
}

#[test]
fn a_reload_on_a_scoped_thread_leaves_the_process_policy_alone() {
let _env = crate::config::TEST_ENV_LOCK.blocking_lock();
let workspace = std::env::temp_dir().join("openhuman_scoped_reload_test");
install(
Arc::new(SecurityPolicy::default()),
workspace.clone(),
workspace.clone(),
);
let _guard = install_scoped(
Arc::new(SecurityPolicy::default()),
workspace.clone(),
workspace,
);

reload_from(&AutonomyConfig {
auto_approve: vec!["create_workflow".into()],
..AutonomyConfig::default()
});

let sibling_list = std::thread::spawn(|| {
current()
.expect("global policy remains installed")
.auto_approve
.clone()
})
.join()
.expect("sibling thread joined");
assert!(
!sibling_list.iter().any(|tool| tool == "create_workflow"),
"a scoped test's reload must not reach the process-global policy"
);
}

#[test]
fn install_then_reload_swaps_policy_and_bumps_generation() {
// Serialize against other tests that install/reload this process-global
Expand Down
Loading