From f266444f7d797bdaf3f6309ebfe791581e211aa4 Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 17 Jul 2026 22:07:13 +1000 Subject: [PATCH] =?UTF-8?q?test(ui):=20=D1=81=D1=80=D0=B5=D0=B7=200.1=20?= =?UTF-8?q?=E2=80=94=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D1=8B=D0=B9=20smoke-=D1=85?= =?UTF-8?q?=D0=B0=D1=80=D0=BD=D0=B5=D1=81=D1=81=20(=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20chat.html=20+=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20/api)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + tests/ui_smoke_harness.py | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/ui_smoke_harness.py diff --git a/.gitignore b/.gitignore index 735b6f8..f4f1380 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __pycache__/ .playwright-mcp/ tests/dialog_baseline.json tests/test_results.json +tests/.ui_smoke_stub.html diff --git a/tests/ui_smoke_harness.py b/tests/ui_smoke_harness.py new file mode 100644 index 0000000..21385ca --- /dev/null +++ b/tests/ui_smoke_harness.py @@ -0,0 +1,74 @@ +"""UI-smoke харнесс (срез UI 0.1): гоняем РЕАЛЬНЫЙ static/chat.html в браузере +без поднятия полного бэкенда (нет .env/venv локально — см. memory +feedback_chat_html_local_smoke). + +Идея: берём настоящий static/chat.html и инъектим в стаб, который +подменяет window.fetch поддельными /api-эндпоинтами и кладёт токен в localStorage. +Так браузер исполняет НАСТОЯЩИЕ функции (sendMessage/runChat/openFeedbackForm/…), +а не их копию — регрессии ловятся на живом коде. + +Использование: + python3 tests/ui_smoke_harness.py # печатает путь к сгенерированному stub + python3 tests/ui_smoke_harness.py /tmp/x.html # свой путь вывода + +Дальше stub раздаётся любым статик-сервером (`python3 -m http.server`) и +драйвится Playwright (file:// заблокирован в MCP-Playwright — только http). + +SSE-стаб /api/chat уважает opts.signal — поэтому корректно тестируется abort +(кнопка «Стоп», newChat/switchChat мид-стрим). +""" +import sys +from pathlib import Path + +CHAT_HTML = Path(__file__).resolve().parent.parent / "static" / "chat.html" + +# Стаб: авторизация + поддельные /api. SSE /api/chat отдаёт tool→text→text→done +# с задержками, уважает signal (abort роняет поток AbortError'ом). +STUB = r""" +""" + + +def build_stub(out_path: Path) -> Path: + html = CHAT_HTML.read_text(encoding="utf-8") + if "" not in html: + raise SystemExit("chat.html: нет — некуда инъектить стаб") + out_path.write_text(html.replace("", STUB + "", 1), encoding="utf-8") + return out_path + + +if __name__ == "__main__": + out = Path(sys.argv[1]) if len(sys.argv) > 1 else CHAT_HTML.parent.parent / "tests" / ".ui_smoke_stub.html" + print(build_stub(out))