mirror of
https://github.com/openai/codex.git
synced 2026-09-09 15:58:47 +00:00
codex: stabilize cwd tests on windows
This commit is contained in:
@@ -24,6 +24,7 @@ use codex_protocol::request_permissions::RequestPermissionsResponse;
|
||||
use codex_protocol::request_user_input::RequestUserInputAnswer;
|
||||
use codex_protocol::request_user_input::RequestUserInputEvent;
|
||||
use codex_protocol::request_user_input::RequestUserInputQuestion;
|
||||
use core_test_support::PathBufExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@@ -267,10 +268,12 @@ async fn handle_exec_approval_uses_call_id_for_guardian_review_and_approval_id_f
|
||||
});
|
||||
|
||||
let cancel_token = CancellationToken::new();
|
||||
let cwd = PathBuf::from("/tmp").abs().to_path_buf();
|
||||
let handle = tokio::spawn({
|
||||
let codex = Arc::clone(&codex);
|
||||
let parent_session = Arc::clone(&parent_session);
|
||||
let parent_ctx = Arc::clone(&parent_ctx);
|
||||
let cwd = cwd.clone();
|
||||
let cancel_token = cancel_token.clone();
|
||||
async move {
|
||||
handle_exec_approval(
|
||||
@@ -283,7 +286,7 @@ async fn handle_exec_approval_uses_call_id_for_guardian_review_and_approval_id_f
|
||||
approval_id: Some("callback-approval-1".to_string()),
|
||||
turn_id: "child-turn-1".to_string(),
|
||||
command: vec!["rm".to_string(), "-rf".to_string(), "tmp".to_string()],
|
||||
cwd: PathBuf::from("/tmp"),
|
||||
cwd,
|
||||
reason: Some("unsafe subcommand".to_string()),
|
||||
network_approval_context: None,
|
||||
proposed_execpolicy_amendment: None,
|
||||
@@ -323,7 +326,7 @@ async fn handle_exec_approval_uses_call_id_for_guardian_review_and_approval_id_f
|
||||
action: GuardianAssessmentAction::Command {
|
||||
source: GuardianCommandSource::Shell,
|
||||
command: "rm -rf tmp".to_string(),
|
||||
cwd: "/tmp".into(),
|
||||
cwd,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -27,6 +27,7 @@ use codex_protocol::protocol::GuardianAssessmentStatus;
|
||||
use codex_protocol::protocol::GuardianRiskLevel;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use core_test_support::PathBufExt;
|
||||
use core_test_support::TempDirExt;
|
||||
use core_test_support::context_snapshot;
|
||||
@@ -128,6 +129,18 @@ fn guardian_snapshot_options() -> ContextSnapshotOptions {
|
||||
.strip_agents_md_user_context()
|
||||
}
|
||||
|
||||
fn guardian_repo_cwd() -> AbsolutePathBuf {
|
||||
core_test_support::test_absolute_path("/repo/codex-rs/core")
|
||||
}
|
||||
|
||||
fn normalize_guardian_repo_cwd_snapshot(snapshot: String) -> String {
|
||||
let cwd = guardian_repo_cwd().to_string_lossy().into_owned();
|
||||
let escaped_cwd = cwd.replace('\\', "\\\\");
|
||||
snapshot
|
||||
.replace(&cwd, "/repo/codex-rs/core")
|
||||
.replace(&escaped_cwd, "/repo/codex-rs/core")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_guardian_transcript_keeps_original_numbering() {
|
||||
let entries = [
|
||||
@@ -536,7 +549,7 @@ async fn guardian_review_request_layout_matches_model_visible_request_snapshot()
|
||||
"origin".to_string(),
|
||||
"guardian-approval-mvp".to_string(),
|
||||
],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some(
|
||||
@@ -566,10 +579,12 @@ async fn guardian_review_request_layout_matches_model_visible_request_snapshot()
|
||||
settings.bind(|| {
|
||||
assert_snapshot!(
|
||||
"codex_core__guardian__tests__guardian_review_request_layout",
|
||||
context_snapshot::format_labeled_requests_snapshot(
|
||||
"Guardian review request layout",
|
||||
&[("Guardian Review Request", &request)],
|
||||
&guardian_snapshot_options(),
|
||||
normalize_guardian_repo_cwd_snapshot(
|
||||
context_snapshot::format_labeled_requests_snapshot(
|
||||
"Guardian review request layout",
|
||||
&[("Guardian Review Request", &request)],
|
||||
&guardian_snapshot_options(),
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
@@ -617,7 +632,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
GuardianApprovalRequest::Shell {
|
||||
id: "shell-1".to_string(),
|
||||
command: vec!["git".to_string(), "push".to_string()],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some("Need to push the first docs fix.".to_string()),
|
||||
@@ -642,7 +657,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
"push".to_string(),
|
||||
"--force-with-lease".to_string(),
|
||||
],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some("Need to push the second docs fix.".to_string()),
|
||||
@@ -699,13 +714,15 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
||||
"codex_core__guardian__tests__guardian_followup_review_request_layout",
|
||||
format!(
|
||||
"{}\n\nshared_prompt_cache_key: {}\nfollowup_contains_first_rationale: {}",
|
||||
context_snapshot::format_labeled_requests_snapshot(
|
||||
"Guardian follow-up review request layout",
|
||||
&[
|
||||
("Initial Guardian Review Request", &requests[0]),
|
||||
("Follow-up Guardian Review Request", &requests[1]),
|
||||
],
|
||||
&guardian_snapshot_options(),
|
||||
normalize_guardian_repo_cwd_snapshot(
|
||||
context_snapshot::format_labeled_requests_snapshot(
|
||||
"Guardian follow-up review request layout",
|
||||
&[
|
||||
("Initial Guardian Review Request", &requests[0]),
|
||||
("Follow-up Guardian Review Request", &requests[1]),
|
||||
],
|
||||
&guardian_snapshot_options(),
|
||||
)
|
||||
),
|
||||
first_body["prompt_cache_key"] == second_body["prompt_cache_key"],
|
||||
second_body.to_string().contains(first_rationale),
|
||||
@@ -762,7 +779,7 @@ async fn guardian_review_surfaces_responses_api_errors_in_rejection_reason() ->
|
||||
GuardianApprovalRequest::Shell {
|
||||
id: "shell-guardian-error".to_string(),
|
||||
command: vec!["git".to_string(), "push".to_string()],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some("Need to push the reviewed docs fix.".to_string()),
|
||||
@@ -873,7 +890,7 @@ async fn guardian_parallel_reviews_fork_from_last_committed_trunk_history() -> a
|
||||
let initial_request = GuardianApprovalRequest::Shell {
|
||||
id: "shell-guardian-1".to_string(),
|
||||
command: vec!["git".to_string(), "status".to_string()],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some("Inspect repo state before proceeding.".to_string()),
|
||||
@@ -886,7 +903,7 @@ async fn guardian_parallel_reviews_fork_from_last_committed_trunk_history() -> a
|
||||
let second_request = GuardianApprovalRequest::Shell {
|
||||
id: "shell-guardian-2".to_string(),
|
||||
command: vec!["git".to_string(), "diff".to_string()],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some("Inspect pending changes before proceeding.".to_string()),
|
||||
@@ -894,7 +911,7 @@ async fn guardian_parallel_reviews_fork_from_last_committed_trunk_history() -> a
|
||||
let third_request = GuardianApprovalRequest::Shell {
|
||||
id: "shell-guardian-3".to_string(),
|
||||
command: vec!["git".to_string(), "push".to_string()],
|
||||
cwd: PathBuf::from("/repo/codex-rs/core").abs(),
|
||||
cwd: guardian_repo_cwd(),
|
||||
sandbox_permissions: crate::sandboxing::SandboxPermissions::UseDefault,
|
||||
additional_permissions: None,
|
||||
justification: Some("Inspect whether pushing is safe before proceeding.".to_string()),
|
||||
|
||||
Reference in New Issue
Block a user