mirror of
https://github.com/openai/codex.git
synced 2026-09-08 15:50:34 +00:00
Accept legacy wsl2 Windows sandbox alias
This commit is contained in:
@@ -27,6 +27,8 @@ use std::fmt;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde::de::Error as _;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub use crate::tui_keymap::KeybindingSpec;
|
||||
pub use crate::tui_keymap::KeybindingsSpec;
|
||||
@@ -111,13 +113,36 @@ pub enum OAuthCredentialsStoreMode {
|
||||
Keyring,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
|
||||
#[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum WindowsSandboxModeToml {
|
||||
Elevated,
|
||||
Unelevated,
|
||||
}
|
||||
|
||||
impl FromStr for WindowsSandboxModeToml {
|
||||
type Err = &'static str;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
let normalized = value.trim().to_ascii_lowercase();
|
||||
match normalized.as_str() {
|
||||
"elevated" => Ok(Self::Elevated),
|
||||
"unelevated" | "wsl2" => Ok(Self::Unelevated),
|
||||
_ => Err("expected `elevated`, `unelevated`, or legacy alias `wsl2`"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for WindowsSandboxModeToml {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let value = String::deserialize(deserializer)?;
|
||||
Self::from_str(&value).map_err(D::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct WindowsToml {
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn windows_sandbox_mode_accepts_legacy_wsl2_alias_case_insensitively() {
|
||||
let mode: WindowsSandboxModeToml =
|
||||
toml::from_str("\"wsL2\"").expect("should deserialize legacy WSL2 alias");
|
||||
|
||||
assert_eq!(mode, WindowsSandboxModeToml::Unelevated);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_sandbox_mode_rejects_unknown_values() {
|
||||
let err = toml::from_str::<WindowsSandboxModeToml>("\"sandboxie\"")
|
||||
.expect_err("unknown sandbox values should be rejected");
|
||||
|
||||
assert!(
|
||||
err.to_string()
|
||||
.contains("expected `elevated`, `unelevated`, or legacy alias `wsl2`"),
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_skill_config_with_name_selector() {
|
||||
let cfg: SkillConfig = toml::from_str(
|
||||
|
||||
Reference in New Issue
Block a user