agent-loadout 1.0.0

Loadout CLI: manage MCP servers, skills and secret references for AI coding clients
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
//! `loadout scanner ...` and `skills add|update --external/--no-external`
//! (#30) against a temp `LOADOUT_HOME`, with the `skillspector-stub`
//! copied as `uvx`, `uv` or `skillspector` into the temp `bin` folder, the
//! first `PATH` entry of the command (the only one, unless a test needs
//! git): detection, Prepare, the switch, scans of library skills, installs
//! and updates for each kind of report, the gate, and what reaches the
//! scanner (its log). `scanner remove` still cleans up a 0.7.0 Snyk Agent
//! Scan install (a fake install folder and settings table).
//! `scanner setup` downloads a test uv archive (the stub as `uv`/`uvx`,
//! served from a local file through `LOADOUT_TEST_UV_ARCHIVE`).

use std::path::{Path, PathBuf};
use std::process::Output;

use agent_loadout_core::brand;
use agent_loadout_core::paths::{HomeSource, LoadoutHome};
use agent_loadout_testkit::TempHome;
use agent_loadout_testkit::git_env::{git_vars, init_bare, system_git_or_skip};
use agent_loadout_testkit::skillspector_stub::{self, SkillSpectorStub, StubConfig, output};
use serde_json::Value;

const SKILL: &str = "---\nname: tidy\ndescription: Tidies.\n---\n\n# Tidy\n\nSort the imports.\n";

/// Variables a user may have set that must never reach SkillSpector.
const PROVIDER_KEYS: &[(&str, &str)] = &[
    ("OPENAI_API_KEY", "sk-openai-cli-test-1"),
    ("ANTHROPIC_API_KEY", "sk-ant-cli-test-2"),
    ("NVIDIA_API_KEY", "nvapi-cli-test-3"),
    ("AWS_SECRET_ACCESS_KEY", "aws-cli-test-4"),
    ("GOOGLE_API_KEY", "google-cli-test-5"),
    ("LANGSMITH_API_KEY", "ls-cli-test-6"),
    ("LANGSMITH_TRACING", "true"),
    ("LANGCHAIN_API_KEY", "lc-cli-test-7"),
    ("SKILLSPECTOR_LLM_PROVIDER", "openai"),
];

struct Cli {
    th: TempHome,
    home: PathBuf,
    stub: SkillSpectorStub,
    /// The system git, for the tests that need one (then also on `PATH`,
    /// after the stub's `bin`).
    git: Option<PathBuf>,
    /// The test uv archive `scanner setup` "downloads", when a test makes one.
    uv_archive: Option<PathBuf>,
}

impl Cli {
    /// Nothing on `PATH` yet.
    fn new() -> Self {
        let th = TempHome::new();
        let home = th.root().join("lh");
        let stub = SkillSpectorStub::new(th.root());
        assert_eq!(stub.bin(), th.bin());
        Self {
            th,
            home,
            stub,
            git: None,
            uv_archive: None,
        }
    }

    /// uvx on `PATH`, SkillSpector already downloaded: ready (uvx).
    fn ready() -> Self {
        let cli = Self::new();
        cli.stub.add("uvx");
        cli.stub.set_prepared(true);
        cli
    }

    fn loadout_home(&self) -> LoadoutHome {
        LoadoutHome {
            path: self.home.clone(),
            source: HomeSource::Flag,
            sync_root: None,
        }
    }

    fn run_with(&self, args: &[&str], vars: &[(&str, &str)]) -> Output {
        let mut command = self.th.command(env!("CARGO_BIN_EXE_loadout"));
        if let Some(git) = &self.git {
            command.envs(git_vars(&self.th, git));
        }
        if let Some(archive) = &self.uv_archive {
            command.env(brand::TEST_UV_ARCHIVE_ENV_VAR, archive);
        }
        command
            .envs(vars.iter().copied())
            .arg("--home")
            .arg(&self.home)
            .args(args)
            .output()
            .expect("run loadout")
    }

    fn run(&self, args: &[&str]) -> Output {
        self.run_with(args, &[])
    }

    /// Exit code, stdout and stderr of a human-readable run.
    fn text(&self, args: &[&str]) -> (i32, String, String) {
        let output = self.run(args);
        (
            output.status.code().unwrap(),
            String::from_utf8_lossy(&output.stdout).into_owned(),
            String::from_utf8_lossy(&output.stderr).into_owned(),
        )
    }

    fn json_with(&self, args: &[&str], vars: &[(&str, &str)]) -> (i32, Value, String) {
        let output = self.run_with(&[&["--json"], args].concat(), vars);
        let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
        let doc = serde_json::from_slice(&output.stdout).unwrap_or_else(|err| {
            panic!(
                "{args:?}: stdout is not JSON ({err}):\n{}\nstderr:\n{stderr}",
                String::from_utf8_lossy(&output.stdout),
            )
        });
        (output.status.code().unwrap(), doc, stderr)
    }

    fn json(&self, args: &[&str]) -> (i32, Value, String) {
        self.json_with(args, &[])
    }

    fn ok(&self, args: &[&str]) -> Value {
        let (code, doc, stderr) = self.json(args);
        assert_eq!(code, 0, "{args:?}: {doc:#}\n{stderr}");
        doc
    }

    fn fails(&self, args: &[&str], code: &str) -> Value {
        let (exit, doc, _) = self.json(args);
        assert_ne!(exit, 0, "{args:?}: {doc:#}");
        assert_eq!(doc["error"]["code"], code, "{args:?}: {doc:#}");
        doc
    }

    /// A skill folder to install.
    fn folder(&self, name: &str) -> String {
        let dir = self.th.root().join("src").join(name);
        std::fs::create_dir_all(&dir).unwrap();
        std::fs::write(dir.join("SKILL.md"), SKILL.replace("tidy", name)).unwrap();
        dir.to_string_lossy().into_owned()
    }

    /// A library skill, installed without the scanner.
    fn library_skill(&self, name: &str) {
        let doc = self.ok(&["skills", "add", &self.folder(name), "--no-external"]);
        assert!(doc.get("external").is_none(), "{doc:#}");
    }

    fn settings_text(&self) -> String {
        std::fs::read_to_string(self.home.join("state").join("local-settings.toml"))
            .unwrap_or_default()
    }

    /// Leaves a 0.7.0 Snyk Agent Scan install where 0.7.0 put it, turned
    /// on: its folder in `tools/` and its settings table.
    fn with_snyk_0_7_0(self) -> Self {
        let dir = self.snyk_dir().join("0.7.1");
        std::fs::create_dir_all(&dir).unwrap();
        std::fs::write(dir.join("agent-scan"), b"not a scanner").unwrap();
        std::fs::write(dir.join("installed.json"), b"{}").unwrap();
        let settings = self.home.join("state").join("local-settings.toml");
        std::fs::create_dir_all(settings.parent().unwrap()).unwrap();
        std::fs::write(
            settings,
            "schema = 1\n\n[snyk_agent_scan]\nenabled = true\ntoken = \"keyring://loadout/snyk\"\n",
        )
        .unwrap();
        self
    }

    /// `<home>/tools/snyk-agent-scan`.
    fn snyk_dir(&self) -> PathBuf {
        self.home.join("tools").join("snyk-agent-scan")
    }

    /// A test uv archive to set up from, and the stub handle over the
    /// private uv folder (`<home>/tools/uv`), configured with `config`.
    fn with_uv_archive(mut self, config: &StubConfig) -> (Self, SkillSpectorStub) {
        let dir = self.th.root().join("uv-release");
        std::fs::create_dir_all(&dir).unwrap();
        self.uv_archive = Some(skillspector_stub::uv_archive(&dir));
        let private = SkillSpectorStub::private(&self.loadout_home());
        private.set(config);
        (self, private)
    }

    fn private_uv_root(&self) -> PathBuf {
        self.home.join("tools").join("uv")
    }

    fn git(&self, cwd: &Path, args: &[&str]) {
        let git = self.git.as_ref().expect("a test with git");
        let status = self
            .th
            .command(git)
            .envs(git_vars(&self.th, git))
            .current_dir(cwd)
            .args(args)
            .status()
            .expect("run git");
        assert!(status.success(), "git {args:?} failed");
    }

    /// Commits `skill_md` as the work tree's `SKILL.md` and pushes it.
    fn push(&self, work: &Path, skill_md: &str, message: &str) {
        std::fs::write(work.join("SKILL.md"), skill_md).unwrap();
        self.git(work, &["add", "-A"]);
        self.git(work, &["commit", "--quiet", "-m", message]);
        self.git(work, &["push", "--quiet", "origin", "HEAD:main"]);
    }
}

fn skill_ids(cli: &Cli) -> Vec<String> {
    cli.ok(&["skills", "ls"])["skills"]
        .as_array()
        .unwrap()
        .iter()
        .filter_map(|skill| skill["id"].as_str().map(str::to_owned))
        .collect()
}

#[test]
fn the_scanner_and_its_flags_are_visible() {
    let cli = Cli::new();
    let (_, help, _) = cli.text(&["--help"]);
    assert!(help.contains("scanner"), "{help}");
    assert!(help.contains("SkillSpector"), "{help}");
    for command in ["add", "update"] {
        let (_, help, _) = cli.text(&["skills", command, "--help"]);
        assert!(help.contains("--external"), "{help}");
        assert!(help.contains("--no-external"), "{help}");
        assert!(help.contains("SkillSpector"), "{help}");
        assert!(!help.contains("Snyk"), "{help}");
    }
    let (_, help, _) = cli.text(&["scanner", "--help"]);
    for command in [
        "ls", "status", "prepare", "enable", "disable", "run", "remove",
    ] {
        assert!(help.contains(command), "{command}: {help}");
    }
    for hidden in ["install", "token"] {
        assert!(
            !help
                .lines()
                .any(|line| line.trim_start().starts_with(hidden)),
            "{help}"
        );
    }
}

#[test]
fn status_when_ready_through_uvx() {
    let cli = Cli::ready();
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["schema"], 1, "{doc:#}");
    assert_eq!(doc["name"], "skillspector", "{doc:#}");
    assert_eq!(doc["tested_version"], "2.13.7", "{doc:#}");
    assert_eq!(doc["python"], "3.13", "{doc:#}");
    assert_eq!(doc["availability"], "ready", "{doc:#}");
    assert_eq!(doc["runtime"], "uvx", "{doc:#}");
    let program = doc["program"].as_str().unwrap();
    assert!(
        program.ends_with(&format!("uvx{}", std::env::consts::EXE_SUFFIX)),
        "{doc:#}"
    );
    assert_eq!(doc["version"], "2.13.7", "{doc:#}");
    assert_eq!(doc["version_tested"], true, "{doc:#}");
    assert!(doc["note"].is_null(), "{doc:#}");
    assert_eq!(doc["enabled"], false, "{doc:#}");
    assert_eq!(doc["timeout_secs"], 120, "{doc:#}");
    assert!(
        doc["sends"].as_str().unwrap().contains("OSV.dev"),
        "{doc:#}"
    );
    assert!(doc["setup"].is_null(), "{doc:#}");
    assert_eq!(doc["snyk_installed"], false, "{doc:#}");
    // The probe ran offline.
    let probe = cli.stub.calls().pop().expect("a --version probe");
    assert!(probe.argv.iter().any(|arg| arg == "--offline"), "{probe:?}");
    assert!(probe.argv.iter().any(|arg| arg == "--version"), "{probe:?}");

    let (code, text, _) = cli.text(&["scanner", "status"]);
    assert_eq!(code, 0);
    assert!(text.contains("Runtime:   uvx ("), "{text}");
    assert!(
        text.contains("--from skillspector==2.13.7 skillspector"),
        "{text}"
    );
    assert!(text.contains("Turned on: no"), "{text}");
    assert!(text.contains("never uploads the skill"), "{text}");
}

#[test]
fn status_when_ready_on_path_with_an_untested_version() {
    let cli = Cli::new();
    cli.stub.add("skillspector");
    cli.stub.set(&StubConfig {
        version: "skillspector 2.14.0".to_owned(),
        ..StubConfig::default()
    });
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "ready", "{doc:#}");
    assert_eq!(doc["runtime"], "path", "{doc:#}");
    assert!(
        doc["program"].as_str().unwrap().contains("skillspector"),
        "{doc:#}"
    );
    assert_eq!(doc["version"], "2.14.0", "{doc:#}");
    assert_eq!(doc["version_tested"], false, "{doc:#}");
    assert_eq!(
        doc["note"], "SkillSpector 2.14.0 is not tested with this Loadout (tested: 2.13.7)",
        "{doc:#}"
    );
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(text.contains("Runtime:   on PATH ("), "{text}");
    assert!(text.contains("is not tested with this Loadout"), "{text}");
}

#[test]
fn status_when_it_needs_prepare_or_is_not_available() {
    let cli = Cli::new();
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "not_available", "{doc:#}");
    assert!(doc["runtime"].is_null(), "{doc:#}");
    assert!(doc["program"].is_null(), "{doc:#}");
    assert!(doc["version"].is_null(), "{doc:#}");
    assert_eq!(doc["version_tested"], true, "{doc:#}");
    assert!(doc["setup"].as_str().unwrap().contains("pipx"), "{doc:#}");
    let (code, text, _) = cli.text(&["scanner", "status"]);
    assert_eq!(code, 0);
    assert!(text.contains("Or set it up yourself"), "{text}");

    cli.stub.add("uvx");
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "needs_prepare", "{doc:#}");
    assert_eq!(doc["runtime"], "uvx", "{doc:#}");
    assert!(doc["program"].is_string(), "{doc:#}");
    assert!(doc["version"].is_null(), "{doc:#}");
    assert!(doc["setup"].is_null(), "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(text.contains("`loadout scanner prepare`"), "{text}");

    let doc = cli.ok(&["scanner", "ls"]);
    let scanners = doc["scanners"].as_array().unwrap();
    assert_eq!(scanners[0]["name"], "builtin", "{doc:#}");
    assert_eq!(scanners[1]["name"], "skillspector", "{doc:#}");
    assert_eq!(scanners[1]["availability"], "needs_prepare", "{doc:#}");
    assert_eq!(scanners[1]["enabled"], false, "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "ls"]);
    assert!(text.contains("skillspector   off"), "{text}");
}

#[test]
fn prepare_downloads_once_with_progress_on_stderr() {
    let cli = Cli::new();
    cli.stub.add("uvx");
    cli.stub.set(&StubConfig {
        prepare_lines: vec![
            "Downloading skillspector (1.2MiB)".to_owned(),
            "Installed 42 packages in 3s".to_owned(),
        ],
        ..StubConfig::default()
    });
    let (code, text, stderr) = cli.text(&["scanner", "prepare"]);
    assert_eq!(code, 0, "{text}\n{stderr}");
    assert!(stderr.contains("from PyPI"), "{stderr}");
    assert!(
        stderr.contains("  Downloading skillspector (1.2MiB)"),
        "{stderr}"
    );
    assert!(stderr.contains("  Installed 42 packages"), "{stderr}");
    assert!(
        text.contains("SkillSpector 2.13.7 is ready (uvx)"),
        "{text}"
    );
    assert!(text.contains("loadout scanner enable"), "{text}");
    assert!(cli.stub.prepared());
    // Prepare is the one call without --offline.
    let online: Vec<_> = cli
        .stub
        .calls()
        .into_iter()
        .filter(|call| !call.argv.iter().any(|arg| arg == "--offline"))
        .collect();
    assert_eq!(online.len(), 1, "{online:?}");
    assert_eq!(cli.ok(&["scanner", "status"])["availability"], "ready");

    // Again: answers at once, still ready.
    let doc = cli.ok(&["scanner", "prepare"]);
    assert_eq!(doc["prepared"], true, "{doc:#}");
    assert_eq!(doc["availability"], "ready", "{doc:#}");
}

#[test]
fn prepare_failures() {
    let cli = Cli::new();
    // Nothing on PATH: the setup text.
    let doc = cli.fails(&["scanner", "prepare"], "scanner_unavailable");
    assert!(
        doc["error"]["message"].as_str().unwrap().contains("pipx"),
        "{doc:#}"
    );
    // A skillspector on PATH, no uv: nothing to prepare.
    cli.stub.add("skillspector");
    let doc = cli.ok(&["scanner", "prepare"]);
    assert_eq!(doc["prepared"], false, "{doc:#}");
    assert_eq!(doc["runtime"], "path", "{doc:#}");
    let (code, text, _) = cli.text(&["scanner", "prepare"]);
    assert_eq!(code, 0);
    assert!(text.contains("nothing to prepare"), "{text}");

    // uv fails to download.
    let cli = Cli::new();
    cli.stub.add("uvx");
    cli.stub.set(&StubConfig {
        prepare_exit: 2,
        ..StubConfig::default()
    });
    let doc = cli.fails(&["scanner", "prepare"], "scanner_download_failed");
    assert!(
        doc["error"]["message"]
            .as_str()
            .unwrap()
            .contains("Failed to fetch"),
        "{doc:#}"
    );
    assert!(!cli.stub.prepared());
    assert_eq!(
        cli.ok(&["scanner", "status"])["availability"],
        "needs_prepare"
    );
}

#[test]
fn enable_and_disable() {
    let cli = Cli::new();
    let (code, text, _) = cli.text(&["scanner", "enable"]);
    assert_eq!(code, 0);
    assert!(text.contains("SkillSpector is on"), "{text}");
    assert!(text.contains("never uploads the skill"), "{text}");
    assert!(text.contains("Or set it up yourself"), "{text}");
    assert!(cli.settings_text().contains("[skillspector]"));

    cli.stub.add("uvx");
    let (_, text, _) = cli.text(&["scanner", "enable"]);
    assert!(text.contains("run `loadout scanner prepare`"), "{text}");

    cli.stub.set_prepared(true);
    let (_, text, _) = cli.text(&["scanner", "enable"]);
    assert!(!text.contains("prepare"), "{text}");
    assert!(!text.contains("Loadout doesn't install"), "{text}");

    let doc = cli.ok(&["scanner", "disable"]);
    assert_eq!(doc["enabled"], false, "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "disable"]);
    assert!(text.contains("SkillSpector is off"), "{text}");
    let doc = cli.ok(&["scanner", "enable"]);
    assert_eq!(doc["enabled"], true, "{doc:#}");
    assert_eq!(doc["availability"], "ready", "{doc:#}");
}

#[test]
fn run_is_refused_while_off() {
    let cli = Cli::ready();
    cli.library_skill("one");
    cli.fails(&["scanner", "run", "one"], "scanner_unavailable");
    assert!(cli.stub.scans().is_empty());
}

/// `scanner run` on a library skill, for each kind of report.
#[test]
fn run_on_a_library_skill() {
    let cli = Cli::ready();
    cli.library_skill("one");
    cli.ok(&["scanner", "enable"]);

    cli.stub.answer(&output("safe.json"), 0);
    let doc = cli.ok(&["scanner", "run", "one"]);
    assert_eq!(doc["id"], "one", "{doc:#}");
    let external = &doc["external"];
    assert_eq!(external["scanner"], "skillspector", "{doc:#}");
    assert_eq!(external["version"], "2.13.7", "{doc:#}");
    assert_eq!(external["status"], "scanned", "{doc:#}");
    assert!(external["reason"].is_null(), "{doc:#}");
    assert_eq!(external["verdict"], "clean", "{doc:#}");
    assert_eq!(external["incomplete"], false, "{doc:#}");
    let scan = cli.stub.scans().pop().expect("a scan");
    assert_eq!(scan.files, vec!["SKILL.md".to_owned()], "{scan:?}");
    assert_eq!(scan.stdin_bytes, 0, "{scan:?}");
    let (code, text, _) = cli.text(&["scanner", "run", "one"]);
    assert_eq!(code, 0);
    assert!(text.contains("SkillSpector: clean (0 findings)"), "{text}");

    // Dangerous: reported (exit 0), never gated here.
    cli.stub.answer(&output("do-not-install.json"), 1);
    let doc = cli.ok(&["scanner", "run", "one"]);
    assert_eq!(doc["external"]["verdict"], "dangerous", "{doc:#}");
    let (code, text, _) = cli.text(&["scanner", "run", "one"]);
    assert_eq!(code, 0);
    assert!(text.contains("SkillSpector: dangerous ("), "{text}");
    assert!(text.contains("--allow-dangerous"), "{text}");

    // Incomplete: never "clean".
    cli.stub.answer(&output("incomplete.json"), 1);
    let doc = cli.ok(&["scanner", "run", "one"]);
    assert_eq!(doc["external"]["incomplete"], true, "{doc:#}");
    assert!(
        doc["external"]["findings"]
            .as_array()
            .unwrap()
            .iter()
            .any(|finding| finding["rule"] == "incomplete"),
        "{doc:#}"
    );
    let (_, text, _) = cli.text(&["scanner", "run", "one"]);
    assert!(text.contains("SkillSpector: not fully scanned ("), "{text}");
    assert!(!text.contains("clean"), "{text}");

    // Not understood: no verdict, exit 1.
    for (fixture, exit) in [
        ("llm-requested.json", 0),
        ("execution-failed.json", 0),
        ("malformed.txt", 0),
    ] {
        cli.stub.answer(&output(fixture), exit);
        let (code, doc, _) = cli.json(&["scanner", "run", "one"]);
        assert_eq!(code, 1, "{fixture}: {doc:#}");
        assert_eq!(
            doc["external"]["status"], "not_understood",
            "{fixture}: {doc:#}"
        );
        assert!(doc["external"]["verdict"].is_null(), "{fixture}: {doc:#}");
    }
    let (code, text, _) = cli.text(&["scanner", "run", "one"]);
    assert_eq!(code, 1);
    assert!(
        text.contains("SkillSpector: scanner output not understood (version 2.13.7)"),
        "{text}"
    );

    // SkillSpector failed (exit 2): not scanned, exit 1.
    cli.stub.set(&StubConfig {
        exit: 2,
        stderr: Some("Error: something broke".to_owned()),
        ..StubConfig::default()
    });
    let (code, doc, _) = cli.json(&["scanner", "run", "one"]);
    assert_eq!(code, 1, "{doc:#}");
    assert_eq!(doc["external"]["status"], "not_scanned", "{doc:#}");
    assert_eq!(doc["external"]["reason"], "failed", "{doc:#}");
    assert!(doc["external"]["verdict"].is_null(), "{doc:#}");
    let (code, text, _) = cli.text(&["scanner", "run", "one"]);
    assert_eq!(code, 1);
    assert!(text.contains("SkillSpector: not scanned ("), "{text}");

    // Not prepared (uv lost its cache): not scanned, exit 1.
    cli.stub.set_prepared(false);
    let (code, doc, _) = cli.json(&["scanner", "run", "one"]);
    assert_eq!(code, 1, "{doc:#}");
    assert_eq!(doc["external"]["reason"], "not_prepared", "{doc:#}");

    let (code, doc, _) = cli.json(&["scanner", "run", "missing"]);
    assert_ne!(code, 0, "{doc:#}");
    assert!(doc["error"]["code"].is_string(), "{doc:#}");
}

/// A dangerous report blocks an install of a local folder unless
/// --allow-dangerous; a not-scanned one never blocks.
#[test]
fn a_dangerous_report_gates_skills_add() {
    let cli = Cli::ready();
    cli.ok(&["scanner", "enable"]);
    cli.stub.answer(&output("do-not-install-high.json"), 1);

    let (code, doc, stderr) = cli.json(&["skills", "add", &cli.folder("bad")]);
    assert_eq!(code, 8, "{doc:#}\n{stderr}");
    assert_eq!(doc["error"]["code"], "scan_blocked", "{doc:#}");
    assert!(
        doc["error"]["message"]
            .as_str()
            .unwrap()
            .starts_with("SkillSpector found"),
        "{doc:#}"
    );
    assert_eq!(doc["scan"]["verdict"], "clean", "{doc:#}");
    assert_eq!(doc["external"]["verdict"], "dangerous", "{doc:#}");
    assert!(
        doc["external"]["findings"]
            .as_array()
            .unwrap()
            .iter()
            .any(|finding| finding["rule"] == "DO_NOT_INSTALL"),
        "{doc:#}"
    );
    assert!(skill_ids(&cli).is_empty());

    let (code, text, stderr) = cli.text(&["skills", "add", &cli.folder("bad")]);
    assert_eq!(code, 8, "{text}\n{stderr}");
    assert!(text.contains("SkillSpector: dangerous ("), "{text}");
    assert!(stderr.contains("Running SkillSpector on bad"), "{stderr}");

    let doc = cli.ok(&["skills", "add", &cli.folder("bad"), "--allow-dangerous"]);
    assert_eq!(doc["skill"]["id"], "bad", "{doc:#}");
    assert_eq!(doc["external"]["verdict"], "dangerous", "{doc:#}");

    // Not prepared: reported, never blocks.
    cli.stub.set_prepared(false);
    let doc = cli.ok(&["skills", "add", &cli.folder("unprepared")]);
    assert_eq!(doc["external"]["status"], "not_scanned", "{doc:#}");
    assert_eq!(doc["external"]["reason"], "not_prepared", "{doc:#}");
    assert!(doc["external"]["verdict"].is_null(), "{doc:#}");
    let (code, text, _) = cli.text(&["skills", "add", &cli.folder("unprepared-2")]);
    assert_eq!(code, 0, "{text}");
    assert!(
        text.contains("SkillSpector: not scanned (SkillSpector is not downloaded yet"),
        "{text}"
    );
}

#[test]
fn incomplete_and_clean_installs_report_but_do_not_block() {
    let cli = Cli::ready();
    cli.ok(&["scanner", "enable"]);
    cli.stub.answer(&output("incomplete.json"), 1);
    let (code, text, stderr) = cli.text(&["skills", "add", &cli.folder("partial")]);
    assert_eq!(code, 0, "{text}\n{stderr}");
    assert!(text.contains("Added skill partial."), "{text}");
    assert!(text.contains("SkillSpector: not fully scanned ("), "{text}");

    cli.stub.answer(&output("caution.json"), 0);
    let doc = cli.ok(&["skills", "add", &cli.folder("careful")]);
    assert_eq!(doc["external"]["verdict"], "warning", "{doc:#}");
    assert_eq!(doc["external"]["incomplete"], false, "{doc:#}");
}

/// `--no-external` skips a turned-on scanner; `--external` runs a
/// turned-off one; off by default nothing runs.
#[test]
fn the_flags_override_the_switch() {
    let cli = Cli::ready();
    cli.stub.answer(&output("safe.json"), 0);
    let doc = cli.ok(&["skills", "add", &cli.folder("default-off")]);
    assert!(doc.get("external").is_none(), "{doc:#}");
    assert!(cli.stub.scans().is_empty());

    let doc = cli.ok(&["skills", "add", &cli.folder("asked"), "--external"]);
    assert_eq!(doc["external"]["status"], "scanned", "{doc:#}");
    assert_eq!(cli.stub.scans().len(), 1);

    cli.ok(&["scanner", "enable"]);
    let doc = cli.ok(&["skills", "add", &cli.folder("skipped"), "--no-external"]);
    assert!(doc.get("external").is_none(), "{doc:#}");
    assert_eq!(cli.stub.scans().len(), 1);

    let doc = cli.ok(&["skills", "add", &cli.folder("on")]);
    assert_eq!(doc["external"]["status"], "scanned", "{doc:#}");
    assert_eq!(cli.stub.scans().len(), 2);

    // Nothing on PATH: not available, never blocks.
    let cli = Cli::new();
    let doc = cli.ok(&["skills", "add", &cli.folder("nothing"), "--external"]);
    assert_eq!(doc["external"]["reason"], "not_available", "{doc:#}");
}

/// What the scan gets: the pinned offline argv, closed stdin, and no
/// provider key from Loadout's own environment.
#[test]
fn provider_keys_never_reach_the_scanner() {
    let cli = Cli::ready();
    cli.stub.answer(&output("safe.json"), 0);
    let (code, doc, stderr) = cli.json_with(
        &["skills", "add", &cli.folder("keys"), "--external"],
        PROVIDER_KEYS,
    );
    assert_eq!(code, 0, "{doc:#}\n{stderr}");
    assert_eq!(doc["external"]["status"], "scanned", "{doc:#}");
    let calls = cli.stub.calls();
    assert!(calls.iter().any(|call| call.is_scan()), "{calls:?}");
    for call in &calls {
        for (name, value) in PROVIDER_KEYS {
            let leaked = call.env.get(*name).is_some_and(|seen| seen == value);
            assert!(!leaked, "{name} reached {}: {:?}", call.program, call.argv);
            assert!(
                !call.env.values().any(|seen| seen == value),
                "{name}'s value reached {}",
                call.program
            );
        }
        assert_eq!(
            call.env.get("LANGSMITH_TRACING").map(String::as_str),
            Some("false")
        );
        assert_eq!(call.stdin_bytes, 0, "{call:?}");
    }
    let scan = calls.iter().find(|call| call.is_scan()).unwrap();
    let argv: Vec<&str> = scan.argv.iter().map(String::as_str).collect();
    assert_eq!(
        &argv[..argv.len() - 1],
        &[
            "--offline",
            "--python",
            "3.13",
            "--from",
            "skillspector==2.13.7",
            "skillspector",
            "scan",
            "--no-llm",
            "--format",
            "json",
            "--fail-on-incomplete",
            "--",
        ],
        "{argv:?}"
    );
}

/// Snyk Agent Scan's hidden `install` and `token` are gone (M54).
#[test]
fn install_and_token_are_gone() {
    let cli = Cli::ready();
    for args in [
        &["scanner", "install"][..],
        &["scanner", "token", "--clear"],
    ] {
        let (code, _, stderr) = cli.text(args);
        assert_eq!(code, 2, "{args:?}: {stderr}");
    }
}

/// `scanner remove` deletes a 0.7.0 install and its settings entry;
/// `status` says one remains until then.
#[test]
fn remove_cleans_up_a_0_7_0_snyk_install() {
    let cli = Cli::new().with_snyk_0_7_0();
    assert_eq!(cli.ok(&["scanner", "status"])["snyk_installed"], true);
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(text.contains("`loadout scanner remove`"), "{text}");
    let doc = cli.ok(&["scanner", "remove"]);
    assert_eq!(doc["removed"], true, "{doc:#}");
    assert_eq!(doc["snyk"], true, "{doc:#}");
    assert!(!cli.snyk_dir().exists());
    assert!(cli.home.join("tools").exists(), "only its own folder goes");
    assert_eq!(cli.ok(&["scanner", "status"])["snyk_installed"], false);
    let text = cli.settings_text();
    assert!(!text.contains("snyk_agent_scan"), "{text}");
    assert_eq!(cli.ok(&["scanner", "remove"])["removed"], false);
}

/// `skills update --external` on a git skill: a dangerous SkillSpector
/// report on the new content blocks the update (exit 8, the skill stays at
/// its commit) unless --allow-dangerous; not-understood and not-prepared
/// reports never block.
#[test]
fn skills_update_external_gates_a_dangerous_update() {
    let Some(git) = system_git_or_skip("skills_update_external_gates_a_dangerous_update") else {
        return;
    };
    let mut cli = Cli::ready();
    cli.git = Some(git.clone());
    let root = cli.th.root().to_path_buf();
    let bare = root.join("up.git");
    init_bare(&cli.th, &git, &bare);
    cli.git(&root, &["init", "--quiet", "--initial-branch=main", "work"]);
    let work = root.join("work");
    cli.git(&work, &["remote", "add", "origin", "../up.git"]);
    let version = |n: u32| format!("---\nname: alpha\ndescription: Alpha.\n---\n\n# Alpha v{n}\n");
    cli.push(&work, &version(1), "v1");
    let url = bare.to_string_lossy().into_owned();
    let doc = cli.ok(&["skills", "add", &url, "--trust-source=repo"]);
    assert!(doc.get("external").is_none(), "off by default: {doc:#}");
    let first = doc["skill"]["source_commit"].as_str().unwrap().to_owned();
    assert!(cli.stub.scans().is_empty());

    // v2: SkillSpector says do not install.
    cli.push(&work, &version(2), "v2");
    cli.stub.answer(&output("do-not-install.json"), 1);
    let (code, doc, stderr) = cli.json(&["skills", "update", "alpha", "--external"]);
    assert_eq!(code, 8, "{doc:#}\n{stderr}");
    let result = &doc["skills"][0];
    assert_eq!(result["status"], "blocked", "{doc:#}");
    assert_eq!(result["error"]["code"], "scan_blocked", "{doc:#}");
    assert_eq!(result["scan"]["verdict"], "clean", "{doc:#}");
    assert_eq!(result["external"]["scanner"], "skillspector", "{doc:#}");
    assert_eq!(result["external"]["verdict"], "dangerous", "{doc:#}");
    let scan = cli.stub.scans().pop().expect("the update was scanned");
    assert_eq!(scan.files, vec!["SKILL.md".to_owned()], "{scan:?}");
    // Not applied: still at the first commit, the update still available.
    let doc = cli.ok(&["skills", "update", "alpha", "--check", "--no-external"]);
    assert_eq!(doc["skills"][0]["status"], "available", "{doc:#}");
    assert_eq!(doc["skills"][0]["current"], first.as_str(), "{doc:#}");
    assert!(doc["skills"][0].get("external").is_none(), "{doc:#}");
    let (code, text, _) = cli.text(&["skills", "update", "alpha", "--external"]);
    assert_eq!(code, 8, "{text}");
    assert!(text.contains("SkillSpector: dangerous ("), "{text}");

    let doc = cli.ok(&[
        "skills",
        "update",
        "alpha",
        "--external",
        "--allow-dangerous",
    ]);
    let result = &doc["skills"][0];
    assert_eq!(result["status"], "updated", "{doc:#}");
    assert_eq!(result["external"]["verdict"], "dangerous", "{doc:#}");
    let second = result["to"].as_str().unwrap().to_owned();
    assert_ne!(second, first);

    // v3: output not understood; applies without the flag.
    cli.push(&work, &version(3), "v3");
    cli.stub.answer(&output("llm-requested.json"), 0);
    let doc = cli.ok(&["skills", "update", "alpha", "--external"]);
    let result = &doc["skills"][0];
    assert_eq!(result["status"], "updated", "{doc:#}");
    assert_eq!(result["external"]["status"], "not_understood", "{doc:#}");
    assert!(result["external"]["verdict"].is_null(), "{doc:#}");
    assert_ne!(result["to"], second.as_str(), "{doc:#}");

    // v4: uv lost the download (not prepared); applies without the flag.
    cli.push(&work, &version(4), "v4");
    cli.stub.answer(&output("do-not-install.json"), 1);
    cli.stub.set_prepared(false);
    let scans = cli.stub.scans().len();
    let doc = cli.ok(&["skills", "update", "alpha", "--external"]);
    let result = &doc["skills"][0];
    assert_eq!(result["status"], "updated", "{doc:#}");
    assert_eq!(result["external"]["status"], "not_scanned", "{doc:#}");
    assert_eq!(result["external"]["reason"], "not_prepared", "{doc:#}");
    assert_eq!(cli.stub.scans().len(), scans, "nothing ran");
    let doc = cli.ok(&["skills", "update", "alpha", "--check", "--no-external"]);
    assert_eq!(doc["skills"][0]["status"], "up_to_date", "{doc:#}");
}

/// `scanner setup` with nothing on PATH: the disclosure, the uv download's
/// progress, then uv's lines on stderr; ready through the private uv.
#[test]
fn setup_downloads_uv_then_prepares() {
    let (cli, private) = Cli::new().with_uv_archive(&StubConfig {
        prepare_lines: vec!["Installed 42 packages in 3s".to_owned()],
        ..StubConfig::default()
    });
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "not_available", "{doc:#}");
    assert_eq!(doc["setup_supported"], true, "{doc:#}");
    assert!(doc["private_uv"].is_null(), "{doc:#}");
    assert!(doc["uv_source"].is_null(), "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(text.contains("`loadout scanner setup`"), "{text}");

    let (code, text, stderr) = cli.text(&["scanner", "setup"]);
    assert_eq!(code, 0, "{text}\n{stderr}");
    assert!(
        stderr.starts_with("SkillSpector runs on this computer"),
        "{stderr}"
    );
    let download = stderr.find("Downloading uv from GitHub").expect(&stderr);
    let installed = stderr.find("  Installed 42 packages").expect(&stderr);
    assert!(download < installed, "{stderr}");
    assert!(stderr.contains(" MB\n"), "{stderr}");
    // Decimal MB, as the GUI and "about 16 MB".
    let size = std::fs::metadata(cli.uv_archive.as_ref().unwrap())
        .unwrap()
        .len();
    assert!(
        stderr.contains(&format!(
            "Downloading uv from GitHub ({:.1} MB)...",
            size as f64 / 1_000_000.0
        )),
        "{stderr}"
    );
    assert!(
        text.contains("is ready (uvx, uv installed by Loadout)"),
        "{text}"
    );
    assert!(text.contains("loadout scanner enable"), "{text}");
    assert!(private.prepared());
    assert!(cli.private_uv_root().is_dir());

    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "ready", "{doc:#}");
    assert_eq!(doc["uv_source"], "private", "{doc:#}");
    assert_eq!(doc["private_uv"], "0.13.10", "{doc:#}");
    assert_eq!(doc["private_uv_present"], true, "{doc:#}");
    assert_eq!(doc["enabled"], false, "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(
        text.contains("uv 0.13.10 installed by Loadout in its data folder; `loadout scanner remove` deletes it"),
        "{text}"
    );

    // Again, as JSON: nothing downloaded, still ready.
    let (code, doc, stderr) = cli.json(&["scanner", "setup"]);
    assert_eq!(code, 0, "{doc:#}\n{stderr}");
    assert_eq!(doc["set_up"], true, "{doc:#}");
    assert_eq!(doc["availability"], "ready", "{doc:#}");
    assert_eq!(doc["uv_source"], "private", "{doc:#}");
    assert!(!stderr.contains("Downloading uv"), "{stderr}");
}

/// uv on PATH: setup prepares with it and never downloads uv.
#[test]
fn setup_with_uv_on_path_does_not_download() {
    let (cli, _private) = Cli::new().with_uv_archive(&StubConfig::default());
    cli.stub.add("uvx");
    let (code, doc, stderr) = cli.json(&["scanner", "setup"]);
    assert_eq!(code, 0, "{doc:#}\n{stderr}");
    assert_eq!(doc["set_up"], true, "{doc:#}");
    assert_eq!(doc["uv_source"], "system", "{doc:#}");
    assert!(doc["private_uv"].is_null(), "{doc:#}");
    assert!(!stderr.contains("Downloading uv"), "{stderr}");
    assert!(cli.stub.prepared());
    assert!(!cli.private_uv_root().join("0.13.10").exists());
}

/// A ready skillspector on PATH and no uv: nothing to set up.
#[test]
fn setup_is_refused_when_skillspector_is_on_path() {
    let (cli, _private) = Cli::new().with_uv_archive(&StubConfig::default());
    cli.stub.add("skillspector");
    let doc = cli.fails(&["scanner", "setup"], "scanner_unavailable");
    assert!(
        doc["error"]["message"]
            .as_str()
            .unwrap()
            .contains("already set up"),
        "{doc:#}"
    );
    assert!(!cli.private_uv_root().join("0.13.10").exists());

    // Also with the private uv installed: the one on PATH runs.
    let (cli, _private) = Cli::new().with_uv_archive(&StubConfig::default());
    cli.ok(&["scanner", "setup"]);
    cli.stub.add("skillspector");
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "ready", "{doc:#}");
    assert_eq!(doc["runtime"], "path", "{doc:#}");
    assert!(doc["uv_source"].is_null(), "{doc:#}");
    assert_eq!(doc["private_uv"], "0.13.10", "{doc:#}");
    let doc = cli.fails(&["scanner", "setup"], "scanner_unavailable");
    assert!(
        doc["error"]["message"]
            .as_str()
            .unwrap()
            .contains("already set up"),
        "{doc:#}"
    );
}

/// No uv pinned for this platform (here: a test pin that cannot be read):
/// only the manual routes, in status and in prepare's error.
#[test]
fn without_setup_support_only_the_manual_routes_are_offered() {
    let mut cli = Cli::new();
    cli.uv_archive = Some(cli.th.root().join("no-such-uv.zip"));
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["availability"], "not_available", "{doc:#}");
    assert_eq!(doc["setup_supported"], false, "{doc:#}");
    let setup = doc["setup"].as_str().unwrap();
    assert!(
        setup.starts_with("Set it up yourself: install uv"),
        "{doc:#}"
    );
    assert!(!setup.contains("loadout scanner setup"), "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(text.contains("Set it up yourself: install uv"), "{text}");
    assert!(!text.contains("loadout scanner setup"), "{text}");
    let doc = cli.fails(&["scanner", "prepare"], "scanner_unavailable");
    let message = doc["error"]["message"].as_str().unwrap();
    assert!(
        message.contains("Set it up yourself: install uv"),
        "{doc:#}"
    );
    assert!(!message.contains("loadout scanner setup"), "{doc:#}");
    // With a pin (the test archive's), the whole text leads with Set up.
    let (cli, _private) = Cli::new().with_uv_archive(&StubConfig::default());
    let doc = cli.ok(&["scanner", "status"]);
    let setup = doc["setup"].as_str().unwrap();
    assert!(setup.contains("loadout scanner setup"), "{doc:#}");
    let doc = cli.fails(&["scanner", "prepare"], "scanner_unavailable");
    assert!(
        doc["error"]["message"]
            .as_str()
            .unwrap()
            .contains("loadout scanner setup"),
        "{doc:#}"
    );
}

/// A `tools/uv` without an installed uv (a failed or tampered setup, or a
/// leftover cache) is reported, and `remove` deletes it.
#[test]
fn a_leftover_private_uv_folder_is_reported_and_removed() {
    let (cli, _private) = Cli::new().with_uv_archive(&StubConfig::default());
    let root = cli.private_uv_root();
    std::fs::create_dir_all(root.join("cache")).unwrap();
    std::fs::write(root.join("cache").join("f"), b"x").unwrap();
    let doc = cli.ok(&["scanner", "status"]);
    assert!(doc["private_uv"].is_null(), "{doc:#}");
    assert_eq!(doc["private_uv_present"], true, "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "status"]);
    assert!(
        text.contains("an incomplete uv setup remains in Loadout's data folder"),
        "{text}"
    );
    let doc = cli.ok(&["scanner", "remove"]);
    assert_eq!(doc["private_uv"], true, "{doc:#}");
    assert!(!root.exists());
    let doc = cli.ok(&["scanner", "status"]);
    assert_eq!(doc["private_uv_present"], false, "{doc:#}");
}

/// `scanner remove` deletes the private uv with its cache and Python, and
/// a 0.7.0 Snyk install, saying what it removed.
#[test]
fn remove_deletes_the_private_uv_and_snyk() {
    let (cli, _private) = Cli::new()
        .with_snyk_0_7_0()
        .with_uv_archive(&StubConfig::default());
    cli.ok(&["scanner", "setup"]);
    let root = cli.private_uv_root();
    for folder in ["cache", "python"] {
        std::fs::create_dir_all(root.join(folder)).unwrap();
        std::fs::write(root.join(folder).join("f"), b"x").unwrap();
    }
    let (code, text, stderr) = cli.text(&["scanner", "remove"]);
    assert_eq!(code, 0, "{text}\n{stderr}");
    assert!(text.contains("Removed the uv Loadout installed"), "{text}");
    assert!(text.contains("Removed Snyk Agent Scan"), "{text}");
    assert!(!root.exists());
    let doc = cli.ok(&["scanner", "status"]);
    assert!(doc["private_uv"].is_null(), "{doc:#}");
    assert_eq!(doc["private_uv_present"], false, "{doc:#}");
    assert_eq!(doc["snyk_installed"], false, "{doc:#}");
    assert_eq!(doc["availability"], "not_available", "{doc:#}");
    let doc = cli.ok(&["scanner", "remove"]);
    assert_eq!(doc["removed"], false, "{doc:#}");
    assert_eq!(doc["private_uv"], false, "{doc:#}");
    let (_, text, _) = cli.text(&["scanner", "remove"]);
    assert!(text.contains("Nothing to remove."), "{text}");
}