from __future__ import annotations import json import os import shutil import sys import time 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 from hub_case import HubCase from hub_support import iso OUT = Path(os.environ.get("E2E_OUT", "/tmp/hub-079-shots")) WORKTREE = "/repo/.worktrees/feature/links" FILE = "src/my app#1.py" ACTIONS = "click opens in VS Code, right-click copies the path" LINKS = """(async () => {@HELPERS@ const card = () => document.querySelector("#main .match-card.front"); await screenShown(8000); await until(() => card() && card().querySelector(".match-file .diff-head"), 8000); await sleep(400); const copied = []; navigator.clipboard.writeText = (value) => { copied.push(value); return Promise.resolve(); }; const chip = (place) => card().querySelector(`.match-place .match-where[data-place="${place}"]`); const head = card().querySelector(".match-file .diff-head a.path-link"); const menuShut = () => all(".ctx-menu").every((menu) => menu.hidden); const rightClick = (node) => { const box = node.getBoundingClientRect(); return !node.dispatchEvent(new MouseEvent("contextmenu", {bubbles: true, cancelable: true, clientX: box.left + 4, clientY: box.top + 4, button: 2})); }; const leftClick = (node) => { document.addEventListener("click", (event) => event.preventDefault(), {capture: true, once: true}); node.click(); }; const facts = { branch: [chip("branch").tagName, chip("branch").getAttribute("href")], repo: [chip("repo").tagName, chip("repo").getAttribute("href"), chip("repo").title], worktree: [chip("worktree").tagName, chip("worktree").getAttribute("href"), chip("worktree").title], head: head ? [head.getAttribute("href"), text(head.querySelector("code.path")), head.title] : null, }; leftClick(chip("worktree")); await sleep(100); const clickCopied = copied.length; const prevented = [rightClick(chip("worktree")), rightClick(head)]; await sleep(200); return {...facts, clickCopied, prevented, copied, menuShut: menuShut(), wide: document.documentElement.scrollWidth > window.innerWidth + 1}; })()""" @unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium") class TestPathLinks(HubCase): drive = base.OrchestratorE2ECase.drive def setUp(self): super().setUp() now = time.time() self.write_council({"work/s1/claim.json": {"office": "work/s1", "session": "s1", "runtime": "claude", "name": "Skills", "since": iso(now - 86400), "beat": now, "work": "links"}}) patch = "@@ -1,2 +1,3 @@\n first\n+added\n second" diff = [{"path": FILE, "status": "M", "mode": "100644", "additions": 1, "deletions": 0, "patch": patch, "note": ""}] arguments = {**self.arguments("feat: path links", "", self.page("links.html", "