Skip to main content

mur_common/config/
browser_setup.rs

1//! Browser setup journey switches (`browser_setup:`).
2
3use super::*;
4
5/// The `browser_request` route ships dark (#2360): nothing yet shows the
6/// user a card for a recorded request, and the route tells the agent to stop
7/// and not offer the setup commands. Flip this default once murmur or Hub
8/// renders the card.
9pub const BROWSER_SETUP_DEFAULT_REQUEST_ROUTE: bool = false;
10
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12pub struct BrowserSetupConfig {
13    /// On: every agent gets the built-in `browser_request` tool and the
14    /// `## Browser` prompt section. Off: neither is registered. An explicit
15    /// profile `Deny` still wins when on.
16    #[serde(default = "browser_setup_default_request_route")]
17    pub request_route: bool,
18}
19
20impl Default for BrowserSetupConfig {
21    fn default() -> Self {
22        Self {
23            request_route: browser_setup_default_request_route(),
24        }
25    }
26}
27
28fn browser_setup_default_request_route() -> bool {
29    BROWSER_SETUP_DEFAULT_REQUEST_ROUTE
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn request_route_is_off_when_the_block_is_absent() {
38        let c: Config = serde_yaml::from_str("{}").unwrap();
39        assert_eq!(
40            c.browser_setup.request_route,
41            BROWSER_SETUP_DEFAULT_REQUEST_ROUTE
42        );
43        assert!(!c.browser_setup.request_route);
44    }
45
46    #[test]
47    fn request_route_is_off_when_the_block_is_empty() {
48        let c: Config = serde_yaml::from_str("browser_setup: {}\n").unwrap();
49        assert!(!c.browser_setup.request_route);
50    }
51
52    #[test]
53    fn request_route_can_be_turned_on() {
54        let c: Config = serde_yaml::from_str("browser_setup:\n  request_route: true\n").unwrap();
55        assert!(c.browser_setup.request_route);
56    }
57
58    #[test]
59    fn the_switch_survives_a_round_trip() {
60        let c: Config = serde_yaml::from_str("browser_setup:\n  request_route: true\n").unwrap();
61        let back: Config = serde_yaml::from_str(&serde_yaml::to_string(&c).unwrap()).unwrap();
62        assert_eq!(back.browser_setup, c.browser_setup);
63    }
64}