102 lines
3.1 KiB
Python
102 lines
3.1 KiB
Python
"""Compare approved original tokens with product CSS; screenshots remain separate artifacts."""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument("--reference", type=Path, required=True)
|
|
p.add_argument("--output", type=Path, required=True)
|
|
args = p.parse_args()
|
|
root = Path(__file__).resolve().parents[2]
|
|
tokens = [
|
|
"--bg-0",
|
|
"--bg-1",
|
|
"--bg-2",
|
|
"--tx-1",
|
|
"--tx-2",
|
|
"--tx-3",
|
|
"--gold",
|
|
"--sc-image",
|
|
"--sc-video",
|
|
"--sc-manage",
|
|
"--font",
|
|
"--fs-body",
|
|
"--studio-side",
|
|
"--lib-filter",
|
|
"--lib-detail",
|
|
"--lib-tile-min",
|
|
"--mdl-detail",
|
|
"--mdl-list-row",
|
|
"--ptband-max-h",
|
|
]
|
|
css = (root / "calliope-web/static/themes.css").read_text() + (
|
|
root / "calliope-web/src/routes/app.css"
|
|
).read_text()
|
|
results = []
|
|
with sync_playwright() as pw:
|
|
browser = pw.chromium.launch(
|
|
headless=True,
|
|
args=["--no-sandbox"],
|
|
env={
|
|
**os.environ,
|
|
"LD_LIBRARY_PATH": os.environ.get(
|
|
"HEL840_BROWSER_LIBS",
|
|
str(
|
|
root
|
|
/ "evidence/hel840/browser-runtime/libs/usr/lib/x86_64-linux-gnu"
|
|
),
|
|
),
|
|
},
|
|
)
|
|
reference = browser.new_page()
|
|
product = browser.new_page()
|
|
reference.goto(args.reference.resolve().as_uri())
|
|
product.set_content(
|
|
"<!doctype html><style>" + css + "</style><body>CSS token probe</body>"
|
|
)
|
|
for theme in ["night", "day", "grade", "bluehour"]:
|
|
for width, height in [(1440, 900), (1366, 768), (1280, 720)]:
|
|
entry = {"theme": theme, "width": width, "height": height}
|
|
for name, page in [("original", reference), ("product_css", product)]:
|
|
page.set_viewport_size({"width": width, "height": height})
|
|
page.evaluate(
|
|
"(theme)=>document.documentElement.dataset.theme=theme", theme
|
|
)
|
|
entry[name] = page.evaluate(
|
|
"(tokens)=>Object.fromEntries(tokens.map(t=>[t,getComputedStyle(document.documentElement).getPropertyValue(t).trim()]))",
|
|
tokens,
|
|
)
|
|
entry["differences"] = {
|
|
key: {
|
|
"original": entry["original"][key],
|
|
"product_css": entry["product_css"][key],
|
|
}
|
|
for key in tokens
|
|
if "".join(entry["original"][key].split())
|
|
!= "".join(entry["product_css"][key].split())
|
|
}
|
|
results.append(entry)
|
|
browser.close()
|
|
args.output.write_text(
|
|
json.dumps(
|
|
{
|
|
"method": "Approved original browser CSS vs product source CSS evaluation; actual product DOM measurements are in geometry.json. No pixel equality is claimed for different media/text.",
|
|
"entries": results,
|
|
},
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"entries": len(results),
|
|
"differences": sum(len(r["differences"]) for r in results),
|
|
}
|
|
)
|
|
)
|