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
//! Test-only helpers shared by unit tests across the TUI crate.
//!
//! The process-global current-working-directory is a shared resource that several
//! tests must mutate (to point App::new at a fresh temp repo). Each test module
//! used to declare its own `Mutex`, which meant tests in different modules could
//! race against each other even though they individually serialised. This
//! module exposes a single crate-wide lock so every test participates in the
//! same serialisation — and it returns a poison-tolerant guard so a single
//! panicking test does not cascade into every subsequent test.
use ;
use ;
static CWD_LOCK: = new;
/// Acquire the shared CWD lock, returning the inner guard even when the mutex
/// has been poisoned by a prior panic. Test isolation is still preserved
/// because the guard still serialises access to the directory.
/// Return a `tokio::runtime::Handle` backed by a process-wide test runtime.
///
/// Production code in the TUI takes a `Handle` everywhere an async forge call
/// fires. Tests need a handle just to satisfy `App::build`'s signature —
/// they don't actually exercise forge async paths. Lazily spinning up a
/// single shared multi-thread runtime keeps the test footprint small while
/// letting every `#[test]` get a real handle without per-test runtime
/// churn.
///
/// The runtime is stored in a `OnceLock` so it's never dropped for the
/// lifetime of the test process; tokio's multi-thread runtime refuses to
/// drop while it still has spawned work, and leaking it matches how the
/// production runtime in `main.rs` lives for the duration of `trv`.