mirror of
https://github.com/openai/codex.git
synced 2026-09-13 11:47:17 +00:00
## What changed Add a public `codex_core::guardian_review` module exposing `GuardianAssessment`, the assessment parser and output schema, and the review session configuration builder for reuse by the Guardian extension. Extract assessment handling and reviewer configuration into dedicated modules, preserving the existing parsing defaults, policy prompt, and read-only reviewer settings. ## Testing Move the existing embedded-JSON, bare allow/deny, and output-schema tests alongside the assessment implementation. GitOrigin-RevId: cb2aba3ccdb597e2876015e718e923d4f8f36802
84 lines
2.5 KiB
Rust
84 lines
2.5 KiB
Rust
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn parse_guardian_assessment_extracts_embedded_json() {
|
|
let parsed = parse_guardian_assessment(Some(
|
|
"preface {\"risk_level\":\"medium\",\"user_authorization\":\"low\",\"outcome\":\"allow\",\"rationale\":\"ok\"}",
|
|
))
|
|
.expect("guardian assessment");
|
|
|
|
assert_eq!(
|
|
parsed,
|
|
GuardianAssessment {
|
|
risk_level: GuardianRiskLevel::Medium,
|
|
user_authorization: GuardianUserAuthorization::Low,
|
|
outcome: GuardianAssessmentOutcome::Allow,
|
|
rationale: "ok".to_string(),
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_guardian_assessment_treats_bare_allow_as_low_risk() {
|
|
let parsed =
|
|
parse_guardian_assessment(Some(r#"{"outcome":"allow"}"#)).expect("guardian assessment");
|
|
|
|
assert_eq!(
|
|
parsed,
|
|
GuardianAssessment {
|
|
risk_level: GuardianRiskLevel::Low,
|
|
user_authorization: GuardianUserAuthorization::Unknown,
|
|
outcome: GuardianAssessmentOutcome::Allow,
|
|
rationale: "Auto-review returned a low-risk allow decision.".to_string(),
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_guardian_assessment_treats_bare_deny_as_high_risk() {
|
|
let parsed =
|
|
parse_guardian_assessment(Some(r#"{"outcome":"deny"}"#)).expect("guardian assessment");
|
|
|
|
assert_eq!(
|
|
parsed,
|
|
GuardianAssessment {
|
|
risk_level: GuardianRiskLevel::High,
|
|
user_authorization: GuardianUserAuthorization::Unknown,
|
|
outcome: GuardianAssessmentOutcome::Deny,
|
|
rationale: "Auto-review returned a deny decision without a rationale.".to_string(),
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn guardian_output_schema_requires_only_outcome_and_allows_optional_details() {
|
|
let schema = guardian_output_schema();
|
|
|
|
assert_eq!(
|
|
schema,
|
|
serde_json::json!({
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"risk_level": {
|
|
"type": "string",
|
|
"enum": ["low", "medium", "high", "critical"]
|
|
},
|
|
"user_authorization": {
|
|
"type": "string",
|
|
"enum": ["unknown", "low", "medium", "high"]
|
|
},
|
|
"outcome": {
|
|
"type": "string",
|
|
"enum": ["allow", "deny"]
|
|
},
|
|
"rationale": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"required": ["outcome"]
|
|
})
|
|
);
|
|
}
|