gunk-dev/the-valley

pending.go

source701f0334f1eamain's published tip history
23.6 KiB
1// valley pending: what is waiting to land, for a person to read.
2//
3// It prints four sections, in this order. ready holds the ready changes
4// whose active version has not landed, by the first two landing rules
5// (inventory.go), and that wait on an approval. approved holds those that
6// have an integration request at the active version's head. They wait on
7// their checks and the integrator, so each is one line: its name and
8// version, its title, and with --checks its check state. A request that
9// names an earlier head whose approval carries to the active version is
10// not counted: judging carry needs the delta between the two heads and
11// the policy's carry mode, so a version approved only by carry is listed
12// under ready. A stack that holds a ready change or a draft is drawn in
13// full wherever its top is, its approved layers marked "(approved)".
14// branches holds each branch on origin, other than main,
15// that main does not reach, that is no change's active head, and that no
16// landed version's head reaches. drafts
17// holds the changes whose record says they are drafts. When no ready
18// change is at the top of a stack, one line says so in place of ready,
19// and says where any ready change inside another section's stack is.
20//
21// Each entry is a block. Its first line is its name, with the age and
22// author of its head: the handle and version of a change, the name of a
23// branch, and for a draft its handle and version on its branch. The lines
24// indented under it give its title, then the commits and the diff the
25// entry adds to its base:
26//
27// act-on-a-change-by-handle-key-its-1902807a 9 hours ago · alice-agent-vm
28// change: share the record bounds and the c-<change ID> request name
29// 10 commits · 31 files +2412 −404
30// approving it lands the 2 below too
31// ├ find-changes-across-repos-valley-changes-1e788c4f 10 hours ago · alice-…
32// │ valley: changes --json and pending by handle, across a host's projects
33// │ 9 commits · 17 files +2701 −137
34// └ a-draft-state-valley-unready-and-what-56ed34ac 12 hours ago · alice-ag…
35// change: read a draft as a third state
36// 14 commits · 20 files +1207 −219
37//
38// A change's title is its record's, for the active version. A branch's
39// title is the subject of its first own commit: the oldest commit on its
40// first-parent line that its base does not hold. When a knot in the plan
41// graph links a change, the first knot's ID follows the title, as
42// "<title> · oc-6335749" (does.go).
43//
44// An entry's base is the nearest other entry its head strictly contains,
45// or main when there is none. That is the ancestry includes reads
46// (inventory.go). Its commits and diff are counted from the nearer of its
47// base and the head of a landed version its head contains: a landed
48// version's commits are not on main, since it landed as one new commit,
49// and its content is. A stack is an entry that no other entry contains, the
50// top, then every entry the top contains, as one list at one indentation,
51// however deep the stack is. Each entry is listed before the entries it
52// contains. The top's block says how many entries approving it lands with
53// it. Each entry is on the entry listed right after it, and says
54// "on <base>" where it is not, as at a fork, where two entries are on one
55// base and the base is listed under only one of them. An entry the top
56// does not contain is never listed under it. A stack is printed in the
57// section of its top, and a listed entry from another section says which
58// it is in.
59//
60// A change may say more, each on a line of its own. includes <handle>
61// names a change its head contains that is not an entry here, such as a
62// withdrawn one. uncertain says the active version may have landed without
63// its evidence being stored. With --checks, it says how many checks the
64// policy requires of the change, by cost, and for a ready change how many
65// of its required checks passed, failed and are pending, as valley
66// changes --checks lists them (versionchecks.go), naming those that
67// failed: "checks: 18 passed, 1 failed (valley-request)". When the host's
68// worker telemetry holds the version's builds, the line goes on with what
69// they cost and the checks that grew against their recent cost on the
70// same capacity
71// (checkcost.go): "checks: 21 passed in 9m10s (eval 24s); worker-e2e
72// 431s, +68s against its recent 363s". --json then carries the same
73// checks objects.
74//
75// Within a section, the stack with the latest commit comes first, and
76// within a stack the entry with the latest commit does. Every line fits
77// stdout's terminal, or 80 columns when stdout is no terminal or does not
78// know its width. A title or an author is cut short with …; a handle or a
79// branch never is. On a terminal, names are bold, unless NO_COLOR is set.
80//
81// With --json it prints valley-pending/v1: valley-changes/v1's shape, with
82// the pending changes alone in changes, each marked approved or not, the
83// drafts in an array of their own, drafts, and the same branches.
84
85package main
86
87import (
88 "fmt"
89 "io"
90 "os"
91 "os/exec"
92 "sort"
93 "strconv"
94 "strings"
95 "unicode"
96
97 "the-valley/change"
98 "the-valley/rebase"
99)
100
101// pendingChange is a ready change whose active version has not landed.
102func pendingChange(s *snapshot, n recorded) bool {
103 return n.record.State == change.Ready && !s.isLanded(n.id, n.record.ActiveVersion())
104}
105
106// approvedVersion reports whether a ready change's active version has an
107// integration request at its head. That is the simple rule: the integrator
108// also accepts a request that names an earlier head whose approval carries
109// to this version, which needs the delta between the two and the policy's
110// carry mode. A version approved only by carry is not counted here, so
111// valley pending lists it with the changes awaiting approval.
112func (s *snapshot) approvedVersion(id string, r *change.Record) bool {
113 return r.State == change.Ready && s.request(id, r.ActiveVersion()) != nil
114}
115
116// unlanded is a change in any state whose active version has not landed:
117// the changes a pending change may include.
118func unlanded(s *snapshot, n recorded) bool {
119 return !s.isLanded(n.id, n.record.ActiveVersion())
120}
121
122func isDraft(_ *snapshot, n recorded) bool {
123 return n.record.State == change.Draft
124}
125
126// pendingView is a repository as valley-pending/v1 writes it: the pending
127// changes in changes and the drafts in drafts, each with includes among
128// the changes that have not landed.
129func (l listed) pendingView(h handleMap) jsonRepo {
130 r := l.repoView(h, pendingChange, unlanded)
131 if l.err == nil {
132 for i, c := range r.Changes {
133 approved := c.Versions[c.Active-1].Request != nil
134 r.Changes[i].Approved = &approved
135 }
136 }
137 drafts := []jsonChange{}
138 if l.err == nil {
139 drafts = l.repoView(h, isDraft, unlanded).Changes
140 }
141 r.Drafts = &drafts
142 return r
143}
144
145func runPending(g git, args []string, stdout, stderr io.Writer) error {
146 l, err := parseListing("pending", args, true)
147 if err != nil {
148 return err
149 }
150 list, host, err := sources(g, l, stderr)
151 if err != nil {
152 return err
153 }
154 repos := readSources(list, newVerifier())
155 readKnots(repos, l.verbose, stderr)
156 h := handles(repos)
157 writeHandleCache(g, repos, h)
158 defer warnUnverified(repos, stderr)
159 if l.asJSON {
160 doc := jsonChanges{Schema: pendingSchema, Host: host, Repos: []jsonRepo{}}
161 c := newCosts()
162 for _, r := range repos {
163 view := r.pendingView(h)
164 if l.checks {
165 r.addChecks(&view, c, stderr)
166 }
167 utf8Branches(&view, stderr)
168 doc.Repos = append(doc.Repos, view)
169 }
170 return writeDocument(stdout, doc)
171 }
172 t := terminalOf(stdout)
173 c := newCosts()
174 for i, r := range repos {
175 if i > 0 {
176 fmt.Fprintln(stdout)
177 }
178 writePending(r, h, l, c, stdout, stderr, len(repos) > 1 || l.all || l.repo != "", t)
179 }
180 return nil
181}
182
183// sections are valley pending's sections, in the order they are printed,
184// each with the word a nested entry from it is marked with.
185var sections = []struct{ name, kind string }{
186 {"ready", "ready"}, {"approved", "approved"}, {"branches", "branch"}, {"drafts", "draft"},
187}
188
189// entry is one block of valley pending: a ready change, a branch no record
190// is on, or a draft.
191type entry struct {
192 section string
193 name string // what the block's first line names
194 ref string // what the entry is typed as: its handle, or its branch
195 head string // the head commit
196 title string // the record's title; for a branch, read by measure
197 knot string // ID of the first knot that links the change (does.go)
198 includes []string // what includes names that is no entry here
199 notes []string // uncertain and checks
200 checks string // the check state line of a change, with --checks
201
202 when int64 // the head's commit time
203 age, author string
204 layer string // the commits and the diff it adds to its base
205
206 parent *entry // the entry it is listed under, if any
207 kids []*entry // the entries nested right under it
208 base *entry // nil for main
209 inside []*entry // every entry whose head strictly contains its own
210 below []*entry // for the top of a stack, every entry listed under it
211 latest int64 // for the top of a stack, the latest commit time in it
212}
213
214// writePending prints one repository's entries, section by section.
215// Several repositories are each headed by their name.
216func writePending(r listed, h handleMap, l listing, c *costs, w, stderr io.Writer, headed bool, t terminal) {
217 p := func(format string, args ...any) { fmt.Fprintf(w, format, args...) }
218 if r.err != nil {
219 p("%s: %v\n", r.name, r.err)
220 return
221 }
222 if headed {
223 p("%s\n%s\n", r.name, strings.Repeat("─", min(columns(r.name), t.width)))
224 }
225 view := r.pendingView(h)
226 if l.checks {
227 r.addChecks(&view, c, stderr)
228 }
229 all := r.entries(view, h, l)
230 tops := r.snap.stack(all)
231 gap := false
232 for _, sec := range sections {
233 var here []*entry
234 for _, e := range tops {
235 if e.section == sec.name {
236 here = append(here, e)
237 }
238 }
239 if sec.name == "ready" && len(here) == 0 {
240 p("%s\n", readyElsewhere(tops))
241 gap = true
242 continue
243 }
244 if len(here) == 0 {
245 continue
246 }
247 if gap {
248 p("\n")
249 }
250 p("%s\n", sec.name)
251 if sec.name == "approved" {
252 for _, e := range here {
253 for _, line := range t.approvedLines(e) {
254 p("%s\n", line)
255 }
256 }
257 gap = true
258 continue
259 }
260 for i, e := range here {
261 if i > 0 {
262 p("\n")
263 }
264 for _, line := range t.drawStack(e) {
265 p("%s\n", line)
266 }
267 }
268 gap = true
269 }
270}
271
272// approvedLines is an approved stack, one line for each approved change:
273// its name, its title, and its check state when --checks gave one. These
274// changes wait on the checks and the integrator, not on the reader. A
275// branch in the stack is landed by the top's request and gets no line. A
276// stack that holds a ready change or a draft is drawn in full, since the
277// reader has something to do in it.
278func (t terminal) approvedLines(top *entry) []string {
279 list := append([]*entry{top}, top.below...)
280 var lines []string
281 for _, e := range list {
282 switch e.section {
283 case "approved":
284 case "branches":
285 continue
286 default:
287 return t.drawStack(top)
288 }
289 tail := ""
290 if e.checks != "" {
291 tail = " " + e.checks
292 }
293 lead := e.name + " "
294 lines = append(lines, t.strong(e.name)+" "+fit(e.title, t.width-columns(lead+tail))+tail)
295 }
296 return lines
297}
298
299// entries are a repository's entries, as its pending view lists them, each
300// with its head's commit time, age and author.
301func (r listed) entries(view jsonRepo, h handleMap, l listing) []*entry {
302 s := r.snap
303 states := map[handleKey]string{}
304 for _, n := range s.all {
305 states[handleKey{r.name, n.record.Target, n.id}] = n.record.State
306 }
307 var all []*entry
308 recorded := func(section string, c jsonChange) {
309 v := c.Versions[c.Active-1]
310 e := &entry{section: section, name: fmt.Sprintf("%s v%d", c.Handle, v.N), ref: c.Handle, head: v.Head, title: readable(v.Title)}
311 if len(c.Knots) > 0 {
312 e.knot = readable(c.Knots[0].ID)
313 }
314 if section == "drafts" && v.Branch != "" {
315 e.name += " on " + branchName(v.Branch)
316 }
317 for _, id := range c.Includes {
318 k := handleKey{r.name, c.Target, id}
319 if st := states[k]; st != change.Ready && st != change.Draft {
320 e.includes = append(e.includes, fmt.Sprintf("includes %s (%s)", h[k], st))
321 }
322 }
323 if v.Landing == uncertain {
324 e.notes = append(e.notes, "uncertain: it may have landed without its evidence being stored")
325 }
326 if c.Restack != nil && c.Restack.Current {
327 name := func(id string) string { return h[handleKey{r.name, c.Target, id}] }
328 e.notes = append(e.notes, "restack: "+readable(restackSays(c.Restack.Report, name)))
329 }
330 if l.checks {
331 e.notes = append(e.notes, s.checks(v.Head))
332 }
333 if v.Checks != nil {
334 e.checks = checksLine(v.Checks)
335 e.notes = append(e.notes, e.checks)
336 }
337 all = append(all, e)
338 }
339 for _, c := range view.Changes {
340 if c.Approved != nil && *c.Approved {
341 recorded("approved", c)
342 } else {
343 recorded("ready", c)
344 }
345 }
346 for _, b := range view.Branches {
347 name := branchName(b.Branch)
348 all = append(all, &entry{section: "branches", name: name, ref: name, head: b.Head})
349 }
350 for _, c := range *view.Drafts {
351 recorded("drafts", c)
352 }
353 for _, e := range all {
354 out, _ := s.g.output(true, "log", "-1", "--format=%ct%x00%cr%x00%an", e.head)
355 if fields := strings.SplitN(out, "\x00", 3); len(fields) == 3 {
356 e.when, _ = strconv.ParseInt(fields[0], 10, 64)
357 e.age, e.author = fields[1], readable(fields[2])
358 }
359 }
360 return all
361}
362
363// stack nests each entry under the nearest entry whose head strictly
364// contains its own, and gives each entry its base: the nearest entry its
365// own head strictly contains, as the rebase engine stacks layers
366// (rebase.Snapshot.Nest). Where two are equally near, the one with the
367// later commit is taken. It returns the entries nested under none, each the
368// top of a stack, the stack with the latest commit first. Each top lists
369// every entry nested under it, at any depth, in its below.
370func (s *snapshot) stack(all []*entry) []*entry {
371 nodes := make([]rebase.Node, len(all))
372 for i, e := range all {
373 nodes[i] = rebase.Node{Name: e.name, Head: e.head, When: e.when}
374 }
375 nest := s.land.Nest(nodes)
376 for i, e := range all {
377 for _, j := range nest.Inside[i] {
378 e.inside = append(e.inside, all[j])
379 }
380 if p := nest.Parent[i]; p >= 0 {
381 e.parent = all[p]
382 e.parent.kids = append(e.parent.kids, e)
383 }
384 }
385 var tops []*entry
386 for i, e := range all {
387 if b := nest.Base[i]; b >= 0 {
388 e.base = all[b]
389 }
390 s.measure(e)
391 if e.parent == nil {
392 tops = append(tops, e)
393 }
394 }
395 for _, top := range tops {
396 top.list()
397 }
398 byActivity(tops, func(e *entry) int64 { return e.latest })
399 return tops
400}
401
402// list puts every entry nested under the top of a stack in its below, each
403// before the entries it contains. Where it can, it lists next the base of
404// the entry it listed last, so a chain is listed unbroken. Otherwise it
405// lists next the entry with the latest commit. It sets latest, the latest
406// commit time in the stack.
407func (top *entry) list() {
408 nested := map[*entry]bool{}
409 var walk func(e *entry)
410 walk = func(e *entry) {
411 for _, k := range e.kids {
412 nested[k] = true
413 walk(k)
414 }
415 }
416 walk(top)
417 top.latest = top.when
418 for last := top; len(nested) > 0; {
419 var free []*entry // those every entry containing them is listed before
420 for e := range nested {
421 listable := true
422 for _, c := range e.inside {
423 listable = listable && !nested[c]
424 }
425 if listable {
426 free = append(free, e)
427 }
428 }
429 byActivity(free, func(e *entry) int64 { return e.when })
430 next := free[0]
431 for _, e := range free {
432 if e == last.base {
433 next = e
434 }
435 }
436 delete(nested, next)
437 top.below = append(top.below, next)
438 top.latest = max(top.latest, next.when)
439 last = next
440 }
441}
442
443// readyElsewhere is what the ready section says when no ready change is at
444// the top of a stack: that nothing is ready, or where the ready changes in
445// other sections' stacks are.
446func readyElsewhere(tops []*entry) string {
447 n, stacks := 0, 0
448 var where []string
449 for _, sec := range sections {
450 found := false
451 for _, top := range tops {
452 held := 0
453 for _, e := range top.below {
454 if e.section == "ready" {
455 held++
456 }
457 }
458 if top.section == sec.name && held > 0 {
459 n, stacks, found = n+held, stacks+1, true
460 }
461 }
462 if found {
463 where = append(where, sec.name)
464 }
465 }
466 if n == 0 {
467 return "nothing is ready"
468 }
469 verb, in := "are", fmt.Sprintf("%d stacks", stacks)
470 if n == 1 {
471 verb = "is"
472 }
473 if stacks == 1 {
474 in = "a stack"
475 }
476 return fmt.Sprintf("nothing is ready on its own; %s %s in %s under %s", counted(n, "ready change"), verb, in, strings.Join(where, " and "))
477}
478
479// byActivity orders entries latest first, and then by name.
480func byActivity(list []*entry, when func(*entry) int64) {
481 sort.SliceStable(list, func(i, j int) bool {
482 if a, b := when(list[i]), when(list[j]); a != b {
483 return a > b
484 }
485 return list[i].name < list[j].name
486 })
487}
488
489// measure reads what an entry adds to what it stands on: how many
490// commits, and the diff. It stands on the nearest of its base and every
491// landed version's head below it, as the rebase engine cuts a landed
492// version's commits from a family, or on its merge base with main when
493// there is none. A landed version's commits are not on main, since it
494// landed as one new commit, and its content is. A branch's title is the
495// subject of the first of the entry's own commits on its first-parent
496// line.
497func (s *snapshot) measure(e *entry) {
498 var below []string
499 for _, h := range s.land.LandedUnder(e.head) {
500 if h != e.head {
501 below = append(below, h)
502 }
503 }
504 if e.base != nil {
505 below = append(below, e.base.head)
506 }
507 var not []string
508 from := s.tip
509 for _, h := range below {
510 not = append(not, "^"+h)
511 // The heads below are all the entry's ancestors, and the nearest
512 // is the one that contains every other.
513 if from == s.tip || s.strictAncestor(from, h) {
514 from = h
515 }
516 }
517 if s.tip != "" {
518 not = append(not, "^"+s.tip)
519 }
520 if from == "" {
521 from, _ = s.g.input(true, strings.NewReader(""), "hash-object", "-t", "tree", "--stdin")
522 }
523 commits := "? commits"
524 if out, err := s.g.output(true, append([]string{"rev-list", "--count", e.head}, not...)...); err == nil {
525 n, _ := strconv.Atoi(out)
526 commits = counted(n, "commit")
527 }
528 files, added, deleted := 0, 0, 0
529 out, _ := s.g.output(true, "diff", "--numstat", from+"..."+e.head)
530 for _, line := range strings.Split(out, "\n") {
531 if f := strings.SplitN(line, "\t", 3); len(f) == 3 {
532 a, _ := strconv.Atoi(f[0]) // a binary file's counts are -, read as 0
533 d, _ := strconv.Atoi(f[1])
534 files, added, deleted = files+1, added+a, deleted+d
535 }
536 }
537 diff := "no file changes"
538 if files > 0 {
539 diff = fmt.Sprintf("%s +%d −%d", counted(files, "file"), added, deleted)
540 }
541 e.layer = commits + " · " + diff
542 if e.section == "branches" {
543 e.title = s.branchTitle(e.head, not)
544 }
545}
546
547// branchTitle is a branch's title: the subject of the first of its own
548// commits on its first-parent line, those its head reaches and not leaves
549// out.
550func (s *snapshot) branchTitle(head string, not []string) string {
551 out, _ := s.g.output(true, append([]string{"log", "--first-parent", "--reverse", "--format=%s", head}, not...)...)
552 first, _, _ := strings.Cut(out, "\n")
553 return readable(change.Title(first))
554}
555
556func counted(n int, noun string) string {
557 switch n {
558 case 0:
559 return "no " + noun + "s"
560 case 1:
561 return "1 " + noun
562 }
563 return fmt.Sprintf("%d %ss", n, noun)
564}
565
566// drawStack is the lines of a stack: the top entry's block, then the
567// block of each entry listed under it, at one indentation however deep the
568// stack is. Each listed entry is on the entry listed right after it, and
569// says "on <base>" where it is not.
570func (t terminal) drawStack(top *entry) []string {
571 list := append([]*entry{top}, top.below...)
572 var lines []string
573 for i, e := range list {
574 var next *entry
575 if i+1 < len(list) {
576 next = list[i+1]
577 }
578 first, rest := "", " "
579 switch {
580 case i > 0 && next != nil:
581 first, rest = " ├ ", " │ "
582 case i > 0:
583 first, rest = " └ ", " "
584 }
585 suffix := ""
586 if e.section != top.section {
587 for _, sec := range sections {
588 if sec.name == e.section {
589 suffix = " (" + sec.kind + ")"
590 }
591 }
592 }
593 lines = append(lines, t.nameLine(first, e.name, suffix, e, rest)...)
594 lines = append(lines, rest+t.titled(e, rest), rest+t.fit(e.layer, rest))
595 switch {
596 case e.base == next:
597 case e.base != nil:
598 lines = append(lines, rest+"on "+e.base.ref)
599 default:
600 lines = append(lines, rest+"on "+recordTarget)
601 }
602 lines = append(lines, prefixed(rest, e.includes)...)
603 for _, note := range e.notes {
604 lines = append(lines, rest+t.fit(note, rest))
605 }
606 if i == 0 && len(top.below) > 0 {
607 lands := fmt.Sprintf("approving it lands the %d below too", len(top.below))
608 if len(top.below) == 1 {
609 lands = "approving it lands the one below too"
610 }
611 lines = append(lines, rest+t.fit(lands, rest))
612 }
613 }
614 return lines
615}
616
617// titled formats e's title line after lead, appending " · <knot ID>" when a
618// knot links the change. Long titles are truncated so the knot ID fits in
619// full.
620func (t terminal) titled(e *entry, lead string) string {
621 if e.knot == "" {
622 return t.fit(e.title, lead)
623 }
624 tail := " · " + e.knot
625 return fit(e.title, t.width-columns(lead+tail)) + tail
626}
627
628func prefixed(lead string, lines []string) []string {
629 var out []string
630 for _, l := range lines {
631 out = append(out, lead+l)
632 }
633 return out
634}
635
636// nameLine is an entry's first line: its name, in bold on a terminal, and
637// the head's age and author at the right margin. When that leaves too
638// little room, the author is cut short. When even that leaves too little,
639// the age and author go on a line of their own, indented as rest is.
640func (t terminal) nameLine(lead, name, suffix string, e *entry, rest string) []string {
641 left := lead + t.strong(name) + suffix
642 used := columns(lead + name + suffix)
643 if e.age == "" && e.author == "" {
644 return []string{left}
645 }
646 right := e.age + " · " + e.author
647 if room := t.width - used - 2; columns(right) > room {
648 short := room - columns(e.age+" · ")
649 if short < 4 {
650 return []string{left, rest + t.fit(right, rest)}
651 }
652 right = e.age + " · " + fit(e.author, short)
653 }
654 return []string{left + strings.Repeat(" ", t.width-used-columns(right)) + right}
655}
656
657// branchName is a branch's name as printed: as it is, or, when it holds a
658// character that is not printable or bytes that are not UTF-8, in the
659// $'...' form a shell reads back as the same name.
660func branchName(b string) string {
661 if printable(b) {
662 return b
663 }
664 return shellQuote(b)
665}
666
667// readable is s as text to print: valid UTF-8, with every control
668// character, which a terminal could act on, made a space.
669func readable(s string) string {
670 return strings.Map(func(r rune) rune {
671 if unicode.IsControl(r) {
672 return ' '
673 }
674 return r
675 }, strings.ToValidUTF8(s, "�"))
676}
677
678// checks says how many checks the policy requires of a head, by cost, as
679// valley checks derives them against the merge base with main. It runs
680// the valley command bin/valley names in VALLEY_COMMAND, inside the
681// repository the change is in.
682func (s *snapshot) checks(head string) string {
683 valley := os.Getenv("VALLEY_COMMAND")
684 if valley == "" {
685 valley = "valley"
686 }
687 base, err := s.g.output(true, "merge-base", s.tip, head)
688 if err != nil {
689 return "requires ? (no merge base with main)"
690 }
691 cmd := exec.Command(valley, "checks", base, head)
692 cmd.Dir = s.g.dir
693 cmd.Env = s.g.env
694 out, err := cmd.Output()
695 if err != nil {
696 return "requires ? (the policy did not derive)"
697 }
698 count := func(prefix string) int {
699 for _, line := range strings.Split(string(out), "\n") {
700 if rest, ok := strings.CutPrefix(line, prefix); ok && rest != "none" {
701 return len(strings.Split(rest, ", "))
702 }
703 }
704 return 0
705 }
706 quick, slow := count("quick: "), count("slow: ")
707 if quick+slow == 0 {
708 return "requires no checks"
709 }
710 noun := "checks"
711 if quick == 1 {
712 noun = "check"
713 }
714 return fmt.Sprintf("requires %d quick %s, %d slow", quick, noun, slow)
715}