#![cfg(test)]
use tempfile::TempDir;
use thoughts_tool::RepoConfigManager;
#[test]
fn test_config_create_detects_malformed_json_as_already_configured() {
let temp_dir = TempDir::new().unwrap();
let thoughts_dir = temp_dir.path().join(".thoughts");
std::fs::create_dir_all(&thoughts_dir).unwrap();
let config_path = thoughts_dir.join("config.json");
std::fs::write(&config_path, "{ invalid json !!!").unwrap();
assert!(config_path.exists());
let config_exists = config_path.exists();
assert!(
config_exists,
"Config file should exist and be detected as 'already configured'"
);
}
#[test]
fn test_mount_remove_does_not_create_config_when_absent() {
let temp_dir = TempDir::new().unwrap();
let thoughts_dir = temp_dir.path().join(".thoughts");
std::fs::create_dir_all(&thoughts_dir).unwrap();
let config_path = thoughts_dir.join("config.json");
assert!(!config_path.exists());
let manager = RepoConfigManager::new(temp_dir.path().to_path_buf());
let result = manager.load_v2_or_bail();
assert!(result.is_err());
assert!(
result
.unwrap_err()
.to_string()
.contains("No repository configuration found")
);
assert!(
!config_path.exists(),
"Config file should not be created when loading fails"
);
}