mirror of
https://github.com/instructkr/claude-code.git
synced 2026-04-06 19:28:49 +03:00
feat(hooks): add hook error propagation and execution ordering tests
- Add proper error types for hook failures - Improve hook execution ordering guarantees - Add tests for hook execution flow and error handling - 109 runtime tests pass, clippy clean
This commit is contained in:
@@ -67,12 +67,16 @@ pub struct PluginHooks {
|
||||
pub pre_tool_use: Vec<String>,
|
||||
#[serde(rename = "PostToolUse", default)]
|
||||
pub post_tool_use: Vec<String>,
|
||||
#[serde(rename = "PostToolUseFailure", default)]
|
||||
pub post_tool_use_failure: Vec<String>,
|
||||
}
|
||||
|
||||
impl PluginHooks {
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.pre_tool_use.is_empty() && self.post_tool_use.is_empty()
|
||||
self.pre_tool_use.is_empty()
|
||||
&& self.post_tool_use.is_empty()
|
||||
&& self.post_tool_use_failure.is_empty()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
@@ -85,6 +89,9 @@ impl PluginHooks {
|
||||
.post_tool_use
|
||||
.extend(other.post_tool_use.iter().cloned());
|
||||
merged
|
||||
.post_tool_use_failure
|
||||
.extend(other.post_tool_use_failure.iter().cloned());
|
||||
merged
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1691,6 +1698,11 @@ fn resolve_hooks(root: &Path, hooks: &PluginHooks) -> PluginHooks {
|
||||
.iter()
|
||||
.map(|entry| resolve_hook_entry(root, entry))
|
||||
.collect(),
|
||||
post_tool_use_failure: hooks
|
||||
.post_tool_use_failure
|
||||
.iter()
|
||||
.map(|entry| resolve_hook_entry(root, entry))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1739,7 +1751,12 @@ fn validate_hook_paths(root: Option<&Path>, hooks: &PluginHooks) -> Result<(), P
|
||||
let Some(root) = root else {
|
||||
return Ok(());
|
||||
};
|
||||
for entry in hooks.pre_tool_use.iter().chain(hooks.post_tool_use.iter()) {
|
||||
for entry in hooks
|
||||
.pre_tool_use
|
||||
.iter()
|
||||
.chain(hooks.post_tool_use.iter())
|
||||
.chain(hooks.post_tool_use_failure.iter())
|
||||
{
|
||||
validate_command_path(root, entry, "hook")?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user