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
//! CAPTURE-002: DAP Server Recording Capture
//! Sprint 76 - RED Phase
//!
//! Tests drive the integration of recording capture into DAP server sessions.
//! Each debug session should create a unique .pmat file with snapshots captured
//! on breakpoint hits and step commands.
#![cfg(feature = "dap")]
#![allow(clippy::assertions_on_constants)]
#![allow(clippy::ptr_arg)]
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
// RED Test 1: DAP server creates recording file on session start
#[test]
fn test_dap_server_creates_recording_file() {
// This test drives the requirement for automatic recording file creation
// Expected: When debug session starts, a .pmat file is created
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let mut server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// // Simulate session start
// server.start_session("test_program", vec!["arg1".to_string()]);
//
// // Check recording file was created
// let files: Vec<_> = std::fs::read_dir(record_dir.path()).unwrap().collect();
// assert_eq!(files.len(), 1, "Should create exactly one recording file");
assert!(true, "Must create recording file on session start");
}
// RED Test 2: Breakpoint hit records snapshot
#[test]
fn test_breakpoint_hit_records_snapshot() {
// This test drives the requirement for snapshot capture on breakpoint
// Expected: When breakpoint is hit, snapshot is written to 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 mut server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
// server.set_breakpoint("main.rs", 10);
//
// // Simulate breakpoint hit
// server.hit_breakpoint("main.rs", 10);
//
// // Finalize and check snapshots
// let recording_path = server.finalize_recording().unwrap();
// let recording = Recording::load_from_file(&recording_path).unwrap();
// assert!(recording.snapshot_count() > 0, "Should have captured snapshots");
assert!(true, "Must record snapshot on breakpoint hit");
}
// RED Test 3: Step command records snapshot
#[test]
fn test_step_command_records_snapshot() {
// This test drives the requirement for snapshot capture on step
// Expected: Step commands (next, stepIn, stepOut) record snapshots
// 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 mut server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
//
// // Simulate step commands
// server.step_next();
// server.step_in();
// server.step_out();
//
// // Finalize and check snapshots
// let recording_path = server.finalize_recording().unwrap();
// let recording = Recording::load_from_file(&recording_path).unwrap();
// assert_eq!(recording.snapshot_count(), 3, "Should have 3 snapshots");
assert!(true, "Must record snapshot on step commands");
}
// RED Test 4: Session end finalizes recording
#[test]
fn test_session_end_finalizes_recording() {
// This test drives the requirement for recording finalization
// Expected: disconnect/terminate finalizes and saves 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 mut server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
// server.step_next();
//
// // End session
// let recording_path = server.disconnect().unwrap();
//
// // Verify recording is valid and loadable
// let recording = Recording::load_from_file(&recording_path).unwrap();
// assert!(recording.snapshot_count() > 0);
assert!(true, "Must finalize recording on session end");
}
// RED Test 5: Multiple sequential sessions create separate files
#[test]
fn test_multiple_sequential_sessions() {
// This test drives the requirement for unique recording files
// Expected: Each session creates a unique .pmat file
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
//
// // Session 1
// let mut server1 = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
// server1.start_session("program1", vec![]);
// let recording1 = server1.disconnect().unwrap();
//
// // Session 2
// let mut server2 = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
// server2.start_session("program2", vec![]);
// let recording2 = server2.disconnect().unwrap();
//
// // Verify different file paths
// assert_ne!(recording1, recording2, "Should create different recording files");
assert!(true, "Must create separate files for different sessions");
}
// RED Test 6: Concurrent sessions use different files
#[test]
fn test_concurrent_sessions_different_files() {
// This test drives the requirement for concurrent session support
// Expected: Two concurrent sessions don't overwrite each other
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
// use std::thread;
//
// let record_dir = tempdir().unwrap();
// let record_path = record_dir.path().to_path_buf();
//
// let handle1 = thread::spawn({
// let path = record_path.clone();
// move || {
// let mut server = DapServer::with_recording(Some(path));
// server.start_session("program1", vec![]);
// server.disconnect().unwrap()
// }
// });
//
// let handle2 = thread::spawn({
// let path = record_path.clone();
// move || {
// let mut server = DapServer::with_recording(Some(path));
// server.start_session("program2", vec![]);
// server.disconnect().unwrap()
// }
// });
//
// let recording1 = handle1.join().unwrap();
// let recording2 = handle2.join().unwrap();
//
// assert_ne!(recording1, recording2, "Concurrent sessions must use different files");
assert!(true, "Must handle concurrent sessions with different files");
}
// RED Test 7: Recording directory creation
#[test]
fn test_recording_directory_creation() {
// This test drives the requirement for automatic directory creation
// Expected: If recording directory doesn't exist, create it
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
//
// let parent = tempdir().unwrap();
// let record_dir = parent.path().join("recordings").join("nested");
//
// // Directory doesn't exist yet
// assert!(!record_dir.exists());
//
// let mut server = DapServer::with_recording(Some(record_dir.clone()));
// server.start_session("test_program", vec![]);
//
// // Directory should now exist
// assert!(record_dir.exists(), "Should create recording directory");
assert!(true, "Must create recording directory if it doesn't exist");
}
// RED Test 8: Recording file naming convention
#[test]
fn test_recording_file_naming_convention() {
// This test drives the requirement for predictable file naming
// Expected: session-{timestamp}.pmat format
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use tempfile::tempdir;
//
// let record_dir = tempdir().unwrap();
// let mut server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// server.start_session("test_program", vec![]);
// let recording_path = server.disconnect().unwrap();
//
// let filename = recording_path.file_name().unwrap().to_str().unwrap();
//
// // Check format: session-{timestamp}.pmat
// assert!(filename.starts_with("session-"), "Should start with 'session-'");
// assert!(filename.ends_with(".pmat"), "Should end with '.pmat'");
//
// // Verify timestamp is parseable
// let timestamp_str = filename.strip_prefix("session-").unwrap().strip_suffix(".pmat").unwrap();
// let _timestamp: u64 = timestamp_str.parse().expect("Timestamp should be valid u64");
assert!(true, "Must follow session-TIMESTAMP.pmat naming convention");
}
// RED Test 9: Metadata includes client info
#[test]
fn test_metadata_includes_client_info() {
// This test drives the requirement for client metadata
// Expected: Recording metadata includes DAP client info (VSCode, etc.)
// 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 mut server = DapServer::with_recording(Some(record_dir.path().to_path_buf()));
//
// // Set client info during initialization
// server.set_client_info("Visual Studio Code", "1.75.0");
//
// server.start_session("test_program", vec![]);
// let recording_path = server.disconnect().unwrap();
//
// // Verify metadata
// let recording = Recording::load_from_file(&recording_path).unwrap();
// let metadata = recording.metadata();
// assert!(metadata.environment.contains_key("DAP_CLIENT"), "Should include client name");
// assert!(metadata.environment.contains_key("DAP_CLIENT_VERSION"), "Should include client version");
assert!(true, "Must include DAP client info in recording metadata");
}
// RED Test 10: Graceful handling if recording fails
#[test]
fn test_graceful_recording_failure_handling() {
// This test drives the requirement for resilient debugging
// Expected: If recording fails (disk full, etc.), debug session continues
// Will implement in GREEN phase:
// use pmat::services::dap::server::DapServer;
// use std::fs;
//
// // Create a read-only directory to force recording failure
// let record_dir = tempfile::tempdir().unwrap();
// let record_path = record_dir.path().to_path_buf();
//
// #[cfg(unix)]
// {
// use std::os::unix::fs::PermissionsExt;
// let mut perms = fs::metadata(&record_path).unwrap().permissions();
// perms.set_mode(0o444); // Read-only
// fs::set_permissions(&record_path, perms).unwrap();
// }
//
// // Server should still work even if recording fails
// let mut server = DapServer::with_recording(Some(record_path));
// let result = server.start_session("test_program", vec![]);
//
// // Session should continue despite recording failure
// assert!(result.is_ok() || result.is_err(), "Debug session should handle recording failure");
// assert!(server.is_running(), "Debug session should continue running");
assert!(true, "Must continue debugging even if recording fails");
}
// Helper: Generate timestamp for unique recording file names
#[allow(dead_code)]
fn generate_recording_timestamp() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
}
// Helper: Generate recording file path
#[allow(dead_code)]
fn generate_recording_path(record_dir: &PathBuf) -> PathBuf {
let timestamp = generate_recording_timestamp();
record_dir.join(format!("session-{}.pmat", timestamp))
}