agent-air-runtime 0.7.0

Core runtime for agent-air - LLM orchestration, tools, and permissions (no TUI dependencies)
Documentation
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
//! WriteFile tool implementation
//!
//! This tool allows the LLM to write files to the local filesystem.
//! It integrates with the PermissionRegistry to require user approval
//! before performing write operations.

use std::collections::HashMap;
use std::future::Future;
use std::path::Path;
use std::pin::Pin;
use std::sync::Arc;

use tokio::fs;

use super::types::{
    DisplayConfig, DisplayResult, Executable, ResultContentType, ToolContext, ToolType,
};
use crate::permissions::{GrantTarget, PermissionLevel, PermissionRegistry, PermissionRequest};

/// WriteFile tool name constant.
pub const WRITE_FILE_TOOL_NAME: &str = "write_file";

/// WriteFile tool description constant.
pub const WRITE_FILE_TOOL_DESCRIPTION: &str = r#"Writes content to a file, creating it if it doesn't exist or overwriting if it does.

Usage:
- The file_path parameter must be an absolute path, not a relative path
- This tool will overwrite the existing file if there is one at the provided path
- Parent directories will be created automatically if they don't exist
- Requires user permission before writing (may be cached for session)

Returns:
- Success message with bytes written on successful write
- Error message if permission is denied or the operation fails"#;

/// WriteFile tool JSON schema constant.
pub const WRITE_FILE_TOOL_SCHEMA: &str = r#"{
    "type": "object",
    "properties": {
        "file_path": {
            "type": "string",
            "description": "The absolute path to the file to write"
        },
        "content": {
            "type": "string",
            "description": "The content to write to the file"
        },
        "create_directories": {
            "type": "boolean",
            "description": "Whether to create parent directories if they don't exist. Defaults to true."
        }
    },
    "required": ["file_path", "content"]
}"#;

/// Tool that writes files to the filesystem with permission checks.
pub struct WriteFileTool {
    /// Reference to the permission registry for requesting write permissions.
    permission_registry: Arc<PermissionRegistry>,
}

impl WriteFileTool {
    /// Create a new WriteFileTool with the given permission registry.
    ///
    /// # Arguments
    /// * `permission_registry` - The registry used to request and cache permissions.
    pub fn new(permission_registry: Arc<PermissionRegistry>) -> Self {
        Self {
            permission_registry,
        }
    }

    /// Builds a permission request for writing to a file.
    ///
    /// # Arguments
    /// * `tool_use_id` - Unique identifier for this tool invocation
    /// * `file_path` - Path to the file being written
    /// * `content_len` - Number of bytes to write
    /// * `is_overwrite` - Whether this overwrites an existing file
    /// * `will_create_directories` - Whether parent directories will be created
    fn build_permission_request(
        tool_use_id: &str,
        file_path: &str,
        content_len: usize,
        is_overwrite: bool,
        will_create_directories: bool,
    ) -> PermissionRequest {
        let action_verb = if is_overwrite { "Overwrite" } else { "Create" };
        let dir_note = if will_create_directories {
            " (will create parent directories)"
        } else {
            ""
        };
        let reason = format!(
            "{} file with {} bytes of content{}",
            action_verb.to_lowercase(),
            content_len,
            dir_note
        );

        PermissionRequest::new(
            tool_use_id,
            GrantTarget::path(file_path, false),
            PermissionLevel::Write,
            format!("Write file: {}", file_path),
        )
        .with_reason(reason)
        .with_tool(WRITE_FILE_TOOL_NAME)
    }
}

impl Executable for WriteFileTool {
    fn name(&self) -> &str {
        WRITE_FILE_TOOL_NAME
    }

    fn description(&self) -> &str {
        WRITE_FILE_TOOL_DESCRIPTION
    }

    fn input_schema(&self) -> &str {
        WRITE_FILE_TOOL_SCHEMA
    }

    fn tool_type(&self) -> ToolType {
        ToolType::TextEdit
    }

    fn execute(
        &self,
        context: ToolContext,
        input: HashMap<String, serde_json::Value>,
    ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> {
        let permission_registry = self.permission_registry.clone();

        Box::pin(async move {
            // ─────────────────────────────────────────────────────────────
            // Step 1: Extract and validate parameters
            // ─────────────────────────────────────────────────────────────
            let file_path = input
                .get("file_path")
                .and_then(|v| v.as_str())
                .ok_or_else(|| "Missing required 'file_path' parameter".to_string())?;

            let content = input
                .get("content")
                .and_then(|v| v.as_str())
                .ok_or_else(|| "Missing required 'content' parameter".to_string())?;

            let create_directories = input
                .get("create_directories")
                .and_then(|v| v.as_bool())
                .unwrap_or(true);

            let path = Path::new(file_path);

            // Validate absolute path
            if !path.is_absolute() {
                return Err(format!(
                    "file_path must be an absolute path, got: {}",
                    file_path
                ));
            }

            // Check if this is an overwrite (file exists) or create (new file)
            let is_overwrite = path.exists();

            // ─────────────────────────────────────────────────────────────
            // Step 2: Determine if directories will be created
            // ─────────────────────────────────────────────────────────────
            let will_create_directories =
                create_directories && path.parent().map(|p| !p.exists()).unwrap_or(false);

            // ─────────────────────────────────────────────────────────────
            // Step 3: Request permission if not pre-approved by batch executor
            // ─────────────────────────────────────────────────────────────
            if !context.permissions_pre_approved {
                let permission_request = Self::build_permission_request(
                    &context.tool_use_id,
                    file_path,
                    content.len(),
                    is_overwrite,
                    will_create_directories,
                );

                let response_rx = permission_registry
                    .request_permission(
                        context.session_id,
                        permission_request,
                        context.turn_id.clone(),
                    )
                    .await
                    .map_err(|e| format!("Failed to request permission: {}", e))?;

                let response = response_rx
                    .await
                    .map_err(|_| "Permission request was cancelled".to_string())?;

                if !response.granted {
                    let reason = response
                        .message
                        .unwrap_or_else(|| "Permission denied by user".to_string());
                    return Err(format!(
                        "Permission denied to write '{}': {}",
                        file_path, reason
                    ));
                }
            }

            // ─────────────────────────────────────────────────────────────
            // Step 7: Create parent directories if requested
            // ─────────────────────────────────────────────────────────────
            if create_directories
                && let Some(parent) = path.parent()
                && !parent.exists()
            {
                fs::create_dir_all(parent)
                    .await
                    .map_err(|e| format!("Failed to create parent directories: {}", e))?;
            }

            // ─────────────────────────────────────────────────────────────
            // Step 8: Perform the write operation
            // ─────────────────────────────────────────────────────────────
            let bytes_written = content.len();
            fs::write(path, content)
                .await
                .map_err(|e| format!("Failed to write file '{}': {}", file_path, e))?;

            let action = if is_overwrite { "overwrote" } else { "created" };
            Ok(format!(
                "Successfully {} '{}' ({} bytes)",
                action, file_path, bytes_written
            ))
        })
    }

    fn display_config(&self) -> DisplayConfig {
        DisplayConfig {
            display_name: "Write File".to_string(),
            display_title: Box::new(|input| {
                input
                    .get("file_path")
                    .and_then(|v| v.as_str())
                    .map(|p| {
                        Path::new(p)
                            .file_name()
                            .and_then(|n| n.to_str())
                            .unwrap_or(p)
                            .to_string()
                    })
                    .unwrap_or_default()
            }),
            display_content: Box::new(|input, result| {
                let content_preview = input
                    .get("content")
                    .and_then(|v| v.as_str())
                    .map(|c| {
                        let lines: Vec<&str> = c.lines().take(10).collect();
                        if c.lines().count() > 10 {
                            format!("{}...\n[truncated]", lines.join("\n"))
                        } else {
                            lines.join("\n")
                        }
                    })
                    .unwrap_or_else(|| result.to_string());

                DisplayResult {
                    content: content_preview,
                    content_type: ResultContentType::PlainText,
                    is_truncated: input
                        .get("content")
                        .and_then(|v| v.as_str())
                        .map(|c| c.lines().count() > 10)
                        .unwrap_or(false),
                    full_length: input
                        .get("content")
                        .and_then(|v| v.as_str())
                        .map(|c| c.lines().count())
                        .unwrap_or(0),
                }
            }),
        }
    }

    fn compact_summary(&self, input: &HashMap<String, serde_json::Value>, _result: &str) -> String {
        let filename = input
            .get("file_path")
            .and_then(|v| v.as_str())
            .map(|p| {
                Path::new(p)
                    .file_name()
                    .and_then(|n| n.to_str())
                    .unwrap_or(p)
            })
            .unwrap_or("unknown");

        let bytes = input
            .get("content")
            .and_then(|v| v.as_str())
            .map(|c| c.len())
            .unwrap_or(0);

        format!("[WriteFile: {} ({} bytes)]", filename, bytes)
    }

    fn required_permissions(
        &self,
        context: &ToolContext,
        input: &HashMap<String, serde_json::Value>,
    ) -> Option<Vec<PermissionRequest>> {
        // Extract file_path parameter
        let file_path = input.get("file_path").and_then(|v| v.as_str())?;

        // Extract content to determine size
        let content = input.get("content").and_then(|v| v.as_str())?;

        let path = Path::new(file_path);

        // Validate absolute path - return None if invalid
        if !path.is_absolute() {
            return None;
        }

        // Check if this is an overwrite (file exists) or create (new file)
        let is_overwrite = path.exists();

        // Check if directories will be created (default is true)
        let create_directories = input
            .get("create_directories")
            .and_then(|v| v.as_bool())
            .unwrap_or(true);
        let will_create_directories =
            create_directories && path.parent().map(|p| !p.exists()).unwrap_or(false);

        // Build and return permission request
        let permission_request = Self::build_permission_request(
            &context.tool_use_id,
            file_path,
            content.len(),
            is_overwrite,
            will_create_directories,
        );

        Some(vec![permission_request])
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::controller::PermissionPanelResponse;
    use crate::controller::types::ControllerEvent;
    use crate::permissions::PermissionLevel;
    use tempfile::TempDir;
    use tokio::sync::mpsc;

    /// Helper to create a permission registry for testing.
    fn create_test_registry() -> (Arc<PermissionRegistry>, mpsc::Receiver<ControllerEvent>) {
        let (tx, rx) = mpsc::channel(16);
        let registry = Arc::new(PermissionRegistry::new(tx));
        (registry, rx)
    }

    fn grant_once() -> PermissionPanelResponse {
        PermissionPanelResponse {
            granted: true,
            grant: None,
            message: None,
        }
    }

    fn deny(reason: &str) -> PermissionPanelResponse {
        PermissionPanelResponse {
            granted: false,
            grant: None,
            message: Some(reason.to_string()),
        }
    }

    #[tokio::test]
    async fn test_write_new_file_with_permission_granted() {
        let (registry, mut event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry.clone());
        let temp_dir = TempDir::new().unwrap();
        let file_path = temp_dir.path().join("test.txt");

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String(file_path.to_str().unwrap().to_string()),
        );
        input.insert(
            "content".to_string(),
            serde_json::Value::String("Hello, World!".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test-123".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        // Spawn task to handle permission request
        let registry_clone = registry.clone();
        tokio::spawn(async move {
            // Wait for permission request event
            if let Some(ControllerEvent::PermissionRequired { tool_use_id, .. }) =
                event_rx.recv().await
            {
                // Grant permission
                registry_clone
                    .respond_to_request(&tool_use_id, grant_once())
                    .await
                    .unwrap();
            }
        });

        let result = tool.execute(context, input).await;

        assert!(result.is_ok());
        assert!(file_path.exists());
        assert_eq!(
            tokio::fs::read_to_string(&file_path).await.unwrap(),
            "Hello, World!"
        );
    }

    #[tokio::test]
    async fn test_write_file_permission_denied() {
        let (registry, mut event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry.clone());
        let temp_dir = TempDir::new().unwrap();
        let file_path = temp_dir.path().join("test.txt");

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String(file_path.to_str().unwrap().to_string()),
        );
        input.insert(
            "content".to_string(),
            serde_json::Value::String("Hello, World!".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test-456".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        // Spawn task to deny permission
        let registry_clone = registry.clone();
        tokio::spawn(async move {
            if let Some(ControllerEvent::PermissionRequired { tool_use_id, .. }) =
                event_rx.recv().await
            {
                // Deny permission
                registry_clone
                    .respond_to_request(&tool_use_id, deny("Not allowed"))
                    .await
                    .unwrap();
            }
        });

        let result = tool.execute(context, input).await;

        assert!(result.is_err());
        assert!(result.unwrap_err().contains("Permission denied"));
        assert!(!file_path.exists());
    }

    #[tokio::test]
    async fn test_write_file_session_permission_cached() {
        let (registry, mut event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry.clone());
        let temp_dir = TempDir::new().unwrap();

        // First write - will request permission
        let file_path_1 = temp_dir.path().join("test1.txt");
        let mut input_1 = HashMap::new();
        input_1.insert(
            "file_path".to_string(),
            serde_json::Value::String(file_path_1.to_str().unwrap().to_string()),
        );
        input_1.insert(
            "content".to_string(),
            serde_json::Value::String("Content 1".to_string()),
        );

        let context_1 = ToolContext {
            session_id: 1,
            tool_use_id: "test-1".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        // Grant with Session scope
        let registry_clone = registry.clone();
        tokio::spawn(async move {
            if let Some(ControllerEvent::PermissionRequired { tool_use_id, .. }) =
                event_rx.recv().await
            {
                registry_clone
                    .respond_to_request(&tool_use_id, grant_once())
                    .await
                    .unwrap();
            }
        });

        let result_1 = tool.execute(context_1, input_1).await;
        assert!(result_1.is_ok());
        assert!(file_path_1.exists());

        // Second write - should use cached permission (no event emitted)
        // Note: Cache matching uses action pattern, so same action "Create file: test2.txt"
        // will NOT match "Create file: test1.txt". This is current behavior.
        // For this test, we verify the first write worked.
    }

    #[tokio::test]
    async fn test_overwrite_existing_file() {
        let (registry, mut event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry.clone());
        let temp_dir = TempDir::new().unwrap();
        let file_path = temp_dir.path().join("existing.txt");

        // Create existing file
        tokio::fs::write(&file_path, "old content").await.unwrap();

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String(file_path.to_str().unwrap().to_string()),
        );
        input.insert(
            "content".to_string(),
            serde_json::Value::String("new content".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test-overwrite".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        // Grant permission
        let registry_clone = registry.clone();
        tokio::spawn(async move {
            if let Some(ControllerEvent::PermissionRequired { tool_use_id, .. }) =
                event_rx.recv().await
            {
                registry_clone
                    .respond_to_request(&tool_use_id, grant_once())
                    .await
                    .unwrap();
            }
        });

        let result = tool.execute(context, input).await;

        assert!(result.is_ok());
        assert!(result.unwrap().contains("overwrote"));
        assert_eq!(
            tokio::fs::read_to_string(&file_path).await.unwrap(),
            "new content"
        );
    }

    #[tokio::test]
    async fn test_create_parent_directories() {
        let (registry, mut event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry.clone());
        let temp_dir = TempDir::new().unwrap();
        let file_path = temp_dir.path().join("nested/dir/test.txt");

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String(file_path.to_str().unwrap().to_string()),
        );
        input.insert(
            "content".to_string(),
            serde_json::Value::String("nested content".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test-nested".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        // Grant permission
        let registry_clone = registry.clone();
        tokio::spawn(async move {
            if let Some(ControllerEvent::PermissionRequired { tool_use_id, .. }) =
                event_rx.recv().await
            {
                registry_clone
                    .respond_to_request(&tool_use_id, grant_once())
                    .await
                    .unwrap();
            }
        });

        let result = tool.execute(context, input).await;

        assert!(result.is_ok());
        assert!(file_path.exists());
        assert!(file_path.parent().unwrap().exists());
    }

    #[tokio::test]
    async fn test_relative_path_rejected() {
        let (registry, _event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry);

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String("relative/path.txt".to_string()),
        );
        input.insert(
            "content".to_string(),
            serde_json::Value::String("content".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        let result = tool.execute(context, input).await;
        assert!(result.is_err());
        assert!(result.unwrap_err().contains("absolute path"));
    }

    #[tokio::test]
    async fn test_missing_file_path() {
        let (registry, _event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry);

        let mut input = HashMap::new();
        input.insert(
            "content".to_string(),
            serde_json::Value::String("content".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        let result = tool.execute(context, input).await;
        assert!(result.is_err());
        assert!(result.unwrap_err().contains("Missing required 'file_path'"));
    }

    #[tokio::test]
    async fn test_missing_content() {
        let (registry, _event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry);

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String("/tmp/test.txt".to_string()),
        );

        let context = ToolContext {
            session_id: 1,
            tool_use_id: "test".to_string(),
            turn_id: None,
            permissions_pre_approved: false,
        };

        let result = tool.execute(context, input).await;
        assert!(result.is_err());
        assert!(result.unwrap_err().contains("Missing required 'content'"));
    }

    #[test]
    fn test_compact_summary() {
        let (registry, _event_rx) = create_test_registry();
        let tool = WriteFileTool::new(registry);

        let mut input = HashMap::new();
        input.insert(
            "file_path".to_string(),
            serde_json::Value::String("/path/to/file.rs".to_string()),
        );
        input.insert(
            "content".to_string(),
            serde_json::Value::String("some content here".to_string()),
        );

        let summary = tool.compact_summary(&input, "Successfully created...");
        assert_eq!(summary, "[WriteFile: file.rs (17 bytes)]");
    }

    #[test]
    fn test_build_permission_request_create() {
        let request = WriteFileTool::build_permission_request(
            "test-id",
            "/path/to/new.txt",
            100,
            false,
            false,
        );

        assert_eq!(request.description, "Write file: /path/to/new.txt");
        assert_eq!(
            request.reason,
            Some("create file with 100 bytes of content".to_string())
        );
        assert_eq!(request.target, GrantTarget::path("/path/to/new.txt", false));
        assert_eq!(request.required_level, PermissionLevel::Write);
    }

    #[test]
    fn test_build_permission_request_overwrite() {
        let request = WriteFileTool::build_permission_request(
            "test-id",
            "/path/to/existing.txt",
            500,
            true,
            false,
        );

        assert_eq!(request.description, "Write file: /path/to/existing.txt");
        assert_eq!(
            request.reason,
            Some("overwrite file with 500 bytes of content".to_string())
        );
        assert_eq!(
            request.target,
            GrantTarget::path("/path/to/existing.txt", false)
        );
        assert_eq!(request.required_level, PermissionLevel::Write);
    }

    #[test]
    fn test_build_permission_request_with_directory_creation() {
        let request = WriteFileTool::build_permission_request(
            "test-id",
            "/new/path/file.txt",
            200,
            false,
            true,
        );

        assert_eq!(request.description, "Write file: /new/path/file.txt");
        assert_eq!(
            request.reason,
            Some(
                "create file with 200 bytes of content (will create parent directories)"
                    .to_string()
            )
        );
        assert_eq!(
            request.target,
            GrantTarget::path("/new/path/file.txt", false)
        );
        assert_eq!(request.required_level, PermissionLevel::Write);
    }
}