1use vitrify_core::model::UtcTime;
5
6use super::snapshot::{GateView, LaneView, RunState, Snapshot, WorkerView};
7use crate::out::J;
8
9pub fn human(s: &Snapshot) -> Vec<String> {
11 let since = |t: &str| UtcTime::parse(t).map(|t| s.at.0 - t.0).unwrap_or(0);
12 let mut out = Vec::new();
13
14 let state = match (&s.state, &s.terminated) {
15 (RunState::Ended, Some(t)) => {
16 let ran = UtcTime::parse(&t.at)
17 .zip(UtcTime::parse(&s.started_at))
18 .map(|(end, start)| end.0 - start.0)
19 .unwrap_or(0);
20 let detail = if t.detail.is_empty() {
21 String::new()
22 } else {
23 format!(" ({})", t.detail)
24 };
25 format!("ended: {}{detail} · ran {}", t.state, duration(ran))
26 }
27 (RunState::Died, _) => format!("died · started {} ago", duration(since(&s.started_at))),
28 _ => format!("alive · {} elapsed", duration(since(&s.started_at))),
29 };
30 let mut header = format!("{} · {state} · {}", s.job_id, s.sdd);
31 if !s.harness.is_empty() {
32 header.push_str(&format!(" · {}", s.harness));
33 }
34 out.push(header);
35 if s.lanes.len() > 1 {
36 out.push(String::new());
37 out.extend(lane_table(&s.lanes));
38 } else {
39 out.push(match &s.progress {
40 Some(p) => p.clone(),
41 None => format!(
42 "Progress: ? ({} could not be read in the primary checkout)",
43 s.sdd
44 ),
45 });
46 }
47
48 out.push(String::new());
49 let active: Vec<(usize, &WorkerView)> = s
50 .workers
51 .iter()
52 .enumerate()
53 .filter(|(_, w)| w.outcome == "running" || w.outcome == "integrating")
54 .collect();
55 if active.is_empty() {
56 out.push("No unit in progress.".to_string());
57 } else {
58 let mut rows = vec![
59 ["UNIT", "TRY", "STAGE", "TIME", "OUTPUT", "WORK"]
60 .map(str::to_string)
61 .to_vec(),
62 ];
63 let budget = duration(s.params.worker_timeout_minutes * 60);
64 for (i, w) in active {
65 let running = w.outcome == "running";
66 let mut time = duration(since(&w.started_at));
67 if running {
68 time.push('/');
69 time.push_str(&budget);
70 }
71 let output = match (running, w.log_quiet_s, w.log_bytes) {
72 (true, Some(q), Some(b)) => format!("{} ago {}", duration(q), size(b)),
73 _ => String::new(),
74 };
75 let mut work_text = match w.stage.as_str() {
76 "reading" | "editing" | "stamped" => {
77 let mut t = work(
78 w.files_changed.unwrap_or(0),
79 w.insertions.unwrap_or(0),
80 w.deletions.unwrap_or(0),
81 );
82 let carried = w.carried_over.unwrap_or(0);
83 if carried > 0 {
84 t.push_str(&format!(" ({carried} carried over)"));
85 }
86 t
87 }
88 "unknown" => format!("? {}", w.error.as_deref().unwrap_or_default()),
89 "exited" => "process ended".to_string(),
90 "queued" => "waiting for the gate".to_string(),
91 "gate" => s
92 .gate
93 .as_ref()
94 .map(|g| gate_text(g, s.at))
95 .unwrap_or_default(),
96 "integrating" => "reported built".to_string(),
97 _ => String::new(),
98 };
99 if w.retry {
100 match s.workers[..i].iter().rev().find(|p| p.unit == w.unit) {
101 Some(p) => {
102 work_text.push_str(&format!(" (retry: c{} {})", p.claim_seq, p.outcome))
103 }
104 None => work_text.push_str(" (retry)"),
105 }
106 }
107 let stage = if w.stage == "unknown" { "?" } else { &w.stage };
108 rows.push(vec![
109 w.unit.clone(),
110 format!("c{}", w.claim_seq),
111 stage.to_string(),
112 time,
113 output,
114 work_text,
115 ]);
116 }
117 out.extend(table(&rows));
118 }
119
120 if let Some(g) = &s.gate
121 && s.state == RunState::Alive
122 && g.step != "idle"
123 && !s.workers.iter().any(|w| w.stage == "gate")
124 {
125 out.push(format!("Gate: {}", gate_text(g, s.at)));
126 }
127
128 if !s.warnings.is_empty() {
129 out.push(String::new());
130 out.extend(s.warnings.iter().map(|w| format!("! {w}")));
131 }
132
133 let finished: Vec<&WorkerView> = s
134 .workers
135 .iter()
136 .filter(|w| w.outcome != "running" && w.outcome != "integrating")
137 .collect();
138 if !finished.is_empty() {
139 out.push(String::new());
140 out.push("Finished".to_string());
141 let skipped = finished.len().saturating_sub(MAX_FINISHED);
142 if skipped > 0 {
143 out.push(format!(
144 "… {skipped} earlier attempts — --json lists them all"
145 ));
146 }
147 let rows: Vec<Vec<String>> = finished[skipped..]
148 .iter()
149 .map(|w| {
150 let took = w
151 .ended()
152 .zip(w.started())
153 .map(|(end, start)| duration(end.0 - start.0))
154 .unwrap_or_default();
155 vec![
156 w.unit.clone(),
157 format!("c{}", w.claim_seq),
158 w.outcome.clone(),
159 took,
160 w.detail.clone().unwrap_or_default(),
161 ]
162 })
163 .collect();
164 out.extend(table(&rows));
165 }
166
167 if let Some(report) = &s.report {
168 out.push(String::new());
169 out.push("Report:".to_string());
170 out.extend(report.iter().cloned());
171 }
172
173 out.push(String::new());
174 out.push(format!("Logs: {}", s.logs));
175 out
176}
177
178fn lane_progress(l: &LaneView) -> String {
181 let (Some(verified), Some(total), Some(waiting)) = (l.verified, l.total, l.waiting) else {
182 return "?".to_string();
183 };
184 let mut parts = vec![format!("{verified}/{total} Verified")];
185 if l.in_flight > 0 {
186 parts.push(format!("{} in flight", l.in_flight));
187 }
188 if waiting > 0 {
189 parts.push(format!("{waiting} waiting"));
190 }
191 parts.join(" · ")
192}
193
194const MAX_WAITS_ON: usize = 3;
197
198fn lane_table(lanes: &[LaneView]) -> Vec<String> {
201 let mut rows = vec![
202 ["LANE", "STATE", "PROGRESS", "WAITS ON"]
203 .map(str::to_string)
204 .to_vec(),
205 ];
206 for l in lanes {
207 let mut waits = l
208 .waits_on
209 .iter()
210 .take(MAX_WAITS_ON)
211 .cloned()
212 .collect::<Vec<_>>()
213 .join(", ");
214 if l.waits_on.len() > MAX_WAITS_ON {
215 waits.push_str(&format!(" +{} more", l.waits_on.len() - MAX_WAITS_ON));
216 }
217 rows.push(vec![
218 l.slug.clone(),
219 l.state.clone(),
220 lane_progress(l),
221 waits,
222 ]);
223 }
224 table(&rows)
225}
226
227const MAX_FINISHED: usize = 20;
230
231fn table(rows: &[Vec<String>]) -> Vec<String> {
234 let cols = rows.iter().map(Vec::len).max().unwrap_or(0);
235 let widths: Vec<usize> = (0..cols)
236 .map(|c| {
237 rows.iter()
238 .filter_map(|r| r.get(c))
239 .map(|cell| cell.chars().count())
240 .max()
241 .unwrap_or(0)
242 })
243 .collect();
244 rows.iter()
245 .map(|r| {
246 let mut line = String::new();
247 for (c, cell) in r.iter().enumerate() {
248 if c > 0 {
249 line.push_str(" ");
250 }
251 line.push_str(cell);
252 let pad = widths[c] - cell.chars().count();
253 line.extend(std::iter::repeat_n(' ', pad));
254 }
255 line.trim_end().to_string()
256 })
257 .collect()
258}
259
260pub fn gate_text(g: &GateView, now: UtcTime) -> String {
263 let lead = match g.step.as_str() {
264 "lock" => return "waiting for the integration checkout".to_string(),
265 "sync" => return "syncing with mainline".to_string(),
266 "merge" => return "merging".to_string(),
267 "publish" => return "stamping and publishing".to_string(),
268 "test-base" => "measuring the Test command before the merge".to_string(),
269 "rows" => match (g.done, g.total) {
270 (Some(done), Some(total)) => format!("rows {done}/{total}"),
271 _ => "rows".to_string(),
272 },
273 "head-check" => "checking the mainline head".to_string(),
274 other => other.to_string(),
275 };
276 let Some((cmd, since)) = g.running.first() else {
277 return lead;
278 };
279 let mut text = format!("{lead} · {}", clip(cmd, 60));
280 if let Some(since) = since {
281 text.push_str(&format!(" ({})", duration(now.0 - since.0)));
282 }
283 if g.running.len() > 1 {
284 text.push_str(&format!(" +{} more", g.running.len() - 1));
285 }
286 text
287}
288
289pub fn clip(s: &str, max: usize) -> String {
292 if s.chars().count() <= max {
293 return s.to_string();
294 }
295 let mut out: String = s.chars().take(max.saturating_sub(1)).collect();
296 out.push('…');
297 out
298}
299
300pub fn json(s: &Snapshot) -> J {
302 let opt_int = |v: Option<i64>| v.map_or(J::Null, J::Int);
303 let opt_u64 = |v: Option<u64>| v.map_or(J::Null, |n| J::Int(n as i64));
304 let opt_bool = |v: Option<bool>| v.map_or(J::Null, J::Bool);
305 let workers = s
306 .workers
307 .iter()
308 .map(|w| {
309 J::Obj(vec![
310 ("unit".into(), J::s(w.unit.clone())),
311 ("claim_seq".into(), J::Int(w.claim_seq)),
312 ("holder".into(), J::s(w.holder.clone())),
313 ("pid".into(), J::Int(w.pid as i64)),
314 ("retry".into(), J::Bool(w.retry)),
315 ("worktree".into(), J::s(w.worktree.clone())),
316 ("started_at".into(), J::s(w.started_at.clone())),
317 ("ended_at".into(), J::opt_str(w.ended_at.clone())),
318 ("outcome".into(), J::s(w.outcome.clone())),
319 ("stage".into(), J::s(w.stage.clone())),
320 ("alive".into(), opt_bool(w.alive)),
321 ("log_bytes".into(), opt_u64(w.log_bytes)),
322 ("log_quiet_s".into(), opt_int(w.log_quiet_s)),
323 ("files_changed".into(), opt_u64(w.files_changed)),
324 ("insertions".into(), opt_u64(w.insertions)),
325 ("deletions".into(), opt_u64(w.deletions)),
326 ("carried_over".into(), opt_u64(w.carried_over)),
327 ("stamped".into(), opt_bool(w.stamped)),
328 ("detail".into(), J::opt_str(w.detail.clone())),
329 ("error".into(), J::opt_str(w.error.clone())),
330 ])
331 })
332 .collect();
333 let terminated = s.terminated.as_ref().map_or(J::Null, |t| {
334 J::Obj(vec![
335 ("state".into(), J::s(t.state.clone())),
336 ("at".into(), J::s(t.at.clone())),
337 ("detail".into(), J::s(t.detail.clone())),
338 ])
339 });
340 let lanes = s.lanes.iter().map(lane_json).collect();
341 J::Obj(vec![
342 ("job_id".into(), J::s(s.job_id.clone())),
343 ("pid".into(), J::Int(s.pid as i64)),
344 ("sdd".into(), J::s(s.sdd.clone())),
345 ("harness".into(), J::s(s.harness.clone())),
346 ("started_at".into(), J::s(s.started_at.clone())),
347 ("at".into(), J::s(s.at.format())),
348 ("state".into(), J::s(s.state.as_str())),
349 ("terminated".into(), terminated),
350 (
351 "report".into(),
352 s.report.as_ref().map_or(J::Null, |lines| {
353 J::Arr(lines.iter().map(|l| J::s(l.clone())).collect())
354 }),
355 ),
356 ("progress".into(), J::opt_str(s.progress.clone())),
357 (
358 "params".into(),
359 J::Obj(vec![
360 ("cap".into(), J::Int(s.params.cap)),
361 ("gate_jobs".into(), J::Int(s.params.gate_jobs)),
362 ("lease_minutes".into(), J::Int(s.params.lease_minutes)),
363 (
364 "worker_timeout_minutes".into(),
365 J::Int(s.params.worker_timeout_minutes),
366 ),
367 ]),
368 ),
369 ("workers".into(), J::Arr(workers)),
370 ("gate".into(), s.gate.as_ref().map_or(J::Null, gate_json)),
371 (
372 "warnings".into(),
373 J::Arr(s.warnings.iter().map(|w| J::s(w.clone())).collect()),
374 ),
375 ("logs".into(), J::s(s.logs.clone())),
376 ("lanes".into(), J::Arr(lanes)),
377 ])
378}
379
380fn lane_json(l: &LaneView) -> J {
382 let opt = |v: Option<u64>| v.map_or(J::Null, |n| J::Int(n as i64));
383 J::Obj(vec![
384 ("slug".into(), J::s(l.slug.clone())),
385 ("root".into(), J::s(l.root.clone())),
386 ("state".into(), J::s(l.state.clone())),
387 ("verified".into(), opt(l.verified)),
388 ("total".into(), opt(l.total)),
389 ("in_flight".into(), J::Int(l.in_flight as i64)),
390 ("waiting".into(), opt(l.waiting)),
391 (
392 "waits_on".into(),
393 J::Arr(l.waits_on.iter().map(|w| J::s(w.clone())).collect()),
394 ),
395 ])
396}
397
398pub fn gate_json(g: &GateView) -> J {
401 let time = |t: &Option<UtcTime>| t.map_or(J::Null, |t| J::s(t.format()));
402 J::Obj(vec![
403 ("step".into(), J::s(g.step.clone())),
404 ("since".into(), time(&g.since)),
405 (
406 "batch".into(),
407 J::Arr(g.batch.iter().map(|u| J::s(u.clone())).collect()),
408 ),
409 (
410 "running".into(),
411 J::Arr(
412 g.running
413 .iter()
414 .map(|(cmd, since)| {
415 J::Obj(vec![
416 ("command".into(), J::s(cmd.clone())),
417 ("since".into(), time(since)),
418 ])
419 })
420 .collect(),
421 ),
422 ),
423 ("done".into(), g.done.map_or(J::Null, J::Int)),
424 ("total".into(), g.total.map_or(J::Null, J::Int)),
425 ])
426}
427
428pub fn duration(secs: i64) -> String {
431 let secs = secs.max(0);
432 if secs < 60 {
433 format!("{secs}s")
434 } else if secs < 3600 {
435 format!("{}m", secs / 60)
436 } else {
437 format!("{}h{:02}m", secs / 3600, (secs % 3600) / 60)
438 }
439}
440
441pub fn size(bytes: u64) -> String {
443 if bytes < 1024 {
444 format!("{bytes} B")
445 } else if bytes < 1024 * 1024 {
446 format!("{} KB", (bytes + 512) / 1024)
447 } else {
448 format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0))
449 }
450}
451
452pub fn hhmmss(t: UtcTime) -> String {
454 t.format()[11..19].to_string()
455}
456
457pub fn work(files: u64, insertions: u64, deletions: u64) -> String {
459 match files {
460 0 => "no changes".to_string(),
461 1 => format!("1 file +{insertions} -{deletions}"),
462 n => format!("{n} files +{insertions} -{deletions}"),
463 }
464}
465
466pub fn died_line(pid: u32) -> String {
468 format!(
469 "the run (pid {pid}) is gone and recorded no end — the next `vitrify run` releases its claims and keeps its workers' files"
470 )
471}
472
473pub fn kill_line(job: &str, pgid: u32, unit: &str) -> String {
476 format!(
477 "a worker of {job} (process group {pgid}, unit {unit}) is still running — stop it with: kill -9 -- -{pgid}"
478 )
479}
480
481#[cfg(test)]
482mod tests {
483 use super::*;
484
485 #[test]
486 fn durations() {
487 assert_eq!(duration(0), "0s");
488 assert_eq!(duration(42), "42s");
489 assert_eq!(duration(60), "1m");
490 assert_eq!(duration(12 * 60 + 59), "12m");
491 assert_eq!(duration(3600 + 5 * 60), "1h05m");
492 assert_eq!(duration(2 * 3600 + 5 * 60 + 30), "2h05m");
493 assert_eq!(duration(-5), "0s");
494 }
495
496 #[test]
497 fn sizes() {
498 assert_eq!(size(0), "0 B");
499 assert_eq!(size(512), "512 B");
500 assert_eq!(size(41 * 1024 + 100), "41 KB");
501 assert_eq!(size(1536), "2 KB");
502 assert_eq!(size(3 * 1024 * 1024 + 210 * 1024), "3.2 MB");
503 }
504
505 #[test]
506 fn clock_and_work() {
507 assert_eq!(
508 hhmmss(UtcTime::parse("2026-11-16T14:08:01Z").unwrap()),
509 "14:08:01"
510 );
511 assert_eq!(work(0, 0, 0), "no changes");
512 assert_eq!(work(1, 40, 0), "1 file +40 -0");
513 assert_eq!(work(7, 210, 14), "7 files +210 -14");
514 }
515}
516
517#[cfg(test)]
518mod view_tests {
519 use super::*;
520 use crate::cmd::run_status::snapshot::tests::worker;
521 use crate::cmd::run_status::snapshot::{Params, RunState, Terminated};
522
523 fn snap() -> Snapshot {
524 let mut w = worker("U-001", "running");
525 w.stage = "editing".to_string();
526 w.alive = Some(true);
527 w.log_bytes = Some(2048);
528 w.log_quiet_s = Some(4);
529 w.files_changed = Some(2);
530 w.insertions = Some(40);
531 w.deletions = Some(1);
532 w.carried_over = Some(0);
533 w.stamped = Some(false);
534 let mut done = worker("U-002", "verified");
535 done.stage = "verified".to_string();
536 done.ended_at = Some("2026-11-16T14:08:00Z".to_string());
537 Snapshot {
538 job_id: "run-x".to_string(),
539 pid: 77,
540 sdd: "specs/calc".to_string(),
541 harness: "claude".to_string(),
542 started_at: "2026-11-16T14:00:00Z".to_string(),
543 at: UtcTime::parse("2026-11-16T14:10:00Z").unwrap(),
544 state: RunState::Alive,
545 terminated: None,
546 report: None,
547 progress: Some("Progress: 1/2 Verified · 1 Claimed".to_string()),
548 params: Params {
549 cap: 2,
550 gate_jobs: 4,
551 lease_minutes: 60,
552 worker_timeout_minutes: 45,
553 },
554 workers: vec![w, done],
555 lanes: vec![LaneView {
556 slug: "calc".to_string(),
557 root: "specs/calc".to_string(),
558 state: "build".to_string(),
559 verified: Some(1),
560 total: Some(2),
561 in_flight: 1,
562 waiting: Some(0),
563 waits_on: Vec::new(),
564 }],
565 gate: Some(GateView {
566 step: "rows".to_string(),
567 since: UtcTime::parse("2026-11-16T14:09:00Z"),
568 batch: vec!["U-003".to_string()],
569 running: vec![(
570 "pytest tests/test_parse.py".to_string(),
571 UtcTime::parse("2026-11-16T14:09:18Z"),
572 )],
573 done: Some(3),
574 total: Some(7),
575 }),
576 warnings: vec!["U-001 c1: no output for 6m (since 14:04:00)".to_string()],
577 logs: ".vitrify/logs/run-x/".to_string(),
578 }
579 }
580
581 fn keys(j: &J) -> Vec<&str> {
582 match j {
583 J::Obj(pairs) => pairs.iter().map(|(k, _)| k.as_str()).collect(),
584 _ => Vec::new(),
585 }
586 }
587
588 fn field<'a>(j: &'a J, key: &str) -> &'a J {
589 match j {
590 J::Obj(pairs) => &pairs.iter().find(|(k, _)| k == key).unwrap().1,
591 _ => panic!("not an object"),
592 }
593 }
594
595 #[test]
596 fn json_field_order() {
597 let j = json(&snap());
598 assert_eq!(
599 keys(&j),
600 [
601 "job_id",
602 "pid",
603 "sdd",
604 "harness",
605 "started_at",
606 "at",
607 "state",
608 "terminated",
609 "report",
610 "progress",
611 "params",
612 "workers",
613 "gate",
614 "warnings",
615 "logs",
616 "lanes"
617 ]
618 );
619 let J::Arr(lanes) = field(&j, "lanes") else {
620 panic!("lanes is not an array")
621 };
622 assert_eq!(
623 keys(&lanes[0]),
624 [
625 "slug",
626 "root",
627 "state",
628 "verified",
629 "total",
630 "in_flight",
631 "waiting",
632 "waits_on"
633 ]
634 );
635 assert_eq!(
636 keys(field(&j, "params")),
637 [
638 "cap",
639 "gate_jobs",
640 "lease_minutes",
641 "worker_timeout_minutes"
642 ]
643 );
644 let J::Arr(workers) = field(&j, "workers") else {
645 panic!("workers is not an array")
646 };
647 assert_eq!(
648 keys(&workers[0]),
649 [
650 "unit",
651 "claim_seq",
652 "holder",
653 "pid",
654 "retry",
655 "worktree",
656 "started_at",
657 "ended_at",
658 "outcome",
659 "stage",
660 "alive",
661 "log_bytes",
662 "log_quiet_s",
663 "files_changed",
664 "insertions",
665 "deletions",
666 "carried_over",
667 "stamped",
668 "detail",
669 "error"
670 ]
671 );
672 assert_eq!(field(&workers[1], "alive"), &J::Null);
674 assert_eq!(field(&workers[1], "files_changed"), &J::Null);
675 let gate = field(&j, "gate");
676 assert_eq!(
677 keys(gate),
678 ["step", "since", "batch", "running", "done", "total"]
679 );
680 let J::Arr(running) = field(gate, "running") else {
681 panic!("running is not an array")
682 };
683 assert_eq!(keys(&running[0]), ["command", "since"]);
684 assert_eq!(field(&j, "state"), &J::s("alive"));
685 assert_eq!(field(&j, "at"), &J::s("2026-11-16T14:10:00Z"));
686 assert_eq!(field(&j, "report"), &J::Null);
687 }
688
689 #[test]
690 fn an_ended_run_shows_its_report() {
691 let mut s = snap();
692 s.state = RunState::Ended;
693 s.gate = None;
694 s.terminated = Some(Terminated {
695 state: "blocked".to_string(),
696 at: "2026-11-16T14:10:00Z".to_string(),
697 detail: "Progress: 1/2 Verified · 1 Ready".to_string(),
698 });
699 let report = vec![
700 "Blocked.".to_string(),
701 " Progress: 1/2 Verified · 1 Ready".to_string(),
702 " U-001: open Q-001: a spec gap".to_string(),
703 " journal tail:".to_string(),
704 ];
705 s.report = Some(report.clone());
706 let lines = human(&s);
707 let at = lines.iter().position(|l| l == "Report:").unwrap();
708 assert_eq!(lines[at + 1..at + 1 + report.len()], report[..]);
709 assert_eq!(lines.last().unwrap(), "Logs: .vitrify/logs/run-x/");
710 assert_eq!(
711 field(&json(&s), "report"),
712 &J::Arr(report.into_iter().map(J::s).collect())
713 );
714 }
715
716 fn lane(slug: &str, state: &str, counts: Option<(u64, u64)>, in_flight: u64) -> LaneView {
717 LaneView {
718 slug: slug.to_string(),
719 root: format!("specs/{slug}"),
720 state: state.to_string(),
721 verified: counts.map(|c| c.0),
722 total: counts.map(|c| c.1),
723 in_flight,
724 waiting: counts.map(|(v, t)| t - v - in_flight),
725 waits_on: Vec::new(),
726 }
727 }
728
729 #[test]
730 fn several_lanes_show_a_table_in_place_of_the_progress_line() {
731 let mut s = snap();
732 s.progress = None;
733 let mut web = lane("web", "idle", Some((0, 4)), 0);
734 web.waits_on = ["api U-007", "core U-002", "core U-003", "core U-004"]
735 .map(str::to_string)
736 .to_vec();
737 s.lanes = vec![
738 lane("api", "build", Some((3, 8)), 2),
739 lane("core", "complete", Some((12, 12)), 0),
740 web,
741 lane("docs", "up to date", None, 0),
742 ];
743 let lines = human(&s);
744 assert!(
745 lines.iter().all(|l| !l.starts_with("Progress:")),
746 "{lines:?}"
747 );
748 let at = lines.iter().position(|l| l.starts_with("LANE")).unwrap();
749 assert_eq!(
750 lines[at..at + 5],
751 [
752 "LANE STATE PROGRESS WAITS ON",
753 "api build 3/8 Verified · 2 in flight · 3 waiting",
754 "core complete 12/12 Verified",
755 "web idle 0/4 Verified · 4 waiting api U-007, core U-002, core U-003 +1 more",
756 "docs up to date ?",
757 ]
758 );
759 }
760
761 #[test]
762 fn human_view() {
763 let lines = human(&snap());
764 assert_eq!(
765 lines[0],
766 "run-x · alive · 10m elapsed · specs/calc · claude"
767 );
768 assert_eq!(lines[1], "Progress: 1/2 Verified · 1 Claimed");
769 assert_eq!(lines[3], "UNIT TRY STAGE TIME OUTPUT WORK");
770 assert_eq!(
771 lines[4],
772 "U-001 c1 editing 10m/45m 4s ago 2 KB 2 files +40 -1"
773 );
774 assert_eq!(
776 lines[5],
777 "Gate: rows 3/7 · pytest tests/test_parse.py (42s)"
778 );
779 assert!(lines.contains(&"! U-001 c1: no output for 6m (since 14:04:00)".to_string()));
780 let fin = lines.iter().position(|l| l == "Finished").unwrap();
781 assert_eq!(lines[fin + 1], "U-002 c1 verified 8m");
782 assert_eq!(lines.last().unwrap(), "Logs: .vitrify/logs/run-x/");
783 }
784
785 #[test]
786 fn gate_texts() {
787 let mut g = snap().gate.unwrap();
788 let now = UtcTime::parse("2026-11-16T14:10:00Z").unwrap();
789 g.running.push(("ruff check .".to_string(), None));
790 assert_eq!(
791 gate_text(&g, now),
792 "rows 3/7 · pytest tests/test_parse.py (42s) +1 more"
793 );
794 g.step = "lock".to_string();
795 assert_eq!(gate_text(&g, now), "waiting for the integration checkout");
796 g.step = "lint".to_string();
797 g.running = vec![("x".repeat(70), None)];
798 let text = gate_text(&g, now);
799 assert_eq!(text, format!("lint · {}…", "x".repeat(59)));
800 g.running.clear();
801 g.step = "head-check".to_string();
802 assert_eq!(gate_text(&g, now), "checking the mainline head");
803 }
804}