diff --git a/bt-daemon/src/codex_hooks/config.rs b/bt-daemon/src/codex_hooks/config.rs index c3d5b48f..77a8d7b6 100644 --- a/bt-daemon/src/codex_hooks/config.rs +++ b/bt-daemon/src/codex_hooks/config.rs @@ -1,15 +1,24 @@ use serde::Deserialize; -use std::collections::BTreeMap; #[derive(Deserialize)] pub(super) struct Config { #[serde(default)] - pub(super) features: BTreeMap, + pub(super) features: Features, +} + +/// Only the flags setup reads. Codex reports every feature flag here, and some +/// are `null` when unset (for example `network_proxy`), so other flags must not +/// be decoded. `null` and an absent flag both mean Codex's default. +#[derive(Default, Deserialize)] +pub(super) struct Features { + #[serde(default)] + hooks: Option, + #[serde(default)] + codex_hooks: Option, } impl Config { pub(super) fn hooks_enabled(&self) -> bool { - self.features.get("hooks") != Some(&false) - && self.features.get("codex_hooks") != Some(&false) + self.features.hooks != Some(false) && self.features.codex_hooks != Some(false) } } diff --git a/bt-daemon/src/codex_hooks/tests.rs b/bt-daemon/src/codex_hooks/tests.rs index 0ecc412b..dd50351a 100644 --- a/bt-daemon/src/codex_hooks/tests.rs +++ b/bt-daemon/src/codex_hooks/tests.rs @@ -53,3 +53,22 @@ async fn rpc_ignores_notifications_and_reports_unsupported_methods() { "hooks/list" ); } + +#[test] +fn config_read_tolerates_null_feature_flags() { + let read = |features: Value| { + serde_json::from_value::(json!({"config": {"features": features}})) + .unwrap() + .config + .hooks_enabled() + }; + assert!(read(json!({"hooks": true, "network_proxy": null}))); + assert!(read(json!({"hooks": null, "codex_hooks": null}))); + assert!(read(json!({"network_proxy": {"enabled": true}}))); + assert!(!read(json!({"hooks": false, "network_proxy": null}))); + assert!(!read(json!({"hooks": true, "codex_hooks": false}))); + assert!(serde_json::from_value::(json!({"config": {}})) + .unwrap() + .config + .hooks_enabled()); +}