isothrum-runner 3.0.2

The Isothrum runner: runs a Compose project, a Vagrantfile or a Terraform module through its own tool (lifecycle, state and locks, the format drivers, events).
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
//! The Vagrant driver: a Vagrantfile's machines, on the provider the run asks for, through
//! `vagrant` with its dotfile folder in the run's state folder ([`dotfile`]), so a replaced
//! project folder never loses track of its VMs. The run's inputs and key reach the Vagrantfile in
//! the tool's environment ([`ToolCx::env`]), which it reads with `ENV.fetch`: the file is never
//! rewritten.
//!
//! | Operation | Vagrant |
//! |---|---|
//! | up | the preamble, then `up --provider <p>`: ready once it exits 0, after the last provisioner |
//! | down | `destroy -f`, then the dotfile reset (what is left by id goes to [`FormatDriver::destroy_by_id`]) |
//! | park | `suspend` (Pause), `halt` (Shutdown) |
//! | resume | refused naming the machines destroyed outside the run ([`gone`]); else the preamble, then `up --provider <p> --no-provision` |
//! | update, provision | `up --provider <p> --provision [machine]` |
//! | attach, retire | `up --provider <p> <machine>`, `destroy -f <machine>` |
//! | exec, console | `ssh <machine> -c <command>`; a console is `ssh <machine>` with a terminal |
//! | observe | `status --machine-readable`, then `port <machine>` of each running one, each forward's protocol from the Vagrantfile's line ([`protocols`]); a machine `not_created` whose VM the store records as made is gone ([`gone`]) |
//! | found | the dotfile's `machines/<machine>/<provider>/id` |
//! | machines | the machines `status` lists, whether made or not |
//! | reapply | `up <added>`, `destroy -f <removed>`, `provision <changed>` |
//! | graphical, native console | the hypervisor, by the VM's recorded id ([`screen`]) |
//!
//! The preamble: a record of the run on another provider than the one asked is destroyed and the
//! dotfile reset (`up` would refuse "a machine with a different provider"); a VirtualBox VM whose
//! saved state was cut off (`aborted-saved`) has it discarded. Recovery: an `up` refused because
//! an earlier VM holds the name (`VERR_ALREADY_EXISTS`, a folder that can't be renamed) or a record
//! is on another provider removes what the run made, by the dotfile's ids and, on VirtualBox, the
//! VMs and folders whose name carries the run's key as a word; then it starts once more. A call
//! another Vagrant process's lock refused is made again ([`lock`]).

mod booting;
mod busy;
mod clear;
mod dotfile;
mod failures;
mod fetched;
mod forwards;
mod gone;
mod lock;
mod names;
mod passing;
mod preamble;
mod progress;
mod protocols;
mod providers;
mod screen;
use names::{checked_user, key_of, of_key, one, ours, own_address, verb_word};
mod vmnet;

use std::time::Duration;

use self::dotfile::{Dotfile, Record};
use self::failures::vagrant_error;
use self::lock::{PATIENCE, Rerun, STATUS_PATIENCE, retrying};
use self::protocols::Declared;
use super::{Change, FormatDriver, Found, Ran, Seen, SeenMachine, SeenPort, ToolCx, tool_error};
use crate::Result;
use crate::cli::vagrant::{self, Failure, Provision, Verb};
use crate::cli::{Call, CliError, vboxmanage};
use crate::console::ShellCommand;
use crate::error::{Error, ProviderNeed};
use crate::events::WarningCode;
use crate::project::platform::Provider;
use crate::state::{Park, RunState};
use crate::status::MachineState;
use crate::store::{Lifetime, ResourceKind};

/// How long an `up` may take: boxes fetched, every VM booted and provisioned.
const UP_LIMIT: Duration = Duration::from_secs(3600);

/// How long a lifecycle call that makes nothing may take (halt, suspend, destroy).
const CALL_LIMIT: Duration = Duration::from_secs(900);

/// How long the clean-up destroy of a record on another provider may take before the record is
/// dropped anyway: a wedged hypervisor must not hang a start.
const RECONCILE_LIMIT: Duration = Duration::from_secs(180);

/// How long a read may take (`status`, `port`, a version, the plugins, a VM's state).
const READ_LIMIT: Duration = Duration::from_secs(120);

/// The Vagrant driver.
#[derive(Debug, Clone, Copy, Default)]
pub(crate) struct Vagrant;

/// A call of `vagrant` (or of the hypervisor's tool) for `cx`, with the dotfile folder set.
fn call<'a>(cx: &'a ToolCx<'_>, limit: Duration) -> Call<'a> {
    let mut call = cx.call(limit);
    call.env.retain(|(k, _)| k != dotfile::VAR);
    call.env.push((dotfile::VAR.to_owned(), dot(cx).path.display().to_string()));
    call
}

/// A read of Vagrant (its status, a machine's ports, its version): [`call`] whose lines aren't
/// said in the operation's log.
fn read<'a>(cx: &'a ToolCx<'_>, limit: Duration) -> Call<'a> {
    Call {
        sink: &super::discard,
        ..call(cx, limit)
    }
}

/// The run's dotfile folder.
fn dot(cx: &ToolCx<'_>) -> Dotfile {
    Dotfile::in_state(cx.state_dir)
}

/// How a start's `up` provisions: as Vagrant does by default on a run with no VM yet, and
/// always (`--provision`) once one is recorded, made by a start that didn't end well (killed,
/// its machine still booting, a provisioner failed). Vagrant marks a machine provisioned before
/// its provisioners run, so its default would skip the set-up that start never finished.
fn up_provision(cx: &ToolCx<'_>) -> Result<Provision> {
    Ok(if dot(cx).recorded()?.is_empty() { Provision::Default } else { Provision::Yes })
}

/// The provider asked for, refused when there is none.
fn asked(cx: &ToolCx<'_>) -> Result<Provider> {
    cx.provider.ok_or_else(|| Error::NoProvider {
        providers: providers::listed_for(providers::this_host()),
    })
}

impl Vagrant {
    /// `up` of `machines` (all when empty) on the provider asked for, made again while another
    /// process's lock refuses it and a second run is safe.
    /// One a passing failure cut short is made once more ([`passing::once_more`]: an Apple event
    /// on UTM, a host-only network VMware made but said it couldn't enable); one a machine still
    /// booting failed is made again once it may answer ([`booting::until_it_answers`]).
    /// The boxes it added are recorded, however it ended ([`fetched`]).
    /// Its lines say its steps ([`progress`]), done once it went through. On VMware on Windows,
    /// the private networks' host adapters are then given their address ([`vmnet`]).
    async fn up_call(&self, cx: &ToolCx<'_>, step: &str, provision: Provision, machines: &[String]) -> std::result::Result<(), CliError<Failure>> {
        let provider = cx.provider.map(Provider::id);
        let rerun = if provision == Provision::Yes { Rerun::Repeats } else { Rerun::Converges };
        let watch = progress::Watch::new(&cx.steps);
        let sink = |stream: crate::events::Stream, line: &str| {
            watch.see(line);
            (cx.sink)(stream, line);
        };
        let call = &Call {
            sink: &sink,
            ..call(cx, UP_LIMIT)
        };
        let up = booting::until_it_answers(cx, step, move || {
            passing::once_more(cx, step, move || {
                retrying(cx.warn, step, rerun, PATIENCE, move || vagrant::up(call, provider, provision, machines))
            })
        });
        let done = fetched::recording(cx, up).await;
        if done.is_ok() {
            vmnet::address_host_adapters(cx, providers::this_host()).await;
            cx.steps.end(true);
        }
        done
    }

    /// `verb` on `machines` (all when empty), made again as [`Rerun`] allows.
    async fn act(&self, cx: &ToolCx<'_>, verb: Verb, machines: &[String], limit: Duration) -> std::result::Result<(), CliError<Failure>> {
        let rerun = match verb {
            Verb::Halt | Verb::Suspend | Verb::Destroy => Rerun::Converges,
            Verb::Provision => Rerun::Repeats,
        };
        let call = call(cx, limit);
        retrying(cx.warn, verb_word(verb), rerun, PATIENCE, || vagrant::act(&call, verb, machines)).await
    }

    /// Each machine `status` lists, with its state label.
    async fn status(&self, cx: &ToolCx<'_>) -> Result<std::collections::BTreeMap<String, String>> {
        self.read_states(cx).await.map_err(|e| vagrant_error(cx, "status", e))
    }

    /// [`Vagrant::status`], its failure as Vagrant's (a lock another process holds).
    async fn read_states(&self, cx: &ToolCx<'_>) -> std::result::Result<std::collections::BTreeMap<String, String>, CliError<Failure>> {
        let call = read(cx, READ_LIMIT);
        let read = retrying(cx.warn, "status", Rerun::Read, STATUS_PATIENCE, || vagrant::status(&call)).await?;
        Ok(read.states)
    }

    /// `up` as asked, with one recovery: a name an earlier VM holds, or a record on another
    /// provider, clears what the run made ([`Vagrant::clear`]) and starts once more.
    async fn up_recovering(&self, cx: &ToolCx<'_>, step: &str, provision: Provision, machines: &[String]) -> Result<()> {
        match self.up_call(cx, step, provision, machines).await {
            Ok(()) => Ok(()),
            Err(CliError::Failed {
                failure: Failure::AlreadyExists | Failure::OtherProvider,
                ..
            }) => {
                tracing::info!(run = %cx.run, "an earlier start's VM holds a name of the run: removing what the run made, then starting again");
                self.clear(cx).await?;
                self.up_call(cx, step, provision, machines).await.map_err(|e| vagrant_error(cx, step, e))
            }
            Err(e) => Err(vagrant_error(cx, step, e)),
        }
    }
}

impl FormatDriver for Vagrant {
    /// Not after a start that didn't end well: a VM running says nothing of the provisioning that
    /// start never finished (one killed while Vagrant provisioned it), and a machine it never
    /// reached reads `not_created`, which doesn't count ([`gone::run_state`]); read ready, the run
    /// would refuse the next `up` as already running. A run failed otherwise (a VM that died,
    /// booted again from its hypervisor's app) is ready again once its VMs all run.
    fn ready_by_observation(&self, failed_start: bool) -> bool {
        !failed_start
    }

    /// Hyper-V takes its management commands from an administrator only.
    fn elevates(&self, provider: Option<Provider>) -> bool {
        provider == Some(Provider::Hyperv)
    }

    async fn probe(&self, cx: &ToolCx<'_>) -> Result<()> {
        let provider = asked(cx)?;
        let host = providers::this_host();
        let refuse_for = |need: Option<ProviderNeed>, reason: String| Error::Provider {
            need,
            provider: provider.id().to_owned(),
            reason,
        };
        let refuse = |reason: String| refuse_for(None, reason);
        if !providers::hosts(provider).contains(&host) {
            return Err(refuse(format!(
                "doesn't run on this computer's system; these do: {}",
                providers::listed_for(host)
            )));
        }
        let read = read(cx, READ_LIMIT);
        let found = vagrant::supported_version(&read).await.map_err(|e| vagrant_error(cx, "tools", e))?;
        super::unknown_version(cx, found.as_ref(), "vagrant", vagrant::MIN_VERSION);
        if let Some(plugin) = provider.plugin() {
            let installed = vagrant::plugins(&read).await.map_err(|e| vagrant_error(cx, "tools", e))?;
            if !installed.iter().any(|(name, _)| name == plugin) {
                return Err(refuse_for(
                    Some(ProviderNeed::Plugin),
                    format!("needs the Vagrant plugin `{plugin}`: `vagrant plugin install {plugin}`"),
                ));
            }
        }
        Ok(())
    }

    async fn up(&self, cx: &ToolCx<'_>) -> Result<()> {
        let provider = asked(cx)?;
        crate::store::create_dir(cx.state_dir)?;
        self.preamble(cx, provider).await?;
        self.up_recovering(cx, "up", up_provision(cx)?, &[]).await
    }

    async fn down(&self, cx: &ToolCx<'_>) -> Result<()> {
        self.act(cx, Verb::Destroy, &[], CALL_LIMIT).await.map_err(|e| vagrant_error(cx, "down", e))?;
        // What `destroy` took is gone from the dotfile; a VM it left keeps its resource row, which
        // the core removes by id (`destroy_by_id`), with its record written back if need be.
        dot(cx).reset()
    }

    async fn park(&self, cx: &ToolCx<'_>, mode: Park) -> Result<()> {
        let verb = match mode {
            Park::Pause => Verb::Suspend,
            Park::Shutdown => Verb::Halt,
        };
        match self.act(cx, verb, &[], CALL_LIMIT).await {
            // ESXi refuses to halt a VM already off: halted is what was asked.
            Ok(())
            | Err(CliError::Failed {
                failure: Failure::AlreadyOff, ..
            }) => Ok(()),
            Err(e) => Err(vagrant_error(cx, "park", e)),
        }
    }

    async fn resume(&self, cx: &ToolCx<'_>) -> Result<()> {
        let provider = asked(cx)?;
        self.refuse_resume_if_gone(cx).await?;
        self.preamble(cx, provider).await?;
        self.up_recovering(cx, "resume", Provision::No, &[]).await
    }

    async fn update(&self, cx: &ToolCx<'_>) -> Result<()> {
        asked(cx)?;
        self.up_call(cx, "update", Provision::Yes, &[])
            .await
            .map_err(|e| vagrant_error(cx, "update", e))
    }

    async fn machines(&self, cx: &ToolCx<'_>) -> Result<Vec<String>> {
        Ok(self.status(cx).await?.into_keys().collect())
    }

    async fn reapply(&self, cx: &ToolCx<'_>, change: &Change) -> Result<()> {
        if !change.added.is_empty() {
            asked(cx)?;
            self.up_call(cx, "reapply", Provision::Default, &change.added)
                .await
                .map_err(|e| vagrant_error(cx, "reapply", e))?;
        }
        if !change.removed.is_empty() {
            // Vagrant acts only on machines the Vagrantfile defines: one it no longer does is
            // removed by its recorded id.
            let defined = self.machines(cx).await?;
            let (known, gone): (Vec<String>, Vec<String>) = change.removed.iter().cloned().partition(|m| defined.contains(m));
            if !known.is_empty() {
                self.act(cx, Verb::Destroy, &known, CALL_LIMIT)
                    .await
                    .map_err(|e| vagrant_error(cx, "reapply", e))?;
            }
            for r in dot(cx).recorded()?.into_iter().filter(|r| gone.contains(&r.machine)) {
                self.remove_at_hypervisor(cx, &r).await?;
            }
        }
        if !change.changed.is_empty() {
            self.act(cx, Verb::Provision, &change.changed, UP_LIMIT)
                .await
                .map_err(|e| vagrant_error(cx, "reapply", e))?;
        }
        Ok(())
    }

    async fn provision(&self, cx: &ToolCx<'_>, machine: Option<&str>, with: Option<&str>) -> Result<()> {
        asked(cx)?;
        let machines: Vec<String> = machine.map(one).unwrap_or_default();
        let Some(name) = with else {
            return self
                .up_call(cx, "provision", Provision::Yes, &machines)
                .await
                .map_err(|e| vagrant_error(cx, "provision", e));
        };
        // One provisioner on machines that run: nothing else of their set-up runs again.
        let name = vagrant::ProvisionerName::new(name).ok_or_else(|| Error::Input {
            name: "provisioner".to_owned(),
            reason: format!("`{name}` isn't a provisioner's name (letters, digits, `-`, `_`)"),
        })?;
        let call = call(cx, super::CHECK_LIMIT);
        retrying(cx.warn, "provision", Rerun::Repeats, PATIENCE, || {
            vagrant::provision_with(&call, &name, &machines)
        })
        .await
        .map_err(|e| vagrant_error(cx, "provision", e))
    }

    async fn attach(&self, cx: &ToolCx<'_>, machine: &str) -> Result<()> {
        asked(cx)?;
        self.up_call(cx, "attach", Provision::Default, &one(machine))
            .await
            .map_err(|e| vagrant_error(cx, "attach", e))
    }

    async fn retire(&self, cx: &ToolCx<'_>, machine: &str) -> Result<()> {
        self.act(cx, Verb::Destroy, &one(machine), CALL_LIMIT)
            .await
            .map_err(|e| vagrant_error(cx, "retire", e))
    }

    async fn package(&self, cx: &ToolCx<'_>, machine: &str, output: &std::path::Path) -> Result<()> {
        asked(cx)?;
        // Halting and exporting a whole disk: as long as a start may take.
        vagrant::package(&call(cx, UP_LIMIT), machine, output)
            .await
            .map_err(|e| vagrant_error(cx, "package", e))
    }

    async fn exec(&self, cx: &ToolCx<'_>, machine: &str, argv: &[String]) -> Result<Ran> {
        let script = argv.iter().map(|w| crate::console::sh_word(w)).collect::<Vec<_>>().join(" ");
        let out = vagrant::ssh_run(&call(cx, super::CHECK_LIMIT), machine, &script)
            .await
            .map_err(|e| vagrant_error(cx, "exec", e))?;
        Ok(Ran {
            exit: out.exit.code.unwrap_or(-1),
            stdout: out.stdout.join("\n"),
            stderr: out.stderr_tail.join("\n"),
        })
    }

    fn console(&self, cx: &ToolCx<'_>, machine: &str, user: Option<&str>) -> impl Future<Output = Result<ShellCommand>> {
        let script = user.map(checked_user).transpose().map(|u| u.map(crate::console::shells::login_shell_as));
        std::future::ready(script.map(|script| {
            let spec = vagrant::console_spec(&call(cx, READ_LIMIT), machine, script.as_deref());
            ShellCommand::of_spec(spec, &cx.project.dir)
        }))
    }

    async fn observe(&self, cx: &ToolCx<'_>) -> Result<(Seen, RunState)> {
        let read = read(cx, READ_LIMIT);
        let records = dot(cx).recorded()?;
        let mut machines = Vec::new();
        let states = match self.read_states(cx).await {
            Ok(states) => states,
            // Another process acts on these machines (a start, a provision from a terminal) past
            // the read's patience: they are busy, the rest as last read.
            Err(CliError::Failed {
                failure: Failure::Locked { machines: named, .. },
                ..
            }) if !named.is_empty() => return Ok((busy::busy(named), RunState::Ready)),
            Err(e) => return Err(vagrant_error(cx, "status", e)),
        };
        // A machine destroyed outside the run reads absent, as one never made, but fails the run.
        let gone = gone::gone(cx, &states)?;
        let declared = cx.project.files.first().map(|f| Declared::of_file(f)).unwrap_or_default();
        for (name, label) in states {
            let state = crate::tool_output::vagrant::machine_state(&label);
            // The provider it was made on, as the dotfile records it (the one asked for, unless a
            // record was left on another).
            let asked = cx.provider.map(Provider::id);
            let mine = records.iter().filter(|r| r.machine == name);
            let kind = mine
                .clone()
                .find(|r| Some(r.provider.as_str()) == asked)
                .or_else(|| mine.clone().next())
                .map(|r| r.provider.clone());
            let mut published = Vec::new();
            if state == MachineState::Running {
                match retrying(cx.warn, "port", Rerun::Read, STATUS_PATIENCE, || vagrant::port(&read, &name)).await {
                    // `port` doesn't say a forward's protocol: the Vagrantfile's line does, else
                    // it is left unknown, never guessed.
                    Ok(forwards) => published.extend(forwards.into_iter().map(|f| SeenPort {
                        protocol: declared.protocol(&name, f.guest.get()),
                        guest: f.guest,
                        host: f.host,
                    })),
                    // vagrant-qemu can't list them: its QEMU says them. libvirt can't either, and
                    // ESXi forwards nothing: no port is proven.
                    Err(CliError::Failed {
                        failure: Failure::PortsUnsupported,
                        ..
                    }) => {
                        if kind.as_deref() == Some(Provider::Qemu.id()) {
                            published.extend(forwards::of_qemu(cx, &name).await);
                        }
                    }
                    Err(e) => return Err(vagrant_error(cx, "status", e)),
                }
            }
            let address = if state == MachineState::Running && kind.as_deref().is_some_and(own_address) {
                self.address(cx, &name).await
            } else {
                None
            };
            machines.push(SeenMachine {
                name,
                state,
                published,
                kind,
                address,
                windows: false,
            });
        }
        let state = gone::run_state(&machines, &gone);
        Ok((Seen { machines, ..Seen::default() }, state))
    }

    /// Read from the dotfile: no call.
    fn found(&self, cx: &ToolCx<'_>) -> impl Future<Output = Result<Vec<Found>>> {
        let found = dot(cx).recorded().map(|records| {
            records
                .into_iter()
                .map(|r| Found {
                    key: key_of(&r, cx.provider),
                    kind: ResourceKind::Vm,
                    native_id: r.id,
                    lifetime: Lifetime::Machines,
                })
                .collect()
        });
        std::future::ready(found)
    }

    async fn destroy_by_id(&self, cx: &ToolCx<'_>, key: &str, kind: ResourceKind, native_id: &str) -> Result<()> {
        let refused = || Error::Unsupported {
            what: format!("removing the {kind:?} resource `{key}` through Vagrant"),
        };
        if kind != ResourceKind::Vm {
            return Err(refused());
        }
        let (machine, provider) = of_key(key, cx.provider).ok_or_else(refused)?;
        let dot = dot(cx);
        let recorded = dot.recorded()?;
        let record = if let Some(r) = recorded.into_iter().find(|r| r.id == native_id) {
            r
        } else {
            let Some(provider) = provider else {
                return Err(Error::NoProvider {
                    providers: providers::listed_for(providers::this_host()),
                });
            };
            let lost = Record {
                machine,
                provider,
                id: native_id.to_owned(),
            };
            // Vagrant acts on a VM by the id its dotfile records: written back, `destroy` takes
            // the VM whose record a reset or a crash lost.
            dot.write_back(&lost)?;
            lost
        };
        match self.act(cx, Verb::Destroy, &one(&record.machine), CALL_LIMIT).await {
            Ok(()) => dot.forget(&record.machine, &record.provider),
            // A machine the Vagrantfile no longer defines: its VM goes at the hypervisor.
            Err(CliError::Failed {
                failure: Failure::UnknownMachine,
                ..
            }) => self.remove_at_hypervisor(cx, &record).await,
            Err(e) => Err(vagrant_error(cx, "remove", e)),
        }
    }

    async fn graphical(&self, cx: &ToolCx<'_>, _seen: &Seen, machine: &SeenMachine) -> Result<Option<crate::graphical::ConsoleOffer>> {
        Ok(screen::offer(cx, machine).await)
    }

    async fn reach_graphical(&self, cx: &ToolCx<'_>, machine: &str) -> Result<crate::graphical::Console> {
        screen::reach(cx, machine).await
    }

    fn native_app(&self, cx: &ToolCx<'_>, seen: &Seen) -> Option<crate::graphical::NativeApp> {
        screen::app(cx, seen)
    }

    async fn native_console(&self, cx: &ToolCx<'_>, machine: &str) -> Result<crate::graphical::NativeConsole> {
        screen::native(cx, machine).await
    }
}

#[cfg(test)]
mod tests;