mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
implementing PartialOrd for Decision instead of defining custom is_stricter_than func
This commit is contained in:
@@ -4,7 +4,7 @@ use serde::Serialize;
|
||||
use crate::error::Error;
|
||||
use crate::error::Result;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum Decision {
|
||||
Allow,
|
||||
@@ -21,13 +21,4 @@ impl Decision {
|
||||
other => Err(Error::InvalidDecision(other.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if `self` is stricter (less permissive) than `other`.
|
||||
pub fn is_stricter_than(self, other: Self) -> bool {
|
||||
matches!(
|
||||
(self, other),
|
||||
(Decision::Forbidden, Decision::Prompt | Decision::Allow)
|
||||
| (Decision::Prompt, Decision::Allow)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,7 @@ impl Policy {
|
||||
if let Some(matched) = rule.matches(cmd) {
|
||||
let decision = match best_decision {
|
||||
None => matched.decision,
|
||||
Some(current) => {
|
||||
if matched.decision.is_stricter_than(current) {
|
||||
matched.decision
|
||||
} else {
|
||||
current
|
||||
}
|
||||
}
|
||||
Some(current) => std::cmp::max(matched.decision, current),
|
||||
};
|
||||
best_decision = Some(decision);
|
||||
matched_rules.push(matched);
|
||||
|
||||
Reference in New Issue
Block a user