use std::collections::HashMap;
use std::panic::{self, AssertUnwindSafe};
use std::time::{Duration, Instant};
use crate::error::{VcpError, VcpResult};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HookType {
PreInject,
PostSelect,
OnTransition,
OnConflict,
OnViolation,
Periodic,
}
impl std::fmt::Display for HookType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let label = match self {
HookType::PreInject => "pre_inject",
HookType::PostSelect => "post_select",
HookType::OnTransition => "on_transition",
HookType::OnConflict => "on_conflict",
HookType::OnViolation => "on_violation",
HookType::Periodic => "periodic",
};
f.write_str(label)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HookAction {
Continue,
Abort {
reason: String,
},
Modify(serde_json::Value),
}
#[derive(Debug, Clone)]
pub struct HookInput {
pub context: serde_json::Value,
pub constitution: serde_json::Value,
pub event: serde_json::Value,
pub session_id: String,
pub chain_state: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct HookResult {
pub action: HookAction,
pub annotations: HashMap<String, serde_json::Value>,
pub duration: Duration,
}
pub trait HookHandler: Send + Sync {
fn execute(&self, input: &HookInput) -> HookResult;
}
pub struct Hook {
pub name: String,
pub hook_type: HookType,
pub priority: u8,
pub handler: Box<dyn HookHandler>,
pub timeout: Duration,
pub enabled: bool,
pub description: String,
}
impl std::fmt::Debug for Hook {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Hook")
.field("name", &self.name)
.field("hook_type", &self.hook_type)
.field("priority", &self.priority)
.field("timeout", &self.timeout)
.field("enabled", &self.enabled)
.field("description", &self.description)
.finish_non_exhaustive()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HookScope {
Deployment,
Session,
}
#[derive(Debug)]
pub struct ChainResult {
pub completed: bool,
pub aborted_by: Option<String>,
pub abort_reason: Option<String>,
pub modified_context: Option<serde_json::Value>,
pub modified_constitution: Option<serde_json::Value>,
pub results: Vec<(String, HookResult)>,
}
fn is_valid_hook_name(name: &str) -> bool {
if name.is_empty() || name.len() > 64 {
return false;
}
name.chars()
.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_' || c == '-')
}
pub struct HookRegistry {
deployment_hooks: HashMap<HookType, Vec<Hook>>,
session_hooks: HashMap<String, HashMap<HookType, Vec<Hook>>>,
}
impl std::fmt::Debug for HookRegistry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HookRegistry")
.field("deployment_hook_count", &self.deployment_hook_count())
.field("session_count", &self.session_hooks.len())
.finish_non_exhaustive()
}
}
impl Default for HookRegistry {
fn default() -> Self {
Self::new()
}
}
impl HookRegistry {
pub fn new() -> Self {
Self {
deployment_hooks: HashMap::new(),
session_hooks: HashMap::new(),
}
}
pub fn register(
&mut self,
hook: Hook,
scope: HookScope,
session_id: Option<&str>,
) -> VcpResult<()> {
self.validate(&hook)?;
match scope {
HookScope::Deployment => {
let hooks = self.deployment_hooks.entry(hook.hook_type).or_default();
if hooks.iter().any(|h| h.name == hook.name) {
return Err(VcpError::HookError(format!(
"hook '{}' already registered in deployment scope",
hook.name
)));
}
hooks.push(hook);
hooks.sort_by_key(|h| std::cmp::Reverse(h.priority));
}
HookScope::Session => {
let sid = session_id.ok_or_else(|| {
VcpError::HookError("session_id is required for session-scoped hooks".into())
})?;
let session_map = self.session_hooks.entry(sid.to_string()).or_default();
let hooks = session_map.entry(hook.hook_type).or_default();
if hooks.iter().any(|h| h.name == hook.name) {
return Err(VcpError::HookError(format!(
"hook '{}' already registered in session scope for '{}'",
hook.name, sid
)));
}
hooks.push(hook);
hooks.sort_by_key(|h| std::cmp::Reverse(h.priority));
}
}
Ok(())
}
pub fn deregister(&mut self, name: &str, scope: HookScope, session_id: Option<&str>) {
match scope {
HookScope::Deployment => {
for hooks in self.deployment_hooks.values_mut() {
hooks.retain(|h| h.name != name);
}
}
HookScope::Session => {
if let Some(sid) = session_id {
if let Some(session_map) = self.session_hooks.get_mut(sid) {
for hooks in session_map.values_mut() {
hooks.retain(|h| h.name != name);
}
}
}
}
}
}
pub fn get_chain(&self, hook_type: HookType, session_id: &str) -> Vec<&Hook> {
let deployment = self
.deployment_hooks
.get(&hook_type)
.map_or(&[][..], |v| v.as_slice());
let session = self
.session_hooks
.get(session_id)
.and_then(|m| m.get(&hook_type))
.map_or(&[][..], |v| v.as_slice());
Self::merge_by_priority(deployment, session)
}
fn merge_by_priority<'a>(deployment: &'a [Hook], session: &'a [Hook]) -> Vec<&'a Hook> {
let mut result = Vec::with_capacity(deployment.len() + session.len());
let (mut d, mut s) = (0, 0);
while d < deployment.len() && s < session.len() {
if deployment[d].priority >= session[s].priority {
result.push(&deployment[d]);
d += 1;
} else {
result.push(&session[s]);
s += 1;
}
}
for hook in &deployment[d..] {
result.push(hook);
}
for hook in &session[s..] {
result.push(hook);
}
result
}
#[allow(clippy::unused_self)] fn validate(&self, hook: &Hook) -> VcpResult<()> {
if !is_valid_hook_name(&hook.name) {
return Err(VcpError::HookError(format!(
"invalid hook name '{}': must match [a-z0-9_-]{{1,64}}",
hook.name
)));
}
if hook.priority > 100 {
return Err(VcpError::HookError(format!(
"priority must be 0-100, got {}",
hook.priority
)));
}
let timeout_ms = hook.timeout.as_millis();
if !(1..=30_000).contains(&timeout_ms) {
return Err(VcpError::HookError(format!(
"timeout must be 1-30000ms, got {timeout_ms}ms",
)));
}
Ok(())
}
fn deployment_hook_count(&self) -> usize {
self.deployment_hooks.values().map(Vec::len).sum()
}
}
pub struct HookExecutor<'a> {
registry: &'a HookRegistry,
}
fn deadline_exceeded(elapsed: Duration, timeout: Duration) -> bool {
elapsed >= timeout
}
impl<'a> HookExecutor<'a> {
pub fn new(registry: &'a HookRegistry) -> Self {
Self { registry }
}
pub fn execute(
&self,
hook_type: HookType,
session_id: &str,
mut input: HookInput,
) -> ChainResult {
let chain = self.registry.get_chain(hook_type, session_id);
let mut results: Vec<(String, HookResult)> = Vec::new();
let mut modified_context: Option<serde_json::Value> = None;
let mut modified_constitution: Option<serde_json::Value> = None;
for hook in &chain {
if !hook.enabled {
continue;
}
let start = Instant::now();
let panic_result =
panic::catch_unwind(AssertUnwindSafe(|| hook.handler.execute(&input)));
let elapsed = start.elapsed();
let hook_result = match panic_result {
Ok(_) if deadline_exceeded(elapsed, hook.timeout) => HookResult {
action: HookAction::Abort {
reason: format!(
"hook '{}' exceeded its {}ms timeout",
hook.name,
hook.timeout.as_millis()
),
},
annotations: HashMap::new(),
duration: elapsed,
},
Ok(mut result) => {
result.duration = elapsed;
result
}
Err(_) => HookResult {
action: HookAction::Abort {
reason: format!("hook '{}' panicked", hook.name),
},
annotations: HashMap::new(),
duration: elapsed,
},
};
match &hook_result.action {
HookAction::Abort { reason } => {
let abort_reason = reason.clone();
let hook_name = hook.name.clone();
results.push((hook.name.clone(), hook_result));
return ChainResult {
completed: false,
aborted_by: Some(hook_name),
abort_reason: Some(abort_reason),
modified_context: None,
modified_constitution: None,
results,
};
}
HookAction::Modify(value) => {
if let Some(ctx) = value.get("context") {
input.context = ctx.clone();
modified_context = Some(ctx.clone());
}
if let Some(con) = value.get("constitution") {
input.constitution = con.clone();
modified_constitution = Some(con.clone());
}
if value.get("context").is_none() && value.get("constitution").is_none() {
input.context = value.clone();
modified_context = Some(value.clone());
}
}
HookAction::Continue => {}
}
results.push((hook.name.clone(), hook_result));
}
ChainResult {
completed: true,
aborted_by: None,
abort_reason: None,
modified_context,
modified_constitution,
results,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
struct ContinueHandler;
impl HookHandler for ContinueHandler {
fn execute(&self, _input: &HookInput) -> HookResult {
HookResult {
action: HookAction::Continue,
annotations: HashMap::new(),
duration: Duration::ZERO,
}
}
}
struct AbortHandler {
reason: String,
}
impl HookHandler for AbortHandler {
fn execute(&self, _input: &HookInput) -> HookResult {
HookResult {
action: HookAction::Abort {
reason: self.reason.clone(),
},
annotations: HashMap::new(),
duration: Duration::ZERO,
}
}
}
struct ModifyHandler {
value: serde_json::Value,
}
impl HookHandler for ModifyHandler {
fn execute(&self, _input: &HookInput) -> HookResult {
HookResult {
action: HookAction::Modify(self.value.clone()),
annotations: HashMap::new(),
duration: Duration::ZERO,
}
}
}
struct PanicHandler;
impl HookHandler for PanicHandler {
fn execute(&self, _input: &HookInput) -> HookResult {
panic!("intentional panic for testing");
}
}
struct SlowHandler;
impl HookHandler for SlowHandler {
fn execute(&self, _input: &HookInput) -> HookResult {
std::thread::sleep(Duration::from_millis(5));
HookResult {
action: HookAction::Continue,
annotations: HashMap::new(),
duration: Duration::ZERO,
}
}
}
fn make_hook(
name: &str,
hook_type: HookType,
priority: u8,
handler: Box<dyn HookHandler>,
) -> Hook {
Hook {
name: name.to_string(),
hook_type,
priority,
handler,
timeout: Duration::from_secs(5),
enabled: true,
description: format!("Test hook: {name}"),
}
}
fn make_input() -> HookInput {
HookInput {
context: serde_json::json!({"key": "value"}),
constitution: serde_json::json!({"rules": []}),
event: serde_json::json!({}),
session_id: "test-session".to_string(),
chain_state: HashMap::new(),
}
}
#[test]
fn register_and_get_chain() {
let mut reg = HookRegistry::new();
reg.register(
make_hook("hook-a", HookType::PreInject, 50, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
let chain = reg.get_chain(HookType::PreInject, "any-session");
assert_eq!(chain.len(), 1);
assert_eq!(chain[0].name, "hook-a");
}
#[test]
fn deregister_removes_hook() {
let mut reg = HookRegistry::new();
reg.register(
make_hook("hook-a", HookType::PreInject, 50, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
assert_eq!(reg.get_chain(HookType::PreInject, "s").len(), 1);
reg.deregister("hook-a", HookScope::Deployment, None);
assert_eq!(reg.get_chain(HookType::PreInject, "s").len(), 0);
}
#[test]
fn invalid_name_rejected() {
let mut reg = HookRegistry::new();
let result = reg.register(
make_hook(
"INVALID_UPPER",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
);
assert!(result.is_err());
assert!(result
.unwrap_err()
.to_string()
.contains("invalid hook name"));
}
#[test]
fn empty_name_rejected() {
let mut reg = HookRegistry::new();
let result = reg.register(
make_hook("", HookType::PreInject, 50, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
);
assert!(result.is_err());
}
#[test]
fn name_too_long_rejected() {
let mut reg = HookRegistry::new();
let long_name = "a".repeat(65);
let result = reg.register(
make_hook(
&long_name,
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
);
assert!(result.is_err());
}
#[test]
fn name_with_special_chars_rejected() {
let mut reg = HookRegistry::new();
let result = reg.register(
make_hook(
"hook.with.dots",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
);
assert!(result.is_err());
}
#[test]
fn priority_ordering() {
let mut reg = HookRegistry::new();
reg.register(
make_hook("low", HookType::PreInject, 10, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook("high", HookType::PreInject, 90, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook("mid", HookType::PreInject, 50, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
let chain = reg.get_chain(HookType::PreInject, "s");
assert_eq!(chain[0].name, "high");
assert_eq!(chain[1].name, "mid");
assert_eq!(chain[2].name, "low");
}
#[test]
fn deployment_before_session_at_same_priority() {
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"session-hook",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Session,
Some("sess-1"),
)
.unwrap();
reg.register(
make_hook(
"deploy-hook",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
)
.unwrap();
let chain = reg.get_chain(HookType::PreInject, "sess-1");
assert_eq!(chain.len(), 2);
assert_eq!(chain[0].name, "deploy-hook");
assert_eq!(chain[1].name, "session-hook");
}
#[test]
fn chain_continue_passes_through() {
let mut reg = HookRegistry::new();
reg.register(
make_hook("h1", HookType::PreInject, 50, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook("h2", HookType::PreInject, 40, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PreInject, "s", make_input());
assert!(result.completed);
assert!(result.aborted_by.is_none());
assert_eq!(result.results.len(), 2);
}
#[test]
fn chain_abort_halts() {
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"aborter",
HookType::PreInject,
90,
Box::new(AbortHandler {
reason: "policy violation".into(),
}),
),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook(
"should-not-run",
HookType::PreInject,
10,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
)
.unwrap();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PreInject, "s", make_input());
assert!(!result.completed);
assert_eq!(result.aborted_by.as_deref(), Some("aborter"));
assert_eq!(result.abort_reason.as_deref(), Some("policy violation"));
assert_eq!(result.results.len(), 1);
}
#[test]
fn chain_modify_transforms_context() {
let modified_val = serde_json::json!({"context": {"modified": true}});
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"modifier",
HookType::PreInject,
90,
Box::new(ModifyHandler {
value: modified_val.clone(),
}),
),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook("after", HookType::PreInject, 10, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PreInject, "s", make_input());
assert!(result.completed);
assert_eq!(
result.modified_context,
Some(serde_json::json!({"modified": true}))
);
assert_eq!(result.results.len(), 2);
}
#[test]
fn disabled_hooks_skipped() {
let mut reg = HookRegistry::new();
let mut hook = make_hook(
"disabled",
HookType::PreInject,
50,
Box::new(AbortHandler {
reason: "should not run".into(),
}),
);
hook.enabled = false;
reg.register(hook, HookScope::Deployment, None).unwrap();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PreInject, "s", make_input());
assert!(result.completed);
assert_eq!(result.results.len(), 0);
}
#[test]
fn empty_chain_returns_completed() {
let reg = HookRegistry::new();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PreInject, "s", make_input());
assert!(result.completed);
assert!(result.aborted_by.is_none());
assert!(result.results.is_empty());
}
#[test]
fn duplicate_name_rejected() {
let mut reg = HookRegistry::new();
reg.register(
make_hook("unique", HookType::PreInject, 50, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
)
.unwrap();
let result = reg.register(
make_hook("unique", HookType::PreInject, 60, Box::new(ContinueHandler)),
HookScope::Deployment,
None,
);
assert!(result.is_err());
assert!(result
.unwrap_err()
.to_string()
.contains("already registered"));
}
#[test]
fn priority_above_100_rejected() {
let mut reg = HookRegistry::new();
let result = reg.register(
make_hook(
"too-high",
HookType::PreInject,
101,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("priority"));
}
#[test]
fn timeout_zero_rejected() {
let mut reg = HookRegistry::new();
let mut hook = make_hook(
"zero-timeout",
HookType::PreInject,
50,
Box::new(ContinueHandler),
);
hook.timeout = Duration::ZERO;
let result = reg.register(hook, HookScope::Deployment, None);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("timeout"));
}
#[test]
fn timeout_over_30000ms_rejected() {
let mut reg = HookRegistry::new();
let mut hook = make_hook(
"long-timeout",
HookType::PreInject,
50,
Box::new(ContinueHandler),
);
hook.timeout = Duration::from_millis(30001);
let result = reg.register(hook, HookScope::Deployment, None);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("timeout"));
}
#[test]
fn panic_in_handler_aborts_fail_closed() {
let mut reg = HookRegistry::new();
reg.register(
make_hook("panicker", HookType::PreInject, 90, Box::new(PanicHandler)),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook(
"after-panic",
HookType::PreInject,
10,
Box::new(ContinueHandler),
),
HookScope::Deployment,
None,
)
.unwrap();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PreInject, "s", make_input());
assert!(!result.completed);
assert_eq!(result.aborted_by.as_deref(), Some("panicker"));
assert_eq!(result.results.len(), 1);
assert!(matches!(
result.results[0].1.action,
HookAction::Abort { .. }
));
}
#[test]
fn abort_discards_modifications_staged_by_earlier_hooks() {
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"staged-modifier",
HookType::PreInject,
90,
Box::new(ModifyHandler {
value: serde_json::json!({"context": {"staged": true}}),
}),
),
HookScope::Deployment,
None,
)
.unwrap();
reg.register(
make_hook("panicker", HookType::PreInject, 80, Box::new(PanicHandler)),
HookScope::Deployment,
None,
)
.unwrap();
let result = HookExecutor::new(®).execute(HookType::PreInject, "s", make_input());
assert!(!result.completed);
assert_eq!(result.aborted_by.as_deref(), Some("panicker"));
assert_eq!(result.results.len(), 2);
assert!(result.modified_context.is_none());
assert!(result.modified_constitution.is_none());
}
#[test]
fn handler_result_after_timeout_aborts_fail_closed() {
let mut reg = HookRegistry::new();
let mut hook = make_hook("slow-hook", HookType::PreInject, 50, Box::new(SlowHandler));
hook.timeout = Duration::from_millis(1);
reg.register(hook, HookScope::Deployment, None).unwrap();
let result = HookExecutor::new(®).execute(HookType::PreInject, "s", make_input());
assert!(!result.completed);
assert_eq!(result.aborted_by.as_deref(), Some("slow-hook"));
assert!(result
.abort_reason
.as_deref()
.is_some_and(|reason| reason.contains("timeout")));
assert!(result.results[0].1.duration >= Duration::from_millis(1));
}
#[test]
fn timeout_boundary_is_inclusive() {
assert!(!deadline_exceeded(
Duration::from_nanos(999_999),
Duration::from_millis(1)
));
assert!(deadline_exceeded(
Duration::from_millis(1),
Duration::from_millis(1)
));
}
#[test]
fn session_scope_requires_session_id() {
let mut reg = HookRegistry::new();
let result = reg.register(
make_hook(
"sess-hook",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Session,
None, );
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("session_id"));
}
#[test]
fn different_sessions_isolated() {
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"sess1-hook",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Session,
Some("sess-1"),
)
.unwrap();
assert_eq!(reg.get_chain(HookType::PreInject, "sess-1").len(), 1);
assert_eq!(reg.get_chain(HookType::PreInject, "sess-2").len(), 0);
}
#[test]
fn hook_type_display() {
assert_eq!(HookType::PreInject.to_string(), "pre_inject");
assert_eq!(HookType::PostSelect.to_string(), "post_select");
assert_eq!(HookType::OnTransition.to_string(), "on_transition");
assert_eq!(HookType::OnConflict.to_string(), "on_conflict");
assert_eq!(HookType::OnViolation.to_string(), "on_violation");
assert_eq!(HookType::Periodic.to_string(), "periodic");
}
#[test]
fn valid_hook_names_accepted() {
assert!(is_valid_hook_name("my-hook"));
assert!(is_valid_hook_name("hook_123"));
assert!(is_valid_hook_name("a"));
assert!(is_valid_hook_name(&"a".repeat(64)));
assert!(is_valid_hook_name("pre-inject-pii-filter"));
assert!(is_valid_hook_name("0-starts-with-digit"));
}
#[test]
fn invalid_hook_names_rejected() {
assert!(!is_valid_hook_name(""));
assert!(!is_valid_hook_name(&"a".repeat(65)));
assert!(!is_valid_hook_name("UPPERCASE"));
assert!(!is_valid_hook_name("has space"));
assert!(!is_valid_hook_name("has.dot"));
assert!(!is_valid_hook_name("has@symbol"));
}
#[test]
fn modify_constitution_forwarded() {
let modified_val = serde_json::json!({
"constitution": {"rules": ["be-safe"]},
});
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"con-modifier",
HookType::PostSelect,
80,
Box::new(ModifyHandler {
value: modified_val,
}),
),
HookScope::Deployment,
None,
)
.unwrap();
let executor = HookExecutor::new(®);
let result = executor.execute(HookType::PostSelect, "s", make_input());
assert!(result.completed);
assert_eq!(
result.modified_constitution,
Some(serde_json::json!({"rules": ["be-safe"]}))
);
}
#[test]
fn deregister_session_hook() {
let mut reg = HookRegistry::new();
reg.register(
make_hook(
"sess-hook",
HookType::PreInject,
50,
Box::new(ContinueHandler),
),
HookScope::Session,
Some("sess-1"),
)
.unwrap();
assert_eq!(reg.get_chain(HookType::PreInject, "sess-1").len(), 1);
reg.deregister("sess-hook", HookScope::Session, Some("sess-1"));
assert_eq!(reg.get_chain(HookType::PreInject, "sess-1").len(), 0);
}
}