fix: load DeepSeek config from browser runtime

This commit is contained in:
zyl
2026-03-27 00:34:14 +08:00
parent 11c0b0fc70
commit 0e3af5a391
8 changed files with 531 additions and 52 deletions

View File

@@ -1,3 +1,4 @@
use std::fs;
use std::path::Path;
use std::sync::{Mutex, OnceLock};
@@ -7,6 +8,7 @@ use sgclaw::compat::config_adapter::{
zeroclaw_workspace_dir,
};
use sgclaw::config::DeepSeekSettings;
use uuid::Uuid;
fn env_lock() -> &'static Mutex<()> {
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
@@ -53,3 +55,44 @@ fn zeroclaw_config_adapter_uses_deterministic_workspace_dir() {
assert_eq!(config.default_model.as_deref(), Some("deepseek-reasoner"));
assert_eq!(config.api_url.as_deref(), Some("https://proxy.example.com/v1"));
}
#[test]
fn deepseek_settings_reload_from_browser_config_path_after_file_changes() {
let root = std::env::temp_dir().join(format!("sgclaw-config-{}", Uuid::new_v4()));
fs::create_dir_all(&root).unwrap();
let config_path = root.join("sgclaw_config.json");
fs::write(
&config_path,
r#"{
"apiKey": "sk-first",
"baseUrl": "",
"model": ""
}"#,
)
.unwrap();
let first = DeepSeekSettings::load(Some(config_path.as_path()))
.unwrap()
.expect("expected config file to produce settings");
assert_eq!(first.api_key, "sk-first");
assert_eq!(first.base_url, "https://api.deepseek.com");
assert_eq!(first.model, "deepseek-chat");
fs::write(
&config_path,
r#"{
"apiKey": "sk-second",
"baseUrl": "https://proxy.example.com/v1",
"model": "deepseek-reasoner"
}"#,
)
.unwrap();
let second = DeepSeekSettings::load(Some(config_path.as_path()))
.unwrap()
.expect("expected updated config file to produce settings");
assert_eq!(second.api_key, "sk-second");
assert_eq!(second.base_url, "https://proxy.example.com/v1");
assert_eq!(second.model, "deepseek-reasoner");
}