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
//! Process-wide env-mutation lock shared by every bridged unit-test module that
//! mutates process env (`THEWAY_DIR`, provider API keys, base URLs, …).
//!
//! History (issue #16): `tests/commands/mod.rs` serialized its env mutations
//! with a local `static ENV_LOCK` while `tests/local_models/mod.rs` used its own
//! TokioMutex. Both modules are bridged into the same lib test binary
//! (`theway-daemon --lib`, via `tests_bridge!`), so the two locks never saw each
//! other: `AuthStore` resolves `THEWAY_DIR` at call time, and a concurrent
//! `THEWAY_DIR` swap from the other module made `model_credential_hint_*` fail
//! ~1/6 of runs. One process-wide lock fixes the race.
//!
//! Wiring: the daemon lib test target bridges this file from `src/lib.rs`
//! (`#[path] mod test_env`). Integration binaries that also pull env-mutating
//! modules bridge it at their own crate root (see `tests/commands_e2e_main.rs`).
//! Every binary is its own process (env is per-process), so no cross-binary
//! coordination is needed.
/// Serializes all env mutations in this test process across bridged modules.
///
/// Holding the guard across `.await` is safe in tests: `#[tokio::test]` runs on
/// a current-thread runtime, so the future never migrates worker threads. (The
/// workspace already allows `clippy::await_holding_lock` for this pattern.)
pub static ENV_LOCK: Mutex = new;
/// Restores the previous env value (or its absence) on drop.
pub