Skip to main content

forge_audit/
lib.rs

1#![warn(missing_docs)]
2//! Audit event types for Forge gateway observability.
3//!
4//! Provides [`AuditEvent`] — a structured, serializable audit record
5//! for tracking gateway operations.
6
7use chrono::{DateTime, Utc};
8use serde::Serialize;
9
10/// A structured audit event emitted by the Forge gateway.
11///
12/// This is a stub that will be expanded in Phase 7 (Observability).
13#[derive(Debug, Clone, Serialize)]
14#[non_exhaustive]
15pub struct AuditEvent {
16    /// When the event occurred.
17    pub timestamp: DateTime<Utc>,
18    /// The type of event.
19    pub event_type: String,
20    /// Human-readable description.
21    pub description: String,
22}
23
24impl AuditEvent {
25    /// Create a new audit event with the current timestamp.
26    pub fn new(event_type: impl Into<String>, description: impl Into<String>) -> Self {
27        Self {
28            timestamp: Utc::now(),
29            event_type: event_type.into(),
30            description: description.into(),
31        }
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn serializes_to_json_without_panic() {
41        let event = AuditEvent::new("test_event", "a test audit event");
42        let json = serde_json::to_string(&event).expect("should serialize");
43        assert!(json.contains("test_event"));
44        assert!(json.contains("a test audit event"));
45        assert!(json.contains("timestamp"));
46    }
47}