//go:build browser package thintest import ( "context" "os" "path/filepath" "strings" "testing" "time" "amadan.net/oficina/equipo/internal/wire" "github.com/chromedp/chromedp" ) // TestBrowserTrackPulse: the stage track's current stop pulses while a // specialist works on it, on the conversation's report card and on the // task page, and is still while the task waits or nothing runs. Reduced // motion keeps a still ring. A step starting and stopping starts and // stops the pulse live, with no reload. func TestBrowserTrackPulse(t *testing.T) { g := newGallery(t) a := g.a report := func(id string) string { return `document.querySelector('[equipo-roster-report] [data-track-task="` + id + `"]')` } cur := func(track string) string { return track + `?.querySelector('[aria-current="step"]')` } ring := func(track string) string { return `getComputedStyle(` + cur(track) + `.querySelector('[equipo-dot]'),'::before')` } cue := func(track string) string { return `getComputedStyle(` + cur(track) + `.querySelector('[data-working-cue]')).display` } for _, motion := range []string{"no-preference", "reduce"} { for _, scheme := range []string{"light", "dark"} { t.Run(motion+"-"+scheme, func(t *testing.T) { p := openInner(t, a.inst.URL, a.inst.Cookie(), 1280, 900, false, scheme, motion) defer p.stop() p.open("/conversation") run := report(g.running) p.wait(cur(run), "the running task's report") p.check(cur(run)+`.hasAttribute('data-working') && `+cue(run)+`!=='none'`, "the running stop is not working") p.check(`(()=>{const w=[...document.querySelectorAll('[equipo-roster-report] [data-track] [data-working]')];return w.length>0 && w.every(li=>li.matches('[aria-current="step"]') && ['`+g.running+`','`+g.merging+`'].includes(li.parentElement.dataset.trackTask))})()`, "a stop with nobody at work pulses") p.check(`[...document.querySelectorAll('[equipo-roster-report] [data-track] [aria-current="step"]:not([data-working])')].every(li=>getComputedStyle(li.querySelector('[equipo-dot]'),'::before').content==='none' && getComputedStyle(li.querySelector('[data-working-cue]')).display==='none')`, "an idle stop draws the ring or the cue") if motion == "reduce" { p.check(ring(run)+`.animationName==='none' && `+ring(run)+`.opacity==='0.6' && `+ring(run)+`.transform!=='none'`, "reduced motion lost the still ring") p.check(`getComputedStyle(`+cur(run)+`.previousElementSibling,'::before').animationName==='none'`, "the line moves under reduced motion") } else { p.check(ring(run)+`.animationName==='equipo-tl-ring' && `+ring(run)+`.animationDuration==='2.4s'`, "the working stop does not pulse") p.check(`getComputedStyle(`+cur(run)+`.previousElementSibling,'::before').animationName==='equipo-tl-flow'`, "the line into the working stop is still") p.check(`document.getAnimations().filter(x=>x.animationName==='equipo-tl-ring').every(x=>x.startTime===0)`, "pulses out of phase") } // The task page's track: the living mark, and the ring. p.open("/tasks/" + g.running) full := `document.querySelector('[equipo-track-full]')` p.check(cur(full)+`.hasAttribute('data-working') && !!`+cur(full)+`.querySelector('[equipo-mark]') && `+cue(full)+`!=='none'`, "the task page's stop is not working") if motion == "reduce" { p.check(ring(full)+`.animationName==='none' && `+ring(full)+`.opacity==='0.6'`, "task page: reduced motion lost the still ring") } else { p.check(ring(full)+`.animationName==='equipo-tl-ring'`, "task page: the working stop does not pulse") } }) } } // Live, light and dark side by side: a new task's step queues, runs // and stops, and its card's pulse follows with no reload. pages := map[string]*innerPage{} for _, scheme := range []string{"light", "dark"} { p := openInner(t, a.inst.URL, a.inst.Cookie(), 1280, 900, false, scheme, "no-preference") defer p.stop() pages[scheme] = p } each := func(f func(scheme string, p *innerPage)) { for _, scheme := range []string{"light", "dark"} { f(scheme, pages[scheme]) } } task := taskID(t, a.call("tp-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/equipo", "title": "Keep the filter when the list refreshes", "brief": "The task filter resets when the list refreshes itself.", "separate": true})) track := report(task) card := `[data-card]:has([data-track-task="` + task + `"])` show := `(()=>{` + cur(track) + `.closest('[data-card]').scrollIntoView({block:'center'});return true})()` each(func(_ string, p *innerPage) { p.open("/conversation") p.wait(cur(track), "the new task's report") p.check(`!`+cur(track)+`.hasAttribute('data-working') && `+ring(track)+`.content==='none'`, "a noted task pulses") }) a.call("tp-start", wire.ToolStartTask, map[string]string{"task": task, "brief": "Keep the filter."}) _, body := a.expect(wire.FrameDispatch) d := body.(*wire.DispatchCommand) each(func(_ string, p *innerPage) { p.wait(cur(track)+`?.hasAttribute('data-working')`, "the queued step's pulse") }) a.step("tp-run", wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: strings.Repeat("8", 40), Family: "claude", Account: "claude-a"}) each(func(scheme string, p *innerPage) { p.wait(cur(track)+`?.hasAttribute('data-working') && `+cur(track)+`.textContent.startsWith('In progress')`, "the running step's pulse") p.check(ring(track)+`.animationName==='equipo-tl-ring'`, "the running card does not pulse") p.check(show, "show the card") p.cardShot(card, "track-pulse-running-"+scheme) }) a.step("tp-fail", wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true}) each(func(scheme string, p *innerPage) { p.wait(cur(track)+` && !`+cur(track)+`.hasAttribute('data-working') && `+ring(track)+`.content==='none' && `+cue(track)+`==='none'`, "the pulse stopped") p.stayed("conversation") p.check(show, "show the card") p.cardShot(card, "track-pulse-idle-"+scheme) }) } // cardShot saves the element sel at twice its size when // EQUIPO_BROWSER_ARTIFACTS names a directory. func (p *innerPage) cardShot(sel, name string) { p.t.Helper() dir := os.Getenv("EQUIPO_BROWSER_ARTIFACTS") if dir == "" { return } // A live refresh may swap the card mid-capture: settle, then retry. var buf []byte var err error for try := 0; try < 4; try++ { time.Sleep(700 * time.Millisecond) err = chromedp.Do(p.ctx, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error buf, err = chromedp.ScreenshotScale(chromedp.CSS(sel), 2)(ctx, target) return err })) if err == nil { break } } if err != nil { p.t.Fatal(err) } if err := os.MkdirAll(dir, 0700); err != nil { p.t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, name+".png"), buf, 0600); err != nil { p.t.Fatal(err) } }