vetto 0.2.14

Daemon-less sandbox + security layer for AI coding agents (Landlock/Seatbelt, TUI statusline, post-session audit reports)
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
//! Fast native shim dispatcher & recursion barrier (Step 15).
//!
//! When developer tools are invoked through transparent shims (e.g. `git`, `node`, `cargo`),
//! this module intercepts execution, prevents recursive sandbox nesting via `VETTO_SANDBOXED=1`,
//! discovers project policy, and delegates to the real host binary.

pub mod registry;

use anyhow::{bail, Context, Result};
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;

/// Environment variable set to indicate execution inside an active Vetto sandbox.
pub const ENV_VETTO_SANDBOXED: &str = "VETTO_SANDBOXED";

/// Environment variable set to prevent nested shim interception.
pub const ENV_VETTO_SHIM_ACTIVE: &str = "VETTO_SHIM_ACTIVE";

/// Environment variable set to indicate that execution is wrapped by vetto enable.
pub const ENV_VETTO_WRAPPED: &str = "VETTO_WRAPPED";

/// Check if the current process is already running in a sandboxed or shim-active context.
pub fn is_sandboxed() -> bool {
    env::var(ENV_VETTO_SANDBOXED)
        .map(|v| v == "1")
        .unwrap_or(false)
        || env::var(ENV_VETTO_SHIM_ACTIVE)
            .map(|v| v == "1")
            .unwrap_or(false)
        || env::var(ENV_VETTO_WRAPPED)
            .map(|v| v == "1")
            .unwrap_or(false)
}

/// Detects if `vetto` was invoked as a shim via `argv[0]` (e.g., symlinked or renamed).
pub fn detect_argv0_shim() -> Option<String> {
    let arg0 = env::args_os().next()?;
    let path = PathBuf::from(arg0);
    let stem = path.file_stem()?.to_string_lossy().to_string();

    if stem.eq_ignore_ascii_case("vetto")
        || stem.eq_ignore_ascii_case("vetto-shim")
        || stem.eq_ignore_ascii_case("__vetto")
    {
        None
    } else {
        Some(stem)
    }
}

/// Helper to detect if a file is a Vetto-generated shim script.
pub fn is_vetto_shim_content(path: &Path) -> bool {
    if let Ok(mut f) = std::fs::File::open(path) {
        use std::io::Read;
        let mut head = [0u8; 512];
        if let Ok(n) = f.read(&mut head) {
            let s = String::from_utf8_lossy(&head[..n]);
            if s.contains("Vetto transparent binary shim")
                || s.contains("Automatically generated by `vetto")
                || s.contains("vetto shim")
            {
                return true;
            }
        }
    }
    false
}

/// Finds the real host binary on `$PATH`, strictly excluding Vetto shim directories
/// to eliminate circular interception loops.
pub fn find_real_binary(name: &str) -> Result<PathBuf> {
    let name_path = Path::new(name);
    if name_path.is_absolute()
        && is_executable_file(name_path)
        && !is_shim_path(name_path)
        && !is_vetto_shim_content(name_path)
    {
        return Ok(name_path.to_path_buf());
    }

    let path_var = env::var_os("PATH").context("PATH environment variable is not set")?;
    let paths = env::split_paths(&path_var);

    let current_exe = env::current_exe().ok();

    for dir in paths {
        if is_shim_directory(&dir) {
            continue;
        }

        let candidate = dir.join(name);
        if is_executable_file(&candidate) && !is_vetto_shim_content(&candidate) {
            // Ensure we don't resolve to our own current executable
            if let Some(ref current) = current_exe {
                if let (Ok(c1), Ok(c2)) = (candidate.canonicalize(), current.canonicalize()) {
                    if c1 == c2 {
                        continue;
                    }
                }
            }
            return Ok(candidate);
        }

        #[cfg(windows)]
        {
            let pathext = env::var_os("PATHEXT").unwrap_or_else(|| ".COM;.EXE;.BAT;.CMD".into());
            for ext in pathext.to_string_lossy().split(';') {
                let ext = ext.trim().trim_start_matches('.');
                if ext.is_empty() {
                    continue;
                }
                let ext_candidate = candidate.with_extension(ext);
                if is_executable_file(&ext_candidate) && !is_vetto_shim_content(&ext_candidate) {
                    return Ok(ext_candidate);
                }
            }
        }
    }

    bail!("could not locate real host binary for '{name}' outside Vetto shims in PATH")
}

/// Checks if a directory path belongs to a Vetto shims directory.
pub fn is_shim_directory(dir: &Path) -> bool {
    let s = dir.to_string_lossy();
    s.contains(".vetto/shims")
        || s.contains(".vetto\\shims")
        || s.ends_with("/vetto/shims")
        || s.ends_with("\\vetto\\shims")
        || s.contains(".vetto/git-hooks")
        || s.contains(".vetto\\git-hooks")
}

/// Checks if a file path is located in a Vetto shims directory.
pub fn is_shim_path(path: &Path) -> bool {
    if let Some(parent) = path.parent() {
        is_shim_directory(parent)
    } else {
        false
    }
}

/// Discovers the nearest project root starting from current directory upwards.
pub fn find_project_root() -> Option<PathBuf> {
    let mut curr = env::current_dir().ok()?;
    loop {
        if curr.join(".vetto").is_dir()
            || curr.join(".vetto.toml").is_file()
            || curr.join("vetto.toml").is_file()
            || curr.join(".git").exists()
            || curr.join("Cargo.toml").is_file()
            || curr.join("package.json").is_file()
            || curr.join("pyproject.toml").is_file()
            || curr.join("go.mod").is_file()
        {
            return Some(curr);
        }
        if !curr.pop() {
            break;
        }
    }
    None
}

fn find_git_subcommand(args: &[String]) -> Option<(usize, &str)> {
    let mut i = 0;
    if i < args.len()
        && (args[i] == "git" || args[i].ends_with("/git") || args[i].ends_with("\\git.exe"))
    {
        i += 1;
    }
    while i < args.len() {
        let arg = &args[i];
        if arg == "--allow-destructive-git" {
            i += 1;
            continue;
        }
        if arg == "-C"
            || arg == "-c"
            || arg == "--git-dir"
            || arg == "--work-tree"
            || arg == "--namespace"
            || arg == "--exec-path"
        {
            i += 2;
            continue;
        }
        if arg.starts_with('-') {
            i += 1;
            continue;
        }
        return Some((i, arg.as_str()));
    }
    None
}

/// Comprehensive Git Guard: detects and blocks destructive git operations.
pub fn is_destructive_git_command(args: &[String]) -> Option<&'static str> {
    if env::var("VETTO_ALLOW_DESTRUCTIVE_GIT")
        .map(|v| v == "1")
        .unwrap_or(false)
        || args.iter().any(|a| a == "--allow-destructive-git")
    {
        return None;
    }

    let (subcmd_idx, subcmd) = find_git_subcommand(args)?;
    let sub_args = &args[subcmd_idx + 1..];

    match subcmd {
        "push" => {
            for arg in sub_args {
                if arg == "--force"
                    || arg == "-f"
                    || arg == "--force-with-lease"
                    || arg.starts_with("--force-with-lease=")
                    || arg == "--force-if-includes"
                    || arg == "--delete"
                    || arg == "-d"
                    || (arg.starts_with('+') && (arg.contains(':') || arg.len() > 1))
                    || (arg.starts_with(':') && arg.len() > 1)
                {
                    return Some("destructive git push (force/delete) blocked by vetto git_guard");
                }
            }
        }
        "reset" => {
            for arg in sub_args {
                if arg == "--hard" || arg.starts_with("--hard=") {
                    return Some(
                        "destructive 'git reset --hard' blocked by vetto git_guard (wipes uncommitted changes)",
                    );
                }
            }
        }
        "clean" => {
            for arg in sub_args {
                if arg == "--force" || arg == "-force" {
                    return Some(
                        "destructive 'git clean -f' blocked by vetto git_guard (deletes untracked files)",
                    );
                }
                if arg.starts_with('-') && !arg.starts_with("--") && arg.contains('f') {
                    return Some(
                        "destructive 'git clean -f' blocked by vetto git_guard (deletes untracked files)",
                    );
                }
            }
        }
        "checkout" => {
            let has_dot = sub_args.iter().any(|a| a == ".");
            let has_force = sub_args.iter().any(|a| a == "-f" || a == "--force");
            if has_dot || has_force {
                return Some(
                    "destructive 'git checkout .' blocked by vetto git_guard (discards working tree changes)",
                );
            }
        }
        "restore" => {
            let has_dot = sub_args.iter().any(|a| a == ".");
            if has_dot {
                return Some(
                    "destructive 'git restore .' blocked by vetto git_guard (discards working tree changes)",
                );
            }
        }
        "branch" => {
            let has_capital_d = sub_args.iter().any(|a| a == "-D");
            let has_delete = sub_args.iter().any(|a| a == "--delete" || a == "-d");
            let has_force = sub_args.iter().any(|a| a == "--force" || a == "-f");
            if has_capital_d || (has_delete && has_force) {
                return Some("destructive 'git branch -D' blocked by vetto git_guard");
            }
        }
        _ => {}
    }

    None
}

/// Checks if git arguments constitute a destructive push operation.
pub fn is_destructive_git_push(args: &[String]) -> Option<&'static str> {
    if let Some(reason) = is_destructive_git_command(args) {
        if reason.contains("push") {
            return Some(reason);
        }
    }
    None
}

/// Extracts shim control flags (`--allow-destructive-git`, `--no-loop-guard`,
/// `--timeout <duration>`) and clean args.
pub fn parse_shim_args(args: &[String]) -> (bool, bool, Option<std::time::Duration>, Vec<String>) {
    let mut clean = Vec::with_capacity(args.len());
    let mut allow_override = false;
    let mut no_loop_guard = false;
    let mut timeout = env::var("VETTO_COMMAND_TIMEOUT")
        .ok()
        .and_then(|v| crate::watchdog::timeout::parse_timeout(&v).ok());

    let mut i = 0;
    while i < args.len() {
        let a = &args[i];
        if a == "--allow-destructive-git" {
            allow_override = true;
            i += 1;
        } else if a == "--no-loop-guard" {
            no_loop_guard = true;
            i += 1;
        } else if a == "--timeout" {
            if i + 1 < args.len() {
                if let Ok(dur) = crate::watchdog::timeout::parse_timeout(&args[i + 1]) {
                    timeout = Some(dur);
                }
                i += 2;
            } else {
                i += 1;
            }
        } else if let Some(raw) = a.strip_prefix("--timeout=") {
            if let Ok(dur) = crate::watchdog::timeout::parse_timeout(raw) {
                timeout = Some(dur);
            }
            i += 1;
        } else {
            clean.push(a.clone());
            i += 1;
        }
    }

    (allow_override, no_loop_guard, timeout, clean)
}

/// Fast native dispatch entrypoint for shimmed binaries.
pub fn dispatch(binary_name: &str, args: &[String]) -> Result<i32> {
    let (allow_override, no_loop_guard, configured_timeout, clean_args) = parse_shim_args(args);

    let bypass_active = allow_override
        || env::var("VETTO_ALLOW_DESTRUCTIVE_GIT")
            .map(|v| v == "1")
            .unwrap_or(false);

    let real_binary = find_real_binary(binary_name)
        .with_context(|| format!("shim: failed to resolve host binary for '{binary_name}'"))?;

    // Git guard check: block destructive git commands
    if (binary_name == "git" || binary_name.ends_with("/git") || binary_name.ends_with("\\git.exe"))
        && (is_sandboxed()
            || env::var("VETTO_GIT_GUARD")
                .map(|v| v == "1")
                .unwrap_or(false))
        && !bypass_active
    {
        if let Some(reason) = is_destructive_git_command(&clean_args) {
            eprintln!("vetto: {reason}");
            bail!("{reason}");
        }
    }

    if !no_loop_guard {
        crate::watchdog::check_before_execution(binary_name, &clean_args, None)?;
    }

    let exit_code = if is_sandboxed() {
        // Recursion barrier active — execute real binary directly with zero overhead
        let mut cmd = Command::new(&real_binary);
        cmd.args(&clean_args);
        if let Some(limit) = configured_timeout {
            let status = crate::watchdog::timeout::run_with_timeout(&mut cmd, limit)?;
            status.code().unwrap_or(124)
        } else {
            let mut child = cmd.spawn()?;
            let status = child.wait()?;
            status.code().unwrap_or(1)
        }
    } else {
        // Not sandboxed yet: execute under Vetto sandbox supervisor
        let vetto_exe = env::current_exe().unwrap_or_else(|_| PathBuf::from("vetto"));

        let mut supervisor_cmd = Command::new(vetto_exe);
        supervisor_cmd.env(ENV_VETTO_SANDBOXED, "1");
        supervisor_cmd.env(ENV_VETTO_SHIM_ACTIVE, "1");
        supervisor_cmd.env(ENV_VETTO_WRAPPED, "1");

        supervisor_cmd.arg("--");
        supervisor_cmd.arg(&real_binary);
        supervisor_cmd.args(&clean_args);

        if let Some(limit) = configured_timeout {
            let status = crate::watchdog::timeout::run_with_timeout(&mut supervisor_cmd, limit)?;
            status.code().unwrap_or(124)
        } else {
            let mut child = supervisor_cmd.spawn()?;
            let status = child.wait()?;
            status.code().unwrap_or(1)
        }
    };

    let _ = crate::watchdog::record_after_execution(binary_name, &clean_args, exit_code, None);
    Ok(exit_code)
}

/// Entrypoint for the `vetto shim` subcommand.
pub fn run_cli(binary: Option<String>, args: Vec<String>) -> Result<()> {
    let target = match binary {
        Some(b) => b,
        None => {
            if let Some(detected) = detect_argv0_shim() {
                detected
            } else {
                bail!("no target binary specified for shim execution; usage: vetto shim <binary> -- [args...]");
            }
        }
    };

    let code = dispatch(&target, &args)?;
    if code != 0 {
        std::process::exit(code);
    }
    Ok(())
}

fn is_executable_file(p: &Path) -> bool {
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt;
        match std::fs::metadata(p) {
            Ok(m) => m.is_file() && (m.permissions().mode() & 0o111) != 0,
            Err(_) => false,
        }
    }
    #[cfg(windows)]
    {
        p.is_file()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn detects_shim_directory_patterns() {
        assert!(is_shim_directory(Path::new("/home/user/.vetto/shims")));
        assert!(is_shim_directory(Path::new(
            "C:\\Users\\user\\.vetto\\shims"
        )));
        assert!(is_shim_directory(Path::new("/repo/.vetto/shims")));
        assert!(!is_shim_directory(Path::new("/usr/bin")));
        assert!(!is_shim_directory(Path::new("/home/user/.cargo/bin")));
    }

    #[test]
    fn recursion_barrier_checks_environment() {
        env::remove_var(ENV_VETTO_SANDBOXED);
        env::remove_var(ENV_VETTO_SHIM_ACTIVE);
        env::remove_var(ENV_VETTO_WRAPPED);
        assert!(!is_sandboxed());

        env::set_var(ENV_VETTO_SANDBOXED, "1");
        assert!(is_sandboxed());
        env::remove_var(ENV_VETTO_SANDBOXED);

        env::set_var(ENV_VETTO_SHIM_ACTIVE, "1");
        assert!(is_sandboxed());
        env::remove_var(ENV_VETTO_SHIM_ACTIVE);

        env::set_var(ENV_VETTO_WRAPPED, "1");
        assert!(is_sandboxed());
        env::remove_var(ENV_VETTO_WRAPPED);
    }

    #[test]
    fn finds_real_system_binary_such_as_sh() {
        #[cfg(unix)]
        {
            let sh_path = find_real_binary("sh");
            assert!(sh_path.is_ok(), "sh should be present in standard PATH");
            let p = sh_path.unwrap();
            assert!(p.exists());
            assert!(!is_shim_directory(p.parent().unwrap()));
        }
    }

    #[test]
    fn detects_destructive_git_push_variants() {
        assert!(is_destructive_git_push(&["push".into(), "--force".into()]).is_some());
        assert!(is_destructive_git_push(&["push".into(), "-f".into()]).is_some());
        assert!(is_destructive_git_push(&["push".into(), "--force-with-lease".into()]).is_some());
        assert!(is_destructive_git_push(&[
            "push".into(),
            "origin".into(),
            "--delete".into(),
            "branch".into()
        ])
        .is_some());
        assert!(
            is_destructive_git_push(&["push".into(), "origin".into(), ":branch".into()]).is_some()
        );
        assert!(
            is_destructive_git_push(&["push".into(), "origin".into(), "main".into()]).is_none()
        );
        assert!(is_destructive_git_push(&["status".into()]).is_none());
    }

    #[test]
    fn detects_destructive_git_commands() {
        // Hard reset
        assert!(is_destructive_git_command(&["reset".into(), "--hard".into()]).is_some());
        assert!(
            is_destructive_git_command(&["reset".into(), "--hard".into(), "HEAD~1".into()])
                .is_some()
        );
        assert!(is_destructive_git_command(&["reset".into(), "--hard=HEAD~1".into()]).is_some());

        // Aggressive clean
        assert!(is_destructive_git_command(&["clean".into(), "-f".into()]).is_some());
        assert!(is_destructive_git_command(&["clean".into(), "-fd".into()]).is_some());
        assert!(is_destructive_git_command(&["clean".into(), "-fx".into()]).is_some());
        assert!(is_destructive_git_command(&["clean".into(), "-fdx".into()]).is_some());
        assert!(is_destructive_git_command(&["clean".into(), "-fxd".into()]).is_some());
        assert!(is_destructive_git_command(&["clean".into(), "-force".into()]).is_some());
        assert!(is_destructive_git_command(&["clean".into(), "--force".into()]).is_some());

        // Discard checkout
        assert!(is_destructive_git_command(&["checkout".into(), ".".into()]).is_some());
        assert!(
            is_destructive_git_command(&["checkout".into(), "--".into(), ".".into()]).is_some()
        );
        assert!(is_destructive_git_command(&["checkout".into(), "-f".into()]).is_some());
        assert!(is_destructive_git_command(&["checkout".into(), "--force".into()]).is_some());

        // Discard restore
        assert!(is_destructive_git_command(&["restore".into(), ".".into()]).is_some());
        assert!(
            is_destructive_git_command(&["restore".into(), "--worktree".into(), ".".into()])
                .is_some()
        );
        assert!(
            is_destructive_git_command(&["restore".into(), "--staged".into(), ".".into()])
                .is_some()
        );

        // Destructive push
        assert!(is_destructive_git_command(&["push".into(), "--force".into()]).is_some());
        assert!(is_destructive_git_command(&["push".into(), "-f".into()]).is_some());
        assert!(
            is_destructive_git_command(&["push".into(), "--force-with-lease".into()]).is_some()
        );
        assert!(is_destructive_git_command(&[
            "push".into(),
            "origin".into(),
            "--delete".into(),
            "feat".into()
        ])
        .is_some());
        assert!(is_destructive_git_command(&[
            "push".into(),
            "origin".into(),
            "-d".into(),
            "feat".into()
        ])
        .is_some());
        assert!(
            is_destructive_git_command(&["push".into(), "origin".into(), ":feat".into()]).is_some()
        );
        assert!(
            is_destructive_git_command(&["push".into(), "origin".into(), "+main:main".into()])
                .is_some()
        );

        // Forced branch delete
        assert!(
            is_destructive_git_command(&["branch".into(), "-D".into(), "feat".into()]).is_some()
        );
        assert!(is_destructive_git_command(&[
            "branch".into(),
            "--delete".into(),
            "--force".into(),
            "feat".into()
        ])
        .is_some());
        assert!(is_destructive_git_command(&[
            "branch".into(),
            "-d".into(),
            "-f".into(),
            "feat".into()
        ])
        .is_some());

        // Works with explicit `git` prefix as well
        assert!(
            is_destructive_git_command(&["git".into(), "reset".into(), "--hard".into()]).is_some()
        );
    }

    #[test]
    fn allows_safe_git_commands() {
        assert!(is_destructive_git_command(&["status".into()]).is_none());
        assert!(
            is_destructive_git_command(&["commit".into(), "-m".into(), "msg".into()]).is_none()
        );
        assert!(is_destructive_git_command(&["diff".into()]).is_none());
        assert!(
            is_destructive_git_command(&["checkout".into(), "-b".into(), "new-branch".into()])
                .is_none()
        );
        assert!(is_destructive_git_command(&["checkout".into(), "main".into()]).is_none());
        assert!(
            is_destructive_git_command(&["push".into(), "origin".into(), "main".into()]).is_none()
        );
        assert!(
            is_destructive_git_command(&["branch".into(), "-d".into(), "safe-delete".into()])
                .is_none()
        );
        assert!(is_destructive_git_command(&["clean".into(), "-n".into()]).is_none());
        assert!(is_destructive_git_command(&["restore".into(), "file.txt".into()]).is_none());
    }

    #[test]
    fn allows_destructive_git_bypass_and_override() {
        // Flag override
        assert!(is_destructive_git_command(&[
            "reset".into(),
            "--hard".into(),
            "--allow-destructive-git".into()
        ])
        .is_none());

        // Env var override
        env::set_var("VETTO_ALLOW_DESTRUCTIVE_GIT", "1");
        assert!(is_destructive_git_command(&["reset".into(), "--hard".into()]).is_none());
        assert!(is_destructive_git_command(&["clean".into(), "-fd".into()]).is_none());
        assert!(is_destructive_git_command(&["push".into(), "--force".into()]).is_none());
        env::remove_var("VETTO_ALLOW_DESTRUCTIVE_GIT");
    }

    #[test]
    fn parse_shim_args_timeout_extraction() {
        let args = vec![
            "--timeout".to_string(),
            "45s".to_string(),
            "status".to_string(),
            "--no-loop-guard".to_string(),
        ];
        let (allow_override, no_loop_guard, timeout, clean) = parse_shim_args(&args);
        assert!(!allow_override);
        assert!(no_loop_guard);
        assert_eq!(timeout, Some(std::time::Duration::from_secs(45)));
        assert_eq!(clean, vec!["status".to_string()]);

        let args_eq = vec!["--timeout=2m".to_string(), "commit".to_string()];
        let (_, _, timeout_eq, clean_eq) = parse_shim_args(&args_eq);
        assert_eq!(timeout_eq, Some(std::time::Duration::from_secs(120)));
        assert_eq!(clean_eq, vec!["commit".to_string()]);
    }
}