croft-software 0.2.232

VSCode-style TUI written in Rust
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
//! Extensions: enabling, consent, uninstalling and recommendations.

use super::*;

/// One consent per extension, read from one place (#485 review): the sidecar
/// gate consults the same session set the viewer gate does, so allowing an
/// extension through either gate satisfies the other in the same session,
/// whatever became of the prefs write. And a prefs write that fails is
/// reported before the command's own argument prompt takes the screen.
#[test]
fn the_sidecar_gate_reads_the_session_consent_set() {
    use crate::widgets::input_prompt::InputPurpose;
    const EXT: &str = r#"
id = "tconsent"
name = "tconsent"
api_version = 1
[[mcp_servers]]
id = "srv"
command = "/bin/false"
[[commands]]
id = "tconsent.go"
title = "tconsent: go"
server = "srv"
tool = "go"
arg = "q"
prompt = "Query"
"#;
    let (_scratch, croft) = scratch_config(&[("tconsent", EXT)]);
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    app.consented_extensions = consent_on_disk(&croft);
    // Allowed this session, not (yet) on disk: the gate must not re-prompt,
    // it must move on to the command's own argument prompt.
    app.consented_extensions.insert("tconsent".into());
    app.run_extension_command("tconsent.go");
    assert!(
        matches!(
            app.input_prompt.as_ref().map(|p| &p.purpose),
            Some(InputPurpose::McpArg { .. })
        ),
        "a consented extension goes straight to its argument prompt, not consent: {:?}",
        app.input_prompt.as_ref().map(|p| p.title.clone())
    );
    // Allowing through the sidecar prompt with the prefs file unwritable: the
    // failure is reported where the user can see it and the grant holds.
    app.close_input_prompt();
    app.consented_extensions.remove("tconsent");
    std::fs::create_dir_all(croft.join("config.json")).unwrap();
    app.run_extension_command("tconsent.go");
    assert!(
        matches!(
            app.input_prompt.as_ref().map(|p| &p.purpose),
            Some(InputPurpose::McpConsent { .. })
        ),
        "fixture: an unconsented extension is asked first"
    );
    app.submit_input_prompt();
    assert!(
        app.status.contains("could not be saved"),
        "a failed prefs write is reported: {:?}",
        app.status
    );
    assert!(
        matches!(
            app.input_prompt.as_ref().map(|p| &p.purpose),
            Some(InputPurpose::McpArg { .. })
        ),
        "and the command went on to its argument prompt"
    );
    assert!(
        app.consented_extensions.contains("tconsent"),
        "the session grant holds"
    );
}

/// #2920: a reload follows the consents the settings file lists. One put in
/// the file applies; one taken out asks again at the next open or command.
/// A grant whose save failed was never in the file, so a reload leaves it
/// for the session.
#[test]
fn a_reload_follows_the_extension_consents_in_the_settings_file() {
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.consented_extensions.insert("unsaved".into());
    let mut file = app.applied_settings.clone();
    file.mcp_consented.insert("listed".into());
    app.apply_merged_settings(&file);
    assert!(
        app.consented_extensions.contains("listed"),
        "a consent put in the file applies: {:?}",
        app.consented_extensions
    );
    file.mcp_consented.remove("listed");
    app.apply_merged_settings(&file);
    assert!(
        !app.consented_extensions.contains("listed"),
        "a consent taken out of the file is gone: {:?}",
        app.consented_extensions
    );
    assert!(
        app.consented_extensions.contains("unsaved"),
        "a session grant the file never held stays"
    );
}

/// An extension whose command asks for its first-run consent, for the
/// consent tests below.
const CONSENT_EXT: &str = r#"
id = "tconsent"
name = "tconsent"
api_version = 1
[[mcp_servers]]
id = "srv"
command = "/bin/false"
[[commands]]
id = "tconsent.go"
title = "tconsent: go"
server = "srv"
tool = "go"
arg = "q"
prompt = "Query"
"#;

/// Whether the open prompt asks for an extension's first-run consent.
fn asks_for_consent(app: &App) -> bool {
    matches!(
        app.input_prompt.as_ref().map(|p| &p.purpose),
        Some(crate::widgets::input_prompt::InputPurpose::McpConsent { .. })
    )
}

/// #2920: a consent allowed in croft and then taken out of `config.json`
/// asks again once the settings reload, with no restart. The settings watch
/// may skip croft's own write of the consent, so the reload compares with a
/// snapshot that has to hold it.
#[test]
fn a_consent_taken_out_of_the_settings_file_asks_again_after_the_reload() {
    let (_scratch, croft) = scratch_config(&[("tconsent", CONSENT_EXT)]);
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    let asked = asks_for_consent;
    app.run_extension_command("tconsent.go");
    assert!(asked(&app), "fixture: a new extension is asked first");
    app.submit_input_prompt();
    app.close_input_prompt();
    assert!(
        consent_on_disk(&croft).contains("tconsent"),
        "fixture: allowing saves the consent"
    );
    // The user takes the id out of the file; the reload reads it without.
    let mut file = app.applied_settings.clone();
    file.mcp_consented.remove("tconsent");
    app.apply_merged_settings(&file);
    app.run_extension_command("tconsent.go");
    assert!(
        asked(&app),
        "the command asks for consent again, not for its argument: {:?}",
        app.input_prompt.as_ref().map(|p| p.title.clone())
    );
}

/// #2920 review: a consent allowed in croft survives the next reload when
/// `config.local.json` lists consents of its own. croft records a consent
/// in `config.json`, and the local list replaced that list in the merged
/// settings, so the reload took back the consent just given.
#[test]
fn a_consent_allowed_in_croft_survives_a_reload_beside_a_local_list() {
    let (_scratch, croft) = scratch_config(&[("tconsent", CONSENT_EXT)]);
    std::fs::write(
        croft.join("config.local.json"),
        r#"{ "mcp_consented": ["another"] }"#,
    )
    .unwrap();
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    app.run_extension_command("tconsent.go");
    assert!(
        asks_for_consent(&app),
        "fixture: a new extension is asked first"
    );
    app.submit_input_prompt();
    app.close_input_prompt();
    let merged = crate::config_layers::load_merged_from(
        &croft,
        None,
        crate::config_layers::current_platform(),
    );
    app.apply_merged_settings(&merged.prefs);
    app.run_extension_command("tconsent.go");
    assert!(
        !asks_for_consent(&app),
        "the consent just given still holds after the reload: {:?}",
        app.input_prompt.as_ref().map(|p| p.title.clone())
    );
}

/// Uninstalling an extension forgets its consent, in the session and on
/// disk: a later re-add is a fresh install of a program the user has not
/// approved this time, so the first-run gate asks again. The disabled state
/// it clears lands in the same config file.
#[test]
fn uninstalling_an_extension_forgets_its_consent() {
    let (_scratch, croft) = scratch_config(&[]);
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    app.consented_extensions = consent_on_disk(&croft);
    crate::prefs::save_mcp_consent_in(&croft, "csvlens").unwrap();
    app.consented_extensions.insert("csvlens".into());
    app.disabled_extensions.insert("csvlens".into());
    crate::prefs::save_disabled_extensions_in(&croft, &app.disabled_extensions).unwrap();
    app.perform_extension_uninstall("csvlens");
    let disabled_on_disk = crate::prefs::Prefs::load(&croft.join("config.json"))
        .unwrap_or_default()
        .disabled_extensions;
    assert!(
        !disabled_on_disk.contains("csvlens"),
        "the disabled state is cleared in the app's own config file: {disabled_on_disk:?}"
    );
    assert!(
        app.status.starts_with("Uninstalled"),
        "fixture: the catalog entry uninstalls cleanly: {:?}",
        app.status
    );
    assert!(
        !app.consented_extensions.contains("csvlens"),
        "the session grant is gone"
    );
    let saved = consent_on_disk(&croft);
    assert!(
        !saved.contains("csvlens"),
        "and so is the one on disk: {saved:?}"
    );
}

/// #2920 review: uninstalling forgets the consent in `config.local.json`
/// too, whose list adds to `config.json`'s: a consent left there came back
/// on the next reload, and the extension added back again skipped its
/// first-run prompt. The local file's other settings and comments stay.
#[test]
fn uninstalling_an_extension_forgets_its_consent_in_the_local_file_too() {
    let (_scratch, croft) = scratch_config(&[]);
    std::fs::create_dir_all(&croft).unwrap();
    std::fs::write(
        croft.join("config.local.json"),
        "{\n  // this box only\n  \"theme\": \"nord\",\n  \"mcp_consented\": [\"csvlens\", \"other\"]\n}\n",
    )
    .unwrap();
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    crate::prefs::save_mcp_consent_in(&croft, "csvlens").unwrap();
    app.consented_extensions.insert("csvlens".into());
    app.disabled_extensions.insert("csvlens".into());
    crate::prefs::save_disabled_extensions_in(&croft, &app.disabled_extensions).unwrap();
    app.perform_extension_uninstall("csvlens");
    assert!(
        app.status.starts_with("Uninstalled"),
        "fixture: the catalog entry uninstalls cleanly: {:?}",
        app.status
    );
    let local = std::fs::read_to_string(croft.join("config.local.json")).unwrap();
    assert!(
        !local.contains("\"csvlens\""),
        "the local consent is gone: {local}"
    );
    assert!(
        local.contains("\"other\"") && local.contains("// this box only") && local.contains("nord"),
        "and the rest of the file stays: {local}"
    );
    let merged = crate::config_layers::load_merged_from(
        &croft,
        None,
        crate::config_layers::current_platform(),
    );
    assert!(
        !merged.prefs.mcp_consented.contains("csvlens"),
        "no layer consents to it any more: {:?}",
        merged.prefs.mcp_consented
    );
}

/// #2920 review: a consent is forgotten wherever the user's settings grant
/// it, not only in the top-level lists: a platform block of `config.json`
/// or `config.local.json` (merged over the flat keys on that platform) and
/// a file either of them `extends` each kept the extension consented, so
/// it came back on the next reload and skipped the prompt when added back.
#[test]
fn uninstalling_an_extension_forgets_its_consent_in_platform_blocks_and_extended_files() {
    let (_scratch, croft) = scratch_config(&[]);
    std::fs::create_dir_all(&croft).unwrap();
    let platform = crate::config_layers::current_platform();
    std::fs::write(
        croft.join("team.json"),
        "{ \"mcp_consented\": [\"csvlens\", \"team-tool\"] }\n",
    )
    .unwrap();
    std::fs::write(
        croft.join("config.json"),
        format!(
            "{{\n  \"extends\": \"team.json\",\n  \"{platform}\": {{ \"mcp_consented\": [\"csvlens\"] }}\n}}\n"
        ),
    )
    .unwrap();
    std::fs::write(
        croft.join("config.local.json"),
        format!(
            "{{\n  // this box only\n  \"{platform}\": {{ \"mcp_consented\": [\"csvlens\", \"other\"] }}\n}}\n"
        ),
    )
    .unwrap();
    let consented = || {
        crate::config_layers::load_merged_from(&croft, None, platform)
            .prefs
            .mcp_consented
    };
    assert!(
        consented().contains("csvlens"),
        "fixture: the user layers consent to it"
    );
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    app.consented_extensions.insert("csvlens".into());
    app.perform_extension_uninstall("csvlens");
    assert!(
        app.status.starts_with("Uninstalled"),
        "the uninstall and its settings writes succeed: {:?}",
        app.status
    );
    let after = consented();
    assert!(
        !after.contains("csvlens"),
        "no user settings file consents to it any more: {after:?}"
    );
    assert!(
        after.contains("team-tool") && after.contains("other"),
        "the other consents stay: {after:?}"
    );
    let local = std::fs::read_to_string(croft.join("config.local.json")).unwrap();
    assert!(local.contains("// this box only"), "{local}");
}

/// #2920 review: a settings file may `extends` something that is no file at
/// all, such as a named pipe. The settings loader refuses to read it, and
/// the uninstall's forget step must too, or it waits on the pipe for good;
/// the consent in the file that names it is still forgotten.
#[cfg(unix)]
#[test]
fn forgetting_a_consent_skips_an_extends_the_settings_loader_refuses() {
    use std::os::unix::ffi::OsStrExt as _;
    let (_scratch, croft) = scratch_config(&[]);
    std::fs::create_dir_all(&croft).unwrap();
    let pipe = croft.join("pipe.json");
    let name = std::ffi::CString::new(pipe.as_os_str().as_bytes()).unwrap();
    assert_eq!(
        unsafe { libc::mkfifo(name.as_ptr(), 0o600) },
        0,
        "fixture: a named pipe"
    );
    std::fs::write(
        croft.join("config.json"),
        "{ \"extends\": \"pipe.json\", \"mcp_consented\": [\"csvlens\"] }\n",
    )
    .unwrap();
    let (tx, rx) = std::sync::mpsc::channel();
    let dir = croft.clone();
    std::thread::spawn(move || {
        let forgot = crate::prefs::forget_mcp_consent_in(&dir, "csvlens");
        let _ = tx.send(forgot.map_err(|e| e.to_string()));
    });
    let forgot = rx.recv_timeout(std::time::Duration::from_secs(10));
    if forgot.is_err() {
        // Free the read stuck on the pipe: a writer that opens and closes it
        // hands that read its end.
        let _ = std::fs::OpenOptions::new().write(true).open(&pipe);
    }
    assert!(
        matches!(forgot, Ok(Ok(()))),
        "the forget step finishes without reading the pipe: {forgot:?}"
    );
    let config = std::fs::read_to_string(croft.join("config.json")).unwrap();
    assert!(!config.contains("csvlens"), "{config}");
}

/// Adding is asking for it: an add from AVAILABLE turns the extension on even
/// when its id was left disabled (CodeQL, disabled back when it was built in,
/// #1842). A config file that cannot take that shows in the status instead of
/// the add's confirmation.
#[test]
fn adding_an_extension_clears_a_stale_disabled_state_and_says_when_that_cannot_save() {
    let (_scratch, croft) = scratch_config(&[]);
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    let add_time = |app: &mut App| {
        app.disabled_extensions.insert(String::from("mcp-time"));
        // The panel lists the real user dir; seat the AVAILABLE row.
        app.extensions
            .set_items(crate::widgets::extensions::items_from_available(
                crate::lsp::manifest::summaries(crate::lsp::manifest::CATALOG_MANIFESTS)
                    .into_iter()
                    .filter(|s| s.id == "mcp-time")
                    .collect(),
            ));
        let pos = app
            .extensions
            .visible_indices()
            .iter()
            .position(|&i| app.extensions.items()[i].id == "mcp-time")
            .expect("the Time row is visible");
        app.extensions.select(pos);
        app.toggle_selected_extension();
    };
    add_time(&mut app);
    assert!(app.status.starts_with("Added 'mcp-time'"), "{}", app.status);
    assert!(croft.join("extensions/mcp-time/extension.toml").is_file());
    assert!(!app.disabled_extensions.contains("mcp-time"));
    let saved = crate::prefs::Prefs::load(&croft.join("config.json"))
        .unwrap_or_default()
        .disabled_extensions;
    assert!(!saved.contains("mcp-time"), "{saved:?}");
    // Again with the config file unwritable: the failed save is what shows.
    std::fs::remove_dir_all(croft.join("extensions/mcp-time")).unwrap();
    std::fs::remove_file(croft.join("config.json")).unwrap();
    std::fs::create_dir_all(croft.join("config.json")).unwrap();
    add_time(&mut app);
    assert!(
        app.status.starts_with("Setting not saved"),
        "{}",
        app.status
    );
}

#[test]
fn an_edit_between_refusal_and_consent_forces_a_fresh_prompt() {
    // The lossy-save prompt names the characters the buffer held when it
    // asked (#1053). Cancelled, then typed into, the next Cmd+S asks again,
    // now naming the new character too, and only S there writes.
    let tmp = tempfile::tempdir().unwrap();
    let mut app = app_with_open_file(tmp.path(), "a.txt", "plain");
    app.editor
        .reopen_with_encoding(encoding_rs::WINDOWS_1252)
        .unwrap();
    app.editor.lines = vec![String::from("æ—¥")];
    app.editor.dirty = true;
    app.save();
    assert_eq!(app.pending_lossy_save.as_ref().unwrap().chars, ['æ—¥']);
    app.handle_key(key(KeyCode::Esc, KeyModifiers::NONE))
        .unwrap();
    app.editor.insert_char('語');
    app.save();
    assert_eq!(
        std::fs::read_to_string(tmp.path().join("a.txt")).unwrap(),
        "plain",
        "nothing was consented to, so this press asks again"
    );
    assert_eq!(
        app.pending_lossy_save.as_ref().unwrap().chars,
        ['語', '日'],
        "the fresh prompt names the newly typed character"
    );
    app.handle_key(key(KeyCode::Char('s'), KeyModifiers::NONE))
        .unwrap();
    assert_eq!(
        std::fs::read(tmp.path().join("a.txt")).unwrap(),
        b"語日",
        "consent given after the prompt that named both characters writes"
    );
}

/// #352: a workspace's `.vscode/extensions.json` recommendations appear in the
/// Extensions panel under FROM VS CODE with what croft has for each.
#[test]
fn workspace_extension_recommendations_show_under_from_vscode() {
    let tmp = tempfile::tempdir().unwrap();
    std::fs::create_dir(tmp.path().join(".vscode")).unwrap();
    std::fs::write(
        tmp.path().join(".vscode").join("extensions.json"),
        r#"{ "recommendations": ["rust-lang.rust-analyzer", "nobody.nothing"] }"#,
    )
    .unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.refresh_extensions();
    let ids: Vec<String> = app
        .extensions
        .items()
        .iter()
        .filter(|i| i.vscode)
        .map(|i| i.id.clone())
        .collect();
    assert_eq!(ids, ["rust-lang.rust-analyzer", "nobody.nothing"]);

    // Toggling a built-in row is an answer, not an install: the status names
    // the extension and what croft has for it, and nothing is disabled.
    let visible = app.extensions.visible_indices();
    let pos = visible
        .iter()
        .position(|&i| app.extensions.items()[i].id == "rust-lang.rust-analyzer")
        .expect("the row is visible");
    app.extensions.select(pos);
    let before = app.disabled_extensions.clone();
    app.toggle_selected_extension();
    assert!(
        app.status
            .starts_with("rust-lang.rust-analyzer: built in: lsp-rust"),
        "the status restates the row: {}",
        app.status
    );
    assert_eq!(app.disabled_extensions, before, "nothing was toggled");
}

/// #624 review: toggling an extension off and on re-approves its tools, as
/// the refusal says: turning it off forgets the fingerprints of the
/// commands it declares, and only those, so the next run trusts afresh.
#[test]
fn toggling_an_extension_off_forgets_its_tool_fingerprints() {
    const EXT: &str = r#"
id = "tfp"
name = "tfp"
api_version = 1
[[mcp_servers]]
id = "srv"
command = "/bin/false"
[[commands]]
id = "tfp.go"
title = "tfp: go"
server = "srv"
tool = "go"
"#;
    let other = EXT.replace("tfp", "oth");
    let (_scratch, croft) = scratch_config(&[("tfp", EXT), ("oth", &other)]);
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    // The panel lists the real user dir; seat the scratch extension's row.
    // A toggle refreshes the panel from that dir, so re-seat before each.
    let toggle_tfp = |app: &mut App| {
        app.extensions
            .set_items(crate::widgets::extensions::items_from_summaries(
                crate::lsp::manifest::summaries(&[EXT]),
                &app.disabled_extensions,
            ));
        let visible = app.extensions.visible_indices();
        let pos = visible
            .iter()
            .position(|&i| app.extensions.items()[i].id == "tfp")
            .expect("the tfp row is visible");
        app.extensions.select(pos);
        app.toggle_selected_extension();
    };
    assert!(crate::prefs::trust_mcp_tool_in(&croft, "tfp.go", "fp1"));
    assert!(crate::prefs::trust_mcp_tool_in(&croft, "oth.go", "o1"));
    toggle_tfp(&mut app);
    assert!(app.disabled_extensions.contains("tfp"), "{}", app.status);
    assert!(
        crate::prefs::trust_mcp_tool_in(&croft, "tfp.go", "fp2"),
        "the changed tool is approved afresh"
    );
    assert!(
        !crate::prefs::trust_mcp_tool_in(&croft, "oth.go", "o2"),
        "another extension's record stays"
    );
    // Turning it back on keeps the new record: a further change is refused.
    toggle_tfp(&mut app);
    assert!(!app.disabled_extensions.contains("tfp"), "{}", app.status);
    assert!(!crate::prefs::trust_mcp_tool_in(&croft, "tfp.go", "fp3"));
}

/// Uninstalling an extension forgets its tools' fingerprints, so a re-added
/// newer version approves its tools afresh instead of being refused.
#[test]
fn uninstalling_an_extension_forgets_its_tool_fingerprints() {
    // Only a catalog entry uninstalls, so the fixture is the bundled Time
    // sidecar beside a hand-added extension whose record must stay.
    const TIME: &str = include_str!("../../../assets/catalog/mcp-time/extension.toml");
    const OTH: &str = r#"
id = "oth"
name = "oth"
api_version = 1
[[mcp_servers]]
id = "srv"
command = "/bin/false"
[[commands]]
id = "oth.go"
title = "oth: go"
server = "srv"
tool = "go"
"#;
    let (_scratch, croft) = scratch_config(&[("mcp-time", TIME), ("oth", OTH)]);
    let tmp = tempfile::tempdir().unwrap();
    let mut app = App::new(tmp.path().to_path_buf()).unwrap();
    app.config_dir = croft.clone();
    assert!(crate::prefs::trust_mcp_tool_in(&croft, "time.now", "fp1"));
    assert!(crate::prefs::trust_mcp_tool_in(&croft, "oth.go", "o1"));
    app.perform_extension_uninstall("mcp-time");
    assert!(app.status.starts_with("Uninstalled"), "{}", app.status);
    assert!(
        crate::prefs::trust_mcp_tool_in(&croft, "time.now", "fp2"),
        "the re-added tool is approved afresh"
    );
    assert!(
        !crate::prefs::trust_mcp_tool_in(&croft, "oth.go", "o2"),
        "another extension's record stays"
    );
}