Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions webapp/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async def questions_partial(request: Request, sid: str):
s = state.get(sid)
if s is None:
return _render("expired.html", request)
return _render("partials/question_list.html", request, s=s)
return _render("partials/question_list.html", request, s=s, status_oob=True)


@app.post("/sessions/{sid}/answers", response_class=HTMLResponse)
Expand Down Expand Up @@ -401,7 +401,7 @@ async def section_partial(request: Request, sid: str, section_id: str):
if s is None or sec is None:
return HTMLResponse("<div class='card error'>Unknown section</div>")
return _render("partials/section_card.html", request, s=s, sec=sec,
examples=flow.REFINE_EXAMPLES)
examples=flow.REFINE_EXAMPLES, oob=True)


@app.post("/sessions/{sid}/sections/{section_id}/retry", response_class=HTMLResponse)
Expand Down
10 changes: 7 additions & 3 deletions webapp/app/templates/partials/question_list.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{% set status_oob = status_oob|default(oob|default(false)) %}
{% set questions_oob = questions_oob|default(oob|default(false)) %}
{% if s.error %}
<div id="questions"{% if oob %} hx-swap-oob="true"{% endif %}>
{% if status_oob %}<div id="status-bar" hx-swap-oob="innerHTML"></div>{% endif %}
<div id="questions"{% if questions_oob %} hx-swap-oob="true"{% endif %}>
<p class="error">Generation failed: {{ s.error }}</p>
<p><a href="/" role="button" class="secondary">Start over</a></p>
</div>
{% elif s.phase == 'clarify' and s.qas %}
{% if status_oob %}<div id="status-bar" hx-swap-oob="innerHTML"></div>{% endif %}
{# Ready: plain div, no auto-refresh attrs — typed answers must survive #}
<div id="questions"{% if oob %} hx-swap-oob="true"{% endif %}>
<div id="questions"{% if questions_oob %} hx-swap-oob="true"{% endif %}>
<form hx-post="/sessions/{{ s.id }}/answers" hx-target="#wizard" hx-swap="innerHTML">
<p>Answer what you can — anything you skip falls back to the stated assumption.</p>
{% for qa in s.qas %}
Expand All @@ -31,7 +35,7 @@
</div>
{% else %}
{# Waiting: keeps refreshing itself via SSE pokes + 10s polling fallback #}
<div id="questions"{% if oob %} hx-swap-oob="true"{% endif %}
<div id="questions"{% if questions_oob %} hx-swap-oob="true"{% endif %}
hx-get="/sessions/{{ s.id }}/questions"
hx-trigger="sse:questions_ready, sse:error, every 10s"
hx-swap="outerHTML">
Expand Down
6 changes: 6 additions & 0 deletions webapp/app/templates/partials/section_card.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{% if oob and not (s.sections | selectattr("status", "in", ["pending", "generating"]) | list) %}
<div id="status-bar" hx-swap-oob="innerHTML"></div>
<div id="step3-actions" hx-swap-oob="innerHTML">
{% include "partials/step3_actions.html" %}
</div>
{% endif %}
{% if sec.status in ('pending', 'generating') %}
{# Waiting: refreshes itself via SSE pokes + 10s polling fallback #}
<div id="section-{{ sec.id }}"
Expand Down
34 changes: 33 additions & 1 deletion webapp/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from app import main
from app.wizard import state
from app.wizard.state import QA
from app.wizard.state import QA, Section


class _FakeRequest:
Expand Down Expand Up @@ -45,3 +45,35 @@ def test_party_questions_tolerates_missing_fields():
s.party_status = "running"
asyncio.run(main.party_questions_start(_FakeRequest(), s.id))
assert s.qas[0].answer == "kept"


def test_questions_poll_clears_stale_status_bar():
"""If the browser missed the final SSE clear, the polling fallback should
clear the initial cold-start status when questions are ready without marking
the polling target itself as an out-of-band swap."""
s = state.create()
s.phase = "clarify"
s.qas = [QA(question="Q1", assumption="A1")]

resp = asyncio.run(main.questions_partial(_FakeRequest(), s.id))
body = resp.body.decode()

assert 'id="status-bar" hx-swap-oob="innerHTML"' in body
assert 'id="questions" hx-swap-oob="true"' not in body


def test_last_section_poll_clears_stale_status_bar():
"""When all sections are terminal, a section poll also clears any stale
model-loading message left behind by a missed SSE event and reveals the
action buttons even if the browser missed job_done."""
s = state.create()
sec = Section(id="overview", title="Overview", instruction="", content="Done", status="done")
s.sections = [sec]

resp = asyncio.run(main.section_partial(_FakeRequest(), s.id, sec.id))
body = resp.body.decode()

assert 'id="status-bar" hx-swap-oob="innerHTML"' in body
assert 'id="step3-actions" hx-swap-oob="innerHTML"' in body
assert "Party review" in body
assert "Finish" in body
Loading