beady-eye 0.13.0

A tree of work in flight: bead graphs annotated with the live agents working them
Documentation
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
//! The row at the foot of the screen: the keys and every notice the view
//! carries.

use ratatui::text::Span;

use crate::model::snapshot::{ProviderState, Snapshot};
use crate::view::fitted::{columns, Fitted, GAP};
use crate::view::forest::Spine;
use crate::view::palette;
use crate::view::phrase;
use crate::view::row::WARNING;
use crate::view::{Notice, Said};

/// Everything the status bar has to say, in the order it should give it up.
///
/// All but the last are read off the snapshot behind this frame, and that is
/// the point rather than a convenience: the snapshot is also what `--json`
/// publishes, so a fact the foot draws from it is a fact a consumer of the
/// contract has too, and neither mouth can qualify a run the other does not.
/// What is left standing is this process's own — a channel that would not
/// open, a config that would not reload — which a run that prints one
/// snapshot and exits has neither of.
///
/// Consequence decides the order, not provenance: a provider nobody can
/// reach empties the agent column, which is what the reader came for, so it
/// is the last thing a narrow screen takes away, and a session nobody can
/// reach empties that session's part of it. A guessed project name outranks
/// the standing ones because it is half of every key on the screen, where a
/// channel that would not open costs freshness alone.
///
/// A provider nobody installed says nothing here. The reader has lost
/// nothing — they never had an agent column — and a warning about a program
/// they have never heard of is a warning they cannot act on.
pub(super) fn notices(snapshot: &Snapshot, standing: &[Notice]) -> Vec<Notice> {
    let collected = match snapshot.agents.state {
        ProviderState::Answering | ProviderState::Absent => None,
        ProviderState::NotAnswering => Some(Notice::AgentsUnknown),
    };
    let unanswered = snapshot
        .agents
        .unanswered()
        .map(|session| Notice::SessionUnanswered(session.to_string()));
    // One line however many projects were guessed, because the remedy is one
    // line in a shell profile and saying it per project would say it once and
    // repeat it.
    let guessed =
        (!snapshot.projects_named_without_git.is_empty()).then_some(Notice::ProjectNamedWithoutGit);

    collected
        .into_iter()
        .chain(unanswered)
        .chain(guessed)
        .chain(standing.iter().cloned())
        .collect()
}

/// The row at the foot of the screen: the keys and every notice the view
/// carries.
///
/// The notices are drawn first and yield last: keys can be rediscovered, and
/// a fact that is silently absent from the one row a reader can neither fold
/// nor scroll away from is a fact they will never learn. Where the screen is
/// too narrow even for those, they yield from the end, so the caller's order
/// is the order they are given up in.
///
/// `keys` is the row of keys and every shorter form of it the caller will
/// stand behind, fullest first. The row says the fullest of them that fits,
/// which is what a notice does with its own words: a caller handing one form
/// has a row that goes whole or not at all, and a caller handing several has
/// one that narrows instead of vanishing.
///
/// How fresh the rows are is not here. It was, while it was one claim about
/// the whole screen; it is now a project's own fact, said beside the
/// project's name where it is exact.
///
/// `said` is what the reader's last keystroke came to, where it came to
/// anything they cannot already see. It is the first thing the row gives up
/// and it goes whole or not at all: half an id names nothing, and the keys
/// were there before the reader pressed anything, so they are never the thing
/// that moves to make room.
///
/// `prompt` is what they have typed into the search prompt, while one is up,
/// and it takes the row for as long as it is there. Nothing else is said
/// beside it: a reader typing is owed their own characters and the column
/// they end at, and one keystroke — Esc, Enter, a click — puts the row back.
///
/// `spine` is the rule opening the fold default where the selection is,
/// and it stands for as long as the reader leaves it in force. It is said
/// where the answer is said, and an answer takes the place while it is up:
/// both are the screen telling the reader what is so, the answer is the
/// newer of the two, and a rule they set is still in force a keystroke
/// later.
///
/// `width` is what this row will be drawn into. Choosing which words to say
/// is a different job from cutting the words chosen, and only the first of
/// them belongs here.
///
/// Nothing here knows what produced a notice. That is the point: a snapshot
/// and this process both reach the screen through the same list, and the next
/// thing that has something to say joins them by being one.
pub(super) fn status_bar(
    notices: &[Notice],
    said: Option<&Said>,
    prompt: Option<&str>,
    keys: &[String],
    spine: Spine,
    width: usize,
) -> Fitted {
    if let Some(typed) = prompt {
        return Fitted::new(
            vec![Span::raw(phrase::prompt(typed))],
            Vec::new(),
            Vec::new(),
        );
    }

    let answer: Vec<Span<'static>> = said
        .map(phrase::said)
        .or_else(|| phrase::spine(spine).map(str::to_string))
        .map(Span::raw)
        .into_iter()
        .collect();

    if notices.is_empty() {
        return Fitted::new(vec![Span::raw(fullest(keys, width))], Vec::new(), answer)
            .state_or_nothing();
    }

    let warning = warnings(notices, width);
    let room = width.saturating_sub(columns(&[Span::raw(warning.clone())]) + GAP);
    Fitted::new(
        vec![Span::styled(warning, palette::ATTENTION)],
        answer,
        vec![Span::raw(fullest(keys, room))],
    )
    .title_or_nothing()
    .state_or_nothing()
}

/// The fullest of `forms` that `room` holds, or the shortest of them where it
/// holds none — which the row then gives up whole, since half a key name
/// presses nothing.
fn fullest(forms: &[String], room: usize) -> String {
    forms
        .iter()
        .find(|form| columns(&[Span::raw((*form).clone())]) <= room)
        .or_else(|| forms.last())
        .cloned()
        .unwrap_or_default()
}

/// Every notice the foot carries, in the fullest words that let all of them
/// still be said.
///
/// Words are given up before facts are, and from the end, which is the order
/// the notices themselves are given up in: the notice the caller put first
/// keeps its full phrase longest, because it is the one that costs the reader
/// most. Neither phrase fits in full on a forty-column screen, so there they
/// all speak briefly and all of them are still there.
///
/// Being cut is the one thing a notice must not be. The mark a cut leaves is
/// the mark any long line gets, so a severed warning reads as a sentence that
/// ran out of room rather than as a fact the reader has lost — and a foot with
/// two notices on it can be cut before the second one has begun.
fn warnings(notices: &[Notice], width: usize) -> String {
    let mut words = notices.iter().map(phrase::notice).collect::<Vec<_>>();

    for (at, notice) in notices.iter().enumerate().rev() {
        if columns(&[Span::raw(marked(&words))]) <= width {
            break;
        }
        words[at] = phrase::brief_notice(notice);
    }

    marked(&words)
}

/// The notices as one run of text, each behind the mark that says it is a
/// warning and clear of the one before it.
fn marked(words: &[String]) -> String {
    words
        .iter()
        .map(|said| format!("{WARNING} {said}"))
        .collect::<Vec<_>>()
        .join(&" ".repeat(GAP))
}

#[cfg(test)]
mod tests {
    use super::*;
    use pretty_assertions::assert_eq;

    use crate::config::Scope;
    use crate::model::snapshot::{a_provider, Filter, ProviderState as State, A_PROVIDER};
    use crate::view::draw::tests::*;
    use crate::view::Action;

    /// A frame's snapshot with the provider a test is about and nothing else
    /// to say.
    fn behind_a_frame(agents: crate::model::snapshot::AgentProvider) -> Snapshot {
        Snapshot {
            agents,
            ..nothing_to_qualify()
        }
    }

    /// A snapshot from a run in which everything answered and no name was
    /// guessed — the state every notice here is measured against.
    fn nothing_to_qualify() -> Snapshot {
        Snapshot::awaiting(
            Vec::new(),
            Vec::new(),
            A_PROVIDER,
            Scope::Everything,
            Filter::LiveAgents,
            "2026-08-30T12:00:00Z".parse().expect("the instant parses"),
        )
    }

    /// A guessed project name is the snapshot's to report, and the same field
    /// `--json` publishes is what the foot reads: one fact, so a screen and a
    /// printed snapshot of the same moment cannot disagree about it.
    #[test]
    fn a_project_named_without_git_is_said_at_the_foot_from_the_snapshot() {
        let guessed = Snapshot {
            projects_named_without_git: vec!["dunwich".to_string()],
            ..nothing_to_qualify()
        };

        assert_eq!(
            notices(&guessed, &[]),
            vec![Notice::ProjectNamedWithoutGit],
            "the foot did not read the guess off the snapshot"
        );
        assert_eq!(
            notices(&nothing_to_qualify(), &[]),
            Vec::new(),
            "a run that guessed no name was warned about one"
        );
    }

    /// Two projects guessed is still one remedy — a line in a shell profile —
    /// so the foot says it once rather than once per project.
    #[test]
    fn several_guessed_names_are_one_notice() {
        let guessed = Snapshot {
            projects_named_without_git: vec!["dunwich".to_string(), "ferry".to_string()],
            ..nothing_to_qualify()
        };

        assert_eq!(notices(&guessed, &[]), vec![Notice::ProjectNamedWithoutGit]);
    }

    /// A guessed name costs the reader more than a channel that would not
    /// open — it is half of every key on the screen — so a narrowing foot
    /// gives up the channel first.
    #[test]
    fn a_guessed_name_outranks_what_this_process_settled() {
        let guessed = Snapshot {
            projects_named_without_git: vec!["dunwich".to_string()],
            ..behind_a_frame(a_provider(State::NotAnswering))
        };

        assert_eq!(
            notices(&guessed, &[Notice::NoInboundChannel]),
            vec![
                Notice::AgentsUnknown,
                Notice::ProjectNamedWithoutGit,
                Notice::NoInboundChannel
            ]
        );
    }

    // ---- the key bar -----------------------------------------------------

    /// What the row says is the loop's to decide; the foot's job is to put it
    /// on screen whole where there is room for it.
    #[test]
    fn the_foot_of_the_screen_shows_the_keys_it_is_handed() {
        let drawn = Painted::of(
            status_bar(&[], None, None, &a_key_row(), Spine::EveryCopy, 60),
            60,
            1,
        )
        .rows();

        assert!(drawn[0].starts_with(A_KEY_ROW), "{drawn:?}");
    }

    /// With no herdr there is no agent on any row, and a screen that only
    /// stopped showing them would read as a fleet with nobody working in it.
    /// It goes at the foot because that is the one row that cannot be folded
    /// or scrolled away.
    #[test]
    fn a_herdr_that_could_not_be_reached_is_said_where_nothing_can_hide_it() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                90,
            ),
            90,
            1,
        )
        .rows();

        says(
            &drawn[0],
            "no herdr session · which agents are alive is unknown",
        );
    }

    /// The bead this row was built for: a `bdi` that could not open its
    /// inbound socket is told nothing when a project changes, so what is on
    /// screen is only as fresh as the last poll. Nothing above the foot could
    /// show that — no row is wrong — so the foot is the only place it can go.
    #[test]
    fn a_bdi_nothing_can_reach_says_so_for_the_life_of_the_session() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::NoInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                90,
            ),
            90,
            1,
        )
        .rows();

        says(
            &drawn[0],
            "nothing can tell bdi a project changed · every project is polled instead",
        );
    }

    /// Two notices are two facts and the reader needs both: neither one
    /// implies the other, and a foot that showed only the first would leave
    /// the second unsaid for the whole session.
    #[test]
    fn a_foot_with_room_says_every_notice_it_is_given() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown, Notice::NoInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                200,
            ),
            200,
            1,
        )
        .rows();

        for words in [
            "no herdr session · which agents are alive is unknown",
            "nothing can tell bdi a project changed · every project is polled instead",
        ] {
            says(&drawn[0], words);
        }
    }

    /// The order the caller gives is the order the foot gives up, so a screen
    /// with room for one full phrase keeps it for the notice that costs the
    /// reader most. What the other gives up is its words, not its place.
    #[test]
    fn a_narrow_foot_gives_up_the_last_notices_words_first() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown, Notice::NoInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                80,
            ),
            80,
            1,
        )
        .rows();

        says(
            &drawn[0],
            "no herdr session · which agents are alive is unknown",
        );
        says(&drawn[0], "polled, not reported");
    }

    /// The bead window's row as the loop hands it to the foot: the forms it
    /// will stand behind, each one the last key of the one before taken off.
    fn a_row_that_can_say_less() -> Vec<String> {
        [
            "Esc back   ? keys   Tab related   y id",
            "Esc back   ? keys   Tab related",
            "Esc back   ? keys",
            "Esc back",
        ]
        .iter()
        .map(|form| (*form).to_string())
        .collect()
    }

    /// The bead this was written for. A window holding four fifths of the
    /// screen leaves the reader nothing to look at, so the row that says how
    /// to leave it must not be what a notice takes away. Eighty columns is a
    /// supported width and a machine with no herdr raises this notice on
    /// every frame.
    #[test]
    fn a_row_that_can_say_less_says_less_rather_than_going() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_row_that_can_say_less(),
                Spine::EveryCopy,
                80,
            ),
            80,
            1,
        )
        .rows();

        assert!(
            drawn[0].trim_end().ends_with("Esc back   ? keys"),
            "{drawn:?}"
        );
    }

    /// Giving up keys is not cutting them: a row narrowed to its last form
    /// and still too wide for the columns left goes whole, like any other.
    #[test]
    fn a_row_too_narrow_for_even_its_shortest_form_draws_none_of_it() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_row_that_can_say_less(),
                Spine::EveryCopy,
                60,
            ),
            60,
            1,
        )
        .rows();

        assert_eq!(
            drawn[0].trim_end(),
            "\u{26a0} no herdr session \u{b7} which agents are alive is unknown"
        );
    }

    // ---- what the reader just copied ---------------------------------------

    /// The keys stay where they are and the id joins them: a reader looking
    /// for the legend must not find it moved by a key they pressed a moment
    /// ago.
    #[test]
    fn a_copied_id_is_said_after_the_keys_where_nothing_is_wrong() {
        let drawn = Painted::of(
            status_bar(
                &[],
                Some(&Said::Copied("grv-1".to_string())),
                None,
                &a_key_row(),
                Spine::EveryCopy,
                80,
            ),
            80,
            1,
        )
        .rows();

        assert!(drawn[0].starts_with(A_KEY_ROW), "{drawn:?}");
        assert!(drawn[0].trim_end().ends_with("copied grv-1"), "{drawn:?}");
    }

    /// Beside a notice the keys keep their place at the end of the row, and
    /// the id goes between.
    #[test]
    fn a_copied_id_is_said_between_a_notice_and_the_keys() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                Some(&Said::Copied("grv-1".to_string())),
                None,
                &a_key_row(),
                Spine::EveryCopy,
                120,
            ),
            120,
            1,
        )
        .rows();

        assert_eq!(
            drawn[0].trim_end(),
            format!(
                "⚠ no herdr session · which agents are alive is unknown  copied grv-1{}{A_KEY_ROW}",
                " ".repeat(120 - 54 - 2 - 12 - A_KEY_ROW.chars().count())
            )
        );
    }

    /// Half an id pastes as nothing anyone asked for, so a row with no room
    /// for the whole of it says none of it — and keeps the keys, which were
    /// there before the reader pressed anything.
    #[test]
    fn a_copied_id_the_row_has_no_room_for_is_dropped_whole_and_the_keys_stay() {
        let drawn = Painted::of(
            status_bar(
                &[],
                Some(&Said::Copied("grv-1".to_string())),
                None,
                &a_key_row(),
                Spine::EveryCopy,
                50,
            ),
            50,
            1,
        )
        .rows();

        assert_eq!(drawn[0].trim_end(), A_KEY_ROW);
    }

    // ---- how fresh the screen is ------------------------------------------

    /// `bdi-7ao.27`: the foot spoke for every project at once, so a refresh
    /// naming one project said the whole screen was being read, and a
    /// resting foot had to quote the oldest read on it to stay true. It is a
    /// project's own fact and it is now said on the project's own line.
    #[test]
    fn the_foot_says_nothing_about_how_fresh_the_rows_above_it_are() {
        let forest = opened(&snapshot(
            vec![grove(1)],
            Vec::new(),
            ProviderState::Answering,
        ));

        let foot = frame_of(&forest, 74, 4).rows().remove(3);

        assert_eq!(foot.trim_end(), A_KEY_ROW);
    }

    /// The bead this was written for. On the narrowest supported screen
    /// neither phrase fits in full, so a foot that could only cut told the
    /// reader nothing: `NoHerdr` was severed mid-sentence and `NoInboundChannel`
    /// never began. The mark a cut leaves is the mark any long line gets, so
    /// there was nothing on screen to say either fact had been lost.
    #[test]
    fn the_narrowest_screen_still_says_the_view_is_polled() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown, Notice::NoInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                40,
            ),
            40,
            1,
        )
        .rows();

        assert_eq!(drawn[0], "⚠ agents unknown  ⚠ polled, not reported");
    }

    /// A second `bdi` on a machine whose herdr is well: one notice, and in
    /// full it is wider than a side-by-side pane. The words a cut took were
    /// the ones that say what it costs the reader, because a cut takes the
    /// end.
    #[test]
    fn a_lone_notice_too_wide_for_the_row_is_said_briefly() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::NoInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                60,
            ),
            60,
            1,
        )
        .rows();

        assert!(drawn[0].starts_with("⚠ polled, not reported"), "{drawn:?}");
    }

    /// A notice is drawn in the colour that asks to be looked at, and saying
    /// it in fewer words does not make it something else.
    #[test]
    fn a_notice_said_briefly_is_still_painted_as_a_warning() {
        let painted = Painted::of(
            status_bar(
                &[Notice::NoInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                60,
            ),
            60,
            1,
        )
        .row(0);

        assert!(
            painted
                .iter()
                .any(|run| run.said.contains("polled, not reported")
                    && run.style.fg == palette::ATTENTION.fg),
            "{painted:?}"
        );
    }

    /// `bdi-7ao.61`: measured on this machine, a `bdi` refused the socket
    /// drew *nothing can tell bdi a project changed · every project is polled
    /// instead* for an hour while a finished mutation run held the socket,
    /// and there was no way to learn that from the screen. The cause is what
    /// was missing, and it is the only one of the three a reader can put
    /// right.
    #[test]
    fn a_socket_another_bdi_holds_says_that_rather_than_only_what_it_cost() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AnotherBdiHadTheInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                100,
            ),
            100,
            1,
        )
        .rows();

        says(
            &drawn[0],
            "another bdi held the inbound channel · every project is polled instead",
        );
    }

    /// The cause is the half a reader can act on, so it survives the width
    /// that takes the words around it. A brief notice that gave it up would
    /// say no more than the notice this bead replaced.
    #[test]
    fn the_narrowest_screen_still_says_another_bdi_took_the_channel() {
        let drawn = Painted::of(
            status_bar(
                &[
                    Notice::AgentsUnknown,
                    Notice::AnotherBdiHadTheInboundChannel,
                ],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                40,
            ),
            40,
            1,
        )
        .rows();

        assert_eq!(
            drawn[0].trim_end(),
            "⚠ agents unknown  ⚠ another bdi had it"
        );
    }

    /// A notice nobody looks at is a notice nobody has, and this one is
    /// asking the reader to go and close something.
    #[test]
    fn a_socket_another_bdi_holds_is_painted_as_a_warning() {
        let painted = Painted::of(
            status_bar(
                &[Notice::AnotherBdiHadTheInboundChannel],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                100,
            ),
            100,
            1,
        )
        .row(0);

        assert!(
            painted.iter().any(
                |run| run.said.contains("another bdi") && run.style.fg == palette::ATTENTION.fg
            ),
            "{painted:?}"
        );
    }

    // ---- which rule opens the spine ----------------------------------------

    /// The rule the forest starts under opens every way down to a bead, which
    /// is the screen this program drew before there was a rule to name. There
    /// is nothing in front of the reader to account for, so the foot accounts
    /// for nothing and the row stays the keys.
    #[test]
    fn the_rule_the_forest_starts_under_is_not_named() {
        let drawn = Painted::of(
            status_bar(&[], None, None, &a_key_row(), Spine::EveryCopy, 100),
            100,
            1,
        )
        .rows();

        assert_eq!(drawn[0].trim_end(), A_KEY_ROW);
    }

    /// A one-copy rule draws a bead in one of the places it stands and rests
    /// the others shut. That screen lasts for as long as the reader leaves
    /// the rule in force, so what accounts for it stands on the row rather
    /// than passing like an answer.
    #[test]
    fn a_rule_the_reader_put_in_force_is_said_at_the_foot() {
        let drawn = Painted::of(
            status_bar(&[], None, None, &a_key_row(), Spine::Deepest, 100),
            100,
            1,
        )
        .rows();

        assert!(drawn[0].starts_with(A_KEY_ROW), "{drawn:?}");
        says(&drawn[0], "opening the deepest copy of each bead");
    }

    /// The foot reads the rule off the forest rather than being handed one,
    /// so the words on the row are the rule the screen above them was drawn
    /// under.
    #[test]
    fn the_foot_names_the_rule_the_forest_was_drawn_under() {
        let mut forest = opened(&snapshot(
            vec![grove(1)],
            Vec::new(),
            ProviderState::Answering,
        ));
        forest.apply(Action::CycleSpineForest);

        let foot = frame_of(&forest, 100, 4).rows().remove(3);

        says(
            &foot,
            phrase::spine(forest.spine()).expect("a rule a reader can reach is named"),
        );
    }

    /// Every rule a reader can reach accounts for its own screen. Two of them
    /// sharing an account would leave a reader who cycled between them with
    /// nothing on the row to tell which one they had stopped on.
    #[test]
    fn each_rule_the_reader_can_reach_is_named_in_its_own_words() {
        let mut said: Vec<&str> = Vec::new();
        let reachable = Spine::EVERY
            .iter()
            .copied()
            .filter(|rule| *rule != Spine::default());
        for rule in reachable {
            let words = phrase::spine(rule).unwrap_or_else(|| panic!("{rule:?} is named"));
            let drawn =
                Painted::of(status_bar(&[], None, None, &a_key_row(), rule, 100), 100, 1).rows();

            says(&drawn[0], words);
            said.push(words);
        }

        let every = said.len();
        said.sort_unstable();
        said.dedup();
        assert_eq!(said.len(), every, "two rules share an account: {said:?}");
    }

    /// Both the answer and the rule are the screen telling the reader what is
    /// so, and the answer is the newer of the two. The rule is still in force
    /// underneath it and comes back with the reader's next key.
    #[test]
    fn what_a_keystroke_came_to_takes_the_rules_place_while_it_is_up() {
        let drawn = Painted::of(
            status_bar(
                &[],
                Some(&Said::Copied("dun-1".to_string())),
                None,
                &a_key_row(),
                Spine::Deepest,
                100,
            ),
            100,
            1,
        )
        .rows();

        assert!(drawn[0].trim_end().ends_with("copied dun-1"), "{drawn:?}");
        assert!(
            !drawn[0].contains("deepest"),
            "the rule and the answer were both said: {drawn:?}"
        );
    }

    /// A notice and a rule are two different things: one is what this run
    /// cannot do and the other is what the reader asked for. The notice keeps
    /// the start of the row and the paint that asks to be looked at, the keys
    /// keep the end, and the rule goes between them where nothing is wrong.
    #[test]
    fn a_rule_beside_a_notice_is_said_between_it_and_the_keys() {
        let painted = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_key_row(),
                Spine::Deepest,
                150,
            ),
            150,
            1,
        );
        let drawn = painted.rows();

        assert_eq!(
            drawn[0].trim_end(),
            format!(
                "⚠ no herdr session · which agents are alive is unknown  \
                 opening the deepest copy of each bead{}{A_KEY_ROW}",
                " ".repeat(150 - 54 - 2 - 37 - A_KEY_ROW.chars().count())
            )
        );
        assert!(
            painted
                .row(0)
                .iter()
                .any(|run| run.said.contains("deepest") && run.style.fg != palette::ATTENTION.fg),
            "a rule the reader asked for was painted as a warning: {:?}",
            painted.row(0)
        );
    }

    /// Half a sentence about the fold default accounts for nothing, so a row
    /// with no room for the whole of it says none of it — and the keys, which
    /// were there before the reader pressed anything, stay.
    #[test]
    fn a_rule_the_row_has_no_room_for_is_dropped_whole_and_the_keys_stay() {
        let row = |width: usize| {
            Painted::of(
                status_bar(&[], None, None, &a_key_row(), Spine::Deepest, width),
                width as u16,
                1,
            )
            .rows()
            .remove(0)
        };
        let rule = "opening the deepest copy of each bead";
        let fits = A_KEY_ROW.chars().count() + GAP + rule.chars().count();

        assert_eq!(row(fits), format!("{A_KEY_ROW}  {rule}"));
        assert_eq!(row(fits - 1).trim_end(), A_KEY_ROW);
    }

    /// A frame draws what the snapshot behind it found and what the session
    /// settled at startup through one list, and the snapshot's go first
    /// because a herdr nobody can reach empties the agent column.
    #[test]
    fn the_snapshots_notice_outranks_the_sessions() {
        assert_eq!(
            notices(
                &behind_a_frame(a_provider(ProviderState::NotAnswering)),
                &[Notice::NoInboundChannel]
            ),
            vec![Notice::AgentsUnknown, Notice::NoInboundChannel]
        );
    }

    /// A provider nobody installed is not a finding, so it costs the foot
    /// nothing — while a provider that is installed and will not answer costs
    /// it the notice above. The two states put the same empty agent column on
    /// the screen and only one of them is something the reader lost.
    #[test]
    fn a_provider_that_was_never_installed_is_not_warned_about() {
        assert_eq!(
            notices(
                &behind_a_frame(a_provider(ProviderState::Absent)),
                &[Notice::NoInboundChannel]
            ),
            vec![Notice::NoInboundChannel]
        );
        assert_eq!(
            notices(&behind_a_frame(a_provider(ProviderState::Absent)), &[]),
            Vec::new()
        );
    }

    /// A session fact reaches the foot whether or not the collection behind
    /// the frame found anything to say — the two travel by the same road and
    /// neither depends on the other.
    #[test]
    fn a_session_notice_stands_alone_where_the_snapshot_is_well() {
        assert_eq!(
            notices(
                &behind_a_frame(a_provider(ProviderState::Answering)),
                &[Notice::NoInboundChannel]
            ),
            vec![Notice::NoInboundChannel]
        );
    }

    #[test]
    fn a_session_with_nothing_wrong_leaves_the_foot_to_the_keys() {
        assert_eq!(
            notices(&behind_a_frame(a_provider(ProviderState::Answering)), &[]),
            Vec::new()
        );
    }

    /// Keys can be rediscovered; a herdr that is silently absent cannot. So on
    /// a screen too narrow for both, the keys are what gives way.
    #[test]
    fn a_narrow_foot_gives_up_the_keys_before_the_missing_herdr() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                60,
            ),
            60,
            1,
        )
        .rows();

        assert!(drawn[0].contains("no herdr session"), "{drawn:?}");
        assert_eq!(drawn[0].chars().count(), 60);
    }

    /// The bead this was written for. Measured at 60 columns, the foot drew
    /// `Ent…` after the notice: four columns saying a key row exists, which
    /// the reader could already see. Half a key name presses nothing, so a
    /// row that cannot be drawn whole is not drawn.
    #[test]
    fn a_foot_too_narrow_for_the_whole_key_row_draws_none_of_it() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                60,
            ),
            60,
            1,
        )
        .rows();

        assert_eq!(
            drawn[0].trim_end(),
            "⚠ no herdr session · which agents are alive is unknown"
        );
    }

    /// On the narrowest screen the brief notice leaves a couple of dozen
    /// columns over, which was room for `Enter focus   a all  …` and nothing
    /// a reader could press.
    #[test]
    fn the_narrowest_screen_draws_no_part_of_the_key_row_beside_a_notice() {
        let drawn = Painted::of(
            status_bar(
                &[Notice::AgentsUnknown],
                None,
                None,
                &a_key_row(),
                Spine::EveryCopy,
                40,
            ),
            40,
            1,
        )
        .rows();

        assert_eq!(drawn[0].trim_end(), "⚠ agents unknown");
    }

    /// Whole where it fits, and the column under that is the whole difference.
    #[test]
    fn the_key_row_is_drawn_whole_at_the_first_width_that_holds_it() {
        let notice = "⚠ no herdr session · which agents are alive is unknown";
        let fits = notice.chars().count() + GAP + A_KEY_ROW.chars().count();
        let row = |width: usize| {
            Painted::of(
                status_bar(
                    &[Notice::AgentsUnknown],
                    None,
                    None,
                    &a_key_row(),
                    Spine::EveryCopy,
                    width,
                ),
                width as u16,
                1,
            )
            .rows()
            .remove(0)
        };

        assert_eq!(row(fits), format!("{notice}  {A_KEY_ROW}"));
        assert_eq!(row(fits - 1).trim_end(), notice);
    }
}