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 "html"
5 "strings"
6 "testing"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// macMade runs w's Engineering attempt d to done with a summary, and the
12// primary publishes it.
13func (r *runnersRig) macMade(w *peer, d *wire.DispatchCommand, cand string) {
14 r.t.Helper()
15 if !w.lease(d.StepID, d.Attempt) {
16 r.t.Fatal("start refused")
17 }
18 w.send(wire.FrameStep, wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, BaseSHA: d.BaseSHA, Findings: []wire.Finding{}})
19 w.send(wire.FrameStep, wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, Findings: []wire.Finding{}})
20 _, body := w.expect(wire.FrameSendPack)
21 h := body.(*wire.SendPackCommand).Transfer
22 w.send(wire.FrameStep, wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: cand, Summary: "Swipe back added.", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}})
23 w.send(wire.FrameBlob, chunk(h, []byte("PACK commit")))
24 r.fromPrimary(wire.FrameBlob)
25 pub := r.fromPrimary(wire.FramePublish).(*wire.PublishCommand)
26 r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: cand, Pushed: true})
27}
28
29// TestContractStepSaysMadeOn: the instance names the worker an
30// Engineering attempt ran on (never before it starts, never the main
31// runner) with what it got of Xcode, and the task page says "Made on"
32// the Mac and, without Xcode access, that the Mac's checks build it.
33// While the base is prepared the step says which Mac it waits for.
34func TestContractStepSaysMadeOn(t *testing.T) {
35 r := newMacRig(t)
36 w := r.newMacEngineer("Tito Studio", wire.EngineeringReady)
37 task := r.macTask("iOS made")
38 if s := r.newestEngineering(task); s.Placement != wire.PlacementBase || s.RunnerLabel != "Tito Studio" || s.MadeOn != "" {
39 t.Fatalf("waiting for its base %+v", s)
40 }
41 r.based(r.prepared(task), sha(1))
42 _, body := w.expect(wire.FrameDispatch)
43 d := body.(*wire.DispatchCommand)
44 r.engineeringTransfer(w, d)
45 if s := r.newestEngineering(task); s.MadeOn != "" {
46 t.Fatalf("named before it started %+v", s)
47 }
48 r.macMade(w, d, sha(0xc1))
49 s := r.newestEngineering(task)
50 if s.MadeOn != "Tito Studio" || s.XcodeAccess != "" {
51 t.Fatalf("made on %+v", s)
52 }
53 page := html.UnescapeString(r.get(r.inst.Cookie(), "/tasks/"+task, 200))
54 for _, want := range []string{"Made on Tito Studio", "Built and tested by the Mac's checks, not while making the change"} {
55 if !strings.Contains(page, want) {
56 t.Fatalf("task page lacks %q:\n%s", want, page)
57 }
58 }
59
60 // F5 denied: sandboxed Xcode access, so no such line.
61 r = newMacRig(t)
62 w = r.newMacEngineerAt("Tito Studio", wire.EngineeringReady, wire.ProtocolMacEngineering, true)
63 task = r.macTask("iOS xcode")
64 r.based(r.prepared(task), sha(2))
65 _, body = w.expect(wire.FrameDispatch)
66 d = body.(*wire.DispatchCommand)
67 r.engineeringTransfer(w, d)
68 r.macMade(w, d, sha(0xc2))
69 if s := r.newestEngineering(task); s.MadeOn != "Tito Studio" || s.XcodeAccess != wire.XcodeAccessSandboxed {
70 t.Fatalf("with Xcode access %+v", s)
71 }
72 if page := html.UnescapeString(r.get(r.inst.Cookie(), "/tasks/"+task, 200)); !strings.Contains(page, "Made on Tito Studio") || strings.Contains(page, "not while making the change") {
73 t.Fatalf("with Xcode access, the page:\n%s", page)
74 }
75}
76
77// Engineering on the main runner names no machine.
78func TestContractMainRunnerNotNamed(t *testing.T) {
79 r := newRunnersRig(t)
80 task, _ := r.candidate("Linux change", false)
81 for _, s := range r.task(task).Steps {
82 if s.Specialist == wire.SpecialistEngineering && (s.MadeOn != "" || s.StartedAt == nil) {
83 t.Fatalf("the main runner named, or the rig did not start it: %+v", s)
84 }
85 }
86}
87
88// TestContractAddClaudeOnConnectionWait: a Mac Engineering attempt that
89// placement put waiting for a Mac's Claude connection links its creator
90// straight to adding Claude to that Mac, by the Mac's id, while the Mac
91// has no connection or is signed out; not while what it lacks is
92// something else (its home folder open).
93func TestContractAddClaudeOnConnectionWait(t *testing.T) {
94 r := newMacRig(t)
95 w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection)
96 wid := w.fr.Welcome.RunnerID
97 task := r.macTask("iOS needs Claude")
98 if s := r.newestEngineering(task); s.Placement != wire.PlacementMacConnection || s.RunnerID != "" || s.WaitingFor != wid {
99 t.Fatalf("waiting %+v", s)
100 }
101 link := `href="/conversation/settings/connections#machine-` + wid + `" data-add-claude>Add Claude to Tito Studio</a>`
102 for _, state := range []string{wire.EngineeringNoConnection, wire.EngineeringSignedOut} {
103 r.macState(w, state, false)
104 if page := r.get(r.inst.Cookie(), "/tasks/"+task, 200); !strings.Contains(page, link) {
105 t.Fatalf("%s: no link to add Claude to the Mac:\n%s", state, page)
106 }
107 }
108 r.macState(w, wire.EngineeringHomeOpen, false)
109 if page := r.get(r.inst.Cookie(), "/tasks/"+task, 200); strings.Contains(page, "data-add-claude") {
110 t.Fatal("home open: offered to add Claude")
111 }
112}
113
114// TestContractMadeOnAfterPrimaryReplaced: whether an attempt was made on
115// a worker is what its dispatch recorded, not a comparison with today's
116// main runner. A change the old Linux primary made says neither "Made on"
117// nor the no-Xcode line once another machine is the main runner.
118func TestContractMadeOnAfterPrimaryReplaced(t *testing.T) {
119 r := newRunnersRig(t)
120 task, _ := r.candidate("Linux change", false)
121 old := r.primary.fr.Welcome.RunnerID
122 r.remove(old, true)
123 h := primaryHello(0)
124 h.Label = "docs-t2"
125 p, err := DialRunnerHello(r.ctx, r.inst.URL, r.inst.EnrolRunner(t).Token, h)
126 if err != nil || p.Welcome.Role != wire.RolePrimary || p.Welcome.RunnerID == old {
127 t.Fatalf("replacement %+v %v", p, err)
128 }
129 t.Cleanup(p.Close)
130 for _, s := range r.task(task).Steps {
131 if s.Specialist == wire.SpecialistEngineering && (s.MadeOn != "" || s.StartedAt == nil) {
132 t.Fatalf("the old primary's change named as made on a worker: %+v", s)
133 }
134 }
135 if page := html.UnescapeString(r.get(r.inst.Cookie(), "/tasks/"+task, 200)); strings.Contains(page, "Made on") || strings.Contains(page, "not while making the change") {
136 t.Fatalf("task page:\n%s", page)
137 }
138}
139