mariadb-cli 0.1.1

One-shot agent-native command line client for MariaDB servers
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
//! Routing one parsed invocation to the command that serves it.
//!
//! This is the only place that decides whether a connection is needed. A
//! command that reaches no server never pays for one, and a command that does
//! gets a session opened, used and closed inside this invocation.
//!
//! # Where each budget is applied
//!
//! Reaching the server is bounded from here, because the driver has no option
//! of its own for it. Running a statement is bounded from here as well, but as
//! the second line: the server was already asked, as the connection opened, to
//! stop any statement that outruns the budget on its own.

pub mod context;
mod fanout;
pub mod flow;
mod open;
pub mod preflight;

use crate::cli::{Cli, Command};
use crate::commands;
use crate::config::vault::FileVault;
use crate::config::Config;
use crate::conn::store::ProfileStore;
use crate::error::{Failure, Result};
use crate::output::Envelope;
use crate::runtime::Shutdown;

/// Everything one connected command runs under.
///
/// Gathered into one value so the call chain carries a single argument rather
/// than half a dozen that must stay in the same order at every hop.
struct Work<'a> {
    cli: &'a Cli,
    config: &'a Config,
    shutdown: &'a Shutdown,
    /// The database every command falls back to, pinned to the destination.
    scope: Option<String>,
    /// Whether this invocation is being served against more than one destination.
    ///
    /// A continuous flow writes its rows straight to the primary channel as
    /// they arrive, so two destinations flowing at once would interleave their
    /// rows into a single set nobody can take apart again. Across destinations
    /// the answer is therefore always built as an envelope, which is also what
    /// lets each block carry the name of the destination it came from.
    many: bool,
}

/// Serves one invocation.
///
/// Answers `None` when the work already wrote its rows as a continuous flow,
/// so nothing is left to shape or emit. Every other command answers with the
/// envelope the caller still has to write.
///
/// # Errors
///
/// Returns whatever the served command returns, plus a configuration failure
/// when the settings or the destination cannot be resolved.
pub async fn serve<W: std::io::Write>(
    cli: &Cli,
    out: &mut W,
    shutdown: &Shutdown,
) -> Result<Option<Envelope>> {
    let config_dir = cli.globals.diagnostics.config_dir.as_deref();
    // Loaded before the command is chosen, because almost everything below
    // needs settings resolved and none of it can resolve them itself. The one
    // exception is the command whose whole subject is this failure: refusing to
    // serve `config doctor` because the settings cannot be read is refusing it
    // precisely when it was written to answer. It is served against the
    // built-in values instead, and reports the unreadable file as a finding —
    // which is what `config::doctor::run` was already written to do, and could
    // never be reached to do from here (G-019).
    let config = match Config::load(config_dir) {
        Ok(config) => config,
        Err(unreadable) if diagnoses_the_settings(&cli.command) => {
            Config::with_nothing_stored(config_dir).map_err(|_| unreadable)?
        }
        Err(unreadable) => return Err(unreadable),
    };

    // Settled before anything is served, and deliberately before the families
    // that reach no server. A ceiling outside the domain is a mistake in the
    // invocation itself, so `--max-concurrency 0` has to be refused whatever
    // the command turns out to be; resolving it further down let the mistake
    // through with a successful answer whenever the command needed no
    // destination (FR-067).
    let permits = crate::settings::concurrency(&config, &cli.globals)?;

    if let Some(answered) = unconnected(cli, &config, config_dir)? {
        return Ok(Some(answered));
    }

    with_destination(cli, &config, permits, shutdown, out).await
}

/// Whether this invocation's subject is the state of the settings themselves.
///
/// Kept as a named question rather than an inline match so the exception in
/// [`serve`] reads as the one rule it is, and so widening it later has to be
/// done here, on purpose, where this comment is.
///
/// Only the diagnosis qualifies. `config get`, `config list` and `config set`
/// all report on settings too, but they report on their VALUES, and values read
/// out of a file nobody could parse would be built-in ones presented as stored.
/// The diagnosis is the only one whose answer is about the file itself.
pub(crate) fn diagnoses_the_settings(command: &Command) -> bool {
    matches!(
        command,
        Command::Config(crate::cli::config::ConfigCommand::Doctor)
    )
}

/// Everything that answers without reaching a server.
///
/// Answers `None` when this invocation really does need a destination, so the
/// connection is opened once and only where one is needed.
///
/// # Errors
///
/// Returns the failure of the command it served, and a validation failure when
/// the statement is refused before any byte reaches the network.
fn unconnected(
    cli: &Cli,
    config: &Config,
    config_dir: Option<&std::path::Path>,
) -> Result<Option<Envelope>> {
    // The output contract is the product's own description of itself, so
    // answering it must never depend on a server being reachable.
    if cli.globals.output.print_schema {
        return contract(cli).map(Some);
    }

    match &cli.command {
        Command::Meta(command) => return commands::meta::execute(command, cli).map(Some),
        Command::Config(command) => {
            return commands::config::execute(command, config_dir, cli.globals.safety.dry_run)
                .map(Some)
        }
        Command::Query(command) => {
            // A token of its own, never cancelled, because nothing reached from
            // here can be interrupted: the two calls below refuse a statement
            // by reading its tree and keep one under a name by touching the
            // settings location. Neither opens a connection and neither loops
            // over rows. Handing the real one down would suggest a reach it
            // does not have.
            let context =
                context::query_context(config, cli, tokio_util::sync::CancellationToken::new())?;
            // Everything the analysis can refuse is refused here, before a
            // single byte reaches the network. A doomed statement must never
            // cost a connection, and must never be reported as a network
            // problem.
            preflight::refuse_early(cli, config, &context)?;
            // Resolving where a result column comes from is read from the
            // statement's own tree, and keeping a statement under a name only
            // touches the settings location.
            if let Some(answered) = commands::query::execute_offline(command, &context) {
                return answered.map(Some);
            }
        }
        _ => {}
    }

    Ok(None)
}

/// The output contract of the command this invocation names.
fn contract(cli: &Cli) -> Result<Envelope> {
    let asked = crate::cli::meta::MetaCommand::Schema(crate::cli::meta::SchemaArgs {
        command: Some(cli.command.published_name().to_owned()),
        types: false,
    });
    commands::meta::execute(&asked, cli)
}

/// Builds the runtime this invocation needs and no more.
///
/// One thread, always, and the reason is that a second one could never run
/// anything here. Worker threads only ever execute work that was spawned onto
/// the runtime, and nothing in this process is: every future borrows what the
/// invocation already holds, which makes it not `Send` — `cargo clippy -W
/// clippy::future_not_send` names fifteen such points, across the fan-out, the
/// continuous flow and the opening of a destination — so all of it is driven
/// by the `block_on` running on the calling thread.
///
/// This used to ask for one worker thread per admitted part. Those threads
/// were started, each reserving its own stack, and then parked for the whole
/// life of the process without executing a single poll. The cost was real and
/// the benefit was arithmetically zero, including for the encrypted handshake:
/// CPU work inside a future that is never spawned stays on the calling thread
/// no matter how many workers exist.
///
/// Nothing is lost. The work waits on a server rather than on this CPU, so
/// several parts make progress on one thread as soon as they are polled
/// together, and how many run at once is decided by the admission gate in
/// `runtime::gate`, never by the size of a thread pool.
///
/// # Errors
///
/// Returns a server failure when the runtime cannot be started.
pub fn build_runtime() -> Result<tokio::runtime::Runtime> {
    tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()
        .map_err(|error| {
            Failure::new(
                crate::error::Category::Server,
                "runtime.unavailable",
                "the work runtime could not be started",
            )
            .with_cause(error.to_string())
        })
}

/// Runs one whole invocation with the operating system signals watched.
///
/// # Why the watcher lives here rather than around the connected work alone
///
/// It used to be created and ended around the part of the work that opens a
/// destination, and that left two stretches of the invocation deaf.
///
/// The first is everything served without a connection — the contract, the
/// settings, the statement catalogue — which ran before any watcher existed and
/// so met the operating system's default disposition, ending at 143 where the
/// published table says 130.
///
/// The second is worse and is the reason this moved. Watching a signal installs
/// a handler for the whole process, and a handler is never taken back out: the
/// task that reads it can end, and the handler stays, delivering signals to
/// nobody. So once the connected work returned, everything after it — shaping
/// the answer, signing it, settling the file — ran with both signals installed
/// and observed by nothing at all. The invocation did not merely fail to stop:
/// it could no longer be stopped, which is the one outcome worse than ignoring
/// the caller.
///
/// # Errors
///
/// Returns whatever the work returns, and an interrupted failure when a signal
/// arrived and the work answered anyway.
pub async fn under_signals<T, F>(work: F) -> Result<T>
where
    F: AsyncFnOnce(&Shutdown) -> Result<T>,
{
    let shutdown = Shutdown::new();
    let signals = shutdown.watch_signals();

    let outcome = work(&shutdown).await;

    // Hands the runtime back for one turn before the reason is read. Without
    // it, a signal that arrived while the last stretch of work held the thread
    // would be sitting in the watcher's own queue unread, and this would answer
    // that nothing happened.
    tokio::task::yield_now().await;

    // Read BEFORE asking for the stop, and this order is the whole point.
    //
    // `stop` records a reason of its own, so reading afterwards answered `Some`
    // for every invocation ever made. That is what the previous shape did, and
    // it left both arms of the decision below returning the same value: the
    // match was equivalent to `outcome`, and nothing reached 130 through here.
    // The number still appeared, because the work itself returns an interrupted
    // failure on the paths that loop over rows — which is exactly why a suite
    // measuring those paths stayed green over a decision that decided nothing.
    let signalled = shutdown.reason();

    // Cancelling lets the signal watcher finish on its own, so no task outlives
    // the invocation.
    shutdown.stop(crate::runtime::StopReason::Terminate);
    let _ = signals.await;

    under_signal(outcome, signalled)
}

/// What an invocation answers once the work is done and the signal is known.
///
/// Written as a function of its two inputs rather than inline, because the
/// shape it replaced was a `match` whose arms all returned the same value and
/// nothing could say so. A decision reachable only through a runtime, a
/// destination and a real signal is a decision no proof ever reads; this one is
/// three lines of arithmetic over two arguments, and the proofs below read it.
fn under_signal<T>(outcome: Result<T>, signalled: Option<crate::runtime::StopReason>) -> Result<T> {
    match (outcome, signalled) {
        // A failure of its own says more than the interruption does: the caller
        // who sent the signal already knows they sent it, and does not know
        // that the credential was refused.
        (Err(failure), _) => Err(failure),
        (Ok(answer), None) => Ok(answer),
        // The work answered, and it answered because it was cut short. This is
        // the shape `--all-profiles` produces: every destination still in
        // flight becomes a gap, the blocks already gathered become an envelope,
        // and a Ctrl-C ended in a successful exit describing a partial answer
        // as though it were the whole one.
        (Ok(_), Some(_)) => Err(Failure::interrupted(
            "interrupted.by_caller",
            "the invocation was stopped by the caller",
        )),
    }
}

/// Opens the destination when one is needed, serves the command and closes.
async fn with_destination<W: std::io::Write>(
    cli: &Cli,
    config: &Config,
    permits: usize,
    shutdown: &Shutdown,
    out: &mut W,
) -> Result<Option<Envelope>> {
    let directory =
        crate::config::paths::config_dir(cli.globals.diagnostics.config_dir.as_deref())?;
    let mut store = ProfileStore::open(&directory)?;
    // The way of keeping is read here, at the one place a vault is built for
    // real work, so a host that publishes `none` really keeps nothing rather
    // than publishing the choice and writing the file anyway.
    let mut vault = FileVault::open_keeping(&directory, crate::settings::secret_storage(config)?)?;

    if let Command::Conn(command) = &cli.command {
        return open::profiles(cli, config, command, &mut store, &mut vault).await;
    }

    if cli.globals.destination.all_profiles {
        return fanout::across_destinations(cli, config, permits, shutdown, &store, &vault)
            .await
            .map(Some);
    }

    let (profile, settings) = open::destination(cli, config, &store, &vault)?;

    // Built before the session opens, from the profile that was resolved and
    // the call that resolved it, so the answer can name a destination even when
    // the caller named none.
    let target = open::declared_target(&profile, cli);

    let session = open::open(&profile, &settings, cli, config, &shutdown.token()).await?;

    let work = Work {
        cli,
        config,
        // The database pinned to the destination is the scope every command
        // falls back to. Without it a listing would sweep the server's own
        // catalogue alongside the caller's data. It is read back from the
        // destination rather than recomputed, so the scope a listing sweeps and
        // the database the session was born in can never disagree.
        scope: profile.database.clone(),
        shutdown,
        many: false,
    };
    open::bounded(&work, session, &profile, &settings, out)
        .await
        .map(|answer| {
            answer
                .map(|envelope| envelope.from_destination(target, cli.globals.destination.source()))
        })
}

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

    fn parse(args: &[&str]) -> Cli {
        let command_line: Vec<String> = std::iter::once("mariadb-cli")
            .chain(args.iter().copied())
            .map(ToOwned::to_owned)
            .collect();
        Cli::try_parse_from(command_line).expect("the sample invocation parses")
    }

    /// An answer that finished while a signal was waiting is the interruption.
    ///
    /// This is the case the previous shape could not reach. `--all-profiles`
    /// turns every destination still in flight into a gap and assembles the
    /// blocks it already had, so the work answers `Ok` after a Ctrl-C and the
    /// caller was told the invocation succeeded.
    #[test]
    fn an_answer_that_finished_under_a_signal_is_reported_as_the_interruption() {
        let answered = under_signal(
            Ok(Some(Envelope::new("query run", serde_json::json!({})))),
            Some(crate::runtime::StopReason::Interrupt),
        );

        let failure = answered.expect_err("a signal arrived, so the answer is not the whole one");
        assert_eq!(failure.category(), crate::error::Category::Interrupted);
        assert_eq!(failure.exit_number().code(), 130);
    }

    /// A signal that arrives while the work runs reaches the number it answers.
    ///
    /// This measures the wiring rather than the decision: the work is handed the
    /// same `Shutdown` the watcher writes into, so stopping it from inside is
    /// indistinguishable, from here, from a signal arriving at that moment. What
    /// it proves is that the reason survives the whole invocation and is still
    /// there to be read at the end — which is the part that was missing while
    /// the watcher lived and died around the connected work alone.
    #[test]
    fn a_signal_that_arrives_during_the_work_reaches_the_answer() {
        let runtime = build_runtime().expect("a runtime starts");

        let answered: Result<Option<Envelope>> = runtime.block_on(under_signals(
            async |shutdown: &crate::runtime::Shutdown| {
                shutdown.stop(crate::runtime::StopReason::Interrupt);
                Ok(Some(Envelope::new("meta version", serde_json::json!({}))))
            },
        ));

        let failure = answered.expect_err("the invocation was stopped while it worked");
        assert_eq!(failure.exit_number().code(), 130);
    }

    /// An invocation nobody signalled answers with what the work produced.
    ///
    /// The guard above would pass just as well if every invocation reported an
    /// interruption, so this is what stops the fix from becoming the next
    /// defect: the whole surface runs through `under_signals` now, including
    /// every command that answers in a millisecond without a server.
    #[test]
    fn an_invocation_nobody_signalled_answers_normally() {
        let runtime = build_runtime().expect("a runtime starts");

        let answered: Result<Option<Envelope>> = runtime.block_on(under_signals(
            async |_shutdown: &crate::runtime::Shutdown| {
                Ok(Some(Envelope::new("meta version", serde_json::json!({}))))
            },
        ));

        assert!(answered.expect("nothing stopped this").is_some());
    }

    /// Without a signal the answer travels untouched.
    #[test]
    fn an_answer_nobody_interrupted_is_the_answer() {
        let answered = under_signal(
            Ok(Some(Envelope::new("query run", serde_json::json!({})))),
            None,
        );

        assert!(answered.expect("nothing stopped this").is_some());
    }

    /// A failure of its own outranks the interruption.
    ///
    /// The caller who sent the signal knows they sent it, and does not know the
    /// credential was refused. Reporting the signal here would replace the one
    /// piece of information they did not already have.
    #[test]
    fn a_failure_of_its_own_survives_the_signal() {
        let answered = under_signal::<Option<Envelope>>(
            Err(Failure::usage("usage.invalid_arguments", "malformed")),
            Some(crate::runtime::StopReason::Terminate),
        );

        let failure = answered.expect_err("the work failed");
        assert_eq!(failure.code(), "usage.invalid_arguments");
    }

    fn scratch() -> (tempfile::TempDir, Config) {
        let directory = tempfile::tempdir().expect("scratch directory");
        let config = Config::load(Some(directory.path())).expect("loads");
        (directory, config)
    }

    /// The contract of a command is the product's own description of itself,
    /// so it must be answerable with no destination configured at all.
    #[test]
    fn the_contract_is_answered_without_reaching_a_server() {
        let (directory, config) = scratch();
        let cli = parse(&["--print-schema", "query", "run", "SELECT 1"]);
        let answered = unconnected(&cli, &config, Some(directory.path()))
            .expect("answers")
            .expect("without a server");
        assert_eq!(answered.data["command"], "query run");
    }

    /// The contract must be answerable for every family, including the ones
    /// that would otherwise open a connection.
    #[test]
    fn every_family_answers_its_own_contract_offline() {
        let (directory, config) = scratch();
        for command in [
            vec!["schema", "tables"],
            vec!["server", "status"],
            vec!["data", "export", "--table", "t"],
            vec!["history", "tables"],
            vec!["conn", "list"],
        ] {
            let argv: Vec<&str> = std::iter::once("--print-schema").chain(command).collect();
            let cli = parse(&argv);
            assert!(
                unconnected(&cli, &config, Some(directory.path()))
                    .expect("answers")
                    .is_some(),
                "`{argv:?}` must answer its contract without a server"
            );
        }
    }

    /// Resolving where a result column comes from is read from the statement's
    /// own tree, so it must cost no connection.
    #[test]
    fn tracing_a_column_to_its_source_costs_no_connection() {
        let (directory, config) = scratch();
        let cli = parse(&["query", "lineage", "SELECT p.a FROM t AS p"]);
        let answered = unconnected(&cli, &config, Some(directory.path()))
            .expect("answers")
            .expect("without a server");
        assert_eq!(answered.command, "query lineage");
        assert_eq!(answered.data["rows"][0]["sources"][0]["table"], "t");
    }

    /// Keeping, listing and removing a statement under a name only touches the
    /// settings location, so none of the three may open a connection.
    #[test]
    fn the_statement_catalogue_costs_no_connection() {
        let (directory, config) = scratch();
        let location = directory.path();

        let saved = parse(&[
            "--config-dir",
            location.to_str().expect("utf8 path"),
            "query",
            "named",
            "save",
            "pedidos",
            "SELECT * FROM pedidos",
        ]);
        assert_eq!(
            unconnected(&saved, &config, Some(location))
                .expect("answers")
                .expect("without a server")
                .data["stored"],
            true
        );

        for action in [vec!["list"], vec!["remove", "pedidos"]] {
            let argv: Vec<&str> = vec![
                "--config-dir",
                location.to_str().expect("utf8 path"),
                "query",
                "named",
            ]
            .into_iter()
            .chain(action.iter().copied())
            .collect();
            assert!(
                unconnected(&parse(&argv), &config, Some(location))
                    .expect("answers")
                    .is_some(),
                "`{argv:?}` must be served without a connection"
            );
        }
    }

    /// Running a statement kept under a name does need the server, so it must
    /// not be answered here.
    ///
    /// The destination is written on the call because nothing forces a kept
    /// statement to be a reading: a change stored under a name and run by that
    /// name would otherwise be a way around FR-144, so the guard treats running
    /// one as capable of changing the server. This proof is about whether the
    /// command needs a destination, and writing one keeps it about that.
    ///
    /// The statement is really kept first. It used to name one that was never
    /// stored, which did not matter while an unknown name was only noticed
    /// after the destination was reached. It is noticed before that now, so a
    /// name nobody kept would make this refuse for the wrong reason and stop
    /// being about destinations at all.
    #[test]
    fn running_a_kept_statement_still_needs_the_server() {
        let (directory, config) = scratch();

        let mut catalogue =
            crate::exec::named::Catalogue::open(directory.path()).expect("the catalogue opens");
        catalogue.put(
            "pedidos",
            crate::exec::named::Stored {
                statement: "SELECT 1".to_owned(),
                params: Vec::new(),
                max_rows: None,
            },
        );
        catalogue.save().expect("the catalogue saves");

        // The location travels on the command line as well as in the argument
        // below, because the guard that now looks the name up reads it from the
        // parsed call. Passing it only beside the call sent the lookup to this
        // machine's own settings directory, where the name is not kept.
        let cli = parse(&[
            "--config-dir",
            directory.path().to_str().expect("a utf8 path"),
            "--profile",
            "producao",
            "query",
            "named",
            "run",
            "pedidos",
        ]);
        assert!(unconnected(&cli, &config, Some(directory.path()))
            .expect("resolves")
            .is_none());
    }

    /// A refused statement must be refused before anything is opened, so the
    /// caller is sent after the statement and not after the network.
    #[test]
    fn a_refused_statement_never_reaches_the_destination() {
        let (directory, config) = scratch();
        let cli = parse(&["query", "run", "SELECT 1; DROP TABLE users"]);
        let failure = unconnected(&cli, &config, Some(directory.path())).expect_err("must refuse");
        assert_eq!(failure.category(), crate::error::Category::Validation);
    }

    /// A command that needs a destination must say so rather than answering.
    #[test]
    fn a_command_that_needs_a_server_is_not_answered_here() {
        let (directory, config) = scratch();
        for command in [
            vec!["schema", "tables"],
            vec!["query", "run", "SELECT 1"],
            vec!["server", "status"],
        ] {
            assert!(
                unconnected(&parse(&command), &config, Some(directory.path()))
                    .expect("resolves")
                    .is_none(),
                "`{command:?}` must be left to the connected path"
            );
        }
    }
}