Skip to content

An agent-managed museum exhibit, built in Rust with Gajae-Code / LazyCodex — developed and maintained with no human intervention.

Rust

Merge branch 'dori/hooks-parity' into main

YeonGyu-Kimef48b7e515b5
diff --cc rust/crates/plugins/src/lib.rs
index 6c7c0bcd,ed1eb760..3070d177
--- a/rust/crates/plugins/src/lib.rs
+++ b/rust/crates/plugins/src/lib.rs
@@@ -2292,20 -2117,16 +2298,30 @@@ mod tests
);
}
+ fn write_directory_path_plugin(root: &Path, name: &str) {
+ fs::create_dir_all(root.join("hooks").join("pre-dir")).expect("hook dir");
+ fs::create_dir_all(root.join("tools").join("tool-dir")).expect("tool dir");
+ fs::create_dir_all(root.join("commands").join("sync-dir")).expect("command dir");
+ fs::create_dir_all(root.join("lifecycle").join("init-dir")).expect("lifecycle dir");
+ write_file(
+ root.join(MANIFEST_FILE_NAME).as_path(),
+ format!(
+ "{{\n \"name\": \"{name}\",\n \"version\": \"1.0.0\",\n \"description\": \"directory path plugin\",\n \"hooks\": {{\n \"PreToolUse\": [\"./hooks/pre-dir\"]\n }},\n \"lifecycle\": {{\n \"Init\": [\"./lifecycle/init-dir\"]\n }},\n \"tools\": [\n {{\n \"name\": \"dir_tool\",\n \"description\": \"Directory tool\",\n \"inputSchema\": {{\"type\": \"object\"}},\n \"command\": \"./tools/tool-dir\"\n }}\n ],\n \"commands\": [\n {{\n \"name\": \"sync\",\n \"description\": \"Directory command\",\n \"command\": \"./commands/sync-dir\"\n }}\n ]\n}}"
+ )
+ .as_str(),
+ );
+ }
+
+ fn write_broken_failure_hook_plugin(root: &Path, name: &str) {
+ write_file(
+ root.join(MANIFEST_RELATIVE_PATH).as_path(),
+ format!(
+ "{{\n \"name\": \"{name}\",\n \"version\": \"1.0.0\",\n \"description\": \"broken plugin\",\n \"hooks\": {{\n \"PostToolUseFailure\": [\"./hooks/missing-failure.sh\"]\n }}\n}}"
+ )
+ .as_str(),
+ );
+ }
+
fn write_lifecycle_plugin(root: &Path, name: &str, version: &str) -> PathBuf {
let log_path = root.join("lifecycle.log");
write_file(
@@@ -3102,82 -2839,9 +3118,83 @@@
let _ = fs::remove_dir_all(source_root);
}
+ #[test]
+ fn plugin_registry_report_collects_load_failures_without_dropping_valid_plugins() {
+ // given
+ let config_home = temp_dir("report-home");
+ let external_root = temp_dir("report-external");
+ write_external_plugin(&external_root.join("valid"), "valid-report", "1.0.0");
+ write_broken_plugin(&external_root.join("broken"), "broken-report");
+
+ let mut config = PluginManagerConfig::new(&config_home);
+ config.external_dirs = vec![external_root.clone()];
+ let manager = PluginManager::new(config);
+
+ // when
+ let report = manager
+ .plugin_registry_report()
+ .expect("report should tolerate invalid external plugins");
+
+ // then
+ assert!(report.registry().contains("valid-report@external"));
+ assert_eq!(report.failures().len(), 1);
+ assert_eq!(report.failures()[0].kind, PluginKind::External);
+ assert!(report.failures()[0]
+ .plugin_root
+ .ends_with(Path::new("broken")));
+ assert!(report.failures()[0]
+ .error()
+ .to_string()
+ .contains("does not exist"));
+
+ let error = manager
+ .plugin_registry()
+ .expect_err("strict registry should surface load failures");
+ match error {
+ PluginError::LoadFailures(failures) => {
+ assert_eq!(failures.len(), 1);
+ assert!(failures[0].plugin_root.ends_with(Path::new("broken")));
+ }
+ other => panic!("expected load failures, got {other}"),
+ }
+
+ let _ = fs::remove_dir_all(config_home);
+ let _ = fs::remove_dir_all(external_root);
+ }
+
+ #[test]
+ fn installed_plugin_registry_report_collects_load_failures_from_install_root() {
+ // given
+ let config_home = temp_dir("installed-report-home");
+ let bundled_root = temp_dir("installed-report-bundled");
+ let install_root = config_home.join("plugins").join("installed");
+ write_external_plugin(&install_root.join("valid"), "installed-valid", "1.0.0");
+ write_broken_plugin(&install_root.join("broken"), "installed-broken");
+
+ let mut config = PluginManagerConfig::new(&config_home);
+ config.bundled_root = Some(bundled_root.clone());
+ config.install_root = Some(install_root);
+ let manager = PluginManager::new(config);
+
+ // when
+ let report = manager
+ .installed_plugin_registry_report()
+ .expect("installed report should tolerate invalid installed plugins");
+
+ // then
+ assert!(report.registry().contains("installed-valid@external"));
+ assert_eq!(report.failures().len(), 1);
+ assert!(report.failures()[0]
+ .plugin_root
+ .ends_with(Path::new("broken")));
+
+ let _ = fs::remove_dir_all(config_home);
+ let _ = fs::remove_dir_all(bundled_root);
+ }
+
#[test]
fn rejects_plugin_sources_with_missing_hook_paths() {
+ // given
let config_home = temp_dir("broken-home");
let source_root = temp_dir("broken-source");
write_broken_plugin(&source_root, "broken");