cosca 0.7.0

Unified cross-platform subprocess management: spawning, stdio, process trees, stable identity, and elevation.
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
use std::future::Future;
use std::pin::pin;
use std::task::{Context, Poll, Waker};
use std::time::Duration;

#[cfg(unix)]
use super::absolute;
use super::{exited_held, run};
use crate::error::Error;
use crate::os_process::drive::ProcessExit;
use crate::os_process::fake::{Answer, FakeProcess};
use crate::wait::fault;
#[cfg(unix)]
use crate::{
    os_process::drive::{
        drive_tests::{ms, whole_ms, Move, Scripted},
        RunOutcome,
    },
    wait::block_probe,
};

fn fake(exits: impl IntoIterator<Item = Answer>) -> FakeProcess {
    FakeProcess::new(exits)
}

/// Poll `fut` once, with a waker that wakes nothing.
pub(crate) fn poll_once<F: Future>(fut: F) -> Poll<F::Output> {
    pin!(fut).as_mut().poll(&mut Context::from_waker(Waker::noop()))
}

/// Mutant: await at a zero timeout, or look a second time.
#[skuld::test]
async fn zero_timeout_looks_once_and_never_waits() {
    let p = fake([Answer::Running]);
    let Poll::Ready(answer) = poll_once(exited_held(&p, Some(Duration::ZERO))) else {
        panic!("a zero timeout must not wait");
    };
    assert!(!answer.unwrap());
    assert_eq!(p.looks(), 1);
}

/// Mutant: swallow a failed look as a wake, or wait before returning it.
#[skuld::test]
async fn a_failed_look_is_returned_without_waiting() {
    let p = fake([Answer::Err(std::io::ErrorKind::PermissionDenied)]);
    let Poll::Ready(answer) = poll_once(exited_held(&p, None)) else {
        panic!("a failed look must not wait");
    };
    let err = answer.unwrap_err();
    assert!(
        matches!(&err, Error::Io(e) if e.kind() == std::io::ErrorKind::PermissionDenied),
        "{err:?}"
    );
    assert_eq!(p.looks(), 1);
}

/// Mutant: wait before looking, or after an `Exited` look.
#[skuld::test]
async fn exited_before_first_look_returns_true_without_waiting() {
    let p = fake([Answer::Exited]);
    let Poll::Ready(answer) = poll_once(exited_held(&p, None)) else {
        panic!("an exited process must not wait");
    };
    assert!(answer.unwrap());
    assert_eq!(p.looks(), 1);
}

/// Mutant: trust the wake as the answer instead of looking again.
#[skuld::test]
async fn wakes_and_looks_again() {
    let p = fake([Answer::Running, Answer::Exited]);
    p.wake();
    assert!(exited_held(&p, Some(Duration::from_secs(60))).await.unwrap());
    assert_eq!(p.looks(), 2);
}

/// Mutant: answer `false` on the expiry itself, without a look after the deadline. The fake is never
/// woken, so only the deadline ends the wait.
#[skuld::test]
async fn expiry_ends_in_one_final_look() {
    let timeout = Duration::from_millis(50);
    let p = fake([Answer::Running, Answer::Running]);
    let start = crate::wait::now();
    assert!(!exited_held(&p, Some(timeout)).await.unwrap());
    assert_eq!(p.looks(), 2);
    let last = *p.look_times().last().unwrap();
    assert!(
        last >= start + timeout,
        "the final look must come at or after the deadline"
    );
}

/// Mutant: answer `false` on the expiry without trusting the final look, which finds an exit that
/// was pending when the deadline passed.
#[skuld::test]
async fn the_final_look_can_find_an_exit() {
    let p = fake([Answer::Running, Answer::Exited]);
    assert!(exited_held(&p, Some(Duration::from_millis(50))).await.unwrap());
    assert_eq!(p.looks(), 2);
}

/// Mutant: let `Duration::MAX` overflow the deadline sum.
#[skuld::test]
async fn duration_max_is_unbounded() {
    #[cfg(unix)]
    let (tx, armed) = std::sync::mpsc::channel();
    #[cfg(unix)]
    let _seam = {
        crate::tokio::test_runtime::assert_current_thread();
        crate::tokio::wait::armed_deadline_seam::install(tx)
    };
    // Windows: the clock reads of the driver and of the blocking half, which arms the wait.
    #[cfg(windows)]
    let (log_tx, reads) = std::sync::mpsc::channel();
    #[cfg(windows)]
    let _log = crate::wait::read_probe::install(log_tx);
    let p = fake([Answer::Running, Answer::Exited]);
    p.wake();
    assert!(exited_held(&p, Some(Duration::MAX)).await.unwrap());
    #[cfg(unix)]
    assert_eq!(armed.try_iter().count(), 0, "an overflowing timeout arms no timer");
    #[cfg(windows)]
    {
        use crate::wait::read_probe::Event;

        let reads: Vec<Event> = reads.try_iter().collect();
        assert!(
            reads
                .iter()
                .any(|event| matches!(event, Event::Read { deadline: None, .. })),
            "the blocking half arms its own wait: {reads:?}"
        );
        assert!(
            reads
                .iter()
                .all(|event| matches!(event, Event::Read { remaining: None, .. })),
            "an overflowing timeout arms an unbounded wait: {reads:?}"
        );
    }
}

/// Mutant: arm the timer for a duration re-derived later, or not at all.
#[cfg(unix)]
#[skuld::test]
async fn a_bounded_wait_arms_the_timer_at_the_deadline() {
    use crate::tokio::wait::armed_deadline_seam::{install, Armed};

    crate::tokio::test_runtime::assert_current_thread();
    let (tx, armed) = std::sync::mpsc::channel();
    let _seam = install(tx);
    let timeout = Duration::from_secs(60);
    let before = crate::tokio::wait::tokio_now();
    let p = fake([Answer::Running, Answer::Exited]);
    p.wake();
    assert!(exited_held(&p, Some(timeout)).await.unwrap());
    let after = crate::tokio::wait::tokio_now();
    let [Armed::At(at)] = armed.try_iter().collect::<Vec<_>>()[..] else {
        panic!("one wait arms one timer");
    };
    assert!(at >= before + timeout && at <= after + timeout, "{at:?}");
}

/// A `Running` fake whose wait is dropped, and then the runtime. Mutant: the Windows
/// watcher is not released by the drop, so the runtime's drop joins a thread parked on the fake
/// forever; the observer then never hears a release.
#[skuld::test]
fn dropped_wait_releases_the_watch() {
    #[cfg(windows)]
    let (tx, released) = std::sync::mpsc::channel();
    #[cfg(windows)]
    let observer = crate::tokio::wait::fault_observer::install(tx);
    let runtime = ::tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()
        .expect("build a runtime");
    let p = fake([Answer::Running]);
    runtime.block_on(async {
        let mut wait = pin!(exited_held(&p, None));
        assert!(
            wait.as_mut().poll(&mut Context::from_waker(Waker::noop())).is_pending(),
            "a running process with nothing fired waits"
        );
    }); // the wait is dropped here
    #[cfg(windows)]
    {
        // The watcher holds its own copy of the observer; ours must go so a missing release ends
        // the `recv` instead of hanging it.
        drop(observer);
        released
            .recv()
            .expect("the blocking watcher must return after the drop released it");
    }
    drop(runtime);
}

/// Open descriptors of this process (each count includes the directory handle that reads it).
#[cfg(target_os = "linux")]
pub(crate) fn open_fds() -> usize {
    std::fs::read_dir("/proc/self/fd").expect("read /proc/self/fd").count()
}

/// A wait round opens no process descriptor of its own (no `pidfd_open`): the one descriptor it adds
/// is a duplicate of the pidfd the process already holds, which is what lets waits on one process
/// run at once (the reactor takes one registration per descriptor).
///
/// Mutant: open a pidfd for the round, which is a second added descriptor. Mutant: register the
/// held pidfd itself, which adds none (and fails a second concurrent wait; see
/// `async_foreign_concurrent_waits_both_resolve_on_exit`).
#[cfg(target_os = "linux")]
#[skuld::test]
fn a_wait_round_adds_only_a_duplicate_of_the_held_pidfd() {
    use crate::os_process::open;
    use crate::test_child::held_contained_blocker_without_cgroup;

    let (child, stdin) = held_contained_blocker_without_cgroup(crate::Stdio::null());
    let process = open(child.id().expect(crate::test_child::IDENTITY_READ))
        .unwrap()
        .expect("a live process opens");
    let runtime = ::tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()
        .expect("build a runtime");
    let before = open_fds();
    let during = runtime.block_on(async {
        let mut wait = pin!(exited_held(&*process, None));
        assert!(
            wait.as_mut().poll(&mut Context::from_waker(Waker::noop())).is_pending(),
            "a running process waits"
        );
        open_fds()
    });
    assert_eq!(during, before + 1, "the round adds exactly one descriptor, a duplicate");
    drop(stdin);
    child.wait().expect("reap the blocker");
}

/// The futures cross threads on every platform: `spawn` needs it.
#[skuld::test]
fn async_waits_are_send() {
    fn assert_send<T: Send>(_: &T) {}

    let p = fake([]);
    assert_send(&exited_held(&p, None));
    assert_send(&run(&mut ProcessExit(&p), None));
    let process = crate::tokio::Process::current().expect("open this process");
    assert_send(&process.wait());
}

/// The pauses `run` recorded, in whole milliseconds.
#[cfg(unix)]
fn pauses() -> Vec<u64> {
    let pauses: Vec<_> = block_probe::take()
        .into_iter()
        .map(|pause| pause.expect("a pause is bounded"))
        .collect();
    whole_ms(&pauses)
}

/// Mutant: pause a constant, or restart the schedule at every pause, or arm no timer.
#[cfg(unix)]
#[skuld::test(runtime = crate::tokio::test_runtime::paused)]
async fn async_run_pauses_on_the_backoff_for_a_recheck() {
    block_probe::take();
    let mut w = Scripted::new([Move::Recheck, Move::Recheck, Move::Recheck, Move::Done]);
    assert!(matches!(run(&mut w, None).await.unwrap(), RunOutcome::Done(())));
    assert_eq!(pauses(), [1, 2, 4]);
    assert_eq!(w.looks, 4, "one look per pause, and one more");
}

/// A pause never outlasts the deadline: the last one is cut to the time remaining, and the look
/// after it is the final one.
///
/// Mutant: pause the whole step; or make no final look after the last pause; or pause again at the
/// deadline.
#[cfg(unix)]
#[skuld::test(runtime = crate::tokio::test_runtime::paused)]
async fn async_run_cuts_a_pause_to_the_deadline_and_looks_once_more() {
    block_probe::take();
    let mut w = Scripted::new([Move::Recheck; 3]);
    let outcome = run(&mut w, absolute(Some(ms(3)))).await.unwrap();
    assert!(matches!(outcome, RunOutcome::DeadlinePassed), "{outcome:?}");
    assert_eq!(pauses(), [1, 2]);
    assert_eq!(w.looks, 3, "the last look is made at the deadline");
}

/// A pause the deadline cuts is armed at the deadline instant, not at a duration from a later clock
/// read: the clock moves between the look and the arm, and the timer still ends at the deadline.
///
/// Mutant: arm `tokio_now() + <the step cut to the time left>`.
#[cfg(unix)]
#[skuld::test(runtime = crate::tokio::test_runtime::paused)]
async fn async_run_arms_a_cut_pause_at_the_deadline_instant() {
    use crate::tokio::wait::armed_deadline_seam::{install, Armed};
    use crate::tokio::wait::{now_override, tokio_now};

    let (tx, armed) = std::sync::mpsc::channel();
    let _seam = install(tx);
    // Half of the first 1 ms step: the deadline cuts the first pause.
    let deadline = absolute(Some(Duration::from_micros(500))).expect("a finite deadline");
    // The clock reads later in the pause than when the look ended.
    let moved = std::rc::Rc::new(std::cell::RefCell::new(None));
    let _moves = block_probe::on_pause({
        let moved = moved.clone();
        move || *moved.borrow_mut() = Some(now_override::install(tokio_now() + Duration::from_micros(200)))
    });
    let mut w = Scripted::new([Move::Recheck, Move::Done]);
    assert!(matches!(
        run(&mut w, Some(deadline)).await.unwrap(),
        RunOutcome::Done(())
    ));
    assert!(moved.borrow().is_some(), "the clock moved before the arm");
    assert_eq!(armed.try_iter().collect::<Vec<_>>(), [Armed::At(deadline)]);
}

/// Mutant: keep the schedule across a wait.
#[cfg(unix)]
#[skuld::test(runtime = crate::tokio::test_runtime::paused)]
async fn async_run_restarts_the_backoff_after_a_wait() {
    block_probe::take();
    let mut w = Scripted::new([Move::Recheck, Move::Recheck, Move::Wait, Move::Recheck, Move::Done]);
    assert!(matches!(run(&mut w, None).await.unwrap(), RunOutcome::Done(())));
    assert_eq!(pauses(), [1, 2, 1]);
}

/// A failed wait is the `Waitable`'s to answer: one that survives it is looked at again.
///
/// Mutant: end the loop on a wait error the `Waitable` survived; or never hand it to the `Waitable`.
#[cfg(target_os = "linux")]
#[skuld::test(runtime = crate::tokio::test_runtime::paused)]
async fn async_run_survives_a_failed_wait_when_the_waitable_does() {
    let mut w = Scripted::new([Move::WaitFails, Move::Recheck, Move::Done]);
    w.survive_block_errors = true;
    assert!(matches!(run(&mut w, None).await.unwrap(), RunOutcome::Done(())));
    assert_eq!(w.block_errors, 1);
    assert_eq!(w.looks, 3);
}

#[cfg(windows)]
mod windows {
    //! The blocking half of the Windows arm, `wait_process_or_cancel`: cancel-race and re-arm tests
    //! on the handle an `OsProcess` hands out.

    use std::time::{Duration, Instant};

    use std::os::windows::io::BorrowedHandle;

    use crate::os_process::windows::cancel::{new_cancel_event, signal_cancel, wait_process_or_cancel};
    use crate::os_process::{open, Exit, OsProcess, WaitFor};
    use crate::wait::test_clock::FrozenClockGuard;
    use crate::wait::wait_ms_probe;
    use crate::wait::{remaining_override_seam, wait_clamp_seam};

    use crate::test_child::live_blocker as blocker;

    /// The handle a look at a live process hands out to wait on.
    fn wait_handle(p: &dyn OsProcess) -> BorrowedHandle<'_> {
        match p.exited().unwrap() {
            Exit::Running(WaitFor::Signalled(handle)) => handle,
            other => panic!("a live process reads Running(Signalled): {other:?}"),
        }
    }

    /// Mutant: truncate in `win32_timeout_ms` -> `ms` is 0. Mutant: add slack -> `ms` is above 1.
    /// Mutant: ignore the site's grace -> `requested` is not 5ms.
    #[skuld::test]
    fn the_blocking_half_arms_the_ceiling_of_the_remaining_duration() {
        let (child, stdin, id) = blocker();
        let process = open(id).unwrap().expect("a live process opens");
        let cancel = new_cancel_event().expect("create cancel event");
        let (_clock, at) = FrozenClockGuard::install();
        wait_ms_probe::take();
        let _override = remaining_override_seam::set(Duration::from_micros(500));
        let deadline = at + Duration::from_millis(5);
        let result = wait_process_or_cancel(wait_handle(&*process), Some(deadline), &cancel);
        let reached = Instant::now() >= deadline;
        let arms = wait_ms_probe::take();
        drop(stdin);
        child.wait().expect("reap the blocker");
        assert!(
            !result.expect("a live never-exiting child must not report a wait failure"),
            "a never-exiting child is still alive when the grace elapses"
        );
        assert!(reached, "the call returned before the real deadline");
        let first = arms.first().expect("at least one armed wait");
        assert_eq!(first.remaining, Duration::from_micros(500));
        assert_eq!(first.ms, 1);
        assert_eq!(
            first.requested,
            Duration::from_millis(5),
            "the site must pass the time left to its own grace (clock frozen at the grace's origin)"
        );
    }

    /// An early, unclamped `WAIT_TIMEOUT` hours before the grace ends is not trusted: the site
    /// re-arms. Exit (`Ok(true)`) proves it, since a cancel or a timeout would both read `Ok(false)`.
    ///
    /// Mutant: return on the first `WAIT_TIMEOUT` -> one arm, wrongly reports alive.
    #[skuld::test]
    fn the_blocking_half_never_reports_still_alive_before_the_deadline() {
        let (child, stdin, id) = blocker();
        let process = open(id).unwrap().expect("a live process opens");
        let cancel = new_cancel_event().expect("create cancel event");
        wait_ms_probe::take();
        let _override = remaining_override_seam::set(Duration::from_micros(500));
        wait_ms_probe::on_second_arm(move || drop(stdin));
        let result = wait_process_or_cancel(
            wait_handle(&*process),
            Some(Instant::now() + Duration::from_secs(3600)),
            &cancel,
        );
        let arms = wait_ms_probe::take();
        let exited = result.expect("a genuinely-terminated child must not report a wait failure");
        child.wait().expect("reap the child after it exits");
        assert!(exited, "an early WAIT_TIMEOUT was trusted");
        assert!(arms.len() >= 2, "expected a re-arm, got {} arm(s)", arms.len());
    }

    /// A wait clamped below the grace re-arms, recomputing `remaining` each round.
    ///
    /// Mutant: drop the re-arm loop -> one arm, wrongly reports alive. Mutant: hoist `remaining`
    /// above the loop -> `remaining` does not shrink.
    #[skuld::test]
    fn the_blocking_half_re_arms_past_a_clamped_timeout() {
        let (child, stdin, id) = blocker();
        let process = open(id).unwrap().expect("a live process opens");
        let cancel = new_cancel_event().expect("create cancel event");
        wait_ms_probe::take();
        let _clamp = wait_clamp_seam::set(5);
        wait_ms_probe::on_second_arm(move || drop(stdin));
        let result = wait_process_or_cancel(
            wait_handle(&*process),
            Some(Instant::now() + Duration::from_secs(3600)),
            &cancel,
        );
        let arms = wait_ms_probe::take();
        let exited = result.expect("a genuinely-terminated child must not report a wait failure");
        child.wait().expect("reap the child after it exits");
        assert!(exited, "a clamped WAIT_TIMEOUT was trusted");
        wait_ms_probe::assert_rearmed_with_fresh_remaining(&arms, 5);
    }

    /// A pre-signalled cancel event releases the wait on a live child.
    #[skuld::test]
    fn cancel_event_releases_the_blocking_wait() {
        let (child, _stdin, id) = blocker();
        let process = open(id).unwrap().expect("a live process opens");
        let cancel = new_cancel_event().expect("event");
        signal_cancel(&cancel);
        let exited = wait_process_or_cancel(wait_handle(&*process), None, &cancel).expect("cancellable wait");
        assert!(!exited, "a live child with a signaled cancel must report still-alive");
        child.kill().expect("cleanup");
        child.wait().expect("reap");
    }

    /// A cancel signalled while the wait is, or is about to be, in flight releases it. The
    /// manual-reset event stays set once signalled, so every interleaving releases the watcher.
    #[skuld::test]
    fn cancel_event_signaled_mid_wait_releases_the_blocking_wait() {
        let (child, _stdin, id) = blocker();
        let process = open(id).unwrap().expect("a live process opens");
        let cancel = std::sync::Arc::new(new_cancel_event().expect("event"));
        let handle = wait_handle(&*process);
        let exited = std::thread::scope(|scope| {
            let watcher = scope.spawn(|| wait_process_or_cancel(handle, None, &cancel));
            signal_cancel(&cancel);
            watcher.join().expect("watcher thread").expect("cancellable wait")
        });
        assert!(!exited, "a live child with a signaled cancel must report still-alive");
        child.kill().expect("cleanup");
        child.wait().expect("reap");
    }

    /// `armed_probe` reaches the blocking half through the driver's hop: the armed poll finds the
    /// fake's event unsignalled, reports it, and force-releases the wait.
    ///
    /// Mutant: the hop does not relay the probe -> nothing is reported.
    #[skuld::test]
    async fn the_armed_probe_reaches_the_blocking_half() {
        use super::{fake, Answer};

        crate::tokio::test_runtime::assert_current_thread();
        let (tx, armed) = std::sync::mpsc::channel();
        let _guard = crate::os_process::windows::cancel::armed_probe::install(tx);
        let p = fake([Answer::Running, Answer::Exited]);
        assert!(super::exited_held(&p, None).await.unwrap());
        assert_eq!(
            armed.try_iter().count(),
            1,
            "the wait armed on an unsignalled target once"
        );
    }

    /// A release that is neither an exit nor the deadline ends the wait after one final look, which
    /// answers.
    ///
    /// Mutant: the arm discards the blocking half's verdict, so the loop re-arms and looks again
    /// past the script.
    #[skuld::test]
    async fn a_forced_release_ends_the_wait_after_one_final_look() {
        use super::{fake, Answer};

        crate::tokio::test_runtime::assert_current_thread();
        let (tx, armed) = std::sync::mpsc::channel();
        let _guard = crate::os_process::windows::cancel::armed_probe::install(tx);
        let p = fake([Answer::Running, Answer::Running]);
        assert!(!super::exited_held(&p, None).await.unwrap());
        assert_eq!(p.looks(), 2, "one look, one wait, one final look");
        assert_eq!(armed.try_iter().count(), 1, "the wait armed once");
    }
}

/// Mutant: `exited_opening` takes the seam only after `open`, so a gone process never reaches it.
#[skuld::test]
async fn exited_opening_returns_a_forced_watch_error_for_a_gone_process() {
    crate::tokio::test_runtime::assert_current_thread();
    fault::set_force_watch_error(true);
    let opened = || panic!("the seam comes before the open");
    assert!(super::exited_opening(opened, None).await.is_err());
    assert!(!fault::armed(), "the seam is consumed");
}

/// Mutant: `exited_opening` waits on, or errs for, a process that is gone.
#[skuld::test]
async fn exited_opening_resolves_at_once_for_a_gone_process() {
    crate::tokio::test_runtime::assert_current_thread();
    assert!(super::exited_opening(|| Ok(None), None).await.unwrap());
}

/// Mutant: `exited_held` skips the seam, or looks at a process the seam should have refused.
#[skuld::test]
async fn exited_held_takes_the_watch_fault_seam() {
    crate::tokio::test_runtime::assert_current_thread();
    let p = fake([Answer::Exited]);
    fault::set_force_watch_error(true);
    assert!(super::exited_held(&p, None).await.is_err());
    assert!(!fault::armed(), "the seam is consumed");
    assert_eq!(p.looks(), 0, "the seam comes before any look");
}

/// Mutant: `exited_held` drops the timeout, or does not resolve for an exited process.
#[skuld::test]
async fn exited_held_resolves_for_an_exited_fake() {
    crate::tokio::test_runtime::assert_current_thread();
    let exited = fake([Answer::Exited]);
    assert!(super::exited_held(&exited, None).await.unwrap());
    let running = fake([Answer::Running]);
    assert!(!super::exited_held(&running, Some(Duration::ZERO)).await.unwrap());
    assert_eq!(running.looks(), 1);
}