travelagent 1.10.3

Agent-first TUI code review tool
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
use clap::Parser;

use crate::theme::{AppearanceArg, ThemeArg};

/// Agent-first TUI code review tool
#[derive(Parser, Debug)]
#[command(name = "trv", version, about = "Agent-first TUI code review tool")]
pub struct Cli {
    /// PR/MR number or URL to review (e.g., 123, https://github.com/owner/repo/pull/123)
    #[arg(conflicts_with_all = ["revisions", "working_tree", "path_filter", "file_path"])]
    pub pr: Option<String>,

    /// Show a picker listing open PRs in the current repo; select one to review
    #[arg(
        short = 'l',
        long = "list",
        conflicts_with_all = ["pr", "revisions", "working_tree", "path_filter", "file_path", "tour", "demo"]
    )]
    pub list: bool,

    /// Color theme to use
    #[arg(long, value_enum)]
    pub theme: Option<ThemeArg>,

    /// Appearance mode for default theme (used when no explicit theme is set)
    #[arg(long, value_enum)]
    pub appearance: Option<AppearanceArg>,

    /// Output to stdout instead of clipboard when exporting
    #[arg(long = "stdout")]
    pub output_to_stdout: bool,

    /// Skip checking for updates on startup
    #[arg(long)]
    pub no_update_check: bool,

    /// Commit range/Revset to review (syntax depends on VCS backend)
    #[arg(short = 'r', long, conflicts_with = "file_path")]
    pub revisions: Option<String>,

    /// Include uncommitted changes (skip commit selector when used alone,
    /// combine with commits when used with -r)
    #[arg(short = 'w', long = "working-tree", conflicts_with = "file_path")]
    pub working_tree: bool,

    /// Filter diff to a specific file or directory path
    #[arg(short = 'p', long = "path", conflicts_with = "file_path")]
    pub path_filter: Option<String>,

    /// Open a file for annotation (no VCS required)
    #[arg(long = "file")]
    pub file_path: Option<String>,

    /// Run an MCP server on stdin/stdout alongside the TUI so an LLM agent can
    /// drive the same review session the human is watching. TUI renders to /dev/tty.
    #[arg(long = "mcp-alongside", conflicts_with = "output_to_stdout")]
    pub mcp_alongside: bool,

    /// Run an MCP server on a Unix-domain socket alongside the TUI so an agent
    /// can attach to the running session later via `trv --attach <path>`. Pass
    /// a path to override the default `$XDG_STATE_HOME/travelagent/sessions/<pid>.sock`.
    /// Accepts bare `--mcp-socket` (default path) or `--mcp-socket=<path>`.
    #[arg(
        long = "mcp-socket",
        num_args = 0..=1,
        default_missing_value = "",
        conflicts_with_all = ["output_to_stdout", "mcp_alongside", "attach"]
    )]
    pub mcp_socket: Option<String>,

    /// Attach stdin/stdout to a running `trv --mcp-socket` session. Argument is
    /// either a socket path or a PID whose default socket path is derived.
    /// Exits 0 when the socket closes cleanly; non-zero on connect failure.
    #[arg(
        long = "attach",
        conflicts_with_all = ["pr", "revisions", "working_tree", "path_filter", "file_path", "mcp_alongside", "mcp_socket", "tour", "demo", "list"]
    )]
    pub attach: Option<String>,

    /// Start Tour Guide mode on the given revset. Resolves the revset and
    /// preloads a default plan (one commit per stop). An agent connected via
    /// --mcp-alongside can refine the plan with trv_tour_set_plan.
    #[arg(
        long = "tour",
        conflicts_with_all = ["pr", "working_tree", "path_filter", "file_path", "revisions"]
    )]
    pub tour: Option<String>,

    /// Launch the TUI with a plausible mock remote PR so the remote review
    /// UX can be explored without hitting GitHub/GitLab. No network calls.
    #[arg(
        long,
        conflicts_with_all = ["pr", "working_tree", "path_filter", "file_path", "revisions", "tour"]
    )]
    pub demo: bool,

    /// Generate shell completions and print to stdout (bash|zsh|fish|powershell|elvish)
    #[arg(long = "completions", value_enum, hide = true)]
    pub completions: Option<clap_complete::Shell>,

    /// Enable live review mode: watch the repo root and rebuild the diff
    /// when files change on disk. Equivalent to issuing `:live` mid-session.
    #[arg(long = "live")]
    pub live: bool,

    /// Disable risk-colored diff borders. By default, file and hunk headers
    /// are tinted green/yellow/red by their computed risk band (Phase F).
    /// Pass this for a monochrome UI — useful for colorblind users or anyone
    /// who prefers the plain look.
    #[arg(long = "no-risk-colors")]
    pub no_risk_colors: bool,

    /// Run session GC and exit (bypasses TUI launch). Applies the
    /// `[session_gc]` config section with any `--gc-*` overrides and prints
    /// a scanned / removed / remaining summary.
    #[arg(
        long = "session-gc",
        conflicts_with_all = ["pr", "revisions", "file_path", "tour", "demo", "list", "mcp_alongside", "mcp_socket", "attach", "working_tree", "path_filter", "live"]
    )]
    pub session_gc: bool,

    /// Print what `--session-gc` would remove without deleting anything.
    #[arg(long = "gc-dry-run", requires = "session_gc")]
    pub gc_dry_run: bool,

    /// Override `[session_gc].max_age_days` for this invocation. `0` disables
    /// the age bound.
    #[arg(long = "gc-max-age-days", requires = "session_gc")]
    pub gc_max_age_days: Option<u64>,

    /// Override `[session_gc].max_size_mb` for this invocation. `0` disables
    /// the size bound.
    #[arg(long = "gc-max-size-mb", requires = "session_gc")]
    pub gc_max_size_mb: Option<u64>,

    /// Override `[session_gc].max_count` for this invocation. `0` disables
    /// the count bound.
    #[arg(long = "gc-max-count", requires = "session_gc")]
    pub gc_max_count: Option<u64>,

    /// Phase I3: hide paths matching `hidden_from_reviewer` in
    /// `.travelagent/review.toml` from the diff view. Toggleable at
    /// runtime with the `:unblind` slash command. When the config
    /// patterns list is empty this flag is a no-op but surfaces a
    /// warning at startup so reviewers notice the misconfiguration
    /// rather than silently seeing everything.
    #[arg(long = "blind-tests")]
    pub blind_tests: bool,

    /// Phase I1 (scaffold): enter Sparring Review mode. Today this
    /// flips a flag and surfaces a `[spar]` status-bar glyph — no
    /// branch management, no commit trailers, no panel wiring yet.
    /// Those land in a follow-up once the VCS trait grows the
    /// branch-creation surface needed to host them. The flag is
    /// intentionally shipped early so downstream work (I4 spec-to-test,
    /// I5 reconciliation, I6 surfacing) has a stable entry point to
    /// gate on.
    #[arg(long = "spar")]
    pub spar: bool,
}

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

    fn parse(args: &[&str]) -> Result<Cli, clap::Error> {
        Cli::try_parse_from(args)
    }

    #[test]
    fn should_parse_theme_when_provided() {
        let cli = parse(&["trv", "--theme", "light"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::Light));
    }

    #[test]
    fn should_parse_catppuccin_themes() {
        let cli = parse(&["trv", "--theme", "catppuccin-mocha"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::CatppuccinMocha));

        let cli = parse(&["trv", "--theme=catppuccin-latte"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::CatppuccinLatte));
    }

    #[test]
    fn should_parse_ayu_light_theme() {
        let cli = parse(&["trv", "--theme", "ayu-light"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::AyuLight));
    }

    #[test]
    fn should_parse_onedark_theme() {
        let cli = parse(&["trv", "--theme", "onedark"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::Onedark));
    }

    #[test]
    fn should_parse_gruvbox_themes() {
        let cli = parse(&["trv", "--theme", "gruvbox-dark"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::GruvboxDark));

        let cli = parse(&["trv", "--theme=gruvbox-light"]).expect("parse should succeed");
        assert_eq!(cli.theme, Some(ThemeArg::GruvboxLight));
    }

    #[test]
    fn should_leave_theme_none_when_not_provided() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert_eq!(cli.theme, None);
    }

    #[test]
    fn should_parse_working_tree_short_flag() {
        let cli = parse(&["trv", "-w"]).expect("parse should succeed");
        assert!(cli.working_tree);
    }

    #[test]
    fn should_parse_working_tree_long_flag() {
        let cli = parse(&["trv", "--working-tree"]).expect("parse should succeed");
        assert!(cli.working_tree);
    }

    #[test]
    fn should_default_working_tree_to_false() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.working_tree);
    }

    #[test]
    fn should_parse_working_tree_with_revisions() {
        let cli = parse(&["trv", "-w", "-r", "HEAD~3..HEAD"]).expect("parse should succeed");
        assert!(cli.working_tree);
        assert_eq!(cli.revisions, Some("HEAD~3..HEAD".to_string()));
    }

    #[test]
    fn should_error_for_invalid_theme() {
        let err = parse(&["trv", "--theme", "nope"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("nope"),
            "error should mention invalid value: {msg}"
        );
    }

    #[test]
    fn should_parse_appearance_when_provided() {
        let cli = parse(&["trv", "--appearance", "system"]).expect("parse should succeed");
        assert_eq!(cli.appearance, Some(AppearanceArg::System));
    }

    #[test]
    fn should_error_for_invalid_appearance() {
        let err = parse(&["trv", "--appearance", "nope"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("nope"),
            "error should mention invalid value: {msg}"
        );
    }

    #[test]
    fn should_parse_path_short_flag() {
        let cli = parse(&["trv", "-p", "src/main.rs"]).expect("parse should succeed");
        assert_eq!(cli.path_filter, Some("src/main.rs".to_string()));
    }

    #[test]
    fn should_parse_path_long_flag() {
        let cli = parse(&["trv", "--path", "src/"]).expect("parse should succeed");
        assert_eq!(cli.path_filter, Some("src/".to_string()));
    }

    #[test]
    fn should_parse_path_equals_syntax() {
        let cli = parse(&["trv", "--path=plans/current-plan.md"]).expect("parse should succeed");
        assert_eq!(cli.path_filter, Some("plans/current-plan.md".to_string()));
    }

    #[test]
    fn should_default_path_filter_to_none() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert_eq!(cli.path_filter, None);
    }

    #[test]
    fn should_parse_path_with_working_tree() {
        let cli = parse(&["trv", "-p", "file.md", "-w"]).expect("parse should succeed");
        assert_eq!(cli.path_filter, Some("file.md".to_string()));
        assert!(cli.working_tree);
    }

    #[test]
    fn should_parse_path_with_revisions() {
        let cli =
            parse(&["trv", "--path", "src/", "-r", "HEAD~3.."]).expect("parse should succeed");
        assert_eq!(cli.path_filter, Some("src/".to_string()));
        assert_eq!(cli.revisions, Some("HEAD~3..".to_string()));
    }

    #[test]
    fn should_reject_pr_with_revisions() {
        let err = parse(&["trv", "123", "-r", "HEAD~3"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_reject_pr_with_working_tree() {
        let err = parse(&["trv", "123", "-w"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_reject_pr_with_path_filter() {
        let err = parse(&["trv", "123", "-p", "src/"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_reject_pr_with_file() {
        let err = parse(&["trv", "123", "--file", "a.rs"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_reject_file_with_path() {
        let err =
            parse(&["trv", "--file", "a.rs", "--path", "src/"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_reject_file_with_revisions() {
        let err =
            parse(&["trv", "--file", "a.rs", "-r", "HEAD~3.."]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_reject_file_with_working_tree() {
        let err = parse(&["trv", "--file", "a.rs", "-w"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_parse_mcp_alongside() {
        let cli = parse(&["trv", "--mcp-alongside"]).expect("parse should succeed");
        assert!(cli.mcp_alongside);
    }

    #[test]
    fn should_reject_mcp_alongside_with_stdout() {
        let err = parse(&["trv", "--mcp-alongside", "--stdout"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("cannot be used with"),
            "error should mention conflict: {msg}"
        );
    }

    #[test]
    fn should_parse_tour_flag() {
        let cli = parse(&["trv", "--tour", "HEAD~5..HEAD"]).expect("parse should succeed");
        assert_eq!(cli.tour.as_deref(), Some("HEAD~5..HEAD"));
    }

    #[test]
    fn should_reject_tour_with_revisions() {
        let err =
            parse(&["trv", "--tour", "HEAD~3..", "-r", "HEAD~5.."]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_tour_with_pr() {
        let err = parse(&["trv", "--tour", "HEAD~3..", "123"]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_tour_with_working_tree() {
        let err = parse(&["trv", "--tour", "HEAD~3..", "-w"]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_parse_demo_flag() {
        let cli = parse(&["trv", "--demo"]).expect("parse should succeed");
        assert!(cli.demo);
    }

    #[test]
    fn should_default_demo_to_false() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.demo);
    }

    #[test]
    fn should_reject_demo_with_pr() {
        let err = parse(&["trv", "--demo", "123"]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_demo_with_working_tree() {
        let err = parse(&["trv", "--demo", "-w"]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_demo_with_path_filter() {
        let err = parse(&["trv", "--demo", "-p", "src/"]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_demo_with_file() {
        let err = parse(&["trv", "--demo", "--file", "a.rs"]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_demo_with_revisions() {
        let err = parse(&["trv", "--demo", "-r", "HEAD~3.."]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_reject_demo_with_tour() {
        let err = parse(&["trv", "--demo", "--tour", "HEAD~3.."]).expect_err("parse should fail");
        assert!(err.to_string().contains("cannot be used with"));
    }

    #[test]
    fn should_parse_completions_shell() {
        let cli = parse(&["trv", "--completions", "zsh"]).expect("parse should succeed");
        assert_eq!(cli.completions, Some(clap_complete::Shell::Zsh));
    }

    #[test]
    fn should_default_completions_to_none() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert_eq!(cli.completions, None);
    }

    #[test]
    fn should_default_live_to_false() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.live);
    }

    #[test]
    fn should_parse_live_flag() {
        let cli = parse(&["trv", "--live"]).expect("parse should succeed");
        assert!(cli.live);
    }

    #[test]
    fn should_default_no_risk_colors_to_false() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.no_risk_colors);
    }

    #[test]
    fn should_parse_no_risk_colors_flag() {
        let cli = parse(&["trv", "--no-risk-colors"]).expect("parse should succeed");
        assert!(cli.no_risk_colors);
    }

    // ── Phase G: --session-gc flags ──

    #[test]
    fn should_parse_session_gc_with_overrides_and_dry_run() {
        let cli = parse(&["trv", "--session-gc", "--gc-max-count", "5", "--gc-dry-run"])
            .expect("parse should succeed");
        assert!(cli.session_gc);
        assert!(cli.gc_dry_run);
        assert_eq!(cli.gc_max_count, Some(5));
        assert_eq!(cli.gc_max_age_days, None);
        assert_eq!(cli.gc_max_size_mb, None);
    }

    #[test]
    fn should_default_session_gc_flags_to_false_or_none() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.session_gc);
        assert!(!cli.gc_dry_run);
        assert_eq!(cli.gc_max_age_days, None);
        assert_eq!(cli.gc_max_size_mb, None);
        assert_eq!(cli.gc_max_count, None);
    }

    #[test]
    fn should_reject_session_gc_with_pr() {
        let err = parse(&["trv", "--session-gc", "123"]).expect_err("parse should fail");
        assert!(
            err.to_string().contains("cannot be used with"),
            "error should mention conflict: {err}"
        );
    }

    #[test]
    fn should_reject_session_gc_with_tui_session_flags() {
        // --session-gc is a standalone maintenance mode; combining it with
        // flags that only make sense once the TUI launches (working_tree,
        // path_filter, live) should fail at parse time rather than silently
        // ignore them.
        for combo in [
            &["trv", "--session-gc", "-w"][..],
            &["trv", "--session-gc", "-p", "src/"][..],
            &["trv", "--session-gc", "--live"][..],
        ] {
            let err = parse(combo).expect_err("parse should fail");
            assert!(
                err.to_string().contains("cannot be used with"),
                "error should mention conflict for {combo:?}: {err}"
            );
        }
    }

    #[test]
    fn should_reject_gc_dry_run_without_session_gc() {
        let err = parse(&["trv", "--gc-dry-run"]).expect_err("parse should fail");
        let msg = err.to_string();
        assert!(
            msg.contains("--session-gc"),
            "error should mention the --session-gc requirement: {msg}"
        );
    }

    #[test]
    fn should_reject_gc_max_count_without_session_gc() {
        let err = parse(&["trv", "--gc-max-count", "5"]).expect_err("parse should fail");
        assert!(err.to_string().contains("--session-gc"));
    }

    // ── Man page generation ──
    //
    // Generates a roff-format man page from the same `clap::Command` the
    // binary parses. Two modes:
    //
    // - Default (every `cargo test` run): generates into a byte buffer and
    //   asserts non-empty + contains expected section headers. This catches
    //   regressions where a new flag is added without a help string.
    // - `TRV_GEN_MANPAGE=1`: also writes the result to `docs/trv.1.gen` so
    //   packagers / distros can pick it up. The filename ends in `.gen` to
    //   make it clear it's generated (not hand-maintained).

    #[test]
    fn generate_manpage_from_clap_command() {
        use clap::CommandFactory;
        let cmd = Cli::command();
        let man = clap_mangen::Man::new(cmd);
        let mut buf: Vec<u8> = Vec::new();
        man.render(&mut buf).expect("render man page");
        let text = String::from_utf8(buf).expect("man page is valid UTF-8");

        assert!(!text.is_empty(), "man page must not be empty");
        assert!(
            text.contains(".TH"),
            "man page must carry a title-header directive (.TH)"
        );
        assert!(
            text.contains("trv"),
            "man page must reference the binary name"
        );
        assert!(
            text.contains("NAME") || text.contains(".SH"),
            "man page must have section headers"
        );

        // Optional: persist for packagers when explicitly requested.
        if std::env::var("TRV_GEN_MANPAGE").as_deref() == Ok("1") {
            let target = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
                .parent()
                .and_then(|p| p.parent())
                .map(|repo| repo.join("docs").join("trv.1.gen"))
                .expect("resolve docs/trv.1.gen path");
            std::fs::write(&target, &text).expect("write generated man page to docs/trv.1.gen");
            eprintln!("trv: wrote man page to {}", target.display());
        }
    }

    // ── --blind-tests (Phase I3b) ──

    #[test]
    fn should_parse_blind_tests_flag() {
        let cli = parse(&["trv", "--blind-tests"]).expect("parse should succeed");
        assert!(cli.blind_tests);
    }

    #[test]
    fn should_default_blind_tests_to_false() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.blind_tests);
    }

    // ── --spar (Phase I1a) ──

    #[test]
    fn should_parse_spar_flag() {
        let cli = parse(&["trv", "--spar"]).expect("parse should succeed");
        assert!(cli.spar);
    }

    #[test]
    fn should_default_spar_to_false() {
        let cli = parse(&["trv"]).expect("parse should succeed");
        assert!(!cli.spar);
    }
}