Files
codex/codex-rs/tui/src/windows_sandbox_tests.rs
T
Eric Traut 7f501cd334 Track Windows sandbox policy and per-thread executor hosts in the TUI (#45813)
## What changed

- Add `WindowsSandboxConfig` helpers to read app-server configuration and managed requirements, preserve legacy feature flag fallbacks, and select an allowed setup mode with elevated mode preferred when the configured mode is disallowed.
- Store the sandbox host classification in thread session state using reported environments across start, resume, fork, and replay paths. Classify missing or empty environments as `Unknown`, and distinguish local, remote, and mixed selections.

## Testing

Add coverage for managed setup restrictions, legacy configuration precedence, unknown policy state, environment classification, and remote host state in inactive-thread replay.

GitOrigin-RevId: ae8920d9c2a1c80b641ac90617ae607b171bd55a
2026-09-16 00:21:49 +00:00

83 lines
2.6 KiB
Rust

use super::*;
use codex_app_server_protocol::WindowsSandboxSetupMode::Elevated;
use codex_app_server_protocol::WindowsSandboxSetupMode::Unelevated;
use pretty_assertions::assert_eq;
use serde_json::json;
#[test]
fn windows_sandbox_server_policy_controls_setup_choices() {
for (configured, allowed, mode, expected) in [
(
Some("unelevated"),
serde_json::Value::Null,
Some(Unelevated),
(true, true, false),
),
(
Some("unelevated"),
json!(["elevated"]),
Some(Elevated),
(true, false, true),
),
(
None,
json!(["unelevated", "elevated"]),
Some(Elevated),
(true, true, true),
),
(
None,
json!(["unelevated"]),
Some(Unelevated),
(false, true, false),
),
(Some("unelevated"), json!([]), None, (false, false, false)),
(
Some("unelevated"),
json!(["mxc"]),
None,
(false, false, false),
),
] {
let config = serde_json::from_value(json!({
"config": {"windows": {"sandbox": configured}}, "origins": {}
}))
.unwrap();
let requirements = serde_json::from_value(json!({
"requirements": {"allowedWindowsSandboxImplementations": allowed}
}))
.unwrap();
let state = WindowsSandboxConfig::from_responses(&config, requirements);
assert_eq!(state.mode, mode);
assert_eq!(
(
state.allows(Elevated),
state.allows(Unelevated),
state.requires_elevated()
),
expected
);
}
for (key, mode) in [
("elevated_windows_sandbox", Elevated),
("experimental_windows_sandbox", Unelevated),
("enable_experimental_windows_sandbox", Unelevated),
] {
for (explicit, expected) in [(None, mode), (Some("elevated"), Elevated)] {
let config = serde_json::from_value(json!({
"config": {"windows": {"sandbox": explicit}, "features": {key: true}},
"origins": {}
}))
.unwrap();
let requirements = serde_json::from_value(json!({"requirements": null})).unwrap();
assert_eq!(
WindowsSandboxConfig::from_responses(&config, requirements).mode,
Some(expected)
);
}
}
let unknown = WindowsSandboxConfig::default();
assert!(!unknown.allows(Elevated));
assert!(!unknown.allows(Unelevated));
}