- dashboard.html: each section sits in OPTIONAL:<name> BEGIN/END blocks in the style, markup and script, with sample answers so a page with no bot shows it working. Core change: setUser records the role on <body>, so CSS hides admin-only parts from operators. - templates/sections.py keeps the chosen sections and deletes the rest, markers included; it stops on a broken marker. - templates/sections.md: what each section needs from the host (events, actions, desktop slot snippets, the role re-check, the login hand-off). - SKILL.md step 5 asks one multi-select question and runs sections.py. - Page check: checkpoint states, admin visibility by role and assign/remove, login theme and hand-off to auth or the stub. Cases skip on a generated page without the section; the template must carry all three. The harness signs in when the page has a login screen. - tests/test_sections.py: no sections leave no trace, and that page still passes the page check. - Eval runner: a-empty-sections variant (all three) and per-section checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
"""Seam 1 page check: load a dashboard page with no backend, push contract envelopes
|
|
through window.__pyMsg, and assert on what is visible.
|
|
|
|
Page under test: set PAGE_CHECK_HTML to a generated dashboard.html. Without it, the
|
|
no-AI template is filled with TEST_FILL. Every test runs in light, dark and narrow mode.
|
|
The page sees a fake Qt bridge: each slot call lands in window.__calls as [slot, ...args].
|
|
"""
|
|
import json
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
TEMPLATE = ROOT / "rpa-dashboard-no-ai" / "templates" / "dashboard.html"
|
|
TEST_FILL = {
|
|
"APP_NAME": "Test Bot",
|
|
"APP_SUBTITLE": "Page check",
|
|
"LOGO_SRC": "",
|
|
"API_BASE": "",
|
|
"STEPS_JSON": json.dumps(["Initializing", "Login", "Process items", "Completed"]),
|
|
"REPORT_COLUMNS_JSON": json.dumps([{"key": "item", "label": "Item"}, {"key": "status", "label": "Status"}]),
|
|
"CHECKPOINTS_JSON": json.dumps(["Sign in", "Open the list", "Process items", "Finish up"]),
|
|
}
|
|
FAKE_BRIDGE = """
|
|
window.__calls = [];
|
|
window.qt = {webChannelTransport: {}};
|
|
window.QWebChannel = function (_transport, ready) {
|
|
const pyBridge = new Proxy({}, {get: (_o, slot) => (...args) => { window.__calls.push([slot, ...args]); }});
|
|
ready({objects: {pyBridge}});
|
|
};
|
|
"""
|
|
MODES = {"light": (1280, 820, False), "dark": (1280, 820, True), "narrow": (800, 900, False)}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def page_url(tmp_path_factory):
|
|
if os.environ.get("PAGE_CHECK_HTML"):
|
|
return Path(os.environ["PAGE_CHECK_HTML"]).resolve().as_uri()
|
|
html = re.sub(r"\{\{(\w+)\}\}", lambda m: TEST_FILL[m[1]], TEMPLATE.read_text(encoding="utf-8"))
|
|
out = tmp_path_factory.mktemp("page") / "dashboard.html"
|
|
out.write_text(html, encoding="utf-8")
|
|
return out.as_uri()
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def browser():
|
|
with sync_playwright() as p:
|
|
b = p.chromium.launch()
|
|
yield b
|
|
b.close()
|
|
|
|
|
|
@pytest.fixture(params=list(MODES))
|
|
def page(request, browser, page_url):
|
|
width, height, dark = MODES[request.param]
|
|
ctx = browser.new_context(viewport={"width": width, "height": height})
|
|
ctx.add_init_script(FAKE_BRIDGE)
|
|
pg = ctx.new_page()
|
|
pg.set_default_timeout(5000)
|
|
errors = []
|
|
pg.on("pageerror", lambda e: errors.append(e))
|
|
pg.goto(page_url)
|
|
assert not errors, f"page script errors: {errors}"
|
|
if pg.get_by_role("form", name="Sign in").is_visible(): # login page section: the host lets us in
|
|
push_to(pg, "login_result", {"ok": True})
|
|
if dark:
|
|
push_to(pg, "apply_dark", {"on": True})
|
|
yield pg
|
|
ctx.close()
|
|
|
|
|
|
def push_to(pg, event, data):
|
|
pg.evaluate("([event, data]) => window.__pyMsg(JSON.stringify({event, data}))", [event, data])
|
|
|
|
|
|
@pytest.fixture
|
|
def push(page):
|
|
"""push(event, data): send one contract envelope to the page, as the bot would."""
|
|
return lambda event, data: push_to(page, event, data)
|