123 lines
7.7 KiB
Python
123 lines
7.7 KiB
Python
"""Проверка .pen после синхронизации с продом (kanban t_ca027aab).
|
||
|
||
Структурные инварианты (не «на глаз»): переменные варианта B с обеими темами, состав и порядок
|
||
секций фрейма B = продакшн `src/index.html` 2026-10-12, счётчики карточек/плашек/полей, наличие
|
||
плашки планеты (§10.11) и тумблера темы, тёмный фрейм-близнец с осью темы `dark` и своими id.
|
||
|
||
Запуск: python design/pen-sync/validate-frame-b.py
|
||
Exit 0 — все проверки прошли; exit 1 — печатает провалы.
|
||
"""
|
||
|
||
import json
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
FILES = [ROOT / "Harvey_Monster_Team_Page.pen", ROOT / "design" / "Harvey_Monster_Team_Page.pen"]
|
||
FRAME_ID = "W0IwN"
|
||
EXPECTED_SECTIONS = ["Navbar", "Hero", "Hero Ticker", "Секция Работы", "Секция Подход",
|
||
"Секция Команда", "Секция Контакты", "Footer"]
|
||
B_TOKEN_LIGHT = {"b-bg": "#F5EEE2", "b-card": "#FFFCF7", "b-text-1": "#211E18"}
|
||
B_TOKEN_DARK = {"b-bg": "#181109", "b-card": "#251A0F", "b-text-1": "#F8F2E7"}
|
||
|
||
problems = []
|
||
|
||
|
||
def check(cond, msg):
|
||
print((" ok " if cond else " FAIL ") + msg)
|
||
if not cond:
|
||
problems.append(msg)
|
||
|
||
|
||
def walk(node):
|
||
yield node
|
||
for c in node.get("children") or []:
|
||
yield from walk(c)
|
||
|
||
|
||
def ids(node, acc):
|
||
for n in walk(node):
|
||
if n.get("id") in acc:
|
||
problems.append("duplicate id " + str(n.get("id")))
|
||
acc.add(n.get("id"))
|
||
return acc
|
||
|
||
|
||
for path in FILES:
|
||
doc = json.load(open(path, encoding="utf-8"))
|
||
print(f"\n===== {path.name} ({path.parent.name}) · version {doc['version']} · token {doc['fileToken'][:8]}…")
|
||
frame = next((c for c in doc["children"] if c.get("id") == FRAME_ID), None)
|
||
check(frame is not None, "фрейм B Editorial Agency (W0IwN) на месте")
|
||
if frame is None:
|
||
continue
|
||
names = [c["name"] for c in frame["children"]]
|
||
check(names == EXPECTED_SECTIONS, f"состав секций = прод ({len(names)}): {names}")
|
||
check(frame.get("theme", {}).get("mode") == "light", "светлый фрейм помечен theme=mode:light")
|
||
|
||
for tok, want in B_TOKEN_LIGHT.items():
|
||
val = doc["variables"].get(tok, {}).get("value")
|
||
light = next((v["value"] for v in val if v.get("theme", {}).get("mode") == "light"), None) if isinstance(val, list) else val
|
||
dark = next((v["value"] for v in val if v.get("theme", {}).get("mode") == "dark"), None) if isinstance(val, list) else None
|
||
check(light == want, f"переменная {tok}: light {light} == {want}")
|
||
check(dark == B_TOKEN_DARK.get(tok), f"переменная {tok}: dark {dark} == {B_TOKEN_DARK.get(tok)}")
|
||
check(doc.get("themes", {}).get("mode") == ["light", "dark"], "ось темы mode: light+dark зарегистрирована")
|
||
|
||
nodes = list(walk(frame))
|
||
by_name = {}
|
||
for n in nodes:
|
||
by_name.setdefault(n.get("name"), []).append(n)
|
||
|
||
def count(prefix):
|
||
return sum(1 for n in nodes if (n.get("name") or "").startswith(prefix))
|
||
|
||
hero = by_name.get("Hero", [{}])[0]
|
||
check(len([n for n in nodes if n.get("name") == "H1"]) == 1, "hero: H1 один")
|
||
check(len([n for n in nodes if n.get("name") == "Оффер"]) == 1, "hero: оффер один")
|
||
check(len([n for n in nodes if n.get("name") == "Ряд CTA"]) == 1, "hero: ряд CTA один")
|
||
check(len([n for n in nodes if n.get("name") == "Арт планеты"]) == 1, "hero: арт планеты один")
|
||
check(len([n for n in nodes if n.get("name") == "Плашка проекта"]) == 1, "hero: плашка планеты (§10.11) есть")
|
||
check(len([n for n in nodes if n.get("name") == "Полоса «Студия полного цикла»"]) == 1,
|
||
"hero: полоса «Студия полного цикла» есть")
|
||
check(count("Стат ") == 4, f"полоса: 4 стата (найдено {count('Стат ')})")
|
||
check(len([n for n in nodes if (n.get("name") or "").startswith("Плашка «")]) == 3,
|
||
"hero: 3 плашки «о нас»")
|
||
check(len([n for n in nodes if n.get("name") == "Тумблер темы"]) == 1, "navbar: тумблер темы есть")
|
||
check(len([n for n in nodes if (n.get("name") or "").startswith("Ссылка ")]) == 4, "navbar: 4 ссылки")
|
||
|
||
case_titles = {"World Wide Wheels", "Moba", "BattleCaps", "TITANS", "Буквика", "Ассоциации"}
|
||
cases = [n for n in nodes if n.get("name") in {"Карточка " + t for t in case_titles}]
|
||
check(len(cases) == 6, f"портфолио: 6 карточек (4 в работе + 2 выпущенные), найдено {len(cases)}")
|
||
check({n["name"].removeprefix("Карточка ") for n in cases} == case_titles,
|
||
"портфолио: состав карточек = 6 проектов прода")
|
||
check(len([n for n in nodes if n.get("name") == "Портфолио 2×2"]) == 1, "портфолио: сетка 2×2 есть")
|
||
check(len([n for n in nodes if n.get("name") == "Выпущенные игры"]) == 1, "портфолио: ряд выпущенных игр есть")
|
||
check(len([n for n in nodes if (n.get("name") or "").startswith("Участник ")]) == 5, "команда: 5 карточек")
|
||
check(len([n for n in nodes if (n.get("name") or "").startswith("Вопрос «")]) == 5, "контакты: 5 вопросов FAQ")
|
||
check(len([n for n in nodes if (n.get("name") or "").startswith("Поле ")]) == 3, "форма: 3 поля")
|
||
check(len([n for n in nodes if n.get("name") == "Карточка формы"]) == 1, "форма: карточка одна")
|
||
check(len([n for n in nodes if n.get("name") == "Footer"]) == 1, "футер есть")
|
||
check(len([n for n in nodes if n.get("name") == "Hero Ticker"]) == 1, "тикер есть")
|
||
check(len([n for n in nodes if n.get("type") == "text" and not n.get("fill")]) == 0,
|
||
"у всех текстов задан fill")
|
||
|
||
dark = next((c for c in doc["children"] if c.get("name") == "B Editorial Agency — Dark"), None)
|
||
check(dark is not None, "тёмный фрейм-близнец есть")
|
||
check(dark and dark.get("id") == "dRoot1", f"id тёмного фрейма = dRoot1 (есть {dark and dark.get(chr(34)+chr(105)+chr(100)+chr(34))})")
|
||
if dark:
|
||
check(dark.get("theme", {}).get("mode") == "dark", "тёмный фрейм помечен theme=mode:dark")
|
||
check([c["name"] for c in dark["children"]] == names, "тёмный фрейм повторяет состав секций")
|
||
light_ids = {n.get("id") for n in walk(frame)}
|
||
dark_ids = {n.get("id") for n in walk(dark)}
|
||
check(not (light_ids & dark_ids), "id светлого и тёмного фреймов не пересекаются")
|
||
check(len(list(walk(dark))) == len(nodes), f"одинаковый размер дерева ({len(nodes)} узлов)")
|
||
check(len([n for n in walk(dark) if n.get("name") == "Плашка проекта"]) == 1, "тёмный фрейм: плашка планеты есть")
|
||
|
||
acc = ids(frame, set())
|
||
ids(dark, acc) if dark else None
|
||
print(f" файл: узлов в фрейме B = {len(nodes)}, переменных = {len(doc['variables'])}, фреймов = {len(doc['children'])}")
|
||
|
||
print("\n" + ("ВСЕ ПРОВЕРКИ ПРОЙДЕНЫ" if not problems else f"ПРОВАЛОВ: {len(problems)}"))
|
||
for p in problems:
|
||
print(" -", p)
|
||
sys.exit(1 if problems else 0)
|