Datasets:
File size: 38,814 Bytes
3fbbdd9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 | """COMPUTATION lane — CodeEdit input -> output behaviour, driven purely through AX.
Every expected value in this module is the value OBSERVED on the reference app and
recorded in recon.md `## COMPUTATION` (or computed deterministically from the fixture
files in FIXTURES_DIR). Nothing is read out of the app and compared to itself.
Surfaces exercised:
* Command Palette fuzzy filter (depth 2: workspace -> palette overlay)
* Open Quickly fuzzy file search (depth 2: workspace -> overlay)
* Editor text area vs the file on disk(depth 2: workspace -> editor)
* Clone-URL validation (depth 1: welcome -> sheet)
* Settings numeric field / stepper (depth 1: Settings -> Text Editing pane)
* Save-panel default file name (depth 1: welcome -> Save panel)
"""
# ─────────────────────────── PRIMITIVES (verbatim from recon.md) ───────────────────────────
import json
import os
import shutil
import subprocess
import time
import pytest
import rb_testgen_kit as kit
import verifier_helpers as helpers
RESULTS_DIR = os.environ.get("RESULTS_DIR", os.path.join(os.path.dirname(__file__), "results"))
FIXTURES_DIR = os.environ.get("FIXTURES_DIR") or os.path.join(os.path.dirname(__file__), "fixtures")
def screenshot_assert(test_name, description, results_dir=None):
results_dir = results_dir or RESULTS_DIR
ss_dir = os.path.join(results_dir, "screenshots")
os.makedirs(ss_dir, exist_ok=True)
ss_path = os.path.join(ss_dir, f"{test_name}.png")
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[f"{test_name}.png"] = description
with open(af, "w") as f:
json.dump(data, f, indent=2)
def win_id(ax, w):
return ax.get(w.id, ["AXIdentifier"]).get("AXIdentifier")
def all_windows(ax):
return ax.find(role="window", max_depth=1, max_results=20)
def find_window(ax, ident=None, title=None, timeout=8.0):
end = time.time() + timeout
while True:
for w in all_windows(ax):
if ident is not None and win_id(ax, w) == ident:
return w
if title is not None and (w.name or "") == title:
return w
if time.time() >= end:
return None
time.sleep(0.25)
def close_window(ax, w):
if w is None:
return False
for b in ax.find(role="button", root_id=w.id, max_results=200, max_depth=3):
if ax.get(b.id, ["AXSubrole"]).get("AXSubrole") == "AXCloseButton":
ax.action(b.id, "AXPress")
time.sleep(0.8)
return True
return False
def values_in(ax, root_id, max_results=400, max_depth=18):
"""Every non-empty AXValue string under root (labels, fields, popups)."""
out = []
for e in ax.find(root_id=root_id, max_results=max_results, max_depth=max_depth):
v = ax.get(e.id, ["AXValue"]).get("AXValue")
if isinstance(v, str) and v.strip():
out.append(v)
return out
def names_in(ax, root_id, role=None, max_results=400, max_depth=18):
return [e.name for e in ax.find(role=role, root_id=root_id,
max_results=max_results, max_depth=max_depth) if e.name]
def buttons_named(ax, root_id, name):
return [b for b in ax.find(role="button", root_id=root_id, max_results=300, max_depth=16)
if (b.name or "") == name]
def menu_item(ax, *path):
mbi = [m for m in ax.find(role="menu_bar_item", max_results=20, max_depth=3)
if (m.name or "") == path[0]]
if not mbi:
return None
cur = mbi[0].id
for label in path[1:]:
items = ax.find(role="menu_item", root_id=cur, max_results=300, max_depth=2)
hit = [i for i in items if (i.name or "") == label]
if not hit:
return None
cur = hit[0].id
return cur
def menu_items(ax, *path):
"""Item NAMES directly under a menu-bar item (or a submenu item)."""
root = menu_item(ax, *path) if len(path) > 1 else None
if root is None:
mbi = [m for m in ax.find(role="menu_bar_item", max_results=20, max_depth=3)
if (m.name or "") == path[0]]
if not mbi:
return []
menus = ax.find(role="menu", root_id=mbi[0].id, max_results=2, max_depth=1)
if not menus:
return []
root = menus[0].id
else:
menus = ax.find(role="menu", root_id=root, max_results=2, max_depth=1)
if not menus:
return []
root = menus[0].id
return [i.name for i in ax.find(role="menu_item", root_id=root, max_results=100, max_depth=1)
if (i.name or "")]
def rb_enter_menu_item(ax, *path, wait=1.6):
mid = menu_item(ax, *path)
if mid is None:
return False
ax.action(mid, "AXPress")
time.sleep(wait)
return True
def rb_enter_welcome(ax):
w = find_window(ax, ident="welcome", timeout=3)
if w is None:
rb_enter_menu_item(ax, "Window", "Welcome to CodeEdit")
w = find_window(ax, ident="welcome", timeout=6)
return w
def rb_enter_settings_window(ax):
w = find_window(ax, ident="settings", timeout=1)
if w is None:
rb_enter_menu_item(ax, "CodeEdit", "Settings...", wait=2.0)
w = find_window(ax, ident="settings", timeout=8)
return w
def rb_reach_settings_pane(ax, pane):
"""Select a Settings sidebar pane. MUST be a CG click (AXPress does NOT select)."""
w = rb_enter_settings_window(ax)
if w is None:
return None
bs = buttons_named(ax, w.id, pane)
if not bs:
return None
ax.click_element_cg(bs[-1].id)
time.sleep(1.0)
return find_window(ax, ident="settings", timeout=3)
def rb_enter_about_window(ax):
rb_enter_menu_item(ax, "CodeEdit", "About CodeEdit", wait=2.0)
return find_window(ax, ident="about", timeout=6)
def rb_enter_extensions_window(ax):
rb_enter_menu_item(ax, "Extensions", "Open Extensions Window", wait=2.0)
return find_window(ax, ident="extensions", timeout=6)
def rb_enter_clone_sheet(ax):
w = rb_enter_welcome(ax)
bs = buttons_named(ax, w.id, "Clone Git Repository...")
if not bs:
return None
ax.action(bs[0].id, "AXPress")
end = time.time() + 6
while time.time() < end:
s = ax.find(role="sheet", max_results=3, max_depth=6)
if s:
return s[0]
time.sleep(0.25)
return None
def rb_enter_save_panel(ax):
w = rb_enter_welcome(ax)
bs = buttons_named(ax, w.id, "Create New File...")
if bs:
ax.action(bs[0].id, "AXPress")
return find_window(ax, title="Save", timeout=8)
def rb_enter_open_panel(ax):
w = rb_enter_welcome(ax)
bs = buttons_named(ax, w.id, "Open File or Folder...")
if bs:
ax.action(bs[0].id, "AXPress")
return find_window(ax, title="Open Workspace or File", timeout=8)
def dismiss_panel_or_sheet(ax):
"""Escape does not work here — press the panel/sheet's own Cancel button."""
for b in ax.find(role="button", max_results=120, max_depth=10):
if (b.name or "") == "Cancel":
ax.action(b.id, "AXPress")
time.sleep(1.0)
return True
return False
def rb_enter_workspace(ax, folder_name="sample_project", timeout=20.0):
"""Open the fixture folder as a workspace the way Finder does: hand the folder to the
RUNNING app's own bundle (discovered from its pid at runtime — portable)."""
from AppKit import NSWorkspace, NSRunningApplication, NSWorkspaceOpenConfiguration
from Foundation import NSURL
src = os.path.join(FIXTURES_DIR, folder_name)
base = os.path.join("/tmp", "rb_codeedit_ws")
dst = os.path.join(base, folder_name)
if os.path.isdir(base):
shutil.rmtree(base, ignore_errors=True)
os.makedirs(base, exist_ok=True)
shutil.copytree(src, dst)
ra = NSRunningApplication.runningApplicationWithProcessIdentifier_(int(ax._pid))
cfg = NSWorkspaceOpenConfiguration.configuration()
cfg.setActivates_(True)
NSWorkspace.sharedWorkspace().openURLs_withApplicationAtURL_configuration_completionHandler_(
[NSURL.fileURLWithPath_(dst)], ra.bundleURL(), cfg, None)
return find_window(ax, ident="workspace", timeout=timeout)
def project_navigator(ax, ws):
for o in ax.find(role="outline", root_id=ws.id, max_results=10, max_depth=14):
if (o.name or "") == "Project Navigator":
return o
return None
def navigator_rows(ax, ws):
nav = project_navigator(ax, ws)
if nav is None:
return []
return [ax.get(t.id, ["AXValue"]).get("AXValue")
for t in ax.find(role="text_field", root_id=nav.id, max_results=60, max_depth=8)]
def rb_reach_editor(ax, ws, filename):
"""Click a file row in the Project Navigator; returns the editor AXTextArea (or None)."""
nav = project_navigator(ax, ws)
if nav is None:
return None
rows = ax.find(role="text_field", root_id=nav.id, max_results=60, max_depth=8)
tgt = [t for t in rows if ax.get(t.id, ["AXValue"]).get("AXValue") == filename]
if not tgt:
return None
ax.click_element_cg(tgt[0].id)
end = time.time() + 8
while time.time() < end:
ta = ax.find(role="text_area", root_id=ws.id, max_results=5, max_depth=18)
if ta:
return ta[0]
time.sleep(0.3)
return None
def rb_enter_command_palette(ax, ws):
"""Command Palette / Open Quickly only exist while a WORKSPACE window is open."""
ax.action(ws.id, "AXRaise")
time.sleep(0.5)
rb_enter_menu_item(ax, "View", "Show Command Palette", wait=1.6)
return _overlay_window(ax)
def rb_enter_open_quickly(ax, ws):
ax.action(ws.id, "AXRaise")
time.sleep(0.5)
rb_enter_menu_item(ax, "File", "Open Quickly", wait=1.6)
return _overlay_window(ax)
def _overlay_window(ax):
"""The palette/quick-open overlay is a borderless AXWindow: no title, no AXIdentifier."""
for w in all_windows(ax):
if win_id(ax, w) is None and not (w.name or ""):
return w
return None
def overlay_rows(ax, pal):
return [v for v in (ax.get(t.id, ["AXValue"]).get("AXValue")
for t in ax.find(role="label", root_id=pal.id,
max_results=60, max_depth=14)) if v]
def overlay_type(ax, pal, text):
tf = ax.find(role="text_field", root_id=pal.id, max_results=5, max_depth=8)
if not tf:
return False
ax.set_value(tf[0].id, text)
time.sleep(1.3)
return True
def switch_for_label(ax, root_id, label):
"""The AXCheckBox(AXSwitch) that follows the AXStaticText whose AXValue == label."""
seq = ax.find(root_id=root_id, max_results=400, max_depth=18)
idx = None
for i, e in enumerate(seq):
if e.role == "label" and ax.get(e.id, ["AXValue"]).get("AXValue") == label:
idx = i
break
if idx is None:
return None
for e in seq[idx + 1:idx + 4]:
if e.role == "checkbox":
return e
return None
def popup_for_label(ax, root_id, label):
seq = ax.find(root_id=root_id, max_results=400, max_depth=18)
idx = None
for i, e in enumerate(seq):
if e.role == "label" and ax.get(e.id, ["AXValue"]).get("AXValue") == label:
idx = i
break
if idx is None:
return None
for e in seq[idx + 1:idx + 4]:
if e.role == "popup":
return e
return None
def popup_options(ax, popup):
ax.action(popup.id, "AXPress")
time.sleep(0.8)
menus = ax.find(role="menu", root_id=popup.id, max_results=3, max_depth=2)
out = []
if menus:
for i in ax.find(role="menu_item", root_id=menus[0].id, max_results=40, max_depth=2):
out.append(i.name or ax.get(i.id, ["AXValue"]).get("AXValue"))
ax.action(menus[0].id, "AXCancel")
time.sleep(0.4)
return [o for o in out if o]
def popup_pick(ax, popup, option):
ax.action(popup.id, "AXPress")
time.sleep(0.8)
menus = ax.find(role="menu", root_id=popup.id, max_results=3, max_depth=2)
if not menus:
return False
for i in ax.find(role="menu_item", root_id=menus[0].id, max_results=40, max_depth=2):
if (i.name or ax.get(i.id, ["AXValue"]).get("AXValue")) == option:
ax.action(i.id, "AXPick")
time.sleep(1.0)
return True
ax.action(menus[0].id, "AXCancel")
return False
# ───────────────────────── end PRIMITIVES ─────────────────────────
# ══════════════════ OBSERVED reference values (recon ## COMPUTATION) ══════════════════
# Command Palette, unfiltered — exactly 7 rows. ORDER IS NOT STABLE -> compare as a SET.
PALETTE_ALL = {
"Toggle Navigator",
"Toggle Inspector",
"Toggle Utility Area",
"Toggle Word Wrap",
"Toggle Type-Over Completion",
"Toggle Autocomplete Braces",
"Quick Open",
}
# The 6 rows the fuzzy query "toggle" keeps (everything except "Quick Open").
PALETTE_TOGGLES = {c for c in PALETTE_ALL if c.startswith("Toggle ")}
# Fixture workspace files (content is read from FIXTURES_DIR at run time; the literals
# below are the exact OBSERVED editor AXValues and act as an offline fallback).
FIXTURE_TEXT = {
"hello.py": 'def greet(name):\n return f"Hello, {name}!"\n\n\nprint(greet("CodeEdit"))\n',
"notes.txt": "alpha\nbeta\ngamma\n",
"README.md": "# Sample Project\n\nA fixture workspace used by the CodeEdit AX test suite.\n",
}
CLONE_URL = "https://github.com/CodeEditApp/CodeEdit.git"
EDITED_TEXT = "print('rb')\n" # OBSERVED: replaces hello.py, AXNumberOfCharacters -> 12
def fixture_text(name):
"""Exact on-disk text of a sample_project file (deterministic expected value)."""
path = os.path.join(FIXTURES_DIR, "sample_project", name)
try:
with open(path, "r") as f:
return f.read()
except Exception:
return FIXTURE_TEXT[name]
# ══════════════════════════════ small local utilities ══════════════════════════════
def _norm(s):
"""Label text normalised for cross-framework matching (whitespace / trailing ':')."""
return " ".join(str(s or "").split()).rstrip(":").strip().lower()
def _text_of(el):
"""Visible text of an element: AXValue if it carries a string, else AXTitle/AXDescription."""
v = getattr(el, "value", None)
if isinstance(v, str) and v.strip():
return str(v)
return str(el.name or "")
def _num(v):
try:
return float(v)
except Exception:
return None
def _int(v):
try:
return int(v)
except Exception:
return None
def _is_labelish(el):
return (el.role or "") in ("label", "heading", "static_text")
def row_after_label(ax, root_id, label, span=10, stop_after_labels=2):
"""Elements that belong to the settings ROW introduced by `label`.
Semantic locator: the row is found by the visible label text (+ role), never by child
index or tree path. The scan walks forward from the label and stops once it has passed
`stop_after_labels` further label-ish elements — i.e. the unit suffix ('spaces') is
still included but the NEXT setting's label ('Tab Width', whose field is also '4')
ends the row, so the two identical-looking rows can never be confused.
Returns (row_elements, seq) where seq is the full walk (reused by the caller)."""
seq = ax.find(root_id=root_id, max_results=400, max_depth=18)
want = _norm(label)
idx = None
for i, e in enumerate(seq):
if _is_labelish(e) and _norm(_text_of(e)) == want:
idx = i
break
if idx is None: # a framework may put the label on the control itself
for i, e in enumerate(seq):
if _norm(_text_of(e)) == want or _norm(e.name) == want:
idx = i
break
if idx is None:
return [], seq
row, labels_seen = [], 0
for e in seq[idx + 1: idx + 1 + span]:
if _is_labelish(e):
labels_seen += 1
if labels_seen > stop_after_labels:
break
row.append(e)
return row, seq
def control_near_label(ax, root_id, label, roles, span=10):
"""The control with one of `roles` in the row introduced by `label`.
Falls back to a control that carries the label itself as AXTitle/AXDescription."""
row, seq = row_after_label(ax, root_id, label, span)
for e in row:
if e.role in roles:
return e
want = _norm(label)
for e in seq:
if e.role in roles and _norm(e.name) == want:
return e
return None
def field_and_stepper(ax, root_id, label, span=10):
"""(numeric AXTextField, AXIncrementor) of one settings row — located in a SINGLE
tree walk so the two controls are guaranteed to belong to the SAME row."""
row, seq = row_after_label(ax, root_id, label, span)
field = next((e for e in row if e.role == "text_field"), None)
incr = next((e for e in row if "incrementor" in (e.role or "").lower()), None)
if field is None:
want = _norm(label)
field = next((e for e in seq if e.role == "text_field" and _norm(e.name) == want), None)
return field, incr
def increment_arrow(ax, incr):
"""The AXIncrementArrow child of an AXIncrementor (skips the incrementor itself).
Falls back to a child whose visible label says 'increment' (SwiftUI stepper halves)."""
kids = [k for k in ax.find(root_id=incr.id, max_results=12, max_depth=2)
if k.id != incr.id and (k.role or "").lower() != "incrementor"]
for k in kids:
role = (k.role or "").lower()
if "increment" in role and "decrement" not in role:
return k
for k in kids:
text = _norm(k.name) + " " + _norm(getattr(k, "value", ""))
if ("increment" in text or "increase" in text or text.strip() == "up") \
and "decrement" not in text:
return k
return None
def bump_incrementor(ax, incr):
"""Press the incrementor's up-arrow (fallback: the AXIncrement action)."""
arrow = increment_arrow(ax, incr)
if arrow is not None and ax.action(arrow.id, "AXPress"):
return True
return ax.action(incr.id, "AXIncrement")
def overlay_rows_settled(ax, pal, timeout=3.0):
"""Overlay row labels, read until two consecutive reads agree (filter has settled)."""
prev = None
end = time.time() + timeout
while time.time() < end:
cur = overlay_rows(ax, pal)
if cur == prev:
return cur
prev = cur
time.sleep(0.4)
return prev if prev is not None else overlay_rows(ax, pal)
def editor_value(ax, ta, timeout=6.0):
"""AXValue of the editor text area, waiting for the file content to land."""
val = None
end = time.time() + timeout
while time.time() < end:
val = ax.get(ta.id, ["AXValue"]).get("AXValue")
if isinstance(val, str) and val.strip():
return val
time.sleep(0.3)
return val
def editor_nchars(ax, ta):
return _int(ax.get(ta.id, ["AXNumberOfCharacters"]).get("AXNumberOfCharacters"))
def text_editor_area(ax, ws, filename):
"""Open `filename` from the Project Navigator and return the editor AXTextArea.
Prefers the area whose AX label is 'Text Editor' (semantic, framework-agnostic)."""
ta = rb_reach_editor(ax, ws, filename)
if ta is None:
return None
named = [t for t in ax.find(role="text_area", root_id=ws.id, max_results=6, max_depth=18)
if (t.name or "") == "Text Editor"]
return named[0] if named else ta
# ══════════════════════════════════════ TESTS ══════════════════════════════════════
class TestCommandPaletteFilter:
"""`View > Show Command Palette` (workspace open) — fuzzy command filtering."""
@pytest.mark.rb(depth=2, jump_kind="value",
expect="unfiltered Command Palette lists exactly the 7 commands "
"{Toggle Navigator, Toggle Inspector, Toggle Utility Area, "
"Toggle Word Wrap, Toggle Type-Over Completion, "
"Toggle Autocomplete Braces, Quick Open}")
def test_palette_unfiltered_command_set(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_command_palette(ax, ws)
assert pal is not None, "Command Palette overlay window did not appear"
rows = overlay_rows_settled(ax, pal)
assert kit.rb_value(set(rows), PALETTE_ALL), f"palette rows={sorted(rows)}"
assert len(rows) == 7, f"palette must list exactly 7 commands, got {len(rows)}: {rows}"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="'navigator' filters the palette to ['Toggle Navigator'] and "
"'wrap' filters it to ['Toggle Word Wrap']")
def test_palette_filter_navigator_then_wrap(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_command_palette(ax, ws)
assert pal is not None, "Command Palette overlay window did not appear"
assert overlay_type(ax, pal, "navigator"), "no text field in the palette overlay"
rows_nav = overlay_rows_settled(ax, pal)
assert kit.rb_value(sorted(set(rows_nav)), ["Toggle Navigator"]), \
f"'navigator' rows={sorted(rows_nav)}"
assert overlay_type(ax, pal, "wrap"), "no text field in the palette overlay"
rows_wrap = overlay_rows_settled(ax, pal)
screenshot_assert(
"computation_test_palette_filter_wrap",
"CodeEdit 'sample_project' workspace with the floating Command Palette overlay "
"on top: the rounded search field contains the query 'wrap' and the command list "
"below it is filtered down to exactly ONE row reading 'Toggle Word Wrap' "
"(the other 6 commands, including 'Quick Open', are hidden).")
assert kit.rb_value(sorted(set(rows_wrap)), ["Toggle Word Wrap"]), \
f"'wrap' rows={sorted(rows_wrap)}"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="'quick' filters the palette to ['Quick Open']")
def test_palette_filter_quick_open(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_command_palette(ax, ws)
assert pal is not None, "Command Palette overlay window did not appear"
assert overlay_type(ax, pal, "quick"), "no text field in the palette overlay"
rows = overlay_rows_settled(ax, pal)
assert kit.rb_value(sorted(set(rows)), ["Quick Open"]), f"'quick' rows={sorted(rows)}"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="'toggle' keeps exactly the 6 'Toggle …' commands and drops "
"'Quick Open'")
def test_palette_filter_toggle_keeps_six(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_command_palette(ax, ws)
assert pal is not None, "Command Palette overlay window did not appear"
assert overlay_type(ax, pal, "toggle"), "no text field in the palette overlay"
rows = set(overlay_rows_settled(ax, pal))
assert kit.rb_value(rows, PALETTE_TOGGLES), f"'toggle' rows={sorted(rows)}"
assert len(rows) == 6, f"'toggle' must keep exactly 6 rows, got {sorted(rows)}"
assert "Quick Open" not in rows, "'Quick Open' must not survive the 'toggle' filter"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="'inspector' -> ['Toggle Inspector']; clearing the query restores "
"all 7 palette commands")
def test_palette_filter_inspector_then_restore(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_command_palette(ax, ws)
assert pal is not None, "Command Palette overlay window did not appear"
assert overlay_type(ax, pal, "inspector"), "no text field in the palette overlay"
rows_ins = overlay_rows_settled(ax, pal)
assert kit.rb_value(sorted(set(rows_ins)), ["Toggle Inspector"]), \
f"'inspector' rows={sorted(rows_ins)}"
assert overlay_type(ax, pal, ""), "no text field in the palette overlay"
rows_all = overlay_rows_settled(ax, pal)
assert kit.rb_value(set(rows_all), PALETTE_ALL), \
f"restored rows={sorted(rows_all)}"
class TestOpenQuicklySearch:
"""`File > Open Quickly` (workspace open) — fuzzy file search over sample_project."""
@pytest.mark.rb(depth=2, jump_kind="value",
expect="Open Quickly query 'hello' returns the row 'hello.py'")
def test_open_quickly_finds_hello_py(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_open_quickly(ax, ws)
assert pal is not None, "Open Quickly overlay window did not appear"
assert overlay_type(ax, pal, "hello"), "no text field in the Open Quickly overlay"
rows = overlay_rows_settled(ax, pal)
hits = [r for r in rows if r == "hello.py"]
assert kit.rb_value(hits, ["hello.py"]), f"'hello' rows={sorted(rows)}"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="Open Quickly query 'notes' returns the row 'notes.txt' and 'README' "
"returns the row 'README.md'")
def test_open_quickly_finds_notes_then_readme(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_open_quickly(ax, ws)
assert pal is not None, "Open Quickly overlay window did not appear"
assert overlay_type(ax, pal, "notes"), "no text field in the Open Quickly overlay"
rows_notes = overlay_rows_settled(ax, pal)
hits_notes = [r for r in rows_notes if r == "notes.txt"]
assert kit.rb_value(hits_notes, ["notes.txt"]), f"'notes' rows={sorted(rows_notes)}"
assert overlay_type(ax, pal, "README"), "no text field in the Open Quickly overlay"
rows_readme = overlay_rows_settled(ax, pal)
hits_readme = [r for r in rows_readme if r == "README.md"]
assert kit.rb_value(hits_readme, ["README.md"]), f"'README' rows={sorted(rows_readme)}"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="Open Quickly query 'zzzznope' matches no file -> zero result rows")
def test_open_quickly_no_match_for_nonsense(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
pal = rb_enter_open_quickly(ax, ws)
assert pal is not None, "Open Quickly overlay window did not appear"
assert overlay_type(ax, pal, "zzzznope"), "no text field in the Open Quickly overlay"
rows = overlay_rows_settled(ax, pal)
hits = sorted(r for r in rows if str(r).endswith((".py", ".txt", ".md")))
assert kit.rb_value(hits, []), f"unexpected result rows for 'zzzznope': {hits}"
assert hits == [], f"'zzzznope' matches no file, so no file row may be listed: {hits}"
class TestEditorContent:
"""Project-Navigator click -> the editor AXTextArea must hold the file on disk."""
@pytest.mark.rb(depth=2, jump_kind="value",
expect="editor shows hello.py verbatim: 'def greet(name):\\n return "
"f\"Hello, {name}!\"\\n\\n\\nprint(greet(\"CodeEdit\"))\\n' "
"(73 characters)")
def test_editor_shows_hello_py(self, ax):
expected = fixture_text("hello.py")
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
ta = text_editor_area(ax, ws, "hello.py")
assert ta is not None, "clicking hello.py did not produce an editor AXTextArea"
value = editor_value(ax, ta)
nchars = editor_nchars(ax, ta)
screenshot_assert(
"computation_test_editor_hello_py",
"CodeEdit workspace window titled 'sample_project': the Project Navigator on the "
"left lists sample_project / src / README.md / hello.py / notes.txt, a tab labelled "
"'hello.py' sits above the centre editor, and the editor shows the "
"syntax-highlighted 73-character Python file — 'def greet(name):', an indented "
"'return f\"Hello, {name}!\"', then 'print(greet(\"CodeEdit\"))'.")
assert kit.rb_value(value, expected) and value == expected, f"editor value={value!r}"
assert kit.rb_value(nchars, len(expected)) and nchars == len(expected), \
f"AXNumberOfCharacters={nchars} (expected {len(expected)})"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="editor shows notes.txt verbatim: 'alpha\\nbeta\\ngamma\\n' "
"(17 characters)")
def test_editor_shows_notes_txt(self, ax):
expected = fixture_text("notes.txt")
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
ta = text_editor_area(ax, ws, "notes.txt")
assert ta is not None, "clicking notes.txt did not produce an editor AXTextArea"
value = editor_value(ax, ta)
nchars = editor_nchars(ax, ta)
assert kit.rb_value(value, expected) and value == expected, f"editor value={value!r}"
assert kit.rb_value(nchars, len(expected)) and nchars == len(expected), \
f"AXNumberOfCharacters={nchars} (expected {len(expected)})"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="editor shows README.md verbatim: '# Sample Project\\n\\nA fixture "
"workspace used by the CodeEdit AX test suite.\\n' (74 characters)")
def test_editor_shows_readme_md(self, ax):
expected = fixture_text("README.md")
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
ta = text_editor_area(ax, ws, "README.md")
assert ta is not None, "clicking README.md did not produce an editor AXTextArea"
value = editor_value(ax, ta)
nchars = editor_nchars(ax, ta)
assert kit.rb_value(value, expected) and value == expected, f"editor value={value!r}"
assert kit.rb_value(nchars, len(expected)) and nchars == len(expected), \
f"AXNumberOfCharacters={nchars} (expected {len(expected)})"
@pytest.mark.rb(depth=2, jump_kind="value",
expect="set_value on the editor replaces hello.py's 73 characters with "
"\"print('rb')\\n\" -> AXNumberOfCharacters 12")
def test_editor_set_value_replaces_content(self, ax):
ws = rb_enter_workspace(ax)
assert ws is not None, "workspace window (id=workspace) did not open"
ta = text_editor_area(ax, ws, "hello.py")
assert ta is not None, "clicking hello.py did not produce an editor AXTextArea"
before = editor_value(ax, ta)
assert kit.rb_value(before, fixture_text("hello.py")), \
f"editor did not load hello.py first: {before!r}"
ax.set_value(ta.id, EDITED_TEXT)
end = time.time() + 4
value, nchars = None, None
while time.time() < end:
value = ax.get(ta.id, ["AXValue"]).get("AXValue")
nchars = editor_nchars(ax, ta)
if nchars == len(EDITED_TEXT):
break
time.sleep(0.3)
assert kit.rb_value(value, EDITED_TEXT) and value == EDITED_TEXT, \
f"editor value after edit={value!r}"
assert kit.rb_value(nchars, len(EDITED_TEXT)) and nchars == len(EDITED_TEXT), \
f"AXNumberOfCharacters after edit={nchars} (expected {len(EDITED_TEXT)})"
class TestCloneUrlValidation:
"""Welcome > 'Clone Git Repository...' — the Clone button validates the URL field."""
@pytest.mark.rb(depth=1, jump_kind="transition",
expect="Clone button AXEnabled flips False -> True once the URL field is "
"set to https://github.com/CodeEditApp/CodeEdit.git")
def test_clone_button_enables_when_url_entered(self, ax):
sheet = rb_enter_clone_sheet(ax)
assert sheet is not None, "Clone sheet did not appear on the welcome window"
fields = ax.find(role="text_field", root_id=sheet.id, max_results=5, max_depth=8)
assert fields, "no URL AXTextField in the clone sheet"
clone = [b for b in ax.find(role="button", root_id=sheet.id,
max_results=30, max_depth=8) if (b.name or "") == "Clone"]
assert clone, "no 'Clone' button in the clone sheet"
before = bool(ax.get(clone[0].id, ["AXEnabled"]).get("AXEnabled"))
assert before is False, "Clone must start DISABLED while the URL field is empty"
ax.set_value(fields[0].id, CLONE_URL)
time.sleep(1.0)
typed = ax.get(fields[0].id, ["AXValue"]).get("AXValue")
after = bool(ax.get(clone[0].id, ["AXEnabled"]).get("AXEnabled"))
screenshot_assert(
"computation_test_clone_url_validation",
"A sheet over the CodeEdit welcome window reading 'Clone a repository' / 'Enter a "
"git repository URL:'; the URL text field now contains "
"https://github.com/CodeEditApp/CodeEdit.git and the 'Clone' button (right of "
"'Cancel') is ENABLED — no longer greyed out.")
assert kit.rb_value(typed, CLONE_URL), f"URL field reads {typed!r}"
assert kit.rb_flip(before, after, expect="Clone enabled after a valid URL"), \
f"Clone AXEnabled did not change: before={before} after={after}"
assert after is True, "Clone must be ENABLED once the URL field holds a repository URL"
dismiss_panel_or_sheet(ax)
class TestSettingsNumericSteppers:
"""Settings ▸ Text Editing — 'Indent Width' numeric field + its AXIncrementor."""
@pytest.mark.rb(depth=1, jump_kind="value",
expect="Indent Width starts at 4 and reads 8 after set_value('8')")
def test_indent_width_set_value_reads_back(self, ax):
w = rb_reach_settings_pane(ax, "Text Editing")
assert w is not None, "Settings ▸ Text Editing pane did not open"
field, _incr = field_and_stepper(ax, w.id, "Indent Width")
assert field is not None, "no numeric AXTextField next to the 'Indent Width' label"
before = ax.get(field.id, ["AXValue"]).get("AXValue")
assert kit.rb_value(before, "4") and str(before).strip() == "4", \
f"Indent Width default={before!r} (expected 4)"
ax.set_value(field.id, "8")
time.sleep(0.8)
after = ax.get(field.id, ["AXValue"]).get("AXValue")
assert kit.rb_value(after, "8") and str(after).strip() == "8", \
f"Indent Width after set_value={after!r} (expected 8)"
@pytest.mark.rb(depth=1, jump_kind="value",
expect="Indent Width incrementor 4.0 -> 5.0 and the paired field '4' -> '5' "
"after one AXIncrementArrow press")
def test_indent_width_incrementor_arrow(self, ax):
w = rb_reach_settings_pane(ax, "Text Editing")
assert w is not None, "Settings ▸ Text Editing pane did not open"
field, incr = field_and_stepper(ax, w.id, "Indent Width")
assert field is not None, "no numeric AXTextField next to the 'Indent Width' label"
assert incr is not None, "no AXIncrementor (stepper) next to the 'Indent Width' label"
before_field = ax.get(field.id, ["AXValue"]).get("AXValue")
before_incr = _num(ax.get(incr.id, ["AXValue"]).get("AXValue"))
assert kit.rb_value(before_field, "4") and str(before_field).strip() == "4", \
f"Indent Width default={before_field!r}"
assert kit.rb_value(before_incr, 4.0) and before_incr == 4.0, \
f"stepper default={before_incr!r}"
assert bump_incrementor(ax, incr), "could not press the stepper's increment arrow"
time.sleep(0.9)
after_incr = _num(ax.get(incr.id, ["AXValue"]).get("AXValue"))
after_field = ax.get(field.id, ["AXValue"]).get("AXValue")
assert kit.rb_value(after_incr, 5.0) and after_incr == 5.0, \
f"stepper after increment={after_incr!r} (expected 5.0)"
assert kit.rb_value(after_field, "5") and str(after_field).strip() == "5", \
f"field after increment={after_field!r} (expected 5)"
class TestSavePanelDefaultName:
"""Welcome > 'Create New File...' — the Save panel's pre-filled document name."""
@pytest.mark.rb(depth=1, jump_kind="value",
expect="the Save panel's 'Save As:' field is pre-filled with 'Untitled'")
def test_save_panel_default_name_is_untitled(self, ax):
w = rb_enter_save_panel(ax)
assert w is not None, "Save panel (title 'Save') did not appear"
field = control_near_label(ax, w.id, "Save As:", ("text_field", "combobox"))
if field is None:
cands = [t for t in ax.find(role="text_field", root_id=w.id,
max_results=20, max_depth=12)
if isinstance(getattr(t, "value", None), str) and str(t.value).strip()]
field = cands[0] if cands else None
assert field is not None, "no 'Save As:' AXTextField in the Save panel"
value = ax.get(field.id, ["AXValue"]).get("AXValue")
assert kit.rb_value(value, "Untitled") and str(value).strip() == "Untitled", \
f"'Save As:' field value={value!r} (expected 'Untitled')"
dismiss_panel_or_sheet(ax)
|