| index 4ad2f348..18bf77d5 100644 |
| --- a/internal/thintest/thinking_browser_test.go |
| +++ b/internal/thintest/thinking_browser_test.go |
| @@ -3,11 +3,15 @@ |
| package thintest |
| |
| import ( |
| + "context" |
| "encoding/json" |
| "fmt" |
| "testing" |
| |
| "amadan.net/oficina/equipo/internal/wire" |
| + "github.com/chromedp/cdproto/cdp" |
| + "github.com/chromedp/cdproto/page" |
| + "github.com/chromedp/chromedp" |
| ) |
| |
| // TestBrowserThinkingWords: the Thinking words page previews the chosen |
| @@ -45,11 +49,20 @@ func TestBrowserThinkingWords(t *testing.T) { |
| p.open("/settings/thinking") |
| preview := `document.querySelector('[data-preview-phrase]').textContent` |
| p.wait(anyOf("professional")+`.includes(`+preview+`)`, "the preview shows Professional") |
| + // Picking a set saves it at once (Paul, iPhone: the button below was |
| + // easy to miss, and the line kept the default). |
| p.check(`(()=>{document.querySelector('[data-set="pirate"] label').click();return document.querySelector('input[value="pirate"]').checked})()`, "pick Pirate adventure") |
| - p.wait(anyOf("pirate")+`.includes(`+preview+`)`, "the preview shows Pirate adventure at once") |
| + p.wait(`location.search.includes('saved=1') && document.querySelector('input[value="pirate"]').checked && document.querySelector('[equipo-saved]')`, "picking saved the set") |
| + p.wait(anyOf("pirate")+`.includes(`+preview+`)`, "the preview shows Pirate adventure") |
| p.check(`document.querySelector('[data-preview-line]').dataset.set==='pirate'`, "preview set") |
| + if got, _ := r.client.Thinking(r.ctx); got.Set != "pirate" { |
| + t.Fatalf("saved %s", got.Set) |
| + } |
| p.shot(fmt.Sprintf("ux1-thinking-words-%d", size.w)) |
| - p.stayed("preview") |
| + cur, _ := r.client.Thinking(r.ctx) |
| + if _, err := r.client.SetThinking(r.ctx, "professional", cur.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| p.stop() |
| } |
| |
| @@ -60,6 +73,7 @@ func TestBrowserThinkingWords(t *testing.T) { |
| line := `document.querySelector('[equipo-thinking][data-turn="` + r.turn + `"]')` |
| phrase := line + `?.querySelector('[equipo-phrase] [data-in]')?.textContent` |
| p.wait(in("professional", "think")+`.includes(`+phrase+`)`, "Professional while thinking") |
| + _ = p |
| cur, _ := r.client.Thinking(r.ctx) |
| if _, err := r.client.SetThinking(r.ctx, "galaxy", cur.Revision); err != nil { |
| t.Fatal(err) |
| @@ -81,3 +95,76 @@ func TestBrowserThinkingWords(t *testing.T) { |
| p.wait(`(()=>{const l=`+line+`;const s=l?.dataset.thinkingWords;const all={professional:`+in("professional", "search")+`,playful:`+in("playful", "search")+`,galaxy:`+in("galaxy", "search")+`,bridge:`+in("bridge", "search")+`,pirate:`+in("pirate", "search")+`,terminal:`+in("terminal", "search")+`};return !!s && s!=='random' && (all[s]||[]).includes(`+phrase+`)})()`, "Random took one set for the turn") |
| p.stayed("conversation") |
| } |
| + |
| +// TestBrowserThinkingCycles: Paul, staging f2602d3, an iPhone: "Still says |
| +// 'Thinking' for me. Shouldn't it cycle if it goes over a waiting |
| +// threshold?" With a fake clock: the first phrase holds until about 3 s, |
| +// then the set's phrases come one after another, every 3 to 4 s, never |
| +// the same twice in a row; a new activity switches to its own phrases at |
| +// once (a situation with only two adds the thinking ones); under reduced |
| +// motion the words still change. |
| +func TestBrowserThinkingCycles(t *testing.T) { |
| + r := newToolRig(t) |
| + words, _ := r.client.Thinking(r.ctx) |
| + var think, read []string |
| + for _, s := range words.Sets { |
| + if s.ID == wire.DefaultThinking { |
| + think, read = s.Phrases["think"], s.Phrases["read"] |
| + } |
| + } |
| + js := func(v any) string { raw, _ := json.Marshal(v); return string(raw) } |
| + for _, motion := range []string{"no-preference", "reduce"} { |
| + p := openInner(t, r.inst.URL, r.inst.Cookie(), 390, 844, true, "dark", motion) |
| + p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| + _, err := cdp.Call(ctx, target, page.AddScriptToEvaluateOnNewDocument, page.AddScriptToEvaluateOnNewDocumentParams{Source: `(()=>{const real=Date.now.bind(Date);window.__skew=0;Date.now=()=>real()+window.__skew;})()`}) |
| + return err |
| + })) |
| + p.open("/conversation") |
| + line := `document.querySelector('[equipo-thinking][data-turn="` + r.turn + `"]')` |
| + phrase := line + `?.querySelector('[equipo-phrase] [data-in]')?.textContent` |
| + p.wait(phrase+`===`+js(think[0]), "the first thinking phrase") |
| + p.check(phrase+`===`+js(think[0]), "changed before the threshold") |
| + seen := []string{think[0]} |
| + for i := 0; i < 7; i++ { |
| + skew := 4100 |
| + if i == 0 { |
| + skew = 3100 |
| + } |
| + p.check(fmt.Sprintf(`(()=>{window.__skew+=%d;return true})()`, skew), "advance the clock") |
| + p.wait(phrase+`!==`+js(seen[len(seen)-1])+` && `+js(think)+`.includes(`+phrase+`)`, fmt.Sprintf("phrase %d after the threshold", i+1)) |
| + seen = append(seen, eval[string](p, phrase)) |
| + } |
| + distinct := map[string]bool{} |
| + for i, s := range seen { |
| + distinct[s] = true |
| + if i > 0 && s == seen[i-1] { |
| + t.Fatalf("%s: the same phrase twice in a row: %v", motion, seen) |
| + } |
| + } |
| + if len(distinct) != len(think) { |
| + t.Fatalf("%s: not every phrase came round: %v", motion, seen) |
| + } |
| + // A new activity: its own phrases at once, then (only two of its |
| + // own) the thinking ones join the rotation. |
| + if err := r.runner.Send(r.ctx, "cyc-read-"+motion, wire.FrameActivity, wire.ActivityReport{TurnID: r.turn, Attempt: 1, Kind: wire.ActivityTool, Tool: wire.ToolReadFile}); err != nil { |
| + t.Fatal(err) |
| + } |
| + p.wait(phrase+`===`+js(read[0]), "the reading phrase at once") |
| + pool := append(append([]string{}, read...), think...) |
| + last := read[0] |
| + for i := 0; i < 5; i++ { |
| + p.check(`(()=>{window.__skew+=4100;return true})()`, "advance the clock") |
| + p.wait(phrase+`!==`+js(last)+` && `+js(pool)+`.includes(`+phrase+`)`, "reading cycles with the thinking phrases") |
| + last = eval[string](p, phrase) |
| + } |
| + if motion == "reduce" { |
| + p.check(`getComputedStyle(document.querySelector('[equipo-sparkle] path')).animationName==='none'`, "the mark moves under reduced motion") |
| + } |
| + p.stayed("conversation") |
| + p.stop() |
| + // The next pass starts from the thinking situation again. |
| + if err := r.runner.Send(r.ctx, "cyc-think-"+motion, wire.FrameActivity, wire.ActivityReport{TurnID: r.turn, Attempt: 1, Kind: wire.ActivityThink}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| +} |