eclipse-core 0.15.1

Core library for eclipse: providers, tools, sessions, config, runtime
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
//! Sight: what the harness does with a picture on a turn (`#346`).
//!
//! Three modes, and each one is a promise about which model sees the bytes:
//!
//! - [`VisionMode::Native`] — the turn's own model, and nothing else. A model that cannot see
//!   means the attach is refused **before the turn starts**, with a sentence naming the model.
//!   Sending it and letting the backend answer 400 is the same information later and worse.
//! - [`VisionMode::Text`] — the turn's model never sees a picture. The picture goes to the
//!   describe route, its answer enters the turn as text, and the turn model is told it is reading
//!   a description rather than looking at something.
//! - [`VisionMode::Auto`] — native when the turn model declares vision, the describe route
//!   otherwise.
//!
//! The one thing `auto` cannot do is notice a backend that accepts an image and quietly ignores
//! it. It reacts to a declared capability and to an outright refusal (a 400 or 422 naming the
//! part), and to nothing else; a model that says "I see no image", or invents one, is
//! indistinguishable from a model that looked. That limitation is in `docs/USER.md` in one
//! sentence because the failure mode is a confident wrong answer.
//!
//! The decision itself ([`Choice::plan`]) is pure: the caller resolves the two facts a config
//! cannot know — the turn provider's own capability, and the describe route's manifest — and the
//! sentences live here so the CLI and the dashboard cannot describe the same refusal differently.

use crate::config::{Config, NamedRoute, ProviderConfig, VisionMode};
use crate::provider::ProviderProfile;

/// The route that describes pictures, as the planner needs to know it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Describe {
    /// The route's name, for the sentence that names it.
    pub route: String,
    /// The wire profile on that route, named in a refusal so the reader knows where to look.
    pub profile: String,
    /// Whether its route config or manifest claims it can see.
    pub sees: bool,
    /// Whether it points at this machine or the LAN.
    pub local: bool,
}

impl Describe {
    /// The describe route, as the planner needs to know it, from a route this config declares.
    ///
    /// This is the only place `local` and `sees` are decided (`#356`): a caller that builds the
    /// struct field by field can hard-code `local: true` and nothing in [`Choice::plan`] will
    /// notice, which is exactly how `allow_cloud` came not to fire.
    pub fn of(route: &NamedRoute, profiles: &[ProviderProfile]) -> Self {
        Self {
            route: route.name.clone(),
            profile: route
                .config
                .profile
                .as_deref()
                .unwrap_or("openai")
                .to_string(),
            sees: route_sees(&route.config, profiles),
            local: is_local_url(&route.config.base_url),
        }
    }

    /// Resolve `[vision] route` against the routes this config declares.
    ///
    /// `None` when the key is empty **or** names nothing: a name that matches no route is a load
    /// error elsewhere ([`Config::validate`](crate::config::Config)), and reaching here with one
    /// means a hand-built config in a test, which must behave like "no route set" rather than
    /// panic.
    pub fn resolve(cfg: &Config, profiles: &[ProviderProfile]) -> Option<Self> {
        let name = cfg.vision.route.trim();
        if name.is_empty() {
            return None;
        }
        let route = resolve_route(cfg, name)?;
        Some(Self::of(&route, profiles))
    }
}

/// The route `name` calls itself, wherever it is declared: `[provider]` is `default`.
///
/// `declared_routes` is the one answer to "which routes does this config have", so `[vision] route`
/// resolves through it rather than reimplementing the `default` rule.
fn resolve_route(cfg: &Config, name: &str) -> Option<NamedRoute> {
    cfg.declared_routes().into_iter().find(|r| r.name == name)
}

/// Whether this connection claims it can see a picture.
///
/// A route-level `vision = true | false` in config wins over the wire profile's declaration,
/// because one profile (`llamacpp`) often serves both blind text models and vision-capable models.
///
/// A *claim*, not a probe: `vision = true` in a config or plugin manifest is an assertion by
/// whoever wrote it, and the alternative — posting a 1×1 PNG at startup to see if it answers
/// 200 — costs a request per model per start and is answered happily by a backend that ignores
/// images anyway.
pub fn route_sees(config: &ProviderConfig, profiles: &[ProviderProfile]) -> bool {
    if let Some(vision) = config.vision {
        return vision;
    }
    ProviderProfile::resolve(config.profile.as_deref().unwrap_or("openai"), profiles)
        .map(|profile| profile.vision == Some(true))
        .unwrap_or(false)
}

/// Whether a URL points at this machine or the LAN, judged by the host alone.
///
/// The same addresses [`crate::netguard`] refuses to fetch are the ones that are local here, so
/// the two agree by construction. A name that is not an IP literal is local only when it is
/// obviously ours — `localhost`, a single label, `.local`, `.lan`, `.home.arpa` — because
/// `api.openai.com` is the internet and a privacy gate must refuse rather than guess.
pub fn is_local_url(url: &str) -> bool {
    let Ok(url) = reqwest::Url::parse(url.trim()) else {
        return false;
    };
    url.host_str().map(host_is_local).unwrap_or(false)
}

/// How much of a description is kept. A describe route is asked one question about one picture;
/// an answer longer than this is not a description, and it is stored on the message and re-sent as
/// text on every later turn.
const DESCRIPTION_CAP: usize = 8_000;

/// The person's own words in a message, without the marker lines the composer adds for pictures.
///
/// A picture-only turn's content *is* the marker (`--- attached picture: shot.png (image/png) ---`),
/// and asking a describe route that string — with the useful question in
/// [`describe_request`] unreachable — is what `#383` was. Marker lines are structure, not a
/// question, so a message made only of them has no words at all.
pub fn asked_text(content: Option<&str>) -> String {
    let Some(text) = content else {
        return String::new();
    };
    text.lines()
        .filter(|line| !is_marker_line(line))
        .collect::<Vec<_>>()
        .join("\n")
        .trim()
        .to_string()
}

fn is_marker_line(line: &str) -> bool {
    let t = line.trim();
    (t.starts_with("--- attached picture:") || t.starts_with("--- end of ")) && t.ends_with("---")
}

/// What is stored, and shown to the turn's model, from a describe route's answer.
///
/// Two things happen here and nowhere else: the text is redacted, because a route that echoes a
/// secret out of the picture would otherwise put it into the session and into every later prompt,
/// and it is capped — the answer is one description, not a document (`#386`).
pub fn describe_text(raw: &str) -> String {
    let redacted = crate::redact::redact(raw.trim(), &[]).text;
    if redacted.chars().count() <= DESCRIPTION_CAP {
        return redacted;
    }
    let mut cut: String = redacted.chars().take(DESCRIPTION_CAP).collect();
    cut.push('…');
    cut
}

fn host_is_local(host: &str) -> bool {
    let host = host.trim_end_matches('.').to_ascii_lowercase();
    let bare = host.trim_start_matches('[').trim_end_matches(']');
    if let Ok(ip) = bare.parse::<std::net::IpAddr>() {
        return crate::netguard::blocked_reason(ip).is_some();
    }
    host == "localhost"
        || !host.contains('.')
        || host.ends_with(".local")
        || host.ends_with(".lan")
        || host.ends_with(".home.arpa")
}

/// What the harness will do with this turn's pictures.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Plan {
    /// The bytes go to the turn's own model.
    Native,
    /// The bytes go to `route`; the turn model gets a description as text.
    Describe { route: String },
    /// The turn does not start. The sentence says why and what to do about it.
    Refuse { sentence: String },
}

impl Plan {
    pub fn refusal(&self) -> Option<&str> {
        match self {
            Plan::Refuse { sentence } => Some(sentence),
            _ => None,
        }
    }
}

/// The facts a planner needs, all of which a surface can answer without asking a model anything.
#[derive(Debug, Clone)]
pub struct Choice<'a> {
    pub mode: VisionMode,
    /// The turn's model, named in a refusal so the reader knows which one cannot see.
    pub model: &'a str,
    /// The turn's active route, named in a refusal so the reader knows which route to update.
    pub route: &'a str,
    /// The active route's wire profile, named in a refusal alongside `route`.
    pub profile: &'a str,
    /// How many pictures are on the turn. Zero means there is nothing to route.
    pub pictures: usize,
    /// Whether the turn's own provider declares vision.
    pub turn_sees: bool,
    /// The resolved `[vision] route`, if the config names one.
    pub describe: Option<Describe>,
    /// `[vision] allow_cloud`: let a description leave this machine.
    pub allow_cloud: bool,
}

impl Choice<'_> {
    pub fn plan(&self) -> Plan {
        if self.pictures == 0 {
            return Plan::Native;
        }
        match self.mode {
            VisionMode::Native => {
                if self.turn_sees {
                    Plan::Native
                } else {
                    Plan::Refuse {
                        sentence: no_native(self.model),
                    }
                }
            }
            VisionMode::Auto if self.turn_sees => Plan::Native,
            VisionMode::Text | VisionMode::Auto => {
                let Some(describe) = &self.describe else {
                    return Plan::Refuse {
                        sentence: no_route(self.mode, self.model, self.route, self.profile),
                    };
                };
                if !describe.sees {
                    return Plan::Refuse {
                        sentence: route_blind(self.mode, describe),
                    };
                }
                if !describe.local && !self.allow_cloud {
                    return Plan::Refuse {
                        sentence: cloud(&describe.route),
                    };
                }
                Plan::Describe {
                    route: describe.route.clone(),
                }
            }
        }
    }
}

/// `native` with a model that cannot see. Names the model and both ways out, because the reader
/// is mid-task and the fix is one of two keystrokes.
pub fn no_native(model: &str) -> String {
    format!(
        "{model} cannot see images — `/model` to one that can, or set `[vision] mode = \"text\"` \
         and name a route that describes pictures in `[vision] route`"
    )
}

fn no_route(mode: VisionMode, model: &str, route: &str, profile: &str) -> String {
    match mode {
        VisionMode::Auto => format!(
            "{model} (route `{route}`, profile `{profile}`) does not declare vision and no \
             `[vision] route` is set to describe the picture instead — add `vision = true` under \
             route `{route}` if it can see, or configure `[vision] route` to a route with \
             `vision = true`"
        ),
        _ => format!(
            "`[vision] mode = \"text\"` needs a describe route: configure `[vision] route` to a \
             route that declares `vision = true` (current route `{route}` uses profile \
             `{profile}`)"
        ),
    }
}

fn route_blind(mode: VisionMode, describe: &Describe) -> String {
    let route = &describe.route;
    let profile = &describe.profile;
    let why = if mode == VisionMode::Auto {
        "and `auto` fell back to it because the turn's model does not declare vision "
    } else {
        ""
    };
    format!(
        "`[vision] route = \"{route}\"` {why}(profile `{profile}`) does not declare vision — \
         add `vision = true` under route `{route}` (or in profile `{profile}`) if it can see"
    )
}

/// The privacy gate. It is a refusal and not a warning because the thing it protects is a
/// screenshot, and "it went to an API once" cannot be undone by reading a log.
pub fn cloud(route: &str) -> String {
    format!(
        "`[vision] route = \"{route}\"` is not on this machine, and describing a picture there \
         would send it off it — set `[vision] allow_cloud = true` if that is what you want"
    )
}

/// The request sent to the describe route: what the reader asked, plus the pictures.
///
/// The instruction is short on purpose. A describe route that editorialises is worse than one that
/// lists what it sees, because the turn model cannot check it — it is reading the only account of a
/// picture it will ever get.
pub fn describe_request(
    asked: &str,
    images: &[crate::message::ImagePart],
) -> Vec<crate::message::Message> {
    let system = crate::message::Message::system(
        "You describe images for another model that cannot see them. Say what is in the picture \
         and answer what is asked about it. Quote text in the picture verbatim, in the language it \
         is written in. Do not guess: if the picture does not show something, say that it does not. \
         Keep it under 250 words unless the question needs more.",
    );
    let question = if asked.trim().is_empty() {
        "Describe this picture in enough detail for someone who cannot see it."
    } else {
        asked.trim()
    };
    let mut user = crate::message::Message::user(question);
    for image in images {
        user = user.with_image(image.clone());
    }
    vec![system, user]
}

/// What the turn's model reads in place of a picture, and the reason it is spelled this way: a
/// model told nothing will answer "I can see…" about something it never looked at.
pub fn described_block(route: &str, asked: &str, lines: &[String]) -> String {
    let head = if asked.trim().is_empty() {
        String::new()
    } else {
        format!("{}\n\n", asked.trim())
    };
    let (what, it) = if lines.len() == 1 {
        ("The attached picture was", "it")
    } else {
        ("The attached pictures were", "them")
    };
    format!(
        "{head}[{what} described by `{route}`, which can see {it}. You cannot see {it} yourself — \
         this is a description, not the picture.]\n\n{}",
        lines.join("\n\n")
    )
}

/// Whether a failure is a backend refusing the image part — the one signal `auto` can react to.
///
/// A 400 or 422 whose body mentions an image part. Deliberately narrow: a 400 for a bad tool schema
/// also names fields, and falling back to a description on that would hide the real error behind a
/// second, different failure.
pub fn refuses_images(failure: &crate::error::ProviderFailure) -> bool {
    use crate::error::ProviderFailure;
    let body = match failure {
        ProviderFailure::InvalidRequest(http) => http.body.to_ascii_lowercase(),
        ProviderFailure::Routed { cause, .. } => return refuses_images(cause),
        _ => return false,
    };
    body.contains("image_url")
        || body.contains("image url")
        || body.contains("image content")
        || body.contains("multimodal")
        // `unsupported` is not listed separately: it contains `support`.
        || (body.contains("image") && body.contains("support"))
}

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

    fn describe(sees: bool, local: bool) -> Option<Describe> {
        Some(Describe {
            route: "sight".into(),
            profile: "llamacpp".into(),
            sees,
            local,
        })
    }

    fn choice(mode: VisionMode, turn_sees: bool, describe: Option<Describe>) -> Choice<'static> {
        Choice {
            mode,
            model: "stub-stream",
            route: "default",
            profile: "llamacpp",
            pictures: 1,
            turn_sees,
            describe,
            allow_cloud: false,
        }
    }

    #[test]
    fn native_sends_the_picture_to_a_model_that_declares_vision() {
        let plan = choice(VisionMode::Native, true, None).plan();
        assert_eq!(plan, Plan::Native);
    }

    #[test]
    fn native_refuses_before_the_turn_when_the_model_cannot_see() {
        let plan = choice(VisionMode::Native, false, describe(true, true)).plan();
        let sentence = plan.refusal().expect("a refusal");
        assert!(
            sentence.starts_with("stub-stream cannot see images"),
            "{sentence}"
        );
        assert!(sentence.contains("mode = \"text\""), "{sentence}");
    }

    #[test]
    fn text_never_uses_the_turn_model_even_when_it_could_see() {
        // The mode is a promise, not a preference: `text` on a vision model still describes.
        let plan = choice(VisionMode::Text, true, describe(true, true)).plan();
        assert_eq!(
            plan,
            Plan::Describe {
                route: "sight".into()
            }
        );
    }

    #[test]
    fn auto_is_native_when_the_turn_model_declares_vision_and_says_nothing_about_the_route() {
        // A vision model plus an unreachable describe route is still a working configuration.
        let plan = choice(VisionMode::Auto, true, None).plan();
        assert_eq!(plan, Plan::Native);
    }

    #[test]
    fn auto_falls_back_to_the_description() {
        let plan = choice(VisionMode::Auto, false, describe(true, true)).plan();
        assert_eq!(
            plan,
            Plan::Describe {
                route: "sight".into()
            }
        );
    }

    #[test]
    fn a_mode_that_needs_a_route_says_which_key_is_missing() {
        let sentence = choice(VisionMode::Text, false, None)
            .plan()
            .refusal()
            .expect("a refusal")
            .to_string();
        assert!(sentence.contains("[vision] route"), "{sentence}");
        let auto = choice(VisionMode::Auto, false, None)
            .plan()
            .refusal()
            .expect("a refusal")
            .to_string();
        // An `auto` refusal explains both halves: why the fallback happened and what is missing.
        assert!(auto.contains("does not declare vision"), "{auto}");
        assert!(auto.contains("[vision] route"), "{auto}");
    }

    #[test]
    fn a_describe_route_that_cannot_see_is_refused_by_name() {
        let sentence = choice(VisionMode::Text, false, describe(false, true))
            .plan()
            .refusal()
            .expect("a refusal")
            .to_string();
        assert!(sentence.contains("vision = true"), "{sentence}");
        assert!(sentence.contains("sight"), "{sentence}");
    }

    #[test]
    fn a_route_off_this_machine_is_refused_until_allow_cloud() {
        let plan = choice(VisionMode::Text, false, describe(true, false)).plan();
        let sentence = plan.refusal().expect("a refusal").to_string();
        assert!(sentence.contains("allow_cloud = true"), "{sentence}");

        let mut allowing = choice(VisionMode::Text, false, describe(true, false));
        allowing.allow_cloud = true;
        assert_eq!(
            allowing.plan(),
            Plan::Describe {
                route: "sight".into()
            }
        );
    }

    #[test]
    fn no_pictures_means_no_decision_and_no_refusal() {
        for mode in [VisionMode::Native, VisionMode::Text, VisionMode::Auto] {
            let mut c = choice(mode, false, None);
            c.pictures = 0;
            assert_eq!(c.plan(), Plan::Native, "{mode:?}");
        }
    }

    /// The one constructor the runtime uses for the describe route. A route off this machine must
    /// come back remote, or `allow_cloud` can never fire (`#356`).
    #[test]
    fn a_describes_locality_is_read_from_its_own_url() {
        let profiles: Vec<ProviderProfile> = Vec::new();
        let route = |base: &str| NamedRoute {
            name: "sight".into(),
            max_parallel: None,
            group: None,
            config: ProviderConfig {
                base_url: base.into(),
                model: "m".into(),
                ..Default::default()
            },
        };
        assert!(Describe::of(&route("http://127.0.0.1:18011/v1"), &profiles).local);
        assert!(!Describe::of(&route("https://api.openai.com/v1"), &profiles).local);
    }

    #[test]
    fn local_means_this_machine_or_the_lan_and_nothing_else() {
        for local in [
            "http://127.0.0.1:18045/v1",
            "http://localhost:18011/v1",
            "http://[::1]:8080/v1",
            "http://192.168.1.120:8080/v1",
            "http://172.17.0.1:8899/",
            "http://mmnuc:8080/v1",
            "http://eclipse.local:8080/v1",
            "http://box.lan/v1",
        ] {
            assert!(is_local_url(local), "{local} is local");
        }
        for remote in [
            "https://api.openai.com/v1",
            "https://ollama.com/v1",
            "https://openrouter.ai/api/v1",
            "not a url",
            "",
        ] {
            assert!(!is_local_url(remote), "{remote} is not local");
        }
    }

    /// `#383`: the marker lines the composer adds are structure, not a question.
    #[test]
    fn a_message_made_only_of_markers_has_no_words() {
        assert_eq!(
            asked_text(Some("--- attached picture: shot.png (image/png) ---")),
            ""
        );
        assert_eq!(asked_text(None), "");
        assert_eq!(asked_text(Some("   \n  ")), "");
        // The person's words survive, in order, with the marker lines gone.
        assert_eq!(
            asked_text(Some(
                "what is this?\n--- attached picture: a.png (image/png) ---\nand this one"
            )),
            "what is this?\nand this one"
        );
        // A line that only looks like a marker is still a line if it does not close like one.
        assert_eq!(
            asked_text(Some("--- attached picture: a.png (image/png)")),
            "--- attached picture: a.png (image/png)"
        );
    }

    /// `#386`: what a describe route answers is stored and re-sent, so it is capped and redacted
    /// before either happens.
    #[test]
    fn a_description_is_capped_and_redacted() {
        let long = "x".repeat(DESCRIPTION_CAP + 500);
        let kept = describe_text(&long);
        assert_eq!(
            kept.chars().count(),
            DESCRIPTION_CAP + 1,
            "the cut is marked"
        );
        assert!(kept.ends_with('…'));
        // A secret the route echoed out of the picture does not reach the session.
        let leaked = describe_text(
            "the screen shows api_key = sk-live-4f9d8e7c6b5a39281706f5e4d3c2b1a0 and a chart",
        );
        assert!(
            !leaked.contains("sk-live-4f9d8e7c6b5a39281706f5e4d3c2b1a0"),
            "the description was stored unredacted: {leaked}"
        );
        assert!(leaked.contains("and a chart"), "{leaked}");
    }

    #[test]
    fn route_sees_gives_route_vision_precedence_over_the_profile() {
        let mut seeing_profile = ProviderProfile::builtin("llamacpp").unwrap();
        seeing_profile.name = "seeing".into();
        seeing_profile.vision = Some(true);

        let mut blind_profile = ProviderProfile::builtin("llamacpp").unwrap();
        blind_profile.name = "blind".into();
        blind_profile.vision = Some(false);

        let profiles = [seeing_profile, blind_profile];

        // Unset `vision` inherits the profile.
        let mut cfg = ProviderConfig {
            base_url: "http://127.0.0.1:18011/v1".into(),
            model: "m".into(),
            profile: Some("llamacpp".into()),
            ..Default::default()
        };
        assert!(!route_sees(&cfg, &profiles));

        cfg.profile = Some("seeing".into());
        assert!(route_sees(&cfg, &profiles));

        // Explicit `vision = true` overrides both an undeclared and a `false` profile.
        cfg.profile = Some("llamacpp".into());
        cfg.vision = Some(true);
        assert!(route_sees(&cfg, &profiles));

        cfg.profile = Some("blind".into());
        assert!(route_sees(&cfg, &profiles));

        // Explicit `vision = false` overrides a profile that claims `vision = true`.
        cfg.profile = Some("seeing".into());
        cfg.vision = Some(false);
        assert!(!route_sees(&cfg, &profiles));
    }

    #[test]
    fn refusals_name_the_route_profile_and_key_instead_of_set_one() {
        let auto_no_route = choice(VisionMode::Auto, false, None)
            .plan()
            .refusal()
            .expect("a refusal")
            .to_string();
        assert!(auto_no_route.contains("default"), "{auto_no_route}");
        assert!(auto_no_route.contains("llamacpp"), "{auto_no_route}");
        assert!(auto_no_route.contains("vision = true"), "{auto_no_route}");
        assert!(!auto_no_route.contains("set one"), "{auto_no_route}");

        let text_no_route = choice(VisionMode::Text, false, None)
            .plan()
            .refusal()
            .expect("a refusal")
            .to_string();
        assert!(text_no_route.contains("default"), "{text_no_route}");
        assert!(text_no_route.contains("llamacpp"), "{text_no_route}");
        assert!(text_no_route.contains("vision = true"), "{text_no_route}");
        assert!(!text_no_route.contains("set one"), "{text_no_route}");

        for mode in [VisionMode::Auto, VisionMode::Text] {
            let blind = choice(mode, false, describe(false, true))
                .plan()
                .refusal()
                .expect("a refusal")
                .to_string();
            assert!(blind.contains("sight"), "{blind}");
            assert!(blind.contains("llamacpp"), "{blind}");
            assert!(blind.contains("vision = true"), "{blind}");
            assert!(!blind.contains("set one"), "{blind}");
        }
    }
}