mockforge_intelligence/handlers/snapshot_diff/models.rs
1//! Public snapshot, comparison and request data.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Snapshot of mock server state at a point in time
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct MockSnapshot {
9 /// Snapshot ID
10 pub id: String,
11 /// Timestamp when snapshot was taken
12 pub timestamp: i64,
13 /// Environment ID (if applicable)
14 pub environment_id: Option<String>,
15 /// Persona ID (if applicable)
16 pub persona_id: Option<String>,
17 /// Scenario ID (if applicable)
18 pub scenario_id: Option<String>,
19 /// Reality level (0.0-1.0, if applicable)
20 pub reality_level: Option<f64>,
21 /// All mocks in this snapshot
22 pub mocks: Vec<MockSnapshotItem>,
23 /// Metadata about the snapshot
24 pub metadata: HashMap<String, serde_json::Value>,
25}
26
27/// Individual mock item in a snapshot
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct MockSnapshotItem {
30 /// Mock ID
31 pub id: String,
32 /// HTTP method
33 pub method: String,
34 /// Path pattern
35 pub path: String,
36 /// Response status code
37 pub status_code: u16,
38 /// Response body
39 pub response_body: serde_json::Value,
40 /// Response headers
41 pub response_headers: Option<HashMap<String, String>>,
42 /// Mock configuration
43 pub config: serde_json::Value,
44}
45
46/// Comparison between two snapshots
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct SnapshotDiff {
49 /// Left snapshot (baseline)
50 pub left: MockSnapshot,
51 /// Right snapshot (comparison)
52 pub right: MockSnapshot,
53 /// Differences found
54 pub differences: Vec<Difference>,
55 /// Summary statistics
56 pub summary: DiffSummary,
57}
58
59/// Individual difference between snapshots
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct Difference {
62 /// Type of difference
63 pub diff_type: DifferenceType,
64 /// Mock ID (if applicable)
65 pub mock_id: Option<String>,
66 /// Path of the mock
67 pub path: String,
68 /// Method of the mock
69 pub method: String,
70 /// Description of the difference
71 pub description: String,
72 /// Left value (if applicable)
73 pub left_value: Option<serde_json::Value>,
74 /// Right value (if applicable)
75 pub right_value: Option<serde_json::Value>,
76 /// Field path where difference occurs (for nested differences)
77 pub field_path: Option<String>,
78}
79
80/// Type of difference
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(rename_all = "snake_case")]
83pub enum DifferenceType {
84 /// Mock exists in left but not right
85 MissingInRight,
86 /// Mock exists in right but not left
87 MissingInLeft,
88 /// Status code differs
89 StatusCodeMismatch,
90 /// Response body differs
91 BodyMismatch,
92 /// Response headers differ
93 HeadersMismatch,
94 /// Configuration differs
95 ConfigMismatch,
96}
97
98/// Summary statistics for a diff
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct DiffSummary {
101 /// Total mocks in left snapshot
102 pub left_total: usize,
103 /// Total mocks in right snapshot
104 pub right_total: usize,
105 /// Number of differences found
106 pub differences_count: usize,
107 /// Number of mocks only in left
108 pub only_in_left: usize,
109 /// Number of mocks only in right
110 pub only_in_right: usize,
111 /// Number of mocks with differences
112 pub mocks_with_differences: usize,
113}
114
115/// Request to create a snapshot
116#[derive(Debug, Deserialize)]
117pub struct CreateSnapshotRequest {
118 /// Environment ID (optional)
119 pub environment_id: Option<String>,
120 /// Persona ID (optional)
121 pub persona_id: Option<String>,
122 /// Scenario ID (optional)
123 pub scenario_id: Option<String>,
124 /// Reality level (optional, 0.0-1.0)
125 pub reality_level: Option<f64>,
126 /// Metadata to attach
127 #[serde(default)]
128 pub metadata: HashMap<String, serde_json::Value>,
129}
130
131/// Request to compare snapshots
132#[derive(Debug, Deserialize)]
133pub struct CompareSnapshotsRequest {
134 /// Left snapshot ID (or use environment/persona/scenario)
135 pub left_snapshot_id: Option<String>,
136 /// Right snapshot ID (or use environment/persona/scenario)
137 pub right_snapshot_id: Option<String>,
138 /// Left environment ID (alternative to snapshot_id)
139 pub left_environment_id: Option<String>,
140 /// Right environment ID (alternative to snapshot_id)
141 pub right_environment_id: Option<String>,
142 /// Left persona ID (alternative to snapshot_id)
143 pub left_persona_id: Option<String>,
144 /// Right persona ID (alternative to snapshot_id)
145 pub right_persona_id: Option<String>,
146 /// Left scenario ID (alternative to snapshot_id)
147 pub left_scenario_id: Option<String>,
148 /// Right scenario ID (alternative to snapshot_id)
149 pub right_scenario_id: Option<String>,
150 /// Left reality level (alternative to snapshot_id)
151 pub left_reality_level: Option<f64>,
152 /// Right reality level (alternative to snapshot_id)
153 pub right_reality_level: Option<f64>,
154}