core tests: submit turns with permission profiles (#20010)

## Summary

- Add `PermissionProfile`-based turn submission helpers to
`core_test_support`, while keeping the legacy `SandboxPolicy` helper for
tests that intentionally exercise legacy fallback behavior.
- Switch the default `TestCodex::submit_turn()` path to send a real
`PermissionProfile` plus the required legacy compatibility projection in
`Op::UserTurn`.
- Migrate straightforward app/search/shell/truncation tests from
`SandboxPolicy::{DangerFullAccess, ReadOnly}` to
`PermissionProfile::{Disabled, read_only}`.
- Add a TUI compatibility projection helper for legacy app-server fields
so non-legacy writable roots are preserved instead of being downgraded
to read-only.
- Fix remote start/resume/fork sandbox-mode projection to classify any
managed profile with writable roots as workspace-write, not only
profiles that can write `cwd`.
- Reduce `SandboxPolicy` references in `codex-rs/core/tests` from 47
files to 41 files without changing production behavior.

## Testing

- `cargo check -p codex-core --tests`
- `cargo test -p codex-tui
compatibility_profile_preserves_unbridgeable_write_roots`
- `cargo test -p codex-tui
sandbox_mode_preserves_non_cwd_write_roots_for_remote_sessions`
- `just fmt`
- `just fix -p core_test_support`
- `just fix -p codex-core`
This commit is contained in:
Michael Bolin
2026-04-28 16:01:40 -07:00
committed by GitHub
parent 2dbde94aa9
commit 891722849d
11 changed files with 354 additions and 118 deletions

View File

@@ -2,7 +2,7 @@
#![allow(clippy::expect_used)]
use anyhow::Result;
use codex_protocol::protocol::SandboxPolicy;
use codex_protocol::models::PermissionProfile;
use core_test_support::assert_regex_match;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
@@ -136,9 +136,9 @@ async fn shell_output_stays_json_without_freeform_apply_patch(
let responses = shell_responses(call_id, vec!["/bin/echo", "shell json"], output_type)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the json shell command",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -192,9 +192,9 @@ async fn shell_output_is_structured_with_freeform_apply_patch(
let responses = shell_responses(call_id, vec!["/bin/echo", "freeform shell"], output_type)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the structured shell command",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -249,9 +249,9 @@ async fn shell_output_preserves_fixture_json_without_serialization(
)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"read the fixture JSON with sed",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -317,9 +317,9 @@ async fn shell_output_structures_fixture_with_serialization(
)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"read the fixture JSON with structured output",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -372,9 +372,9 @@ async fn shell_output_for_freeform_tool_records_duration(
let responses = shell_responses(call_id, vec!["/bin/sh", "-c", "sleep 0.2"], output_type)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the structured shell command",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -429,9 +429,9 @@ async fn shell_output_reserializes_truncated_content(output_type: ShellModelOutp
let responses = shell_responses(call_id, vec!["/bin/sh", "-c", "seq 1 400"], output_type)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the truncation shell command",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -495,9 +495,9 @@ async fn apply_patch_custom_tool_output_is_structured(
harness
.test()
.submit_turn_with_policy(
.submit_turn_with_permission_profile(
"apply the patch via custom tool",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -537,9 +537,9 @@ async fn apply_patch_custom_tool_call_creates_file(
harness
.test()
.submit_turn_with_policy(
.submit_turn_with_permission_profile(
"apply the patch via custom tool to create a file",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -593,9 +593,9 @@ async fn apply_patch_custom_tool_call_updates_existing_file(
harness
.test()
.submit_turn_with_policy(
.submit_turn_with_permission_profile(
"apply the patch via custom tool to update a file",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -645,9 +645,9 @@ async fn apply_patch_custom_tool_call_reports_failure_output(
harness
.test()
.submit_turn_with_policy(
.submit_turn_with_permission_profile(
"attempt a failing apply_patch via custom tool",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -688,9 +688,9 @@ async fn apply_patch_function_call_output_is_structured(
.await;
harness
.test()
.submit_turn_with_policy(
.submit_turn_with_permission_profile(
"apply the patch via function-call apply_patch",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -727,9 +727,9 @@ async fn shell_output_is_structured_for_nonzero_exit(output_type: ShellModelOutp
let responses = shell_responses(call_id, vec!["/bin/sh", "-c", "exit 42"], output_type)?;
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the failing shell command",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -778,9 +778,9 @@ async fn shell_command_output_is_freeform() -> Result<()> {
];
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the shell_command script in the user's shell",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -830,9 +830,9 @@ async fn shell_command_output_is_not_truncated_under_10k_bytes() -> Result<()> {
];
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the shell_command script in the user's shell",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -881,9 +881,9 @@ async fn shell_command_output_is_not_truncated_over_10k_bytes() -> Result<()> {
];
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the shell_command script in the user's shell",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;
@@ -929,9 +929,9 @@ async fn local_shell_call_output_is_structured() -> Result<()> {
];
let mock = mount_sse_sequence(&server, responses).await;
test.submit_turn_with_policy(
test.submit_turn_with_permission_profile(
"run the local shell command",
SandboxPolicy::DangerFullAccess,
PermissionProfile::Disabled,
)
.await?;