use chrono::{DateTime, Utc};
use hmac::{Hmac, Mac};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, BufWriter, Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use zeroize::Zeroizing;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AuditEventType {
ToolAccess,
AgentAccess,
PermissionCheck,
Authentication,
Authorization,
ResourceCreated,
ResourceUpdated,
ResourceDeleted,
ConfigChanged,
SecretAccessed,
SecretRotated,
PaymentExecuted,
PolicyEvaluated,
SessionStarted,
SessionEnded,
Custom(String),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AuditOutcome {
Allowed,
Denied,
Error,
Created,
Updated,
Deleted,
Blocked,
Paused,
Escalated,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuditEvent {
pub timestamp: DateTime<Utc>,
pub user: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
pub event_type: AuditEventType,
pub resource: String,
pub outcome: AuditOutcome,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tenant_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub request_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ip_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prev_hash: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub agent_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub on_behalf_of: Option<adk_core::SubjectRef>,
}
impl AuditEvent {
pub fn new(
event_type: AuditEventType,
user: impl Into<String>,
resource: impl Into<String>,
outcome: AuditOutcome,
) -> Self {
Self {
timestamp: Utc::now(),
user: user.into(),
session_id: None,
event_type,
resource: resource.into(),
outcome,
metadata: None,
workspace_id: None,
tenant_id: None,
request_id: None,
ip_address: None,
resource_id: None,
action: None,
prev_hash: None,
agent_id: None,
on_behalf_of: None,
}
}
pub fn tool_access(user: &str, tool_name: &str, outcome: AuditOutcome) -> Self {
Self::new(AuditEventType::ToolAccess, user, tool_name, outcome)
}
pub fn agent_access(user: &str, agent_name: &str, outcome: AuditOutcome) -> Self {
Self::new(AuditEventType::AgentAccess, user, agent_name, outcome)
}
pub fn authentication(user: &str, outcome: AuditOutcome) -> Self {
Self::new(AuditEventType::Authentication, user, "auth", outcome)
}
pub fn resource_event(
event_type: AuditEventType,
user: &str,
resource: &str,
resource_id: &str,
outcome: AuditOutcome,
) -> Self {
Self::new(event_type, user, resource, outcome).with_resource_id(resource_id)
}
pub fn secret_accessed(user: &str, secret_name: &str, outcome: AuditOutcome) -> Self {
Self::new(AuditEventType::SecretAccessed, user, secret_name, outcome)
}
pub fn config_changed(user: &str, config_key: &str, outcome: AuditOutcome) -> Self {
Self::new(AuditEventType::ConfigChanged, user, config_key, outcome)
}
pub fn custom(event_type: &str, user: &str, resource: &str, outcome: AuditOutcome) -> Self {
Self::new(AuditEventType::Custom(event_type.to_string()), user, resource, outcome)
}
pub fn with_session(mut self, session_id: impl Into<String>) -> Self {
self.session_id = Some(session_id.into());
self
}
pub fn with_metadata(mut self, metadata: serde_json::Value) -> Self {
self.metadata = Some(metadata);
self
}
pub fn with_workspace(mut self, workspace_id: impl Into<String>) -> Self {
self.workspace_id = Some(workspace_id.into());
self
}
pub fn with_tenant(mut self, tenant_id: impl Into<String>) -> Self {
self.tenant_id = Some(tenant_id.into());
self
}
pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
self.request_id = Some(request_id.into());
self
}
pub fn with_ip_address(mut self, ip: impl Into<String>) -> Self {
self.ip_address = Some(ip.into());
self
}
pub fn with_resource_id(mut self, id: impl Into<String>) -> Self {
self.resource_id = Some(id.into());
self
}
pub fn with_agent_id(mut self, agent_id: impl Into<String>) -> Self {
self.agent_id = Some(agent_id.into());
self
}
pub fn with_acting_context(mut self, acting: &adk_core::ActingContext) -> Self {
self.agent_id = Some(acting.agent.id.to_string());
self.on_behalf_of = acting.on_behalf_of.clone();
if self.tenant_id.is_none() {
self.tenant_id = acting.agent.tenant.clone();
}
self
}
pub fn with_action(mut self, action: impl Into<String>) -> Self {
self.action = Some(action.into());
self
}
pub fn with_prev_hash(mut self, prev_event_json: &str) -> Self {
let mut hasher = Sha256::new();
hasher.update(prev_event_json.as_bytes());
self.prev_hash = Some(hex::encode(hasher.finalize()));
self
}
pub fn to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string(self)
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AuditFilter {
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tenant_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub event_type: Option<AuditEventType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub outcome: Option<AuditOutcome>,
#[serde(skip_serializing_if = "Option::is_none")]
pub resource: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub agent_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub offset: Option<usize>,
}
impl AuditFilter {
pub fn matches(&self, event: &AuditEvent) -> bool {
if let Some(ref user) = self.user
&& &event.user != user
{
return false;
}
if let Some(ref ws) = self.workspace_id
&& event.workspace_id.as_ref() != Some(ws)
{
return false;
}
if let Some(ref tid) = self.tenant_id
&& event.tenant_id.as_ref() != Some(tid)
{
return false;
}
if let Some(ref et) = self.event_type
&& &event.event_type != et
{
return false;
}
if let Some(ref oc) = self.outcome
&& &event.outcome != oc
{
return false;
}
if let Some(ref res) = self.resource
&& !event.resource.contains(res.as_str())
{
return false;
}
if let Some(ref rid) = self.resource_id
&& event.resource_id.as_ref() != Some(rid)
{
return false;
}
if let Some(ref agent) = self.agent_id
&& event.agent_id.as_ref() != Some(agent)
{
return false;
}
if let Some(after) = self.after
&& event.timestamp <= after
{
return false;
}
if let Some(before) = self.before
&& event.timestamp >= before
{
return false;
}
true
}
}
#[async_trait::async_trait]
pub trait AuditSink: Send + Sync {
async fn log(&self, event: AuditEvent) -> Result<(), crate::AuthError>;
async fn log_batch(&self, events: Vec<AuditEvent>) -> Result<(), crate::AuthError> {
for event in events {
self.log(event).await?;
}
Ok(())
}
async fn query(&self, _filter: &AuditFilter) -> Result<Vec<AuditEvent>, crate::AuthError> {
Ok(Vec::new())
}
async fn purge_before(&self, _cutoff: DateTime<Utc>) -> Result<u64, crate::AuthError> {
Ok(0)
}
async fn flush(&self) -> Result<(), crate::AuthError> {
Ok(())
}
}
#[async_trait::async_trait]
impl<T: AuditSink + ?Sized> AuditSink for std::sync::Arc<T> {
async fn log(&self, event: AuditEvent) -> Result<(), crate::AuthError> {
(**self).log(event).await
}
async fn log_batch(&self, events: Vec<AuditEvent>) -> Result<(), crate::AuthError> {
(**self).log_batch(events).await
}
async fn query(&self, filter: &AuditFilter) -> Result<Vec<AuditEvent>, crate::AuthError> {
(**self).query(filter).await
}
async fn purge_before(&self, cutoff: DateTime<Utc>) -> Result<u64, crate::AuthError> {
(**self).purge_before(cutoff).await
}
async fn flush(&self) -> Result<(), crate::AuthError> {
(**self).flush().await
}
}
pub use adk_core::audit_log::AuditFailureMode;
pub(crate) async fn record_decision(
sink: &dyn AuditSink,
event: AuditEvent,
mode: AuditFailureMode,
tool_name: &str,
) -> adk_core::Result<()> {
let Err(error) = sink.log(event).await else {
return Ok(());
};
match mode {
AuditFailureMode::Block => {
tracing::error!(tool.name = %tool_name, error = %error, "audit sink failed; refusing the call");
Err(adk_core::AdkError::new(
adk_core::ErrorComponent::Auth,
adk_core::ErrorCategory::Unavailable,
"auth.audit_failed",
format!(
"tool '{tool_name}' refused: the access decision could not be audited ({error}). \
Restore the audit sink, or set AuditFailureMode::Warn to run without a record"
),
))
}
AuditFailureMode::Warn => {
tracing::warn!(tool.name = %tool_name, error = %error, "audit sink failed; continuing without a record");
Ok(())
}
}
}
fn chain_link(key: Option<&[u8]>, previous_line: &str) -> String {
match key {
Some(key) => {
let mut mac = <Hmac<Sha256> as Mac>::new_from_slice(key)
.expect("HMAC-SHA256 accepts keys of any length");
mac.update(previous_line.as_bytes());
hex::encode(mac.finalize().into_bytes())
}
None => hex::encode(Sha256::digest(previous_line.as_bytes())),
}
}
fn read_last_line(path: &Path) -> std::io::Result<Option<String>> {
const BLOCK: u64 = 8 * 1024;
let mut file = match File::open(path) {
Ok(file) => file,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
Err(error) => return Err(error),
};
let mut end = file.metadata()?.len();
let mut tail: Vec<u8> = Vec::new();
while end > 0 {
let start = end.saturating_sub(BLOCK);
let mut block = vec![0u8; usize::try_from(end - start).unwrap_or(0)];
file.seek(SeekFrom::Start(start))?;
file.read_exact(&mut block)?;
block.extend_from_slice(&tail);
tail = block;
end = start;
let content_end =
tail.iter().rposition(|byte| !matches!(byte, b'\n' | b'\r')).map_or(0, |at| at + 1);
tail.truncate(content_end);
if let Some(newline) = tail.iter().rposition(|byte| *byte == b'\n') {
tail.drain(..=newline);
break;
}
}
if tail.is_empty() {
return Ok(None);
}
String::from_utf8(tail)
.map(Some)
.map_err(|error| std::io::Error::new(std::io::ErrorKind::InvalidData, error))
}
pub struct FileAuditSink {
writer: Mutex<BufWriter<File>>,
path: PathBuf,
last_event_json: Mutex<Option<String>>,
chain_enabled: bool,
chain_key: Option<Zeroizing<Vec<u8>>>,
}
impl FileAuditSink {
pub fn new(path: impl Into<PathBuf>) -> Result<Self, std::io::Error> {
Self::open(path.into(), false, None)
}
pub fn with_chaining(path: impl Into<PathBuf>) -> Result<Self, std::io::Error> {
Self::open(path.into(), true, None)
}
pub fn with_hmac_chaining(
path: impl Into<PathBuf>,
key: impl Into<Vec<u8>>,
) -> Result<Self, std::io::Error> {
Self::open(path.into(), true, Some(Zeroizing::new(key.into())))
}
fn open(
path: PathBuf,
chain_enabled: bool,
chain_key: Option<Zeroizing<Vec<u8>>>,
) -> Result<Self, std::io::Error> {
let last_event_json = if chain_enabled { read_last_line(&path)? } else { None };
let file = OpenOptions::new().create(true).append(true).open(&path)?;
Ok(Self {
writer: Mutex::new(BufWriter::new(file)),
path,
last_event_json: Mutex::new(last_event_json),
chain_enabled,
chain_key,
})
}
pub fn path(&self) -> &PathBuf {
&self.path
}
pub fn verify(&self) -> Result<u64, crate::AuthError> {
self.writer.lock().unwrap_or_else(|poisoned| poisoned.into_inner()).flush()?;
Self::verify_file(&self.path, self.chain_key.as_deref().map(Vec::as_slice))
}
pub fn verify_file(
path: impl AsRef<Path>,
hmac_key: Option<&[u8]>,
) -> Result<u64, crate::AuthError> {
let reader = BufReader::new(File::open(path)?);
let mut previous: Option<String> = None;
let mut events = 0u64;
for (index, line) in reader.lines().enumerate() {
let line = line?;
let number = index + 1;
let event: AuditEvent = serde_json::from_str(&line).map_err(|error| {
crate::AuthError::AuditError(format!(
"audit chain broken at line {number}: not an audit event ({error})"
))
})?;
let expected = previous.as_deref().map(|previous| chain_link(hmac_key, previous));
if event.prev_hash != expected {
return Err(crate::AuthError::AuditError(format!(
"audit chain broken at line {number}: prev_hash does not match the line before it"
)));
}
previous = Some(line);
events += 1;
}
Ok(events)
}
}
#[async_trait::async_trait]
impl AuditSink for FileAuditSink {
async fn log(&self, mut event: AuditEvent) -> Result<(), crate::AuthError> {
let mut last = self.last_event_json.lock().unwrap_or_else(|p| p.into_inner());
if self.chain_enabled {
event.prev_hash = last
.as_deref()
.map(|previous| chain_link(self.chain_key.as_deref().map(Vec::as_slice), previous));
}
let line = serde_json::to_string(&event)
.map_err(|e| crate::AuthError::AuditError(e.to_string()))?;
let mut writer = self.writer.lock().unwrap_or_else(|poisoned| {
tracing::warn!(path = %self.path.display(), "audit writer lock poisoned, recovering");
poisoned.into_inner()
});
writeln!(writer, "{line}")?;
writer.flush()?;
if self.chain_enabled {
*last = Some(line);
}
Ok(())
}
}
pub struct InMemoryAuditSink {
events: tokio::sync::RwLock<Vec<AuditEvent>>,
}
impl InMemoryAuditSink {
pub fn new() -> Self {
Self { events: tokio::sync::RwLock::new(Vec::new()) }
}
pub async fn len(&self) -> usize {
self.events.read().await.len()
}
pub async fn is_empty(&self) -> bool {
self.events.read().await.is_empty()
}
}
impl Default for InMemoryAuditSink {
fn default() -> Self {
Self::new()
}
}
#[async_trait::async_trait]
impl AuditSink for InMemoryAuditSink {
async fn log(&self, event: AuditEvent) -> Result<(), crate::AuthError> {
self.events.write().await.push(event);
Ok(())
}
async fn log_batch(&self, events: Vec<AuditEvent>) -> Result<(), crate::AuthError> {
self.events.write().await.extend(events);
Ok(())
}
async fn query(&self, filter: &AuditFilter) -> Result<Vec<AuditEvent>, crate::AuthError> {
let events = self.events.read().await;
let mut results: Vec<AuditEvent> =
events.iter().filter(|e| filter.matches(e)).cloned().collect();
if let Some(offset) = filter.offset {
if offset < results.len() {
results = results[offset..].to_vec();
} else {
results.clear();
}
}
if let Some(limit) = filter.limit {
results.truncate(limit);
}
Ok(results)
}
async fn purge_before(&self, cutoff: DateTime<Utc>) -> Result<u64, crate::AuthError> {
let mut events = self.events.write().await;
let before_len = events.len();
events.retain(|e| e.timestamp >= cutoff);
Ok((before_len - events.len()) as u64)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_audit_event_serialization() {
let event = AuditEvent::tool_access("alice", "search", AuditOutcome::Allowed);
let json = serde_json::to_string(&event).unwrap();
assert!(json.contains("\"user\":\"alice\""));
assert!(json.contains("\"resource\":\"search\""));
assert!(json.contains("\"outcome\":\"allowed\""));
}
#[test]
fn test_audit_event_with_session() {
let event = AuditEvent::tool_access("bob", "exec", AuditOutcome::Denied)
.with_session("session-123");
assert_eq!(event.session_id, Some("session-123".to_string()));
}
#[test]
fn test_enterprise_context_fields() {
let event = AuditEvent::tool_access("alice", "search", AuditOutcome::Allowed)
.with_workspace("ws_123")
.with_tenant("tenant_abc")
.with_request_id("req_456")
.with_ip_address("192.168.1.1")
.with_resource_id("550e8400-e29b-41d4-a716-446655440000")
.with_action("execute");
assert_eq!(event.workspace_id, Some("ws_123".to_string()));
assert_eq!(event.tenant_id, Some("tenant_abc".to_string()));
assert_eq!(event.request_id, Some("req_456".to_string()));
assert_eq!(event.ip_address, Some("192.168.1.1".to_string()));
assert_eq!(event.resource_id, Some("550e8400-e29b-41d4-a716-446655440000".to_string()));
assert_eq!(event.action, Some("execute".to_string()));
let json = serde_json::to_string(&event).unwrap();
assert!(json.contains("\"workspace_id\":\"ws_123\""));
assert!(json.contains("\"tenant_id\":\"tenant_abc\""));
assert!(json.contains("\"request_id\":\"req_456\""));
}
#[test]
fn test_custom_event_type() {
let event =
AuditEvent::custom("deployment_triggered", "ci-bot", "agent-v2", AuditOutcome::Created);
let json = serde_json::to_string(&event).unwrap();
assert!(json.contains("deployment_triggered"));
assert!(json.contains("\"outcome\":\"created\""));
}
#[test]
fn test_new_outcomes() {
for outcome in [
AuditOutcome::Created,
AuditOutcome::Updated,
AuditOutcome::Deleted,
AuditOutcome::Blocked,
AuditOutcome::Paused,
AuditOutcome::Escalated,
] {
let event =
AuditEvent::new(AuditEventType::ResourceCreated, "user", "res", outcome.clone());
let json = serde_json::to_string(&event).unwrap();
let deserialized: AuditEvent = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.outcome, outcome);
}
}
#[test]
fn test_new_event_types() {
let types = vec![
AuditEventType::Authentication,
AuditEventType::Authorization,
AuditEventType::ResourceCreated,
AuditEventType::ResourceUpdated,
AuditEventType::ResourceDeleted,
AuditEventType::ConfigChanged,
AuditEventType::SecretAccessed,
AuditEventType::SecretRotated,
AuditEventType::PaymentExecuted,
AuditEventType::PolicyEvaluated,
AuditEventType::SessionStarted,
AuditEventType::SessionEnded,
AuditEventType::Custom("my_event".to_string()),
];
for event_type in types {
let event =
AuditEvent::new(event_type.clone(), "user", "resource", AuditOutcome::Allowed);
let json = serde_json::to_string(&event).unwrap();
let deserialized: AuditEvent = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.event_type, event_type);
}
}
#[test]
fn last_line_is_read_across_block_boundaries() {
let path = std::env::temp_dir().join(format!(
"adk-audit-last-line-{}-{}.jsonl",
std::process::id(),
Utc::now().timestamp_nanos_opt().unwrap_or_default()
));
assert_eq!(read_last_line(&path).unwrap(), None);
std::fs::write(&path, "").unwrap();
assert_eq!(read_last_line(&path).unwrap(), None);
let long = "x".repeat(20_000);
std::fs::write(&path, format!("first\n{long}\n\n")).unwrap();
assert_eq!(read_last_line(&path).unwrap(), Some(long.clone()));
std::fs::write(&path, &long).unwrap();
assert_eq!(read_last_line(&path).unwrap(), Some(long));
std::fs::remove_file(&path).unwrap();
}
#[test]
fn test_hash_chaining() {
let event1 = AuditEvent::tool_access("alice", "search", AuditOutcome::Allowed);
let json1 = event1.to_json().unwrap();
let event2 =
AuditEvent::tool_access("bob", "exec", AuditOutcome::Denied).with_prev_hash(&json1);
assert!(event2.prev_hash.is_some());
assert_eq!(event2.prev_hash.as_ref().unwrap().len(), 64);
}
#[test]
fn test_audit_filter_matches() {
let event = AuditEvent::tool_access("alice", "search", AuditOutcome::Allowed)
.with_workspace("ws_1");
let filter = AuditFilter { user: Some("alice".to_string()), ..Default::default() };
assert!(filter.matches(&event));
let filter = AuditFilter { user: Some("bob".to_string()), ..Default::default() };
assert!(!filter.matches(&event));
let filter = AuditFilter { workspace_id: Some("ws_1".to_string()), ..Default::default() };
assert!(filter.matches(&event));
let filter = AuditFilter { workspace_id: Some("ws_2".to_string()), ..Default::default() };
assert!(!filter.matches(&event));
}
#[test]
fn test_backward_compatible_serialization() {
let old_json = r#"{"timestamp":"2026-01-01T00:00:00Z","user":"alice","event_type":"tool_access","resource":"search","outcome":"allowed"}"#;
let event: AuditEvent = serde_json::from_str(old_json).unwrap();
assert_eq!(event.user, "alice");
assert_eq!(event.workspace_id, None);
assert_eq!(event.tenant_id, None);
}
#[tokio::test]
async fn test_in_memory_sink_query() {
let sink = InMemoryAuditSink::new();
sink.log(
AuditEvent::tool_access("alice", "search", AuditOutcome::Allowed)
.with_workspace("ws_1"),
)
.await
.unwrap();
sink.log(
AuditEvent::tool_access("bob", "exec", AuditOutcome::Denied).with_workspace("ws_1"),
)
.await
.unwrap();
sink.log(
AuditEvent::tool_access("alice", "deploy", AuditOutcome::Allowed)
.with_workspace("ws_2"),
)
.await
.unwrap();
let results = sink
.query(&AuditFilter { user: Some("alice".to_string()), ..Default::default() })
.await
.unwrap();
assert_eq!(results.len(), 2);
let results = sink
.query(&AuditFilter { workspace_id: Some("ws_1".to_string()), ..Default::default() })
.await
.unwrap();
assert_eq!(results.len(), 2);
let results = sink
.query(&AuditFilter { outcome: Some(AuditOutcome::Denied), ..Default::default() })
.await
.unwrap();
assert_eq!(results.len(), 1);
assert_eq!(results[0].user, "bob");
}
#[tokio::test]
async fn test_in_memory_sink_purge() {
let sink = InMemoryAuditSink::new();
sink.log(AuditEvent::tool_access("alice", "search", AuditOutcome::Allowed)).await.unwrap();
sink.log(AuditEvent::tool_access("bob", "exec", AuditOutcome::Denied)).await.unwrap();
assert_eq!(sink.len().await, 2);
let cutoff = Utc::now() + chrono::Duration::seconds(1);
let purged = sink.purge_before(cutoff).await.unwrap();
assert_eq!(purged, 2);
assert!(sink.is_empty().await);
}
#[tokio::test]
async fn test_in_memory_sink_batch() {
let sink = InMemoryAuditSink::new();
let events = vec![
AuditEvent::tool_access("alice", "a", AuditOutcome::Allowed),
AuditEvent::tool_access("bob", "b", AuditOutcome::Denied),
AuditEvent::tool_access("carol", "c", AuditOutcome::Allowed),
];
sink.log_batch(events).await.unwrap();
assert_eq!(sink.len().await, 3);
}
}