oficina / base Public

Polish Ask cards: no answer bubble, own-key words, Equipo-hosted links

- An answered merge or publish card adds no bubble, as in Equipo, whose
  answerMerge and answerPublish send no message (the card's own line says
  what was chosen). The fake Equipo now does the same; the panel skips an
  empty message and turn.
- The panel's option and state words come from prototype-free tables read
  with Object.hasOwn: an option named "constructor" shows as itself.
- Preview and site links are any absolute http(s) URL, as on the server,
  so one on Equipo's own /tasks/ path is no longer dropped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 951820199fd1939c3ecadb63464e6484beaa7e10 parent 64f3048
4 files changed, +91 −15
  • internal/browsertest/cards_test.go +37 −0
  • internal/equipo/equipotest/chat.go +23 −0
  • internal/look/static/ask.js +28 −15
  • internal/webtest/ask_test.go +3 −0
diff --git a/internal/browsertest/cards_test.go b/internal/browsertest/cards_test.go
index fdbaabb..582a26e 100644
--- a/internal/browsertest/cards_test.go
+++ b/internal/browsertest/cards_test.go
@@ -66,3 +66,40 @@ func TestAskWebsiteCards(t *testing.T) {
rig.Screen("#ask-panel", "the panel after publishing")
mobileShot(t, rig, "3-published")
}
+
+// Polish: an answered merge or publish card adds no bubble (Equipo sends
+// none), option and state words come only from Base's own tables, and a
+// preview on Equipo's own origin is a link like any other.
+func TestAskCardsPolish(t *testing.T) {
+ rig, f := askBase(t)
+ openPanel(t, rig)
+ wait := func(js string) {
+ t.Helper()
+ drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second)))
+ }
+ merge := f.AskMerge("Quick website")
+ preview := f.URL + "/tasks/tk0001/preview"
+ f.SetPreview(merge, preview, true)
+ card := `#ask-panel [data-card="` + merge + `"]`
+ wait(`!!document.querySelector(` + strconv.Quote(card+` a.card-link[href="`+preview+`"]`) + `)`)
+ drive(t, rig, chromedp.Click(chromedp.CSS(card+` button[value="merge"]`)))
+ wait(`document.querySelector(` + strconv.Quote(card) + `).textContent.includes("Merging without checks.")`)
+ drive(t, rig, chromedp.Sleep(300*time.Millisecond))
+ if got := harness.Evaluate[string](rig, `[...document.querySelectorAll("#ask-panel .msg.person")].map(m => "[" + m.textContent + "]").join("") + "|" + document.querySelector("#ask-panel .ask-status").textContent`); got != "|" {
+ t.Errorf("after answering a merge card: bubbles and status %q, want none", got)
+ }
+
+ q := f.AskQuestion("Pick one", "constructor", "toString")
+ qcard := `#ask-panel [data-card="` + q + `"]`
+ wait(`!!document.querySelector(` + strconv.Quote(qcard+` button`) + `)`)
+ if got := harness.Evaluate[string](rig, `[...document.querySelectorAll(`+strconv.Quote(qcard+` button`)+`)].map(b => b.textContent).join("|")`); got != "constructor|toString" {
+ t.Errorf("option buttons read %q", got)
+ }
+ publish := f.AskPublish("Quick website", "site-sample")
+ f.SetCard(publish, "answered", "constructor", "toString")
+ pcard := `#ask-panel [data-card="` + publish + `"]`
+ wait(`!!document.querySelector(` + strconv.Quote(pcard+` .card-state`) + `)`)
+ if got := harness.Evaluate[string](rig, `document.querySelector(`+strconv.Quote(pcard+` .card-state`)+`).textContent`); got != "Nothing to decide any more." {
+ t.Errorf("a card with unknown choice and site state reads %q", got)
+ }
+}
diff --git a/internal/equipo/equipotest/chat.go b/internal/equipo/equipotest/chat.go
index ca92e40..5c949a4 100644
--- a/internal/equipo/equipotest/chat.go
+++ b/internal/equipo/equipotest/chat.go
@@ -187,6 +187,22 @@ func (f *Fake) publish(c *card) {
f.emit("message", "message", m.ID, 1, "", m)
}
+// SetCard moves card id to state with choice, and its site (if it has
+// one) to site, announcing it.
+func (f *Fake) SetCard(id, state, choice, siteState string) {
+ f.cmu.Lock()
+ defer f.cmu.Unlock()
+ for _, c := range f.cards {
+ if c.ID == id {
+ c.State, c.Choice, c.Revision = state, choice, c.Revision+1
+ if c.Site != nil {
+ c.Site.State = siteState
+ }
+ f.emit("card", "card", c.ID, c.Revision, "", *c)
+ }
+ }
+}
+
// Say adds a coordinator line to the conversation.
func (f *Fake) Say(text string) {
f.cmu.Lock()
@@ -419,6 +435,13 @@ func (f *Fake) answer(w http.ResponseWriter, r *http.Request, id string) {
}
}
f.emit("card", "card", c.ID, c.Revision, c.TurnID, *c)
+ if c.Kind == "merge" || c.Kind == "publish" {
+ // As Equipo does (answerMerge, answerPublish): the card alone
+ // answers; no message, no turn.
+ f.cmu.Unlock()
+ writeJSON(w, 200, map[string]any{"card": *c, "message": message{}, "turn": turn{}})
+ return
+ }
m, t := f.ask(in.Choice)
f.cmu.Unlock()
writeJSON(w, 200, map[string]any{"card": *c, "message": m, "turn": t})
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index 669f131..a0aa71c 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -50,7 +50,9 @@ function start(root) {
// A message, once: a coordinator's reply takes its streamed draft's place.
function addMessage(m) {
- if (!m || item("data-id", m.id)) return;
+ // An answered merge or publish card brings no message (Equipo sends
+ // none: the card says what was chosen), so an empty one is skipped.
+ if (!m || !m.id || item("data-id", m.id)) return;
const li = document.createElement("li");
li.className = "msg " + (m.role === "person" ? "person" : "coordinator");
li.dataset.id = m.id;
@@ -80,10 +82,9 @@ function start(root) {
// rest, raw HTML included, is text. Base's server does the same
// (richText in ask_cards.go).
const linkRE = /\[([^\[\]\n]{1,300})\]\(([^()\s]{1,1000})\)|https?:\/\/[^\s<>()\[\]"']+/g;
- function safeHref(target) {
- if (target.startsWith("/tasks/")) {
- return /^[A-Za-z0-9_-]{1,64}$/.test(target.slice(7)) && equipo ? equipo + target : "";
- }
+ // webURL is target if it is an absolute http(s) URL with a host and no
+ // user info, else "" (equipo.WebURL on the server).
+ function webURL(target) {
try {
const u = new URL(target);
return (u.protocol === "http:" || u.protocol === "https:") && u.host && !u.username && !u.password ? u.href : "";
@@ -91,6 +92,12 @@ function start(root) {
return "";
}
}
+ function safeHref(target) {
+ if (target.startsWith("/tasks/")) {
+ return /^[A-Za-z0-9_-]{1,64}$/.test(target.slice(7)) && equipo ? equipo + target : "";
+ }
+ return webURL(target);
+ }
function link(href, text) {
const a = document.createElement("a");
a.href = href;
@@ -120,15 +127,20 @@ function start(root) {
// The words for a card's options and, once it is answered, its state:
// Equipo's own wording (its chat.card copy). Base's server has the same
// (cardOption and cardStatus in ask_cards.go).
- const options = { merge: "Merge", wait: "Wait for checks", wait_mac: "Wait for a Mac", not_now: "Not now", publish: "Publish" };
- const sites = { publishing: "Publishing.", published: "Published", unconfirmed: "Publish could not be confirmed",
- failed: "Publishing failed.", declined: "Not published." };
- const chosen = { merge: "Merging without checks.", wait: "Waiting for checks.", wait_mac: "Waiting for a Mac.",
- not_now: "Not now.", publish: "Publishing." };
+ // Tables without a prototype, read only for their own keys: an option
+ // or state named "constructor" is just an unknown word.
+ const table = (o) => Object.assign(Object.create(null), o);
+ const word = (t, k) => (typeof k === "string" && Object.hasOwn(t, k) ? t[k] : undefined);
+ const options = table({ merge: "Merge", wait: "Wait for checks", wait_mac: "Wait for a Mac", not_now: "Not now", publish: "Publish" });
+ const sites = table({ publishing: "Publishing.", published: "Published", unconfirmed: "Publish could not be confirmed",
+ failed: "Publishing failed.", declined: "Not published." });
+ const chosen = table({ merge: "Merging without checks.", wait: "Waiting for checks.", wait_mac: "Waiting for a Mac.",
+ not_now: "Not now.", publish: "Publishing." });
function cardStatus(c) {
- if (c.kind === "publish" && c.site && sites[c.site.state]) return sites[c.site.state];
+ const site = c.kind === "publish" && c.site && word(sites, c.site.state);
+ if (site) return site;
if (c.state === "open") return "";
- return chosen[c.choice] || "Nothing to decide any more.";
+ return word(chosen, c.choice) || "Nothing to decide any more.";
}
// A card: a question, a merge card (with its preview) or a publish card
@@ -152,8 +164,8 @@ function start(root) {
q.textContent = c.question || c.name || "";
li.append(q);
for (const [href, text] of [[c.preview_url, "Open the preview"], [c.site && c.site.url, "Open the site"]]) {
- const safe = href && safeHref(href);
- if (!safe || safe.startsWith(equipo + "/tasks/")) continue;
+ const safe = href && webURL(href);
+ if (!safe) continue;
const p = document.createElement("p");
const a = link(safe, text);
a.className = "card-link";
@@ -176,7 +188,7 @@ function start(root) {
b.type = "submit";
b.name = "choice";
b.value = o;
- b.textContent = options[o] || o;
+ b.textContent = word(options, o) || o;
form.append(b);
}
li.append(form);
@@ -194,6 +206,7 @@ function start(root) {
const ended = (s) => s === "replied" || s === "failed" || s === "cancelled";
function setTurn(t, line) {
+ if (t && !t.id) return;
if (t && !ended(t.state)) {
turn = t;
stop.action = `/ask/turns/${encodeURIComponent(t.id)}/cancel`;
diff --git a/internal/webtest/ask_test.go b/internal/webtest/ask_test.go
index 88a353b..711b2fd 100644
--- a/internal/webtest/ask_test.go
+++ b/internal/webtest/ask_test.go
@@ -673,6 +673,9 @@ func TestAskMergeAndPublishCards(t *testing.T) {
}
time.Sleep(20 * time.Millisecond)
}
+ if strings.Contains(body, `<li class="msg person"`) {
+ t.Errorf("an answered card left a bubble (Equipo sends no message for it):\n%s", body)
+ }
for _, want := range []string{
`<a class="card-link" href="https://site-sample.example.test/" target="_blank" rel="noopener">Open the site</a>`,
`<p class="card-state">Published</p>`,