|
2 | 2 | //! `reader.rs` stays under the 1000-line budget; `#[path]`-included from |
3 | 3 | //! there). |
4 | 4 |
|
5 | | -use std::collections::BTreeMap; |
| 5 | +use std::{collections::BTreeMap, path::Path, sync::Mutex}; |
6 | 6 |
|
7 | 7 | use super::*; |
8 | 8 | use crate::managed_agents::discovery::KnownAcpRuntime; |
9 | 9 | use crate::managed_agents::types::ManagedAgentRecord; |
10 | 10 |
|
| 11 | +static GOOSE_PATH_ROOT_LOCK: Mutex<()> = Mutex::new(()); |
| 12 | + |
| 13 | +fn with_goose_path_root<T>(value: Option<&str>, body: impl FnOnce() -> T) -> T { |
| 14 | + let _guard = GOOSE_PATH_ROOT_LOCK |
| 15 | + .lock() |
| 16 | + .unwrap_or_else(|err| err.into_inner()); |
| 17 | + let prior = std::env::var_os("GOOSE_PATH_ROOT"); |
| 18 | + match value { |
| 19 | + Some(value) => std::env::set_var("GOOSE_PATH_ROOT", value), |
| 20 | + None => std::env::remove_var("GOOSE_PATH_ROOT"), |
| 21 | + } |
| 22 | + let output = body(); |
| 23 | + match prior { |
| 24 | + Some(value) => std::env::set_var("GOOSE_PATH_ROOT", value), |
| 25 | + None => std::env::remove_var("GOOSE_PATH_ROOT"), |
| 26 | + } |
| 27 | + output |
| 28 | +} |
| 29 | + |
11 | 30 | fn test_runtime() -> &'static KnownAcpRuntime { |
12 | 31 | &KnownAcpRuntime { |
13 | 32 | id: "goose", |
@@ -111,6 +130,68 @@ fn pre_spawn_surface_reports_pending_acp_tiers() { |
111 | 130 | assert_eq!(surface.sources.env_vars, ConfigTierStatus::Available); |
112 | 131 | } |
113 | 132 |
|
| 133 | +#[test] |
| 134 | +fn surface_reports_mcp_specific_config_path() { |
| 135 | + let record = test_record(); |
| 136 | + let runtime = test_runtime(); |
| 137 | + let surface = with_goose_path_root(None, || { |
| 138 | + read_config_surface(&record, Some(runtime), None, None) |
| 139 | + }); |
| 140 | + |
| 141 | + let path = surface |
| 142 | + .sources |
| 143 | + .mcp_config_file_path |
| 144 | + .expect("mcp config path"); |
| 145 | + let expected_suffix = Path::new(".config").join("goose").join("config.yaml"); |
| 146 | + assert!( |
| 147 | + Path::new(&path).ends_with(&expected_suffix), |
| 148 | + "unexpected MCP config path: {path}" |
| 149 | + ); |
| 150 | +} |
| 151 | + |
| 152 | +#[test] |
| 153 | +fn goose_mcp_config_path_follows_path_root_override() { |
| 154 | + let record = test_record(); |
| 155 | + let runtime = test_runtime(); |
| 156 | + let surface = with_goose_path_root(Some("/tmp/buzz-goose-root"), || { |
| 157 | + read_config_surface(&record, Some(runtime), None, None) |
| 158 | + }); |
| 159 | + |
| 160 | + let expected_path = Path::new("/tmp/buzz-goose-root") |
| 161 | + .join("config") |
| 162 | + .join("config.yaml"); |
| 163 | + assert_eq!( |
| 164 | + surface |
| 165 | + .sources |
| 166 | + .mcp_config_file_path |
| 167 | + .as_deref() |
| 168 | + .map(Path::new), |
| 169 | + Some(expected_path.as_path()) |
| 170 | + ); |
| 171 | +} |
| 172 | + |
| 173 | +#[test] |
| 174 | +fn claude_surface_uses_mcp_config_path_not_settings_path() { |
| 175 | + let record = test_record(); |
| 176 | + let runtime = &KnownAcpRuntime { |
| 177 | + id: "claude", |
| 178 | + config_file_path: Some("~/.claude/settings.json"), |
| 179 | + ..*test_runtime() |
| 180 | + }; |
| 181 | + let surface = read_config_surface(&record, Some(runtime), None, None); |
| 182 | + |
| 183 | + assert!(surface |
| 184 | + .sources |
| 185 | + .config_file_path |
| 186 | + .as_deref() |
| 187 | + .is_some_and(|path| path.ends_with(".claude/settings.json"))); |
| 188 | + assert!(surface |
| 189 | + .sources |
| 190 | + .mcp_config_file_path |
| 191 | + .as_deref() |
| 192 | + .is_some_and(|path| path.ends_with(".claude.json"))); |
| 193 | +} |
| 194 | + |
114 | 195 | #[test] |
115 | 196 | fn record_model_overrides_file_model() { |
116 | 197 | let mut record = test_record(); |
|
0 commit comments