1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#![cfg(feature = "dap")]
//! CAPTURE-003: CLI Recording Workflow End-to-End
//! Sprint 76 - RED Phase
//!
//! Tests drive the complete end-to-end workflow from `pmat debug serve` with
//! recording enabled through to `pmat debug replay` of the captured session.
// RED Test 1: End-to-end workflow (serve → capture → replay)
#[test]
fn test_end_to_end_serve_capture_replay() {
// This test drives the requirement for complete E2E workflow
// Expected: User can serve, capture, and replay a debug session
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use pmat::services::dap::recording::Recording;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
//
// // Step 1: Serve with recording
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
// server.start_session("test_program", vec![]);
//
// // Step 2: Simulate debug session
// server.step_next(); // Capture snapshot
// server.step_in(); // Capture snapshot
// server.step_out(); // Capture snapshot
//
// // Step 3: Disconnect and get recording path
// let recording_path = server.disconnect().unwrap();
//
// // Step 4: Replay the recording
// let recording = Recording::load_from_file(&recording_path).unwrap();
// assert_eq!(recording.snapshot_count(), 3, "Should have 3 snapshots");
assert!(
true,
"Must support end-to-end serve → capture → replay workflow"
);
}
// RED Test 2: Recording metadata matches session
#[test]
fn test_recording_metadata_matches_session() {
// This test drives the requirement for metadata preservation
// Expected: Program name, args, environment preserved in recording
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use pmat::services::dap::recording::Recording;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("my_program", vec!["--flag".to_string(), "value".to_string()]);
// server.add_environment("DAP_CLIENT", "VSCode");
// server.add_environment("DAP_CLIENT_VERSION", "1.75.0");
//
// let recording_path = server.disconnect().unwrap();
// let recording = Recording::load_from_file(&recording_path).unwrap();
//
// let metadata = recording.metadata();
// assert_eq!(metadata.program, "my_program");
// assert_eq!(metadata.args, vec!["--flag", "value"]);
// assert_eq!(metadata.environment.get("DAP_CLIENT"), Some(&"VSCode".to_string()));
assert!(true, "Recording metadata must match session parameters");
}
// RED Test 3: All snapshots present in recording
#[test]
fn test_all_snapshots_present_in_recording() {
// This test drives the requirement for snapshot preservation
// Expected: Every captured snapshot appears in the recording
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use pmat::services::dap::recording::Recording;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
//
// // Capture 100 snapshots
// for _ in 0..100 {
// server.step_next();
// }
//
// let recording_path = server.disconnect().unwrap();
// let recording = Recording::load_from_file(&recording_path).unwrap();
//
// assert_eq!(recording.snapshot_count(), 100, "All 100 snapshots should be preserved");
assert!(true, "All captured snapshots must be present in recording");
}
// RED Test 4: Variable values match execution
#[test]
fn test_variable_values_match_execution() {
// This test drives the requirement for variable value accuracy
// Expected: Variables in recording match actual execution state
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use pmat::services::dap::recording::Recording;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
// server.set_variable("x", 42);
// server.step_next(); // Capture snapshot with x=42
//
// let recording_path = server.disconnect().unwrap();
// let recording = Recording::load_from_file(&recording_path).unwrap();
//
// let snapshot = recording.get_snapshot(0).unwrap();
// assert_eq!(snapshot.variables.get("x"), Some(&serde_json::json!(42)));
assert!(
true,
"Variable values in recording must match execution state"
);
}
// RED Test 5: Stack frames match execution
#[test]
fn test_stack_frames_match_execution() {
// This test drives the requirement for stack frame accuracy
// Expected: Call stack in recording matches actual execution
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use pmat::services::dap::recording::Recording;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
// server.push_stack_frame("main", "main.rs", 10);
// server.push_stack_frame("helper", "utils.rs", 23);
// server.step_next(); // Capture snapshot
//
// let recording_path = server.disconnect().unwrap();
// let recording = Recording::load_from_file(&recording_path).unwrap();
//
// let snapshot = recording.get_snapshot(0).unwrap();
// assert_eq!(snapshot.stack_frames.len(), 2);
// assert_eq!(snapshot.stack_frames[0].name, "main");
// assert_eq!(snapshot.stack_frames[1].name, "helper");
assert!(true, "Stack frames in recording must match execution state");
}
// RED Test 6: Recording file size reasonable
#[test]
fn test_recording_file_size_reasonable() {
// This test drives the requirement for file size limits
// Expected: Recording file size < 10MB for 1000 snapshots
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
//
// // Capture 1000 snapshots with typical data
// for i in 0..1000 {
// server.set_variable("counter", i);
// server.step_next();
// }
//
// let recording_path = server.disconnect().unwrap();
// let file_size = std::fs::metadata(&recording_path).unwrap().len();
//
// const MAX_SIZE_BYTES: u64 = 10 * 1024 * 1024; // 10MB
// assert!(file_size < MAX_SIZE_BYTES, "Recording size {} bytes exceeds 10MB limit", file_size);
assert!(
true,
"Recording file size must be reasonable (<10MB for 1000 snapshots)"
);
}
// RED Test 7: Replay displays correct snapshot count
#[test]
fn test_replay_displays_correct_snapshot_count() {
// This test drives the requirement for replay accuracy
// Expected: Replay shows correct number of snapshots
// Will implement in GREEN phase:
// use pmat::services::dap::recording::Recording;
// use tempfile::NamedTempFile;
//
// // Create a recording with known snapshot count
// let temp_file = NamedTempFile::new().unwrap();
// let mut writer = RecordingWriter::new(
// temp_file.reopen().unwrap(),
// "test_program".to_string(),
// vec![]
// ).unwrap();
//
// // Write 50 snapshots
// for i in 0..50 {
// writer.write_snapshot(&create_test_snapshot(i)).unwrap();
// }
// writer.finalize().unwrap();
//
// // Replay the recording
// let recording = Recording::load_from_file(temp_file.path()).unwrap();
// assert_eq!(recording.snapshot_count(), 50);
assert!(true, "Replay must display correct snapshot count");
}
// RED Test 8: Replay position navigation works
#[test]
fn test_replay_position_navigation() {
// This test drives the requirement for replay navigation
// Expected: Can navigate to any snapshot position in replay
// Will implement in GREEN phase:
// use pmat::services::dap::recording::Recording;
// use tempfile::NamedTempFile;
//
// let temp_file = NamedTempFile::new().unwrap();
// let mut writer = RecordingWriter::new(
// temp_file.reopen().unwrap(),
// "test_program".to_string(),
// vec![]
// ).unwrap();
//
// // Write snapshots with distinct frame IDs
// for i in 0..10 {
// writer.write_snapshot(&create_test_snapshot(i)).unwrap();
// }
// writer.finalize().unwrap();
//
// let recording = Recording::load_from_file(temp_file.path()).unwrap();
//
// // Navigate to different positions
// assert_eq!(recording.get_snapshot(0).unwrap().frame_id, 0);
// assert_eq!(recording.get_snapshot(5).unwrap().frame_id, 5);
// assert_eq!(recording.get_snapshot(9).unwrap().frame_id, 9);
assert!(true, "Replay position navigation must work");
}
// RED Test 9: Multiple sessions create separate recordings
#[test]
fn test_multiple_sessions_separate_recordings() {
// This test drives the requirement for session isolation
// Expected: Multiple debug sessions create different recording files
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
//
// // Session 1
// let server1 = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
// server1.start_session("program1", vec![]);
// server1.step_next();
// let recording1 = server1.disconnect().unwrap();
//
// // Session 2
// let server2 = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
// server2.start_session("program2", vec![]);
// server2.step_next();
// let recording2 = server2.disconnect().unwrap();
//
// // Verify different files
// assert_ne!(recording1, recording2, "Sessions should create different recording files");
//
// // Verify both exist
// assert!(recording1.exists());
// assert!(recording2.exists());
assert!(
true,
"Multiple sessions must create separate recording files"
);
}
// RED Test 10: Performance - snapshot capture overhead
#[test]
fn test_snapshot_capture_performance() {
// This test drives the requirement for performance
// Expected: Snapshot capture adds <1ms overhead per snapshot
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
// use std::time::Instant;
//
// let record_dir = tempdir().unwrap();
// let server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
//
// // Measure 100 snapshot captures
// let start = Instant::now();
// for _ in 0..100 {
// server.step_next(); // Captures snapshot
// }
// let elapsed = start.elapsed();
//
// let avg_ms = elapsed.as_millis() as f64 / 100.0;
// assert!(avg_ms < 1.0, "Average snapshot capture time {} ms exceeds 1ms target", avg_ms);
assert!(true, "Snapshot capture must add <1ms overhead per snapshot");
}
/// Helper: Create test snapshot for E2E tests
#[allow(dead_code)]
fn create_test_snapshot(frame_id: u64) -> pmat::services::dap::recording::Snapshot {
use pmat::services::dap::recording::{Snapshot, StackFrame};
use std::collections::HashMap;
let mut variables = HashMap::new();
variables.insert("test_var".to_string(), serde_json::json!(frame_id));
let stack_frames = vec![StackFrame {
name: "test_function".to_string(),
file: Some("test.rs".to_string()),
line: Some(10 + frame_id as u32),
locals: HashMap::new(),
}];
Snapshot {
frame_id,
timestamp_relative_ms: (frame_id * 100) as u32,
variables,
stack_frames,
instruction_pointer: 0x401000 + (frame_id * 0x10),
memory_snapshot: None,
}
}