gunk-dev/the-valley

pending_test.go

source58e68be0d151main's published tip history
21.3 KiB
1package main
2
3import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "os"
8 "os/exec"
9 "path/filepath"
10 "regexp"
11 "strings"
12 "testing"
13 "time"
14
15 "the-valley/telemetry"
16)
17
18// pending fits its text to 80 columns when stdout is no terminal: a long
19// title is cut short with …, and a branch or a handle is printed whole,
20// even where the line it is on cannot fit. A stack of branches four deep
21// is listed at one indentation, so its deepest entry has the room its
22// second has. Nothing it prints is an escape code.
23func TestPendingFitsEightyColumnsAndKeepsNamesWhole(t *testing.T) {
24 dir := t.TempDir()
25 t.Setenv("HOME", dir)
26 t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config"))
27 t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
28 t.Setenv("VALLEY_KNOWN_SIGNERS", "")
29 origin, work := filepath.Join(dir, "origin.git"), filepath.Join(dir, "work")
30 sh := func(args ...string) {
31 t.Helper()
32 cmd := exec.Command("git", args...)
33 cmd.Dir = work
34 if out, err := cmd.CombinedOutput(); err != nil {
35 t.Fatalf("git %s: %v\n%s", strings.Join(args, " "), err, out)
36 }
37 }
38 if out, err := exec.Command("git", "init", "--quiet", "--bare", "--initial-branch=main", origin).CombinedOutput(); err != nil {
39 t.Fatalf("git init: %v\n%s", err, out)
40 }
41 if out, err := exec.Command("git", "clone", "--quiet", origin, work).CombinedOutput(); err != nil {
42 t.Fatalf("git clone: %v\n%s", err, out)
43 }
44 sh("config", "user.name", "a committer whose name is so long that the line it is on has to cut it short")
45 sh("config", "user.email", "committer@localhost")
46 sh("config", "valley.principal", "alice")
47 sh("checkout", "--quiet", "-b", "main")
48 sh("commit", "--quiet", "--allow-empty", "-m", "base")
49 sh("push", "--quiet", "origin", "main")
50
51 long := "a-branch-whose-name-runs-on-well-past-the-eightieth-column-of-any-terminal-it-is-shown-in"
52 title := "a subject that says far more than one line has room for, " + strings.Repeat("and then some more ", 4)
53 sh("checkout", "--quiet", "-b", long, "main")
54 sh("commit", "--quiet", "--allow-empty", "-m", title+"on the long branch")
55 sh("push", "--quiet", "origin", long)
56 sh("checkout", "--quiet", "-b", "short", "main")
57 sh("commit", "--quiet", "--allow-empty", "-m", title)
58 sh("push", "--quiet", "origin", "short")
59 from := "main"
60 for _, layer := range []string{"1", "2", "3", "4"} {
61 sh("checkout", "--quiet", "-b", "layer-"+layer, from)
62 sh("commit", "--quiet", "--allow-empty", "-m", "layer "+layer+": "+title)
63 sh("push", "--quiet", "origin", "layer-"+layer)
64 from = "layer-" + layer
65 }
66
67 t.Chdir(work)
68 var stdout, stderr bytes.Buffer
69 if code := run([]string{"ready", "--change", strings.Repeat("q", 32), "short"}, &stdout, &stderr, os.Exit); code != 0 {
70 t.Fatalf("ready: %s", stderr.String())
71 }
72 stdout.Reset()
73 if code := run([]string{"pending", "--branches"}, &stdout, &stderr, os.Exit); code != 0 {
74 t.Fatalf("pending: %s", stderr.String())
75 }
76 out := stdout.String()
77 if strings.Contains(out, "\x1b") {
78 t.Errorf("pending printed an escape code to no terminal:\n%s", out)
79 }
80 if !strings.Contains(out, "\n"+long+"\n") {
81 t.Errorf("the long branch is not whole, on a line of its own:\n%s", out)
82 }
83 if !strings.Contains(out, "\n 1 qqqq v1") {
84 t.Errorf("the change is not named by its whole handle and version:\n%s", out)
85 }
86 cut := 0
87 for _, line := range strings.Split(strings.TrimSuffix(out, "\n"), "\n") {
88 if strings.Contains(line, long) {
89 continue
90 }
91 if columns(line) > 80 {
92 t.Errorf("a line is %d columns wide: %q", columns(line), line)
93 }
94 if strings.HasPrefix(strings.TrimLeft(line, " "), "a subject that says") {
95 if columns(line) != 80 || !strings.HasSuffix(line, "…") {
96 t.Errorf("a long title is not cut to 80 columns with …: %q", line)
97 }
98 cut++
99 }
100 if strings.HasPrefix(line, "layer-4 ") && !strings.HasSuffix(line, "…") {
101 t.Errorf("the author is not cut short to keep the line within 80 columns: %q", line)
102 }
103 }
104 lines := strings.Split(out, "\n")
105 for layer, lead := range map[string]string{"4": " ", "3": " │ ", "2": " │ ", "1": " "} {
106 listed := false
107 for _, line := range lines {
108 if strings.HasPrefix(line, lead+"layer "+layer+": ") {
109 listed = true
110 if columns(line) != 80 || !strings.HasSuffix(line, "…") {
111 t.Errorf("layer %s's title is not cut to 80 columns with …: %q", layer, line)
112 }
113 }
114 }
115 if !listed {
116 t.Errorf("layer %s's title is not at %q:\n%s", layer, lead, out)
117 }
118 }
119 if !strings.Contains(out, "\n approving it lands the 3 below too\n") || strings.Contains(out, "on layer-") {
120 t.Errorf("the stack four deep is not one list, each layer on the next:\n%s", out)
121 }
122 if cut != 2 {
123 t.Errorf("%d titles were cut short, where the change's and the branch's should be:\n%s", cut, out)
124 }
125}
126
127// fit cuts by columns, not bytes: a wide character takes two, and a
128// combining mark none.
129func TestFitCountsColumns(t *testing.T) {
130 for _, c := range []struct {
131 s string
132 n int
133 want string
134 }{
135 {"short", 10, "short"},
136 {"exactly ten", 11, "exactly ten"},
137 {"one word too many", 12, "one word to…"},
138 {"漢字漢字漢字", 7, "漢字漢…"},
139 {"café au lait", 5, "café au lait"[:6] + "…"},
140 } {
141 if got := fit(c.s, c.n); got != c.want || columns(got) > c.n {
142 t.Errorf("fit(%q, %d) = %q, %d columns; want %q", c.s, c.n, got, columns(got), c.want)
143 }
144 }
145}
146
147// toolsOnPath puts on PATH, for the test, a shim for each tool named that
148// logs each start to the file it returns and runs the real tool. It
149// skips the test when a tool is missing, unless VALLEY_TEST_TOOLS is
150// required.
151func toolsOnPath(t *testing.T, dir string, tools ...string) (starts string) {
152 t.Helper()
153 bin, starts := filepath.Join(dir, "bin"), filepath.Join(dir, "starts")
154 if err := os.MkdirAll(bin, 0o755); err != nil {
155 t.Fatal(err)
156 }
157 for _, tool := range tools {
158 real, err := exec.LookPath(tool)
159 if err != nil {
160 if os.Getenv("VALLEY_TEST_TOOLS") == "required" {
161 t.Fatalf("no %s on PATH, and VALLEY_TEST_TOOLS=required", tool)
162 }
163 t.Skipf("no %s to run; the nix check provides one", tool)
164 }
165 shim := fmt.Sprintf("#!/bin/sh\necho %s >> '%s'\nexec '%s' \"$@\"\n", tool, starts, real)
166 if err := os.WriteFile(filepath.Join(bin, tool), []byte(shim), 0o755); err != nil {
167 t.Fatal(err)
168 }
169 }
170 t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
171 return starts
172}
173
174// testSchema is the verification schema, read from the package's
175// directory before a test changes to another.
176var testSchema, _ = filepath.Abs(filepath.Join("..", "schema", "verification.cue"))
177
178// policyProject is a repository at root with its own origin, whose floor
179// has one class requiring checks c-1 to c-<checks> of every path under
180// src/, made the current directory. head pushes a branch off main that
181// adds src/<branch> and readies it as the change id.
182func policyProject(t *testing.T, root string, checks int) (sh func(...string), head func(branch, id string)) {
183 t.Helper()
184 t.Setenv("HOME", root)
185 t.Setenv("XDG_CONFIG_HOME", filepath.Join(root, "config"))
186 t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
187 t.Setenv("VALLEY_KNOWN_SIGNERS", "")
188 t.Setenv("VALLEY_VERIFICATION_SCHEMA", testSchema)
189 origin, work := filepath.Join(root, "origin.git"), filepath.Join(root, "work")
190 sh = func(args ...string) {
191 t.Helper()
192 cmd := exec.Command("git", args...)
193 cmd.Dir = work
194 if out, err := cmd.CombinedOutput(); err != nil {
195 t.Fatalf("git %s: %v\n%s", strings.Join(args, " "), err, out)
196 }
197 }
198 if out, err := exec.Command("git", "init", "--quiet", "--bare", "--initial-branch=main", origin).CombinedOutput(); err != nil {
199 t.Fatalf("git init: %v\n%s", err, out)
200 }
201 if out, err := exec.Command("git", "clone", "--quiet", origin, work).CombinedOutput(); err != nil {
202 t.Fatalf("git clone: %v\n%s", err, out)
203 }
204 sh("config", "user.name", "operator")
205 sh("config", "user.email", "operator@example.org")
206 sh("config", "valley.principal", "operator")
207 sh("checkout", "--quiet", "-b", "main")
208 var floor strings.Builder
209 floor.WriteString("package verification\nfloor: {\n")
210 for i := 1; i <= checks; i++ {
211 fmt.Fprintf(&floor, "\tchecks: \"c-%d\": {runner: \"nix\", attribute: \"c-%d\"}\n", i, i)
212 fmt.Fprintf(&floor, "\tclasses: src: {paths: \"src/**\": true, requires: \"c-%d\": true}\n", i)
213 }
214 floor.WriteString("\tunclassified: \"c-1\": true\n}\n")
215 if err := os.MkdirAll(filepath.Join(work, "policy", "instance"), 0o755); err != nil {
216 t.Fatal(err)
217 }
218 if err := os.WriteFile(filepath.Join(work, "policy", "instance", "floor.cue"), []byte(floor.String()), 0o644); err != nil {
219 t.Fatal(err)
220 }
221 sh("add", ".")
222 sh("commit", "--quiet", "-m", "base")
223 sh("push", "--quiet", "origin", "main")
224 t.Chdir(work)
225 head = func(branch, id string) {
226 t.Helper()
227 sh("checkout", "--quiet", "-b", branch, "main")
228 if err := os.MkdirAll(filepath.Join(work, "src"), 0o755); err != nil {
229 t.Fatal(err)
230 }
231 if err := os.WriteFile(filepath.Join(work, "src", branch), []byte(branch+"\n"), 0o644); err != nil {
232 t.Fatal(err)
233 }
234 sh("add", ".")
235 sh("commit", "--quiet", "-m", branch)
236 sh("push", "--quiet", "origin", branch)
237 var stdout, stderr bytes.Buffer
238 if code := run([]string{"ready", "--change", id, branch}, &stdout, &stderr, os.Exit); code != 0 {
239 t.Fatalf("ready: %s", stderr.String())
240 }
241 }
242 return sh, head
243}
244
245// runCounted runs valley with args, and returns what it printed and how
246// many processes the shims on PATH logged, by tool, and in all under "".
247func runCounted(t *testing.T, starts string, args ...string) (string, map[string]int) {
248 t.Helper()
249 os.Remove(starts)
250 var stdout, stderr bytes.Buffer
251 if code := run(args, &stdout, &stderr, os.Exit); code != 0 {
252 t.Fatalf("%s: %s", strings.Join(args, " "), stderr.String())
253 }
254 log, _ := os.ReadFile(starts)
255 started := map[string]int{}
256 for _, tool := range strings.Fields(string(log)) {
257 started[tool]++
258 started[""]++
259 }
260 return stdout.String(), started
261}
262
263// pending reads the policy at main's tip once for a project, and asks cue
264// no requirement's pin: the cue processes it starts, with --checks or
265// without, are as many for a class requiring nine checks and four ready
266// heads as for one requiring three and one head.
267func TestPendingStartsCueOncePerProject(t *testing.T) {
268 dir := t.TempDir()
269 starts := toolsOnPath(t, dir, "cue")
270
271 // project lists a project whose class requires checks c-1 to
272 // c-<checks>, with heads ready changes touching it. It returns what
273 // each listing printed and how many cue processes it started.
274 project := func(checks, heads int) (printed map[string]string, started map[string]int) {
275 t.Helper()
276 _, head := policyProject(t, filepath.Join(dir, fmt.Sprintf("%d-%d", checks, heads)), checks)
277 for i := 1; i <= heads; i++ {
278 head(fmt.Sprintf("head-%d", i), strings.Repeat(string(rune('p'+i)), 32))
279 }
280 printed, started = map[string]string{}, map[string]int{}
281 for _, args := range [][]string{{"pending"}, {"pending", "--checks"}} {
282 listing := strings.Join(args, " ")
283 out, n := runCounted(t, starts, args...)
284 printed[listing], started[listing] = out, n["cue"]
285 }
286 return printed, started
287 }
288
289 _, small := project(3, 1)
290 out, large := project(9, 4)
291 if want := "requires 9 quick checks, 0 slow"; strings.Count(out["pending --checks"], want) != 4 {
292 t.Fatalf("pending --checks does not say %q of each of four heads:\n%s", want, out["pending --checks"])
293 }
294 for listing, n := range small {
295 if n == 0 || large[listing] != n {
296 t.Errorf("%s started %d cue processes for three checks and one head, and %d for nine and four heads", listing, n, large[listing])
297 }
298 }
299}
300
301// pending --checks reads a draft's checks only when --drafts lists the
302// drafts. A listing starts attest only to read checks, once for each head
303// to digest its tree. Without --drafts, two drafts start no attest, add
304// nothing to what --checks starts, and change no row; with it, each
305// draft's tree is digested and its block shows its checks.
306func TestPendingReadsDraftChecksOnlyWhenListed(t *testing.T) {
307 dir := t.TempDir()
308 starts := toolsOnPath(t, dir, "git", "cue")
309 // attest logs its start as the shims do and answers with one digest:
310 // when origin holds no evidence, a listing asks it only to digest each
311 // head's tree, and the digest decides nothing.
312 stand := fmt.Sprintf("#!/bin/sh\necho attest >> '%s'\necho valley-tree-v1:0123\n", starts)
313 if err := os.WriteFile(filepath.Join(dir, "bin", "attest"), []byte(stand), 0o755); err != nil {
314 t.Fatal(err)
315 }
316 _, head := policyProject(t, filepath.Join(dir, "project"), 2)
317 head("ready-1", strings.Repeat("p", 32))
318 // listing is pending with args and --checks: what it printed, its ages
319 // left out, since a row's age ticks, the attest processes it started,
320 // and how many processes --checks added.
321 ages := regexp.MustCompile(`(?m) +[0-9]+[smhd]$`)
322 listing := func(args ...string) (out string, attest, added int) {
323 t.Helper()
324 _, without := runCounted(t, starts, append([]string{"pending"}, args...)...)
325 out, with := runCounted(t, starts, append([]string{"pending", "--checks"}, args...)...)
326 return ages.ReplaceAllString(out, ""), with["attest"], with[""] - without[""]
327 }
328 before, attest, added := listing()
329 if attest != 1 {
330 t.Fatalf("pending --checks started attest %d times for one ready head", attest)
331 }
332 for _, id := range []string{"q", "r"} {
333 head("draft-"+id, strings.Repeat(id, 32))
334 var stdout, stderr bytes.Buffer
335 if code := run([]string{"unready", strings.Repeat(id, 32)}, &stdout, &stderr, os.Exit); code != 0 {
336 t.Fatalf("unready: %s", stderr.String())
337 }
338 }
339 after, drafted, addedNow := listing()
340 if drafted != attest || addedNow != added {
341 t.Errorf("with two drafts not listed, pending --checks started attest %d times, not %d, and --checks added %d processes, not %d",
342 drafted, attest, addedNow, added)
343 }
344 if want := before + "\n2 drafts · valley pending --drafts\n"; after != want {
345 t.Errorf("pending --checks printed, with two drafts:\n%s\nand with none:\n%s", after, before)
346 }
347 out, listed, _ := listing("--drafts")
348 if listed != attest+2 {
349 t.Errorf("pending --drafts --checks started attest %d times for one ready head and two drafts", listed)
350 }
351 for _, d := range []string{"qqqq v1 on draft-q 2 checks pending", "rrrr v1 on draft-r 2 checks pending"} {
352 if !strings.Contains(out, "\n"+d) {
353 t.Errorf("pending --drafts --checks does not open a block with %q:\n%s", d, out)
354 }
355 }
356 if n := strings.Count(out, "\n checks: 2 pending\n"); n != 2 {
357 t.Errorf("pending --drafts --checks gives %d drafts their checks line, not 2:\n%s", n, out)
358 }
359}
360
361// pending --checks says when the worker's newest build of a pending
362// check failed, for a ready change and for a draft alike, apart from a
363// check whose failed build a later one passed and a check never built, and
364// says where the worker's report is read. With --json, the check's state
365// stays pending and the worker's report is beside it. A batch that failed
366// before any check ran is said the same way. A host whose telemetry does
367// not read leaves the listing as it is with no worker records.
368func TestPendingSaysWhenTheWorkersBuildFailed(t *testing.T) {
369 dir := t.TempDir()
370 toolsOnPath(t, dir, "git", "cue")
371 // attest only digests each head's tree, since origin holds no
372 // evidence, and gives every head one digest: the worker's records
373 // about that tree are about the ready change's and the draft's. ssh
374 // answers the worker's read from a file, as the host would.
375 answer := filepath.Join(dir, "answer")
376 for tool, script := range map[string]string{
377 "attest": "#!/bin/sh\necho valley-tree-v1:0123\n",
378 "ssh": fmt.Sprintf("#!/bin/sh\ncat '%s'\n", answer),
379 } {
380 if err := os.WriteFile(filepath.Join(dir, "bin", tool), []byte(script), 0o755); err != nil {
381 t.Fatal(err)
382 }
383 }
384 sh, head := policyProject(t, filepath.Join(dir, "origin"), 3)
385 sh("config", "valley.telemetry.remote", "ssh://git@valley-host/origin.git")
386 ready, draft := strings.Repeat("p", 32), strings.Repeat("q", 32)
387 head("ready-1", ready)
388 head("draft-1", draft)
389 var stdout, stderr bytes.Buffer
390 if code := run([]string{"unready", draft}, &stdout, &stderr, os.Exit); code != 0 {
391 t.Fatalf("unready: %s", stderr.String())
392 }
393
394 // records makes the host's answer: one page of the worker's records.
395 records := func(lines ...string) {
396 t.Helper()
397 page := `{"kind":"header","host":"valley-host","format":"valley-telemetry/v1"}` + "\n"
398 for i, l := range lines {
399 page += fmt.Sprintf(`{"kind":"record","stream":"worker","seq":%d,%s}`+"\n", i+1, l)
400 }
401 page += fmt.Sprintf(`{"kind":"end","cursor":"worker=0123456789abcdef:%d","truncated":false}`+"\n", len(lines))
402 if err := os.WriteFile(answer, []byte(page), 0o644); err != nil {
403 t.Fatal(err)
404 }
405 }
406 at := func(ago time.Duration) string { return telemetry.Stamp(time.Now().Add(-ago)) }
407 // build is a check.result of the draft's version, as attest records
408 // one.
409 build := func(when, run, tree, check, result string) string {
410 return fmt.Sprintf(`"type":"check.result","time":%q,"run":%q,"project":"origin","change":%q,"version":1,"tree":%q,"check":%q,`+
411 `"data":{"result":%q,"build_ms":1000,"eval_ms":4000,"log_bytes":10,"cached":false}`, when, run, draft, tree, check, result)
412 }
413 ages := regexp.MustCompile(`(?m) +[0-9]+[smhd]$| +[0-9]+ [a-z]+ ago · operator$`)
414 pending := func(args ...string) (string, string) {
415 t.Helper()
416 var stdout, stderr bytes.Buffer
417 if code := run(append([]string{"pending", "--checks", "--drafts"}, args...), &stdout, &stderr, os.Exit); code != 0 {
418 t.Fatalf("pending: %s", stderr.String())
419 }
420 return ages.ReplaceAllString(stdout.String(), ""), stderr.String()
421 }
422 checksOf := func() map[string]*jsonVersionChecks {
423 t.Helper()
424 out, _ := pending("--json")
425 var doc jsonChanges
426 if err := json.Unmarshal([]byte(out), &doc); err != nil || len(doc.Repos) != 1 || doc.Repos[0].Drafts == nil {
427 t.Fatalf("pending --json printed no listing of one project (%v):\n%s", err, out)
428 }
429 checks := map[string]*jsonVersionChecks{}
430 for _, c := range append(doc.Repos[0].Changes, *doc.Repos[0].Drafts...) {
431 checks[c.ChangeID] = c.Versions[c.Active-1].Checks
432 }
433 if len(checks) != 2 {
434 t.Fatalf("pending --json lists %d changes, not the ready change and the draft:\n%s", len(checks), out)
435 }
436 return checks
437 }
438 see := " see: valley telemetry read --source worker --logs"
439
440 records()
441 plain, _ := pending()
442
443 // c-1's newest build failed; c-2 failed, then passed; c-3 was built
444 // only for another tree.
445 failed := at(5*time.Minute + 10*time.Second)
446 records(build(at(20*time.Minute), "r1", "0123", "c-1", "failed"), build(at(20*time.Minute), "r1", "0123", "c-2", "failed"),
447 build(failed, "r2", "0123", "c-1", "failed"), build(at(5*time.Minute), "r2", "0123", "c-2", "passed"),
448 build(at(time.Minute), "r3", "4567", "c-3", "failed"))
449 out, _ := pending()
450 says := "c-1 failed in the worker's build, 5m ago"
451 for _, want := range []string{
452 "\n 1 pppp v1 ✗ " + says + "\n ready-1\n requires 3 quick checks, 0 slow\n" +
453 " checks: 3 pending (" + says + ")\n " + see + "\n",
454 "\nqqqq v1 on draft-1 ✗ " + says + "\n",
455 "\n requires 3 quick checks, 0 slow\n checks: 3 pending (" + says + ") in 2s (eval 4s)\n " + see + "\n",
456 } {
457 if !strings.Contains(out, want) {
458 t.Errorf("pending --checks --drafts does not say\n%s\nin:\n%s", want, out)
459 }
460 }
461 for id, c := range checksOf() {
462 if c == nil || c.State != checkPending || c.Worker != nil || len(c.Required) != 3 {
463 t.Fatalf("%s's checks are not three, pending, with no batch reported: %+v", id, c)
464 }
465 if q := c.Required[0]; q.State != checkPending || q.Worker == nil || *q.Worker != (jsonWorkerReport{Result: checkFailed, Time: failed, Run: "r2"}) {
466 t.Errorf("%s's c-1 is not pending with the worker's report of r2's failure: %+v", id, q)
467 }
468 for _, q := range c.Required[1:] {
469 if q.State != checkPending || q.Worker != nil {
470 t.Errorf("%s's %s is not pending with no worker's report: %+v", id, q.Name, q)
471 }
472 }
473 }
474
475 // A batch that failed before any check ran recorded no check's result.
476 ended := at(time.Minute + 10*time.Second)
477 records(build(at(20*time.Minute), "r1", "0123", "c-1", "passed"),
478 fmt.Sprintf(`"type":"batch.end","time":%q,"run":"p1","project":"origin","change":%q,"version":1,"tree":"0123",`+
479 `"data":{"result":"failed","attest_run":"r4","reason":"attest run r4: exit status 1"}`, ended, ready))
480 out, _ = pending()
481 says = "the worker's batch failed, 1m ago"
482 if want := "\n 1 pppp v1 ✗ " + says + "\n ready-1\n requires 3 quick checks, 0 slow\n" +
483 " checks: 3 pending (" + says + ")\n " + see + "\n"; !strings.Contains(out, want) {
484 t.Errorf("pending --checks does not say\n%s\nin:\n%s", want, out)
485 }
486 for id, c := range checksOf() {
487 if c.Worker == nil || *c.Worker != (jsonWorkerReport{Result: checkFailed, Time: ended, Run: "r4"}) || c.State != checkPending {
488 t.Errorf("%s's checks do not carry the worker's report of the failed batch: %+v", id, c)
489 }
490 }
491
492 // A host that refuses: the listing is as it is with no worker records.
493 if err := os.WriteFile(answer, []byte(`{"kind":"error","error":"operator holds no observe grant"}`+"\n"), 0o644); err != nil {
494 t.Fatal(err)
495 }
496 out, errs := pending()
497 if out != plain {
498 t.Errorf("with the worker's telemetry refused, pending printed:\n%s\nand with no worker records:\n%s", out, plain)
499 }
500 if n := strings.Count(errs, "no check lists its build times"); n != 1 {
501 t.Errorf("a refusing host was said %d times on stderr, not once:\n%s", n, errs)
502 }
503 for id, c := range checksOf() {
504 reported := c.Worker != nil
505 for _, q := range c.Required {
506 reported = reported || q.Worker != nil
507 }
508 if reported {
509 t.Errorf("with the worker's telemetry refused, %s carries a worker's report: %+v", id, c)
510 }
511 }
512}