fix(booth): asks were invisible in a booth serving its own index.html

A custom index.html is returned verbatim, so booth.html's asks panel never
rendered there — a valid ask (emmie-anchor/anchor.ask.json) was listed by the
CLI and shown nowhere, with nothing to say so.

- panel extracted to _asks.html; new GET /b/<name>/asks standalone page
- verbatim pages get an amber '? N open asks' chip beside the back chip
- POST /answer honours back=asks so answering returns to that page
- single-question asks now keep an optional 'title' (was silently dropped)
- README + routes table; 8 regression tests; v0.1.12
This commit is contained in:
vh
2026-09-09 10:39:18 -07:00
parent 2a186e4762
commit a56743ade3
9 changed files with 244 additions and 82 deletions
+73
View File
@@ -308,3 +308,76 @@ def test_write_ask_accepts_full_doc(tmp_path):
assert load_ask(tmp_path / "b", "batch")["multi"] is True
with pytest.raises(AskError):
write_ask(tmp_path / "b", "bad", doc={"questions": []})
# ---- verbatim-index booths ---------------------------------------------------
#
# A booth's own index.html is served VERBATIM, so the inline asks panel can never
# render on it. Found 2026-09-09 on `emmie-anchor`: a valid ask, listed by the
# CLI, invisible on the page with nothing to say so. The fix is a chip injected
# into the verbatim page plus a standalone /asks page that carries the forms.
def test_verbatim_booth_gets_an_asks_chip(client):
c, data = client
b = _ask(data / "b")
(b / "index.html").write_text("<!doctype html><title>report</title><body>hi</body>")
html = c.get("/b/b/").text
assert "hi" in html # the report is still served verbatim
assert "booth-nav-asks" in html # ...with a chip pointing at the asks
assert "1 open ask" in html
assert "/b/b/asks" in html
def test_verbatim_chip_disappears_once_answered(client):
c, data = client
b = _ask(data / "b")
(b / "index.html").write_text("<!doctype html><body>hi</body>")
write_answer(b, "winner", "A — baseline")
assert "booth-nav-asks" not in c.get("/b/b/").text
def test_verbatim_booth_without_asks_is_untouched(client):
c, data = client
(data / "b").mkdir()
(data / "b" / "index.html").write_text("<!doctype html><body>hi</body>")
assert "booth-nav-asks" not in c.get("/b/b/").text
def test_asks_page_renders_forms_and_answers_back_to_itself(client):
c, data = client
b = _ask(data / "b")
(b / "index.html").write_text("<!doctype html><body>hi</body>")
page = c.get("/b/b/asks").text
assert "Which render wins?" in page and 'type="radio"' in page
assert 'name="back" value="asks"' in page
r = c.post("/b/b/answer", data={"ask": "winner", "choice": "B — async", "back": "asks"},
follow_redirects=False)
assert r.headers["location"] == "/b/b/asks#ask-winner"
assert read_answer(b, "winner")["choice"] == "B — async"
assert "answered" in c.get("/b/b/asks").text
def test_asks_page_on_a_booth_with_none(client):
c, data = client
(data / "b").mkdir()
assert "no asks" in c.get("/b/b/asks").text
def test_asks_page_404s_for_unknown_booth(client):
c, _ = client
assert c.get("/b/nope/asks").status_code == 404
def test_single_ask_keeps_its_title(tmp_path):
a = normalize_ask({"title": "emmie — pick the anchor", "prompt": "Which?",
"options": ["a", "b"]}, "s")
assert a["multi"] is False and a["title"] == "emmie — pick the anchor"
with pytest.raises(AskError):
normalize_ask({"title": 7, "prompt": "p", "options": ["a", "b"]}, "s")
def test_asks_page_shows_a_single_ask_title(client):
c, data = client
_ask(data / "b", title="emmie — pick the anchor")
assert "emmie — pick the anchor" in c.get("/b/b/asks").text