mutating in memory policy instead of reloading

This commit is contained in:
kevin zhao
2025-11-20 19:56:48 -05:00
parent fe742b89fd
commit 6e68870567
2 changed files with 16 additions and 0 deletions

View File

@@ -1668,6 +1668,7 @@ mod handlers {
}
}
/// Propagate a user's exec approval decision to the session
/// Also optionally whitelists command in execpolicy
pub async fn exec_approval(sess: &Arc<Session>, id: String, decision: ReviewDecision) {

View File

@@ -127,6 +127,7 @@ pub(crate) async fn append_allow_prefix_rule_and_update(
.add_prefix_rule(prefix, Decision::Allow)?;
Ok(())
Ok(())
}
fn requirement_from_decision(
@@ -463,6 +464,20 @@ prefix_rule(pattern=["rm"], decision="forbidden")
"hello".to_string(),
"world".to_string(),
]);
=======
#[test]
fn append_allow_prefix_rule_updates_policy_and_file() {
let codex_home = tempdir().expect("create temp dir");
let current_policy = Arc::new(Policy::empty());
let prefix = vec!["echo".to_string(), "hello".to_string()];
let updated_policy =
append_allow_prefix_rule_and_update(codex_home.path(), current_policy, &prefix)
.expect("update policy");
let evaluation =
updated_policy.check(&["echo".to_string(), "hello".to_string(), "world".to_string()]);
>>>>>>> 8fb06a9d5 (mutating in memory policy instead of reloading)
assert!(matches!(
evaluation,
Evaluation::Match {