mirror of
https://github.com/openglow-org/forgefirm.git
synced 2026-09-27 16:51:12 -07:00
The acceptance page is assembled by page.py from forgetest/forgetest/ui/ (index.html, page.css, help.js, app.js) plus theme.css and the vendored Bootstrap files, which are byte for byte the ones forgectrl's panel carries, so the two pages look like one product and share the light and dark themes (same localStorage key). A plain file is read in a checkout; on the dev image the recipe installs ui/ gzipped and page.py reads the .gz sibling, inflating once at first request: the rootfs is raw ext4, so bytes in the package are bytes on the image. The explanatory prose (campaign rules, the queues, the campaign actions, the prerequisites switch, the bench intro) is a "?" popover with a link into the documentation site; operator steps, prompts, notices and the live-laser acknowledgment stay in the page, and confirmLive() stays a blocking dialog. The page's own rules hold: rows, prompt buttons and tool entries are built once and updated in place, and the popovers sit on static markup only, so no rebuild orphans one. On a phone the Run pane goes to the top for the duration of a run. scripts/check-ui-vendor.py compares the shared files against forgectrl at its pinned revision (or a local checkout with --forgectrl); it runs in forgetest-ci.yml, so the copies cannot drift. Tests: test_page.py (the gzipped install assembles to the same bytes as a checkout, one self-contained response, the token placeholder once, a missing marker refused); test_server asserts the served page's invariants; test_responsiveness keeps its rules with needles pointed at the new files, its ASCII rule applied to our own sources (Bootstrap's CSS carries an em dash of its own), and its self-contained rule testing asset tags rather than the presence of https:// (the documentation links are meant to be there). forgectrl.panel-serves gains two needles for the panel's theme attribute and save bar. Proof: the unit suite, and the page in Chrome against a fake catalog (both themes, popovers, the bench tab, a full operator run with its prompt, abort). forgectrl pinned at 9d1f6f2 (the panel on Bootstrap, one save bar, help popovers, themes, the gzipped page); PV unchanged. The pin moves only forgectrl's fingerprint. The forgetest changes are the harness's own and have no catalog consequence.
62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
"""The single page: acceptance tab + bench tab, assembled from ui/ into
|
|
one self-contained response (no external assets). Bootstrap and the
|
|
OpenGlow theme are inlined; theme.css and the vendor/ files are the same
|
|
bytes forgectrl's panel carries, so the two pages look like one product
|
|
and follow the same light and dark themes (scripts/check-ui-vendor.py
|
|
holds them identical).
|
|
|
|
ui/ holds index.html, theme.css, page.css, help.js, app.js and vendor/.
|
|
A plain file is read when it is there (a checkout); otherwise its .gz
|
|
sibling is, which is what the recipe installs on the dev image: the
|
|
rootfs is raw ext4, so bytes in the package are bytes on the image, and
|
|
the page is inflated once at first request. The token placeholder is
|
|
spliced in per render."""
|
|
import gzip
|
|
import os
|
|
|
|
UI_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui")
|
|
# The files index.html links, in load order: one marker tag per file.
|
|
CSS_FILES = ("vendor/bootstrap.min.css", "theme.css", "page.css")
|
|
JS_FILES = ("vendor/bootstrap.bundle.min.js", "help.js", "app.js")
|
|
TOKEN_MARK = "__TOKEN__"
|
|
|
|
|
|
def read_ui(name, ui_dir=UI_DIR):
|
|
"""A ui/ file as text: the plain file, or its gzipped install."""
|
|
path = os.path.join(ui_dir, *name.split("/"))
|
|
try:
|
|
with open(path, "rb") as f:
|
|
return f.read().decode("utf-8")
|
|
except FileNotFoundError:
|
|
with gzip.open(path + ".gz", "rb") as f:
|
|
return f.read().decode("utf-8")
|
|
|
|
|
|
def assemble(ui_dir=UI_DIR):
|
|
"""index.html with every linked stylesheet and script inlined in place
|
|
of its tag. A missing marker is a broken page, not a silent one."""
|
|
html = read_ui("index.html", ui_dir)
|
|
for name in CSS_FILES:
|
|
tag = '<link rel="stylesheet" href="%s" />' % name
|
|
if tag not in html:
|
|
raise ValueError("index.html lacks the marker %s" % tag)
|
|
html = html.replace(tag, "<style>\n" + read_ui(name, ui_dir) + "</style>", 1)
|
|
for name in JS_FILES:
|
|
tag = '<script src="%s"></script>' % name
|
|
if tag not in html:
|
|
raise ValueError("index.html lacks the marker %s" % tag)
|
|
html = html.replace(tag, "<script>\n" + read_ui(name, ui_dir) + "</script>", 1)
|
|
if html.count(TOKEN_MARK) != 1:
|
|
raise ValueError("the page must carry %s exactly once" % TOKEN_MARK)
|
|
return html
|
|
|
|
|
|
_html = None
|
|
|
|
|
|
def render(token):
|
|
global _html
|
|
if _html is None:
|
|
_html = assemble()
|
|
return _html.replace(TOKEN_MARK, token)
|