mirror of
https://github.com/openai/codex.git
synced 2026-11-22 15:15:18 +00:00
Enforce exact values from managed config requirements (#34597)
## What changed - Apply managed values for `sqlite_home`, `log_dir`, `model_catalog_json`, `check_for_update_on_startup`, `allow_login_shell`, the report-submission opt-in, and `windows.sandbox_private_desktop` to the runtime configuration, with source-aware warnings when they override configured values. - Expose these values through `configRequirements/read`, return them from `config/read`, include them in session config locks, and show their sources in the TUI config debug view. - Reject app-server writes that overlap an exact managed requirement with `configRequirementReadonly` while leaving unrelated sibling keys writable. ## Testing - Cover runtime overrides, requirement API mapping, config reads and writes, session lock serialization, cross-platform path URIs, and debug output. GitOrigin-RevId: d4e23b6fd7775c1a6dfe2eab313cdcee50b07081
This commit is contained in:
1 parent
7442f5f932
commit
ee71c4a90f
34 files changed
+1566
-71
No files matched your search
@@ -9093,6 +9093,12 @@ async fn test_requirements_web_search_mode_allowlist_does_not_warn_when_unset()
|
||||
let fixture = create_test_fixture()?;
|
||||
|
||||
let requirements_toml = codex_config::ConfigRequirementsToml {
|
||||
sqlite_home: None,
|
||||
log_dir: None,
|
||||
model_catalog_json: None,
|
||||
check_for_update_on_startup: None,
|
||||
allow_login_shell: None,
|
||||
feedback: None,
|
||||
allowed_approval_policies: None,
|
||||
allowed_approvals_reviewers: None,
|
||||
allowed_sandbox_modes: None,
|
||||
@@ -11710,3 +11716,134 @@ fn test_tui_notification_condition_rejects_unknown_value() {
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
async fn load_with_enterprise_requirement(
|
||||
codex_home: &TempDir,
|
||||
requirements: impl Into<String>,
|
||||
) -> std::io::Result<Config> {
|
||||
ConfigBuilder::without_managed_config_for_tests()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(codex_home.path().to_path_buf()))
|
||||
.cloud_config_bundle(
|
||||
CloudConfigBundleFixture::loader_with_enterprise_requirement(requirements),
|
||||
)
|
||||
.build()
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn exact_requirements_apply_to_runtime_config() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let catalog_path = codex_home.path().join("required-models.json");
|
||||
let mut catalog = bundled_models_response()
|
||||
.unwrap_or_else(|err| panic!("bundled models.json should parse: {err}"));
|
||||
catalog.models = catalog.models.into_iter().take(1).collect();
|
||||
std::fs::write(
|
||||
&catalog_path,
|
||||
serde_json::to_string(&catalog).expect("serialize catalog"),
|
||||
)?;
|
||||
std::fs::write(
|
||||
codex_home.path().join(CONFIG_TOML_FILE),
|
||||
r#"
|
||||
check_for_update_on_startup = true
|
||||
allow_login_shell = true
|
||||
|
||||
[feedback]
|
||||
enabled = true
|
||||
|
||||
[windows]
|
||||
sandbox_private_desktop = true
|
||||
"#,
|
||||
)?;
|
||||
|
||||
let required_sqlite_home = codex_home.path().join("required-state");
|
||||
let required_log_dir = codex_home.path().join("required-logs");
|
||||
let requirements = format!(
|
||||
r#"
|
||||
sqlite_home = {:?}
|
||||
log_dir = {:?}
|
||||
model_catalog_json = {:?}
|
||||
check_for_update_on_startup = false
|
||||
allow_login_shell = false
|
||||
|
||||
[feedback]
|
||||
enabled = false
|
||||
|
||||
[windows]
|
||||
sandbox_private_desktop = false
|
||||
"#,
|
||||
required_sqlite_home.display(),
|
||||
required_log_dir.display(),
|
||||
catalog_path.display(),
|
||||
);
|
||||
let config = load_with_enterprise_requirement(&codex_home, requirements).await?;
|
||||
|
||||
assert_eq!(config.sqlite_home, required_sqlite_home);
|
||||
assert_eq!(config.log_dir, required_log_dir);
|
||||
assert_eq!(config.model_catalog, Some(catalog));
|
||||
assert!(!config.check_for_update_on_startup);
|
||||
assert!(!config.permissions.allow_login_shell);
|
||||
assert!(!config.feedback_enabled);
|
||||
assert!(!config.permissions.windows_sandbox_private_desktop);
|
||||
assert!(config.startup_warnings.iter().any(|warning| {
|
||||
warning.contains("Configured value for `check_for_update_on_startup` is overridden")
|
||||
}));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn absent_allow_login_shell_does_not_report_an_override() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let config = load_with_enterprise_requirement(&codex_home, "allow_login_shell = false").await?;
|
||||
|
||||
assert!(!config.permissions.allow_login_shell);
|
||||
assert!(
|
||||
config
|
||||
.startup_warnings
|
||||
.iter()
|
||||
.all(|warning| !warning.contains("allow_login_shell"))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sqlite_home_env_conflict_reports_an_override() -> std::io::Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let required = AbsolutePathBuf::try_from(codex_home.path().join("required-state"))?;
|
||||
let environment = codex_home.path().join("environment-state");
|
||||
let requirement = Sourced::new(required.clone(), RequirementSource::Unknown);
|
||||
let mut warnings = Vec::new();
|
||||
|
||||
super::requirements::push_sqlite_home_env_override_warning(
|
||||
/*configured_sqlite_home*/ None,
|
||||
Some(environment.as_path()),
|
||||
Some(&requirement),
|
||||
&mut warnings,
|
||||
);
|
||||
assert_eq!(
|
||||
warnings,
|
||||
vec![format!(
|
||||
"Environment value for `$CODEX_SQLITE_HOME` is overridden by the required `sqlite_home` value {required:?} from {}.",
|
||||
RequirementSource::Unknown
|
||||
)]
|
||||
);
|
||||
|
||||
warnings.clear();
|
||||
super::requirements::push_sqlite_home_env_override_warning(
|
||||
/*configured_sqlite_home*/ None,
|
||||
Some(required.as_path()),
|
||||
Some(&requirement),
|
||||
&mut warnings,
|
||||
);
|
||||
assert!(warnings.is_empty());
|
||||
|
||||
super::requirements::push_sqlite_home_env_override_warning(
|
||||
Some(&required),
|
||||
Some(environment.as_path()),
|
||||
Some(&requirement),
|
||||
&mut warnings,
|
||||
);
|
||||
assert!(warnings.is_empty());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user