Mac slice F task 13 fix 2: the composer shows the offline Mac's line
Astra round 2, #5: chat-stream.js threw on the 409 before reading it, so with script an ask about an offline Mac showed only the generic retry. A failed send now reads the body; a 409 runner_offline line is shown in the failed bubble as text only (textContent), beside the retry, and a retry removes it. TestBrowserAskMacOffline (written first): the Mac named, with when to ask again, and a line holding markup shown as literal text. Mutations B1 innerHTML, B2 body never read, B3 old line kept: each a failure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+79
−17
.rastrillo/budgets.txt+1 −1internal/equipo/static/chat-stream.js+23 −3internal/thintest/mac_ask_browser_test.go+35 −0internal/thintest/mac_ask_contract_test.go+20 −13
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 1c4cef9e..db5ec5c1 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| size internal/headless - 11999 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files end to end; the restart wait; the live site waits for a place; a card answer settles at the bottom; measured 11999 test lines. |
| -size internal/thintest - 39904 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering, conns, asks; measured 39904. |
| +size internal/thintest - 39946 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering, conns, asks; measured 39946. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index 7e9aa032..c0099abf 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -1291,12 +1291,24 @@ |
| delete el.dataset.sendFailed; |
| var old = el.querySelector("[data-retry-send]"); |
| if (old) old.remove(); |
| + var said = el.querySelector("[data-send-error]"); |
| + if (said) said.remove(); |
| var params = new URLSearchParams(extra || {}); |
| params.set("body", text); |
| params.set("request_id", id); |
| (files || []).forEach(function (f) { params.append("attachment", f); }); |
| fetch(form.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: params }) |
| - .then(function (r) { if (!r.ok) throw new Error("send"); return r.json(); }) |
| + .then(function (r) { |
| + if (r.ok) return r.json(); |
| + // The one refusal that says why (the runner holding the session is |
| + // offline, by name); any other is the plain retry. |
| + return r.json().catch(function () { return null; }).then(function (body) { |
| + var err = new Error("send"); |
| + var e = body && body.error; |
| + if (r.status === 409 && e && e.code === "runner_offline" && typeof e.message === "string") err.say = e.message; |
| + throw err; |
| + }); |
| + }) |
| .then(function (sent) { |
| local.delete(el); |
| delete el.dataset.pending; |
| @@ -1327,7 +1339,7 @@ |
| sentFiles(el, served(sent.message.attachments)); |
| } |
| }) |
| - .catch(function () { |
| + .catch(function (err) { |
| // Nothing was sent: no line waits for a reply, nor a note. |
| drop(line); |
| el.queuedAtSend = false; |
| @@ -1340,7 +1352,15 @@ |
| retry.dataset.retrySend = ""; |
| retry.textContent = form.dataset.retry; |
| retry.addEventListener("click", function () { post(el, text, id, extra, files, lineOrNote(el, extra.specialist)); }); |
| - el.querySelector("[equipo-bubble]").append(retry); |
| + var bubble = el.querySelector("[equipo-bubble]"); |
| + if (err && err.say) { |
| + // The server's line, as text only. |
| + var why = document.createElement("p"); |
| + why.dataset.sendError = ""; |
| + why.textContent = err.say; |
| + bubble.append(why); |
| + } |
| + bubble.append(retry); |
| }); |
| } |
| function send() { |
diff --git a/internal/thintest/mac_ask_browser_test.go b/internal/thintest/mac_ask_browser_test.go| new file mode 100644 |
| index 00000000..c567ed82 |
| --- /dev/null |
| +++ b/internal/thintest/mac_ask_browser_test.go |
| @@ -0,0 +1,35 @@ |
| +//go:build browser |
| + |
| +package thintest |
| + |
| +import ( |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// With script, a question asked about a Mac-made step while that Mac is |
| +// offline says which Mac and to ask again when it is back, as text, beside |
| +// the retry; nothing was asked. |
| +func TestBrowserAskMacOffline(t *testing.T) { |
| + r := newMacRig(t) |
| + a := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + task, d := r.macDispatch(a, "iOS offline page", sha(1)) |
| + r.askableOn(a, d, sha(0xc1), "mac-c1", "sess-1") |
| + r.macOffline(a) |
| + p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") |
| + defer p.stop() |
| + p.open("/tasks/" + task) |
| + p.wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`, "the task's composer") |
| + p.check(`(()=>{const i=document.querySelector('#chat-body');i.value='What did you change?';i.dispatchEvent(new Event('input'));document.querySelector('#composer').requestSubmit();return true})()`, "ask") |
| + p.wait(`!!document.querySelector('[data-send-failed] [data-retry-send]')`, "the send failed") |
| + p.check(`(()=>{const e=document.querySelector('[data-send-failed] [data-send-error]');return !!e && e.textContent==='Tito Studio is offline. Ask again when it is back.' && e.children.length===0})()`, "the offline Mac named, with when to ask again, as text") |
| + // The line is shown as text, whatever it holds. |
| + hostile := `Mac <b>B</b><img src=x onerror="window.__pwned=1"> is offline. Ask again when it is back.` |
| + p.check(`(()=>{const m=`+jsString(hostile)+`;window.fetch=()=>Promise.resolve(new Response(JSON.stringify({error:{code:'runner_offline',message:m}}),{status:409,headers:{'Content-Type':'application/json'}}));document.querySelector('[data-send-failed] [data-retry-send]').click();return true})()`, "retry, refused with markup in the line") |
| + p.wait(`(()=>{const e=document.querySelector('[data-send-failed] [data-send-error]');return !!e && e.textContent.startsWith('Mac <b>')})()`, "the hostile line") |
| + p.check(`(()=>{const es=document.querySelectorAll('[data-send-error]');return es.length===1 && es[0].children.length===0 && es[0].textContent===`+jsString(hostile)+` && !document.querySelector('[data-send-failed] img') && window.__pwned===undefined})()`, "the line as text only, once") |
| + if k := r.task(task); len(k.Questions) != 0 { |
| + t.Fatalf("a question was asked: %+v", k.Questions) |
| + } |
| +} |
diff --git a/internal/thintest/mac_ask_contract_test.go b/internal/thintest/mac_ask_contract_test.go| index b4bdda6d..daaa00c7 100644 |
| --- a/internal/thintest/mac_ask_contract_test.go |
| +++ b/internal/thintest/mac_ask_contract_test.go |
| @@ -203,16 +203,11 @@ func TestContractQuestionLifecycleFrozen(t *testing.T) { |
| }) |
| } |
| -// Asking about a Mac-made step while that Mac is offline is answered at |
| -// once (runner_offline), even with the primary online, and nothing |
| -// queues; once the Mac is back, the question is asked of it. |
| -func TestContractAskMacOffline(t *testing.T) { |
| - r := newMacRig(t) |
| - a := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| - base, cand := sha(1), sha(0xc1) |
| - task, d := r.macDispatch(a, "iOS offline", base) |
| - r.askableOn(a, d, cand, "mac-c1", "sess-1") |
| - a.fr.Close() |
| +// macOffline disconnects the Mac w and waits until the instance shows it |
| +// offline, with the primary still online. |
| +func (r *runnersRig) macOffline(w *peer) { |
| + r.t.Helper() |
| + w.fr.Close() |
| deadline := time.Now().Add(5 * time.Second) |
| for { |
| rs, err := r.client.Runners(context.Background()) |
| @@ -220,14 +215,26 @@ func TestContractAskMacOffline(t *testing.T) { |
| for _, x := range rs.Items { |
| online[x.ID] = x.Online |
| } |
| - if err == nil && !online[a.fr.Welcome.RunnerID] && online[r.primary.fr.Welcome.RunnerID] { |
| - break |
| + if err == nil && !online[w.fr.Welcome.RunnerID] && online[r.primary.fr.Welcome.RunnerID] { |
| + return |
| } |
| if time.Now().After(deadline) { |
| - t.Fatalf("Mac still online: %+v %v", rs, err) |
| + r.t.Fatalf("Mac still online: %+v %v", rs, err) |
| } |
| time.Sleep(50 * time.Millisecond) |
| } |
| +} |
| + |
| +// Asking about a Mac-made step while that Mac is offline is answered at |
| +// once (runner_offline), even with the primary online, and nothing |
| +// queues; once the Mac is back, the question is asked of it. |
| +func TestContractAskMacOffline(t *testing.T) { |
| + r := newMacRig(t) |
| + a := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + base, cand := sha(1), sha(0xc1) |
| + task, d := r.macDispatch(a, "iOS offline", base) |
| + r.askableOn(a, d, cand, "mac-c1", "sess-1") |
| + r.macOffline(a) |
| if _, err := r.client.Ask(r.ctx, task, "What did you change?", "", "o1"); Status(err) != http.StatusConflict || !strings.Contains(err.Error(), "runner_offline") { |
| t.Fatalf("ask of an offline Mac: %v", err) |
| } |