Add keyed shell environment policy filters (#34590)

## What changed

- Add `shell_environment_policy.filters`, mapping environment-variable patterns to `include` or `exclude`, while continuing to accept the legacy `exclude` and `include_only` arrays.
- Merge filter keys case-insensitively across config layers so higher-precedence entries can override individual patterns. Switching representations replaces the other representation instead of combining them.
- Reject mixed, duplicate, or malformed filter definitions in enabled layers, config writes, and reloads, while retaining the previous session configuration when a reload is invalid.
- Make config-manager reads and writes representation-aware and preserve existing formatting when updating individual policy values.

## Testing

Add coverage for parsing, schema constraints, layered merging, validation and diagnostics, config writes, override metadata, and invalid session reloads.

GitOrigin-RevId: e15464bca53e6e7ef31fcc97537fda60ed5d670a
This commit is contained in:
Abhinav authored and copyberry committed 2026-07-21 18:23:26 +00:00
1 parent 65f8bf6853
commit 7442f5f932
29 files changed
+1662 -115

No files matched your search

+28
View File
@@ -73,3 +73,31 @@ fn config_schema_hides_unsupported_inline_mcp_bearer_token() {
(false, true),
);
}
#[test]
fn shell_environment_policy_schema_rejects_mixed_filter_representations() {
let schema_json = config_schema_json().expect("serialize config schema");
let schema_value: serde_json::Value =
serde_json::from_slice(&schema_json).expect("decode schema json");
let constraints = schema_value
.pointer("/definitions/ShellEnvironmentPolicyToml/allOf")
.and_then(serde_json::Value::as_array)
.expect("shell environment policy constraints should be an array");
let required_pairs = constraints
.iter()
.map(|constraint| {
constraint
.pointer("/not/required")
.expect("constraint should prohibit a required-field pair")
.clone()
})
.collect::<Vec<_>>();
assert_eq!(
required_pairs,
vec![
serde_json::json!(["exclude", "filters"]),
serde_json::json!(["filters", "include_only"]),
]
);
}