"""test_ax_structure.py — AX STRUCTURE lane for Logseq (macos-logseq-logseq). Every fact asserted here comes from `recon.md` (`## APP`, `## AX_TREE`, `## STRUCTURE`, `## VISUAL`) — observed by driving the running reference app. Nothing was read from the app source tree and no live tree was explored while authoring this module. ROLE CENSUS catalogued from recon `## AX_TREE` (fresh launch, 563 elements total): group 202, menu_item 142, label 94, link 55, image 25, button 17, menu 12, menu_bar_item 8, heading 5, checkbox 3, list 2, popup 2, application 1, window 1, webarea 1, splitter 1, menu_bar 1, text_field 1, table 1, column 1 -> 20 distinct roles; the gate asserts >= 12 distinct roles and >= 350 total elements. RECON NOTES (why some "standard" structure checks are shaped differently for this app): * There is NO `AXToolbar` in the census — Logseq is Electron and its toolbar is a row of `AXButton`s inside the `AXWebArea`. The toolbar is therefore verified by its 8 NAMED controls (recon STRUCTURE gate item 3), not by a toolbar role. * There is NO status bar and NO `AXTabGroup`/`AXTab`: the right sidebar's "tabs" are `AXButton`s (`Contents` / `Page graph` / `Help`) beside `splitter "Right sidebar resize handler"` (gate item 5). Panels are `AXGroup`s (`Navigation menu`, `Warning`, `Tip`, `Notifications (F8)`, ...). * `link " Whiteboards"` and `button " Create"` carry a leading icon glyph, so those are matched by visible-label substring, never `==`. * Locators are semantic: visible label (AXTitle/AXDescription or AXValue) + AXRole. No child indexes, no tree paths, no framework-internal identifiers. * Nothing on recon's NEVER-PRESS lists is activated: the macOS menu bar is read statically with `root_id` scoping, and the only presses are the toolbar sidebar toggles, `Search`, `More`, sidebar nav links, `link "Settings"`, `link "Close"` and the in-block page reference. No Settings checkbox is pressed OR read (recon FOCUS/UNREACHED forbid both). """ # ── MANDATORY PREAMBLE (copied verbatim from recon.md ## APP) ──────────────── import os, time, re, json, subprocess, datetime import pytest import rb_testgen_kit as kit import verifier_helpers as helpers RESULTS_DIR = os.environ.get("RESULTS_DIR") or os.path.join(os.path.dirname(__file__), "baseline_results") def rb_enter_app(ax, timeout=60.0, min_els=150): """NAV/readiness gate — Logseq's Chromium AX tree is EMPTY then partially built for the first ~3 s after launch; the demo graph content streams in after that. Every test MUST call this first or it reads a half-built tree and fails spuriously. Ready = a window with a real title (not 'Loading...') AND element count stable AND large.""" end = time.time() + timeout prev, stable = -1, 0 while time.time() < end: try: wins = [w.name or "" for w in ax.find(role="window", max_results=10)] n = len(ax.find(max_results=8000)) if wins and not any("Loading" in w for w in wins) and n >= min_els: stable = stable + 1 if n == prev else 0 if stable >= 2: return True prev = n except Exception: pass time.sleep(0.6) return False def showing(ax): """rb_showing MUST be called with max_depth>=18 for this app — the default 12 does NOT reach into Logseq's Chromium subtree and returns an identical set every time.""" return kit.rb_showing(ax, max_depth=30) def find_el(ax, text, role=None, idx=0): """Locate by AXTitle/AXDescription **or** AXValue (Logseq labels carry the text in AXValue and have an empty name, while buttons/links carry it in the name).""" hits = [] for e in ax.find(role=role, max_results=8000): nm = (e.name or "") vl = e.value if isinstance(e.value, str) else "" if nm.strip() == text or vl.strip() == text: hits.append(e) return hits[idx] if len(hits) > idx else None def find_contains(ax, text, role=None): for e in ax.find(role=role, max_results=8000): nm = (e.name or "") vl = e.value if isinstance(e.value, str) else "" if text in nm or text in vl: return e return None def all_text(ax): """Every non-empty text string the app currently exposes (labels use AXValue, headings/ links/buttons use AXTitle).""" out = [] for e in ax.find(max_results=8000): if e.role in ("menu_item", "menu_bar_item", "menu", "menu_bar"): continue for f in ((e.name or ""), (e.value if isinstance(e.value, str) else "")): if f.strip(): out.append(f.strip()) return out def win_title(ax): ws = [w.name or "" for w in ax.find(role="window", max_results=10)] return ws[0] if ws else "" def el_width(ax, e): g = ax.get(e.id, ["AXSize"]) m = re.findall(r"w:([-\d.]+)", str(g.get("AXSize"))) return float(m[0]) if m else -1.0 def press(ax, e): """Activate an element. ALWAYS try AXPress first, even when the element does not advertise it: Logseq's Chromium tree omits AXPress from the action list of its clickable
s (the bottom-right '?' FAB, in-block page references, the TODO rotator) yet AXUIElementPerformAction still drives them, and it drives them CORRECTLY (a page reference navigates, whereas a synthetic click at the same point merely docks it in the right sidebar). The CGEvent click is only a fallback for when AXPress genuinely fails.""" if ax.action(e.id, "AXPress"): return True return ax.click_element_cg(e.id) def esc(n=2): for _ in range(n): helpers.send_key(helpers.KC_ESCAPE) time.sleep(0.5) def screenshot_assert(test_name, description, results_dir=RESULTS_DIR): ss_dir = os.path.join(results_dir, "screenshots") os.makedirs(ss_dir, exist_ok=True) ss_path = os.path.join(ss_dir, "%s.png" % test_name) try: subprocess.run(["screencapture", "-x", ss_path], timeout=5) except Exception: pass af = os.path.join(ss_dir, "assertions.json") data = {} if os.path.exists(af): try: with open(af) as f: data = json.load(f) except Exception: data = {} data["%s.png" % test_name] = description with open(af, "w") as f: json.dump(data, f, indent=2) # ── END MANDATORY PREAMBLE ─────────────────────────────────────────────────── # ── sidebar state normalisers ──────────────────────────────────────────────── # Logseq PERSISTS both sidebar states in its Electron profile, so "the state on launch" is # whatever a previous run left behind. Every sidebar test therefore NORMALISES the sidebar to # the state it wants to flip FROM instead of assuming a default — the flip itself is still the # thing under test, and the same test drives a recreation whose default differs. def rb_enter_right_sidebar_state(ax, want_open, tries=3): """Put the right sidebar into `want_open`. Returns True when it got there.""" for _ in range(tries): if (find_el(ax, "Contents", role="button") is not None) == want_open: return True tog = find_el(ax, "Toggle right sidebar", role="button") if tog is None: return False press(ax, tog) time.sleep(2.0) return (find_el(ax, "Contents", role="button") is not None) == want_open def rb_enter_left_sidebar_state(ax, want_expanded, tries=3): """Put the left sidebar into `want_expanded`, measured by nav-link AXSize width.""" for _ in range(tries): j = find_el(ax, "Journals", role="link") if j is None: return False w = el_width(ax, j) if w >= 0.0 and (w > 50.0) == want_expanded: return True tog = find_el(ax, "Toggle left sidebar", role="button") if tog is None: return False press(ax, tog) time.sleep(2.0) j = find_el(ax, "Journals", role="link") return j is not None and (el_width(ax, j) > 50.0) == want_expanded READY_MSG = ("Logseq AX tree never became ready (no window with a real title, or the element " "count never stabilised at >= 150 within 60 s)") # Catalogued from recon ## AX_TREE + ## STRUCTURE gate items 3-6. TOOLBAR_BUTTONS = ["Skip to main content", "Toggle left sidebar", "Search", "Go back", "Go forward", "More", "Toggle right sidebar"] NAV_LINKS = ["Journals", "Whiteboards", "Flashcards", "Graph view", "All pages"] RIGHT_SIDEBAR_TABS = ["Contents", "Page graph", "Help"] FLOATING_GROUPS = ["Notifications (F8)", "Click to check shortcuts and other tips"] MENU_BAR_ITEMS = ["Logseq", "File", "Edit", "View", "Window", "Help"] MORE_MENU_LINKS = ["Settings", "Import", "Export graph", "Plugins", "Themes", "Join the community", "Bug report"] SETTINGS_TABS = ["General", "Editor", "Keymap", "Version control", "Advanced", "Features"] # Per-role count floors observed on a PRISTINE fresh launch (n=518: heading 4, link 50, # label 84, button 11, checkbox 3, group 176). At rest there is NO text_field and NO popup — # the search field only exists while the search modal is open and the right-sidebar `More` # popup only while that sidebar is open, so both are covered by the delta tests instead. ROLE_FLOORS = {"heading": 4, "link": 40, "label": 80, "button": 11, "checkbox": 3, "group": 150} # BOTH sidebars are CLOSED on a pristine launch. Toggling the right one open adds exactly # these four buttons (plus popup "More"); the pristine right sidebar is otherwise empty. RSB_CLUSTER = ["Contents", "Page graph", "Help", "Close"] EXPANDED_MIN = 50.0 # an expanded nav link measures 213-234 pt depending on window width COLLAPSED_MAX = 3.0 # a collapsed nav link keeps its node in the tree at width 1.0 # ── one-pass catalog + semantic label matching (no indexes, no tree paths) ─── def catalog(ax): """ONE full pass over the app's AX tree -> (elements, {"role|visible label"}, role census). Both AXTitle/AXDescription (buttons, links, headings, groups, windows) and AXValue (labels) are indexed, mirroring the preamble's find_el semantics.""" els = ax.find(max_results=8000) labels = set() census = {} for e in els: census[e.role] = census.get(e.role, 0) + 1 nm = (e.name or "").strip() vl = (e.value if isinstance(e.value, str) else "").strip() if nm: labels.add("%s|%s" % (e.role, nm)) if vl: labels.add("%s|%s" % (e.role, vl)) return els, labels, census def has(labels, role, text): """Exact visible-label match for a role.""" return ("%s|%s" % (role, text)) in labels def has_like(labels, role, text): """Visible-label match tolerating a leading icon glyph / decoration (`link " Whiteboards"`, `button " Create"`, `heading "All whiteboards · 0"`).""" pre = role + "|" for k in labels: if k.startswith(pre) and text in k[len(pre):]: return True return False def names_for(labels, role): pre = role + "|" return sorted(k[len(pre):] for k in labels if k.startswith(pre)) def wait_until(fn, timeout=8.0, interval=0.6): """Poll `fn` until it is truthy. React replaces nodes asynchronously, so every state change is re-read rather than assumed. Returns the final truthiness.""" end = time.time() + timeout while True: try: if fn(): return True except Exception: pass if time.time() >= end: return False time.sleep(interval) def find_nav_link(ax, label_text): """A left-sidebar nav link located by its VISIBLE label, tolerating the leading icon glyph Logseq puts in the AXTitle (e.g. `link " Whiteboards"`).""" for e in ax.find(role="link", max_results=8000): nm = (e.name or "").strip() if nm == label_text or nm.endswith(label_text) or label_text in nm: return e return None def find_btn_contains(ax, fragment): """A button whose visible label CONTAINS `fragment` (e.g. the `" Create"` button).""" for e in ax.find(role="button", max_results=8000): if fragment in (e.name or ""): return e return None def find_heading_contains(ax, fragment): for e in ax.find(role="heading", max_results=8000): if fragment in (e.name or ""): return e return None def surface_titles(ax): """Titles of every top-level surface (AXWindow + AXWebArea) — Logseq's route indicator.""" out = [w.name or "" for w in ax.find(role="window", max_results=10)] out += [w.name or "" for w in ax.find(role="webarea", max_results=10)] return out def right_sidebar_markers(ax): """The right-sidebar cluster as a sorted list of the markers CURRENTLY present. On a pristine launch the right sidebar is CLOSED, so this is empty; toggling it open yields all five (the four tab/close buttons plus the panel's `More` popup).""" _els, labels, _census = catalog(ax) found = [] for n in RSB_CLUSTER: if has(labels, "button", n): found.append("button %s" % n) if has(labels, "popup", "More"): found.append("popup More") return sorted(found) # ── navigation helpers (named rb_enter_*/rb_reach_* so declared depth is backed) ── def rb_enter_search(ax): """NAV surface +1: toolbar `button "Search"` -> the search modal.""" btn = find_el(ax, "Search", role="button") assert btn is not None, "toolbar button 'Search' not found — cannot open the search modal" press(ax, btn) time.sleep(2.5) wait_until(lambda: len(ax.find(role="text_field", max_results=50)) >= 2, timeout=6.0) def rb_enter_more_menu(ax): """NAV surface +1: toolbar `button "More"` -> the `⋯` dropdown.""" btn = find_el(ax, "More", role="button") assert btn is not None, "toolbar button 'More' not found — cannot open the More dropdown" press(ax, btn) time.sleep(1.6) wait_until(lambda: find_el(ax, "Settings", role="link") is not None, timeout=6.0) def rb_reach_settings_modal(ax): """NAV surface +1 (from the OPEN More dropdown): `link "Settings"` -> the Settings modal.""" lnk = find_el(ax, "Settings", role="link") assert lnk is not None, "link 'Settings' not present in the open More dropdown" press(ax, lnk) time.sleep(2.5) wait_until(lambda: find_el(ax, "Settings", role="heading") is not None, timeout=8.0) def rb_reach_route(ax, label_text): """NAV surface +1: press a left-sidebar nav link to switch route (the window title is the route indicator, so settle on the title change).""" lnk = find_nav_link(ax, label_text) assert lnk is not None, "left-sidebar nav link %r not found" % label_text prev = win_title(ax) press(ax, lnk) time.sleep(2.5) wait_until(lambda: win_title(ax) != prev, timeout=8.0) def rb_reach_dummy_notes_page(ax): """NAV surface +1: press the in-block page reference `group "How to take dummy notes?"`.""" g = find_el(ax, "How to take dummy notes?", role="group") assert g is not None, ("page-reference group 'How to take dummy notes?' not found in today's " "journal content") prev = win_title(ax) press(ax, g) time.sleep(2.5) wait_until(lambda: win_title(ax) != prev, timeout=8.0) def rb_reach_flashcards_modal(ax): """NAV surface +1: `link "Flashcards"` -> the flashcards modal (NOT a route, so the window title deliberately stays 'Logseq' — settle on the modal heading instead).""" lnk = find_nav_link(ax, "Flashcards") assert lnk is not None, "left-sidebar link 'Flashcards' not found" press(ax, lnk) time.sleep(2.5) wait_until(lambda: find_el(ax, "Time to create a card!", role="heading") is not None, timeout=8.0) def rb_back_to_journals(ax): """Cleanup: return to the journal route (belt-and-braces — the app relaunches per test).""" lnk = find_nav_link(ax, "Journals") if lnk is not None: press(ax, lnk) time.sleep(2.0) # ───────────────────────────────────────────────────────────────────────────── # GATE — existence only (jump_kind="none", depth=0). recon STRUCTURE items 1-8. # ───────────────────────────────────────────────────────────────────────────── class TestStructureGate: @pytest.mark.rb(depth=0, jump_kind="none") def test_gate_window_menu_bar_and_role_census(self, ax): """Gate 1 + 2 + 7 + 8: exactly one AXWindow titled `Logseq` containing an AXWebArea, an AXMenuBar carrying the six named app menus, >= 12 distinct roles, >= 350 elements, the per-role count floors and a real interactive-widget population.""" assert rb_enter_app(ax), READY_MSG els, labels, census = catalog(ax) assert census.get("window", 0) == 1, ( "expected exactly 1 AXWindow, found %d (titles %r)" % ( census.get("window", 0), names_for(labels, "window"))) assert has(labels, "window", "Logseq"), ( "no AXWindow titled 'Logseq' on the journals route; window titles were %r" % (names_for(labels, "window"),)) assert census.get("webarea", 0) >= 1, ( "no AXWebArea under the window (Logseq renders its whole UI in a web area)") assert has(labels, "webarea", "Logseq"), ( "no AXWebArea titled 'Logseq'; web-area titles were %r" % (names_for(labels, "webarea"),)) assert census.get("menu_bar", 0) >= 1, "no AXMenuBar exposed by the app" mbi_names = names_for(labels, "menu_bar_item") missing = [n for n in MENU_BAR_ITEMS if n not in mbi_names] assert not missing, "menu bar is missing menu_bar_item(s) %r; found %r" % (missing, mbi_names) assert len(els) >= 350, ( "total AX element count is %d, expected >= 350 (recon observed 563 on a fresh " "launch)" % len(els)) assert len(census) >= 12, ( "only %d distinct AX roles exposed, expected >= 12; roles=%r" % ( len(census), sorted(census))) low = {r: (census.get(r, 0), floor) for r, floor in ROLE_FLOORS.items() if census.get(r, 0) < floor} assert not low, "per-role count floor(s) not met {role: (found, floor)} = %r" % (low,) assert census.get("menu_item", 0) >= 40, ( "only %d menu_item elements; recon observed 142 across the six app menus " "(Logseq 10 / File 3 / Edit 16 / View 9 / Window 16 / Help 1 + submenus)" % census.get("menu_item", 0)) assert census.get("splitter", 0) >= 1, ( "no AXSplitter found (recon: splitter 'Right sidebar resize handler')") interactive = [e for e in els if "AXPress" in (e.actions or [])] assert len(interactive) >= 60, ( "only %d elements expose AXPress, expected >= 60 interactive widgets (toolbar + nav " "links + menu items + in-block controls)" % len(interactive)) screenshot_assert( "structure_default_layout", "Logseq main window on its journals route: a slim toolbar across the top with a " "hamburger toggle and a search icon on the left and 'Add a graph', a '...' menu " "and a right-sidebar toggle on the right; the content column below shows an orange " "warning triangle beside the demo-graph banner, then a large date heading and the " "'Hi, welcome to Logseq!' tutorial bullets. Neither side panel is expanded.") @pytest.mark.rb(depth=0, jump_kind="none") def test_gate_menu_bar_items_are_statically_readable(self, ax): """Gate 2 (detail): each named `menu_bar_item` owns an `AXMenu` whose depth-1 `menu_item`s are readable WITHOUT pressing anything (recon MENUS). Nothing is activated — every item in these menus is on recon's NEVER-PRESS list or irrelevant.""" assert rb_enter_app(ax), READY_MSG expect_counts = {"Logseq": 10, "File": 3, "Edit": 16, "View": 9, "Window": 16, "Help": 1} seen = {} for menu_name in MENU_BAR_ITEMS: mbi = find_el(ax, menu_name, role="menu_bar_item") assert mbi is not None, "menu_bar_item %r not found" % menu_name menus = ax.find(role="menu", root_id=mbi.id, max_results=5) assert menus, "menu_bar_item %r exposes no AXMenu child" % menu_name items = [(m.name or "").strip() for m in ax.find(role="menu_item", root_id=menus[0].id, max_results=200, max_depth=1)] seen[menu_name] = items assert len(items) >= expect_counts[menu_name], ( "menu %r has %d depth-1 items, recon observed %d (%r)" % ( menu_name, len(items), expect_counts[menu_name], items)) # App-owned items asserted by NAME (recon MENUS); Edit/Window are macOS-version # dependent, so only the stable subset is required there. assert "About Logseq" in seen["Logseq"], ( "Logseq menu %r does not include 'About Logseq'" % (seen["Logseq"],)) assert "Close Window" in seen["File"], ( "File menu %r does not include 'Close Window'" % (seen["File"],)) for n in ("Actual Size", "Zoom In", "Zoom Out"): assert n in seen["View"], "View menu %r does not include %r" % (seen["View"], n) assert "Official Documentation" in seen["Help"], ( "Help menu %r does not include 'Official Documentation'" % (seen["Help"],)) missing_edit = [n for n in ("Undo", "Redo", "Cut", "Copy", "Paste", "Select All") if n not in seen["Edit"]] assert not missing_edit, "Edit menu is missing %r; found %r" % (missing_edit, seen["Edit"]) missing_win = [n for n in ("Minimize", "Zoom", "Bring All to Front") if n not in seen["Window"]] assert not missing_win, "Window menu is missing %r; found %r" % ( missing_win, seen["Window"]) @pytest.mark.rb(depth=0, jump_kind="none") def test_gate_toolbar_sidebars_and_floating_groups(self, ax): """Gate 3 + 4 + 5 + 6: the 8 named toolbar controls, the left-sidebar `group "Navigation menu"` with its 5 nav links + FAVORITES/RECENT + Create, the right-sidebar tab buttons + resize splitter, and the two floating groups.""" assert rb_enter_app(ax), READY_MSG _els, labels, _census = catalog(ax) missing_tb = [n for n in TOOLBAR_BUTTONS if not has(labels, "button", n)] assert not missing_tb, "toolbar button(s) missing: %r" % (missing_tb,) assert has(labels, "link", "Add a graph"), ( "toolbar link 'Add a graph' not found (the 8th toolbar control)") assert has(labels, "group", "Navigation menu"), ( "left-sidebar container group 'Navigation menu' not found") missing_nav = [n for n in NAV_LINKS if not has_like(labels, "link", n)] assert not missing_nav, ( "left-sidebar nav link(s) missing: %r (note: Whiteboards' AXTitle carries a leading " "icon glyph, so it is matched by substring); link titles were %r" % (missing_nav, names_for(labels, "link")[:20])) assert has(labels, "link", "Demo"), "left-sidebar graph-switcher link 'Demo' not found" for lbl in ("FAVORITES", "RECENT"): assert has(labels, "label", lbl), "left-sidebar section label %r not found" % lbl assert has_like(labels, "button", "Create"), ( "left-sidebar button whose visible label contains 'Create' not found") create = find_btn_contains(ax, "Create") assert create is not None and "AXPress" in (create.actions or []), ( "the Create button exposes no AXPress action (actions=%r)" % ( (create.actions if create else None),)) # The right sidebar is CLOSED on a pristine launch, so only its resize splitter is # present at rest; its tab cluster is proved by the toggle delta test below. assert has(labels, "splitter", "Right sidebar resize handler"), ( "splitter 'Right sidebar resize handler' not found") for g in FLOATING_GROUPS: assert has(labels, "group", g), "floating group %r not found" % g for g in ("Warning", "Tip"): assert has(labels, "group", g), ( "in-content panel group %r not found on today's journal page" % g) # ───────────────────────────────────────────────────────────────────────────── # SHAPE DELTAS — sidebars + dropdowns (recon S1, S2, S3, S4, S5) # ───────────────────────────────────────────────────────────────────────────── class TestLayoutShapeDeltas: @pytest.mark.rb(depth=1, jump_kind="reach", expect="button 'Search' -> text_field count 0->1 and label 'Commands' + " "footer label 'Tip:' appear") def test_search_modal_adds_a_second_text_field(self, ax): """recon S1 — at rest Logseq exposes NO text_field; opening the search modal adds one.""" assert rb_enter_app(ax), READY_MSG fields_before = len(ax.find(role="text_field", max_results=50)) assert fields_before == 0, ( "expected 0 text_field at rest on a pristine launch, found %d" % fields_before) assert find_el(ax, "Commands", role="label") is None, ( "label 'Commands' already present before the search modal was opened") before = showing(ax) rb_enter_search(ax) after = showing(ax) ok = kit.rb_reach(before, after, target="Commands", source=None) fields_after = len(ax.find(role="text_field", max_results=50)) assert fields_after == 1, ( "text_field count went 0 -> %d; the open search modal contributes exactly one " "editable field" % fields_after) assert find_el(ax, "Commands", role="label") is not None, ( "label 'Commands' missing from the open search modal") # The modal renders a footer 'Tip:' line. Its SENTENCE rotates between usage hints on # each open, so only the stable prefix is asserted, never the hint's wording. wait_until(lambda: find_el(ax, "Tip:", role="label") is not None, timeout=8.0) assert find_el(ax, "Tip:", role="label") is not None, ( "the open search modal exposes no footer 'Tip:' label") assert ok, ("the search modal did not register as a surface jump: no new AX node matching " "'Commands' appeared after AXPress on button 'Search'") esc(2) @pytest.mark.rb(depth=1, jump_kind="reach", expect="right-sidebar cluster (buttons Contents/Page graph/Help/Close + " "popup 'More'): 0 markers -> 5 after AXPress 'Toggle right sidebar', " "back to 0 on the 2nd press") def test_right_sidebar_toggle_removes_then_restores_cluster(self, ax): """recon S2 + S3 / STATE T2 — the round trip. A pristine launch has the right sidebar CLOSED, so the OPEN leg is the surface jump and the 2nd press tears it down again.""" assert rb_enter_app(ax), READY_MSG assert rb_enter_right_sidebar_state(ax, False), ( "could not normalise the right sidebar to CLOSED before testing the open flip") closed = right_sidebar_markers(ax) assert closed == [], ( "with the right sidebar closed none of its markers should be present; found %r" % (closed,)) btn = find_el(ax, "Toggle right sidebar", role="button") assert btn is not None, "toolbar button 'Toggle right sidebar' not found" before_open = showing(ax) press(ax, btn) time.sleep(1.8) wait_until(lambda: find_el(ax, "Contents", role="button") is not None, timeout=8.0) after_open = showing(ax) opened = right_sidebar_markers(ax) reach = kit.rb_reach(before_open, after_open, target="Contents", source=None) assert opened == sorted(["button %s" % n for n in RSB_CLUSTER] + ["popup More"]), ( "opening the right sidebar should expose the buttons %r plus popup 'More'; found %r" % (RSB_CLUSTER, opened)) assert reach, ("opening the right sidebar produced no new AX node matching 'Contents'") # Close again — re-find the toggle, React replaced the toolbar nodes. btn2 = find_el(ax, "Toggle right sidebar", role="button") assert btn2 is not None, ( "toolbar button 'Toggle right sidebar' vanished while the sidebar was open") press(ax, btn2) time.sleep(1.8) wait_until(lambda: find_el(ax, "Contents", role="button") is None, timeout=8.0) reclosed = right_sidebar_markers(ax) screenshot_assert( "structure_right_sidebar_closed", "The right panel is gone: no Contents / Page graph / Help tab row on the right edge; " "the journal column occupies the content area, with the demo-graph banner and the " "large date heading visible.") assert reclosed == [], ( "the second AXPress on 'Toggle right sidebar' left these markers behind: %r" % (reclosed,)) assert kit.rb_flip(closed, opened, expect="0 -> 5 right-sidebar markers"), ( "the right-sidebar marker set did not change when the sidebar was toggled open") @pytest.mark.rb(depth=0, jump_kind="transition", expect="link 'Journals' AXSize width <=3 (collapsed) -> >=50 (expanded) on " "AXPress 'Toggle left sidebar', collapsed again on the 2nd press") def test_left_sidebar_collapse_changes_journals_link_width(self, ax): """recon S4 / STATE T3 — rb_showing does NOT change here, the WIDTH does. A pristine launch has the left sidebar COLLAPSED (the nav nodes stay in the tree at width 1.0).""" assert rb_enter_app(ax), READY_MSG assert rb_enter_left_sidebar_state(ax, False), ( "could not normalise the left sidebar to COLLAPSED before testing the expand flip") j = find_nav_link(ax, "Journals") assert j is not None, "left-sidebar link 'Journals' not found" w_closed = el_width(ax, j) assert w_closed != -1.0, "could not read AXSize of link 'Journals'" assert w_closed <= COLLAPSED_MAX, ( "with the left sidebar collapsed link 'Journals' should be <= %r wide, got %r" % (COLLAPSED_MAX, w_closed)) btn = find_el(ax, "Toggle left sidebar", role="button") assert btn is not None, "toolbar button 'Toggle left sidebar' not found" press(ax, btn) time.sleep(1.8) # Re-find: React replaces the sidebar nodes, so the old element id is stale. wait_until(lambda: el_width(ax, find_nav_link(ax, "Journals")) > EXPANDED_MIN, timeout=8.0) j2 = find_nav_link(ax, "Journals") assert j2 is not None, "link 'Journals' disappeared when the left sidebar expanded" w_open = el_width(ax, j2) screenshot_assert( "structure_left_sidebar_expanded", "The left navigation column is visible, listing Demo, Journals, Whiteboards, " "Flashcards, Graph view and All pages with FAVORITES / RECENT section headers and a " "'+ Create' button pinned at the bottom; the journal content is pushed to the right.") flip = kit.rb_flip(w_closed, w_open, expect="collapsed -> expanded") assert w_open > EXPANDED_MIN, ( "link 'Journals' width is %r with the left sidebar expanded, expected > %r" % (w_open, EXPANDED_MIN)) assert flip, "link 'Journals' width did not change when the left sidebar was expanded" btn2 = find_el(ax, "Toggle left sidebar", role="button") assert btn2 is not None, "toolbar button 'Toggle left sidebar' not found after expanding" press(ax, btn2) time.sleep(1.8) wait_until(lambda: el_width(ax, find_nav_link(ax, "Journals")) <= COLLAPSED_MAX, timeout=8.0) j3 = find_nav_link(ax, "Journals") assert j3 is not None, "link 'Journals' not found after re-collapsing the left sidebar" w_back = el_width(ax, j3) assert w_back <= COLLAPSED_MAX, ( "link 'Journals' width is %r after re-collapsing the left sidebar, expected <= %r" % (w_back, COLLAPSED_MAX)) @pytest.mark.rb(depth=1, jump_kind="reach", expect="button 'More' -> links Settings, Import, Export graph, Plugins, " "Themes, Join the community, Bug report appear") def test_more_dropdown_reveals_seven_links(self, ax): """recon S5 / MENUS 'More ⋯ dropdown'. Nothing inside the dropdown is activated here (Import / Export graph / Join the community / Bug report are NEVER-PRESS).""" assert rb_enter_app(ax), READY_MSG assert find_el(ax, "Settings", role="link") is None, ( "link 'Settings' already present before the More dropdown was opened") before = showing(ax) rb_enter_more_menu(ax) after = showing(ax) ok = kit.rb_reach(before, after, target="Settings", source=None) _els, labels, _census = catalog(ax) missing = [n for n in MORE_MENU_LINKS if not has(labels, "link", n)] assert not missing, ( "the More dropdown is missing link(s) %r (recon S5 lists all 7)" % (missing,)) assert ok, ("AXPress on button 'More' produced no new AX node matching 'Settings' — the " "dropdown surface did not open") esc(2) # ───────────────────────────────────────────────────────────────────────────── # DEEPER SURFACES (recon MENUS 'More > Settings' depth 2, S6, S11) # ───────────────────────────────────────────────────────────────────────────── class TestSurfaceReach: @pytest.mark.rb(depth=2, jump_kind="reach", expect="More dropdown -> Settings modal: heading 'Settings' + heading " "'General' + link 'Close' + the 6 tab-rail entries appear while link " "'Bug report' disappears") def test_settings_modal_is_a_second_level_surface(self, ax): """recon MENUS 'More > Settings' (depth 2). The tab rail is the structural payload; no Settings checkbox is pressed or read (recon FOCUS / UNREACHED forbid both).""" assert rb_enter_app(ax), READY_MSG rb_enter_more_menu(ax) assert find_el(ax, "Bug report", role="link") is not None, ( "link 'Bug report' not present after opening the More dropdown — the reach proof's " "source surface is missing") assert find_el(ax, "Settings", role="heading") is None, ( "heading 'Settings' already present before the Settings modal was opened") before = showing(ax) rb_reach_settings_modal(ax) after = showing(ax) ok = kit.rb_reach(before, after, target="Settings", source="Bug report") _els, labels, census = catalog(ax) assert has(labels, "heading", "Settings"), ( "heading 'Settings' missing after pressing link 'Settings' in the More dropdown") assert has(labels, "heading", "General"), ( "heading 'General' (the default Settings pane) missing from the Settings modal") missing_tabs = [t for t in SETTINGS_TABS if not (has(labels, "label", t) or has(labels, "heading", t))] assert not missing_tabs, ( "the Settings modal's tab rail is missing %r (recon STATE T4 lists all 6)" % (missing_tabs,)) assert has(labels, "link", "Close"), "link 'Close' missing from the Settings modal" assert not has(labels, "link", "Bug report"), ( "link 'Bug report' is still present — the More dropdown did not give way to the " "Settings modal") assert census.get("checkbox", 0) >= 3, ( "the Settings modal exposes only %d checkbox elements; the General pane's toggle " "switches should keep the count at >= 3" % census.get("checkbox", 0)) assert ok, ("the Settings modal did not register as a surface jump from the More dropdown " "(target 'Settings' / source 'Bug report')") # recon: Escape does NOT close Settings — press its link named 'Close'. close = find_el(ax, "Close", role="link") assert close is not None, "link 'Close' vanished before the Settings modal could be closed" press(ax, close) time.sleep(1.6) @pytest.mark.rb(depth=1, jump_kind="reach", expect="group 'How to take dummy notes?' -> a surface titled 'How to take " "dummy notes?' with heading '2 Linked References' + heading 'Unlinked " "References' + button 'Home'; heading 'Hi, welcome to Logseq!' gone") def test_page_reference_opens_a_new_page_surface(self, ax): """recon S6.""" assert rb_enter_app(ax), READY_MSG assert find_el(ax, "Hi, welcome to Logseq!", role="heading") is not None, ( "journal heading 'Hi, welcome to Logseq!' not found on the fresh journals route") before = showing(ax) rb_reach_dummy_notes_page(ax) after = showing(ax) ok = kit.rb_reach(before, after, target="2 Linked References", source="Hi, welcome to Logseq!") titles = surface_titles(ax) assert "How to take dummy notes?" in titles, ( "no window/web-area titled 'How to take dummy notes?' after pressing the page " "reference; surface titles were %r" % (titles,)) _els, labels, _census = catalog(ax) assert has(labels, "heading", "How to take dummy notes?"), ( "heading 'How to take dummy notes?' missing on the page-reference surface") assert has(labels, "heading", "2 Linked References"), ( "heading '2 Linked References' missing on the page-reference surface") assert has(labels, "heading", "Unlinked References"), ( "heading 'Unlinked References' missing on the page-reference surface") assert has(labels, "button", "Home"), ( "breadcrumb button 'Home' missing on the page-reference surface") assert has(labels, "label", "I'm a child block!"), ( "child-block label \"I'm a child block!\" missing on the page-reference surface") assert not has(labels, "heading", "Hi, welcome to Logseq!"), ( "journal heading 'Hi, welcome to Logseq!' is still present — the route did not change") assert ok, ("pressing group 'How to take dummy notes?' did not register as a surface jump " "(target '2 Linked References' / source 'Hi, welcome to Logseq!')") rb_back_to_journals(ax) @pytest.mark.rb(depth=1, jump_kind="reach", expect="link 'Flashcards' -> modal heading 'Time to create a card!' + link " "'click this link' appear while the window title stays 'Logseq'") def test_flashcards_is_a_modal_not_a_route(self, ax): """recon S11 — the discriminator is that win_title does NOT change.""" assert rb_enter_app(ax), READY_MSG assert find_el(ax, "Time to create a card!", role="heading") is None, ( "heading 'Time to create a card!' already present before 'Flashcards' was pressed") title_before = win_title(ax) assert title_before == "Logseq", ( "window title is %r before pressing 'Flashcards', expected 'Logseq'" % title_before) before = showing(ax) rb_reach_flashcards_modal(ax) after = showing(ax) ok = kit.rb_reach(before, after, target="Time to create a card!", source=None) assert find_el(ax, "Time to create a card!", role="heading") is not None, ( "modal heading 'Time to create a card!' missing after pressing link 'Flashcards'") assert find_el(ax, "click this link", role="link") is not None, ( "link 'click this link' missing from the Flashcards modal") title_after = win_title(ax) assert title_after == "Logseq", ( "the window title became %r — the Flashcards surface is a modal, so the title must " "stay 'Logseq'" % title_after) assert ok, ("pressing link 'Flashcards' produced no new AX node matching 'Time to create " "a card!'") esc(2) # ───────────────────────────────────────────────────────────────────────────── # ROUTE SHAPE — the window title is the route indicator (recon S7-S10 / STATE T5) # ───────────────────────────────────────────────────────────────────────────── class TestRouteShape: @pytest.mark.rb(depth=1, jump_kind="value", expect="window title 'Logseq' -> 'All pages' (heading 'All pages' + button " "'Home', journal content gone), then back to 'Logseq' with heading " "'Hi, welcome to Logseq!' via link 'Journals'") def test_all_pages_route_title_then_back_to_journals(self, ax): """recon S7 + S10.""" assert rb_enter_app(ax), READY_MSG t0 = win_title(ax) assert kit.rb_value(t0, "Logseq"), ( "window title is %r on the fresh journals route, expected 'Logseq'" % t0) rb_reach_route(ax, "All pages") t = win_title(ax) ok_ap = kit.rb_value(t, "All pages") _els, labels, _census = catalog(ax) assert has(labels, "heading", "All pages"), ( "heading 'All pages' missing after pressing link 'All pages'") assert has(labels, "button", "Home"), ( "breadcrumb button 'Home' missing on the All pages route") assert not has(labels, "heading", "Hi, welcome to Logseq!"), ( "journal heading 'Hi, welcome to Logseq!' is still present on the All pages route") assert ok_ap, ( "window title is %r after pressing link 'All pages', expected 'All pages'" % t) rb_reach_route(ax, "Journals") t2 = win_title(ax) ok_j = kit.rb_value(t2, "Logseq") assert find_el(ax, "Hi, welcome to Logseq!", role="heading") is not None, ( "heading 'Hi, welcome to Logseq!' did not come back after pressing link 'Journals'") assert find_heading_contains(ax, str(datetime.date.today().year)) is not None, ( "the journal date heading (which carries the current year) did not come back on the " "journals route") assert ok_j, ( "window title is %r after returning via link 'Journals', expected 'Logseq'" % t2) @pytest.mark.rb(depth=1, jump_kind="value", expect="link 'Graph view' -> window title 'Graph' with the force-graph " "controls (labels Charge Range / Charge Strength / Link Distance / " "Reset Forces / Reset Graph) plus slider widgets") def test_graph_view_route_title_and_controls(self, ax): """recon S8. The sliders are a role the journals route does not expose at all, so they double as a shape delta.""" assert rb_enter_app(ax), READY_MSG assert not ax.find(role="slider", max_results=5), ( "the journals route already exposes slider widgets; recon's fresh-launch census has " "none (they belong to the Graph view control panel)") rb_reach_route(ax, "Graph view") t = win_title(ax) ok = kit.rb_value(t, "Graph") _els, labels, census = catalog(ax) found = [s for s in ("Charge Range", "Charge Strength", "Link Distance", "Reset Forces", "Reset Graph", "Orphan pages") if has(labels, "label", s)] graph_btns = [n for n in ("Export", "Forces", "Nodes") if has(labels, "button", n)] screenshot_assert( "structure_graph_view", "Graph view: a force-directed graph canvas of linked page nodes filling the content " "area, with a right-hand settings panel of sliders labelled Charge Range, Charge " "Strength and Link Distance plus Reset Forces / Reset Graph links.") assert len(found) >= 3, ( "graph-view control labels missing: found only %r of Charge Range / Charge Strength / " "Link Distance / Reset Forces / Reset Graph / Orphan pages" % (found,)) assert graph_btns, ( "none of the graph-view panel buttons Export / Forces / Nodes were found") assert census.get("slider", 0) >= 1, ( "the Graph view exposes no slider widgets; recon S8 observed 3 (Charge Range, " "Charge Strength, Link Distance)") assert ok, "window title is %r after pressing link 'Graph view', expected 'Graph'" % t rb_back_to_journals(ax) @pytest.mark.rb(depth=1, jump_kind="value", expect="link 'Whiteboards' -> window title 'Whiteboards' with heading 'All " "whiteboards · 0', label 'New whiteboard' and button 'Home'") def test_whiteboards_route_title_and_heading(self, ax): """recon S9. `link " Whiteboards"` carries a leading icon glyph — matched by substring.""" assert rb_enter_app(ax), READY_MSG assert find_heading_contains(ax, "All whiteboards") is None, ( "a heading containing 'All whiteboards' is present before the route switch") rb_reach_route(ax, "Whiteboards") t = win_title(ax) ok = kit.rb_value(t, "Whiteboards") _els, labels, _census = catalog(ax) assert has_like(labels, "heading", "All whiteboards"), ( "no heading containing 'All whiteboards' on the Whiteboards route " "(recon: heading 'All whiteboards · 0'); headings were %r" % (names_for(labels, "heading"),)) assert has(labels, "label", "New whiteboard"), ( "label 'New whiteboard' missing on the Whiteboards route") assert has(labels, "button", "Home"), ( "breadcrumb button 'Home' missing on the Whiteboards route") assert not has(labels, "heading", "Hi, welcome to Logseq!"), ( "journal heading 'Hi, welcome to Logseq!' is still present on the Whiteboards route") assert ok, ( "window title is %r after pressing link 'Whiteboards', expected 'Whiteboards'" % t) rb_back_to_journals(ax)