feat: POST /log from the page + load state.json on page open

- Browser can record entries (e.g. meter readings) into session.md/jsonl;
  broadcast to other open clients. Log feed renders as text, not HTML.
- Page loads state.json on open instead of only localStorage, so a new
  device (or one that missed the WS push) shows current content.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mortdecai
2026-09-28 16:28:36 -04:00
parent 65622501fe
commit 05fcb7f2f2
3 changed files with 43 additions and 7 deletions
+16
View File
@@ -124,3 +124,19 @@ async def test_static_blocks_path_traversal(server, tmp_workbench):
async with session.get(base + "/") as r:
assert r.status == 200
await server.workbench_stop("p")
@pytest.mark.asyncio
async def test_browser_post_log_persists_and_broadcasts(server, tmp_workbench):
from workbench.project import read_log
session, base = await _live(server)
async with session:
ws = await session.ws_connect(base + "/ws")
async with session.post(base + "/log", json={"entry": "R303 3.31M", "data": {"part": "R303"}}) as r:
assert r.status == 200
msg = await asyncio.wait_for(ws.receive_json(), 3)
assert msg == {"type": "log", "entry": "R303 3.31M"}
await ws.close()
entries = read_log("p", workbench_dir=tmp_workbench)
assert entries[-1]["entry"] == "R303 3.31M" and entries[-1]["part"] == "R303"
await server.workbench_stop("p")