boxlite 0.10.7

Embeddable virtual machine runtime for secure, isolated code execution
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
use super::*;
use crate::disk::DiskFormat;
use crate::litebox::ssh::*;
use crate::litebox::{
    BoxState,
    config::{BoxConfig, ContainerRuntimeConfig},
};
use crate::runtime::rt_impl::RuntimeImpl;
use crate::vmm::controller::VmmMetrics;
use crate::{BoxIDMint, BoxOptions, BoxStatus, BoxliteOptions, ContainerID};
use boxlite_shared as proto;
use std::sync::Mutex;
use tonic::{Request, Response, Status};

#[derive(Default)]
struct Mock {
    requests: Mutex<Vec<&'static str>>,
    config: Mutex<Option<proto::SshConfig>>,
    error: Mutex<Option<tonic::Code>>,
    missing: Mutex<bool>,
    block: Mutex<bool>,
    entered: tokio::sync::Notify,
    release: tokio::sync::Notify,
    start_entered: tokio::sync::Notify,
    start_release: tokio::sync::Notify,
    start_block: Mutex<bool>,
    start_fail: Mutex<bool>,
}

impl Mock {
    /// Record each RPC before injecting a blocked, rejected, or incomplete response.
    /// The notification lets tests cancel or advance time after the RPC arrives.
    #[allow(
        clippy::result_large_err,
        reason = "mock returns the tonic service error type"
    )]
    async fn reply(&self, name: &'static str) -> Result<Option<proto::SshStatus>, Status> {
        self.requests.lock().unwrap().push(name);
        self.entered.notify_one();
        let block = *self.block.lock().unwrap();
        if block {
            self.release.notified().await;
        }
        if let Some(code) = *self.error.lock().unwrap() {
            return Err(Status::new(code, "mock rejection"));
        }
        Ok((!*self.missing.lock().unwrap()).then(|| proto::SshStatus {
            enabled: true,
            generation: 7,
            listen_address: "0.0.0.0:2222".into(),
            host_public_key: "public host".into(),
            host_key_fingerprint: "SHA256:test".into(),
        }))
    }
}

struct MockService(Arc<Mock>);

#[tonic::async_trait]
impl proto::Ssh for MockService {
    /// Capture the decoded configuration so assertions cover the serialization boundary.
    async fn configure(
        &self,
        request: Request<proto::SshConfigureRequest>,
    ) -> Result<Response<proto::SshConfigureResponse>, Status> {
        *self.0.config.lock().unwrap() = request.into_inner().config;
        Ok(Response::new(proto::SshConfigureResponse {
            status: self.0.reply("configure").await?,
        }))
    }
    /// Use the shared response controls to exercise status errors and cancellation.
    async fn status(
        &self,
        _: Request<proto::SshStatusRequest>,
    ) -> Result<Response<proto::SshStatusResponse>, Status> {
        Ok(Response::new(proto::SshStatusResponse {
            status: self.0.reply("status").await?,
        }))
    }
    /// Exercise disable's RPC path without simulating guest listener lifecycle.
    async fn disable(
        &self,
        _: Request<proto::SshDisableRequest>,
    ) -> Result<Response<proto::SshDisableResponse>, Status> {
        Ok(Response::new(proto::SshDisableResponse {
            status: self.0.reply("disable").await?,
        }))
    }
}

#[tonic::async_trait]
impl proto::Container for MockService {
    /// Reject reinitialization: the fixture already represents a booted guest.
    async fn init(
        &self,
        _: Request<proto::ContainerInitRequest>,
    ) -> Result<Response<proto::ContainerInitResponse>, Status> {
        unreachable!("fixture already has an initialized LiveState")
    }

    /// Gate or fail container startup independently of the subsequent SSH request.
    async fn start(
        &self,
        request: Request<proto::ContainerStartRequest>,
    ) -> Result<Response<proto::ContainerStartResponse>, Status> {
        self.0.start_entered.notify_one();
        let block = *self.0.start_block.lock().unwrap();
        if block {
            self.0.start_release.notified().await;
        }
        if *self.0.start_fail.lock().unwrap() {
            return Err(Status::internal("injected Container.Start failure"));
        }
        Ok(Response::new(proto::ContainerStartResponse {
            result: Some(proto::container_start_response::Result::Success(
                proto::ContainerStartSuccess {
                    container_id: request.into_inner().container_id,
                },
            )),
        }))
    }
}

struct TestHandler;
impl VmmHandler for TestHandler {
    /// Allow normal backend cleanup without stopping a real VM.
    fn stop(&mut self) -> BoxliteResult<()> {
        Ok(())
    }
    /// Supply neutral metrics because these tests exercise RPCs, not hypervisor accounting.
    fn metrics(&self) -> BoxliteResult<VmmMetrics> {
        Ok(VmmMetrics::default())
    }
    /// Model a live VM while tests independently control the container's startup state.
    fn is_running(&self) -> bool {
        true
    }
    /// Use a sentinel PID because the fixture never spawns a VMM process.
    fn pid(&self) -> u32 {
        0
    }
}

struct Fixture {
    ssh: SshHandle,
    backend: Arc<BoxImpl>,
    mock: Arc<Mock>,
    server: tokio::task::JoinHandle<()>,
    _home: tempfile::TempDir,
}
impl Drop for Fixture {
    /// Abort the socket server so blocked mock RPCs do not outlive the fixture.
    fn drop(&mut self) {
        self.server.abort();
    }
}

/// Skip startup to isolate SSH request, response, and deadline behavior.
async fn fixture() -> Fixture {
    fixture_with_container(true).await
}

/// Connect a local box backend to mock guest services over its real Unix socket path.
/// Optionally leave Container.Start pending so tests can observe the startup boundary.
async fn fixture_with_container(started: bool) -> Fixture {
    let home = tempfile::TempDir::new_in("/tmp").unwrap();
    let runtime = RuntimeImpl::new_for_test(BoxliteOptions {
        home_dir: home.path().into(),
        image_registries: vec![],
    })
    .unwrap();
    let id = BoxIDMint::mint();
    let config = BoxConfig {
        box_home: runtime.layout.boxes_dir().join(id.as_str()),
        id,
        name: None,
        created_at: chrono::Utc::now(),
        container: ContainerRuntimeConfig {
            id: ContainerID::new(),
        },
        options: BoxOptions::default(),
        engine_kind: crate::vmm::VmmKind::Libkrun,
    };
    let mut state = BoxState::new();
    state.status = BoxStatus::Running;
    state.pid = Some(std::process::id());
    let backend = Arc::new(BoxImpl::new(
        config,
        state,
        runtime.clone(),
        runtime.shutdown_token.child_token(),
    ));
    let live = LiveState::new(
        Box::new(TestHandler),
        GuestSession::new(backend.config.transport()),
        None,
        None,
        BoxMetricsStorage::new(),
        Disk::new(home.path().join("container.qcow2"), DiskFormat::Qcow2, true),
        None,
        #[cfg(target_os = "linux")]
        None,
    );
    assert!(backend.live.set(live).is_ok());
    if started {
        backend.container_start.set(()).unwrap();
    }
    std::fs::create_dir_all(backend.layout.sockets().real_dir()).unwrap();
    backend.layout.sockets().ensure().unwrap();
    let proto::BoxTransport::Unix { socket_path } = backend.config.transport() else {
        unreachable!()
    };
    let listener = tokio::net::UnixListener::bind(socket_path).unwrap();
    let incoming = futures::stream::unfold(listener, |listener| async {
        Some((listener.accept().await.map(|(stream, _)| stream), listener))
    });
    let mock = Arc::new(Mock::default());
    let service = mock.clone();
    let server = tokio::spawn(async move {
        tonic::transport::Server::builder()
            .add_service(proto::ContainerServer::new(MockService(service.clone())))
            .add_service(proto::SshServer::new(MockService(service)))
            .serve_with_incoming(incoming)
            .await
            .unwrap();
    });
    let ssh = SshHandle::new(backend.clone());
    Fixture {
        ssh,
        backend,
        mock,
        server,
        _home: home,
    }
}

/// Populate every credential field with recognizable sentinels for wire and redaction checks.
fn config() -> SshConfig {
    SshConfig {
        listen_address: "0.0.0.0:2222".into(),
        host_private_key: "private sentinel".into(),
        accounts: vec![SshAccount {
            login: "alice".into(),
            authorized_keys: vec!["authorized sentinel".into()],
            ca: Some(SshCaConfig {
                public_key: "ca sentinel".into(),
                principal: "principal sentinel".into(),
            }),
        }],
    }
}

/// Preserve configuration fields and guest status across serialization for all three RPCs.
#[tokio::test]
async fn ssh_requests_and_responses_cross_wire() {
    let f = fixture().await;
    let status = f.ssh.configure(config()).await.unwrap();
    assert_eq!(
        status,
        SshStatus {
            enabled: true,
            generation: 7,
            listen_address: "0.0.0.0:2222".into(),
            host_public_key: "public host".into(),
            host_key_fingerprint: "SHA256:test".into()
        }
    );
    assert_eq!(f.ssh.status().await.unwrap(), status);
    assert_eq!(f.ssh.disable().await.unwrap(), status);
    let received = f.mock.config.lock().unwrap().clone().unwrap();
    assert_eq!(received.listen_address, "0.0.0.0:2222");
    assert_eq!(received.host_private_key, "private sentinel");
    assert_eq!(received.accounts[0].login, "alice");
    assert_eq!(
        received.accounts[0].authorized_keys,
        ["authorized sentinel"]
    );
    let ca = received.accounts[0].ca.as_ref().unwrap();
    assert_eq!(ca.public_key, "ca sentinel");
    assert_eq!(ca.principal, "principal sentinel");
    assert_eq!(
        *f.mock.requests.lock().unwrap(),
        ["configure", "status", "disable"]
    );
}

/// Guest rejections retain their error categories; missing status is an error, and
/// neither failure causes an extra request that could repeat a configuration change.
#[tokio::test]
async fn ssh_errors_missing_status_and_no_retry() {
    let f = fixture().await;
    for operation in 0..3 {
        for code in [
            tonic::Code::InvalidArgument,
            tonic::Code::FailedPrecondition,
            tonic::Code::Unimplemented,
            tonic::Code::Unavailable,
        ] {
            *f.mock.error.lock().unwrap() = Some(code);
            let error = match operation {
                0 => f.ssh.configure(config()).await,
                1 => f.ssh.status().await,
                _ => f.ssh.disable().await,
            }
            .unwrap_err();
            assert!(match code {
                tonic::Code::InvalidArgument => matches!(error, BoxliteError::InvalidArgument(_)),
                tonic::Code::FailedPrecondition => matches!(error, BoxliteError::InvalidState(_)),
                tonic::Code::Unimplemented => matches!(error, BoxliteError::Unsupported(_)),
                _ => matches!(error, BoxliteError::Rpc(_)),
            });
            assert!(error.to_string().contains("mock rejection"));
        }
        *f.mock.error.lock().unwrap() = None;
        *f.mock.missing.lock().unwrap() = true;
        let error = match operation {
            0 => f.ssh.configure(config()).await,
            1 => f.ssh.status().await,
            _ => f.ssh.disable().await,
        }
        .unwrap_err();
        assert!(matches!(error, BoxliteError::Internal(_)));
        *f.mock.missing.lock().unwrap() = false;
    }
    assert_eq!(f.mock.requests.lock().unwrap().len(), 15);
}

/// Apply the same lifecycle assertions to configure (0), status (1), and disable (2).
async fn operate(ssh: SshHandle, operation: usize) -> BoxliteResult<SshStatus> {
    match operation {
        0 => ssh.configure(config()).await,
        1 => ssh.status().await,
        _ => ssh.disable().await,
    }
}

/// Cold handles observe lifecycle state regardless of the configured main command.
#[tokio::test]
async fn ssh_observation_does_not_start_idle_boxes() {
    let f = fixture().await;
    for status in [
        BoxStatus::Configured,
        BoxStatus::Stopped,
        BoxStatus::Unknown,
        BoxStatus::Stopping,
        BoxStatus::Paused,
        BoxStatus::Failed,
    ] {
        for command in [None, Some("cmd"), Some("entrypoint")] {
            let mut config = f.backend.config.clone();
            match command {
                Some("cmd") => config.options.cmd = Some(vec!["main".into()]),
                Some(_) => config.options.entrypoint = Some(vec!["main".into()]),
                None => {}
            }
            let mut state = BoxState::new();
            state.status = status;
            let backend = Arc::new(BoxImpl::new(
                config,
                state,
                f.backend.runtime.clone(),
                f.backend.runtime.shutdown_token.child_token(),
            ));
            let ssh = SshHandle::new(backend.clone());
            for operation in 1..3 {
                let result = operate(ssh.clone(), operation).await;
                if matches!(status, BoxStatus::Configured | BoxStatus::Stopped) {
                    assert_eq!(
                        result.unwrap(),
                        SshStatus {
                            enabled: false,
                            generation: 0,
                            listen_address: String::new(),
                            host_public_key: String::new(),
                            host_key_fingerprint: String::new(),
                        }
                    );
                } else {
                    assert!(matches!(result, Err(BoxliteError::InvalidState(_))));
                }
                assert_eq!(backend.state.read().status, status);
                assert_eq!(backend.state.read().pid, None);
                assert!(!backend.live.initialized());
                assert!(!backend.container_start.initialized());
            }
            backend.shutdown_token.cancel();
            for operation in 1..3 {
                assert!(matches!(
                    operate(ssh.clone(), operation).await,
                    Err(BoxliteError::Stopped(_))
                ));
            }
        }
    }
    assert!(f.mock.requests.lock().unwrap().is_empty());
}

/// An attached or recovered VM serves SSH without initializing its main command.
#[tokio::test]
async fn ssh_observation_uses_existing_vm_without_container_start() {
    let f = fixture_with_container(false).await;
    let recovered = Arc::new(BoxImpl::new(
        f.backend.config.clone(),
        f.backend.state.read().clone(),
        f.backend.runtime.clone(),
        f.backend.runtime.shutdown_token.child_token(),
    ));
    for backend in [&f.backend, &recovered] {
        let ssh = SshHandle::new(backend.clone());
        for operation in 1..3 {
            assert_eq!(operate(ssh.clone(), operation).await.unwrap().generation, 7);
            assert!(!backend.container_start.initialized());
        }
    }
    assert!(!recovered.live.initialized());
    assert_eq!(
        *f.mock.requests.lock().unwrap(),
        ["status", "disable", "status", "disable"]
    );
}

/// Allow legitimate guest work beyond five seconds and preserve its drain error.
#[tokio::test]
async fn ssh_waits_for_guest_response_within_total_deadline() {
    for operation in 0..3 {
        for (seconds, code) in [(6, None), (10, Some(tonic::Code::DeadlineExceeded))] {
            let f = fixture().await;
            *f.mock.block.lock().unwrap() = true;
            *f.mock.error.lock().unwrap() = code;
            let call = tokio::spawn(operate(f.ssh.clone(), operation));
            f.mock.entered.notified().await;
            tokio::time::pause();
            tokio::time::advance(Duration::from_secs(seconds)).await;
            tokio::task::yield_now().await;
            tokio::time::resume();
            f.mock.release.notify_one();
            let result = tokio::time::timeout(Duration::from_secs(1), call)
                .await
                .unwrap()
                .unwrap();
            if let Some(code) = code {
                let error = result.unwrap_err();
                assert!(matches!(error, BoxliteError::Rpc(_)), "{error}");
                assert!(
                    error.to_string().contains(&format!("status: {code:?}")),
                    "{error}"
                );
                assert!(error.to_string().contains("mock rejection"), "{error}");
            } else {
                assert!(result.unwrap().enabled);
            }
            assert_eq!(f.mock.requests.lock().unwrap().len(), 1);
        }
    }
}

/// Configure waits for container startup, whose duration must not
/// consume the SSH deadline even when startup exceeds fifteen seconds.
#[tokio::test]
async fn ssh_configure_waits_for_container_start_without_charging_rpc_deadline() {
    let f = fixture_with_container(false).await;
    assert!(
        !f.backend.container_start.initialized(),
        "creating a handle must not start"
    );
    *f.mock.start_block.lock().unwrap() = true;
    *f.mock.block.lock().unwrap() = true;
    let call = tokio::spawn(operate(f.ssh.clone(), 0));
    tokio::select! {
        _ = f.mock.start_entered.notified() => {}
        _ = f.mock.entered.notified() => panic!("SSH RPC sent before Container.Start"),
    }
    // Running is already published, but configure is still waiting for main startup.
    *f.mock.block.lock().unwrap() = false;
    for operation in 1..3 {
        tokio::time::timeout(Duration::from_secs(1), operate(f.ssh.clone(), operation))
            .await
            .unwrap()
            .unwrap();
        assert!(!f.backend.container_start.initialized());
    }
    f.mock.requests.lock().unwrap().clear();
    f.mock.entered.notified().await;
    *f.mock.block.lock().unwrap() = true;
    tokio::time::pause();
    tokio::time::advance(Duration::from_secs(16)).await;
    tokio::task::yield_now().await;
    assert!(
        !call.is_finished(),
        "startup must not consume the SSH deadline"
    );
    assert!(f.mock.requests.lock().unwrap().is_empty());
    tokio::time::resume();
    f.mock.start_release.notify_one();
    f.mock.entered.notified().await;
    tokio::time::pause();
    tokio::time::advance(Duration::from_secs(6)).await;
    tokio::task::yield_now().await;
    tokio::time::resume();
    f.mock.release.notify_one();
    tokio::time::timeout(Duration::from_secs(5), call)
        .await
        .unwrap()
        .unwrap()
        .unwrap();
    assert!(f.backend.container_start.initialized());
    assert_eq!(f.mock.requests.lock().unwrap().len(), 1);
}

/// A startup failure must reach the caller before any SSH request is sent.
#[tokio::test]
async fn ssh_configure_container_start_failure_sends_no_ssh_rpc() {
    let f = fixture_with_container(false).await;
    *f.mock.start_fail.lock().unwrap() = true;
    let error = operate(f.ssh.clone(), 0).await.unwrap_err();
    assert!(
        error
            .to_string()
            .contains("injected Container.Start failure"),
        "{error}"
    );
    assert!(f.mock.requests.lock().unwrap().is_empty());
}

/// Container.Start retains its own cancellation after VM initialization completes.
#[tokio::test]
async fn ssh_configure_shutdown_cancels_container_start() {
    let f = fixture_with_container(false).await;
    *f.mock.start_block.lock().unwrap() = true;
    let call = tokio::spawn(operate(f.ssh.clone(), 0));
    tokio::select! {
        _ = f.mock.start_entered.notified() => {}
        _ = f.mock.entered.notified() => panic!("SSH RPC sent before Container.Start"),
    }
    f.backend.runtime.shutdown_token.cancel();
    let error = tokio::time::timeout(Duration::from_secs(1), call)
        .await
        .unwrap()
        .unwrap()
        .unwrap_err();
    assert!(matches!(error, BoxliteError::Stopped(_)));
    assert!(error.to_string().contains("SSH configure:"));
    assert!(f.mock.requests.lock().unwrap().is_empty());
}

/// Neither a spent live-state handle nor a cancelled backend may send another SSH RPC.
#[tokio::test]
async fn ssh_spent_and_cancelled_handles_send_nothing() {
    let f = fixture().await;
    f.backend.state.write().status = BoxStatus::Stopped;
    for operation in 0..3 {
        assert!(matches!(
            operate(f.ssh.clone(), operation).await,
            Err(BoxliteError::Stopped(_))
        ));
    }
    f.backend.state.write().status = BoxStatus::Running;
    f.backend.shutdown_token.cancel();
    for operation in 0..3 {
        let error = operate(f.ssh.clone(), operation).await.unwrap_err();
        assert!(matches!(error, BoxliteError::Stopped(_)));
        let name = ["configure", "status", "disable"][operation];
        assert!(error.to_string().contains(&format!("SSH {name}:")));
    }
    assert!(f.mock.requests.lock().unwrap().is_empty());
}

/// Bound an unanswered RPC by the deadline or shutdown signal, without retrying it.
#[tokio::test]
async fn ssh_timeout_and_runtime_shutdown() {
    for operation in 0..3 {
        for cancel in [false, true] {
            let f = fixture().await;
            *f.mock.block.lock().unwrap() = true;
            let ssh = f.ssh.clone();
            let call = tokio::spawn(async move {
                match operation {
                    0 => ssh.configure(config()).await,
                    1 => ssh.status().await,
                    _ => ssh.disable().await,
                }
            });
            f.mock.entered.notified().await;
            if cancel {
                f.backend.runtime.shutdown_token.cancel();
            } else {
                tokio::time::pause();
                tokio::time::advance(Duration::from_secs(14)).await;
                tokio::task::yield_now().await;
                assert!(!call.is_finished(), "SSH must have a 15-second budget");
                tokio::time::advance(Duration::from_secs(1)).await;
            }
            let error = tokio::time::timeout(Duration::from_millis(100), call)
                .await
                .expect("SSH operation must finish within its 15-second deadline")
                .unwrap()
                .unwrap_err();
            let name = ["configure", "status", "disable"][operation];
            assert!(error.to_string().contains(&format!("SSH {name}:")));
            if cancel {
                assert!(matches!(error, BoxliteError::Stopped(_)));
            } else {
                assert!(matches!(error, BoxliteError::Rpc(_)));
                assert!(error.to_string().contains("timed out after 15 seconds"));
                tokio::time::resume();
            }
            assert_eq!(f.mock.requests.lock().unwrap().len(), 1);
        }
    }
}

/// Nested account and CA credentials must stay out of configuration debug output.
#[test]
fn ssh_debug_redacts_credentials() {
    let debug = format!("{:?}", config());
    assert!(!debug.contains("sentinel"), "{debug}");
}

/// A peer accepting the socket but stalling HTTP/2 must not bypass the SSH deadline
/// or shutdown cancellation while the interface is being acquired.
#[tokio::test]
async fn ssh_deadline_and_shutdown_include_connection_handshake() {
    for operation in 0..3 {
        for cancel in [false, true] {
            let mut f = fixture().await;
            f.server.abort();
            let _ = (&mut f.server).await;
            let proto::BoxTransport::Unix { socket_path } = f.backend.config.transport() else {
                unreachable!()
            };
            std::fs::remove_file(&socket_path).unwrap();
            let listener = tokio::net::UnixListener::bind(socket_path).unwrap();
            let call = tokio::spawn(operate(f.ssh.clone(), operation));
            // Accept the transport but never answer the HTTP/2 handshake.
            let (_connection, _) = listener.accept().await.unwrap();
            if cancel {
                f.backend.runtime.shutdown_token.cancel();
            } else {
                tokio::time::pause();
                tokio::time::advance(Duration::from_secs(14)).await;
                tokio::task::yield_now().await;
                assert!(!call.is_finished(), "SSH must have a 15-second budget");
                tokio::time::advance(Duration::from_secs(1)).await;
            }
            let error = tokio::time::timeout(Duration::from_millis(100), call)
                .await
                .expect("SSH operation must finish within its 15-second deadline")
                .unwrap()
                .unwrap_err();
            if cancel {
                assert!(matches!(error, BoxliteError::Stopped(_)));
            } else {
                assert!(matches!(error, BoxliteError::Rpc(_)));
                assert!(error.to_string().contains("timed out after 15 seconds"));
                tokio::time::resume();
            }
            assert!(f.mock.requests.lock().unwrap().is_empty());
        }
    }
}