//go:build browser package thintest import ( "encoding/json" "strings" "testing" "time" "amadan.net/oficina/equipo/internal/wire" ) // TestBrowserPausedWork (spec 2026-11-24-paused-work-design.md): Paul's // case in the browser. Engineering is held for the Claude allowance and // Codex has room. On the conversation's report card and on the task // page, in light and dark, on a desktop and a phone: the current stop // says Paused in indigo, still, with its stage kept for screen readers; // the lead says until when in the browser's own zone (which zone.js told // Equipo) and relative, never UTC; the text keeps AA contrast on the // pause's ground; and Run it now with Codex is on the card and writes // Run now's release. Set EQUIPO_BROWSER_ARTIFACTS for the screenshots. func TestBrowserPausedWork(t *testing.T) { r := newToolRigAt(t, wire.ProtocolCurrent) reset := time.Now().Add(9*time.Hour + 30*time.Second).UTC().Truncate(time.Minute) // Never on local midnight, which reads "midnight" (review N11). if madrid, _ := time.LoadLocation("Europe/Madrid"); reset.In(madrid).Hour() == 0 && reset.In(madrid).Minute() == 0 { reset = reset.Add(time.Minute) } var runner string if err := r.inst.DB.Writer().QueryRow("SELECT runner_id FROM runner_sessions LIMIT 1").Scan(&runner); err != nil { t.Fatal(err) } at := time.Now().UTC() for _, c := range []struct { id, local, provider, state string used float64 resets time.Time }{{"cn_claude", "claude-1", "claude", wire.ConnLimited, 100, reset}, {"cn_codex", "codex-1", "codex", wire.ConnHealthy, 12, reset.Add(72 * time.Hour)}} { h, _ := json.Marshal(wire.Headroom{ResetsAt: &c.resets, Windows: []wire.Window{{Name: "five_hour", UsedPercent: c.used, Minutes: 300, ResetsAt: &c.resets}}}) 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,?,?)", c.id, Owner, runner, c.local, c.provider, wire.KindToken, "", c.state, string(h), at, at); err != nil { t.Fatal(err) } } // Every other connection the rig has is at its limit, with no reset. if _, err := r.inst.DB.Writer().Exec("UPDATE chat_connections SET state = ? WHERE id NOT IN ('cn_claude', 'cn_codex')", wire.ConnLimited); err != nil { t.Fatal(err) } 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"})) r.call("pw2", wire.ToolStartTask, map[string]string{"task": id, "brief": "go"}) _, body := r.expect(wire.FrameDispatch) d := body.(*wire.DispatchCommand) r.hold("pw-hold", d, wire.StepHold{Reason: wire.HoldHeadroom, Connection: "claude-1", Provider: "claude", ResetsAt: &reset, WakeAt: &reset, StepRevision: 1}) madrid, _ := time.LoadLocation("Europe/Madrid") local := reset.In(madrid).Format("15:04") card := `document.querySelector('[equipo-roster-report] [data-track-task="` + id + `"]')?.closest('[equipo-roster-report]')` 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)})()` for _, scheme := range []string{"light", "dark"} { for _, phone := range []bool{false, true} { name := scheme w, h := int64(1280), int64(900) if phone { name, w, h = scheme+"-phone", 390, 844 } t.Run(name, func(t *testing.T) { p := openInner(t, r.inst.URL, r.inst.Cookie(), w, h, phone, scheme, "no-preference") defer p.stop() p.timezone("Europe/Madrid") p.open("/conversation") // zone.js tells Equipo the browser's zone; the next draw uses it. deadline := time.Now().Add(8 * time.Second) for r.inst.Store.Chat().Zone(Owner).String() != "Europe/Madrid" { if time.Now().After(deadline) { t.Fatal("zone.js did not send the browser's zone") } time.Sleep(40 * time.Millisecond) } p.open("/conversation") p.wait(card, "the report card") cur := card + `.querySelector('[aria-current="step"]')` 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") p.check(`getComputedStyle(`+cur+`.querySelector('[equipo-dot]'),'::after').backgroundImage.includes('linear-gradient')`, "the paused dot has no pause mark") lead := card + `.querySelector('[equipo-pause-lead]').textContent` // "21:00 tonight", or "tomorrow at 00:15" past midnight in Madrid. 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") p.check(card+`.querySelector('strong').textContent.startsWith('Paused until ') && `+card+`.querySelector('strong').textContent.includes('`+local+`') && !`+card+`.querySelector('strong').textContent.includes('.')`, "the bold time phrase") 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") p.check(`!`+card+`.querySelector('[equipo-roster-stage]')`, "the eyebrow repeats the pause") if min := eval[float64](p, strings.ReplaceAll(contrast, "SCOPE", card)); min < 4.5 { t.Fatalf("contrast %.2f below AA on the report card (%s)", min, name) } p.shot("paused-report-" + name) p.open("/tasks/" + id) page := `document.querySelector('[equipo-task-page]')` p.wait(page+`?.querySelector('[equipo-pause]')`, "the task page's pause") p.check(page+`.querySelector('[aria-current="step"]').dataset.tone==='paused' && `+page+`.querySelector('[equipo-pause-lead]').textContent.includes('`+local+`')`, "the task page is not paused") if min := eval[float64](p, strings.ReplaceAll(contrast, "SCOPE", page)); min < 4.5 { t.Fatalf("contrast %.2f below AA on the task page (%s)", min, name) } p.shot("paused-task-" + name) }) } } // Run it now with Codex, from the conversation's card: Run now's // release for the held step. p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") defer p.stop() p.open("/conversation") p.wait(card, "the report card") p.check(`(()=>{const b=`+card+`.querySelector('[data-pause-act="run-now"]');b.click();return true})()`, "click Run it now") deadline := time.Now().Add(8 * time.Second) for r.frames(wire.FrameRelease) != 1 { if time.Now().After(deadline) { t.Fatal("Run it now with Codex wrote no release") } time.Sleep(40 * time.Millisecond) } }