oficina / equipo Public

Conversation: the coordinator's line appears the moment you send

The thinking line used to wait for the server's turn event. Now the send
inserts it at once (same element, Stardust, phrases, a timer from 0),
before any network answer. The turn adopts that element in place: from
its event, a delta or activity, a refresh that shows it, or the send's
answer naming the turn. If the message joined an earlier queued turn,
or the turn is over, the line goes. A turn waiting for a connection
gives the line up for the quiet waiting state, and a failed send
removes it beside the existing error (Retry shows it again). It works
the same with attachments still uploading and for task-thread asks.

TestBrowserInstantThinking (instant then adopted on a fake clock, an
attachment, a failed send, no connection) and
TestBrowserInstantThinkingQueued (a third message joins a queued turn:
one line per turn, the original elements) fail on the old script and
catch three mutations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 22f92a7f709ed3101a14fd01c0f9fa4c3ac5ea89 parent 0285479
2 files changed, +336 −10
  • internal/equipo/static/chat-stream.js +109 −10
  • internal/thintest/instant_browser_test.go +227 −0

CI passed — run details

diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js
index 99a04820..299ef9ea 100644
--- a/internal/equipo/static/chat-stream.js
+++ b/internal/equipo/static/chat-stream.js
@@ -90,7 +90,9 @@
var set = root.dataset.thinkingSet || "professional";
if (set !== "random") return set;
var ids = Object.keys(WORDS).filter(function (k) { return k !== "random" && Object.keys(WORDS[k] || {}).length; }).sort();
- var turn = li.dataset.turn || "", h = 0;
+ // An optimistic line keeps the seed it started with when its turn
+ // adopts it, so the words never switch mid-line.
+ var turn = li.seed || li.dataset.turn || "", h = 0;
for (var i = 0; i < turn.length; i++) h = (h * 31 + turn.charCodeAt(i)) >>> 0;
return ids.length ? ids[h % ids.length] : "professional";
}
@@ -308,7 +310,13 @@
// kind is a turn the coordinator takes on its own (move_in, explore):
// its line says so before any activity arrives.
function bubble(turn, kind) {
- var el = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(turn) + '"]');
+ var el = lineFor(turn);
+ if (!el && !kind && pending.length) {
+ // The line shown since the send becomes this turn's, in place.
+ el = pending[0];
+ adopt(el, turn);
+ return el;
+ }
if (!el) {
el = template("equipo-thinking-template");
el.dataset.turn = turn;
@@ -328,6 +336,63 @@
}
return el;
}
+ // ── The line from the moment of sending ────────────────────────────
+ // A send shows the coordinator's line at once, before the server has
+ // answered: the same element, sparkle, phrases and timer (from 0) that
+ // the turn then adopts in place. pending holds the lines no turn has
+ // adopted yet, oldest first; ended the turns that are over or held, so a
+ // late answer to the send never adopts a line for them.
+ var pending = [], ended = {};
+ function lineFor(turn) {
+ return turn ? feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(turn) + '"]') : null;
+ }
+ function optimistic(who) {
+ // Nothing can answer: the server's quiet status says so instead.
+ if (!thread && feed.querySelector("[data-no-connection]")) return null;
+ var el = template("equipo-thinking-template");
+ el.dataset.turn = "";
+ el.setAttribute("data-optimistic", "");
+ el.seed = requestID();
+ var name = el.querySelector("[data-who]");
+ if (name && who) name.textContent = root.dataset["name" + who.charAt(0).toUpperCase() + who.slice(1)] || "";
+ el.dataset.started = String(Date.now());
+ pending.push(el);
+ feed.append(el);
+ enliven(el);
+ tick();
+ scroll(true);
+ return el;
+ }
+ function adopt(el, turn) {
+ var at = pending.indexOf(el);
+ if (at >= 0) pending.splice(at, 1);
+ el.removeAttribute("data-optimistic");
+ el.dataset.turn = turn;
+ }
+ function drop(el) {
+ if (!el) return;
+ var at = pending.indexOf(el);
+ if (at >= 0) pending.splice(at, 1);
+ el.remove();
+ }
+ // claim: the server named the turn (or, in a thread, the question) the
+ // send belongs to. A line still waiting is adopted, or goes when the turn
+ // already has one (the message joined an earlier queued turn) or is over.
+ function claim(el, turn) {
+ if (!el || !turn || !el.isConnected || !el.hasAttribute("data-optimistic")) return;
+ if (lineFor(turn) || ended[turn]) drop(el);
+ else adopt(el, turn);
+ }
+ // Who a thread question goes to, as ask-target.js shows it.
+ function askedOf() {
+ var chosen = form.querySelector("[data-ask-specialist]");
+ if (!chosen) return "";
+ if (chosen.value) return chosen.value;
+ var target = form.querySelector("[equipo-ask-target]");
+ var choices = ((target && target.dataset.choices) || "").split(",").filter(Boolean);
+ if (choices.indexOf("review") >= 0 && /\breview(?:er|ers|ed|ing|s)?\b/i.test(input.value)) return "review";
+ return choices[0] || "";
+ }
function atBottom() {
return box.scrollHeight - box.scrollTop - box.clientHeight < 48;
}
@@ -427,7 +492,7 @@
// A newly committed reply settles into its draft's element; a turn
// may already have earlier messages on the page.
var keep = {}, shown = {}, opened = {};
- feed.querySelectorAll("[equipo-thinking]").forEach(function (el) { keep[el.dataset.turn] = el; });
+ feed.querySelectorAll("[equipo-thinking]:not([data-optimistic])").forEach(function (el) { keep[el.dataset.turn] = el; });
// A receipt the person opened with ⋯ stays open.
feed.querySelectorAll("[equipo-receipt][data-open]").forEach(function (el) { opened[el.dataset.card] = true; });
next.querySelectorAll("[equipo-receipt]").forEach(function (el) {
@@ -441,11 +506,27 @@
var fresh = el.matches('[equipo-message="incoming"][data-turn-id]') && !shown[el.dataset.message];
var turn = el.hasAttribute("equipo-thinking") ? el.dataset.turn : fresh ? el.dataset.turnId : "";
var old = turn && keep[turn];
+ if (!old && el.hasAttribute("equipo-thinking") && !el.dataset.kind && pending.length && !ended[turn]) {
+ // The server shows the turn before its event came: the line
+ // shown since the send takes it, with the server's words.
+ old = pending[0];
+ adopt(old, turn);
+ var said = el.querySelector("[equipo-activity]"), mine = old.querySelector("[equipo-activity]");
+ if (said && mine && said.textContent !== mine.textContent) {
+ mine.textContent = said.textContent;
+ var line = old.querySelector("[equipo-activity-line]");
+ if (line) line.title = said.textContent;
+ }
+ var who = el.querySelector("[data-who]"), whoMine = old.querySelector("[data-who]");
+ if (who && whoMine && who.textContent) whoMine.textContent = who.textContent;
+ return old;
+ }
if (!old) return el;
delete keep[turn];
return el.hasAttribute("equipo-thinking") ? old : settle(old, el);
}));
local.forEach(function (el) { place(el); });
+ pending.forEach(function (el) { feed.append(el); });
Object.keys(drafts).forEach(function (turn) {
if (feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(turn) + '"]')) showDraft(turn);
});
@@ -469,7 +550,10 @@
if (type === "question") {
if (v.task_id !== thread) return;
asked[v.id] = v.specialist;
- if (v.state === "answered" || v.state === "failed" || v.state === "cancelled") delete drafts[v.id];
+ if (v.state === "answered" || v.state === "failed" || v.state === "cancelled") {
+ delete drafts[v.id];
+ ended[v.id] = true;
+ }
if (v.state === "running") {
// Its turn came: the waiting line becomes the thinking line.
var waiting = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]');
@@ -498,6 +582,7 @@
clearEmpty();
if (v.role === "coordinator") {
delete drafts[v.turn_id];
+ ended[v.turn_id] = true;
refreshSoon();
return;
}
@@ -515,10 +600,14 @@
// Nothing can answer yet: no thinking line, no timer; the quiet
// status and the one card are the server's.
delete drafts[v.id];
- var thinking = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]');
- if (thinking) thinking.remove();
+ var thinking = lineFor(v.id);
+ // The line shown since the send was this turn's: it goes too.
+ if (!thinking && !v.kind) thinking = pending[0];
+ drop(thinking);
+ ended[v.id] = true;
refreshSoon();
} else if (v.state === "queued" || v.state === "running" || v.state === "waiting") {
+ delete ended[v.id];
var shownDraft = bubble(v.id, v.kind);
if (drafts[v.id] && drafts[v.id].attempt !== v.attempt) {
// The refused attempt's words go; the next attempt's follow.
@@ -531,10 +620,12 @@
} else if (v.state === "replied" && !v.reply_id) {
// A turn that ended with nothing to say (an empty explore).
delete drafts[v.id];
+ ended[v.id] = true;
var quiet = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]');
if (quiet) quiet.remove();
} else if (v.state === "failed" || v.state === "cancelled") {
delete drafts[v.id];
+ ended[v.id] = true;
var el = feed.querySelector('[equipo-thinking][data-turn="' + CSS.escape(v.id) + '"]');
if (el) el.remove();
// A move-in that gave way to the person, or stopped, is not the
@@ -631,7 +722,7 @@
});
box.hidden = false;
}
- function post(el, text, id, extra, files) {
+ function post(el, text, id, extra, files, line) {
el.dataset.pending = "";
delete el.dataset.sendFailed;
var old = el.querySelector("[data-retry-send]");
@@ -645,6 +736,8 @@
.then(function (sent) {
local.delete(el);
delete el.dataset.pending;
+ // A conversation send names its turn; a thread question is its own.
+ claim(line, thread ? sent.message.id : sent.turn && sent.turn.id);
if (feed.querySelector('[data-message="' + CSS.escape(sent.message.id) + '"]')) {
el.remove();
return;
@@ -660,6 +753,8 @@
}
})
.catch(function () {
+ // Nothing was sent: no line waits for a reply.
+ drop(line);
delete el.dataset.pending;
el.dataset.sendFailed = "";
var retry = document.createElement("button");
@@ -667,7 +762,7 @@
retry.setAttribute("rst-btn", "");
retry.dataset.retrySend = "";
retry.textContent = form.dataset.retry;
- retry.addEventListener("click", function () { post(el, text, id, extra, files); });
+ retry.addEventListener("click", function () { post(el, text, id, extra, files, optimistic(extra.specialist)); });
el.querySelector("[equipo-bubble]").append(retry);
});
}
@@ -679,6 +774,7 @@
var waiting = attach ? attach.count() : 0;
if (!text && !waiting) return;
var taken = waiting ? attach.take() : null;
+ var who = thread ? askedOf() : "";
input.value = "";
input.focus();
var el = template("equipo-own-template");
@@ -690,6 +786,8 @@
local.add(el);
lastSend = Date.now();
place(el);
+ // The coordinator's line, now: nothing waits on the network.
+ var line = optimistic(who);
scroll(true);
// The form's other fields as they are now (who a question is for).
var extra = {};
@@ -705,12 +803,13 @@
if (!files.length && !text) {
local.delete(el);
el.remove();
+ drop(line);
return;
}
- post(el, text, id, extra, files.map(function (f) { return f.id; }));
+ post(el, text, id, extra, files.map(function (f) { return f.id; }), line);
});
} else {
- post(el, text, id, extra);
+ post(el, text, id, extra, undefined, line);
}
form.dispatchEvent(new CustomEvent("equipo:sent"));
}
diff --git a/internal/thintest/instant_browser_test.go b/internal/thintest/instant_browser_test.go
new file mode 100644
index 00000000..bffefc85
--- /dev/null
+++ b/internal/thintest/instant_browser_test.go
@@ -0,0 +1,227 @@
+//go:build browser
+
+package thintest
+
+import (
+ "context"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/wire"
+ "github.com/chromedp/cdproto/cdp"
+ "github.com/chromedp/cdproto/page"
+ "github.com/chromedp/chromedp"
+)
+
+// instantPage opens the conversation with a fake clock (window.__skew) and
+// a hold on the send: every POST to /conversation waits until
+// window.__release() (or fails, with window.__fail set), so what the page
+// shows before any answer from the server can be checked.
+func instantPage(t *testing.T, r *rig) *innerPage {
+ t.Helper()
+ p := openInner(t, r.inst.URL, r.inst.Cookie(), 390, 844, true, "dark", "no-preference")
+ p.do(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := cdp.Call(ctx, target, page.AddScriptToEvaluateOnNewDocument, page.AddScriptToEvaluateOnNewDocumentParams{Source: `(()=>{
+window.__beats=0;setInterval(()=>window.__beats++,250);const real=Date.now.bind(Date);window.__skew=0;Date.now=()=>real()+window.__skew;
+const fetch0=window.fetch.bind(window);window.__held=[];window.__answered=0;
+window.fetch=(url,opts)=>{
+ if(!opts||opts.method!=='POST'||!String(url).endsWith('/conversation'))return fetch0(url,opts);
+ if(window.__fail)return Promise.resolve(new Response('',{status:500}));
+ return new Promise(go=>window.__held.push(()=>go(fetch0(url,opts).then(r=>{window.__answered++;return r}))));
+};
+window.__release=()=>{const h=window.__held.shift();if(h)h();return true};
+})()`})
+ return err
+ }))
+ p.open("/conversation")
+ p.wait(`document.querySelector('[data-chat-stream]')`, "the conversation")
+ // The page's timers are going (the thinking line's clock runs on them).
+ p.wait(`window.__beats>2`, "page timers running")
+ return p
+}
+
+// sendNow types text, sends it, and reports in the same task whether the
+// coordinator's line is already there, then again at the next frame.
+const sendNow = `(text=>{
+ const before=window.__answered;
+ const box=document.querySelector('#composer textarea');box.value=text;box.dispatchEvent(new Event('input'));
+ document.querySelector('#composer').requestSubmit();
+ const lines=[...document.querySelectorAll('[equipo-thinking][data-optimistic]')];
+ window.__line=lines[lines.length-1]||null;
+ window.__sync=!!window.__line && window.__answered===before && window.__line.querySelector('[equipo-elapsed]').textContent==='0s' && !!window.__line.querySelector('[equipo-sparkle]') && !!window.__line.querySelector('[equipo-phrase] [data-in]');
+ requestAnimationFrame(()=>{window.__frame=!!window.__line&&window.__line.isConnected&&window.__answered===before});
+ return window.__sync;
+})`
+
+const oneLine = `document.querySelectorAll('[equipo-thinking]').length===1`
+
+// TestBrowserInstantThinking: Paul, "a slight delay before the
+// coordinator's loading state appears". The line comes with the send,
+// before the server has answered (the POST held back), with its sparkle, a
+// phrase and a timer from 0 on the fake clock; the turn then adopts that
+// same element, timer and all. A send that fails takes its line away and
+// says so; a turn with no connection gives the line up for the quiet
+// waiting state; two sends that share a queued turn leave one line.
+func TestBrowserInstantThinking(t *testing.T) {
+
+ t.Run("instant_then_adopted", func(t *testing.T) {
+ r, runner := instantRig(t)
+ p := instantPage(t, r)
+ defer p.stop()
+ p.check(sendNow+`('Can you look at the build?')`, "no line at once, before the server answered")
+ p.wait(`window.__frame===true`, "the line within one frame of the send")
+ p.check(`window.__held.length===1 && window.__answered===0`, "the send was not held")
+ started := eval[string](p, `window.__line.dataset.started`)
+ // The timer counts on the fake clock while the server has said nothing.
+ p.check(`(()=>{window.__skew+=2100;return true})()`, "advance the clock")
+ p.wait(`window.__line.querySelector('[equipo-elapsed]').textContent==='2s'`, "the timer counting from the send")
+ p.check(`window.__release()`, "release the send")
+ f := messageFrame(t, r, runner)
+ p.wait(`window.__line.isConnected && window.__line.dataset.turn!=='' && !window.__line.hasAttribute('data-optimistic')`, "the turn adopted the line")
+ p.check(oneLine+` && document.querySelector('[equipo-thinking]')===window.__line`, "a second line, or a new element, for the turn")
+ p.check(`window.__line.dataset.started===`+jsString(started), "the timer restarted")
+ runner.Send(r.ctx, "a-1", wire.FrameAck, wire.Ack{ID: f.ID})
+ turn := eval[string](p, `window.__line.dataset.turn`)
+ r.wait("running", func(c *Conversation) bool { return c.Turns[turn].State == wire.TurnRunning })
+ p.check(`(()=>{window.__skew+=1000;return true})()`, "advance the clock")
+ p.wait(`window.__line.isConnected && window.__line.querySelector('[equipo-elapsed]').textContent.match(/^(\d+)s$/)?.[1]>=3 && window.__line.dataset.started===`+jsString(started), "the same line runs on, timed from the send")
+ p.check(oneLine, "one line while running")
+ runner.Send(r.ctx, "r-1", wire.FrameReply, wire.Reply{TurnID: turn, Attempt: 1, Text: "It builds now."})
+ p.wait(`!document.querySelector('[equipo-thinking]') && [...document.querySelectorAll('[data-message]')].some(m=>m.textContent.includes('It builds now.'))`, "the reply took the line's place")
+ p.stayed("instant send")
+ })
+
+ t.Run("attachment_line_before_upload", func(t *testing.T) {
+ r, runner := instantRig(t)
+ p := instantPage(t, r)
+ defer p.stop()
+ // A pasted file is still uploading when the send goes.
+ p.check(`(()=>{const dt=new DataTransfer();dt.items.add(new File(['notes'],'notes.txt',{type:'text/plain'}));const box=document.querySelector('#composer textarea');box.dispatchEvent(new ClipboardEvent('paste',{clipboardData:dt,bubbles:true,cancelable:true}));return document.querySelectorAll('[equipo-chip]').length===1})()`, "the pasted file")
+ p.check(sendNow+`('Here are the notes.')`, "no line at once with an attachment")
+ p.wait(`window.__held.length===1`, "the send waits for the upload, then is held")
+ p.check(`window.__line.isConnected && window.__line.hasAttribute('data-optimistic')`, "the line went while the upload ran")
+ p.check(`window.__release()`, "release the send")
+ f := messageFrame(t, r, runner)
+ p.wait(`window.__line.isConnected && !window.__line.hasAttribute('data-optimistic')`, "the turn adopted the line")
+ p.check(oneLine, "one line")
+ turn := eval[string](p, `window.__line.dataset.turn`)
+ runner.Send(r.ctx, "a-2", wire.FrameAck, wire.Ack{ID: f.ID})
+ runner.Send(r.ctx, "r-2", wire.FrameReply, wire.Reply{TurnID: turn, Attempt: 1, Text: "Read them."})
+ p.wait(`!document.querySelector('[equipo-thinking]')`, "the reply")
+ })
+
+ t.Run("send_failed", func(t *testing.T) {
+ r, runner := instantRig(t)
+ p := instantPage(t, r)
+ defer p.stop()
+ p.check(`(()=>{window.__fail=true;return true})()`, "fail the next send")
+ p.check(sendNow+`('This one will not go.')`, "no line at once")
+ p.wait(`!document.querySelector('[equipo-thinking]') && document.querySelector('[data-send-failed] [data-retry-send]')`, "the line gone and the send error shown")
+ // Trying again shows the line again, at once.
+ p.check(`(()=>{window.__fail=false;document.querySelector('[data-retry-send]').click();return !!document.querySelector('[equipo-thinking][data-optimistic]')})()`, "no line on retry")
+ p.check(`window.__release()`, "release the retry")
+ f := messageFrame(t, r, runner)
+ p.wait(`document.querySelector('[equipo-thinking]:not([data-optimistic])') && `+oneLine, "the retry's turn adopted its line")
+ turn := eval[string](p, `document.querySelector('[equipo-thinking]').dataset.turn`)
+ runner.Send(r.ctx, "a-3", wire.FrameAck, wire.Ack{ID: f.ID})
+ runner.Send(r.ctx, "r-3", wire.FrameReply, wire.Reply{TurnID: turn, Attempt: 1, Text: "Got it."})
+ p.wait(`!document.querySelector('[equipo-thinking]')`, "the reply")
+ })
+
+ t.Run("no_connection", func(t *testing.T) {
+ r, runner := instantRig(t)
+ p := instantPage(t, r)
+ defer p.stop()
+ p.check(sendNow+`('Are you there?')`, "no line at once")
+ p.check(`window.__release()`, "release the send")
+ f := messageFrame(t, r, runner)
+ runner.Send(r.ctx, "a-4", wire.FrameAck, wire.Ack{ID: f.ID})
+ var turn string
+ r.wait("queued or running", func(c *Conversation) bool {
+ for id, v := range c.Turns {
+ if v.State == wire.TurnQueued || v.State == wire.TurnRunning {
+ turn = id
+ return true
+ }
+ }
+ return false
+ })
+ runner.Send(r.ctx, "r-hold", wire.FrameTurn, wire.TurnReport{TurnID: turn, Attempt: 1, State: wire.TurnWaiting, Reason: wire.ReasonNoConnection})
+ p.wait(`!document.querySelector('[equipo-thinking]') && document.querySelector('[data-waiting-connection]')`, "the quiet waiting state in place of the line")
+ // It goes on, on a connection: the thinking line again.
+ runner.Send(r.ctx, "r-go", wire.FrameTurn, wire.TurnReport{TurnID: turn, Attempt: 1, State: wire.TurnRunning})
+ p.wait(oneLine+` && document.querySelector('[equipo-thinking]').dataset.turn===`+jsString(turn), "the line back when it runs")
+ runner.Send(r.ctx, "r-4", wire.FrameReply, wire.Reply{TurnID: turn, Attempt: 1, Text: "Here now."})
+ p.wait(`!document.querySelector('[equipo-thinking]')`, "the reply")
+ })
+}
+
+// instantRig is an instance with a scripted runner online.
+func instantRig(t *testing.T) (*rig, *FakeRunner) {
+ t.Helper()
+ r := newRig(t)
+ runner := r.dial(0)
+ if err := runner.Send(r.ctx, "h1", wire.FrameHello, toolHello(runner.Welcome.Generation)); err != nil {
+ t.Fatal(err)
+ }
+ r.wait("runner online", func(c *Conversation) bool { return c.Runner.Online })
+ return r, runner
+}
+
+// messageFrame is the next message frame, attachment chunks acked on the way.
+func messageFrame(t *testing.T, r *rig, runner *FakeRunner) wire.Frame {
+ t.Helper()
+ for {
+ f, _, err := runner.Next(r.ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ switch f.Type {
+ case wire.FrameMessage:
+ return f
+ case wire.FrameAttachment:
+ runner.Send(r.ctx, "a-"+f.ID, wire.FrameAck, wire.Ack{ID: f.ID})
+ case wire.FrameAck:
+ default:
+ t.Fatalf("unexpected frame %s", f.Type)
+ }
+ }
+}
+
+// TestBrowserInstantThinkingQueued: while one turn runs, a second message
+// queues a turn behind it and a third joins that queued turn (the server
+// says so in its answer). Every send shows a line at once; when the server
+// has answered, there is one line per turn, each the element shown at the
+// send, and nothing is orphaned.
+func TestBrowserInstantThinkingQueued(t *testing.T) {
+ r, runner := instantRig(t)
+ p := instantPage(t, r)
+ defer p.stop()
+ p.check(sendNow+`('First thing.')`, "no line for the first send")
+ p.check(`(()=>{window.__first=window.__line;return window.__release()})()`, "release the first")
+ f := messageFrame(t, r, runner)
+ runner.Send(r.ctx, "a-q1", wire.FrameAck, wire.Ack{ID: f.ID})
+ p.wait(`!window.__first.hasAttribute('data-optimistic')`, "the first turn adopted its line")
+ first := eval[string](p, `window.__first.dataset.turn`)
+ r.wait("first running", func(c *Conversation) bool { return c.Turns[first].State == wire.TurnRunning })
+ p.check(sendNow+`('And a second.')`, "no line for the second send")
+ p.check(`(()=>{window.__second=window.__line;return true})()`, "keep the second")
+ p.check(sendNow+`('And a third.')`, "no line for the third send")
+ p.check(`(()=>{window.__third=window.__line;return document.querySelectorAll('[equipo-thinking][data-optimistic]').length===2 && window.__held.length===2})()`, "two waiting lines, both sends held")
+ p.check(`window.__release()`, "release the second")
+ p.wait(`!window.__second.hasAttribute('data-optimistic') && window.__second.dataset.turn!==`+jsString(first), "the queued turn adopted the second line")
+ p.check(`window.__release()`, "release the third")
+ p.wait(`window.__answered===3 && !document.querySelector('[equipo-thinking][data-optimistic]')`, "the third line gone")
+ lines := `[...document.querySelectorAll('[equipo-thinking]')].map(l=>(l===window.__first?'first:':l===window.__second?'second:':l===window.__third?'third:':'')+l.dataset.turn).join(' ')`
+ second := eval[string](p, `window.__second.dataset.turn`)
+ if got := eval[string](p, lines); got != "first:"+first+" second:"+second {
+ t.Fatalf("lines %q, want the first and second for turns %s and %s", got, first, second)
+ }
+ snap, err := r.client.Snapshot(r.ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(snap.Turns) != 2 {
+ t.Fatalf("the third message did not join the queued turn: %+v", snap.Turns)
+ }
+ p.stayed("queued sends")
+}