Files
IdeA/crates/infrastructure/tests/project_plugin_settings.rs

85 lines
2.5 KiB
Rust

use std::path::PathBuf;
use std::sync::Arc;
use domain::{
AgentId, AgentPluginAssignments, FileSystem, PluginId, PluginSkillId, PluginSkillRef,
ProjectPath, ProjectPluginActivation, ProjectPluginSettings, ProjectPluginSettingsStore,
};
use infrastructure::{FsProjectPluginSettingsStore, LocalFileSystem};
use uuid::Uuid;
struct TempDir(PathBuf);
impl TempDir {
fn new() -> Self {
let path = std::env::temp_dir().join(format!("idea-project-plugins-{}", Uuid::new_v4()));
std::fs::create_dir_all(&path).unwrap();
Self(path)
}
fn root(&self) -> ProjectPath {
ProjectPath::new(self.0.to_string_lossy().into_owned()).unwrap()
}
}
impl Drop for TempDir {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
fn store() -> FsProjectPluginSettingsStore {
let fs: Arc<dyn FileSystem> = Arc::new(LocalFileSystem::new());
FsProjectPluginSettingsStore::new(fs)
}
#[tokio::test]
async fn missing_document_returns_version_one_defaults() {
let tmp = TempDir::new();
let settings = store().load(&tmp.root()).await.unwrap();
assert_eq!(settings, ProjectPluginSettings::default());
}
#[tokio::test]
async fn settings_round_trip_under_project_ideai_directory() {
let tmp = TempDir::new();
let plugin_id = PluginId::new("dev.acme.tools").unwrap();
let agent_id = AgentId::from_uuid(Uuid::from_u128(42));
let settings = ProjectPluginSettings {
version: 1,
plugins: vec![ProjectPluginActivation {
plugin_id: plugin_id.clone(),
enabled: true,
}],
agents: vec![AgentPluginAssignments {
agent_id,
skills: vec![PluginSkillRef {
plugin_id,
skill_id: PluginSkillId::new("build-debug").unwrap(),
}],
tools: Vec::new(),
}],
};
store().save(&tmp.root(), &settings).await.unwrap();
assert_eq!(store().load(&tmp.root()).await.unwrap(), settings);
assert!(tmp.0.join(".ideai/project-plugins.json").is_file());
}
#[tokio::test]
async fn unsupported_document_version_is_rejected() {
let tmp = TempDir::new();
std::fs::create_dir_all(tmp.0.join(".ideai")).unwrap();
std::fs::write(
tmp.0.join(".ideai/project-plugins.json"),
br#"{"version":2,"plugins":[],"agents":[]}"#,
)
.unwrap();
let error = store().load(&tmp.root()).await.unwrap_err();
assert!(error
.to_string()
.contains("unsupported project plugin settings version 2"));
}