| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "amadan.net/oficina/equipo/internal/wire" |
| 7 | "fmt" |
| 8 | "github.com/chromedp/chromedp" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestBrowserProjectPlacement(t *testing.T) { |
| 13 | for _, width := range []int64{1280, 390} { |
| 14 | for _, scheme := range []string{"light", "dark"} { |
| 15 | t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| 16 | r := newToolRigAt(t, wire.ProtocolCurrent) |
| 17 | id := r.shopTask("browser-placement") |
| 18 | if err := r.runner.Send(r.ctx, "placement-reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "The task is recorded."}); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | r.wait("replied", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied }) |
| 22 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 23 | defer p.stop() |
| 24 | p.open("/tasks/" + id) |
| 25 | p.check(`(()=>{document.querySelector("[equipo-placement] > summary").focus();return document.activeElement.matches("[equipo-placement] > summary")})()`, "focus project chip") |
| 26 | p.do(chromedp.KeyEvent("\r")) |
| 27 | p.wait(`document.querySelector('[equipo-placement][open]')`, "project menu") |
| 28 | p.check(`document.querySelector('[equipo-placement] strong').textContent==='Wrong project?'`, "menu label") |
| 29 | p.check(`[...document.querySelectorAll('[equipo-placement] a')].length===2`, "two corrections") |
| 30 | if width == 390 { |
| 31 | p.check(`document.querySelector('[equipo-placement] summary').getBoundingClientRect().height>=44`, "phone target") |
| 32 | } |
| 33 | p.fits("task menu") |
| 34 | p.shot(fmt.Sprintf("placement-task-menu-%d-%s", width, scheme)) |
| 35 | p.click(`[equipo-placement] a[href$="/move"]`) |
| 36 | p.wait(`document.querySelector('[equipo-placement-page]')`, "destination page") |
| 37 | p.check(`document.querySelector('[rst-shell-back] a[rel=up]').getAttribute('href')==='/tasks/`+id+`'`, "phone parent task") |
| 38 | p.check(`document.querySelector('select[name=repo]').value==='oficina/equipo'`, "destination") |
| 39 | p.fits("destination") |
| 40 | p.shot(fmt.Sprintf("placement-choose-%d-%s", width, scheme)) |
| 41 | p.click(`[equipo-placement-page] button[type=submit]`) |
| 42 | p.wait(`location.pathname==='/tasks/`+id+`' && document.querySelector('[equipo-placement]')?.textContent.includes('Equipo')`, "moved task") |
| 43 | if task := r.task(id); task.Repo != "amadan.net/oficina/equipo" || task.Stage != wire.StageNoted { |
| 44 | t.Fatal("instant move", task) |
| 45 | } |
| 46 | p.open("/conversation") |
| 47 | p.wait(`document.querySelector('[equipo-roster-byline] [equipo-placement]')`, "Roster project chip") |
| 48 | p.click(`[equipo-roster-byline] [equipo-placement] > summary`) |
| 49 | p.fits("Roster menu") |
| 50 | p.shot(fmt.Sprintf("placement-roster-menu-%d-%s", width, scheme)) |
| 51 | p.click(`[equipo-placement][open] a[href$="new=1"]`) |
| 52 | p.wait(`document.querySelector('input[name=repo]')`, "new project form") |
| 53 | p.check(`document.querySelector('[equipo-placement-page] button[type=submit]').textContent.includes('Create project and move')`, "explicit create action") |
| 54 | p.shot(fmt.Sprintf("placement-new-%d-%s", width, scheme)) |
| 55 | p.open("/conversation/settings/notebook") |
| 56 | p.wait(`document.querySelector('[equipo-note] form button')`, "removable correction") |
| 57 | p.check(`document.querySelector('[equipo-note-caption]').textContent.includes('Observed by Equipo')`, "system attribution") |
| 58 | p.fits("correction notebook") |
| 59 | p.shot(fmt.Sprintf("placement-review-notebook-%d-%s", width, scheme)) |
| 60 | p.click(`[equipo-note] form button`) |
| 61 | p.wait(`!document.querySelector('[equipo-note]')`, "correction removed") |
| 62 | }) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func TestBrowserPlacementQuestionAndPending(t *testing.T) { |
| 68 | for _, width := range []int64{1280, 390} { |
| 69 | for _, scheme := range []string{"light", "dark"} { |
| 70 | t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| 71 | r := newToolRigAt(t, wire.ProtocolCurrent) |
| 72 | id := r.shopTask("pending-placement") |
| 73 | r.begin("pending-start", id) |
| 74 | old := r.nextDispatch() |
| 75 | if res := r.call("placement-card", wire.ToolAskPerson, map[string]any{"question": "Where?", "placement": wire.Placement{Repos: []string{"oficina/sample", "oficina/equipo"}, NewRepo: "oficina/calendar"}}); res.Code != "asked" { |
| 76 | t.Fatal(res) |
| 77 | } |
| 78 | if err := r.runner.Send(r.ctx, "pending-reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Where should this go?"}); err != nil { |
| 79 | t.Fatal(err) |
| 80 | } |
| 81 | r.wait("reply", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied }) |
| 82 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 83 | defer p.stop() |
| 84 | p.open("/conversation") |
| 85 | p.wait(`document.querySelector('[data-card] button[value="Add to oficina/sample"]')`, "placement choices") |
| 86 | p.check(`!!document.querySelector('button[value="New project: oficina/calendar"]')`, "exact proposed repository shown") |
| 87 | p.check(`(()=>{document.querySelector('button[value="Add to oficina/sample"]').closest('[data-card]').scrollIntoView({block:'center'});return true})()`, "show choices") |
| 88 | p.fits("placement question") |
| 89 | p.shot(fmt.Sprintf("placement-question-%d-%s", width, scheme)) |
| 90 | p.check(`(()=>{document.querySelector('button[value="Add to oficina/sample"]').closest('[data-card]').querySelector('[data-set-aside]').click();return true})()`, "set placement aside") |
| 91 | p.wait(`document.querySelector('[equipo-aside-stub]')`, "set-aside stub") |
| 92 | p.shot(fmt.Sprintf("placement-aside-%d-%s", width, scheme)) |
| 93 | p.click(`[equipo-aside-stub] [data-aside-undo]`) |
| 94 | p.wait(`document.querySelector('button[value="Add to oficina/sample"]')`, "restore choices") |
| 95 | p.open("/tasks/" + id + "/move") |
| 96 | p.check(`document.querySelector('[equipo-placement-page] button').textContent==='Move and restart'`, "restart label") |
| 97 | p.click(`[equipo-placement-page] button[type=submit]`) |
| 98 | p.wait(`document.querySelector('[data-placement-pending]')`, "waiting for termination") |
| 99 | p.fits("pending move") |
| 100 | p.shot(fmt.Sprintf("placement-pending-%d-%s", width, scheme)) |
| 101 | if task := r.task(id); !task.Moving || task.Repo != "amadan.net/oficina/sample" { |
| 102 | t.Fatal("browser skipped proof", task) |
| 103 | } |
| 104 | p.open("/conversation") |
| 105 | p.wait(`document.querySelector('[data-placement-task="`+id+`"] > summary')`, "held Roster chip") |
| 106 | p.click(`[data-placement-task="` + id + `"] > summary`) |
| 107 | p.wait(`document.querySelector('[data-placement-task="`+id+`"] button[name=abandon]')`, "Roster abandon") |
| 108 | p.shot(fmt.Sprintf("placement-review-roster-held-%d-%s", width, scheme)) |
| 109 | p.open("/tasks/" + id) |
| 110 | p.click(`[equipo-placement] > summary`) |
| 111 | p.wait(`document.querySelector('[equipo-placement] button[name=abandon]')`, "abandon in chip") |
| 112 | p.check(`document.querySelector('[equipo-placement-reason]').textContent.includes('runner to confirm')`, "held reason") |
| 113 | p.fits("held chip") |
| 114 | p.check(`(()=>{const r=document.querySelector("[equipo-placement] > div").getBoundingClientRect();return r.left>=0 && r.right<=innerWidth})()`, "held menu fits viewport") |
| 115 | p.shot(fmt.Sprintf("placement-review-held-%d-%s", width, scheme)) |
| 116 | p.click(`[equipo-placement] button[name=abandon]`) |
| 117 | p.wait(`document.body.textContent.includes('Move abandoned.')`, "abandoned note") |
| 118 | p.wait(`document.querySelector('[data-stage-line]').textContent==='Stopping…'`, "abandon waits for proof") |
| 119 | if task := r.task(id); task.Moving || !task.Stopping || wire.FinalStage(task.Stage) || task.Repo != "amadan.net/oficina/sample" { |
| 120 | t.Fatal("abandon ended without proof or moved", task) |
| 121 | } |
| 122 | p.fits("abandoned move stopping") |
| 123 | r.step("abandoned-push", wire.StepReport{TaskID: id, StepID: old.StepID, Attempt: old.Attempt, State: wire.StepDone, Pushed: true, BaseSHA: baseX, CandidateSHA: candX}) |
| 124 | p.wait(`document.body.textContent.includes('after the move was abandoned.')`, "late push history") |
| 125 | p.check(`document.querySelector('[data-stage-line]').textContent==='Stopping…'`, "push is not termination proof") |
| 126 | r.step("abandoned-proof", wire.StepReport{TaskID: id, StepID: old.StepID, Attempt: old.Attempt, State: wire.StepCancelled, Termination: true}) |
| 127 | p.wait(`document.querySelector('[data-stage-line]').textContent==='Cancelled.'`, "cancelled after proof") |
| 128 | if task := r.task(id); task.Stopping || task.Stage != wire.StageCancelled || task.CandidateSHA != "" { |
| 129 | t.Fatal("proof did not settle history-only task", task) |
| 130 | } |
| 131 | p.shot(fmt.Sprintf("placement-review-abandoned-%d-%s", width, scheme)) |
| 132 | }) |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |