aKode fase 3: provider locali, chiavi per provider, modelli dal server, SearXNG
- Provider: rimossi openai, Bedrock e GCP integrati e ogni fallback a OpenAI;
restano ollama, lmstudio e i provider personalizzati. Senza provider, exec e
TUI mostrano come configurarlo.
- Chiave per provider: api_key = "keyring", provider_api_key_store =
auto|keyring|file (fallback su file 0600 / ACL Windows); `codex login
--provider <id> --with-api-key`, `logout --provider`; login status e doctor
mostrano dove sta la chiave senza rivelarla.
- Modelli letti da GET {base_url}/models; contesto da config, poi dal server
(/props, meta.n_ctx), poi 32768; apply_patch come tool function; niente tool
ospitati; niente piu' avviso "metadata not found".
- Unione dei soli messaggi system/developer iniziali in un unico system;
quelli successivi restano al loro posto come user (cache del server
preservata: turno N prefisso esatto del turno N+1).
- Modelli ausiliari (memorie, guardian-v2) = modello di sessione se il
preferito gpt-* non e' nel catalogo.
- Ricerca web: crate web-tools, backend SearXNG con web_search e web_fetch
(protezione SSRF); senza backend nessuno strumento web.
- Skill: rimossa openai-docs; skill-installer punta a git.difonzo.net.
- apply_patch accetta gli header @@ -a,b +c,d @@ dei diff unificati.
- Rimossi resti: request_plugin_install, AppsInstructions, --cyber-access-program,
URL updater/realtime predefiniti.
- Fix: importazione sessioni con provider vuoto.
- Istruzioni di sistema invariate. Test: cancellati solo quelli del codice
rimosso, test di sicurezza adattati; restano solo fallimenti d'ambiente.
- Prova reale su imeAI + SearXNG: risposta, modifica file, web_search,
cache riusata, connessioni solo verso .25 e .57.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,7 +72,6 @@ use codex_config::types::WindowsToml;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_features::Feature;
|
||||
use codex_features::FeaturesToml;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_login::default_client::RESIDENCY_HEADER_NAME;
|
||||
use codex_login::test_support::auth_manager_from_optional_auth;
|
||||
use codex_model_provider::ProviderCapabilities;
|
||||
@@ -82,7 +81,6 @@ use codex_model_provider_info::WireApi;
|
||||
use codex_models_manager::bundled_models_response;
|
||||
use codex_network_proxy::NetworkMode;
|
||||
use codex_prompts::ResolvedMessage;
|
||||
use codex_protocol::config_types::ModelProviderAuthInfo;
|
||||
use codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE;
|
||||
use codex_protocol::config_types::ServiceTier;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
@@ -1040,26 +1038,6 @@ command = "print-token"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_provider_aws_for_custom_provider() {
|
||||
let err = toml::from_str::<ConfigToml>(
|
||||
r#"
|
||||
[model_providers.custom]
|
||||
name = "Custom Provider"
|
||||
|
||||
[model_providers.custom.aws]
|
||||
profile = "codex-bedrock"
|
||||
"#,
|
||||
)
|
||||
.unwrap_err();
|
||||
|
||||
assert!(
|
||||
err.to_string().contains(
|
||||
"model_providers.custom: provider aws is only supported for `amazon-bedrock`"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn managed_residency_warns_about_provider_header_overrides_without_mutating_config()
|
||||
-> std::io::Result<()> {
|
||||
@@ -1140,240 +1118,6 @@ env_http_headers = { "x-openai-internal-codex-residency" = "CODEX_TEST_UNSET_RES
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_amazon_bedrock_aws_profile_override() {
|
||||
let cfg = toml::from_str::<ConfigToml>(
|
||||
r#"
|
||||
[model_providers.amazon-bedrock.aws]
|
||||
profile = "codex-bedrock"
|
||||
region = "us-west-2"
|
||||
"#,
|
||||
)
|
||||
.expect("Amazon Bedrock AWS overrides should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
cfg.model_providers
|
||||
.get("amazon-bedrock")
|
||||
.and_then(|provider| provider.aws.as_ref())
|
||||
.and_then(|aws| aws.profile.as_deref()),
|
||||
Some("codex-bedrock")
|
||||
);
|
||||
assert_eq!(
|
||||
cfg.model_providers
|
||||
.get("amazon-bedrock")
|
||||
.and_then(|provider| provider.aws.as_ref())
|
||||
.and_then(|aws| aws.region.as_deref()),
|
||||
Some("us-west-2")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_applies_amazon_bedrock_aws_profile_override() {
|
||||
let cfg = toml::from_str::<ConfigToml>(
|
||||
r#"
|
||||
model_provider = "amazon-bedrock"
|
||||
|
||||
[model_providers.amazon-bedrock.aws]
|
||||
profile = "codex-bedrock"
|
||||
region = "us-west-2"
|
||||
"#,
|
||||
)
|
||||
.expect("Amazon Bedrock AWS overrides should deserialize");
|
||||
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides::default(),
|
||||
tempdir().expect("tempdir").abs(),
|
||||
)
|
||||
.await
|
||||
.expect("load config");
|
||||
|
||||
assert_eq!(config.model_provider_id, "amazon-bedrock");
|
||||
assert_eq!(
|
||||
config
|
||||
.model_provider
|
||||
.aws
|
||||
.as_ref()
|
||||
.and_then(|aws| aws.profile.as_deref()),
|
||||
Some("codex-bedrock")
|
||||
);
|
||||
assert_eq!(
|
||||
config
|
||||
.model_provider
|
||||
.aws
|
||||
.as_ref()
|
||||
.and_then(|aws| aws.region.as_deref()),
|
||||
Some("us-west-2")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_applies_amazon_bedrock_transport_overrides() {
|
||||
let cfg = toml::from_str::<ConfigToml>(
|
||||
r#"
|
||||
model_provider = "amazon-bedrock"
|
||||
|
||||
[model_providers.amazon-bedrock]
|
||||
base_url = "https://bedrock.example.com/v1"
|
||||
http_headers = { "X-Custom-Header" = "value" }
|
||||
|
||||
[model_providers.amazon-bedrock.auth]
|
||||
command = "print-token"
|
||||
"#,
|
||||
)
|
||||
.expect("Amazon Bedrock transport overrides should deserialize");
|
||||
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides::default(),
|
||||
tempdir().expect("tempdir").abs(),
|
||||
)
|
||||
.await
|
||||
.expect("load config");
|
||||
|
||||
let mut expected_provider = built_in_model_providers(/*openai_base_url*/ None)
|
||||
.remove("amazon-bedrock")
|
||||
.expect("Amazon Bedrock provider should be built in");
|
||||
expected_provider.base_url = Some("https://bedrock.example.com/v1".to_string());
|
||||
expected_provider.auth = Some(ModelProviderAuthInfo {
|
||||
command: "print-token".to_string(),
|
||||
args: Vec::new(),
|
||||
timeout_ms: std::num::NonZeroU64::new(5_000).expect("timeout should be non-zero"),
|
||||
refresh_interval_ms: 300_000,
|
||||
cwd: std::env::current_dir()
|
||||
.expect("current directory should be available")
|
||||
.try_into()
|
||||
.expect("current directory should be absolute"),
|
||||
});
|
||||
expected_provider
|
||||
.http_headers
|
||||
.get_or_insert_default()
|
||||
.insert("X-Custom-Header".to_string(), "value".into());
|
||||
|
||||
assert_eq!(config.model_provider_id, "amazon-bedrock");
|
||||
assert_eq!(config.model_provider, expected_provider);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_uses_resolved_cwd_for_default_gcp_auth() {
|
||||
let codex_home = tempdir().expect("tempdir");
|
||||
let workspace = tempdir().expect("tempdir");
|
||||
let cwd = workspace.abs();
|
||||
|
||||
for base_url in [None, Some("https://vertex.example.com/v1")] {
|
||||
let mut cfg = ConfigToml {
|
||||
model_provider: Some("gcp".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(base_url) = base_url {
|
||||
cfg.model_providers.insert(
|
||||
"gcp".to_string(),
|
||||
ModelProviderInfo {
|
||||
base_url: Some(base_url.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides {
|
||||
cwd: Some(cwd.to_path_buf()),
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await
|
||||
.expect("load config");
|
||||
|
||||
let mut expected_provider = ModelProviderInfo::create_gcp_provider();
|
||||
expected_provider.base_url = base_url.map(str::to_string);
|
||||
expected_provider.auth = Some(ModelProviderAuthInfo {
|
||||
command: if cfg!(windows) {
|
||||
"gcloud.cmd"
|
||||
} else {
|
||||
"gcloud"
|
||||
}
|
||||
.to_string(),
|
||||
args: vec![
|
||||
"auth".into(),
|
||||
"application-default".into(),
|
||||
"print-access-token".into(),
|
||||
],
|
||||
timeout_ms: std::num::NonZeroU64::new(30_000).expect("timeout should be non-zero"),
|
||||
refresh_interval_ms: 3_000_000,
|
||||
cwd: cwd.clone(),
|
||||
});
|
||||
assert_eq!(config.model_provider_id, "gcp");
|
||||
assert_eq!(config.model_provider, expected_provider);
|
||||
assert_eq!(config.model_providers.get("gcp"), Some(&expected_provider));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_config_applies_gcp_transport_overrides() {
|
||||
let cfg = toml::from_str::<ConfigToml>(
|
||||
r#"
|
||||
model_provider = "gcp"
|
||||
|
||||
[model_providers.gcp]
|
||||
base_url = "https://vertex.example.com/v1"
|
||||
http_headers = { "X-Custom-Header" = "value" }
|
||||
|
||||
[model_providers.gcp.auth]
|
||||
command = "print-token"
|
||||
"#,
|
||||
)
|
||||
.expect("GCP transport overrides should deserialize");
|
||||
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides::default(),
|
||||
tempdir().expect("tempdir").abs(),
|
||||
)
|
||||
.await
|
||||
.expect("load config");
|
||||
|
||||
let mut expected_provider = built_in_model_providers(/*openai_base_url*/ None)
|
||||
.remove("gcp")
|
||||
.expect("GCP provider should be built in");
|
||||
expected_provider.base_url = Some("https://vertex.example.com/v1".to_string());
|
||||
expected_provider.auth = Some(ModelProviderAuthInfo {
|
||||
command: "print-token".to_string(),
|
||||
args: Vec::new(),
|
||||
timeout_ms: std::num::NonZeroU64::new(5_000).expect("timeout should be non-zero"),
|
||||
refresh_interval_ms: 300_000,
|
||||
cwd: std::env::current_dir()
|
||||
.expect("current directory should be available")
|
||||
.try_into()
|
||||
.expect("current directory should be absolute"),
|
||||
});
|
||||
expected_provider.http_headers = Some(std::collections::HashMap::from([(
|
||||
"X-Custom-Header".to_string(),
|
||||
"value".into(),
|
||||
)]));
|
||||
|
||||
assert_eq!(config.model_provider_id, "gcp");
|
||||
assert_eq!(config.model_provider, expected_provider);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_toml_rejects_unsupported_amazon_bedrock_overrides() {
|
||||
let err = toml::from_str::<ConfigToml>(
|
||||
r#"
|
||||
model_provider = "amazon-bedrock"
|
||||
|
||||
[model_providers.amazon-bedrock]
|
||||
name = "Custom Bedrock"
|
||||
requires_openai_auth = true
|
||||
supports_websockets = true
|
||||
"#,
|
||||
)
|
||||
.expect_err("Amazon Bedrock unsupported overrides should fail validation");
|
||||
assert!(err.to_string().contains(
|
||||
"model_providers.amazon-bedrock only supports changing `base_url`, `auth`, `http_headers`, `aws.profile`, `aws.region`, `aws.credential_export`, and `aws.auth_refresh`; other non-default provider fields are not supported"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_toml_deserializes_model_availability_nux() {
|
||||
let toml = r#"
|
||||
@@ -4076,56 +3820,6 @@ async fn implicit_builtin_workspace_profile_preserves_sandbox_workspace_write_se
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn implicit_builtin_workspace_profile_preserves_add_dir_metadata_carveouts()
|
||||
-> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let cwd = TempDir::new()?;
|
||||
let extra_root = TempDir::new()?;
|
||||
for subpath in [".git", ".agents", ".codex", ".aws"] {
|
||||
std::fs::create_dir_all(extra_root.path().join(subpath))?;
|
||||
}
|
||||
let project_key = cwd.path().to_string_lossy().to_string();
|
||||
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
ConfigToml {
|
||||
projects: Some(HashMap::from([(
|
||||
project_key,
|
||||
ProjectConfig {
|
||||
trust_level: Some(TrustLevel::Trusted),
|
||||
},
|
||||
)])),
|
||||
windows: Some(WindowsToml {
|
||||
sandbox: Some(WindowsSandboxModeToml::Elevated),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
ConfigOverrides {
|
||||
cwd: Some(cwd.path().to_path_buf()),
|
||||
additional_writable_roots: vec![extra_root.path().to_path_buf()],
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let policy = config.permissions.file_system_sandbox_policy();
|
||||
let extra_root = extra_root.path().abs();
|
||||
assert!(
|
||||
policy.can_write_local_path_with_cwd(extra_root.as_path(), cwd.path()),
|
||||
"expected implicit :workspace to preserve additional writable roots, policy: {policy:?}"
|
||||
);
|
||||
for subpath in [".git", ".agents", ".codex", ".aws"] {
|
||||
assert!(
|
||||
!policy.can_write_local_path_with_cwd(&extra_root.join(subpath), cwd.path()),
|
||||
"expected implicit :workspace to preserve legacy metadata carveout for {subpath}, \
|
||||
policy: {policy:?}"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_config_defaults_to_builtin_read_only_without_trust_decision() -> std::io::Result<()>
|
||||
{
|
||||
@@ -5180,151 +4874,6 @@ exclude_slash_tmp = true
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_sandbox_mode_builds_profiles_with_compatible_projection() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let cwd = TempDir::new()?;
|
||||
let extra_root = test_absolute_path("/tmp/legacy-extra-root");
|
||||
let cases = vec![
|
||||
(
|
||||
"danger-full-access".to_string(),
|
||||
r#"sandbox_mode = "danger-full-access"
|
||||
"#
|
||||
.to_string(),
|
||||
),
|
||||
(
|
||||
"read-only".to_string(),
|
||||
r#"sandbox_mode = "read-only"
|
||||
"#
|
||||
.to_string(),
|
||||
),
|
||||
(
|
||||
"workspace-write".to_string(),
|
||||
format!(
|
||||
r#"sandbox_mode = "workspace-write"
|
||||
|
||||
[sandbox_workspace_write]
|
||||
writable_roots = [{}]
|
||||
exclude_tmpdir_env_var = true
|
||||
exclude_slash_tmp = true
|
||||
"#,
|
||||
serde_json::json!(extra_root)
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
for (name, config_toml) in cases {
|
||||
let cfg = toml::from_str::<ConfigToml>(&config_toml)
|
||||
.unwrap_or_else(|err| panic!("case `{name}` should parse: {err}"));
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides {
|
||||
cwd: Some(cwd.path().to_path_buf()),
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let sandbox_policy = config.legacy_sandbox_policy();
|
||||
let file_system_policy = config.permissions.file_system_sandbox_policy();
|
||||
let network_policy = config.permissions.network_sandbox_policy();
|
||||
|
||||
assert_eq!(
|
||||
network_policy,
|
||||
NetworkSandboxPolicy::from(&sandbox_policy),
|
||||
"case `{name}` should preserve network semantics from legacy config"
|
||||
);
|
||||
assert_eq!(
|
||||
file_system_policy
|
||||
.to_legacy_sandbox_policy(network_policy, cwd.path())
|
||||
.unwrap_or_else(|err| panic!("case `{name}` should round-trip: {err}")),
|
||||
sandbox_policy,
|
||||
"case `{name}` should preserve its legacy compatibility projection"
|
||||
);
|
||||
|
||||
match name.as_str() {
|
||||
"danger-full-access" | "read-only" => {
|
||||
assert_eq!(
|
||||
file_system_policy,
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy_for_cwd(
|
||||
&sandbox_policy,
|
||||
cwd.path()
|
||||
),
|
||||
"case `{name}` should match the legacy filesystem projection exactly"
|
||||
);
|
||||
}
|
||||
"workspace-write" => {
|
||||
if cfg!(target_os = "windows") {
|
||||
assert_eq!(
|
||||
sandbox_policy,
|
||||
SandboxPolicy::new_read_only_policy(),
|
||||
"legacy workspace-write should keep the existing Windows downgrade when \
|
||||
the experimental Windows sandbox is disabled"
|
||||
);
|
||||
assert_eq!(
|
||||
file_system_policy,
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy_for_cwd(
|
||||
&sandbox_policy,
|
||||
cwd.path()
|
||||
),
|
||||
"downgraded workspace-write should match the legacy read-only projection"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
assert_eq!(
|
||||
config.permissions.workspace_roots(),
|
||||
&[cwd.abs(), extra_root.clone()]
|
||||
);
|
||||
assert!(
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: cwd.abs().into(),
|
||||
access: FileSystemAccessMode::Write,
|
||||
missing_path_behavior: None,
|
||||
})
|
||||
);
|
||||
assert!(
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: FileSystemPath::Path {
|
||||
path: extra_root.clone().into(),
|
||||
},
|
||||
access: FileSystemAccessMode::Write,
|
||||
missing_path_behavior: None,
|
||||
})
|
||||
);
|
||||
for subpath in [".git", ".agents", ".codex", ".aws"] {
|
||||
assert!(
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: FileSystemPath::Path {
|
||||
path: AbsolutePathBuf::resolve_path_against_base(
|
||||
subpath,
|
||||
cwd.path()
|
||||
)
|
||||
.into(),
|
||||
},
|
||||
access: FileSystemAccessMode::Read,
|
||||
missing_path_behavior: Some(
|
||||
codex_protocol::permissions::FileSystemSandboxEntryMissingPathBehavior::Skip,
|
||||
),
|
||||
}),
|
||||
"case `{name}` should materialize `{subpath}` for the runtime workspace \
|
||||
root"
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => unreachable!("unexpected test case `{name}`"),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_mcp_servers_by_allowlist_enforces_identity_rules() {
|
||||
const MISMATCHED_COMMAND_SERVER: &str = "mismatched-command-should-disable";
|
||||
@@ -6682,107 +6231,6 @@ async fn config_resolves_explicit_keyring_auth_store_mode() -> std::io::Result<(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case("https://managed.example/backend-api/"; "custom")]
|
||||
#[test_case::test_case(DEFAULT_CHATGPT_BASE_URL; "explicit_default")]
|
||||
#[tokio::test]
|
||||
async fn config_applies_managed_auth_store_and_chatgpt_base_url(
|
||||
managed_url: &str,
|
||||
) -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let managed_store = AuthCredentialsStoreMode::Keyring;
|
||||
let requirements = codex_config::ConfigRequirements {
|
||||
cli_auth_credentials_store: Some(Sourced::new(managed_store, RequirementSource::Unknown)),
|
||||
chatgpt_base_url: Some(Sourced::new(
|
||||
managed_url.to_string(),
|
||||
RequirementSource::Unknown,
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
let config_layer_stack = ConfigLayerStack::new(
|
||||
Vec::new(),
|
||||
requirements,
|
||||
codex_config::ConfigRequirementsToml::default(),
|
||||
)?;
|
||||
|
||||
let config = Config::load_config_with_layer_stack(
|
||||
LOCAL_FS.as_ref(),
|
||||
ConfigToml {
|
||||
cli_auth_credentials_store: Some(AuthCredentialsStoreMode::File),
|
||||
chatgpt_base_url: Some("https://user.example/backend-api/".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
ConfigOverrides {
|
||||
cwd: Some(codex_home.path().to_path_buf()),
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
config_layer_stack,
|
||||
)
|
||||
.await?;
|
||||
|
||||
assert_eq!(config.cli_auth_credentials_store_mode, managed_store);
|
||||
assert_eq!(config.chatgpt_base_url, managed_url);
|
||||
assert!(config.chatgpt_base_url_is_explicit);
|
||||
assert_eq!(
|
||||
config
|
||||
.chatgpt_backend_url()
|
||||
.resolve(&CodexAuth::from_api_key("sk-proj-fedramp-test-key")),
|
||||
managed_url
|
||||
);
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `cli_auth_credentials_store` is overridden")
|
||||
}));
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `chatgpt_base_url` is overridden")
|
||||
}));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn chatgpt_backend_url_defaults_follow_captured_auth() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let legacy = CodexAuth::from_api_key("legacy-key");
|
||||
let marked = CodexAuth::from_api_key("sk-proj-fedramp-test-key");
|
||||
let custom_url = "https://custom.example/backend-api/";
|
||||
for configured_url in [None, Some(custom_url), Some(DEFAULT_CHATGPT_BASE_URL)] {
|
||||
std::fs::write(
|
||||
codex_home.path().join(CONFIG_TOML_FILE),
|
||||
configured_url
|
||||
.map(|url| format!("chatgpt_base_url = '{url}'\n"))
|
||||
.unwrap_or_default(),
|
||||
)?;
|
||||
let mut config = ConfigBuilder::without_managed_config_for_tests()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(codex_home.path().to_path_buf()))
|
||||
.build()
|
||||
.await?;
|
||||
let raw_url = configured_url.unwrap_or(DEFAULT_CHATGPT_BASE_URL);
|
||||
let raw_auth_config = config.auth_config();
|
||||
assert_eq!(
|
||||
config.chatgpt_base_url_is_explicit,
|
||||
configured_url.is_some()
|
||||
);
|
||||
for (auth, default_url) in [
|
||||
(&legacy, DEFAULT_CHATGPT_BASE_URL),
|
||||
(&marked, "https://gov.chatgpt.com/backend-api/"),
|
||||
(&legacy, DEFAULT_CHATGPT_BASE_URL),
|
||||
] {
|
||||
assert_eq!(
|
||||
config.chatgpt_backend_url().resolve(auth),
|
||||
configured_url.unwrap_or(default_url)
|
||||
);
|
||||
assert_eq!(config.chatgpt_base_url, raw_url);
|
||||
assert_eq!(config.auth_config(), raw_auth_config);
|
||||
}
|
||||
if configured_url.is_none() {
|
||||
config.chatgpt_base_url = custom_url.to_owned();
|
||||
assert_eq!(config.chatgpt_backend_url().resolve(&marked), custom_url);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn config_resolves_default_oauth_store_mode() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
@@ -6888,7 +6336,7 @@ fn web_search_mode_defaults_to_none_if_unset() {
|
||||
#[test]
|
||||
fn web_search_mode_prefers_config_over_legacy_flags() {
|
||||
let cfg = ConfigToml {
|
||||
web_search: Some(WebSearchMode::Live),
|
||||
web_search: Some(WebSearchMode::Live.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut features = Features::with_defaults();
|
||||
@@ -6903,7 +6351,7 @@ fn web_search_mode_prefers_config_over_legacy_flags() {
|
||||
#[test]
|
||||
fn web_search_mode_disabled_overrides_legacy_request() {
|
||||
let cfg = ConfigToml {
|
||||
web_search: Some(WebSearchMode::Disabled),
|
||||
web_search: Some(WebSearchMode::Disabled.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut features = Features::with_defaults();
|
||||
@@ -7633,7 +7081,10 @@ async fn to_mcp_config_flows_independent_mcp_2026_features() -> std::io::Result<
|
||||
|
||||
let _ = config.features.enable(Feature::Mcp20260728);
|
||||
let mcp_config = config.to_mcp_config(&plugins_manager).await;
|
||||
assert_eq!(mcp_config.protocol_mode, codex_mcp::McpProtocolMode::V20260728);
|
||||
assert_eq!(
|
||||
mcp_config.protocol_mode,
|
||||
codex_mcp::McpProtocolMode::V20260728
|
||||
);
|
||||
|
||||
let _ = config.features.disable(Feature::Mcp20260728);
|
||||
let _ = config.features.enable(Feature::CodexAppsMcp20260728);
|
||||
@@ -8614,7 +8065,7 @@ async fn for_config_writes_selected_user_config_file() -> anyhow::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let base_config = codex_home.path().join(CONFIG_TOML_FILE);
|
||||
let selected_config = codex_home.path().join("work.config.toml");
|
||||
tokio::fs::write(&base_config, r#"model_provider = "openai""#).await?;
|
||||
tokio::fs::write(&base_config, r#"model_provider = "ollama""#).await?;
|
||||
tokio::fs::write(&selected_config, r#"model = "gpt-old""#).await?;
|
||||
|
||||
let config = ConfigBuilder::without_managed_config_for_tests()
|
||||
@@ -8638,7 +8089,7 @@ async fn for_config_writes_selected_user_config_file() -> anyhow::Result<()> {
|
||||
assert_eq!(selected.model_reasoning_effort, Some(ReasoningEffort::High));
|
||||
assert_eq!(
|
||||
tokio::fs::read_to_string(&base_config).await?,
|
||||
r#"model_provider = "openai""#
|
||||
r#"model_provider = "ollama""#
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@@ -14129,3 +13580,248 @@ fn sqlite_home_env_conflict_reports_an_override() -> std::io::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn implicit_builtin_workspace_profile_preserves_add_dir_metadata_carveouts()
|
||||
-> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let cwd = TempDir::new()?;
|
||||
let extra_root = TempDir::new()?;
|
||||
for subpath in [".git", ".agents", ".codex", ".aws"] {
|
||||
std::fs::create_dir_all(extra_root.path().join(subpath))?;
|
||||
}
|
||||
let project_key = cwd.path().to_string_lossy().to_string();
|
||||
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
ConfigToml {
|
||||
projects: Some(HashMap::from([(
|
||||
project_key,
|
||||
ProjectConfig {
|
||||
trust_level: Some(TrustLevel::Trusted),
|
||||
},
|
||||
)])),
|
||||
windows: Some(WindowsToml {
|
||||
sandbox: Some(WindowsSandboxModeToml::Elevated),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
ConfigOverrides {
|
||||
cwd: Some(cwd.path().to_path_buf()),
|
||||
additional_writable_roots: vec![extra_root.path().to_path_buf()],
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let policy = config.permissions.file_system_sandbox_policy();
|
||||
let extra_root = extra_root.path().abs();
|
||||
assert!(
|
||||
policy.can_write_local_path_with_cwd(extra_root.as_path(), cwd.path()),
|
||||
"expected implicit :workspace to preserve additional writable roots, policy: {policy:?}"
|
||||
);
|
||||
for subpath in [".git", ".agents", ".codex", ".aws"] {
|
||||
assert!(
|
||||
!policy.can_write_local_path_with_cwd(&extra_root.join(subpath), cwd.path()),
|
||||
"expected implicit :workspace to preserve legacy metadata carveout for {subpath}, \
|
||||
policy: {policy:?}"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_sandbox_mode_builds_profiles_with_compatible_projection() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let cwd = TempDir::new()?;
|
||||
let extra_root = test_absolute_path("/tmp/legacy-extra-root");
|
||||
let cases = vec![
|
||||
(
|
||||
"danger-full-access".to_string(),
|
||||
r#"sandbox_mode = "danger-full-access"
|
||||
"#
|
||||
.to_string(),
|
||||
),
|
||||
(
|
||||
"read-only".to_string(),
|
||||
r#"sandbox_mode = "read-only"
|
||||
"#
|
||||
.to_string(),
|
||||
),
|
||||
(
|
||||
"workspace-write".to_string(),
|
||||
format!(
|
||||
r#"sandbox_mode = "workspace-write"
|
||||
|
||||
[sandbox_workspace_write]
|
||||
writable_roots = [{}]
|
||||
exclude_tmpdir_env_var = true
|
||||
exclude_slash_tmp = true
|
||||
"#,
|
||||
serde_json::json!(extra_root)
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
for (name, config_toml) in cases {
|
||||
let cfg = toml::from_str::<ConfigToml>(&config_toml)
|
||||
.unwrap_or_else(|err| panic!("case `{name}` should parse: {err}"));
|
||||
let config = Config::load_from_base_config_with_overrides(
|
||||
cfg,
|
||||
ConfigOverrides {
|
||||
cwd: Some(cwd.path().to_path_buf()),
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let sandbox_policy = config.legacy_sandbox_policy();
|
||||
let file_system_policy = config.permissions.file_system_sandbox_policy();
|
||||
let network_policy = config.permissions.network_sandbox_policy();
|
||||
|
||||
assert_eq!(
|
||||
network_policy,
|
||||
NetworkSandboxPolicy::from(&sandbox_policy),
|
||||
"case `{name}` should preserve network semantics from legacy config"
|
||||
);
|
||||
assert_eq!(
|
||||
file_system_policy
|
||||
.to_legacy_sandbox_policy(network_policy, cwd.path())
|
||||
.unwrap_or_else(|err| panic!("case `{name}` should round-trip: {err}")),
|
||||
sandbox_policy,
|
||||
"case `{name}` should preserve its legacy compatibility projection"
|
||||
);
|
||||
|
||||
match name.as_str() {
|
||||
"danger-full-access" | "read-only" => {
|
||||
assert_eq!(
|
||||
file_system_policy,
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy_for_cwd(
|
||||
&sandbox_policy,
|
||||
cwd.path()
|
||||
),
|
||||
"case `{name}` should match the legacy filesystem projection exactly"
|
||||
);
|
||||
}
|
||||
"workspace-write" => {
|
||||
if cfg!(target_os = "windows") {
|
||||
assert_eq!(
|
||||
sandbox_policy,
|
||||
SandboxPolicy::new_read_only_policy(),
|
||||
"legacy workspace-write should keep the existing Windows downgrade when \
|
||||
the experimental Windows sandbox is disabled"
|
||||
);
|
||||
assert_eq!(
|
||||
file_system_policy,
|
||||
FileSystemSandboxPolicy::from_legacy_sandbox_policy_for_cwd(
|
||||
&sandbox_policy,
|
||||
cwd.path()
|
||||
),
|
||||
"downgraded workspace-write should match the legacy read-only projection"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
assert_eq!(
|
||||
config.permissions.workspace_roots(),
|
||||
&[cwd.abs(), extra_root.clone()]
|
||||
);
|
||||
assert!(
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: cwd.abs().into(),
|
||||
access: FileSystemAccessMode::Write,
|
||||
missing_path_behavior: None,
|
||||
})
|
||||
);
|
||||
assert!(
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: FileSystemPath::Path {
|
||||
path: extra_root.clone().into(),
|
||||
},
|
||||
access: FileSystemAccessMode::Write,
|
||||
missing_path_behavior: None,
|
||||
})
|
||||
);
|
||||
for subpath in [".git", ".agents", ".codex", ".aws"] {
|
||||
assert!(
|
||||
file_system_policy
|
||||
.entries
|
||||
.contains(&FileSystemSandboxEntry {
|
||||
path: FileSystemPath::Path {
|
||||
path: AbsolutePathBuf::resolve_path_against_base(
|
||||
subpath,
|
||||
cwd.path()
|
||||
)
|
||||
.into(),
|
||||
},
|
||||
access: FileSystemAccessMode::Read,
|
||||
missing_path_behavior: Some(
|
||||
codex_protocol::permissions::FileSystemSandboxEntryMissingPathBehavior::Skip,
|
||||
),
|
||||
}),
|
||||
"case `{name}` should materialize `{subpath}` for the runtime workspace \
|
||||
root"
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => unreachable!("unexpected test case `{name}`"),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case("https://managed.example/backend-api/"; "custom")]
|
||||
#[tokio::test]
|
||||
async fn config_applies_managed_auth_store_and_chatgpt_base_url(
|
||||
managed_url: &str,
|
||||
) -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let managed_store = AuthCredentialsStoreMode::Keyring;
|
||||
let requirements = codex_config::ConfigRequirements {
|
||||
cli_auth_credentials_store: Some(Sourced::new(managed_store, RequirementSource::Unknown)),
|
||||
chatgpt_base_url: Some(Sourced::new(
|
||||
managed_url.to_string(),
|
||||
RequirementSource::Unknown,
|
||||
)),
|
||||
..Default::default()
|
||||
};
|
||||
let config_layer_stack = ConfigLayerStack::new(
|
||||
Vec::new(),
|
||||
requirements,
|
||||
codex_config::ConfigRequirementsToml::default(),
|
||||
)?;
|
||||
|
||||
let config = Config::load_config_with_layer_stack(
|
||||
LOCAL_FS.as_ref(),
|
||||
ConfigToml {
|
||||
cli_auth_credentials_store: Some(AuthCredentialsStoreMode::File),
|
||||
chatgpt_base_url: Some("https://user.example/backend-api/".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
ConfigOverrides {
|
||||
cwd: Some(codex_home.path().to_path_buf()),
|
||||
..Default::default()
|
||||
},
|
||||
codex_home.abs(),
|
||||
config_layer_stack,
|
||||
)
|
||||
.await?;
|
||||
|
||||
assert_eq!(config.cli_auth_credentials_store_mode, managed_store);
|
||||
assert_eq!(config.chatgpt_base_url, managed_url);
|
||||
assert!(config.chatgpt_base_url_is_explicit);
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `cli_auth_credentials_store` is overridden")
|
||||
}));
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `chatgpt_base_url` is overridden")
|
||||
}));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user