| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "encoding/json" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "amadan.net/oficina/equipo/internal/wire" |
| 12 | ) |
| 13 | |
| 14 | // TestBrowserPausedWork (spec 2026-11-24-paused-work-design.md): Paul's |
| 15 | // case in the browser. Engineering is held for the Claude allowance and |
| 16 | // Codex has room. On the conversation's report card and on the task |
| 17 | // page, in light and dark, on a desktop and a phone: the current stop |
| 18 | // says Paused in indigo, still, with its stage kept for screen readers; |
| 19 | // the lead says until when in the browser's own zone (which zone.js told |
| 20 | // Equipo) and relative, never UTC; the text keeps AA contrast on the |
| 21 | // pause's ground; and Run it now with Codex is on the card and writes |
| 22 | // Run now's release. Set EQUIPO_BROWSER_ARTIFACTS for the screenshots. |
| 23 | func TestBrowserPausedWork(t *testing.T) { |
| 24 | r := newToolRigAt(t, wire.ProtocolCurrent) |
| 25 | reset := time.Now().Add(9*time.Hour + 30*time.Second).UTC().Truncate(time.Minute) |
| 26 | // Never on local midnight, which reads "midnight" (review N11). |
| 27 | if madrid, _ := time.LoadLocation("Europe/Madrid"); reset.In(madrid).Hour() == 0 && reset.In(madrid).Minute() == 0 { |
| 28 | reset = reset.Add(time.Minute) |
| 29 | } |
| 30 | var runner string |
| 31 | if err := r.inst.DB.Writer().QueryRow("SELECT runner_id FROM runner_sessions LIMIT 1").Scan(&runner); err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | at := time.Now().UTC() |
| 35 | for _, c := range []struct { |
| 36 | id, local, provider, state string |
| 37 | used float64 |
| 38 | resets time.Time |
| 39 | }{{"cn_claude", "claude-1", "claude", wire.ConnLimited, 100, reset}, {"cn_codex", "codex-1", "codex", wire.ConnHealthy, 12, reset.Add(72 * time.Hour)}} { |
| 40 | h, _ := json.Marshal(wire.Headroom{ResetsAt: &c.resets, Windows: []wire.Window{{Name: "five_hour", UsedPercent: c.used, Minutes: 300, ResetsAt: &c.resets}}}) |
| 41 | if _, err := r.inst.DB.Writer().Exec("INSERT INTO chat_connections(id, person, runner_id, local_id, provider, kind, label, state, headroom, revision, created_at, updated_at) VALUES (?,?,?,?,?,?,?,?,?,1,?,?)", |
| 42 | c.id, Owner, runner, c.local, c.provider, wire.KindToken, "", c.state, string(h), at, at); err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | } |
| 46 | // Every other connection the rig has is at its limit, with no reset. |
| 47 | if _, err := r.inst.DB.Writer().Exec("UPDATE chat_connections SET state = ? WHERE id NOT IN ('cn_claude', 'cn_codex')", wire.ConnLimited); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | id := taskID(t, r.call("pw1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Swipe down to dismiss the keyboard on iOS", "brief": "b"})) |
| 51 | r.call("pw2", wire.ToolStartTask, map[string]string{"task": id, "brief": "go"}) |
| 52 | _, body := r.expect(wire.FrameDispatch) |
| 53 | d := body.(*wire.DispatchCommand) |
| 54 | r.hold("pw-hold", d, wire.StepHold{Reason: wire.HoldHeadroom, Connection: "claude-1", Provider: "claude", ResetsAt: &reset, WakeAt: &reset, StepRevision: 1}) |
| 55 | |
| 56 | madrid, _ := time.LoadLocation("Europe/Madrid") |
| 57 | local := reset.In(madrid).Format("15:04") |
| 58 | card := `document.querySelector('[equipo-roster-report] [data-track-task="` + id + `"]')?.closest('[equipo-roster-report]')` |
| 59 | contrast := `(()=>{const rgb=c=>c.match(/[\d.]+/g).slice(0,3).map(Number).map(v=>{v/=255;return v<=0.03928?v/12.92:Math.pow((v+0.055)/1.055,2.4)});const L=c=>{const [r,g,b]=rgb(c);return 0.2126*r+0.7152*g+0.0722*b};const ratio=(a,b)=>{const x=L(a),y=L(b);return (Math.max(x,y)+0.05)/(Math.min(x,y)+0.05)};const box=SCOPE.querySelector('[equipo-pause]');const bg=getComputedStyle(box).backgroundColor;const out=[...box.querySelectorAll('strong,[equipo-pause-lead],[equipo-pause-next],small')].map(el=>ratio(getComputedStyle(el).color,bg));const stop=SCOPE.querySelector('[aria-current="step"] > span:not([equipo-dot])');out.push(ratio(getComputedStyle(stop).color,getComputedStyle(document.body).backgroundColor));return Math.min(...out)})()` |
| 60 | for _, scheme := range []string{"light", "dark"} { |
| 61 | for _, phone := range []bool{false, true} { |
| 62 | name := scheme |
| 63 | w, h := int64(1280), int64(900) |
| 64 | if phone { |
| 65 | name, w, h = scheme+"-phone", 390, 844 |
| 66 | } |
| 67 | t.Run(name, func(t *testing.T) { |
| 68 | p := openInner(t, r.inst.URL, r.inst.Cookie(), w, h, phone, scheme, "no-preference") |
| 69 | defer p.stop() |
| 70 | p.timezone("Europe/Madrid") |
| 71 | p.open("/conversation") |
| 72 | // zone.js tells Equipo the browser's zone; the next draw uses it. |
| 73 | deadline := time.Now().Add(8 * time.Second) |
| 74 | for r.inst.Store.Chat().Zone(Owner).String() != "Europe/Madrid" { |
| 75 | if time.Now().After(deadline) { |
| 76 | t.Fatal("zone.js did not send the browser's zone") |
| 77 | } |
| 78 | time.Sleep(40 * time.Millisecond) |
| 79 | } |
| 80 | p.open("/conversation") |
| 81 | p.wait(card, "the report card") |
| 82 | cur := card + `.querySelector('[aria-current="step"]')` |
| 83 | p.check(cur+`.dataset.tone==='paused' && !`+cur+`.hasAttribute('data-working') && `+cur+`.textContent.includes('Paused') && `+cur+`.textContent.includes('In progress')`, "the stop is not Paused, still, with its stage") |
| 84 | p.check(`getComputedStyle(`+cur+`.querySelector('[equipo-dot]'),'::after').backgroundImage.includes('linear-gradient')`, "the paused dot has no pause mark") |
| 85 | lead := card + `.querySelector('[equipo-pause-lead]').textContent` |
| 86 | // "21:00 tonight", or "tomorrow at 00:15" past midnight in Madrid. |
| 87 | p.check(lead+`.startsWith('Paused until ') && `+lead+`.includes('`+local+`') && `+lead+`.includes('(in 9 hours): your Claude allowance has run out.') && !`+lead+`.includes('UTC')`, "the lead is not Paul's, in Madrid") |
| 88 | p.check(card+`.querySelector('strong').textContent.startsWith('Paused until ') && `+card+`.querySelector('strong').textContent.includes('`+local+`') && !`+card+`.querySelector('strong').textContent.includes('.')`, "the bold time phrase") |
| 89 | p.check(card+`.querySelector('[data-pause-act="run-now"]').textContent==='Run it now with Codex' && `+card+`.querySelector('[equipo-pause-act] small').textContent==='Codex has room now'`, "the action does not name Codex") |
| 90 | p.check(`!`+card+`.querySelector('[equipo-roster-stage]')`, "the eyebrow repeats the pause") |
| 91 | if min := eval[float64](p, strings.ReplaceAll(contrast, "SCOPE", card)); min < 4.5 { |
| 92 | t.Fatalf("contrast %.2f below AA on the report card (%s)", min, name) |
| 93 | } |
| 94 | p.shot("paused-report-" + name) |
| 95 | p.open("/tasks/" + id) |
| 96 | page := `document.querySelector('[equipo-task-page]')` |
| 97 | p.wait(page+`?.querySelector('[equipo-pause]')`, "the task page's pause") |
| 98 | p.check(page+`.querySelector('[aria-current="step"]').dataset.tone==='paused' && `+page+`.querySelector('[equipo-pause-lead]').textContent.includes('`+local+`')`, "the task page is not paused") |
| 99 | if min := eval[float64](p, strings.ReplaceAll(contrast, "SCOPE", page)); min < 4.5 { |
| 100 | t.Fatalf("contrast %.2f below AA on the task page (%s)", min, name) |
| 101 | } |
| 102 | p.shot("paused-task-" + name) |
| 103 | }) |
| 104 | } |
| 105 | } |
| 106 | // Run it now with Codex, from the conversation's card: Run now's |
| 107 | // release for the held step. |
| 108 | p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") |
| 109 | defer p.stop() |
| 110 | p.open("/conversation") |
| 111 | p.wait(card, "the report card") |
| 112 | p.check(`(()=>{const b=`+card+`.querySelector('[data-pause-act="run-now"]');b.click();return true})()`, "click Run it now") |
| 113 | deadline := time.Now().Add(8 * time.Second) |
| 114 | for r.frames(wire.FrameRelease) != 1 { |
| 115 | if time.Now().After(deadline) { |
| 116 | t.Fatal("Run it now with Codex wrote no release") |
| 117 | } |
| 118 | time.Sleep(40 * time.Millisecond) |
| 119 | } |
| 120 | } |
| 121 | |