返回 CodeWhale
workbar.rs
根目录 / crates / tui / src / tui / widgets / workbar.rs
1 //! Engine facts and localization for the shared terminal kit's workflow rows.
2 //!
3 //! The kit replaces the former RowCells, column fitter, bar partition and
4 //! clipping renderer. WorkflowPanel remains the Engine's lifecycle authority;
5 //! this adapter passes its reported facts into WorkflowProgress. The existing
6 //! backend still owns terminal capabilities and custom palette adaptation.
7
8 use std::time::Duration;
9
10 use codewhale_localization::{Locale, MessageId, tr};
11 use codewhale_palette::UiTheme;
12 use codewhale_ratatui::{
13 Caps, Role, Theme, TuiInk, TuiPalette, WorkflowProgress, WorkflowProgressWords, WorkflowRun,
14 WorkflowRunState, color::ColorDepth, detect::Appearance,
15 };
16 use ratatui::text::Line;
17
18 use crate::tui::widgets::workflow_panel::{WorkflowPanel, WorkflowPanelLifecycle};
19
20 #[cfg(test)]
21 const LARGE_WORKFLOW_AGENTS: usize = 25;
22 #[cfg(test)]
23 const MAX_RUN_ROWS: usize = WorkflowProgress::desired_rows_for(usize::MAX) as usize - 1;
24
25 pub(crate) struct WorkbarRun<'a> {
26 pub panel: &'a WorkflowPanel,
27 pub queued: usize,
28 }
29
30 #[must_use]
31 pub(crate) fn desired_rows(runs: usize) -> u16 {
32 WorkflowProgress::desired_rows_for(runs)
33 }
34
35 pub(crate) fn render(
36 area: ratatui::layout::Rect,
37 buf: &mut ratatui::buffer::Buffer,
38 runs: &[WorkbarRun<'_>],
39 now_ms: u64,
40 theme: &UiTheme,
41 locale: Locale,
42 ) {
43 use ratatui::widgets::{Paragraph, Widget};
44 let area = area.intersection(buf.area);
45 Paragraph::new(lines(
46 runs,
47 area.width,
48 usize::from(area.height),
49 now_ms,
50 theme,
51 locale,
52 ))
53 .render(area, buf);
54 }
55
56 #[must_use]
57 pub(crate) fn lines(
58 runs: &[WorkbarRun<'_>],
59 width: u16,
60 max_rows: usize,
61 now_ms: u64,
62 theme: &UiTheme,
63 locale: Locale,
64 ) -> Vec<Line<'static>> {
65 let word = |id| tr(locale, id).into_owned().into();
66 let progress = WorkflowProgress::new(
67 runs.iter().map(|run| facts(run, now_ms, locale)).collect(),
68 )
69 .words(WorkflowProgressWords {
70 done: word(MessageId::WorkflowSettledOfTotal),
71 failed: word(MessageId::WorkflowCountFailed),
72 cancelled: word(MessageId::WorkflowCountCancelled),
73 queued: word(MessageId::AgentRailQueuedCount),
74 no_tasks: word(MessageId::WorkflowNoTasksYet),
75 large: word(MessageId::WorkbarLargeWorkflow),
76 gaps: word(MessageId::WorkflowLineFinishedWithGaps),
77 stopped: word(MessageId::WorkflowLineStopped),
78 more: word(MessageId::WorkbarMoreRuns),
79 manage: word(MessageId::FooterHintToManage),
80 });
81 // The selected/custom UiTheme and existing backend retain palette authority.
82 // A fixed full-color kit palette supplies distinct semantic ink identities;
83 // map those identities before the backend's single capability pass.
84 let source_theme = Theme::new(Caps {
85 depth: ColorDepth::TrueColor,
86 ascii: false,
87 appearance: Appearance::Dark,
88 })
89 .tui_palette(TuiPalette::Underwater);
90 let inks = [
91 (source_theme.color(Role::Foreground), theme.text_body),
92 (source_theme.color(Role::Muted), theme.text_muted),
93 (source_theme.color(Role::Hint), theme.text_hint),
94 (source_theme.color(Role::Danger), theme.error_fg),
95 (
96 source_theme.tui_ink(TuiInk::Working).fg,
97 theme.accent_action,
98 ),
99 (source_theme.tui_ink(TuiInk::Success).fg, theme.success),
100 (source_theme.tui_ink(TuiInk::Warning).fg, theme.warning),
101 ];
102 let mut rows = progress.lines(width, max_rows, &source_theme);
103 for row in &mut rows {
104 for span in &mut row.spans {
105 if let Some((_, color)) = inks
106 .iter()
107 .find(|(ink, _)| ink.is_some() && *ink == span.style.fg)
108 {
109 span.style.fg = Some(*color);
110 }
111 }
112 }
113 rows
114 }
115
116 fn facts(run: &WorkbarRun<'_>, now_ms: u64, locale: Locale) -> WorkflowRun<'static> {
117 let panel = run.panel;
118 let (succeeded, _, _, total) = panel.row_outcomes();
119 let (failed, cancelled) = panel.failure_cancel_counts();
120 let state = match panel.lifecycle {
121 WorkflowPanelLifecycle::Pending => WorkflowRunState::Pending,
122 WorkflowPanelLifecycle::Running => WorkflowRunState::Running,
123 WorkflowPanelLifecycle::Succeeded => WorkflowRunState::Succeeded,
124 WorkflowPanelLifecycle::Degraded => WorkflowRunState::Degraded,
125 WorkflowPanelLifecycle::Failed => WorkflowRunState::Failed,
126 WorkflowPanelLifecycle::Cancelled => WorkflowRunState::Cancelled,
127 };
128 let mut facts = WorkflowRun::new(panel.short_title(), state)
129 .outcomes(succeeded, failed, cancelled, total)
130 .queued(run.queued);
131 if panel.started_at_ms != 0 {
132 let end = panel.completed_at_ms.unwrap_or(now_ms);
133 facts = facts.elapsed(Duration::from_millis(
134 end.saturating_sub(panel.started_at_ms),
135 ));
136 }
137 if let Some(tokens) = panel.tokens_so_far() {
138 facts = facts.tokens(tokens);
139 }
140 if let Some(reason) = panel.outcome_reason() {
141 facts = facts.reason(reason);
142 } else if state == WorkflowRunState::Failed {
143 facts = facts.reason(tr(locale, MessageId::WorkflowLineFailed).into_owned());
144 }
145 facts
146 }
147
148 #[cfg(test)]
149 mod tests {
150 use super::*;
151 use crate::tui::widgets::workflow_panel::{
152 WorkflowPanelEvent, WorkflowRowStatus, WorkflowRowUsage,
153 };
154 use ratatui::{Terminal, backend::TestBackend};
155 use unicode_width::UnicodeWidthStr;
156
157 const NOW: u64 = 1_000_000;
158
159 fn run(label: &str, started: u64, agents: usize, settled: usize) -> WorkflowPanel {
160 let mut panel = WorkflowPanel::new(format!("run-{label}"), label, started);
161 panel.apply_event(WorkflowPanelEvent::PhaseStarted {
162 title: "Survey".to_string(),
163 at_ms: started,
164 });
165 for index in 0..agents {
166 let value = serde_json::json!({
167 "type": "task_started",
168 "task_id": format!("{label}-{index}"),
169 "workflow_task_label": format!("agent-{index}"),
170 "at_ms": started,
171 });
172 panel.apply_event(WorkflowPanelEvent::from_json_value(&value).expect("task_started"));
173 }
174 for index in 0..settled {
175 complete(&mut panel, label, index, WorkflowRowStatus::Succeeded, None);
176 }
177 panel
178 }
179
180 fn complete(
181 panel: &mut WorkflowPanel,
182 label: &str,
183 index: usize,
184 status: WorkflowRowStatus,
185 reason: Option<&str>,
186 ) {
187 panel.apply_event(WorkflowPanelEvent::TaskCompleted {
188 task_id: format!("{label}-{index}"),
189 status,
190 usage: None,
191 reason: reason.map(str::to_string),
192 at_ms: panel.started_at_ms + 1_000,
193 });
194 }
195
196 fn settled(
197 label: &str,
198 status: WorkflowPanelLifecycle,
199 agents: usize,
200 done: usize,
201 ) -> WorkflowPanel {
202 let mut panel = run(label, NOW - 60_000, agents, done);
203 panel.apply_event(WorkflowPanelEvent::RunCompleted {
204 status,
205 error: None,
206 at_ms: NOW - 1_000,
207 });
208 panel
209 }
210
211 /// The founder's run from 2026-09-28, as its status record came back: a
212 /// read-only audit whose two agents both failed auth 355 ms in.
213 fn founder_all_failed() -> WorkflowPanel {
214 let goal = "Read-only release-readiness audit for Codewhale v0.10.1. Determine \
215 actionable remaining blockers from live evidence, separating engine \
216 release from desktop and deferred backlog. No edits.";
217 let reason = "[auth] Authorization failed: You have run out of credits or need a \
218 Grok subscription. Add credits at https://grok.com/?_s=usage.\n\
219 (provider `xAI` · requested model `grok-4.6`)";
220 let error = "no task produced a result: all 2 task(s) failed and 1 fan-out(s) lost \
221 every slot (no work survived them); the recorded result reflects no \
222 completed work";
223 WorkflowPanel::from_run_json(&serde_json::json!({
224 "run_id": "workflow_6409ebe6",
225 "status": "failed",
226 "started_at_ms": 1_790_651_979_185_u64,
227 "completed_at_ms": 1_790_651_979_540_u64,
228 "workflow_goal": goal,
229 "error": error,
230 "events": [
231 {"at_ms": 1_790_651_979_185_u64, "type": "run_started", "workflow_goal": goal},
232 {"at_ms": 1_790_651_979_187_u64, "type": "phase_started", "title": "parallel-evidence"},
233 {"at_ms": 1_790_651_979_265_u64, "type": "task_started", "task_id": "agent_f6665537",
234 "workflow_task_label": "engine-readiness"},
235 {"at_ms": 1_790_651_979_302_u64, "type": "task_started", "task_id": "agent_94fe8e6a",
236 "workflow_task_label": "desktop-readiness"},
237 {"at_ms": 1_790_651_979_514_u64, "type": "task_completed", "task_id": "agent_f6665537",
238 "status": "failed", "reason": reason},
239 {"at_ms": 1_790_651_979_523_u64, "type": "task_completed", "task_id": "agent_94fe8e6a",
240 "status": "failed", "reason": reason},
241 {"at_ms": 1_790_651_979_540_u64, "type": "run_completed", "status": "failed",
242 "error": error},
243 ],
244 }))
245 .expect("run record")
246 }
247
248 fn partial_success() -> WorkflowPanel {
249 let mut panel = run("Port the fixture suite", NOW - 134_000, 4, 3);
250 complete(
251 &mut panel,
252 "Port the fixture suite",
253 3,
254 WorkflowRowStatus::Failed,
255 Some("Timed out waiting for the model after 600s. Retried once."),
256 );
257 panel.apply_event(WorkflowPanelEvent::RunCompleted {
258 status: WorkflowPanelLifecycle::Degraded,
259 error: Some("completed with dropped slots".to_string()),
260 at_ms: NOW,
261 });
262 panel
263 }
264
265 fn render(runs: &[WorkbarRun<'_>], width: u16, rows: u16) -> String {
266 buffer_rows(&render_band(runs, width, rows)).join("\n")
267 }
268
269 fn render_band(runs: &[WorkbarRun<'_>], width: u16, height: u16) -> ratatui::buffer::Buffer {
270 let area = ratatui::layout::Rect::new(0, 0, width, height);
271 let mut terminal = Terminal::new(TestBackend::new(width, height)).expect("terminal");
272 terminal
273 .draw(|frame| {
274 super::render(
275 area,
276 frame.buffer_mut(),
277 runs,
278 NOW,
279 &codewhale_palette::UI_THEME,
280 Locale::En,
281 );
282 })
283 .expect("draw");
284 terminal.backend().buffer().clone()
285 }
286
287 fn buffer_rows(buf: &ratatui::buffer::Buffer) -> Vec<String> {
288 let area = buf.area;
289 (area.y..area.bottom())
290 .map(|y| {
291 (area.x..area.right())
292 .map(|x| buf[(x, y)].symbol().to_string())
293 .collect::<String>()
294 .trim_end()
295 .to_string()
296 })
297 .collect()
298 }
299
300 fn one(panel: &WorkflowPanel) -> [WorkbarRun<'_>; 1] {
301 [WorkbarRun { panel, queued: 0 }]
302 }
303
304 /// The four states the founder's screenshot needed, as the buffer paints
305 /// them. These strings are the PR's evidence; keep them exact.
306 #[test]
307 fn snapshot_running_all_failed_partial_and_narrow() {
308 let mut running = run("Compare Cline with Codewhale", NOW - 134_000, 10, 4);
309 complete(
310 &mut running,
311 "Compare Cline with Codewhale",
312 4,
313 WorkflowRowStatus::Failed,
314 Some("rate limited"),
315 );
316 running.phases[0].rows[0].usage = Some(WorkflowRowUsage {
317 total_tokens: Some(1_234_567),
318 ..WorkflowRowUsage::default()
319 });
320 let founder = founder_all_failed();
321 let partial = partial_success();
322 let cases = [
323 (
324 "running",
325 render(&one(&running), 110, 1),
326 " • Compare Cline with Codewhale ████████××░░░░░░░░░░ 4/10 done · 1 failed 2m 14s ↓1.2M",
327 ),
328 (
329 "all failed",
330 render(&one(&founder), 140, 1),
331 " ✕ Read-only release-readiness audit for… ×××××××××××××××××××× 0/2 done · 2 failed 355ms Authorization failed: You have run out of…",
332 ),
333 (
334 "partial success",
335 render(&one(&partial), 140, 1),
336 " ◆ Port the fixture suite ███████████████××××× 3/4 done · 1 failed 2m 14s finished with gaps · Timed out waiting for the model after…",
337 ),
338 (
339 "narrow 60",
340 render(&one(&founder), 60, 1),
341 " ✕ Read-only release-readiness… 0/2 done · 2 failed 355ms",
342 ),
343 (
344 "narrow 40",
345 render(&one(&founder), 40, 1),
346 " ✕ Read-only… 0/2 done · 2 failed",
347 ),
348 ];
349 let wrong: Vec<String> = cases
350 .iter()
351 .filter(|(_, actual, expected)| actual != expected)
352 .map(|(name, actual, expected)| {
353 format!("{name}:\n got {actual:?}\n want {expected:?}")
354 })
355 .collect();
356 assert!(wrong.is_empty(), "{}", wrong.join("\n"));
357 for (_, row, _) in &cases[3..] {
358 assert!(!row.contains('█') && !row.contains('×'), "{row}");
359 }
360 assert!(cases[3].1.width() <= 60 && cases[4].1.width() <= 40);
361 }
362
363 #[test]
364 fn a_failed_run_never_paints_a_success_bar_or_rounds_to_zero_seconds() {
365 let founder = founder_all_failed();
366 let band = render_band(&one(&founder), 140, 1);
367 let row = &buffer_rows(&band)[0];
368 assert!(!row.contains('█'), "no agent succeeded: {row}");
369 assert!(row.contains("0/2 done · 2 failed"), "{row}");
370 assert!(row.contains("355ms") && !row.contains(" 0s"), "{row}");
371 // The failed state mark carries error ink; the custom-theme regression
372 // separately covers failure bar cells.
373 let theme = codewhale_palette::UI_THEME;
374 let failed_cell = (0..140)
375 .find(|&x| band[(x, 0)].symbol() == codewhale_ratatui::glyphs::FAILED)
376 .expect("failed state mark");
377 assert_eq!(band[(failed_cell, 0)].fg, theme.error_fg);
378 // The agents' own reason, not the run's aggregate, and not cut mid-word.
379 assert!(row.contains("Authorization failed"), "{row}");
380 assert!(!row.contains("no task produced"), "{row}");
381 assert!(row.ends_with('…') || row.ends_with("subscription"), "{row}");
382 }
383
384 #[test]
385 fn settled_rows_read_without_colour() {
386 let done = settled("audit", WorkflowPanelLifecycle::Succeeded, 3, 3);
387 let mut failed = run("migrate", NOW - 60_000, 2, 0);
388 failed.apply_event(WorkflowPanelEvent::RunCompleted {
389 status: WorkflowPanelLifecycle::Failed,
390 error: Some("script error".to_string()),
391 at_ms: NOW - 1_000,
392 });
393 let gaps = settled("review", WorkflowPanelLifecycle::Degraded, 2, 1);
394 let runs = [
395 WorkbarRun {
396 panel: &done,
397 queued: 0,
398 },
399 WorkbarRun {
400 panel: &failed,
401 queued: 0,
402 },
403 WorkbarRun {
404 panel: &gaps,
405 queued: 0,
406 },
407 ];
408 assert_eq!(
409 render(&runs, 80, 3),
410 [
411 " ✓ audit ████████████████████ 3/3 done 59s",
412 " ✕ migrate ░░░░░░░░░░░░░░░░░░░░ 0/2 done 59s script error",
413 " ◆ review ██████████░░░░░░░░░░ 1/2 done 59s finished with gaps",
414 ]
415 .join("\n")
416 );
417 }
418
419 #[test]
420 fn chips_are_only_ever_true() {
421 // Small and healthy: no chip at all.
422 let small = run("small", NOW - 5_000, 3, 1);
423 let plain = render(&one(&small), 100, 1);
424 assert!(
425 !plain.contains('⚠') && !plain.contains("queued") && !plain.contains("failed"),
426 "{plain}"
427 );
428
429 // Large only at the threshold, a failure count only after a failure,
430 // queued only when the runtime reports waiting follow-ups.
431 let mut large = run("large", NOW - 5_000, LARGE_WORKFLOW_AGENTS, 0);
432 complete(&mut large, "large", 0, WorkflowRowStatus::Failed, None);
433 let busy = render(
434 &[WorkbarRun {
435 panel: &large,
436 queued: 2,
437 }],
438 120,
439 1,
440 );
441 assert!(busy.contains("0/25 done · 1 failed"), "{busy}");
442 assert!(busy.contains("⚠ Large workflow"), "{busy}");
443 assert!(busy.ends_with("· 2 queued"), "{busy}");
444 let under = run("under", NOW - 5_000, LARGE_WORKFLOW_AGENTS - 1, 0);
445 let under = render(&one(&under), 120, 1);
446 assert!(!under.contains("Large"), "{under}");
447 }
448
449 #[test]
450 fn one_failure_in_a_large_run_still_gets_a_bar_cell() {
451 let mut panel = run("large", NOW - 5_000, 100, 99);
452 complete(&mut panel, "large", 99, WorkflowRowStatus::Failed, None);
453 let shown = render(&one(&panel), 160, 1);
454 assert_eq!(shown.matches('×').count(), 1, "{shown}");
455 assert_eq!(shown.matches('█').count(), 19, "{shown}");
456 }
457
458 #[test]
459 fn many_runs_fold_into_a_more_row_that_names_the_key() {
460 let panels: Vec<WorkflowPanel> = (0..12)
461 .map(|index| run(&format!("wf-{index:02}"), NOW - 10_000, 8, index % 8))
462 .collect();
463 let runs: Vec<WorkbarRun<'_>> = panels
464 .iter()
465 .map(|panel| WorkbarRun { panel, queued: 0 })
466 .collect();
467 // Six run rows and the fold row; no rules.
468 assert_eq!(desired_rows(runs.len()), MAX_RUN_ROWS as u16 + 1);
469 let snapshot = render(&runs, 100, MAX_RUN_ROWS as u16 + 1);
470 let rows: Vec<&str> = snapshot.lines().collect();
471 assert_eq!(rows.len(), MAX_RUN_ROWS + 1);
472 assert_eq!(rows[MAX_RUN_ROWS], " +6 more · ↓ to manage");
473 }
474
475 #[test]
476 fn the_band_is_one_row_per_run_and_draws_no_rules() {
477 let live = run("Audit the parser", NOW - 30_000, 4, 1);
478 let done = settled("Port fixtures", WorkflowPanelLifecycle::Succeeded, 2, 2);
479 let runs = [
480 WorkbarRun {
481 panel: &live,
482 queued: 3,
483 },
484 WorkbarRun {
485 panel: &done,
486 queued: 0,
487 },
488 ];
489 assert_eq!(desired_rows(runs.len()), 2);
490 assert_eq!(desired_rows(0), 0);
491 let rows = buffer_rows(&render_band(&runs, 90, desired_rows(runs.len())));
492 assert_eq!(
493 rows,
494 vec![
495 " • Audit the parser █████░░░░░░░░░░░░░░░ 1/4 done 30s · 3 queued".to_string(),
496 " ✓ Port fixtures ████████████████████ 2/2 done 59s".to_string(),
497 ]
498 );
499 assert!(!rows.iter().any(|row| row.contains('─')), "{rows:?}");
500 }
501
502 /// NO_COLOR / 16-colour / ASCII terminals: every state still reads. Under
503 /// monochrome the text is unchanged and each state keeps its own mark;
504 /// at 16 colours the state inks stay apart; ASCII-safe marks stay apart
505 /// except failed/stopped, which their words tell apart.
506 #[test]
507 fn states_read_on_no_color_sixteen_colour_and_ascii_terminals() {
508 use crate::tui::color_compat::{adapt_cell_colors, adapt_cell_symbol_for_ascii};
509 use codewhale_palette::{ColorDepth, PaletteMode, ThemeId};
510 let theme = codewhale_palette::UI_THEME;
511 let running = run("running", NOW - 10_000, 4, 1);
512 let ok = settled("ok", WorkflowPanelLifecycle::Succeeded, 2, 2);
513 let gaps = settled("gaps", WorkflowPanelLifecycle::Degraded, 2, 1);
514 let failed = settled("failed", WorkflowPanelLifecycle::Failed, 2, 0);
515 let stopped = settled("stopped", WorkflowPanelLifecycle::Cancelled, 2, 0);
516 let panels = [&running, &ok, &gaps, &failed, &stopped];
517 let runs: Vec<WorkbarRun<'_>> = panels
518 .iter()
519 .map(|panel| WorkbarRun { panel, queued: 0 })
520 .collect();
521 let source = render_band(&runs, 100, desired_rows(runs.len()));
522 let text = buffer_rows(&source);
523 let marks: Vec<String> = text[0..5]
524 .iter()
525 .map(|row| row.chars().nth(1).expect("mark").to_string())
526 .collect();
527 for (index, mark) in marks.iter().enumerate() {
528 assert!(
529 !marks[index + 1..].contains(mark),
530 "state marks collide: {marks:?}"
531 );
532 }
533 assert!(text[2].contains("finished with gaps"), "{text:?}");
534 assert!(text[3].ends_with("failed"), "{text:?}");
535 assert!(text[4].contains("stopped"), "{text:?}");
536
537 let adapted = |depth: ColorDepth| {
538 let mut buf = source.clone();
539 for cell in buf.content.iter_mut() {
540 adapt_cell_colors(cell, depth, PaletteMode::Dark, ThemeId::Whale, &theme, None);
541 }
542 buf
543 };
544 let mono = adapted(ColorDepth::Monochrome);
545 assert_eq!(buffer_rows(&mono), text, "monochrome changes no text");
546 assert!(
547 mono.content.iter().all(|cell| {
548 cell.fg == ratatui::style::Color::Reset && cell.bg == ratatui::style::Color::Reset
549 }),
550 "monochrome paints no colour"
551 );
552 let ansi16 = adapted(ColorDepth::Ansi16);
553 let mark_ink: Vec<ratatui::style::Color> = (0..5).map(|y| ansi16[(1, y)].fg).collect();
554 for (index, ink) in mark_ink.iter().enumerate() {
555 assert!(
556 !mark_ink[index + 1..].contains(ink),
557 "16-colour state inks collide: {mark_ink:?}"
558 );
559 }
560
561 let mut ascii = source.clone();
562 for cell in ascii.content.iter_mut() {
563 adapt_cell_symbol_for_ascii(cell);
564 }
565 let ascii_rows = buffer_rows(&ascii);
566 assert!(
567 ascii_rows.iter().all(|row| row.is_ascii()),
568 "{ascii_rows:?}"
569 );
570 let ascii_marks: Vec<char> = ascii_rows[0..4]
571 .iter()
572 .map(|row| row.chars().nth(1).expect("mark"))
573 .collect();
574 for (index, mark) in ascii_marks.iter().enumerate() {
575 assert!(
576 !ascii_marks[index + 1..].contains(mark),
577 "ASCII marks collide: {ascii_marks:?}"
578 );
579 }
580 }
581
582 #[test]
583 fn localized_folded_counts_and_custom_failure_ink_survive_kit_adoption() {
584 use ratatui::style::Color;
585 let panels: Vec<_> = (0..8)
586 .map(|n| settled(&format!("run-{n}"), WorkflowPanelLifecycle::Failed, 2, 0))
587 .collect();
588 let runs: Vec<_> = panels
589 .iter()
590 .map(|panel| WorkbarRun { panel, queued: 0 })
591 .collect();
592 let mut theme = codewhale_palette::UI_THEME;
593 theme.error_fg = Color::Rgb(231, 12, 56);
594 let folded = lines(&runs, 100, 1, NOW, &theme, Locale::Ja);
595 let text = folded[0]
596 .spans
597 .iter()
598 .map(|span| span.content.as_ref())
599 .collect::<String>();
600 assert!(text.contains("ほか 8 件"), "{text}");
601 assert!(!text.contains("{count}"), "{text}");
602 let row = lines(&runs[..1], 100, 1, NOW, &theme, Locale::En);
603 assert_eq!(row[0].spans[1].style.fg, Some(theme.error_fg));
604 assert!(
605 row[0]
606 .spans
607 .iter()
608 .filter(|span| span.content.contains('×'))
609 .all(|span| { span.style.fg == Some(theme.error_fg) })
610 );
611 }
612
613 #[test]
614 fn seventy_five_agents_across_ten_runs_render_in_one_pass() {
615 let panels: Vec<WorkflowPanel> = (0..10)
616 .map(|index| run(&format!("wf-{index}"), NOW - 10_000, 8, 3))
617 .collect();
618 let runs: Vec<WorkbarRun<'_>> = panels
619 .iter()
620 .map(|panel| WorkbarRun { panel, queued: 0 })
621 .collect();
622 let started = std::time::Instant::now();
623 for _ in 0..100 {
624 let _ = lines(
625 &runs,
626 120,
627 MAX_RUN_ROWS + 1,
628 NOW,
629 &codewhale_palette::UI_THEME,
630 Locale::En,
631 );
632 }
633 assert!(
634 started.elapsed() < std::time::Duration::from_secs(1),
635 "100 frames of 10 runs × 8 agents took {:?}",
636 started.elapsed()
637 );
638 }
639 }
640
640 lines RUST