runner-manager 0.4.13

Local-first autoscaling manager for ephemeral GitHub Actions self-hosted runners, with a CLI and a Ratatui TUI.
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
// owner: b1-local-model-corpus
//
//! The typed action grammar: the allowlist, and the only road to an argument
//! vector.
//!
//! # The allowlist is an enum, and that is the security property
//!
//! `02-target-architecture.md`: "The action grammar is an enum, not arbitrary
//! strings." [`Action`] has one variant per allowlisted command leaf, each field
//! is one of the closed value sets in [`super::values`], and [`Action::argv`] is
//! a `match` that spells each variant out literally. There is no parser in the
//! other direction: the checked-in inventory is *rendered from* typed cases and
//! compared, never read back into a command. `daemon run`, `service`, `update`,
//! `tui`, `wsl` and every hidden command are unreachable by construction, and
//! `only_allowlisted_commands_are_generated` in `cli_chains_model.rs` checks
//! the rendered vectors anyway.
//!
//! # CLI syntax is enforced here; domain validity is not
//!
//! `03-coverage-model.md`: "The action constructor enforces CLI syntax;
//! domain-invalid values remain available so refusal paths are covered." So a
//! label command cannot be built with no label (the parser requires one), a
//! persistent workspace cannot be built without a path (a usage error), and a
//! capacity is a `u16` — while a zero capacity, a malformed repository, or an
//! ephemeral workspace *with* a path are all constructible, because the product
//! refuses those itself and that refusal is what the corpus exists to observe.

use std::fmt;

use super::values::{
    Capacity, HostLabelValue, LabelValue, OrgName, PathValue, RepoName, Resolver, Scope,
};

/// The subject of a policy command.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Target {
    Repo(RepoName),
    Org(OrgName),
}

impl Target {
    #[must_use]
    pub const fn scope(self) -> Scope {
        match self {
            Target::Repo(_) => Scope::Repository,
            Target::Org(_) => Scope::Organization,
        }
    }

    /// The literal argument, exactly as typed.
    #[must_use]
    pub fn token(self) -> String {
        match self {
            Target::Repo(repo) => repo.token(),
            Target::Org(org) => org.token(),
        }
    }

    /// The case-folded identity, or `None` for a spelling the product refuses.
    #[must_use]
    pub fn key(self) -> Option<TargetKey> {
        let canonical = match self {
            Target::Repo(repo) => repo.canonical(),
            Target::Org(org) => org.canonical(),
        }?;
        Some(TargetKey {
            scope: self.scope(),
            slug: canonical,
        })
    }

    #[must_use]
    pub const fn class(self) -> &'static str {
        match self {
            Target::Repo(repo) => repo.class(),
            Target::Org(org) => org.class(),
        }
    }
}

/// A target's identity: scope plus case-folded slug.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TargetKey {
    pub scope: Scope,
    pub slug: String,
}

impl fmt::Display for TargetKey {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}:{}", self.scope.word(), self.slug)
    }
}

/// One or more `--label` values. Empty is unrepresentable because the parser
/// requires at least one for `add-label` and `remove-label`.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Labels(Vec<LabelValue>);

impl Labels {
    /// # Panics
    /// On an empty list: that is a usage error, not a corpus value.
    #[must_use]
    pub fn of(values: &[LabelValue]) -> Self {
        assert!(
            !values.is_empty(),
            "a label command needs at least one --label"
        );
        Self(values.to_vec())
    }

    #[must_use]
    pub fn values(&self) -> &[LabelValue] {
        &self.0
    }
}

/// `repo set-workspace --mode … [--path …]`.
///
/// `--mode persistent` with no path is a usage error and has no variant;
/// `--mode ephemeral --path …` is a domain refusal and does.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum WorkspaceSetting {
    Ephemeral,
    EphemeralWithPath(PathValue),
    Persistent(PathValue),
}

/// `repo add` / `org add`.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct AddArgs {
    pub target: Target,
    pub host_label: HostLabelValue,
    pub max_capacity: Option<Capacity>,
    pub labels: Vec<LabelValue>,
    pub enable: bool,
}

/// Every allowlisted local action.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Action {
    /// `auth login` against the loopback fake GitHub.
    AuthLogin,
    /// `auth logout`.
    AuthLogout,
    HostSetCapacity(Capacity),
    HostSetRuntimeRoot(PathValue),
    HostResetRuntimeRoot,
    HostShow,
    Add(AddArgs),
    List(Scope),
    SetCapacity {
        target: Target,
        max_capacity: Capacity,
    },
    SetScale {
        target: Target,
        enabled: bool,
    },
    AddLabel {
        target: Target,
        labels: Labels,
    },
    RemoveLabel {
        target: Target,
        labels: Labels,
    },
    /// Repository scope only: `org` has no `set-workspace` leaf.
    SetWorkspace {
        repo: RepoName,
        setting: WorkspaceSetting,
    },
    Remove {
        target: Target,
        purge: bool,
    },
    StatusJson,
}

/// An action's command leaf, without its arguments.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ActionKind {
    AuthLogin,
    AuthLogout,
    HostSetCapacity,
    HostSetRuntimeRoot,
    HostResetRuntimeRoot,
    HostShow,
    RepoAdd,
    RepoList,
    RepoSetCapacity,
    RepoSetScale,
    RepoAddLabel,
    RepoRemoveLabel,
    RepoSetWorkspace,
    RepoRemove,
    OrgAdd,
    OrgList,
    OrgSetCapacity,
    OrgSetScale,
    OrgAddLabel,
    OrgRemoveLabel,
    OrgRemove,
    StatusJson,
}

impl ActionKind {
    /// Every leaf the local model drives, in a fixed order.
    pub const ALL: [ActionKind; 22] = [
        ActionKind::AuthLogin,
        ActionKind::AuthLogout,
        ActionKind::HostSetCapacity,
        ActionKind::HostSetRuntimeRoot,
        ActionKind::HostResetRuntimeRoot,
        ActionKind::HostShow,
        ActionKind::RepoAdd,
        ActionKind::RepoList,
        ActionKind::RepoSetCapacity,
        ActionKind::RepoSetScale,
        ActionKind::RepoAddLabel,
        ActionKind::RepoRemoveLabel,
        ActionKind::RepoSetWorkspace,
        ActionKind::RepoRemove,
        ActionKind::OrgAdd,
        ActionKind::OrgList,
        ActionKind::OrgSetCapacity,
        ActionKind::OrgSetScale,
        ActionKind::OrgAddLabel,
        ActionKind::OrgRemoveLabel,
        ActionKind::OrgRemove,
        ActionKind::StatusJson,
    ];

    /// The stable dotted name used in coverage units and the inventory.
    #[must_use]
    pub const fn name(self) -> &'static str {
        match self {
            ActionKind::AuthLogin => "auth.login",
            ActionKind::AuthLogout => "auth.logout",
            ActionKind::HostSetCapacity => "host.set-capacity",
            ActionKind::HostSetRuntimeRoot => "host.set-runtime-root",
            ActionKind::HostResetRuntimeRoot => "host.reset-runtime-root",
            ActionKind::HostShow => "host.show",
            ActionKind::RepoAdd => "repo.add",
            ActionKind::RepoList => "repo.list",
            ActionKind::RepoSetCapacity => "repo.set-capacity",
            ActionKind::RepoSetScale => "repo.set-scale",
            ActionKind::RepoAddLabel => "repo.add-label",
            ActionKind::RepoRemoveLabel => "repo.remove-label",
            ActionKind::RepoSetWorkspace => "repo.set-workspace",
            ActionKind::RepoRemove => "repo.remove",
            ActionKind::OrgAdd => "org.add",
            ActionKind::OrgList => "org.list",
            ActionKind::OrgSetCapacity => "org.set-capacity",
            ActionKind::OrgSetScale => "org.set-scale",
            ActionKind::OrgAddLabel => "org.add-label",
            ActionKind::OrgRemoveLabel => "org.remove-label",
            ActionKind::OrgRemove => "org.remove",
            ActionKind::StatusJson => "status.json",
        }
    }

    /// Reads never change state; everything else may.
    #[must_use]
    pub const fn is_read(self) -> bool {
        matches!(
            self,
            ActionKind::HostShow
                | ActionKind::RepoList
                | ActionKind::OrgList
                | ActionKind::StatusJson
        )
    }

    #[must_use]
    pub const fn is_mutating(self) -> bool {
        !self.is_read()
    }

    /// The mutating leaves, in [`ActionKind::ALL`] order.
    #[must_use]
    pub fn mutating() -> Vec<ActionKind> {
        Self::ALL.into_iter().filter(|k| k.is_mutating()).collect()
    }

    /// The read leaves, in [`ActionKind::ALL`] order.
    #[must_use]
    pub fn reads() -> Vec<ActionKind> {
        Self::ALL.into_iter().filter(|k| k.is_read()).collect()
    }

    /// The two leading argument-vector words of this leaf.
    #[must_use]
    pub const fn command_path(self) -> [&'static str; 2] {
        match self {
            ActionKind::AuthLogin => ["auth", "login"],
            ActionKind::AuthLogout => ["auth", "logout"],
            ActionKind::HostSetCapacity => ["host", "set-capacity"],
            ActionKind::HostSetRuntimeRoot => ["host", "set-runtime-root"],
            ActionKind::HostResetRuntimeRoot => ["host", "reset-runtime-root"],
            ActionKind::HostShow => ["host", "show"],
            ActionKind::RepoAdd => ["repo", "add"],
            ActionKind::RepoList => ["repo", "list"],
            ActionKind::RepoSetCapacity => ["repo", "set-capacity"],
            ActionKind::RepoSetScale => ["repo", "set-scale"],
            ActionKind::RepoAddLabel => ["repo", "add-label"],
            ActionKind::RepoRemoveLabel => ["repo", "remove-label"],
            ActionKind::RepoSetWorkspace => ["repo", "set-workspace"],
            ActionKind::RepoRemove => ["repo", "remove"],
            ActionKind::OrgAdd => ["org", "add"],
            ActionKind::OrgList => ["org", "list"],
            ActionKind::OrgSetCapacity => ["org", "set-capacity"],
            ActionKind::OrgSetScale => ["org", "set-scale"],
            ActionKind::OrgAddLabel => ["org", "add-label"],
            ActionKind::OrgRemoveLabel => ["org", "remove-label"],
            ActionKind::OrgRemove => ["org", "remove"],
            ActionKind::StatusJson => ["status", "--json"],
        }
    }
}

impl fmt::Display for ActionKind {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.name())
    }
}

fn scoped(scope: Scope, repo: ActionKind, org: ActionKind) -> ActionKind {
    match scope {
        Scope::Repository => repo,
        Scope::Organization => org,
    }
}

impl Action {
    #[must_use]
    pub fn kind(&self) -> ActionKind {
        match self {
            Action::AuthLogin => ActionKind::AuthLogin,
            Action::AuthLogout => ActionKind::AuthLogout,
            Action::HostSetCapacity(_) => ActionKind::HostSetCapacity,
            Action::HostSetRuntimeRoot(_) => ActionKind::HostSetRuntimeRoot,
            Action::HostResetRuntimeRoot => ActionKind::HostResetRuntimeRoot,
            Action::HostShow => ActionKind::HostShow,
            Action::Add(args) => {
                scoped(args.target.scope(), ActionKind::RepoAdd, ActionKind::OrgAdd)
            }
            Action::List(scope) => scoped(*scope, ActionKind::RepoList, ActionKind::OrgList),
            Action::SetCapacity { target, .. } => scoped(
                target.scope(),
                ActionKind::RepoSetCapacity,
                ActionKind::OrgSetCapacity,
            ),
            Action::SetScale { target, .. } => scoped(
                target.scope(),
                ActionKind::RepoSetScale,
                ActionKind::OrgSetScale,
            ),
            Action::AddLabel { target, .. } => scoped(
                target.scope(),
                ActionKind::RepoAddLabel,
                ActionKind::OrgAddLabel,
            ),
            Action::RemoveLabel { target, .. } => scoped(
                target.scope(),
                ActionKind::RepoRemoveLabel,
                ActionKind::OrgRemoveLabel,
            ),
            Action::SetWorkspace { .. } => ActionKind::RepoSetWorkspace,
            Action::Remove { target, .. } => scoped(
                target.scope(),
                ActionKind::RepoRemove,
                ActionKind::OrgRemove,
            ),
            Action::StatusJson => ActionKind::StatusJson,
        }
    }

    /// The policy target this action addresses, if any.
    #[must_use]
    pub fn target(&self) -> Option<Target> {
        match self {
            Action::Add(args) => Some(args.target),
            Action::SetCapacity { target, .. }
            | Action::SetScale { target, .. }
            | Action::AddLabel { target, .. }
            | Action::RemoveLabel { target, .. }
            | Action::Remove { target, .. } => Some(*target),
            Action::SetWorkspace { repo, .. } => Some(Target::Repo(*repo)),
            _ => None,
        }
    }

    /// The literal argument vector, without the binary and without the
    /// scenario's `--data-dir`, which the runner prepends.
    ///
    /// Options whose value could begin with `-` are spelled `--flag=value` so a
    /// value is never mistaken for an option.
    #[must_use]
    pub fn argv(&self, resolver: &dyn Resolver) -> Vec<String> {
        let mut argv: Vec<String> = self
            .kind()
            .command_path()
            .iter()
            .map(|word| (*word).to_string())
            .collect();
        match self {
            Action::AuthLogin
            | Action::AuthLogout
            | Action::HostResetRuntimeRoot
            | Action::HostShow
            | Action::List(_)
            | Action::StatusJson => {}
            Action::HostSetCapacity(capacity) => argv.push(capacity.value().to_string()),
            Action::HostSetRuntimeRoot(path) => {
                argv.push(format!("--path={}", resolver.path(*path)));
            }
            Action::Add(args) => {
                argv.push(args.target.token());
                argv.push(format!("--host-label={}", args.host_label.token()));
                if let Some(maximum) = args.max_capacity {
                    argv.push(format!("--max-capacity={}", maximum.value()));
                }
                for label in &args.labels {
                    argv.push(format!("--label={}", label.token(resolver)));
                }
                if args.enable {
                    argv.push("--enable".to_string());
                }
            }
            Action::SetCapacity {
                target,
                max_capacity,
            } => {
                argv.push(target.token());
                argv.push(format!("--max-capacity={}", max_capacity.value()));
            }
            Action::SetScale { target, enabled } => {
                argv.push(target.token());
                argv.push(format!("--enabled={enabled}"));
            }
            Action::AddLabel { target, labels } | Action::RemoveLabel { target, labels } => {
                argv.push(target.token());
                for label in labels.values() {
                    argv.push(format!("--label={}", label.token(resolver)));
                }
            }
            Action::SetWorkspace { repo, setting } => {
                argv.push(repo.token());
                match setting {
                    WorkspaceSetting::Ephemeral => argv.push("--mode=ephemeral".to_string()),
                    WorkspaceSetting::EphemeralWithPath(path) => {
                        argv.push("--mode=ephemeral".to_string());
                        argv.push(format!("--path={}", resolver.path(*path)));
                    }
                    WorkspaceSetting::Persistent(path) => {
                        argv.push("--mode=persistent".to_string());
                        argv.push(format!("--path={}", resolver.path(*path)));
                    }
                }
            }
            Action::Remove { target, purge } => {
                argv.push(target.token());
                if *purge {
                    argv.push("--purge".to_string());
                }
            }
        }
        argv
    }

    /// The equivalence classes this action's arguments exercise, as coverage
    /// units (`value:<leaf>:<parameter>=<class>`).
    #[must_use]
    pub fn value_units(&self) -> Vec<String> {
        let kind = self.kind().name();
        let unit = |parameter: &str, class: &str| format!("value:{kind}:{parameter}={class}");
        let mut units = Vec::new();
        match self {
            Action::AuthLogin
            | Action::AuthLogout
            | Action::HostResetRuntimeRoot
            | Action::HostShow
            | Action::List(_)
            | Action::StatusJson => {}
            Action::HostSetCapacity(capacity) => units.push(unit("capacity", capacity.class())),
            Action::HostSetRuntimeRoot(path) => units.push(unit("path", path.class())),
            Action::Add(args) => {
                units.push(unit("target", args.target.class()));
                units.push(unit("host-label", args.host_label.class()));
                units.push(unit(
                    "max-capacity",
                    args.max_capacity
                        .map_or("absent-monitor-only", Capacity::class),
                ));
                if args.labels.is_empty() {
                    units.push(unit("label", "none"));
                }
                for label in &args.labels {
                    units.push(unit("label", label.class()));
                }
                units.push(unit("enable", if args.enable { "true" } else { "false" }));
            }
            Action::SetCapacity {
                target,
                max_capacity,
            } => {
                units.push(unit("target", target.class()));
                units.push(unit("max-capacity", max_capacity.class()));
            }
            Action::SetScale { target, enabled } => {
                units.push(unit("target", target.class()));
                units.push(unit("enabled", if *enabled { "true" } else { "false" }));
            }
            Action::AddLabel { target, labels } | Action::RemoveLabel { target, labels } => {
                units.push(unit("target", target.class()));
                for label in labels.values() {
                    units.push(unit("label", label.class()));
                }
                if labels.values().len() > 1 {
                    units.push(unit("label-count", "several"));
                }
            }
            Action::SetWorkspace { repo, setting } => {
                units.push(unit("target", repo.class()));
                match setting {
                    WorkspaceSetting::Ephemeral => units.push(unit("mode", "ephemeral")),
                    WorkspaceSetting::EphemeralWithPath(path) => {
                        units.push(unit("mode", "ephemeral-with-path"));
                        units.push(unit("path", path.class()));
                    }
                    WorkspaceSetting::Persistent(path) => {
                        units.push(unit("mode", "persistent"));
                        units.push(unit("path", path.class()));
                    }
                }
            }
            Action::Remove { target, purge } => {
                units.push(unit("target", target.class()));
                units.push(unit("purge", if *purge { "true" } else { "false" }));
            }
        }
        units.sort();
        units.dedup();
        units
    }
}

/// A store-level setup step the runner applies through the public `Store` or
/// secret-store interface, never through a command.
///
/// Some states are real and reachable only by the daemon or by another
/// process: a runner attempt, a `repair_required` policy after an interrupted
/// add, a policy left `draining` by a confirmed disable. The local suite does
/// not run the daemon, so a case that needs one of those states seeds it. A
/// seed is part of a case's named initial state and is reported as such.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Seed {
    /// Store a fake credential for the recorded start mode, as a completed
    /// `auth login` would. Cheaper than the device flow, which waits out the
    /// polling interval on every sign-in.
    Credential,
    /// Journal one runner attempt against the target's policy. Every seeded
    /// attempt uses an ephemeral workspace.
    Attempt { target: Target, kind: AttemptKind },
    /// Move a `pending` policy to `repair_required`.
    RepairRequired(Target),
    /// Move an `active` policy to `draining` (`enabled` becomes false).
    Drain(Target),
    /// Create the shared runner package cache, `<data>/state/packages`.
    PackageCache,
}

/// What a seeded attempt counts as.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum AttemptKind {
    /// Non-terminal (for example `busy`): occupies host capacity.
    Active,
    /// Terminal and not yet `cleaned`: holds no capacity, still owns its
    /// directory.
    AwaitingCleanup,
    /// `cleaned`: historical diagnostics only.
    Cleaned,
}

impl AttemptKind {
    #[must_use]
    pub const fn name(self) -> &'static str {
        match self {
            AttemptKind::Active => "active",
            AttemptKind::AwaitingCleanup => "awaiting-cleanup",
            AttemptKind::Cleaned => "cleaned",
        }
    }
}

impl Seed {
    #[must_use]
    pub fn describe(&self) -> String {
        match self {
            Seed::Credential => "seed credential".to_string(),
            Seed::Attempt { target, kind } => format!(
                "seed {} attempt for {} {}",
                kind.name(),
                target.scope().word(),
                target.token()
            ),
            Seed::RepairRequired(target) => format!(
                "seed repair_required for {} {}",
                target.scope().word(),
                target.token()
            ),
            Seed::Drain(target) => format!(
                "seed draining for {} {}",
                target.scope().word(),
                target.token()
            ),
            Seed::PackageCache => "seed package cache".to_string(),
        }
    }
}

/// One step of a case: a real command, or a seeded fact.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Step {
    Run(Action),
    Seed(Seed),
}

impl Step {
    /// The step as the inventory prints it.
    ///
    /// Display only: an argument holding whitespace is quoted and a long run of
    /// one character is abbreviated, so the text is reviewable. It is never
    /// parsed back into a command.
    #[must_use]
    pub fn describe(&self, resolver: &dyn Resolver) -> String {
        match self {
            Step::Run(action) => action
                .argv(resolver)
                .iter()
                .map(|argument| display_argument(argument))
                .collect::<Vec<_>>()
                .join(" "),
            Step::Seed(seed) => seed.describe(),
        }
    }
}

/// One argument, quoted when it holds whitespace and with any run of more than
/// sixteen identical characters written as `<c*N>`.
fn display_argument(argument: &str) -> String {
    let mut text = String::new();
    let characters: Vec<char> = argument.chars().collect();
    let mut index = 0;
    while index < characters.len() {
        let current = characters[index];
        let mut run = 1;
        while index + run < characters.len() && characters[index + run] == current {
            run += 1;
        }
        if run > 16 {
            text.push_str(&format!("<{current}*{run}>"));
        } else {
            text.extend(std::iter::repeat_n(current, run));
        }
        index += run;
    }
    if text.chars().any(char::is_whitespace) {
        format!("'{text}'")
    } else {
        text
    }
}