Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions bt-daemon/src/codex_hooks/config.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
use serde::Deserialize;
use std::collections::BTreeMap;

#[derive(Deserialize)]
pub(super) struct Config {
#[serde(default)]
pub(super) features: BTreeMap<String, bool>,
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<bool>,
#[serde(default)]
codex_hooks: Option<bool>,
}

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)
}
}
19 changes: 19 additions & 0 deletions bt-daemon/src/codex_hooks/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ConfigRead>(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::<ConfigRead>(json!({"config": {}}))
.unwrap()
.config
.hooks_enabled());
}
Loading