trusty-mpm 1.7.3

trusty-mpm: unified multi-agent orchestration platform (core, daemon, CLI, TUI, Telegram)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//! `tm ls` stop-then-delete: the errored-session route and its fail-open check (#7224).
//!
//! Why: split out of `tests_behavior_d_tests.rs`, which sits within a few
//! dozen lines of the 3000-SLOC test cap — the same reason
//! `tests_behavior_d_ls_connector_tests.rs` exists. The block is cohesive on
//! its own: everything here is about ONE route, `picker_delete::stop_then_delete`.
//!
//! What: the two pure seams the route is built from
//! ([`delete_needs_stop_first`](crate::commands::picker_delete::delete_needs_stop_first)
//! and [`classify_stop_first`](crate::commands::picker_delete::classify_stop_first)),
//! plus real-HTTP round trips against a counting stub daemon. The counting is
//! the point: proving a REJECTED stop issues no delete needs a server that can
//! say the delete endpoint was never called, which a message assertion cannot.

use std::net::SocketAddr;

use crate::commands::picker_delete::DeleteReport;

/// #7224: the stop-first leg is scoped to `errored` and nothing else. A
/// `stopped` record has no runtime to stop, and `active`/`provisioning` take the
/// force-confirm path — neither may pick up a stop it does not need.
#[test]
fn delete_needs_stop_first_only_for_errored() {
    use crate::commands::picker_delete::delete_needs_stop_first;
    assert!(delete_needs_stop_first("errored"));
    for state in [
        "stopped",
        "active",
        "provisioning",
        "decommissioned",
        "deleted",
    ] {
        assert!(
            !delete_needs_stop_first(state),
            "{state} must not take the stop-first route"
        );
    }
}

/// #7224 fail-open check: only an explicit 2xx or 404 lets the delete proceed.
/// Every other status — a 409, a 500, a 503 — is `Failed`, which the caller
/// turns into "nothing was deleted". A carve-out keyed on "an error happened"
/// rather than on the daemon's own answer is exactly how a stop-then-delete
/// sequence deletes a session the daemon still considers live.
#[test]
fn classify_stop_first_maps_each_status() {
    use crate::commands::picker_delete::{StopFirstNext, classify_stop_first};
    assert_eq!(
        classify_stop_first(reqwest::StatusCode::OK),
        StopFirstNext::Stopped
    );
    assert_eq!(
        classify_stop_first(reqwest::StatusCode::ACCEPTED),
        StopFirstNext::Stopped,
        "any 2xx means the daemon accepted the stop"
    );
    assert_eq!(
        classify_stop_first(reqwest::StatusCode::NOT_FOUND),
        StopFirstNext::NothingToStop,
        "404 is the daemon's explicit 'no live session here'"
    );
    for status in [
        reqwest::StatusCode::CONFLICT,
        reqwest::StatusCode::INTERNAL_SERVER_ERROR,
        reqwest::StatusCode::SERVICE_UNAVAILABLE,
        reqwest::StatusCode::BAD_REQUEST,
    ] {
        assert_eq!(
            classify_stop_first(status),
            StopFirstNext::Failed,
            "{status} must NOT be downgraded into a delete"
        );
    }
}

/// A hermetic stand-in for the two managed endpoints the stop-first route
/// touches, so the STOP status can be dialled to anything and the delete leg
/// can be OBSERVED — the fail-open check needs to prove no delete request was
/// issued, which only a counting server can show.
#[derive(Clone)]
struct StopStub {
    stop_status: axum::http::StatusCode,
    stops: std::sync::Arc<std::sync::atomic::AtomicUsize>,
    deletes: std::sync::Arc<std::sync::atomic::AtomicUsize>,
}

impl StopStub {
    fn new(stop_status: axum::http::StatusCode) -> Self {
        Self {
            stop_status,
            stops: Default::default(),
            deletes: Default::default(),
        }
    }

    fn router(&self) -> axum::Router {
        use axum::{Router, extract::State, routing::post};
        let stub = self.clone();
        Router::new()
            .route(
                "/api/v1/sessions/managed/{id}/runtime-stop",
                post(|State(s): State<StopStub>| async move {
                    s.stops.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
                    (s.stop_status, "stub stop body")
                }),
            )
            .route(
                "/api/v1/sessions/managed/{id}/delete",
                post(|State(s): State<StopStub>| async move {
                    s.deletes.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
                    axum::Json(serde_json::json!({
                        "name": "tm-stub-01",
                        "state": "errored",
                        "deleted": true,
                    }))
                }),
            )
            .with_state(stub)
    }

    fn counts(&self) -> (usize, usize) {
        use std::sync::atomic::Ordering::SeqCst;
        (self.stops.load(SeqCst), self.deletes.load(SeqCst))
    }
}

/// Serve `router` on a fresh loopback port; returns the base URL and the task.
async fn serve_stub(router: axum::Router) -> (String, tokio::task::JoinHandle<()>) {
    let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
        .await
        .expect("bind loopback port");
    let addr: SocketAddr = listener.local_addr().expect("resolve bound addr");
    let handle = tokio::spawn(async move {
        let _ = axum::serve(listener, router).await;
    });
    (format!("http://{addr}"), handle)
}

/// The whole point of the route: an errored session whose runtime is up gets
/// stopped and then deleted, in one operator action, with no bounce to the CLI.
#[tokio::test]
async fn stop_then_delete_deletes_after_a_successful_stop() {
    use crate::commands::picker_delete::stop_then_delete;
    let stub = StopStub::new(axum::http::StatusCode::OK);
    let (url, handle) = serve_stub(stub.router()).await;

    let report = stop_then_delete(&reqwest::Client::new(), &url, "sid-1", false)
        .await
        .expect("routing call must not error");
    assert!(
        matches!(report, DeleteReport::Deleted { local: false, .. }),
        "expected a managed delete, got {report:?}"
    );
    assert_eq!(stub.counts(), (1, 1), "one stop, then one delete");
    handle.abort();
}

/// "Nothing to stop" is the daemon's EXPLICIT 404, not a guess: the delete still
/// goes out, and its own not-found routing decides what that means.
#[tokio::test]
async fn stop_then_delete_treats_not_found_as_nothing_to_stop() {
    use crate::commands::picker_delete::stop_then_delete;
    let stub = StopStub::new(axum::http::StatusCode::NOT_FOUND);
    let (url, handle) = serve_stub(stub.router()).await;

    let report = stop_then_delete(&reqwest::Client::new(), &url, "sid-2", false)
        .await
        .expect("routing call must not error");
    assert!(
        matches!(report, DeleteReport::Deleted { .. }),
        "a 404 stop must not block the delete, got {report:?}"
    );
    assert_eq!(stub.counts(), (1, 1));
    handle.abort();
}

/// Fail-open check. A stop the daemon REJECTED (500, and separately 409) must
/// leave the record alone: the report says nothing was deleted, and — the part
/// a message assertion alone would not prove — the delete endpoint is never
/// called at all.
#[tokio::test]
async fn stop_then_delete_never_deletes_after_a_failed_stop() {
    use crate::commands::picker_delete::stop_then_delete;
    for status in [
        axum::http::StatusCode::INTERNAL_SERVER_ERROR,
        axum::http::StatusCode::CONFLICT,
    ] {
        let stub = StopStub::new(status);
        let (url, handle) = serve_stub(stub.router()).await;

        let report = stop_then_delete(&reqwest::Client::new(), &url, "sid-3", false)
            .await
            .expect("routing call must not error");
        match report {
            DeleteReport::StopFailed(msg) => {
                assert!(
                    msg.contains(status.as_str()),
                    "must carry the status: {msg}"
                );
                assert!(msg.contains("stub stop body"), "must carry the body: {msg}");
            }
            other => panic!("a {status} stop must report StopFailed, got {other:?}"),
        }
        assert_eq!(
            stub.counts(),
            (1, 0),
            "a rejected stop must issue NO delete request ({status})"
        );
        handle.abort();
    }
}

// ── the numbered picker's own delete route (#7224) ──────────────────────────

/// The daemon's answer for an ERRORED session whose tmux pane is still up: the
/// delete guard 409s until the runtime has actually been stopped. This is the
/// shape of the reported bug — a delete that never stops first bounces off that
/// 409 with advice to leave the surface and run `tm session stop` by hand.
#[derive(Clone)]
struct LiveErroredStub {
    stop_status: axum::http::StatusCode,
    runtime_down: std::sync::Arc<std::sync::atomic::AtomicBool>,
    stops: std::sync::Arc<std::sync::atomic::AtomicUsize>,
    deletes: std::sync::Arc<std::sync::atomic::AtomicUsize>,
}

impl LiveErroredStub {
    fn new(stop_status: axum::http::StatusCode) -> Self {
        Self {
            stop_status,
            runtime_down: Default::default(),
            stops: Default::default(),
            deletes: Default::default(),
        }
    }

    fn router(&self) -> axum::Router {
        use std::sync::atomic::Ordering::SeqCst;

        use axum::{Router, extract::State, response::IntoResponse, routing::post};
        let stub = self.clone();
        Router::new()
            .route(
                "/api/v1/sessions/managed/{id}/runtime-stop",
                post(|State(s): State<LiveErroredStub>| async move {
                    s.stops.fetch_add(1, SeqCst);
                    // 2xx and 404 are both "no live runtime remains"; anything
                    // else leaves the session exactly as it was.
                    if s.stop_status.is_success()
                        || s.stop_status == axum::http::StatusCode::NOT_FOUND
                    {
                        s.runtime_down.store(true, SeqCst);
                    }
                    (s.stop_status, "stub stop body")
                }),
            )
            .route(
                "/api/v1/sessions/managed/{id}/delete",
                post(|State(s): State<LiveErroredStub>| async move {
                    s.deletes.fetch_add(1, SeqCst);
                    if !s.runtime_down.load(SeqCst) {
                        return (
                            axum::http::StatusCode::CONFLICT,
                            "session is errored — stop it first with `tm session stop`",
                        )
                            .into_response();
                    }
                    axum::Json(serde_json::json!({
                        "name": "tm-quiet-falcon",
                        "state": "errored",
                        "deleted": true,
                    }))
                    .into_response()
                }),
            )
            .with_state(stub)
    }

    fn counts(&self) -> (usize, usize) {
        use std::sync::atomic::Ordering::SeqCst;
        (self.stops.load(SeqCst), self.deletes.load(SeqCst))
    }
}

/// A managed row in `state`, with the id the stub answers for.
fn row(state: &str) -> trusty_mpm::client::ManagedSessionSummary {
    trusty_mpm::client::ManagedSessionSummary {
        id: "sid-picker".to_string(),
        name: "tm-quiet-falcon".to_string(),
        state: state.to_string(),
        persisted_state: None,
        workspace_path: None,
        repo_url: None,
        branch: None,
        created_at: None,
        last_activity_at: None,
        pending_decision: None,
        proposed_default: None,
        source_id: None,
        task: None,
        cwd: None,
        claude_session_id: None,
        deliverable_id: None,
        pane_id: None,
        injection_status: None,
        unresumable: false,
        stale_assets: false,
        stale_assets_unchecked: false,
        attached: false,
        slot: 1,
        deleted: false,
        auto_resume_parked: None,
    }
}

/// The reported bug, on the surface it was reported from. `tm ls` falls back to
/// the NUMBERED picker whenever the terminal has no raw mode, and that picker's
/// delete driver used to issue the delete alone — so an errored row whose tmux
/// pane was still up got the daemon's 409 and the operator got told to go run a
/// different command in a different surface.
#[tokio::test]
async fn picker_delete_stops_an_errored_session_before_deleting_it() {
    use crate::commands::picker_delete::delete_confirmed;
    let stub = LiveErroredStub::new(axum::http::StatusCode::OK);
    let (url, handle) = serve_stub(stub.router()).await;

    let deleted = delete_confirmed(&reqwest::Client::new(), &url, &row("errored"))
        .await
        .expect("the delete driver must not error");
    assert!(deleted, "the errored row must end up deleted, not refused");
    assert_eq!(stub.counts(), (1, 1), "one stop, then one delete");
    handle.abort();
}

/// A 404 stop is the daemon's explicit "no live session here", not a failure —
/// the delete still goes out and does its own not-found routing.
#[tokio::test]
async fn picker_delete_treats_a_not_found_stop_as_nothing_to_stop() {
    use crate::commands::picker_delete::delete_confirmed;
    let stub = LiveErroredStub::new(axum::http::StatusCode::NOT_FOUND);
    let (url, handle) = serve_stub(stub.router()).await;

    let deleted = delete_confirmed(&reqwest::Client::new(), &url, &row("errored"))
        .await
        .expect("the delete driver must not error");
    assert!(deleted, "a 404 stop must not block the delete");
    assert_eq!(stub.counts(), (1, 1));
    handle.abort();
}

/// Fail-open check on the picker's own route: a stop the daemon REJECTED leaves
/// the record alone, and the delete endpoint is never reached at all.
#[tokio::test]
async fn picker_delete_never_deletes_after_a_failed_stop() {
    use crate::commands::picker_delete::delete_confirmed;
    for status in [
        axum::http::StatusCode::INTERNAL_SERVER_ERROR,
        axum::http::StatusCode::CONFLICT,
    ] {
        let stub = LiveErroredStub::new(status);
        let (url, handle) = serve_stub(stub.router()).await;

        let deleted = delete_confirmed(&reqwest::Client::new(), &url, &row("errored"))
            .await
            .expect("the delete driver must not error");
        assert!(!deleted, "a {status} stop must not report a deletion");
        assert_eq!(
            stub.counts(),
            (1, 0),
            "a rejected stop must issue NO delete request ({status})"
        );
        handle.abort();
    }
}

/// The carve-out stays scoped: a `stopped` row is deleted exactly as before,
/// with no runtime-stop request issued on its behalf.
#[tokio::test]
async fn picker_delete_issues_no_stop_for_a_non_errored_row() {
    use crate::commands::picker_delete::delete_confirmed;
    let stub = StopStub::new(axum::http::StatusCode::OK);
    let (url, handle) = serve_stub(stub.router()).await;

    let deleted = delete_confirmed(&reqwest::Client::new(), &url, &row("stopped"))
        .await
        .expect("the delete driver must not error");
    assert!(deleted);
    assert_eq!(
        stub.counts(),
        (0, 1),
        "a stopped row has no runtime to stop — one delete, no stop"
    );
    handle.abort();
}

/// The pair is the whole reason the two surfaces cannot diverge again, so it
/// must stay exactly the two guards it composes — never a third opinion.
#[test]
fn delete_route_flags_match_the_two_guards() {
    use crate::commands::picker_delete::{
        delete_needs_force, delete_needs_stop_first, delete_route_flags,
    };
    for state in [
        "errored",
        "stopped",
        "active",
        "provisioning",
        "decommissioned",
        "deleted",
    ] {
        assert_eq!(
            delete_route_flags(state),
            (delete_needs_force(state), delete_needs_stop_first(state)),
            "{state}"
        );
    }
}

/// Confirming an errored row runs two legs, and both surfaces must promise the
/// same two before the operator agrees — one sentence, not two spellings.
#[test]
fn both_delete_surfaces_ask_the_same_errored_question() {
    use crate::commands::picker_delete::errored_confirm_ask;
    assert_eq!(
        errored_confirm_ask("tm-quiet-falcon"),
        "'tm-quiet-falcon' is errored. Stop it and delete it? Type y, then Enter."
    );
}

// ── the `tm session delete <id>` verb's own route (#7388) ───────────────────

/// The three managed endpoints the VERB touches, with the state it reports
/// dialled per test and the stop/delete legs recorded IN ORDER.
///
/// The order is the point: proving the verb stops an errored session *first*
/// needs a server that can say which request arrived when, and a delete that
/// refuses while the runtime is still up — exactly what the daemon does.
#[derive(Clone)]
struct VerbStub {
    /// The `state` the managed GET reports, or `None` to answer 404 there —
    /// the id then names no managed record (a project-only session).
    state: Option<String>,
    stop_status: axum::http::StatusCode,
    /// While true the delete endpoint 409s, mirroring the daemon's tmux probe.
    live: std::sync::Arc<std::sync::atomic::AtomicBool>,
    legs: std::sync::Arc<std::sync::Mutex<Vec<&'static str>>>,
}

impl VerbStub {
    fn new(state: Option<&str>, stop_status: axum::http::StatusCode, live: bool) -> Self {
        Self {
            state: state.map(str::to_string),
            stop_status,
            live: std::sync::Arc::new(std::sync::atomic::AtomicBool::new(live)),
            legs: Default::default(),
        }
    }

    fn router(&self) -> axum::Router {
        use std::sync::atomic::Ordering::SeqCst;

        use axum::{
            Router,
            extract::State,
            response::IntoResponse,
            routing::{get, post},
        };
        let stub = self.clone();
        Router::new()
            .route(
                "/api/v1/sessions/managed/{id}",
                get(|State(s): State<VerbStub>| async move {
                    match s.state {
                        Some(state) => axum::Json(serde_json::json!({
                            "id": "sid-verb",
                            "name": "tm-quiet-falcon",
                            "state": state,
                        }))
                        .into_response(),
                        None => (axum::http::StatusCode::NOT_FOUND, "no such managed session")
                            .into_response(),
                    }
                }),
            )
            .route(
                "/api/v1/sessions/managed/{id}/runtime-stop",
                post(|State(s): State<VerbStub>| async move {
                    s.legs.lock().expect("legs lock").push("stop");
                    if s.stop_status.is_success()
                        || s.stop_status == axum::http::StatusCode::NOT_FOUND
                    {
                        s.live.store(false, SeqCst);
                    }
                    (s.stop_status, "stub stop body")
                }),
            )
            .route(
                "/api/v1/sessions/managed/{id}/delete",
                post(|State(s): State<VerbStub>| async move {
                    s.legs.lock().expect("legs lock").push("delete");
                    if s.live.load(SeqCst) {
                        return (
                            axum::http::StatusCode::CONFLICT,
                            "session 'tm-quiet-falcon' is errored — stop it first with \
                             `tm session stop`",
                        )
                            .into_response();
                    }
                    axum::Json(serde_json::json!({
                        "name": "tm-quiet-falcon",
                        "state": "errored",
                        "deleted": true,
                    }))
                    .into_response()
                }),
            )
            .with_state(stub)
    }

    fn legs(&self) -> Vec<&'static str> {
        self.legs.lock().expect("legs lock").clone()
    }
}

/// #7388, the reported bug: `tm session delete <errored-id>` exited 1 telling
/// the operator to go run `tm session stop` — the command they were already
/// asking for. It must stop the runtime and THEN delete the record, in that
/// order. A fix that deletes without stopping records `["delete"]` and gets the
/// daemon's 409 back; a fix that special-cases `errored` by skipping the stop
/// records the same. Only the real two-leg route records `["stop", "delete"]`.
#[tokio::test]
async fn verb_delete_stops_an_errored_session_before_deleting_it() {
    let stub = VerbStub::new(Some("errored"), axum::http::StatusCode::OK, true);
    let (url, handle) = serve_stub(stub.router()).await;

    crate::commands::delete::session_delete(
        &reqwest::Client::new(),
        &url,
        "sid-verb".to_string(),
        false,
    )
    .await
    .expect("an errored session must delete, not refuse");
    assert_eq!(
        stub.legs(),
        vec!["stop", "delete"],
        "the stop must arrive before the delete"
    );
    handle.abort();
}

/// Fail-open check on the verb's route: a stop the daemon REJECTED leaves the
/// record alone, the delete endpoint is never reached, and the verb exits
/// non-zero so a script sees the failure.
#[tokio::test]
async fn verb_delete_never_deletes_after_a_failed_stop() {
    for status in [
        axum::http::StatusCode::INTERNAL_SERVER_ERROR,
        axum::http::StatusCode::CONFLICT,
    ] {
        let stub = VerbStub::new(Some("errored"), status, true);
        let (url, handle) = serve_stub(stub.router()).await;

        let err = crate::commands::delete::session_delete(
            &reqwest::Client::new(),
            &url,
            "sid-verb".to_string(),
            false,
        )
        .await
        .expect_err("a rejected stop must not report success");
        assert!(
            err.to_string().contains("stop failed"),
            "must name the failed stop: {err}"
        );
        assert_eq!(
            stub.legs(),
            vec!["stop"],
            "a rejected stop must issue NO delete request ({status})"
        );
        handle.abort();
    }
}

/// The carve-out stays scoped on the verb too: an id the managed store does not
/// know (a project-only session) gets no runtime-stop issued on its behalf, so
/// the local-fallback route is unchanged.
#[tokio::test]
async fn verb_delete_issues_no_stop_when_the_id_is_not_a_managed_record() {
    let stub = VerbStub::new(None, axum::http::StatusCode::OK, false);
    let (url, handle) = serve_stub(stub.router()).await;

    // The managed GET 404s, so the state is unknown and the plain delete goes
    // out; the stub's delete endpoint answers it (the local fallback beyond it
    // is covered by `local_delete_*` in `tests_behavior_d_tests.rs`).
    crate::commands::delete::session_delete(
        &reqwest::Client::new(),
        &url,
        "sid-verb".to_string(),
        false,
    )
    .await
    .expect("an unknown-state delete must route exactly as before");
    assert_eq!(
        stub.legs(),
        vec!["delete"],
        "an unclassifiable id must not pick up a stop leg"
    );
    handle.abort();
}

/// #7388: the two surfaces must decide the same route for the same state. The
/// picker reads the state off the row it listed and the verb asks the daemon
/// for it, but from there both go through `route_delete_for_state`, so the
/// stop/delete legs they issue must match state for state.
#[tokio::test]
async fn picker_and_verb_route_each_state_identically() {
    use crate::commands::picker_delete::delete_confirmed;
    // Every variant of `ManagedSessionState`, in its serde (snake_case) spelling.
    for state in [
        "provisioning",
        "active",
        "stopped",
        "errored",
        "decommissioned",
        "deleted",
    ] {
        // `live = false`: the delete succeeds either way, so what differs
        // between the surfaces is the ROUTE, not the daemon's verdict.
        let picker_stub = VerbStub::new(Some(state), axum::http::StatusCode::OK, false);
        let (picker_url, picker_handle) = serve_stub(picker_stub.router()).await;
        delete_confirmed(&reqwest::Client::new(), &picker_url, &row(state))
            .await
            .expect("the picker's delete driver must not error");
        picker_handle.abort();

        let verb_stub = VerbStub::new(Some(state), axum::http::StatusCode::OK, false);
        let (verb_url, verb_handle) = serve_stub(verb_stub.router()).await;
        // The picker force-confirms a running row by having the operator type
        // `force`; `--force` is the verb's spelling of the same consent, so
        // pass the flag the state calls for and compare like with like.
        let force = crate::commands::picker_delete::delete_needs_force(state);
        crate::commands::delete::session_delete(
            &reqwest::Client::new(),
            &verb_url,
            "sid-verb".to_string(),
            force,
        )
        .await
        .expect("the verb must not error");
        verb_handle.abort();

        assert_eq!(
            picker_stub.legs(),
            verb_stub.legs(),
            "the picker and `tm session delete` must route a {state} session the same way"
        );
    }
}