oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package thintest
4
5import (
6 "strings"
7 "testing"
8
9 "amadan.net/oficina/equipo/internal/wire"
10)
11
12// TestBrowserTryAgain: a reply fails while the conversation is open. The
13// note comes from the event at once, then says why in the server's words,
14// with the account and Try again. Try again goes in place, with no
15// reload: the note and its button go, the thinking line comes, and the
16// runner has the same message again, sent once. Without scripts Try again
17// is a form post (TestContractRetryAnswersAgain). Tried again from
18// another device, the open page drops the note as the retry starts. Saved as
19// try-again-<width>.png when EQUIPO_BROWSER_ARTIFACTS names a directory.
20func TestBrowserTryAgain(t *testing.T) {
21 r, runner := retryRig(t, nil)
22 p := openInner(t, r.inst.URL, r.inst.Cookie(), 390, 844, true, "light", "no-preference")
23 defer p.stop()
24 p.open("/conversation")
25 p.wait(`document.querySelector('[data-chat-stream]')`, "the conversation")
26 const words = "Where is the login bug?"
27 failed := r.say(runner, words, "k1").TurnID
28 r.failOn(runner, failed, "provider_failed", "claude-a")
29 note := `document.querySelector('[data-ended=` + jsString(failed) + `]')`
30 p.wait(`(`+note+`?.querySelector('p')||{}).textContent===`+jsString("Claude (owner@example.com) stopped before finishing the reply. Try again.")+` && !!`+note+`.querySelector('button[data-retry-turn]')`, "the note's reason, account and Try again")
31 p.check(`(b=>b.textContent==='Try again' && b.getBoundingClientRect().height>0 && b.getBoundingClientRect().width>0)(`+note+`.querySelector('[data-retry-turn]'))`, "Try again is not visible")
32 p.fits("the failed reply's note")
33 p.shot("try-again-390")
34 p.click(`[data-retry-turn]`)
35 cmd := r.running(runner)
36 if cmd.TurnID == failed || strings.Join(cmd.PersonText, "|") != words {
37 t.Fatalf("Try again sent %s %q", cmd.TurnID, cmd.PersonText)
38 }
39 p.wait(`!document.querySelector('[data-ended]') && !document.querySelector('[data-retry-turn]') && !!document.querySelector('[equipo-thinking][data-turn=`+jsString(cmd.TurnID)+`]')`, "the note gone and the thinking line there")
40 p.check(`[...document.querySelectorAll('[equipo-message="own"] [equipo-message-body]')].filter(e=>e.textContent===`+jsString(words)+`).length===1`, "the message shows twice, or not at all")
41 p.stayed("Try again")
42 if n := r.count("SELECT count(*) FROM chat_turns WHERE retry_of = ?", failed); n != 1 {
43 t.Fatalf("%d retries queued", n)
44 }
45 // It fails again, and another device tries again: the open page
46 // follows, the note going as the retry starts.
47 r.failOn(runner, cmd.TurnID, "turn_timeout", "")
48 again := `document.querySelector('[data-ended=` + jsString(cmd.TurnID) + `] [data-retry-turn]')`
49 p.wait(again, "the failed retry's Try again")
50 if _, err := r.client.Retry(r.ctx, cmd.TurnID); err != nil {
51 t.Fatal(err)
52 }
53 p.wait(`!document.querySelector('[data-ended]')`, "the note gone when another device tried again")
54 p.stayed("another device's Try again")
55}
56
57// TestBrowserEndedNoteStaysGone: a reply fails, then the next message
58// waits for a connection. The note goes as that turn starts, and the
59// refresh that brings the connection card does not bring it back.
60func TestBrowserEndedNoteStaysGone(t *testing.T) {
61 r, runner := retryRig(t, nil)
62 p := openInner(t, r.inst.URL, r.inst.Cookie(), 390, 844, true, "light", "no-preference")
63 defer p.stop()
64 p.open("/conversation")
65 p.wait(`document.querySelector('[data-chat-stream]')`, "the conversation")
66 failed := r.say(runner, "First", "k1").TurnID
67 r.failOn(runner, failed, "turn_timeout", "")
68 p.wait(`document.querySelector('[data-ended=`+jsString(failed)+`] [data-retry-turn]')`, "the failed reply's note")
69 waiting := r.say(runner, "Second", "k2").TurnID
70 runner.Send(r.ctx, "w-"+waiting, wire.FrameTurn, wire.TurnReport{TurnID: waiting, Attempt: 1, State: wire.TurnWaiting, Reason: wire.ReasonNoConnection})
71 p.wait(`!!document.querySelector('[data-no-connection]') && !document.querySelector('[data-ended]')`, "the connection card, and no note")
72 p.check(`!document.querySelector('[data-ended]')`, "the note came back")
73 p.stayed("waiting for a connection")
74}
75