Cloudflare Pages / Build and verify the site (push) Successful in 3m29s
Use the verified dependency lock across native hosts and bundled apps. Preserve saved styles, local app reactivation, and offline packages while integrating the latest practice, Habits, Lumi, and figure preview updates.
236 lines
12 KiB
Python
236 lines
12 KiB
Python
#!/usr/bin/env python3
|
|
"""Apps from the node open only once they are on this device.
|
|
|
|
Radio is installed on the account, as from another device, but its package
|
|
never reached this one; Photos is only offered. The network is cut off, so
|
|
nothing downloads. Tapping Radio's pin in the navigation, either app in
|
|
Apps, or launching with --app radio must not open them, and "Installing
|
|
this app" is never drawn. The app runs on a private Xvfb display; widgets
|
|
come from Kryon's test driver and routes from the app's debug log, never
|
|
from screenshots.
|
|
"""
|
|
import contextlib
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import sqlite3
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
from ui_driver import UiDriver
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
OUTPUT = ROOT / "build/node-app-not-installed-ui-test"
|
|
OUTPUT.mkdir(parents=True, exist_ok=True)
|
|
BINARY = Path(sys.argv[1]).resolve()
|
|
FAILURE_ONLY = "--failure-only" in sys.argv[2:]
|
|
DESKTOP_ENV = ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS",
|
|
"GDK_DISPLAY", "SESSION_MANAGER")
|
|
assert all(not os.environ.get(key) for key in DESKTOP_ENV), "Inherited desktop environment"
|
|
WIDTH, HEIGHT = 390, 844
|
|
# ScreenNodeApp, the screen of an app the node offers.
|
|
NODE_APP_SCREEN = "26"
|
|
# The navigation's buttons share this focus group.
|
|
NAVIGATION = 6600
|
|
# Routes: Diary, then the app in the node's first slot.
|
|
DIARY_ROUTE, FIRST_NODE_APP_ROUTE = 11, 14
|
|
SWITCH = re.compile(r"ROUTE switch frame=\d+ screen=(\d+)->(\d+)")
|
|
|
|
|
|
def stop(process):
|
|
if process.poll() is None:
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait(timeout=5)
|
|
|
|
|
|
def wait(predicate, description, timeout=30):
|
|
end = time.monotonic() + timeout
|
|
while time.monotonic() < end:
|
|
value = predicate()
|
|
if value:
|
|
return value
|
|
time.sleep(.05)
|
|
raise AssertionError(description)
|
|
|
|
|
|
with contextlib.ExitStack() as stack:
|
|
profile = Path(stack.enter_context(tempfile.TemporaryDirectory(prefix="inbe-node-closed-")))
|
|
env = {key: value for key, value in os.environ.items() if key not in DESKTOP_ENV}
|
|
for key in ("HARMONY_DATA_ROOT", "INBE_DIARY_IMPORT", "INBE_NODE_APP_FILE"):
|
|
env.pop(key, None)
|
|
# Offline: a download Radio or Photos asks for fails at once.
|
|
env.update(YUE_DESKTOP_RECOVERY="0", APP_NO_TRAY="1", SDL_AUDIODRIVER="dummy",
|
|
APP_DATA_ROOT=str(profile), INBE_DEBUG_ROUTE="1",
|
|
https_proxy="http://127.0.0.1:9", http_proxy="http://127.0.0.1:9", NO_PROXY="")
|
|
display_log = stack.enter_context((OUTPUT / "display.log").open("w"))
|
|
display = subprocess.Popen(["Xvfb", "-noreset", "-displayfd", "1", "-screen", "0", "1200x1000x24",
|
|
"-nolisten", "tcp"], env=env, stdout=subprocess.PIPE, stderr=display_log)
|
|
stack.callback(stop, display)
|
|
number = display.stdout.readline().decode().strip()
|
|
display.stdout.close()
|
|
assert number.isdecimal(), "Private display did not start"
|
|
env["DISPLAY"] = ":" + number
|
|
driver = UiDriver(OUTPUT / "driver")
|
|
env.update(driver.environment())
|
|
|
|
@contextlib.contextmanager
|
|
def application(name, *arguments):
|
|
log_path = OUTPUT / (name + ".log")
|
|
with log_path.open("w") as log:
|
|
app = subprocess.Popen([str(BINARY), *arguments], cwd=ROOT, env=env,
|
|
stdout=log, stderr=subprocess.STDOUT)
|
|
driver.attach(app, log_path)
|
|
try:
|
|
def window():
|
|
assert app.poll() is None, log_path.read_text()[-4000:]
|
|
result = subprocess.run(["xdotool", "search", "--onlyvisible", "--pid", str(app.pid)],
|
|
env=env, capture_output=True, text=True, timeout=5)
|
|
return result.stdout.splitlines()[0] if result.returncode == 0 else None
|
|
owned_window = wait(window, "App did not map a window")
|
|
subprocess.run(["xdotool", "windowsize", owned_window, str(WIDTH), str(HEIGHT)],
|
|
env=env, check=True, capture_output=True)
|
|
wait(lambda: (profile / "inbe.db").exists(), "Database was not created")
|
|
wait(lambda: driver.tree(), "App did not draw")
|
|
yield owned_window, log_path
|
|
assert app.poll() is None, log_path.read_text()[-4000:]
|
|
finally:
|
|
stop(app)
|
|
|
|
def settings():
|
|
uri = (profile / "inbe.db").as_uri() + "?mode=ro"
|
|
with contextlib.closing(sqlite3.connect(uri, uri=True, timeout=3)) as db:
|
|
return dict(db.execute("SELECT key,value FROM settings WHERE user_id=?", (user,)))
|
|
|
|
def stays_closed(log_path, step):
|
|
"""No route reaches an app's screen, and the installing notice never shows."""
|
|
driver.wait_idle(frames=5, timeout=3)
|
|
# Long enough for a deferred switch or a download failure to land.
|
|
time.sleep(1.0)
|
|
driver.wait_idle(frames=3, timeout=3)
|
|
opened = []
|
|
with log_path.open() as log:
|
|
for line in log:
|
|
assert "NODE: install radio " not in line and "NODE: install photos " not in line, \
|
|
f"{step}: opening started a download before confirmation: {line.strip()}"
|
|
switch = SWITCH.search(line)
|
|
if switch and switch[2] == NODE_APP_SCREEN:
|
|
opened.append(switch.groups())
|
|
assert not opened, f"{step}: an app that is not installed opened: {opened}"
|
|
text = driver.text(visible=False)
|
|
assert "Installing this app" not in text and "node_app_installing" not in text, \
|
|
f"{step}: the installing notice was drawn:\n{text}"
|
|
|
|
def apps_open():
|
|
return driver.find(label="Find an app", role="text_field", visible=True)
|
|
|
|
def grid_cards(label):
|
|
"""Apps cards with this label, outside the navigation."""
|
|
return [node for node in driver.find(label=label, role="button", visible=True)
|
|
if node.get("focus_id") != NAVIGATION and node["width"] > 60]
|
|
|
|
def close_download(name):
|
|
driver.wait(label=name, role="modal")
|
|
driver.wait(label="Cancel", role="button")
|
|
driver.key("escape")
|
|
driver.wait_gone(label=name, role="modal")
|
|
|
|
with application("initialize"):
|
|
pass
|
|
with contextlib.closing(sqlite3.connect(profile / "inbe.db")) as db, db:
|
|
user = db.execute("SELECT id FROM users WHERE kind='local' LIMIT 1").fetchone()[0]
|
|
seeded = dict(language="en", language_system=0, language_setup_done=1, apps_setup_done=1,
|
|
enabled_apps=63, lumi_introduced=1, tutorial_seen=1, habits_guide_seen=1,
|
|
launcher_guide_seen=1, lumi_guides_seen=127, main_tab=3,
|
|
# No update check or catalog read is due.
|
|
package_updates_allowed=0, apps_last_update_check=1900000000,
|
|
node_apps_checked_at=int(time.time()),
|
|
node_apps_offers="radio|Radio\nphotos|Photos\n",
|
|
node_app_size_radio=120000, node_app_size_photos=150000,
|
|
# Radio is on the account in this device's first slot,
|
|
# without its package; it is pinned after Diary.
|
|
node_app_slot_0="radio", app_used_radio=1,
|
|
launcher_favorite_count=2, launcher_favorite_0=DIARY_ROUTE,
|
|
launcher_favorite_1=FIRST_NODE_APP_ROUTE)
|
|
for name in ("lists", "habits", "practices", "diary", "lumi", "leaderboard"):
|
|
seeded["app_used_" + name] = 1
|
|
for key, value in seeded.items():
|
|
db.execute("INSERT INTO settings(user_id,key,value,updated_at) VALUES(?,?,?,1) "
|
|
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value", (user, key, str(value)))
|
|
|
|
if not FAILURE_ONLY:
|
|
with application("taps") as (window, log_path):
|
|
driver.wait(label="Apps", role="button", focus_id=NAVIGATION)
|
|
stays_closed(log_path, "start")
|
|
|
|
# Radio's pin in the navigation.
|
|
driver.press(label="Radio", role="button", focus_id=NAVIGATION)
|
|
close_download("Radio")
|
|
stays_closed(log_path, "navigation pin")
|
|
|
|
# Radio's card in Apps: Apps stays open on its list.
|
|
driver.press(label="Apps", role="button", focus_id=NAVIGATION)
|
|
wait(apps_open, "Apps did not open")
|
|
radio = wait(lambda: grid_cards("Radio"), "Radio has no card in Apps")[0]
|
|
driver.press(key=radio["key"], label="Radio")
|
|
close_download("Radio")
|
|
stays_closed(log_path, "Apps card")
|
|
assert apps_open(), "Tapping an app that is not installed closed Apps"
|
|
|
|
# An offered app asks in the same dialog before installing.
|
|
driver.press(label="Find an app", role="text_field")
|
|
driver.type("Photos")
|
|
photos = wait(lambda: grid_cards("Photos"), "Photos is not offered in Apps")[0]
|
|
driver.press(key=photos["key"], label="Photos")
|
|
driver.wait(contains="Download size:")
|
|
assert settings().get("app_used_photos") != "1", "The app downloaded before consent"
|
|
close_download("Photos")
|
|
stays_closed(log_path, "offered app")
|
|
assert apps_open(), "Tapping an offered app closed Apps"
|
|
|
|
# A launcher's shortcut asks for Radio by name: Inbe starts on its own
|
|
# page, with its navigation, instead of on Radio's.
|
|
with application("launcher", "--app", "radio") as (window, log_path):
|
|
driver.wait(label="Apps", role="button", focus_id=NAVIGATION)
|
|
stays_closed(log_path, "launcher shortcut")
|
|
driver.wait(label="Apps", role="button", focus_id=NAVIGATION)
|
|
title = subprocess.run(["xdotool", "getwindowname", window], env=env,
|
|
capture_output=True, text=True, timeout=5).stdout.strip()
|
|
assert title != "Radio", "The launcher opened Radio"
|
|
|
|
# A real opening failure has a dialog over the loading state. It never
|
|
# becomes the app's page or appears while the background work is pending.
|
|
broken = profile / "radio.zx"
|
|
broken.write_bytes(b"ZX\0truncated-test-package")
|
|
env["INBE_NODE_APP_FILE"] = str(broken)
|
|
with application("failed-open", "--app", "radio") as (window, log_path):
|
|
driver.wait(label="This app could not be installed. Check your connection and try again from Apps.",
|
|
role="text", timeout=60)
|
|
driver.wait(role="modal")
|
|
destination = os.environ.get("BREEZE_LOADING_CAPTURE")
|
|
if destination:
|
|
assert display.poll() is None and Path(f"/proc/{display.pid}/exe").resolve().name == "Xvfb"
|
|
assert "-displayfd" in display.args
|
|
pid = subprocess.check_output(["xdotool", "getwindowpid", window], env=env, text=True).strip()
|
|
assert pid == str(driver.process.pid)
|
|
target = Path(destination)
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.with_suffix(".source.txt").write_text(repr((display.pid, display.args, number, pid, window)))
|
|
subprocess.run(["import", "-window", window, str(target)], env=env, check=True)
|
|
driver.wait(label="Retry", role="button")
|
|
driver.press(label="Retry", role="button")
|
|
driver.wait_gone(role="modal", timeout=5)
|
|
driver.wait(role="modal", timeout=60)
|
|
driver.press(label="Close", role="button")
|
|
driver.wait(label="Find an app", role="text_field")
|
|
assert not driver.find(label="Retry", role="button", visible=True), "The failure dialog stayed after Close"
|
|
|
|
print("Failed opening uses a Retry/Close modal over loading and Close returns to Apps" if FAILURE_ONLY else
|
|
"Apps from the node that are not on this device stay closed from the navigation, "
|
|
"Apps, an offer and a launcher shortcut, and never show the installing notice")
|