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:
Abhinav authored and copyberry committed 2026-07-21 19:08:58 +00:00
1 parent 7442f5f932
commit ee71c4a90f
34 files changed
+1566 -71

No files matched your search

@@ -77,6 +77,7 @@ impl ComposableRequirementsLayer {
.as_ref()
.and_then(|_| hostname_resolver());
requirements.apply_remote_sandbox_config(hostname.as_deref());
materialize_resolved_path_requirements(&mut regular_toml, &requirements)?;
materialize_remote_sandbox_config(&mut regular_toml, &requirements)?;
strip_special_fields(&mut regular_toml);
@@ -140,6 +141,30 @@ fn parse_layer_requirements(
}
}
fn materialize_resolved_path_requirements(
layer_toml: &mut TomlValue,
requirements: &ConfigRequirementsToml,
) -> Result<(), RequirementsCompositionError> {
let Some(table) = layer_toml.as_table_mut() else {
return Ok(());
};
for (key, value) in [
("sqlite_home", requirements.sqlite_home.as_ref()),
("log_dir", requirements.log_dir.as_ref()),
(
"model_catalog_json",
requirements.model_catalog_json.as_ref(),
),
] {
if let Some(value) = value {
table.insert(key.to_string(), toml_value_from_serializable(value)?);
}
}
Ok(())
}
fn materialize_remote_sandbox_config(
layer_toml: &mut TomlValue,
requirements: &ConfigRequirementsToml,
@@ -206,6 +206,12 @@ fn populate_merged_regular_fields_with_sources(
// Destructure without `..` so every new requirements field must choose
// whether it belongs in the regular TOML merge path or in a special merger.
let ConfigRequirementsToml {
sqlite_home,
log_dir,
model_catalog_json,
check_for_update_on_startup,
allow_login_shell,
feedback,
allowed_approval_policies,
allowed_approvals_reviewers,
allowed_sandbox_modes,
@@ -232,6 +238,15 @@ fn populate_merged_regular_fields_with_sources(
guardian_policy_config,
} = requirements;
set_sourced!(sqlite_home, &["sqlite_home"]);
set_sourced!(log_dir, &["log_dir"]);
set_sourced!(model_catalog_json, &["model_catalog_json"]);
set_sourced!(
check_for_update_on_startup,
&["check_for_update_on_startup"]
);
set_sourced!(allow_login_shell, &["allow_login_shell"]);
set_sourced!(feedback, &["feedback"]);
set_sourced!(allowed_approval_policies, &["allowed_approval_policies"]);
set_sourced!(
allowed_approvals_reviewers,
@@ -14,6 +14,7 @@ use pretty_assertions::assert_eq;
use std::cell::Cell;
use std::collections::BTreeMap;
use tempfile::TempDir;
use tempfile::tempdir;
fn layer(id: &str, name: &str, contents: &str) -> RequirementsLayerEntry {
RequirementsLayerEntry::from_toml(
@@ -149,6 +150,45 @@ service_tier = "fast"
);
}
#[test]
fn relative_paths_resolve_against_their_own_layer_base() {
let low_dir = tempdir().expect("low-priority requirements directory");
let high_dir = tempdir().expect("high-priority requirements directory");
let low_base = AbsolutePathBuf::from_absolute_path(low_dir.path()).expect("absolute low base");
let high_base =
AbsolutePathBuf::from_absolute_path(high_dir.path()).expect("absolute high base");
let composed = compose(vec![
layer(
"req_low",
"Low",
"sqlite_home = \"state\"\nlog_dir = \"low-logs\"",
)
.with_base_dir(low_base),
layer(
"req_high",
"High",
"log_dir = \"high-logs\"\nmodel_catalog_json = \"models.json\"",
)
.with_base_dir(high_base),
])
.expect("compose requirements")
.expect("requirements present");
assert_eq!(
composed.sqlite_home.as_deref(),
Some(low_dir.path().join("state").as_path())
);
assert_eq!(
composed.log_dir.as_deref(),
Some(high_dir.path().join("high-logs").as_path())
);
assert_eq!(
composed.model_catalog_json.as_deref(),
Some(high_dir.path().join("models.json").as_path())
);
}
#[test]
fn composition_strategy_applies_to_non_cloud_layers() {
let mdm_source = RequirementSource::MdmManagedPreferences {