Generalize hook handler execution (#37644)

## What changed

- Represent configured handlers by handler kind and route execution through the
  hooks engine, while preserving command hook behavior.
- Reject MCP tool inputs containing values such as `null` that cannot be
  represented in TOML for trust hashing.

## Testing

- Add coverage for rejecting `null` at the top level and within nested MCP tool
  input objects and arrays.

GitOrigin-RevId: 3854a349c2a721691450467592f99cf57e6260ef
This commit is contained in:
Abhinav authored and copyberry committed 2026-08-09 00:57:15 +00:00
1 parent 420accf199
commit a875dd6b22
17 files changed
+512 -333

No files matched your search

+35 -2
View File
@@ -68,7 +68,7 @@ fn hooks_file_deserializes_mcp_tool_handler_with_json_inputs() {
"tool": "scan",
"input": {
"file_path": "${tool_input.file_path}",
"optional": null,
"include_ignored": false,
},
"timeout": 30,
"statusMessage": "Scanning file",
@@ -88,7 +88,10 @@ fn hooks_file_deserializes_mcp_tool_handler_with_json_inputs() {
"file_path".to_string(),
serde_json::Value::String("${tool_input.file_path}".to_string()),
),
("optional".to_string(), serde_json::Value::Null),
(
"include_ignored".to_string(),
serde_json::Value::Bool(false)
),
]),
timeout_sec: Some(30),
status_message: Some("Scanning file".to_string()),
@@ -96,6 +99,36 @@ fn hooks_file_deserializes_mcp_tool_handler_with_json_inputs() {
);
}
#[test]
fn hooks_file_rejects_mcp_tool_handler_with_null_input() {
for input in [
serde_json::json!({ "optional": null }),
serde_json::json!({ "metadata": { "optional": null } }),
serde_json::json!({ "values": [null] }),
] {
let error = serde_json::from_value::<HooksFile>(serde_json::json!({
"hooks": {
"PostToolUse": [{
"hooks": [{
"type": "mcp_tool",
"server": "security",
"tool": "scan",
"input": input,
}],
}],
},
}))
.expect_err("literal null MCP hook arguments should be rejected");
assert!(
error
.to_string()
.contains("MCP hook input must be representable as TOML"),
"unexpected parse error: {error}"
);
}
}
#[test]
fn hooks_file_rejects_events_outside_hooks_object() {
let error = serde_json::from_str::<HooksFile>(