Skip to content

Commit 836d820

Browse files
author
windows-xp
committed
fix(agent): resolve oauth cache home cross-platform
Co-authored-by: windows-xp <31c9c2d1ce0b4e88e27027eb68710d35c12f1edb20289ecdf1a2e1fd4a7c8c69@buzz.block.builderlab.xyz> Signed-off-by: windows-xp <31c9c2d1ce0b4e88e27027eb68710d35c12f1edb20289ecdf1a2e1fd4a7c8c69@buzz.block.builderlab.xyz>
1 parent f53bbd1 commit 836d820

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/buzz-agent/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ hex = { workspace = true }
4343
sha2 = { workspace = true }
4444
urlencoding = "2"
4545
webbrowser = "1"
46+
dirs = "6"
4647

4748
[target.'cfg(unix)'.dependencies]
4849
nix = { version = "0.31", default-features = false, features = ["signal", "process"] }

‎crates/buzz-agent/src/auth.rs‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,12 @@ fn cache_path_for(cfg: &PkceOAuthConfig) -> Result<PathBuf, AgentError> {
453453

454454
let dir = match &cfg.cache_dir_override {
455455
Some(p) => p.join(&cfg.cache_namespace),
456-
None => {
457-
let home = std::env::var("HOME")
458-
.map_err(|_| AgentError::Llm("oauth cache: $HOME not set".into()))?;
459-
PathBuf::from(home)
460-
.join(".config")
461-
.join("buzz-agent")
462-
.join("oauth")
463-
.join(&cfg.cache_namespace)
464-
}
456+
None => dirs::home_dir()
457+
.ok_or_else(|| AgentError::Llm("oauth cache: home directory not found".into()))?
458+
.join(".config")
459+
.join("buzz-agent")
460+
.join("oauth")
461+
.join(&cfg.cache_namespace),
465462
};
466463
Ok(dir.join(format!("{hash}.json")))
467464
}
@@ -683,8 +680,7 @@ mod tests {
683680
}
684681

685682
#[test]
686-
fn cache_path_includes_namespace_and_hash() {
687-
// HOME is required; cargo test runs set it.
683+
fn cache_path_uses_platform_home_directory() {
688684
let cfg = PkceOAuthConfig {
689685
discovery_url: "https://example.com/.well-known".into(),
690686
client_id: "abc".into(),
@@ -693,8 +689,14 @@ mod tests {
693689
cache_dir_override: None,
694690
};
695691
let p = cache_path_for(&cfg).unwrap();
696-
assert!(p.to_string_lossy().contains("/buzz-agent/oauth/demo/"));
697-
assert!(p.extension().and_then(|s| s.to_str()) == Some("json"));
692+
let expected_dir = dirs::home_dir()
693+
.unwrap()
694+
.join(".config")
695+
.join("buzz-agent")
696+
.join("oauth")
697+
.join("demo");
698+
assert_eq!(p.parent(), Some(expected_dir.as_path()));
699+
assert_eq!(p.extension().and_then(|s| s.to_str()), Some("json"));
698700
}
699701

700702
#[test]

0 commit comments

Comments
 (0)