oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "regexp"
5 "strings"
6 "testing"
7)
8
9// TestPagesMachines: Machines in Settings (Paul, 2026-11-11) on a real
10// instance. The owner's own machines are rows (the online primary and
11// Mac, the Mac that never connected saying what to check); a member's
12// machine is folded under Other people's machines, closed, with its
13// count; the details and the quiet, confirmed Revoke and Remove now are
14// behind a click. The member sees only their own. /runners/enrol, the
15// address a runner prints, still serves the list, and with a code the
16// Add a machine page; Add a machine lists the new machine.
17func TestPagesMachines(t *testing.T) {
18 r := newMachinesRig(t)
19 owner := r.inst.Cookie()
20 row := func(page, id string) string {
21 t.Helper()
22 m := regexp.MustCompile(`(?s)<details equipo-mach data-machine="` + id + `" data-state="([a-z]+)">.*?</summary>`).FindString(page)
23 if m == "" {
24 t.Fatalf("no row %s", id)
25 }
26 return m
27 }
28 for _, path := range []string{"/conversation/settings/machines", "/runners/enrol"} {
29 page := r.get(owner, path, 200)
30 mine, others, ok := strings.Cut(page, "data-other-machines")
31 if !ok || !strings.Contains(mine, "data-my-machines") {
32 t.Fatalf("%s: no folded others after the person's own", path)
33 }
34 if !regexp.MustCompile(`<details equipo-mach-others data-other-machines><summary><span>Other people&#39;s machines</span> <span equipo-conn-n>1</span>`).MatchString(page) {
35 t.Fatalf("%s: others not folded, closed, with a count", path)
36 }
37 for id, state := range map[string]string{r.worker: "online", r.never: "never"} {
38 if got := row(mine, id); !strings.Contains(got, `data-state="`+state+`"`) {
39 t.Fatalf("%s: %s is not %s: %s", path, id, state, got)
40 }
41 }
42 if !strings.Contains(row(mine, r.worker), ">Tito Studio<") || !strings.Contains(row(mine, r.worker), ">Runs checks<") {
43 t.Fatalf("%s: the Mac's row: %s", path, row(mine, r.worker))
44 }
45 never := row(mine, r.never)
46 if !strings.Contains(never, "Never connected") || !strings.Contains(never, "Check that the runner is running on it.") {
47 t.Fatalf("%s: never connected unclear: %s", path, never)
48 }
49 if !strings.Contains(row(others, r.others), "ana@example.com") || strings.Contains(mine, r.others) {
50 t.Fatalf("%s: the member's machine is not folded with whose it is", path)
51 }
52 for _, id := range []string{r.worker, r.never} {
53 if !strings.Contains(page, `<form method="post" action="/runners/`+id+`/revoke" equipo-inline-form>`) || !strings.Contains(page, `action="/runners/`+id+`/remove-now"`) {
54 t.Fatalf("%s: %s has no confirmed Revoke and Remove now", path, id)
55 }
56 }
57 if strings.Count(page, "<details equipo-mach-confirm><summary rst-btn data-quiet>") < 4 {
58 t.Fatalf("%s: destructive actions are not quiet confirmations", path)
59 }
60 }
61 // A member sees only their own machine, and no fold.
62 member := r.get(r.inst.SessionFor(t, machinesMember), "/conversation/settings/machines", 200)
63 if strings.Contains(member, "data-other-machines") || !strings.Contains(member, r.others) || strings.Contains(member, r.never) {
64 t.Fatal("a member's Machines shows other people's machines")
65 }
66 // Add a machine: the code, and the new machine waiting to connect.
67 add := r.get(owner, "/conversation/settings/machines/add", 200)
68 if !strings.Contains(add, "data-add-machine-steps") || !strings.Contains(add, `name="action" value="inspect"`) || !strings.Contains(row(add, r.never), `data-state="never"`) || !strings.Contains(add, `href="/conversation/settings/machines" rel="up"`) {
69 t.Fatal("Add a machine lacks its steps, its new machine or its way back")
70 }
71 if strings.Contains(add, "ana@example.com") {
72 t.Fatal("another person's machine on Add a machine")
73 }
74}
75