AI sections fall back to fetch with no Qt bridge, for non-React web frontends

ai_sections.html fetches {API_BASE}+path when window.qt is absent; a page-check case routes those requests to server_stub.dispatch(). AI SKILL.md step 6 and frontend.md send plain-HTML/Vue/Angular/Svelte projects to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
VasanthandClaude Opus 5.5 committed 2026-10-16 15:55:30 +05:30
1 parent 344718007e
commit 461798127a
6 files changed
+100 -13

No files matched your search

+4
View File
@@ -40,6 +40,10 @@ uv run --with pytest --with playwright pytest tests
does). Runs the AI web page's review and cost cases and the no-AI cases unchanged, plus
a tampered page calling the slot directly (still refused). To check a generated folder,
set `PAGE_CHECK_AI_DESKTOP_DIR=path/to/dashboard`; `PAGE_CHECK_WIRED=1` as above.
`test_ai_fetch.py` runs the review cases on the same page with no Qt bridge (a plain-HTML
web project): the AI sections fetch `/api/...`, routed to `server_stub.dispatch()`.
- `page_check_common.py`: what the three page checks share (modes, test fill, fake Qt
bridge, stub loader, page opener, the list of no-AI cases the AI pages rerun).
- `test_pricing.py`: the AI cost function (normal, long-context, thinking tokens,
unknown model).
- `test_reference_scan.py`: no patient data, internal IPs, credentials or keys in any
@@ -0,0 +1,54 @@
"""The same AI sections with no Qt bridge: a plain-HTML (or Vue/Angular) web project.
The page is served over HTTP with API_BASE "/api", and every AI request goes out as
fetch({API_BASE}{path}). Playwright routes the API to the review backend's dispatch()
in this process (what a real backend serves; server_stub.py over HTTP does the same).
This module's `page` replaces the folder's bridge one; the review cases run unchanged.
"""
import json
import sys
from pathlib import Path
import pytest
from page_check_common import MODES, open_page
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "page_check_ai"))
from test_ai_review import ( # noqa: E402,F401
test_approve_stays_blocked_while_rows_are_unverified,
test_band_counts_and_legend_match,
test_band_filters_show_the_right_rows,
test_draft_edit_is_not_saved_until_save,
test_page_x_of_y_updates_while_running,
)
from test_ai_cost import cost_page, test_coverage_pill_counts_priced_of_all_documents # noqa: E402,F401
ORIGIN = "http://dashboard.test"
NO_BRIDGE = "window.__calls = [];"
@pytest.fixture(params=list(MODES))
def page(request, browser, site, stub):
html = (site / "dashboard.html").read_text(encoding="utf-8").replace(
'const API_BASE = "";', 'const API_BASE = "/api";')
def serve(route):
path = route.request.url[len(ORIGIN):].split("?")[0]
if not path.startswith("/api/"):
return route.fulfill(body=html, content_type="text/html")
body = json.loads(route.request.post_data or "{}")
status, payload = stub.dispatch(route.request.method, path[len("/api"):], body)
if isinstance(payload, str):
return route.fulfill(status=status, body=payload, content_type="image/svg+xml")
route.fulfill(status=status, body=json.dumps(payload), content_type="application/json")
yield from open_page(browser, ORIGIN + "/dashboard.html", request.param, NO_BRIDGE,
route=(ORIGIN + "/**", serve))
def test_ai_requests_go_over_fetch(page, stub):
"""With no Qt bridge, nothing reaches a bridge slot: the review loads over HTTP."""
from test_ai_review import FIELDS, open_review
stub.put_run("job-f", "fetch.pdf", FIELDS)
open_review(page, "job-f")
assert page.evaluate("window.__calls") == []
assert page.locator("#rv-doc").get_attribute("src") == "/api/runs/job-f/document"
+3 -1
View File
@@ -63,13 +63,15 @@ def push_to(pg, event, data):
pg.evaluate("([event, data]) => window.__pyMsg(JSON.stringify({event, data}))", [event, data])
def open_page(browser, url, mode, init_script, expose=None):
def open_page(browser, url, mode, init_script, expose=None, route=None):
"""Generator for a `page` fixture: opens url in one mode, signs in through a login
section if the page has one, switches to dark, and fails on any page script error."""
width, height, dark = MODES[mode]
ctx = browser.new_context(viewport={"width": width, "height": height})
if expose:
ctx.expose_function(*expose)
if route:
ctx.route(*route)
ctx.add_init_script(init_script)
pg = ctx.new_page()
pg.set_default_timeout(5000)