import json from perfkit import results from perfkit.modals_inventory import build, render_md, load_modals MODALS = [ {"id": "a", "title": "A", "page": "task", "source": "web/src/a.jsx:1", "priority": 1, "role": "rf", "open": {"selector": "button", "action": "click"}}, {"id": "b", "title": "B", "page": "forms", "source": "web/src/b.jsx:2", "priority": 1, "role": "admin", "open": {"selector": "", "action": "click"}, "skip_reason": "мёртвый код"}, {"id": "c", "title": "C", "page": "admin_users", "source": "web/src/c.jsx:3", "priority": 2, "role": "admin", "open": {"selector": "x", "action": "click"}, "big_sheet": "FORM_2/AHR/null"}, ] def rec(target, v, **kw): r = {"run_id": "r", "scenario": "modal", "target": target, "role": "rf", "scale": 1, "cpu_rate": 1, "repeat": 0, "metrics": {"click_to_visible_ms": v, "main_thread_ms": v + 5}, "artifacts": [], "incomplete": False, "ts": "x"} r.update(kw) return r def test_build_marks_skipped_and_measured(tmp_path): for v in (10, 30, 20): results.append(tmp_path, rec("a", v)) results.append(tmp_path, rec("a", 999, incomplete=True, metrics={})) rows = {r["id"]: r for r in build(MODALS, tmp_path)} assert rows["a"]["status"] == "measured" and rows["a"]["n"] == 3 and rows["a"]["median_ms"] == 20 assert rows["b"]["status"] == "skip" and rows["b"]["skip_reason"] == "мёртвый код" assert rows["c"]["status"] == "not_run" def test_render_md_table(tmp_path): md = render_md(build(MODALS, None)) assert "| id |" in md and "`a`" in md and "мёртвый код" in md assert md.count("\n|") >= 4 # заголовок + разделитель + 3 строки def test_load_real_modals_json_is_consistent(): ms = load_modals() ids = [m["id"] for m in ms] assert len(ids) == len(set(ids)) for m in ms: assert m["priority"] in (1, 2) and m["source"].startswith("web/src/") assert m.get("skip_reason") or (m["open"]["selector"] and (m.get("page_ref") or m.get("sheet_ref")))