forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits

alerts.rs690 lines, 25.0 KiBHistoryRawDownload
1//! Admin alerts: tells the site admins about trouble before something breaks.
2//!
3//! An alert is a condition with a stable key. [`raise`] tells the admins once, however often the
4//! condition is reported, and [`resolve`] tells them once that it is over (see
5//! `Store::raise_alert`). [`event`] is for a thing that happened once, such as a killed CI job.
6//! Delivery is an inbox row for every site admin, pushed to their open bell stream, plus an email
7//! when `alerts.email` is on and the admin has a verified address.
8//!
9//! Most alerts are raised where the trouble is seen: a failed backup, a failed self-update, a
10//! killed job, a runner that checks in again. The conditions nothing reports (a runner that went
11//! silent, a full disk, an overdue backup, a lagging standby) are looked at on ticks that already
12//! exist: [`check_runners`] on every CI reaper pass, [`check_slow`] on every tenth.
13
14use std::sync::OnceLock;
15use std::sync::atomic::{AtomicBool, Ordering};
16
17use forge_core::alerts::{self, AlertKind};
18use forge_core::mail::{MailKind, OutgoingMail};
19use forge_core::store::backup_runs::RunKind;
20use forge_core::time::stamp_to_unix;
21
22use crate::i18n::{self, alerts as text};
23use crate::mail;
24use crate::notify_hub::publish_unread;
25use crate::state::AppState;
26use crate::views::now_unix;
27
28/// True while some runner-offline alert is active, so a runner that checks in costs a database
29/// write only when there is something to resolve.
30static OFFLINE_ACTIVE: AtomicBool = AtomicBool::new(false);
31/// When this process started, as unix seconds. An install that never made a backup is overdue
32/// from here, not from 1970.
33static STARTED: OnceLock<i64> = OnceLock::new();
34
35fn started() -> i64 {
36 *STARTED.get_or_init(now_unix)
37}
38
39fn kind_of(topic: &str) -> AlertKind {
40 match topic {
41 "runner_offline" => AlertKind::RunnerOffline,
42 "backup_failed" | "backup_verify_failed" | "backup_overdue" | "fsck_failed" => {
43 AlertKind::Backup
44 }
45 "disk_low" => AlertKind::Disk,
46 "ci_killed" => AlertKind::CiKilled,
47 "self_update_restart" | "self_update_failed" => AlertKind::SelfUpdate,
48 _ => AlertKind::Replication,
49 }
50}
51
52/// Raises the alert `key` of `topic`. The admins hear about it once, until it resolves.
53pub async fn raise(state: &AppState, topic: &str, key: &str, subject: &str, detail: &str) {
54 if !state.live().alerts.kind_enabled(kind_of(topic)) {
55 return;
56 }
57 match state.store.raise_alert(key, topic, subject, detail).await {
58 Ok(true) => {
59 if topic == "runner_offline" {
60 OFFLINE_ACTIVE.store(true, Ordering::Relaxed);
61 }
62 deliver(state, key, topic, subject, detail, false).await;
63 }
64 Ok(false) => {}
65 Err(e) => tracing::error!(error = %e, key, "alerts: raising failed"),
66 }
67}
68
69/// Resolves the alert `key`. The admins are told only when it was active.
70pub async fn resolve(state: &AppState, key: &str) {
71 match state.store.resolve_alert(key).await {
72 Ok(Some(alert)) => {
73 crate::live::admin().bump(&crate::live::Topic::AdminHealth);
74 let kind = kind_of(&alert.kind);
75 if state.live().alerts.kind_enabled(kind) {
76 deliver(state, key, &alert.kind, &alert.subject, &alert.detail, true).await;
77 }
78 }
79 Ok(None) => {}
80 Err(e) => tracing::error!(error = %e, key, "alerts: resolving failed"),
81 }
82}
83
84/// Tells the admins that something happened, once per `key`.
85pub async fn event(state: &AppState, topic: &str, key: &str, subject: &str, detail: &str) {
86 if !state.live().alerts.kind_enabled(kind_of(topic)) {
87 return;
88 }
89 match state
90 .store
91 .record_alert_event(key, topic, subject, detail)
92 .await
93 {
94 Ok(true) => deliver(state, key, topic, subject, detail, false).await,
95 Ok(false) => {}
96 Err(e) => tracing::error!(error = %e, key, "alerts: recording an event failed"),
97 }
98}
99
100/// Writes the inbox rows and queues the emails for one message to every site admin.
101async fn deliver(
102 state: &AppState,
103 key: &str,
104 topic: &str,
105 subject: &str,
106 detail: &str,
107 resolved: bool,
108) {
109 // The alert was written (raised, resolved or recorded): the health page follows it.
110 crate::live::admin().bump(&crate::live::Topic::AdminHealth);
111 let admins = match state.store.list_admins().await {
112 Ok(admins) => admins,
113 Err(e) => {
114 tracing::error!(error = %e, "alerts: listing the admins failed");
115 return;
116 }
117 };
118 let live = state.live();
119 let base = live.base_url.trim_end_matches('/').to_owned();
120 let state_word = if resolved { "resolved" } else { "raised" };
121 for admin in admins.into_iter().filter(|u| !u.is_org()) {
122 if let Err(e) = state
123 .store
124 .add_admin_notice(&admin.id, key, topic, subject, detail, resolved)
125 .await
126 {
127 tracing::error!(error = %e, key, "alerts: writing an inbox row failed");
128 continue;
129 }
130 publish_unread(state, &admin.id).await;
131 crate::web_push::queue(
132 state,
133 &admin.id,
134 crate::web_push::Alert::Admin {
135 subject: subject.to_owned(),
136 detail: detail.to_owned(),
137 },
138 );
139 if !live.alerts.email {
140 continue;
141 }
142 let Some(address) = admin.email.as_deref().filter(|a| !a.is_empty()) else {
143 continue;
144 };
145 match state.store.email_is_verified(&admin.id).await {
146 Ok(true) => {}
147 Ok(false) => continue,
148 Err(e) => {
149 tracing::error!(error = %e, "alerts: checking the admin's address failed");
150 continue;
151 }
152 }
153 let lang = i18n::resolve(Some(admin.language.as_str()), &http::HeaderMap::new());
154 let title = text::title(lang, topic, subject, resolved);
155 let body = text::mail_body(
156 lang,
157 &text::body(lang, topic, subject, detail, resolved),
158 &format!("{base}/admin/health"),
159 &format!("{base}/admin/server?tab=alerts"),
160 );
161 let outgoing = OutgoingMail {
162 to: address.to_owned(),
163 subject: text::mail_subject(lang, &title),
164 body,
165 message_id: None,
166 in_reply_to: None,
167 kind: MailKind::Notification,
168 user_id: Some(admin.id.clone()),
169 };
170 let idem = format!(
171 "alert:{key}:{state_word}:{}:{}",
172 forge_core::time::now_stamp(),
173 admin.id
174 );
175 if let Err(e) = mail::enqueue_message(state, &idem, &outgoing).await {
176 tracing::error!(error = %e, key, "alerts: queueing the email failed");
177 }
178 }
179}
180
181// ---- events seen where they happen ----
182
183/// A runner authenticated, so it is online. Resolves its offline alert if it had one.
184pub async fn runner_seen(state: &AppState, runner_id: &str) {
185 if !OFFLINE_ACTIVE.load(Ordering::Relaxed) {
186 return;
187 }
188 resolve(state, &format!("runner_offline:{runner_id}")).await;
189 match state.store.active_alert_keys("runner_offline").await {
190 Ok(keys) if keys.is_empty() => OFFLINE_ACTIVE.store(false, Ordering::Relaxed),
191 Ok(_) => {}
192 Err(e) => tracing::error!(error = %e, "alerts: reading the active alerts failed"),
193 }
194}
195
196/// A job ended `Failure` or `Error`. Tells the admins once per run when it looks like the job was
197/// killed, naming the runner. `oom_killed` is the runner's report that the OOM killer took a
198/// process in the job's cgroup.
199pub async fn job_ended(
200 state: &AppState,
201 job: &forge_core::ci::CiJob,
202 exit_code: Option<i64>,
203 message: Option<&str>,
204 oom_killed: bool,
205) {
206 // The runner's own reading of the job cgroup comes first: a killed rustc leaves cargo to exit
207 // 101 with the signal only in the log. The exit code and message are the fallback.
208 if !oom_killed && !alerts::is_kill_signature(exit_code, message) {
209 return;
210 }
211 let runner = match &job.runner_id {
212 Some(id) => state
213 .store
214 .list_runners()
215 .await
216 .ok()
217 .and_then(|runners| runners.into_iter().find(|r| &r.id == id))
218 .map_or_else(|| id.clone(), |r| r.name),
219 None => "unknown".to_owned(),
220 };
221 let detail = format!("job {} of run {}", job.name, job.run_id);
222 event(
223 state,
224 "ci_killed",
225 &format!("ci_killed:{}", job.run_id),
226 &runner,
227 &detail,
228 )
229 .await;
230}
231
232/// The outcome of a scheduled or manual backup. A good one resolves the backup alerts.
233pub async fn backup_finished(state: &AppState, outcome: Result<(), &str>) {
234 match outcome {
235 Ok(()) => {
236 resolve(state, "backup_failed").await;
237 resolve(state, "backup_verify_failed").await;
238 resolve(state, "backup_overdue").await;
239 }
240 Err(error) => {
241 let topic = if error.contains("failed verification") {
242 "backup_verify_failed"
243 } else {
244 "backup_failed"
245 };
246 raise(state, topic, topic, "", error).await;
247 }
248 }
249}
250
251/// The outcome of an integrity check.
252pub async fn fsck_finished(state: &AppState, outcome: Result<(), &str>) {
253 match outcome {
254 Ok(()) => resolve(state, "fsck_failed").await,
255 Err(error) => raise(state, "fsck_failed", "fsck_failed", "", error).await,
256 }
257}
258
259/// A self-update installed a new binary and asked for a restart.
260pub async fn self_update_deployed(state: &AppState, version: &str) {
261 raise(
262 state,
263 "self_update_restart",
264 "self_update_restart",
265 version,
266 "",
267 )
268 .await;
269}
270
271/// A self-update failed. One message per run.
272pub async fn self_update_failed(state: &AppState, run_id: &str, error: &str) {
273 event(
274 state,
275 "self_update_failed",
276 &format!("self_update_failed:{run_id}"),
277 "",
278 error,
279 )
280 .await;
281}
282
283/// Called once at boot. A self-update that asked for a restart is over when the server is up.
284pub async fn on_boot(state: &AppState) {
285 started();
286 match state.store.active_alert_keys("runner_offline").await {
287 Ok(keys) => OFFLINE_ACTIVE.store(!keys.is_empty(), Ordering::Relaxed),
288 Err(e) => tracing::error!(error = %e, "alerts: reading the active alerts failed"),
289 }
290 if let Ok(Some(alert)) = state.store.resolve_alert("self_update_restart").await
291 && state.live().alerts.kind_enabled(AlertKind::SelfUpdate)
292 {
293 {
294 let version = crate::self_update::running()
295 .map(|r| r.sha256.chars().take(12).collect::<String>())
296 .unwrap_or(alert.subject.clone());
297 deliver(
298 state,
299 "self_update_restart",
300 "self_update_restart",
301 &version,
302 "",
303 true,
304 )
305 .await;
306 }
307 }
308}
309
310// ---- conditions nothing reports: looked at on existing ticks ----
311
312/// Raises an alert for each runner silent for longer than the configured minutes and resolves the
313/// ones that are not any more. Runs on every CI reaper pass: one query.
314pub async fn check_runners(state: &AppState) {
315 check_runners_at(state, now_unix()).await;
316}
317
318/// [`check_runners`] with an explicit clock.
319pub async fn check_runners_at(state: &AppState, now: i64) {
320 let live = state.live();
321 let cfg = &live.alerts;
322 let runners = match state.store.list_runners().await {
323 Ok(runners) => runners,
324 Err(e) => {
325 tracing::error!(error = %e, "alerts: listing the runners failed");
326 return;
327 }
328 };
329 let mut offline = std::collections::BTreeSet::new();
330 // The runners page dot flips on its own window, so a runner that goes quiet changes the page
331 // here, not on its next report. Only a change wakes the page.
332 for runner in &runners {
333 let online = forge_core::store::health::runner_is_online(
334 runner.disabled,
335 runner.last_seen_at.as_deref(),
336 now,
337 );
338 state.ci_live.note_runner_online(&runner.id, online);
339 }
340 let ids: Vec<&str> = runners.iter().map(|r| r.id.as_str()).collect();
341 state.ci_live.forget_runners_except(&ids);
342 for runner in &runners {
343 let seen = runner.last_seen_at.as_deref().and_then(stamp_to_unix);
344 if runner.disabled || !alerts::runner_is_offline(now, seen, cfg.runner_offline_minutes) {
345 continue;
346 }
347 let key = format!("runner_offline:{}", runner.id);
348 offline.insert(key.clone());
349 let since = seen.map_or_else(String::new, |t| forge_core::tz::format_in_tz(t, "UTC"));
350 raise(state, "runner_offline", &key, &runner.name, &since).await;
351 }
352 // Whatever is active but no longer offline (back, disabled or deleted) is resolved.
353 match state.store.active_alert_keys("runner_offline").await {
354 Ok(active) => {
355 for key in active.into_iter().filter(|k| !offline.contains(k)) {
356 resolve(state, &key).await;
357 }
358 }
359 Err(e) => tracing::error!(error = %e, "alerts: reading the active alerts failed"),
360 }
361}
362
363/// The checks that need a look at the disk or the history: free space, an overdue backup and the
364/// standby. Meant to run every few minutes.
365pub async fn check_slow(state: &AppState) {
366 check_disk(state).await;
367 check_backup_overdue(state, now_unix()).await;
368 check_replication(state, now_unix()).await;
369 // A copy goes lagging by the clock alone, so the replication page is woken on this tick. Its
370 // fingerprint drops the wake when no row changed.
371 crate::live::admin().bump(&crate::live::Topic::AdminReplication);
372 let old = forge_core::time::stamp_ago(std::time::Duration::from_secs(90 * 86_400));
373 if let Err(e) = state.store.prune_admin_alerts(&old).await {
374 tracing::error!(error = %e, "alerts: pruning failed");
375 }
376}
377
378/// Free and total bytes of the filesystem holding `path`.
379pub fn disk_space(path: &std::path::Path) -> Option<(u64, u64)> {
380 let stat = nix::sys::statvfs::statvfs(path).ok()?;
381 let block = stat.fragment_size();
382 let total = stat.blocks().saturating_mul(block);
383 let avail = stat.blocks_available().saturating_mul(block);
384 Some((total, avail))
385}
386
387async fn check_disk(state: &AppState) {
388 let live = state.live();
389 let cfg = &live.alerts;
390 if !cfg.kind_enabled(AlertKind::Disk) {
391 return;
392 }
393 let dir = live.data_dir.clone();
394 let space = tokio::task::spawn_blocking({
395 let dir = dir.clone();
396 move || disk_space(&dir)
397 })
398 .await
399 .ok()
400 .flatten();
401 let Some((total, avail)) = space else {
402 return;
403 };
404 if alerts::disk_is_low(total, avail, cfg.disk_free_percent, cfg.disk_free_gib) {
405 let percent = alerts::free_percent(total, avail).unwrap_or(0);
406 let detail = format!(
407 "{percent}% free ({} of {})",
408 crate::views::human_size(i18n::Lang::En, avail),
409 crate::views::human_size(i18n::Lang::En, total)
410 );
411 raise(
412 state,
413 "disk_low",
414 "disk_low",
415 &dir.to_string_lossy(),
416 &detail,
417 )
418 .await;
419 } else {
420 resolve(state, "disk_low").await;
421 }
422}
423
424async fn check_backup_overdue(state: &AppState, now: i64) {
425 let live = state.live();
426 if !live.backup.enabled() || !live.alerts.kind_enabled(AlertKind::Backup) {
427 return;
428 }
429 let last_ok = match state.store.last_ok(RunKind::Backup).await {
430 Ok(run) => run.and_then(|r| r.finished_at.or(Some(r.started_at))),
431 Err(e) => {
432 tracing::error!(error = %e, "alerts: reading the backup history failed");
433 return;
434 }
435 };
436 let last_ok_unix = last_ok.as_deref().and_then(stamp_to_unix);
437 if alerts::backup_overdue(now, last_ok_unix, started(), live.backup.interval_hours) {
438 let detail = last_ok_unix.map_or_else(
439 || "never".to_owned(),
440 |t| forge_core::tz::format_in_tz(t, "UTC"),
441 );
442 raise(state, "backup_overdue", "backup_overdue", "", &detail).await;
443 } else {
444 resolve(state, "backup_overdue").await;
445 }
446}
447
448async fn check_replication(state: &AppState, now: i64) {
449 let live = state.live();
450 if !live.replication.enabled() || !live.alerts.kind_enabled(AlertKind::Replication) {
451 return;
452 }
453 let rows = match state.store.list_replication_status().await {
454 Ok(rows) => rows,
455 Err(e) => {
456 tracing::error!(error = %e, "alerts: reading the replication status failed");
457 return;
458 }
459 };
460 let window =
461 i64::try_from(live.replication.db_snapshot_minutes.saturating_mul(120)).unwrap_or(i64::MAX);
462 let mut problem: Option<String> = None;
463 for row in &rows {
464 if let Some(error) = &row.last_error {
465 problem = Some(format!("{}: {error}.", row.subject));
466 break;
467 }
468 if row.subject == forge_core::store::replication::DB_SUBJECT {
469 let ok = row.last_ok_at.as_deref().and_then(stamp_to_unix);
470 if ok.is_none_or(|t| now.saturating_sub(t) > window) {
471 problem = Some("The database snapshot has not reached the standby in time.".into());
472 break;
473 }
474 }
475 }
476 match problem {
477 Some(detail) => raise(state, "replication", "replication", "", &detail).await,
478 None => resolve(state, "replication").await,
479 }
480}
481
482#[cfg(test)]
483mod tests {
484 use super::*;
485 use crate::test_support::test_state;
486 use forge_core::mail::MailState;
487
488 async fn admin(state: &AppState, name: &str, verified: bool) -> String {
489 let address = format!("{name}@test.example");
490 let user = state
491 .store
492 .create_user(name, Some(&address), "hash", true)
493 .await
494 .unwrap();
495 if verified {
496 let token = state
497 .store
498 .create_verify_token(&user.id, &address)
499 .await
500 .unwrap();
501 state.store.redeem_verify_token(&token).await.unwrap();
502 }
503 user.id
504 }
505
506 async fn inbox(
507 state: &AppState,
508 user_id: &str,
509 ) -> Vec<forge_core::store::admin_alerts::AdminNotice> {
510 state
511 .store
512 .list_admin_notices(user_id, false, None, 50)
513 .await
514 .unwrap()
515 }
516
517 async fn queued_mail(state: &AppState) -> usize {
518 state
519 .store
520 .mail_state_counts(&forge_core::time::now_stamp())
521 .await
522 .unwrap()
523 .into_iter()
524 .filter(|(s, _)| matches!(s, MailState::Queued | MailState::Retrying))
525 .map(|(_, n)| n as usize)
526 .sum()
527 }
528
529 #[tokio::test]
530 async fn an_alert_reaches_every_admin_once_and_resolves_once() {
531 let dir = tempfile::tempdir().unwrap();
532 let state = test_state(dir.path()).await;
533 let tahinli = admin(&state, "tahinli", true).await;
534 let second = admin(&state, "tahinli2", false).await;
535
536 raise(&state, "disk_low", "disk_low", "/data", "4% free").await;
537 raise(&state, "disk_low", "disk_low", "/data", "3% free").await;
538 assert_eq!(inbox(&state, &tahinli).await.len(), 1, "deduplicated");
539 assert_eq!(inbox(&state, &second).await.len(), 1);
540 assert_eq!(state.store.active_alerts().await.unwrap().len(), 1);
541 assert_eq!(
542 queued_mail(&state).await,
543 1,
544 "only the verified admin is mailed"
545 );
546
547 resolve(&state, "disk_low").await;
548 resolve(&state, "disk_low").await;
549 let rows = inbox(&state, &tahinli).await;
550 assert_eq!(rows.len(), 2, "raised and resolved, once each");
551 assert!(rows.iter().any(|r| r.resolved));
552 assert!(state.store.active_alerts().await.unwrap().is_empty());
553 assert_eq!(queued_mail(&state).await, 2);
554 assert_eq!(state.store.unread_count(&tahinli).await.unwrap(), 2);
555
556 raise(&state, "disk_low", "disk_low", "/data", "2% free").await;
557 assert_eq!(
558 inbox(&state, &tahinli).await.len(),
559 3,
560 "a new episode is told again"
561 );
562 }
563
564 #[tokio::test]
565 async fn switches_stop_raising_and_email_off_sends_no_mail() {
566 let dir = tempfile::tempdir().unwrap();
567 let mut state = test_state(dir.path()).await;
568 let tahinli = admin(&state, "tahinli", true).await;
569 let mut config = (*state.config).clone();
570 config.alerts.on_disk = false;
571 state.set_config(config.clone());
572 raise(&state, "disk_low", "disk_low", "/data", "4% free").await;
573 assert!(inbox(&state, &tahinli).await.is_empty());
574
575 config.alerts.on_disk = true;
576 config.alerts.email = false;
577 state.set_config(config.clone());
578 raise(&state, "disk_low", "disk_low", "/data", "4% free").await;
579 assert_eq!(inbox(&state, &tahinli).await.len(), 1);
580 assert_eq!(queued_mail(&state).await, 0);
581
582 config.alerts.enabled = false;
583 state.set_config(config);
584 raise(&state, "backup_failed", "backup_failed", "", "boom").await;
585 assert_eq!(
586 inbox(&state, &tahinli).await.len(),
587 1,
588 "the master switch wins"
589 );
590 }
591
592 #[tokio::test]
593 async fn a_silent_runner_is_flagged_and_clears_when_it_checks_in() {
594 let dir = tempfile::tempdir().unwrap();
595 let state = test_state(dir.path()).await;
596 let tahinli = admin(&state, "tahinli", false).await;
597 let token = state
598 .store
599 .create_registration_token(&tahinli, 1)
600 .await
601 .unwrap();
602 let (runner, secret) = state
603 .store
604 .register_runner(&token, "tahinli-ci", &["linux".to_owned()])
605 .await
606 .unwrap();
607 // The runner has just been seen: the clock is real for the first check.
608 state.store.runner_by_secret(&secret).await.unwrap();
609
610 let now = now_unix();
611 check_runners_at(&state, now).await;
612 assert!(inbox(&state, &tahinli).await.is_empty(), "fresh heartbeat");
613
614 // Eleven minutes of silence on a fake clock (the default is ten).
615 check_runners_at(&state, now + 11 * 60).await;
616 check_runners_at(&state, now + 12 * 60).await;
617 let rows = inbox(&state, &tahinli).await;
618 assert_eq!(rows.len(), 1, "told once");
619 assert_eq!(rows[0].subject, "tahinli-ci");
620 assert_eq!(state.store.active_alerts().await.unwrap().len(), 1);
621
622 // It checks in again: the heartbeat hook resolves it.
623 runner_seen(&state, &runner.id).await;
624 let rows = inbox(&state, &tahinli).await;
625 assert_eq!(rows.len(), 2);
626 assert!(rows[0].resolved);
627 assert!(state.store.active_alerts().await.unwrap().is_empty());
628 }
629
630 #[tokio::test]
631 async fn a_killed_job_is_told_once_per_run() {
632 let dir = tempfile::tempdir().unwrap();
633 let state = test_state(dir.path()).await;
634 let tahinli = admin(&state, "tahinli", false).await;
635 let mut job = forge_core::ci::CiJob {
636 id: "job-1".into(),
637 run_id: "run-1".into(),
638 name: "build".into(),
639 spec_json: "{}".into(),
640 state: forge_core::ci::JobState::Running,
641 runner_id: None,
642 exit_code: None,
643 message: None,
644 queued_at: None,
645 started_at: None,
646 finished_at: None,
647 heartbeat_at: None,
648 cancel_requested: false,
649 log_bytes: 0,
650 oom_kills: None,
651 };
652 job_ended(&state, &job, Some(137), None, false).await;
653 job.name = "second".into();
654 job_ended(&state, &job, None, Some("signal: 9"), false).await;
655 job_ended(&state, &job, Some(1), None, false).await;
656 assert_eq!(inbox(&state, &tahinli).await.len(), 1);
657 job.run_id = "run-2".into();
658 job_ended(&state, &job, Some(137), None, false).await;
659 assert_eq!(inbox(&state, &tahinli).await.len(), 2);
660 }
661
662 #[tokio::test]
663 async fn an_oom_kill_the_job_survived_still_raises_the_alert() {
664 let dir = tempfile::tempdir().unwrap();
665 let state = test_state(dir.path()).await;
666 let tahinli = admin(&state, "tahinli", false).await;
667 let job = forge_core::ci::CiJob {
668 id: "job-1".into(),
669 run_id: "run-1".into(),
670 name: "build".into(),
671 spec_json: "{}".into(),
672 state: forge_core::ci::JobState::Failure,
673 runner_id: None,
674 exit_code: Some(101),
675 message: None,
676 queued_at: None,
677 started_at: None,
678 finished_at: None,
679 heartbeat_at: None,
680 cancel_requested: false,
681 log_bytes: 0,
682 oom_kills: None,
683 };
684 // cargo exits 101 when rustc is killed, so the exit code and message show nothing.
685 job_ended(&state, &job, Some(101), None, false).await;
686 assert_eq!(inbox(&state, &tahinli).await.len(), 0);
687 job_ended(&state, &job, Some(101), None, true).await;
688 assert_eq!(inbox(&state, &tahinli).await.len(), 1);
689 }
690}