from __future__ import annotations import json import os import shutil import sys import unittest from pathlib import Path HERE = Path(__file__).resolve().parent sys.path[:0] = [str(HERE.parent), str(HERE)] import hub_e2e_kit as base import test_home_bookmarks_e2e as bm import test_home_dashboard_e2e as dash import test_match_review_e2e as matched import test_workbench_w4_e2e as w4 from hub_case import HubCase from test_hub_match import git, merge_repo OUT = Path(os.environ.get("E2E_OUT", "/tmp/match-content-shots")) SCAN = """ const stray = (root) => { const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT); const found = []; for (let node = walker.nextNode(); node; node = walker.nextNode()) { if (["null", "undefined"].includes(node.nodeValue.trim())) { found.push(node.parentElement ? node.parentElement.className || node.parentElement.tagName : "-"); } } return found; }; """ MERGE = """(async () => {@HELPERS@@CARD@@SCAN@ await screenShown(8000); await until(card, 8000); const shown = await pick("@MERGE@"); await sleep(400); const files = shown ? all(".match-file", shown).map((file) => file.dataset.path) : null; const added = shown ? all(".match-file tr", shown).some((row) => text(row).includes("added = 2")) : false; const visited = []; for (const tab of all("#main .match-peek")) { tab.click(); await sleep(250); visited.push(stray(document.getElementById("main"))); } return {files, added, none: text(shown && shown.querySelector(".match-body > p.muted")), stray: stray(document.getElementById("main")), visited: visited.flat(), reasons: all("#main .match-reason").filter((node) => ["", "-"].includes(text(node).trim())).length, wide: document.documentElement.scrollWidth > innerWidth + 1}; })()""" SEED = """(async () => {@HELPERS@ await ViewStore.update("home.pins", () => [{kind: "panel", id: "tasks/match", w: innerWidth > 640 ? 6 : 4, h: 6}]); return true; })()""" TILE = """(async () => {@HELPERS@@HOME@@SCAN@ await go("home"); const pinned = await until(() => tile("panel:tasks/match")?.querySelector(".match-card"), 8000); await sleep(600); return {found: Boolean(pinned), stray: stray(document.getElementById("main"))}; })()""" def probe(template: str, **names: str) -> str: fills = {"@HELPERS@": base.HELPERS, "@HOME@": dash.HOME, "@CARD@": matched.CARD, "@SCAN@": SCAN} fills.update({f"@{key.upper()}@": value for key, value in names.items()}) for key, value in fills.items(): template = template.replace(key, value) return template @unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium") class TestMatchContent(HubCase): drive = base.OrchestratorE2ECase.drive cards = matched.TestMatchReview.cards review = matched.TestMatchReview.review payload = matched.TestMatchReview.payload def setUp(self): super().setUp() OUT.mkdir(parents=True, exist_ok=True) self.cards() repo, target = merge_repo(self.work) git(repo, "merge", "--no-commit", "--no-ff", "-q", target) arguments = {**self.arguments("Merge feature into main", "", self.page("merge.html", "