Skip to main content

rpi_cli/
experimental.rs

1//! Experimental feature gate.
2//!
3//! Port of the upstream `packages/coding-agent/src/core/experimental.ts`.
4//! Experimental surfaces (e.g. the extended footer) are only enabled when
5//! `RPI_EXPERIMENTAL=1` is set.
6
7/// True when `RPI_EXPERIMENTAL=1`. Evaluated once per process.
8pub fn enabled() -> bool {
9    static ENABLED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
10    *ENABLED.get_or_init(|| {
11        std::env::var("RPI_EXPERIMENTAL")
12            .map(|v| v == "1")
13            .unwrap_or(false)
14    })
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[test]
22    fn gate_matches_env() {
23        let expected = std::env::var("RPI_EXPERIMENTAL")
24            .map(|v| v == "1")
25            .unwrap_or(false);
26        assert_eq!(enabled(), expected);
27    }
28}