abstractcore-console 0.8.1

A terminal console for AbstractCore: configure models, providers and capability routes, browse, download and delete local models, and install local engines (Ollama, LM Studio, MLX, llama.cpp). Also a library of the shared Models/Engines screens, rendered by AbstractTUI.
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
//! The seam between the shared Models / Engines screens and whatever
//! answers them (contract H).
//!
//! The screens never know WHERE the answers come from. The core
//! console's binary plugs in [`CliTransport`], which runs
//! `abstractcore … --json` subprocesses on this machine; the gateway
//! console plugs in its own `HttpTransport` over the gateway's
//! `/api/gateway/models/*` and `/api/gateway/engines/*` mirrors. Both
//! return the SAME JSON documents (contracts A–E in the mission's
//! `CONTRACTS.md`), so one set of screens renders both.
//!
//! Every method is BLOCKING and is only ever called from the screens'
//! worker thread ([`crate::screens::spawn_worker`]), never from the UI
//! thread — an implementation is free to do network or process I/O.
//!
//! # Implementing a transport
//!
//! ```
//! use abstractcore_console::transport::{ConsoleTransport, TransportError};
//! use serde_json::{json, Value};
//!
//! /// A transport that knows nothing: every read says so honestly.
//! struct Offline;
//!
//! impl ConsoleTransport for Offline {
//!     fn host_profile(&self) -> Result<Value, TransportError> {
//!         Err(TransportError::unavailable("offline"))
//!     }
//!     fn engines_status(&self, _probe: bool) -> Result<Value, TransportError> {
//!         Ok(json!({"schema": "engines_status_v1", "engines": []}))
//!     }
//!     fn models_catalog(&self, _q: &str, _engine: Option<&str>, _fits_only: bool)
//!         -> Result<Value, TransportError> {
//!         Ok(json!({"schema": "model_catalog_v1", "rows": []}))
//!     }
//!     fn models_installed(&self, _provider: Option<&str>) -> Result<Value, TransportError> {
//!         Ok(json!({"schema": "models_installed_v1", "rows": []}))
//!     }
//!     fn start_download(&self, _p: &str, _a: &str, _bytes: Option<u64>)
//!         -> Result<Value, TransportError> {
//!         Err(TransportError::refused("offline", None))
//!     }
//!     fn delete_model(&self, _p: &str, _a: &str, _force: bool) -> Result<Value, TransportError> {
//!         Err(TransportError::refused("offline", None))
//!     }
//!     fn engine_install(&self, _id: &str, _dry_run: bool) -> Result<Value, TransportError> {
//!         Err(TransportError::refused("offline", None))
//!     }
//!     fn job(&self, id: &str) -> Result<Value, TransportError> {
//!         Err(TransportError::not_found(format!("no job {id}")))
//!     }
//!     fn cancel_job(&self, id: &str) -> Result<Value, TransportError> {
//!         Err(TransportError::not_found(format!("no job {id}")))
//!     }
//! }
//!
//! let t: std::sync::Arc<dyn ConsoleTransport> = std::sync::Arc::new(Offline);
//! assert_eq!(t.host_label(), "this machine");
//! assert!(t.start_download("ollama", "qwen3:8b", None).unwrap_err().is_refused());
//! ```

pub mod cli;

use serde_json::Value;

pub use cli::CliTransport;

/// What went wrong talking to the backend — classified so the screens
/// can say what the operator can DO about it.
///
/// `#[non_exhaustive]`: a new backend answer gets a new class (0.3.0
/// added [`Unsupported`](TransportErrorKind::Unsupported)); a host that
/// matches on the kind keeps a wildcard arm.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum TransportErrorKind {
    /// The backend is not there at all: no `abstractcore` binary, the
    /// gateway is unreachable, the process could not be spawned.
    Unavailable,
    /// The backend answered and SAID NO: CLI exit code 2, HTTP 403/409.
    /// Not a failure of the machinery — a decision (a loaded model, a
    /// shared cache, installs disabled, a job already running). The
    /// payload's own explanation rides in [`TransportError::body`].
    Refused,
    /// The backend tried and failed: CLI exit 1, HTTP 5xx, a crash.
    Failed,
    /// The thing asked about does not exist (unknown job id, HTTP 404).
    NotFound,
    /// No answer within the deadline.
    Timeout,
    /// An answer arrived but was not the JSON the contract promises.
    Protocol,
    /// The caller is not allowed (HTTP 401): sign in / token.
    Unauthorized,
    /// This backend has no such verb at all (the CLI transport cannot
    /// start an engine server, the gateway can). Not a refusal and not a
    /// failure: the screens say "not available over this backend" and
    /// never fake the verb. See [`TransportCaps`].
    Unsupported,
}

/// A transport failure: its class, one human line, and whatever JSON
/// the backend sent with it (a refusal's reasons, a job's error).
#[derive(Clone, Debug, PartialEq)]
pub struct TransportError {
    pub kind: TransportErrorKind,
    pub message: String,
    /// The exit code (CLI) or HTTP status (gateway), when there was one.
    pub code: Option<i32>,
    /// The backend's JSON body, if it sent one — a refusal's
    /// `delete_blockers`, `error`, or the job it refused to start.
    pub body: Option<Value>,
}

impl TransportError {
    pub fn new(kind: TransportErrorKind, message: impl Into<String>) -> TransportError {
        TransportError {
            kind,
            message: message.into(),
            code: None,
            body: None,
        }
    }

    pub fn unavailable(message: impl Into<String>) -> TransportError {
        TransportError::new(TransportErrorKind::Unavailable, message)
    }

    pub fn refused(message: impl Into<String>, body: Option<Value>) -> TransportError {
        TransportError {
            body,
            ..TransportError::new(TransportErrorKind::Refused, message)
        }
    }

    pub fn failed(message: impl Into<String>) -> TransportError {
        TransportError::new(TransportErrorKind::Failed, message)
    }

    pub fn not_found(message: impl Into<String>) -> TransportError {
        TransportError::new(TransportErrorKind::NotFound, message)
    }

    pub fn protocol(message: impl Into<String>) -> TransportError {
        TransportError::new(TransportErrorKind::Protocol, message)
    }

    pub fn unsupported(message: impl Into<String>) -> TransportError {
        TransportError::new(TransportErrorKind::Unsupported, message)
    }

    pub fn with_code(mut self, code: i32) -> TransportError {
        self.code = Some(code);
        self
    }

    pub fn with_body(mut self, body: Value) -> TransportError {
        self.body = Some(body);
        self
    }

    pub fn is_refused(&self) -> bool {
        self.kind == TransportErrorKind::Refused
    }

    /// One short word for the class, as the screens print it.
    pub fn headline(&self) -> &'static str {
        match self.kind {
            TransportErrorKind::Unavailable => "unavailable",
            TransportErrorKind::Refused => "refused",
            TransportErrorKind::Failed => "failed",
            TransportErrorKind::NotFound => "not found",
            TransportErrorKind::Timeout => "timed out",
            TransportErrorKind::Protocol => "unexpected answer",
            TransportErrorKind::Unauthorized => "not authorized",
            TransportErrorKind::Unsupported => "not available here",
        }
    }

    /// The refusal's reasons, when the backend named them: the body's
    /// `delete_blockers` (contract D) and/or its `error` string.
    pub fn reasons(&self) -> Vec<String> {
        let Some(body) = &self.body else {
            return Vec::new();
        };
        let mut out: Vec<String> = body
            .get("delete_blockers")
            .and_then(Value::as_array)
            .map(|a| {
                a.iter()
                    .filter_map(Value::as_str)
                    .map(str::to_string)
                    .collect()
            })
            .unwrap_or_default();
        if let Some(e) = body.get("error").and_then(Value::as_str) {
            if !e.is_empty() && !out.iter().any(|o| o == e) {
                out.push(e.to_string());
            }
        }
        out
    }
}

impl std::fmt::Display for TransportError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}: {}", self.headline(), self.message)
    }
}

impl std::error::Error for TransportError {}

/// The Models / Engines backend (contract H). Every method returns the
/// contract document verbatim as a [`serde_json::Value`]; the screens
/// parse it tolerantly (unknown keys ignored, missing = unknown).
///
/// | method | CLI (`CliTransport`) | gateway route | contract |
/// |---|---|---|---|
/// | `host_profile` | `abstractcore host profile --json` | `GET /api/gateway/host/profile` | A |
/// | `engines_status` | `abstractcore engines status [--probe] --json` | `GET /api/gateway/engines` | B |
/// | `models_catalog` | `abstractcore models catalog\|search … --json` | `GET /api/gateway/models/catalog` | C |
/// | `models_installed` | `abstractcore models list [--provider X] --json` | `GET /api/gateway/models/installed` | D |
/// | `start_download` | `abstractcore models download P A --json` | `POST /api/gateway/models/download {provider, artifact, expected_bytes?}` | E |
/// | `delete_model` | `abstractcore models delete P A --yes [--force] --json` | `POST /api/gateway/models/delete` | E |
/// | `engine_install` | `abstractcore engines install ID --yes [--dry-run] --json` | `POST /api/gateway/engines/{id}/install` | E |
/// | `job` / `cancel_job` | the transport's own child jobs | `GET /api/gateway/jobs/{id}` / `POST …/cancel` | E |
/// | `download_job` | = `job` (default) | `GET /api/gateway/models/download/{id}` (a `grp_…` group too) | E |
/// | `cancel_download` | = `cancel_job` (default) | `POST /api/gateway/models/download/{id}/cancel {"via":"console"}` | E |
/// | `models_catalog_hub` | `abstractcore models search Q --hub --json` | `GET /api/gateway/models/catalog?q=&hub=true` | C |
/// | `download_jobs` | the transport's own download children | `GET /api/gateway/models/downloads` | E |
/// | `capability_defaults` | `abstractcore config defaults --json` | `GET /api/gateway/config/capability-defaults` | — |
/// | `set_text_default` | `abstractcore config set-default output.text --provider P --model M --base-url "" --reasoning "" --option ""` | `PUT /api/gateway/config/capability-defaults/output/text {provider, model, base_url: "", reasoning: "", options: {}}` | — |
/// | `engine_install_at` | — (auto only) | `POST /api/gateway/engines/{id}/install {dry_run, location}` | E |
/// | `engine_job_continue` | — | `POST /api/gateway/engines/jobs/{id}/continue {action}` | E |
/// | `engine_server` | — | `POST /api/gateway/engines/{id}/start\|stop` | — |
///
/// The rows from `models_catalog_hub` down are OPTIONAL (default:
/// [`TransportErrorKind::Unsupported`]); [`ConsoleTransport::capabilities`]
/// names the ones a transport implements.
///
/// The three verbs return a `host_job_v1` document; a job that is not
/// yet terminal is polled with [`ConsoleTransport::job`].
pub trait ConsoleTransport: Send + Sync {
    /// Contract A: the machine the models would run on.
    fn host_profile(&self) -> Result<Value, TransportError>;
    /// Contract B: every engine, installed or not. `probe` asks the
    /// backend to also contact local servers (slower, fresher).
    fn engines_status(&self, probe: bool) -> Result<Value, TransportError>;
    /// Contract C: the catalog, filtered by free text, engine and fit.
    fn models_catalog(
        &self,
        q: &str,
        engine: Option<&str>,
        fits_only: bool,
    ) -> Result<Value, TransportError>;
    /// Contract D: what is on disk now, per engine.
    fn models_installed(&self, provider: Option<&str>) -> Result<Value, TransportError>;
    /// Contract E: start (or join) a download job. `expected_bytes` is
    /// the catalog's own size for the artifact when the catalog vouches
    /// for it ([`ArtifactRow::expected_bytes`]); a backend that can
    /// pre-check the disk with it must forward it (the gateway's
    /// `expected_bytes` body field, the web console's rule).
    ///
    /// [`ArtifactRow::expected_bytes`]: crate::screens::ArtifactRow::expected_bytes
    fn start_download(
        &self,
        provider: &str,
        artifact: &str,
        expected_bytes: Option<u64>,
    ) -> Result<Value, TransportError>;
    /// Contract E: delete an installed artifact. Without `force` the
    /// backend refuses a loaded model or a shared cache
    /// ([`TransportErrorKind::Refused`], blockers in the body).
    fn delete_model(
        &self,
        provider: &str,
        artifact: &str,
        force: bool,
    ) -> Result<Value, TransportError>;
    /// Contract E: install an engine on the backend's HOST. `dry_run`
    /// returns the job that WOULD run (its `command`) without running it.
    fn engine_install(&self, id: &str, dry_run: bool) -> Result<Value, TransportError>;
    /// Contract E: one job's current state.
    fn job(&self, id: &str) -> Result<Value, TransportError>;
    /// Contract E: stop a running job; returns the job after the request.
    fn cancel_job(&self, id: &str) -> Result<Value, TransportError>;

    /// Where installs and deletes RUN, in words — the install prompt
    /// says "runs on host X". Additive to contract H with a default:
    /// the CLI transport names this machine, the gateway transport
    /// should name the gateway host.
    fn host_label(&self) -> String {
        "this machine".to_string()
    }

    // ---- optional verbs (0.3.0) ------------------------------------
    //
    // Every verb below has a default that answers
    // [`TransportErrorKind::Unsupported`], and [`capabilities`] says
    // which ones a transport really implements — the screens grey a
    // verb out (footer: "not here") instead of calling a default.
    //
    // [`capabilities`]: ConsoleTransport::capabilities

    /// Cancel a MODEL DOWNLOAD (or a "download all" group). The web
    /// console cancels downloads on their own route so the job records
    /// who asked (gateway `POST /models/download/{id}/cancel
    /// {"via":"console"}`); the default is the generic
    /// [`cancel_job`](ConsoleTransport::cancel_job), which is what the
    /// CLI transport's child jobs need.
    fn cancel_download(&self, id: &str) -> Result<Value, TransportError> {
        self.cancel_job(id)
    }

    /// One MODEL DOWNLOAD's current state — a "download all" group
    /// (`download_group`) included, which only the download route knows
    /// (gateway `GET /models/download/{id}`, answering `{"job": …}`: a
    /// transport returns the job itself). The default is the generic
    /// [`job`](ConsoleTransport::job), which is what the CLI transport's
    /// child jobs need. The screens poll every download through this.
    fn download_job(&self, id: &str) -> Result<Value, TransportError> {
        self.job(id)
    }

    /// Which optional verbs this transport implements.
    fn capabilities(&self) -> TransportCaps {
        TransportCaps::default()
    }

    /// Contract C with the Hugging Face hub: exact sizes and hub search
    /// rows for `q` (CLI `models search Q --hub`, gateway
    /// `GET /models/catalog?q=&hub=true`).
    fn models_catalog_hub(
        &self,
        q: &str,
        engine: Option<&str>,
        fits_only: bool,
    ) -> Result<Value, TransportError> {
        let _ = (q, engine, fits_only);
        Err(TransportError::unsupported(
            "this backend cannot search Hugging Face",
        ))
    }

    /// Every download job the backend knows, newest first: `{"jobs":
    /// [host_job_v1, …]}` (gateway `GET /models/downloads`; the CLI
    /// transport lists the children it owns). Lets the Models screen
    /// re-attach to downloads started elsewhere or before a restart.
    fn download_jobs(&self) -> Result<Value, TransportError> {
        Err(TransportError::unsupported(
            "this backend cannot list its downloads",
        ))
    }

    /// The capability routing defaults document (`{"routes": [{key,
    /// provider, model, …}]}`: CLI `config defaults --json`, gateway
    /// `GET /config/capability-defaults` — the same shape).
    fn capability_defaults(&self) -> Result<Value, TransportError> {
        Err(TransportError::unsupported(
            "this backend cannot read the capability defaults",
        ))
    }

    /// Make `provider`/`model` the default TEXT model (route
    /// `output.text`) and answer the refreshed defaults document.
    ///
    /// The route becomes EXACTLY this model: the write also clears the
    /// row's `base_url`, `reasoning` and `options`. Those described the
    /// PREVIOUS model — a kept `base_url` pointed an Ollama model at LM
    /// Studio's port, a kept reasoning level or speculation option names
    /// a model that is no longer the route's. CLI: `config set-default
    /// output.text --provider P --model M --base-url "" --reasoning ""
    /// --option ""` then `config defaults --json`; gateway `PUT
    /// /config/capability-defaults/output/text {provider, model,
    /// base_url: "", reasoning: "", options: {}}`.
    fn set_text_default(&self, provider: &str, model: &str) -> Result<Value, TransportError> {
        let _ = (provider, model);
        Err(TransportError::unsupported(
            "this backend cannot change the default text model",
        ))
    }

    /// [`engine_install`](ConsoleTransport::engine_install) with an
    /// install location (app engines on macOS: `user` = ~/Applications,
    /// `system` = /Applications). The default runs `Auto` as a plain
    /// install and answers `Unsupported` for anything else.
    fn engine_install_at(
        &self,
        id: &str,
        dry_run: bool,
        location: InstallLocation,
    ) -> Result<Value, TransportError> {
        match location {
            InstallLocation::Auto => self.engine_install(id, dry_run),
            other => Err(TransportError::unsupported(format!(
                "this backend cannot choose where an engine is installed ({})",
                other.as_str()
            ))),
        }
    }

    /// Resume an engine install job paused in `needs_admin` /
    /// `needs_tools` (`action` = one of the job's `continue_actions`;
    /// `None` = the backend's default). Answers the job.
    fn engine_job_continue(
        &self,
        job_id: &str,
        action: Option<&str>,
    ) -> Result<Value, TransportError> {
        let _ = (job_id, action);
        Err(TransportError::unsupported(
            "this backend cannot continue a paused install",
        ))
    }

    /// Start or stop a local engine SERVER (Ollama, LM Studio). Answers
    /// `{running, message, …}` after the server answered (or not).
    fn engine_server(&self, id: &str, action: ServerAction) -> Result<Value, TransportError> {
        let _ = (id, action);
        Err(TransportError::unsupported(
            "this backend cannot start or stop engine servers",
        ))
    }
}

/// Which optional [`ConsoleTransport`] verbs a transport implements.
/// All `false` by default: a transport opts in verb by verb.
///
/// `#[non_exhaustive]`: every new optional verb adds a flag. Build one
/// from [`TransportCaps::ALL`] or `TransportCaps::default()` and set
/// fields (`let mut c = TransportCaps::default(); c.hub_search = true;`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct TransportCaps {
    /// [`ConsoleTransport::models_catalog_hub`].
    pub hub_search: bool,
    /// [`ConsoleTransport::capability_defaults`] +
    /// [`ConsoleTransport::set_text_default`].
    pub text_default: bool,
    /// [`ConsoleTransport::download_jobs`].
    pub downloads_feed: bool,
    /// [`ConsoleTransport::engine_job_continue`].
    pub engine_continue: bool,
    /// [`ConsoleTransport::engine_server`].
    pub engine_server: bool,
    /// [`ConsoleTransport::engine_install_at`] beyond `Auto`.
    pub install_location: bool,
}

impl TransportCaps {
    /// Every optional verb (a full backend such as the gateway).
    pub const ALL: TransportCaps = TransportCaps {
        hub_search: true,
        text_default: true,
        downloads_feed: true,
        engine_continue: true,
        engine_server: true,
        install_location: true,
    };
}

/// Where an app engine is installed (gateway `location`).
///
/// `#[non_exhaustive]`: the backend's location vocabulary may grow.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum InstallLocation {
    /// The backend decides (/Applications when writable, else
    /// ~/Applications).
    #[default]
    Auto,
    /// Just this account (~/Applications): never a password.
    User,
    /// Every account (/Applications): an administrator step when this
    /// account cannot write there.
    System,
}

impl InstallLocation {
    /// The wire word: `auto` / `user` / `system`.
    pub fn as_str(self) -> &'static str {
        match self {
            InstallLocation::Auto => "auto",
            InstallLocation::User => "user",
            InstallLocation::System => "system",
        }
    }
}

/// [`ConsoleTransport::engine_server`]'s verb.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ServerAction {
    Start,
    Stop,
}

impl ServerAction {
    /// The wire word: `start` / `stop`.
    pub fn as_str(self) -> &'static str {
        match self {
            ServerAction::Start => "start",
            ServerAction::Stop => "stop",
        }
    }
}

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

    #[test]
    fn reasons_collect_blockers_and_error() {
        let e = TransportError::refused(
            "model is loaded",
            Some(json!({"delete_blockers": ["loaded"], "error": "unload it first"})),
        );
        assert!(e.is_refused());
        assert_eq!(e.reasons(), vec!["loaded", "unload it first"]);
        assert_eq!(e.to_string(), "refused: model is loaded");
        assert!(TransportError::failed("x").reasons().is_empty());
    }

    struct Bare;
    impl ConsoleTransport for Bare {
        fn host_profile(&self) -> Result<Value, TransportError> {
            Ok(json!({}))
        }
        fn engines_status(&self, _p: bool) -> Result<Value, TransportError> {
            Ok(json!({}))
        }
        fn models_catalog(
            &self,
            _q: &str,
            _e: Option<&str>,
            _f: bool,
        ) -> Result<Value, TransportError> {
            Ok(json!({}))
        }
        fn models_installed(&self, _p: Option<&str>) -> Result<Value, TransportError> {
            Ok(json!({}))
        }
        fn start_download(
            &self,
            _p: &str,
            _a: &str,
            _b: Option<u64>,
        ) -> Result<Value, TransportError> {
            Ok(json!({}))
        }
        fn delete_model(&self, _p: &str, _a: &str, _f: bool) -> Result<Value, TransportError> {
            Ok(json!({}))
        }
        fn engine_install(&self, id: &str, _d: bool) -> Result<Value, TransportError> {
            Ok(json!({"engine": id}))
        }
        fn job(&self, id: &str) -> Result<Value, TransportError> {
            Ok(json!({"job_id": id, "via": "job"}))
        }
        fn cancel_job(&self, id: &str) -> Result<Value, TransportError> {
            Ok(json!({"job_id": id, "via": "cancel_job"}))
        }
    }

    #[test]
    fn optional_verbs_default_to_unsupported_never_a_fake() {
        let t = Bare;
        assert_eq!(t.capabilities(), TransportCaps::default());
        for e in [
            t.models_catalog_hub("q", None, false).unwrap_err(),
            t.download_jobs().unwrap_err(),
            t.capability_defaults().unwrap_err(),
            t.set_text_default("p", "m").unwrap_err(),
            t.engine_job_continue("j", None).unwrap_err(),
            t.engine_server("ollama", ServerAction::Start).unwrap_err(),
            t.engine_install_at("ollama", false, InstallLocation::User)
                .unwrap_err(),
        ] {
            assert_eq!(e.kind, TransportErrorKind::Unsupported, "{e}");
            assert_eq!(e.headline(), "not available here");
        }
        // Auto is just an install.
        assert_eq!(
            t.engine_install_at("ollama", false, InstallLocation::Auto)
                .unwrap()["engine"],
            "ollama"
        );
        // The download verbs default to the generic job verbs.
        assert_eq!(t.download_job("dl_1").unwrap()["via"], "job");
        assert_eq!(t.cancel_download("dl_1").unwrap()["via"], "cancel_job");
    }
}