Files
VasanthandClaude Opus 5.5 461798127a 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>
2026-10-16 15:55:30 +05:30

55 lines
2.3 KiB
Python

"""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"