Files
NeitzelFXDesigner/scripts/check-ide-host.py
T

107 lines
8.9 KiB
Python

#!/usr/bin/env python3
"""Run the disposable companion checks in real isolated IntelliJ windows (macOS)."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import signal
import subprocess
import sys
import time
import tempfile
import zipfile
from native_crashes import NativeCrashGuard, descendant_workers, await_worker_exit
ROOT = Path(__file__).resolve().parent.parent
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--java-home", type=Path, required=True)
p.add_argument("--target-java-home", type=Path, required=True)
p.add_argument("--idea-home", type=Path, required=True)
p.add_argument("--mode", choices=["all", "classpath", "modulepath"], default="all")
p.add_argument("--repeat", type=int, default=1, help="Consecutive independent runs per mode")
p.add_argument("--archiver", type=Path, help="Qualify ArchiveWindow.fxml in a disposable project copy")
forms = p.add_mutually_exclusive_group()
forms.add_argument("--connection-form", action="store_true", help="Qualify the Archiver connection form")
forms.add_argument("--grid-docking", type=Path, metavar="REFERENCE_FXML", help="Qualify the Archiver grid, dock layout and the supplied reference workspace")
forms.add_argument("--dock-rules", action="store_true", help="Verify group minima, split directions and persistence in the Archiver")
forms.add_argument("--media-layout-grid", action="store_true", help="Verify media permissions, form destinations and grid setups in the Archiver")
forms.add_argument("--management-readers", action="store_true", help="Verify account and trash commands and the five reader toolbars")
forms.add_argument("--viewer-import", action="store_true", help="Verify HtmlViewer references and retry in the Archiver import dialog")
forms.add_argument("--row-menus", action="store_true", help="Edit Archiver row menu bindings and literal grid group labels")
forms.add_argument("--folder-profiles", action="store_true", help="Check the Archiver profile commands and metadata columns")
forms.add_argument("--folder-actions", action="store_true", help="Check visual event references, folder search, selection and display profiles")
forms.add_argument("--import-form", action="store_true", help="Check generic binding types and the Archiver import collision")
forms.add_argument("--document-tabs", action="store_true", help="Qualify the production Archiver HTML document tabs")
forms.add_argument("--saved-document", action="store_true", help="Open the Archiver saved HTML and tag example")
args = p.parse_args()
if (args.connection_form or args.grid_docking or args.saved_document or args.document_tabs or args.import_form or args.folder_actions or args.viewer_import or args.row_menus or args.folder_profiles or args.management_readers or args.media_layout_grid or args.dock_rules) and not args.archiver:
p.error("Selecting an Archiver view requires --archiver")
if args.repeat < 1:
p.error("--repeat must be positive")
output = ROOT / "target/ide-workflow"
output.mkdir(parents=True, exist_ok=True)
batch = Path(tempfile.mkdtemp(prefix="runs-", dir=output))
print("Host evidence: " + str(batch), flush=True)
modes = ("classpath",) if args.archiver else (("classpath", "modulepath") if args.mode == "all" else (args.mode,))
for run_number, mode in ((n, mode) for n in range(1, args.repeat + 1) for mode in modes):
crashes = NativeCrashGuard(ROOT)
launch = subprocess.run([sys.executable, ROOT / "scripts/run-fixture-host.py", "intellij",
"--check", *(["--viewer-import"] if args.viewer_import else []), *(["--row-menus"] if args.row_menus else []), *(["--folder-profiles"] if args.folder_profiles else []), *(["--dock-rules"] if args.dock_rules else []), *(["--media-layout-grid"] if args.media_layout_grid else []), *(["--management-readers"] if args.management_readers else []), *(["--folder-actions"] if args.folder_actions else []), *(["--import-form"] if args.import_form else []), *(["--document-tabs"] if args.document_tabs else []), *(["--saved-document"] if args.saved_document else []), *(["--grid-docking", str(args.grid_docking.resolve())] if args.grid_docking else []), *(["--connection-form"] if args.connection_form else []), *(["--archiver", str(args.archiver.resolve())] if args.archiver else []), "--mode", mode, "--java-home", args.java_home,
"--target-java-home", args.target_java_home, "--idea-home", args.idea_home],
cwd=ROOT, text=True, capture_output=True, timeout=60)
if launch.returncode:
raise RuntimeError(launch.stdout + launch.stderr)
evidence = batch / f"{mode}-run-{run_number}"
evidence.mkdir(exist_ok=True)
(output / (mode + "-launch.log")).write_text(launch.stdout + launch.stderr)
(evidence / "launch.log").write_text(launch.stdout + launch.stderr)
base = Path(re.search(r"Disposable host: (.+)", launch.stdout)[1])
pid = int(re.search(r"Host PID: (\d+)", launch.stdout)[1])
try:
until = time.monotonic() + (480 if args.archiver else 240)
while time.monotonic() < until:
if (base / "FAILURE.txt").exists():
raise RuntimeError((base / "FAILURE.txt").read_text())
if (base / "SUCCESS.txt").exists():
break
if not subprocess.run(["ps", "-p", str(pid), "-o", "pid="], capture_output=True).stdout.strip():
raise RuntimeError("IDE exited during qualification. See " + str(base / "launcher.log"))
time.sleep(.25)
else:
raise RuntimeError("IDE qualification timed out: " + str(base))
natives = subprocess.run([args.java_home / "bin/jcmd", str(pid), "VM.dynlibs"],
capture_output=True, text=True, check=True, timeout=20).stdout
(output / (mode + "-natives.txt")).write_text(natives)
paths = sorted(set(re.findall(r"(/[^\r\n]*?libglass\.dylib)", natives)))
expected = {}
for artifact in (Path.home() / ".m2/repository/org/openjfx").glob("*/26/*-mac*.jar"):
with zipfile.ZipFile(artifact) as jar:
for name in jar.namelist():
if name.endswith(".dylib"):
expected.setdefault(Path(name).name, set()).add(hashlib.sha256(jar.read(name)).hexdigest())
actual = {path: hashlib.sha256(Path(path).read_bytes()).hexdigest() for path in paths}
assert len(actual) == 1 and next(iter(actual.values())) in expected["libglass.dylib"], actual
all_paths = sorted(set(re.findall(r"(/[^\r\n]*?/\.openjfx/[^\r\n]*?\.dylib)", natives)))
all_native = {path: hashlib.sha256(Path(path).read_bytes()).hexdigest() for path in all_paths}
assert all(digest in expected.get(Path(path).name, set()) for path, digest in all_native.items())
proof = {"mode": mode, "host": str(base), "glass": actual, "openjfx": all_native,
"result": (base / "SUCCESS.txt").read_text()}
(output / (mode + ".json")).write_text(json.dumps(proof, indent=2) + "\n")
shutil.copyfile(base / "intellij.png", output / (mode + ".png"))
(evidence / "proof.json").write_text(json.dumps(proof, indent=2) + "\n")
finally:
for name in ("viewer-target.png", "import-pending.png", "import-failed.png", "import-retried.png", "import-new-session.png", "row-folders.png", "row-types.png", "folder-metadata.png", "dock-horizontal.png", "dock-vertical.png", "dock-empty-kept.png", "dock-empty-removed.png", "media-granted.png", "details-moved.png", "trash-split.png", "grid-group.png", "reader-pdf.png", "reader-epub.png", "reader-slides.png", "reader-attachment.png", "management-accounts.png", "management-trash.png", "reader-icon.png", "folder-events.png", "folder-search.png", "folder-profile.png", "result-folder-actions", "result-detail-action", "details-invoice-tags.png", "details-delivery-tags.png", "details-invoice.png", "details-delivery.png", "details-readonly.png", "details-busy.png", "html-invoice.png", "html-delivery.png", "rechnung-zwei-tags.png", "import-collision.png", "import-accepted.png", "result-import-free", "result-import-busy", "result-import-collision", "result-import-grid", "SUCCESS.txt", "FAILURE.txt", "ui-state.txt", "launcher.log", "steps.txt", "target-error.txt", "preview-restored.png", "imap.png", "jmap.png", "invoice.png", "delivery.png", "saved-document-result", "saved-bindings.fxml", "binding-article.png", "binding-dynamic.png", "tags-Pr.png", "tags-Re.png", "tags-Li.png", "document-tabs-result", "rechnung-tab.png", "lieferschein-tab.png", "rechnung-tab-tags.png", "lieferschein-tab-tags.png", "folder.png", "right.png", "bottom.png", "result-folder", "result-right", "result-bottom", "intellij.png"):
if (base / name).exists():
shutil.copyfile(base / name, evidence / name)
workers = descendant_workers(pid)
try:
os.kill(pid, signal.SIGTERM)
except ProcessLookupError:
pass
await_worker_exit(workers)
crashes.check()
print("PASS registered IntelliJ " + mode + f" run {run_number}: editor, exclusive JavaFX 26 natives and worker shutdown", flush=True)