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
//! Fixtures shared across module test suites (`auth`, `client`), `#[cfg(test)]`-only.
//!
//! Extracted from `auth`'s own test fixtures (A2 Task 4 fix round) rather than
//! re-derived: `auth::tests` hit a umask trap there first — `create_dir_all`
//! and `std::fs::write` both apply the process umask to the mode they
//! request, so a 0700 directory or a 0600 file can silently come out wider
//! (0755 / 0644 under a common umask) and get rejected by `TokenStore`'s own
//! permission checks before the code under test ever runs (see
//! `auth::tests::temp_dir`'s doc, before this module existed, for the original
//! writeup). `client`'s Task 6+ fixtures need to drive a real `TokenManager`
//! against a real on-disk token directory, so they need the identical
//! umask-proof 0700-dir + 0600-token-file construction — moved here instead
//! of being re-derived (and re-broken) a second time in a different module.
use ;
use ;
/// A private, process+thread-scoped temp directory, created 0700 directly and
/// **removed when the guard drops**.
///
/// Never build this with `create_dir_all`: `mkdir(2)` applies the process
/// umask to the requested mode, so 0700 can come out as 0755 (umask 022) or
/// 0775 (a shared-group umask 002) — and `TokenStore::prepare_dir` then
/// rejects the fixture itself as `BadDirPermissions` before any test logic
/// runs, so every test using it fails without ever reaching the code path it
/// meant to exercise.
///
/// 이 값은 **가드**다 — 살아 있는 동안만 디렉터리가 존재한다. 즉시 버리는 형태
/// (`let _ = temp_dir("x");` · `temp_dir("x").join(..)`)를 쓰면 테스트 도중 디렉터리가
/// 사라진다. 반드시 이름 있는 바인딩(`let dir = temp_dir("x");`)으로 받을 것.
///
/// `Deref<Target = Path>` 이므로 `dir.join(..)`·`&dir` 는 그대로 쓸 수 있다. 소유
/// `PathBuf` 가 필요한 자리에서는 `dir.to_path_buf()` — 가드 바인딩은 살려 둘 것.
pub ;
/// [`TempDir`] 하나를 만든다.
///
/// 만들기 전에 지우고 다시 만든다. 이제는 `Drop` 이 정상 경로를 청소하므로 이
/// 사전 삭제가 잡는 것은 **좁다**: 같은 pid 를 재사용한 다른 실행이 SIGKILL·SIGSEGV
/// 로 죽어 `Drop` 조차 돌지 못하고 남긴 잔여물뿐이다.
///
/// 예전 doc 은 "pid/thread id 는 실행 간 재사용되므로 사전 삭제가 이전 실행의
/// 잔여물을 치운다" 고 적었는데 **그 논증은 틀렸다.** pid 는 `cargo test` 실행마다
/// 바뀌므로 이름이 거의 매칭되지 않고, 그래서 사전 삭제는 사실상 아무것도 치우지
/// 못한 채 (실행 × 태그 × 스레드)마다 디렉터리가 하나씩 영구 누적됐다.
///
/// **사고의 실측치는 여기 한 곳에만 적는다**(2026-08-13 KST, 다른 세션 계측).
/// `/tmp` 최상위 `fleetwire-*` 가 **77,890 개**(05:39 분류 실측). 이것은 하한이다 —
/// 그 시점엔 `systemd-tmpfiles` 가 이미 10분째 지우고 있었고, 부팅 시점 실제값은
/// **77,890 ~ 83,585** 구간, 단일 점으로는 **약 8만**. (최초 보고된 "약 97,000" 은
/// 뺄셈 오류로 **철회됐다** — 다른 크레이트의 가드 doc 이 그 수를 복제하고 있었기에
/// 여기로 모았다. 숫자를 다시 퍼뜨리지 말 것.) 그 결과 부팅 시 `systemd-tmpfiles` 가
/// 약 30건/초로 지우느라 `sysinit.target` 을 **76분** 막았고, 뒤따르던
/// `cron`·`docker`·`dbus` 가 전부 대기해 운영 cron 이 유실됐다.
///
/// **청소를 보장하는 것은 `Drop` 이다** — 사전 삭제가 아니다.
///
/// `Drop` 은 SIGKILL·강제중단에서는 돌지 않는다. 그 경로로 죽으면 그 실행분은
/// 그대로 남는다(사전 삭제가 pid 재사용 시에만 좁게 회수). 스위트가 정상 종료하는
/// 한 증가분은 0 이다 — 그것이 이 파일의 계약이다.
pub
/// Seeds a 0600 token file directly at `dir/`[`crate::auth::TOKEN_FILE`],
/// matching `auth::store::TokenStore`'s on-disk shape.
///
/// Fix round 1 (Minor 1): this used to hardcode the literal `"tokens.json"`
/// while `auth::tests::token_path` derived the same name from `TokenStore` —
/// exactly the split source of truth A2 warned about avoiding. Both now read
/// the one constant `auth::store` owns.
///
/// Never seed with `std::fs::write` alone: the process umask widens a
/// requested 0644-ish default further, and `TokenStore::load` stops at
/// `BadPermissions` before it ever parses the content.
pub
/// An already-expired token (so the first `access_token*` call is forced
/// through the refresh/adopt path rather than served from cache).
pub
/// An expiry far enough in the future that no test needs a refresh to reach it.
pub const FAR_FUTURE: u64 = 4_000_000_000;
// --- A4 live-captured fixtures (2026-08-03) ---------------------------------
//
// Real bytes from live measurements, shared across A4 task test suites.
// Do not reformat, re-indent, or "fix" these — later tasks assert against
// the precise strings, including an empty `error_description` and an
// embedded `txid`.
/// 408, vehicle offline. Uses the envelope, and `error_description` is an
/// **empty string**.
///
/// Consumed by A4 Task 3's `txid_survives_on_vehicle_offline` and
/// `txid_is_not_redacted`.
pub const FIXTURE_408_OFFLINE: &str = r#"{"response":null,"error":"vehicle unavailable: vehicle is offline or asleep","error_description":"","txid":"432e7faaa94cf732bdda8f82f2184eea"}"#;
/// List response. `pagination` and `count` are **sibling keys** of `response`.
pub const FIXTURE_VEHICLES_PAGED: &str = r#"{"response":[{"id":1,"vin":"5YJ3E1EA1JF000001","state":"offline"}],"pagination":{"previous":null,"next":null,"current":1,"per_page":1,"count":1,"pages":1},"count":1}"#;
/// State query for the cost gate. `backseat_token` rides along on a
/// successful response.
pub const FIXTURE_VEHICLE_STATE_OFFLINE: &str = r#"{"response":{"id":1,"vin":"5YJ3E1EA1JF000001","state":"offline","backseat_token":"SECRET-BACKSEAT","display_name":"","in_service":false}}"#;
/// `error` is an **empty string**, so the T3 fallback chain actually runs.
/// `FIXTURE_408_OFFLINE` alone never falls through, which would make that
/// test vacuous (design doc §8 T-b).
///
/// Consumed by A4 Task 3's `empty_error_is_skipped_and_description_wins`.
pub const FIXTURE_ERR_EMPTY_ERROR: &str = r#"{"response":null,"error":"","error_description":"the vehicle could not be reached","txid":"deadbeef"}"#;