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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
//! 🚀 **Release** tab — the release-op DAG (`release_events`) as a viz surface.
//!
//! Two panes over the same data, both driven by the warehouse
//! [`release_events`](crate::warehouse::release_events) table:
//!
//! 1. **Op-log** (B3) — a streaming worklog, one line per
//! `component × op × phase` boundary, prefixed by the component it acts on:
//! `[znippy] test start`, `[znippy] test end ok (1.2s)`, `[holger] gate end ok`.
//! Grouped by `run_id`, **newest run on top**, `seq`-ordered within a run.
//! 2. **Lit-up dep-graph** (B4) — the rectangular dep-graph (reusing
//! [`super::graph`]'s node/edge geometry) where each node is **coloured by
//! its latest `release_events` status for the selected run**: running = amber
//! pulse, ok = green, fail = red, idle = dim. As a run progresses (the table
//! gains rows), the graph lights up.
//!
//! Read path: **local** mode opens the warehouse read-only and calls
//! [`query_release_events`]. **Remote** mode reads the SAME rows over the
//! `Viz.ReleaseEvents` gRPC (the warehouse lives on the server, which holds the
//! redb lock), decoding them into the identical [`ReleaseEventRow`] — so the
//! op-log + lit-up dep-graph render byte-identically whether the viz is embedded
//! or thin. This is the same local-or-remote split the other tabs use.
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::time::Instant;
use eframe::egui::{
self, Align2, Color32, CornerRadius, FontId, Pos2, Rect, RichText, ScrollArea, Sense, Stroke,
Vec2,
};
use crate::release::doctor::{self, DepPolicy, DoctorReport};
use crate::release::edition::{self, EditionReport};
use crate::warehouse::iceberg::IcebergWarehouse;
use crate::warehouse::release_events::{
query_release_events, status, EventSelector, ReleaseEventRow,
};
use super::facett_theme::{Theme, AMBER, GREEN, RED};
/// Where the release events come from (mirrors the other tabs' local/remote split).
enum Src {
Local(PathBuf),
/// Thin mode — read `release_events` over the `Viz.ReleaseEvents` RPC. The
/// `workspace` selects which served workspace's events (the gRPC header).
Remote { endpoint: String, token: String, workspace: String },
}
/// One "run" — the rows of a single `run_id`, newest run on top.
#[derive(Clone)]
struct RunGroup {
run_id: String,
/// `seq`-ordered rows for this run.
rows: Vec<ReleaseEventRow>,
/// Latest `ts_micros` in the run — used to sort runs newest-first.
latest_ts: i64,
}
// The cached **Gate / Doctor** model is the SHARED [`super::gate::GateModel`] —
// the same computation + `gate_json` shape the 🧬 nornir RELEASE DASHBOARD reuses.
use super::gate::GateModel;
pub struct ReleaseTabState {
src: Src,
loaded: bool,
error: Option<String>,
/// Inputs for the **Gate / Doctor** section: the workspace checkout root and
/// the repos to analyze. Only LOCAL mode has a checkout to scan; remote mode
/// leaves this empty (the gate section then shows a "local-only" note).
gate_repos: Vec<(String, PathBuf)>,
/// Forbidden-version policy fed to the doctor's skew analysis (e.g. `arrow 56`).
gate_policy: DepPolicy,
/// Cached gate/doctor model — computed in `load()`/`reload()`, NOT per repaint.
gate: Option<GateModel>,
/// Set when computing the gate model failed (rendered in the section).
gate_error: Option<String>,
/// Whether the opt-in dynamic edition lint pass (`cargo check`, multi-second)
/// has been requested via the button; folded into the next gate recompute.
edition_lint_requested: bool,
/// All runs found, newest first.
runs: Vec<RunGroup>,
/// The selected run_id (the graph + op-log scope). Defaults to newest.
selected_run: Option<String>,
/// Pulse phase for the amber "running" glow (advances every frame).
started_at: Instant,
/// Active palette — every colour below derives from it so a palette switch
/// re-skins the whole pane.
theme: Theme,
/// Two-step confirm latch for the HEAVY release-grade operation (runs the
/// full release gate across the build order server-side — release-grade).
run_armed: bool,
/// Last `Ops.RunRelease` result (rendered + reported in state_json).
run_result: Option<Result<super::remote::OpRunResult, String>>,
}
impl ReleaseTabState {
pub fn local(root: PathBuf) -> Self {
Self::with(Src::Local(root))
}
pub fn remote(endpoint: String, token: String, workspace: String) -> Self {
Self::with(Src::Remote { endpoint, token, workspace })
}
/// Re-point the thin-mode RPC at a new workspace (the picker switched). No-op
/// when local; drops the cache so the next draw refetches.
pub fn set_workspace(&mut self, workspace: String) {
if let Src::Remote { workspace: w, .. } = &mut self.src {
*w = workspace;
}
self.reload();
}
/// Wire the **Gate / Doctor** section's inputs: the workspace root + repo names
/// (local mode only). Each repo's checkout is `root/<repo>`; repos without a
/// `Cargo.toml` are skipped. The forbidden-version policy mirrors the CLI's
/// `--forbid crate=version` (e.g. `arrow 56`). Drops any cached model so the
/// next `load()` recomputes.
pub fn set_gate_inputs(&mut self, root: &std::path::Path, repos: &[String], policy: DepPolicy) {
self.gate_repos = repos
.iter()
.map(|name| (name.clone(), root.join(name)))
.filter(|(_, p)| p.join("Cargo.toml").exists())
.collect();
self.gate_policy = policy;
self.gate = None;
self.gate_error = None;
self.loaded = false;
}
fn with(src: Src) -> Self {
Self {
src,
loaded: false,
error: None,
gate_repos: Vec::new(),
gate_policy: DepPolicy::default(),
gate: None,
gate_error: None,
edition_lint_requested: false,
runs: Vec::new(),
selected_run: None,
started_at: Instant::now(),
theme: Theme::default(),
run_armed: false,
run_result: None,
}
}
/// The 🚀 Release pane's operation strip: **Release (heavy gate)** — the
/// full release-grade gate across the build order. HEAVY: confirm + a
/// "long-running / release-grade" warning before firing `Ops.RunRelease`,
/// which persists `release_events` so this very pane lights up. Remote-only;
/// CLI parity = `nornir release gate all` / `nornir release run`.
fn draw_release_op(&mut self, ui: &mut egui::Ui) {
let Src::Remote { endpoint, token, workspace } = &self.src else {
ui.label(
egui::RichText::new("release via `nornir release` CLI (local mode)")
.color(self.theme.text_dim),
);
return;
};
let (endpoint, token, workspace) = (endpoint.clone(), token.clone(), workspace.clone());
if !self.run_armed {
if ui
.button("🚀 Release (heavy gate)")
.on_hover_text("HEAVY / release-grade — runs the full release gate across the build order server-side (Ops.RunRelease). CLI: nornir release gate all")
.clicked()
{
self.run_armed = true;
}
} else {
ui.colored_label(AMBER, "⚠ heavy / release-grade — confirm?");
if ui.button("✓ run release gate").clicked() {
self.run_result = Some(
super::remote::run_release(&endpoint, &token, "", &workspace)
.map_err(|e| format!("{e:#}")),
);
self.run_armed = false;
self.reload();
}
if ui.button("✕ cancel").clicked() {
self.run_armed = false;
}
}
match &self.run_result {
Some(Ok(r)) => { ui.colored_label(if r.ok { GREEN } else { RED }, &r.summary); }
Some(Err(e)) => { ui.colored_label(RED, e); }
None => {}
}
}
/// Swap the active palette so the next draw re-skins every colour.
pub fn set_palette(&mut self, t: Theme) {
self.theme = t;
}
/// Test-only: inject release-op rows directly (no warehouse on disk), marking
/// the tab loaded so `draw`/`state_json` render the injected DAG. Mirrors
/// the app's `inject_timeline_for_test` for this surface.
#[doc(hidden)]
pub fn inject_for_test(&mut self, rows: Vec<ReleaseEventRow>) {
self.runs = group_runs(rows);
self.selected_run = self.runs.first().map(|r| r.run_id.clone());
self.loaded = true;
self.error = None;
}
/// Test-only: inject a Gate / Doctor model directly (no checkout to scan), so
/// the robot/inject-assert harness can read the `"gate"` block out of
/// `state_json()`. Mirrors `inject_for_test` for the gate surface. Marks the
/// tab loaded and emits the trace, exactly as `compute_gate` would.
#[doc(hidden)]
pub fn inject_gate_for_test(&mut self, doctor: DoctorReport, edition: EditionReport) {
// Mark configured so `draw_gate_section` renders the model (not the
// local-only note); use a sentinel repo entry the doctor would have filled.
if self.gate_repos.is_empty() {
self.gate_repos.push(("nornir".into(), PathBuf::from(".")));
}
self.gate = Some(GateModel::new(doctor, edition));
self.gate_error = None;
self.loaded = true;
self.emit_trace();
}
/// Re-scope (workspace switch / reload): drop the cache so the next draw reloads.
pub fn reload(&mut self) {
self.loaded = false;
self.error = None;
self.runs.clear();
self.selected_run = None;
self.gate = None;
self.gate_error = None;
}
/// Compute (and cache) the **Gate / Doctor** model: the doctor advisory + the
/// edition gate. Runs ONCE per load/reload (not per repaint). The edition
/// dynamic lint pass (`cargo check`) only runs when `edition_lint_requested`
/// — otherwise we skip it and use only the cheap `static_findings`, per the
/// perf caveat. Local mode only (remote has no checkout to scan).
fn compute_gate(&mut self) {
if self.gate.is_some() || self.gate_repos.is_empty() {
return;
}
// The dynamic `cargo check` edition lint pass is opt-in — the always-on
// view uses static-only. The SHARED gate model does the same computation
// the 🧬 dashboard reuses.
match GateModel::compute(&self.gate_repos, &self.gate_policy, self.edition_lint_requested) {
Ok(m) => {
self.gate = Some(m);
self.gate_error = None;
self.emit_trace();
}
Err(e) => self.gate_error = Some(e),
}
}
/// Emit the gate/doctor model as a machine-readable trace (the twin of what the
/// pane paints), and self-report a `functional_status` row so a pane that can't
/// build its model becomes a RED matrix row. No-op for trace when unconfigured.
fn emit_trace(&self) {
let model = self.gate_json();
super::trace::emit_out("release.gate.build", &model);
super::trace::emit_end(
"release.gate",
&serde_json::json!({
"skew_count": model["skew_count"],
"held_back": model["held_back"],
"cycle_advice": model["cycle_advice"],
"edition_clean": model["edition_clean"],
}),
);
#[cfg(feature = "testmatrix")]
{
// ok ⇔ the pane built a gate model (or had no inputs to build one) AND
// did not error. A broken model build → RED row.
let built = self.gate.is_some() || self.gate_repos.is_empty();
crate::selftest::emit(
"viz/release (gate/doctor)",
"release_gate_model_built",
built && self.gate_error.is_none(),
&format!(
"skew={} held_back={} cycle_advice={} edition_clean={} error={:?}",
model["skew_count"],
model["held_back"].as_array().map(|a| a.len()).unwrap_or(0),
model["cycle_advice"],
model["edition_clean"],
self.gate_error,
),
);
}
}
/// Read every release event from the warehouse and group by run (local only).
fn load(&mut self) {
if self.loaded {
return;
}
self.loaded = true;
// Build the cached Gate / Doctor model (once per load; perf-sensitive code
// paths are gated — dynamic `cargo check` is opt-in).
self.compute_gate();
let rows = match &self.src {
Src::Local(root) => {
// Read-only + lock-tolerant: coexist with a live server holding
// the catalog lock (the snapshot-copy fallback) exactly as the
// `nornir release events` CLI read path does.
match IcebergWarehouse::open_read_only(root)
.and_then(|wh| wh.block_on(query_release_events(&wh, &EventSelector::All)))
{
Ok(rows) => rows,
Err(e) => {
self.error = Some(format!("{e:#}"));
return;
}
}
}
Src::Remote { endpoint, token, workspace } => {
// Thin mode: read the SAME rows over Viz.ReleaseEvents (the server
// holds the warehouse lock). Decoded into ReleaseEventRow, so the
// grouping/graph below is source-agnostic.
match super::remote::fetch_release_events(endpoint, token, workspace) {
Ok(rows) => rows,
Err(e) => {
self.error = Some(format!("{e:#}"));
return;
}
}
}
};
self.runs = group_runs(rows);
self.selected_run = self.runs.first().map(|r| r.run_id.clone());
}
/// The currently-selected run (or the newest if none chosen yet).
fn current(&self) -> Option<&RunGroup> {
let sel = self.selected_run.as_deref();
sel.and_then(|id| self.runs.iter().find(|r| r.run_id == id))
.or_else(|| self.runs.first())
}
pub fn draw(&mut self, ui: &mut egui::Ui) {
let theme = self.theme;
self.load();
if let Some(err) = self.error.clone() {
ui.colored_label(RED, format!("release_events read failed:\n{err}"));
return;
}
if self.runs.is_empty() {
ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
ui.vertical_centered(|ui| {
ui.add_space(20.0);
ui.heading("🚀 Release — no release runs recorded yet");
ui.label("Every `nornir release run` records its op DAG here:");
ui.monospace("nornir release run");
ui.monospace("nornir release events <run-id|repo> # CLI twin");
ui.add_space(12.0);
ui.horizontal(|ui| self.draw_release_op(ui));
});
ui.add_space(16.0);
ui.separator();
// Even with no runs yet, the Gate / Doctor advisory is useful.
self.draw_gate_section(ui);
});
return;
}
// ── run picker (newest first) ────────────────────────────────────────
let runs: Vec<(String, usize, i64)> = self
.runs
.iter()
.map(|r| (r.run_id.clone(), r.rows.len(), r.latest_ts))
.collect();
egui::TopBottomPanel::top("release_controls").show_inside(ui, |ui| {
ui.horizontal_wrapped(|ui| {
ui.label("run:");
let sel = self
.selected_run
.clone()
.unwrap_or_else(|| runs.first().map(|r| r.0.clone()).unwrap_or_default());
egui::ComboBox::from_id_salt("release_run")
.selected_text(short_run(&sel))
.show_ui(ui, |ui| {
for (id, n, _) in &runs {
ui.selectable_value(
&mut self.selected_run,
Some(id.clone()),
format!("{} · {n} events", short_run(id)),
);
}
});
if ui.button("↻ reload").on_hover_text("re-read release_events").clicked() {
self.reload();
}
ui.separator();
self.draw_release_op(ui);
ui.separator();
legend(ui, &theme);
});
});
// Resolve the selected run AFTER the picker may have changed it.
let Some(run) = self.current().cloned() else { return };
// Latest status per component for THIS run (drives the graph colours).
let comp_status = component_status(&run.rows);
// ── B4: the lit-up dep-graph (top half) ──────────────────────────────
let graph_h = (ui.available_height() * 0.5).max(180.0);
egui::TopBottomPanel::top("release_graph")
.resizable(true)
.default_height(graph_h)
.show_inside(ui, |ui| {
ScrollArea::both().auto_shrink([false, false]).show(ui, |ui| {
self.draw_lit_graph(ui, &run, &comp_status);
});
});
// ── B3: the op-log (bottom half) ─────────────────────────────────────
egui::CentralPanel::default().show_inside(ui, |ui| {
ui.horizontal(|ui| {
ui.strong(format!("run {}", short_run(&run.run_id)));
ui.separator();
let overall = run_outcome(&run.rows);
let (col, txt) = match overall {
RunOutcome::Running => (AMBER, "● running"),
RunOutcome::Ok => (GREEN, "✓ ok"),
RunOutcome::Fail => (RED, "✗ failed"),
};
ui.colored_label(col, txt);
ui.separator();
ui.weak(format!("{} events", run.rows.len()));
});
ui.separator();
ScrollArea::vertical()
.auto_shrink([false, false])
.stick_to_bottom(true)
.show(ui, |ui| {
for r in &run.rows {
op_log_row(ui, &theme, r);
}
ui.add_space(8.0);
ui.separator();
// The Gate / Doctor advisory beneath the op-log (cached model).
self.draw_gate_section(ui);
});
});
// Keep the amber pulse animating while any op is still running.
if comp_status.values().any(|s| *s == status::RUNNING) {
ui.ctx().request_repaint_after(std::time::Duration::from_millis(80));
}
}
/// B4 — the rectangular dep-graph, nodes coloured by latest release status.
fn draw_lit_graph(
&self,
ui: &mut egui::Ui,
run: &RunGroup,
comp_status: &BTreeMap<String, String>,
) {
let theme = self.theme;
// Components (graph nodes) = every component named in this run, ordered
// deps-first by depends_on (a stable toposort; falls back to first-seen).
let order = topo_order(run);
if order.is_empty() {
ui.label("(no components in this run)");
return;
}
const NODE_W: f32 = 150.0;
const NODE_H: f32 = 52.0;
const COL_GAP: f32 = 210.0;
const LEFT_PAD: f32 = 24.0;
const TOP_PAD: f32 = 40.0;
let col_of: BTreeMap<&str, usize> =
order.iter().enumerate().map(|(i, c)| (c.as_str(), i)).collect();
let pos_for = |rect: Rect, comp: &str| -> Pos2 {
let col = *col_of.get(comp).unwrap_or(&0);
Pos2::new(rect.left() + LEFT_PAD + col as f32 * COL_GAP, rect.top() + TOP_PAD)
};
let needed_w = LEFT_PAD + order.len() as f32 * COL_GAP + NODE_W;
let canvas = Vec2::new(ui.available_width().max(needed_w), (NODE_H + TOP_PAD * 2.0).max(160.0));
let (rect, _resp) = ui.allocate_exact_size(canvas, Sense::hover());
let painter = ui.painter_at(rect);
painter.rect_filled(rect, CornerRadius::ZERO, theme.bg);
// amber pulse 0..1 for the running glow.
let pulse = {
let t = self.started_at.elapsed().as_secs_f32();
0.5 + 0.5 * (t * 3.0).sin()
};
// edges (consumer → producer), drawn under nodes.
for comp in &order {
if let Some(deps) = depends_on_of(run, comp) {
let from = pos_for(rect, comp) + Vec2::new(0.0, NODE_H / 2.0);
for dep in deps {
if !col_of.contains_key(dep.as_str()) {
continue;
}
let to = pos_for(rect, dep) + Vec2::new(NODE_W, NODE_H / 2.0);
painter.line_segment(
[from, to],
Stroke::new(2.0, theme.edge),
);
}
}
}
// nodes.
for comp in &order {
let node_pos = pos_for(rect, comp);
let node_rect = Rect::from_min_size(node_pos, Vec2::new(NODE_W, NODE_H));
let st = comp_status.get(comp.as_str()).map(String::as_str).unwrap_or("idle");
let base = lit_color(&theme, st);
// Running nodes pulse between dim and full amber.
let fill = if st == status::RUNNING {
let a = (110.0 + 110.0 * pulse) as u8;
AMBER.linear_multiply(a as f32 / 255.0)
} else {
theme.node_fill
};
painter.rect_filled(node_rect, CornerRadius::same(6), fill);
painter.rect_stroke(
node_rect,
CornerRadius::same(6),
Stroke::new(2.5, base),
egui::StrokeKind::Inside,
);
painter.text(
node_pos + Vec2::new(NODE_W / 2.0, 12.0),
Align2::CENTER_TOP,
comp,
FontId::proportional(14.0),
theme.text,
);
painter.text(
node_pos + Vec2::new(NODE_W / 2.0, 30.0),
Align2::CENTER_TOP,
st,
FontId::monospace(11.0),
base,
);
}
}
/// The structured **Gate / Doctor** block folded into `state_json` — what the
/// robot test (track D) asserts on. Stable keys regardless of whether the model
/// is present (remote / unconfigured → `present: false`, zero counts).
fn gate_json(&self) -> serde_json::Value {
// Delegate to the SHARED gate model's `gate_json` shape (the same the 🧬
// dashboard ships), so the two surfaces can never drift.
match &self.gate {
Some(m) => m.gate_json(self.gate_error.as_deref()),
None => super::gate::gate_json_absent(self.gate_error.as_deref()),
}
}
/// The **Gate / Doctor** section of the Release pane: dirty trees, external-dep
/// skew (with the ⛔ transitive-pin rows), cycle-break advice, and the
/// edition-2024 gate result. Reads only the CACHED model (no recompute per
/// frame); the dynamic edition lint pass is behind a button.
fn draw_gate_section(&mut self, ui: &mut egui::Ui) {
let theme = self.theme;
egui::CollapsingHeader::new("🩺 Gate / Doctor")
.default_open(true)
.show(ui, |ui| {
if self.gate_repos.is_empty() {
ui.label(
RichText::new(
"gate/doctor is local-only — run `nornir release doctor` / `nornir release gate edition <repo>` via the CLI",
)
.color(theme.text_dim),
);
return;
}
if let Some(err) = &self.gate_error {
ui.colored_label(RED, format!("gate/doctor failed: {err}"));
return;
}
let Some(m) = &self.gate else {
ui.label(RichText::new("(computing gate model…)").color(theme.text_dim));
return;
};
// ── dirty trees ──────────────────────────────────────────────
let dirty: Vec<&str> =
m.doctor.dirty.iter().filter(|d| d.dirty).map(|d| d.repo.as_str()).collect();
ui.horizontal_wrapped(|ui| {
ui.strong("Working trees:");
if dirty.is_empty() {
ui.colored_label(GREEN, "✅ all clean");
} else {
ui.colored_label(AMBER, format!("🟡 dirty: {}", dirty.join(", ")));
}
});
// ── external-dep skew (with ⛔ transitive-pin rows) ───────────
ui.add_space(2.0);
ui.strong(format!("External dependency skew ({}):", m.doctor.skew.len()));
if m.doctor.skew.is_empty() {
ui.colored_label(GREEN, " ✅ no divergence");
} else {
for c in &m.doctor.skew {
ui.label(
RichText::new(format!(" {} (target {})", c.crate_name, c.target))
.color(theme.text),
);
for e in &c.entries {
use doctor::SkewStatus;
let (glyph, col) = match e.status {
SkewStatus::Ok => ("✓", GREEN),
SkewStatus::Behind if e.held_by_transitive_pin => ("⛔", RED),
SkewStatus::Behind => ("·", theme.text_dim),
SkewStatus::Forbidden => ("⚠", AMBER),
};
let note = if e.held_by_transitive_pin {
format!(" (held: lock already resolves {}; a transitive dep pins {})", c.target, e.version)
} else {
String::new()
};
ui.colored_label(
col,
format!(" {glyph} {} {}{}", e.repo, e.version, note),
);
}
}
}
// ── cycle-break advice ───────────────────────────────────────
ui.add_space(2.0);
if m.doctor.cycle_advice.is_empty() {
ui.horizontal(|ui| {
ui.strong("Cycle-break advice:");
ui.colored_label(GREEN, "✅ clean DAG (no cycle)");
});
} else {
ui.strong(format!("Cycle-break advice ({}):", m.doctor.cycle_advice.len()));
for a in &m.doctor.cycle_advice {
ui.colored_label(
AMBER,
format!(" ⟲ {} — 💡 {}", a.members.join(" ⇄ "), a.rationale),
);
}
}
// ── edition-2024 gate ────────────────────────────────────────
ui.add_space(2.0);
ui.horizontal_wrapped(|ui| {
ui.strong("Edition 2024 gate:");
if m.edition.is_clean() {
ui.colored_label(GREEN, "✅ clean");
} else {
ui.colored_label(
RED,
format!(
"✗ {} static finding(s){}",
m.edition.static_findings.len(),
if m.edition.lint_pass_ran {
format!(" + {} lint(s)", m.edition.lints.len())
} else {
String::new()
},
),
);
}
});
for f in &m.edition.static_findings {
ui.colored_label(theme.text_dim, format!(" · {} — {}", f.package, f.issue));
}
if m.edition.lint_pass_ran {
for l in &m.edition.lints {
ui.colored_label(AMBER, format!(" ⚠ {l}"));
}
}
// The HEAVY opt-in: run the dynamic `cargo check` 2024-compat lint
// pass (multi-second) — off by default per the perf caveat.
if !self.edition_lint_requested {
if ui
.button("▶ run edition lint pass (cargo check)")
.on_hover_text("HEAVY: shells `cargo check` with --force-warn rust-2024-compatibility; multi-second")
.clicked()
{
self.edition_lint_requested = true;
self.gate = None; // force recompute with the dynamic pass
self.loaded = false;
}
} else {
ui.label(RichText::new("(dynamic lint pass ran)").color(theme.text_dim));
}
});
}
/// Test/introspection hook: the release-op rows + run + per-component status
/// the tab is rendering, as a JSON value folded into the app's `state_json`.
pub fn state_json(&self) -> serde_json::Value {
let current = self.current();
let rows: Vec<serde_json::Value> = current
.map(|run| {
run.rows
.iter()
.map(|r| {
serde_json::json!({
"component": r.component,
"op": r.op,
"phase": r.phase,
"status": r.status,
"line": op_log_line(r),
})
})
.collect()
})
.unwrap_or_default();
let comp_status = current
.map(|run| component_status(&run.rows))
.unwrap_or_default();
serde_json::json!({
"source": match &self.src {
Src::Local(p) => format!("local {}", p.display()),
Src::Remote { endpoint, workspace, .. } => {
format!("remote {endpoint} ws={workspace} (Viz.ReleaseEvents)")
}
},
"error": self.error,
"runs": self.runs.len(),
"selected_run": current.map(|r| r.run_id.clone()),
"rows": rows,
"component_status": comp_status,
"palette": self.theme.name,
// The Gate / Doctor model this pane renders (track C/D): skew, the ⛔
// transitive-pin held-back set, cycle-break advice, and the edition gate.
"gate": self.gate_json(),
// The HEAVY operation button this pane exposes (this feature): the
// release-grade gate → Ops.RunRelease. The matrix walks `ops` to prove
// the button is wired; `run_result` reports the last gate's outcome.
"ops": {
"buttons": [ { "id": "run_release_gate", "rpc": "Ops.RunRelease", "heavy": true, "confirm": true } ],
"armed": self.run_armed,
},
"run_result": match &self.run_result {
None => serde_json::json!({ "ran": false }),
Some(Ok(r)) => serde_json::json!({
"ran": true, "ok": r.ok, "summary": r.summary, "run_id": r.run_id,
"targets": r.targets.iter().map(|(n, s, m)| serde_json::json!({ "name": n, "status": s, "message": m })).collect::<Vec<_>>(),
}),
Some(Err(e)) => serde_json::json!({ "ran": true, "ok": false, "error": e }),
},
})
}
}
// ─── grouping + status reduction ─────────────────────────────────────────────
/// Group rows into runs (newest first; rows within a run kept in `seq` order —
/// `query_release_events` already sorts by `(run_id, seq)`).
fn group_runs(rows: Vec<ReleaseEventRow>) -> Vec<RunGroup> {
let mut by_run: BTreeMap<String, Vec<ReleaseEventRow>> = BTreeMap::new();
for r in rows {
by_run.entry(r.run_id.clone()).or_default().push(r);
}
let mut runs: Vec<RunGroup> = by_run
.into_iter()
.map(|(run_id, mut rows)| {
rows.sort_by_key(|r| r.seq);
let latest_ts = rows.iter().map(|r| r.ts_micros).max().unwrap_or(0);
RunGroup { run_id, rows, latest_ts }
})
.collect();
// Newest run on top.
runs.sort_by(|a, b| b.latest_ts.cmp(&a.latest_ts));
runs
}
/// Latest status per component within a run, walking rows in `seq` order so the
/// final state wins (a `running` start followed by an `ok` end → `ok`).
fn component_status(rows: &[ReleaseEventRow]) -> BTreeMap<String, String> {
let mut out: BTreeMap<String, String> = BTreeMap::new();
for r in rows {
// Skip the `run/*` envelope rows (no real component lane).
if r.op == "run" {
continue;
}
out.insert(r.component.clone(), r.status.clone());
}
out
}
/// Components in deps-first order: a simple Kahn toposort over the run's
/// `depends_on` edges; falls back to first-seen order on a cycle / missing data.
fn topo_order(run: &RunGroup) -> Vec<String> {
use std::collections::{BTreeSet, VecDeque};
// Components that are real ops (not the run envelope).
let mut comps: Vec<String> = Vec::new();
let mut seen: BTreeSet<String> = BTreeSet::new();
for r in &run.rows {
if r.op == "run" {
continue;
}
if seen.insert(r.component.clone()) {
comps.push(r.component.clone());
}
}
let set: BTreeSet<&str> = comps.iter().map(String::as_str).collect();
let mut indeg: BTreeMap<&str, usize> = comps.iter().map(|c| (c.as_str(), 0)).collect();
let mut adj: BTreeMap<&str, Vec<&str>> = BTreeMap::new();
for c in &comps {
if let Some(deps) = depends_on_of(run, c) {
for d in deps {
if set.contains(d.as_str()) {
// edge c → d means c consumes d; we want d first.
adj.entry(d.as_str()).or_default().push(c.as_str());
*indeg.entry(c.as_str()).or_insert(0) += 1;
}
}
}
}
let mut q: VecDeque<&str> =
comps.iter().map(String::as_str).filter(|c| indeg[c] == 0).collect();
let mut out: Vec<String> = Vec::new();
while let Some(c) = q.pop_front() {
out.push(c.to_string());
if let Some(children) = adj.get(c) {
for &ch in children {
let Some(d) = indeg.get_mut(ch) else { continue };
*d = d.saturating_sub(1);
if *d == 0 {
q.push_back(ch);
}
}
}
}
if out.len() == comps.len() {
out
} else {
comps
}
}
/// The `depends_on` list recorded for a component in this run (the first non-null
/// occurrence — every per-repo row carries the same list).
fn depends_on_of<'a>(run: &'a RunGroup, comp: &str) -> Option<&'a Vec<String>> {
run.rows
.iter()
.find(|r| r.component == comp && r.depends_on.is_some())
.and_then(|r| r.depends_on.as_ref())
}
enum RunOutcome {
Running,
Ok,
Fail,
}
/// The run's overall outcome: any `fail` → Fail; else any non-`end` op still open
/// → Running; else Ok.
fn run_outcome(rows: &[ReleaseEventRow]) -> RunOutcome {
if rows.iter().any(|r| r.status == status::FAIL) {
return RunOutcome::Fail;
}
// A run that emitted a `run/end ok` is done.
let ended_ok = rows
.iter()
.any(|r| r.op == "run" && r.phase == "end" && r.status == status::OK);
if ended_ok {
RunOutcome::Ok
} else if rows.iter().any(|r| r.status == status::RUNNING) {
RunOutcome::Running
} else {
RunOutcome::Ok
}
}
// ─── rendering helpers ───────────────────────────────────────────────────────
/// The op-log line for a row: `[component] op phase status (elapsed) — detail`.
fn op_log_line(r: &ReleaseEventRow) -> String {
let elapsed = r
.elapsed_ms
.map(|ms| format!(" ({:.1}s)", ms as f32 / 1000.0))
.unwrap_or_default();
let detail = if r.detail.is_empty() {
String::new()
} else {
format!(" — {}", r.detail)
};
format!(
"[{}] {} {} {}{}{}",
r.component, r.op, r.phase, r.status, elapsed, detail
)
}
/// One coloured op-log row (the component-prefixed worklog line).
fn op_log_row(ui: &mut egui::Ui, theme: &Theme, r: &ReleaseEventRow) {
let (glyph, col) = match r.status.as_str() {
status::OK => ("✓", GREEN),
status::FAIL => ("✗", RED),
status::WARN => ("⚠", AMBER),
status::RUNNING => ("…", AMBER),
_ => ("·", theme.text_dim),
};
ui.horizontal(|ui| {
ui.colored_label(col, glyph);
// `[component]` prefix in a distinct tint so lanes are scannable.
ui.label(
RichText::new(format!("[{}]", r.component))
.monospace()
.size(12.0)
.color(theme.text_dim),
);
ui.colored_label(col, op_log_line_suffix(r));
});
}
/// The part of the op-log line after the `[component]` prefix (so the row can
/// tint the prefix separately).
fn op_log_line_suffix(r: &ReleaseEventRow) -> String {
let elapsed = r
.elapsed_ms
.map(|ms| format!(" ({:.1}s)", ms as f32 / 1000.0))
.unwrap_or_default();
let detail = if r.detail.is_empty() {
String::new()
} else {
format!(" — {}", r.detail)
};
format!("{} {} {}{}{}", r.op, r.phase, r.status, elapsed, detail)
}
/// Node outline / status-text colour for a component's latest status.
fn lit_color(theme: &Theme, st: &str) -> Color32 {
match st {
status::OK => GREEN,
status::FAIL => RED,
status::WARN => AMBER,
status::RUNNING => AMBER,
_ => theme.node_stroke, // idle / dim
}
}
fn short_run(id: &str) -> String {
if id.chars().count() > 12 {
let head: String = id.chars().take(12).collect();
format!("{head}…")
} else {
id.to_string()
}
}
/// Status legend for the graph + op-log.
fn legend(ui: &mut egui::Ui, theme: &Theme) {
for (st, label) in [
(status::RUNNING, "running"),
(status::OK, "ok"),
(status::FAIL, "fail"),
("idle", "idle"),
] {
ui.colored_label(lit_color(theme, st), "●");
ui.weak(label);
ui.add_space(4.0);
}
}
#[cfg(test)]
mod tests {
use super::*;
fn row(
run: &str,
seq: i64,
comp: &str,
op: &str,
phase: &str,
st: &str,
deps: Option<Vec<&str>>,
elapsed: Option<i64>,
) -> ReleaseEventRow {
ReleaseEventRow {
run_id: run.into(),
seq,
ts_micros: seq * 10,
component: comp.into(),
repo: comp.into(),
op: op.into(),
phase: phase.into(),
status: st.into(),
detail: String::new(),
depends_on: deps.map(|v| v.into_iter().map(String::from).collect()),
elapsed_ms: elapsed,
}
}
#[test]
fn group_runs_newest_first_and_seq_ordered() {
let rows = vec![
row("runA", 1, "znippy", "test", "end", status::OK, None, Some(1200)),
row("runA", 0, "znippy", "test", "start", status::RUNNING, None, None),
row("runB", 0, "korp", "test", "start", status::RUNNING, Some(vec![]), None),
];
// runB has the highest ts (seq 0 * 10 = 0) vs runA (max seq 1 → ts 10),
// so runA is newest. Verify ordering + per-run seq order.
let runs = group_runs(rows);
assert_eq!(runs.len(), 2);
assert_eq!(runs[0].run_id, "runA", "newest (highest ts) run on top");
assert_eq!(runs[0].rows.iter().map(|r| r.seq).collect::<Vec<_>>(), vec![0, 1]);
}
#[test]
fn component_status_takes_latest() {
let rows = vec![
row("r", 0, "znippy", "test", "start", status::RUNNING, None, None),
row("r", 1, "znippy", "test", "end", status::OK, None, Some(5)),
row("r", 2, "holger", "gate", "start", status::RUNNING, Some(vec!["znippy"]), None),
row("r", 3, "r", "run", "end", status::OK, None, None), // envelope skipped
];
let st = component_status(&rows);
assert_eq!(st.get("znippy").map(String::as_str), Some(status::OK));
assert_eq!(st.get("holger").map(String::as_str), Some(status::RUNNING));
assert!(!st.contains_key("r"), "run-envelope component is not a node");
}
#[test]
fn topo_order_is_deps_first() {
let run = RunGroup {
run_id: "r".into(),
latest_ts: 0,
rows: vec![
row("r", 0, "holger", "gate", "start", status::RUNNING, Some(vec!["znippy"]), None),
row("r", 1, "znippy", "test", "start", status::RUNNING, Some(vec![]), None),
],
};
// holger depends on znippy → znippy must come first.
let order = topo_order(&run);
assert_eq!(order, vec!["znippy".to_string(), "holger".to_string()]);
}
#[test]
fn op_log_line_is_component_prefixed() {
let r = row("r", 0, "znippy", "test", "end", status::OK, None, Some(1200));
assert_eq!(op_log_line(&r), "[znippy] test end ok (1.2s)");
}
#[test]
fn run_outcome_fail_wins() {
let rows = vec![
row("r", 0, "znippy", "test", "end", status::OK, None, Some(5)),
row("r", 1, "holger", "test", "end", status::FAIL, None, Some(3)),
];
assert!(matches!(run_outcome(&rows), RunOutcome::Fail));
}
}