diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c36b9ce..6dde78312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +## [1.15.6] + +### Highlights + +**Zimi** + +- Voices install on the portable Linux build (#151). +- A voice missing its engine gets a Set up button. + +**Games** + +- Fixes and Kiwix compatibility, so the Games ZIM can be shared with the community. + +**Almanac** + +- Ten languages, fixes and Kiwix compatibility, so the Almanac ZIM can be shared with the community. + ## [1.15.5] ### Highlights diff --git a/ci/smoke_portable.sh b/ci/smoke_portable.sh index a6760d1d4..b749caaa8 100755 --- a/ci/smoke_portable.sh +++ b/ci/smoke_portable.sh @@ -28,8 +28,9 @@ echo "zimi config (the portable folder decides the paths)..." "$Z" config | tee "$STICK/config.txt" grep -q "portable" "$STICK/config.txt" || { echo "FAIL: config does not show the portable folder"; exit 1; } -echo "zimi doctor --check..." -"$Z" doctor --check +echo "zimi doctor --check (also: the machine's python3, started from the app, is not handed the bundle's libraries, #151)..." +"$Z" doctor --check | tee "$STICK/doctor.txt" +grep -q "would not run properly" "$STICK/doctor.txt" && { echo "FAIL: the app leaks its environment to outside programs"; exit 1; } echo "zimi service print (ExecStart must be this executable)..." "$Z" service print | tee "$STICK/unit.txt" diff --git a/pyproject.toml b/pyproject.toml index 26f68e57c..365cc51f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "zimi" -version = "1.15.5" +version = "1.15.6" description = "Offline knowledge server for ZIM files — search and read Wikipedia, Stack Overflow and 50+ sources with no internet" readme = "README.md" license = {text = "GPL-3.0-or-later"} diff --git a/scripts/build_almanac_kiwix.py b/scripts/build_almanac_kiwix.py new file mode 100644 index 000000000..4f371c39d --- /dev/null +++ b/scripts/build_almanac_kiwix.py @@ -0,0 +1,99 @@ +"""Build the Almanac for openZIM/Kiwix: the standard Almanac without the Golden Record pictures that are not public domain. + + python scripts/build_almanac_kiwix.py [--out DIR] [--file NAME] [--name ZIM_NAME] [--title TITLE] + +openZIM and Kiwix take only free content. The Almanac's Golden Record gallery shows 49 of the record's pictures: +8 NASA photographs (public domain) and 41 that are copyright their owners (golden-record/credits.json). This +edition keeps the 8 and names each of the 41 in the gallery's list (number, title, credit), so the record's +sequence stays whole (almanacstage.stage, community). Everything else is the Almanac ``python -m zimi.ownzims`` builds; +Zimi's own Almanac keeps all 49. Nothing is committed: the file goes to --out. + +Its Name and Title are openZIM's, not the ones Zimi's own copy carries: Name ``zimi_mul_almanac`` (openZIM's +{domain}_{lang}_{selection}; ``mul`` for several languages) and Title "Zimi Almanac". The page speaks Zimi's ten languages. +""" + +import argparse +import datetime +import os +import re +import sys +import tempfile + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, ROOT) + +DEFAULT_NAME = "zimi_mul_almanac" # openZIM: {domain}_{lang}_{selection}; several languages are "mul" +#: The Language metadata: the ten languages the page speaks, ISO 639-3, in the order the Games use. +LANGUAGES = "eng,zho,hin,spa,ara,fra,por,rus,deu,heb" +DEFAULT_TITLE = "Zimi Almanac" +FILE_FMT = "%s_%s.zim" +_NAME = re.compile(r"^zimi_([a-z]{2,3})_([a-z0-9][a-z0-9.-]*)$") +#: Text for the ZIM's Description or LongDescription instead of zimi.txt's (None keeps zimi.txt's). Change a line, rebuild. +DESCRIPTION = None +LONG_DESCRIPTION = None + + +def set_fields(folder, **fields): + """Rewrite lines of the folder's zimi.txt; each field must already be there exactly once. None leaves it alone.""" + meta = os.path.join(folder, "zimi.txt") + with open(meta, encoding="utf-8") as f: + text = f.read() + for key, value in fields.items(): + if value is None: + continue + text, n = re.subn(r"(?m)^%s:.*$" % key, lambda m: "%s: %s" % (key, value), text) + if n != 1: + raise SystemExit("zimi.txt has no single %s line" % key) + with open(meta, "w", encoding="utf-8", newline="\n") as f: + f.write(text) + + +def build(out_dir, file_name=None, name=DEFAULT_NAME, title=DEFAULT_TITLE, month=None, description=None, long_description=None): + """The community Almanac, built from the source as it is now. Returns its path.""" + from zimi import almanacstage, creator, ownzims + + m = _NAME.match(name) + if not m: + raise SystemExit( + "--name must look like zimi__, e.g. %s" % DEFAULT_NAME + ) + month = month or datetime.date.today().strftime("%Y-%m") + os.makedirs(out_dir, exist_ok=True) + path = os.path.join(out_dir, file_name or FILE_FMT % (name, month)) + with tempfile.TemporaryDirectory(prefix="zimi-kiwix-") as tmp: + dest = os.path.join(tmp, m.group(2)) + os.mkdir(dest) + almanacstage.stage(dest, community=True) + set_fields(dest, Title=title, Language=LANGUAGES, Description=description or DESCRIPTION, LongDescription=long_description or LONG_DESCRIPTION) + # The Name is set outright: creator derives it from the Language metadata's 3-letter code (zimi_eng_...). + real = creator.zim_name + creator.zim_name = lambda scope, language="eng": name + try: + creator.create_folder_zim(dest, out_path=path, register=False, extra_items=ownzims.with_build_year()) + finally: + creator.zim_name = real + return path + + +def main(argv=None): + ap = argparse.ArgumentParser() + ap.add_argument("--out", default=os.path.join(ROOT, "dist", "kiwix")) + ap.add_argument("--file", help="the file's name (default _.zim)") + ap.add_argument( + "--name", + default=DEFAULT_NAME, + help="the ZIM's Name metadata (default %(default)s)", + ) + ap.add_argument( + "--title", default=DEFAULT_TITLE, help="the ZIM's Title (default %(default)s)" + ) + ap.add_argument("--description", help="the ZIM's Description (default zimi.txt's)") + ap.add_argument("--long-description", help="the ZIM's LongDescription (default zimi.txt's)") + a = ap.parse_args(argv) + path = build(a.out, a.file, a.name, a.title, description=a.description, long_description=a.long_description) + print("built %s (%.1f MB)" % (path, os.path.getsize(path) / 1e6)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/build_games_kiwix.py b/scripts/build_games_kiwix.py new file mode 100644 index 000000000..170414461 --- /dev/null +++ b/scripts/build_games_kiwix.py @@ -0,0 +1,65 @@ +"""Build Zimi Games for openZIM/Kiwix: the same games, with the ZIM's Name, Title and languages openZIM's catalogue uses. + + python scripts/build_games_kiwix.py [--out DIR] [--file NAME] [--name ZIM_NAME] [--title TITLE] + +The games folder is copied to a temporary folder whose zimi.txt gets the Title and the ten interface languages; nothing in +the repo changes. A ZIM in several languages is named ``mul`` by Kiwix, so the Name is set outright (``zimi_mul_games``). +build_almanac_kiwix.py holds the sibling for the Almanac, and the DESCRIPTION / LONG_DESCRIPTION switches that both share. +""" + +import argparse +import datetime +import os +import shutil +import sys +import tempfile + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, ROOT) +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +DEFAULT_NAME = "zimi_mul_games" +DEFAULT_TITLE = "Zimi Games" +FILE_FMT = "%s_%s.zim" +#: Text for the ZIM's Description or LongDescription instead of zimi.txt's (None keeps zimi.txt's). Change a line, rebuild. +DESCRIPTION = None +LONG_DESCRIPTION = None + + +def build(out_dir, file_name=None, name=DEFAULT_NAME, title=DEFAULT_TITLE, month=None, description=None, long_description=None): + """The community Games, built from the source as it is now. Returns its path.""" + from build_almanac_kiwix import LANGUAGES, set_fields + from zimi import creator, ownzims + + month = month or datetime.date.today().strftime("%Y-%m") + os.makedirs(out_dir, exist_ok=True) + path = os.path.join(out_dir, file_name or FILE_FMT % (name, month)) + with tempfile.TemporaryDirectory(prefix="zimi-kiwix-") as tmp: + src = os.path.join(tmp, "games") + shutil.copytree(os.path.join(ownzims.SOURCE_ROOT, "games"), src) + set_fields(src, Title=title, Language=LANGUAGES, Description=description or DESCRIPTION, LongDescription=long_description or LONG_DESCRIPTION) + real = creator.zim_name + creator.zim_name = lambda scope, language="eng": name + try: + creator.create_folder_zim(src, out_path=path, register=False, extra_items=ownzims.with_build_year()) + finally: + creator.zim_name = real + return path + + +def main(argv=None): + ap = argparse.ArgumentParser() + ap.add_argument("--out", default=os.path.join(ROOT, "dist", "kiwix")) + ap.add_argument("--file", help="the file's name (default _.zim)") + ap.add_argument("--name", default=DEFAULT_NAME, help="the ZIM's Name metadata (default %(default)s)") + ap.add_argument("--title", default=DEFAULT_TITLE, help="the ZIM's Title (default %(default)s)") + ap.add_argument("--description", help="the ZIM's Description (default zimi.txt's)") + ap.add_argument("--long-description", help="the ZIM's LongDescription (default zimi.txt's)") + a = ap.parse_args(argv) + path = build(a.out, a.file, a.name, a.title, description=a.description, long_description=a.long_description) + print("built %s (%.1f MB)" % (path, os.path.getsize(path) / 1e6)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/verify_games_qids.py b/scripts/verify_games_qids.py new file mode 100644 index 000000000..5f48df113 --- /dev/null +++ b/scripts/verify_games_qids.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +"""Check ZimiGames' Q-IDs against English Wikipedia. + + python3 scripts/verify_games_qids.py + +Each row of zimi/builtin/games/games.json that stands for a game with an +encyclopedia article carries `qid` and `wiki` (the English title). The About +link and the "learn more" links resolve through the Q-ID, so a wrong one opens +the wrong article. For every row this asks the English Wikipedia API for the +title's `wikibase_item` (redirects followed) and reports a title that is +missing, a disambiguation page, or whose item is not the Q-ID written down. +Same lookup as verify_almanac_qids.py. Needs the network; nothing at runtime does. +""" + +import json +import os +import sys +import urllib.parse +import urllib.request + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from verify_almanac_qids import BATCH, USER_AGENT, lookup # noqa: E402 + +GAMES_JSON = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + "zimi", + "builtin", + "games", + "games.json", +) + + +def entries(path=GAMES_JSON): + """[(q, en title, page)] for every row that has an article.""" + with open(path, encoding="utf-8") as f: + rows = json.load(f) + return [ + (r["qid"], r["wiki"], r["path"]) for r in rows if r.get("qid") and r.get("wiki") + ] + + +WIKIDATA = "https://www.wikidata.org/w/api.php" + + +def enwiki_titles(qids): + """{Q-ID: the English Wikipedia title the item's sitelink names}, 50 at a time.""" + out = {} + qids = list(dict.fromkeys(qids)) + for i in range(0, len(qids), BATCH): + url = WIKIDATA + "?" + urllib.parse.urlencode( + { + "action": "wbgetentities", + "format": "json", + "props": "sitelinks", + "sitefilter": "enwiki", + "ids": "|".join(qids[i : i + BATCH]), + } + ) + req = urllib.request.Request(url, headers={"User-Agent": USER_AGENT}) + with urllib.request.urlopen(req, timeout=60) as r: + data = json.load(r)["entities"] + for q, ent in data.items(): + link = ent.get("sitelinks", {}).get("enwiki") + if link: + out[q] = link["title"] + return out + + +def audit(found, res, sitelinks=lambda qids: {}): + """[(q, title, page, why)] for each entry whose article is not its Q-ID. + + A title that is a redirect to another item's article still fits when the + Q-ID's own English sitelink is that very title (Wikidata files a game under + the redirect), so only the rest are reported.""" + bad = [] + mismatched = [q for q, en, _ in found if not (res[en]["missing"] or res[en]["disambig"]) and res[en]["q"] != q] + own = sitelinks(mismatched) if mismatched else {} + for q, en, page in found: + r = res[en] + if r["missing"]: + bad.append((q, en, page, "missing")) + elif r["disambig"]: + bad.append((q, en, page, "disambiguation page")) + elif r["q"] != q and own.get(q) != en: + bad.append((q, en, page, "is %s" % r["q"])) + return bad + + +def main(): + found = entries() + bad = audit(found, lookup([en for _, en, _ in found]), enwiki_titles) + for q, en, page, why in bad: + print("BAD %-10s %-45s %-28s %s" % (q, en, page, why)) + print("%d games, %d bad" % (len(found), len(bad))) + return 1 if bad else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/conftest.py b/tests/conftest.py index 82ac5f88b..baf284616 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -345,3 +345,16 @@ def _no_router_changes(request, monkeypatch): monkeypatch.setattr(p2p, "is_upnp_enabled", lambda: False) monkeypatch.setattr(p2p_nat, "add_port_mapping", lambda port: False) yield + + +@pytest.fixture(autouse=True) +def _p2p_prefs_path_is_put_back(monkeypatch): + """A test that points the BT prefs at its own temp file (p2p.set_prefs_path) leaves them there for the next test of the + worker, whose "seeding is on by default" then reads a stranger's file.""" + try: + from zimi import p2p + except Exception: + yield + return + monkeypatch.setattr(p2p, "_prefs_path", p2p._prefs_path) + yield diff --git a/tests/fixtures/games_solitaire/freecell.json b/tests/fixtures/games_solitaire/freecell.json index 81bd549e2..31c3de023 100644 --- a/tests/fixtures/games_solitaire/freecell.json +++ b/tests/fixtures/games_solitaire/freecell.json @@ -160,7 +160,7 @@ "fact": "", "label": "shell new game", "moves": 0, - "sheet": "FreeCellNew gameHintSettingsHow to playHistoryStatsAbout this game", + "sheet": "FreeCellNew gameHintSettingsHow to playHistoryStatsAbout this game\u00a9 Zimi", "stat": "0:00", "state": "796b862f", "sub": "", @@ -174,5 +174,5 @@ "hseed": 42, "plays": "tap:31>fr0 tap:15>fr1 drag:5>fr2 drag:33>c1 tap:50>fr3 dead-end drag:9>fr3 tap:44>c7 dead-end drag:19>c6 tap:31>c7 stray:37 tap:44>c6 tap:18>fr0 drag:41>c4 drag:15>c0 tap:15>fr1 drag:15>c0 tap:45>c1 drag:50>fr1 stray:40 tap:1>c0 drag:0>fd0 drag:27>c4 tap:2>fd0 dead-end tap:27>c7 drag:27>c4 stray:32 tap:2>fd0 dead-end tap:27>c7 tap:27>c4 tap:27>c7 drag:27>c4 drag:27>c7 tap:27>c4 stray:0 tap:27>c7 tap:27>c4 tap:2>fd0 dead-end drag:2>fd0 dead-end tap:2>fd0 dead-end tap:2>fd0 dead-end drag:2>fd0 dead-end drag:2>fd0 dead-end drag:27>c7 tap:27>c4 tap:2>fd0 dead-end tap:2>fd0 dead-end drag:27>c7 tap:27>c4 tap:2>fd0 dead-end drag:27>c7 tap:27>c4 tap:27>c7 tap:27>c4 drag:27>c7 drag:27>c4 drag:27>c7 tap:27>c4 drag:2>fd0 dead-end drag:27>c7 tap:27>c4 stray:1 tap:2>fd0 dead-end tap:27>c7 tap:27>c4 drag:27>c7 tap:27>c4 drag:27>c7 drag:27>c4 drag:2>fd0 dead-end tap:2>fd0 dead-end drag:27>c7 tap:27>c4 drag:27>c7 tap:27>c4 drag:27>c7 tap:27>c4 tap:2>fd0 dead-end tap:2>fd0 dead-end drag:27>c7 drag:27>c4 tap:27>c7 drag:27>c4 drag:27>c7 drag:27>c4 tap:27>c7 tap:27>c4 tap:2>fd0 dead-end tap:27>c7 drag:27>c4 tap:2>fd0 dead-end tap:27>c7 drag:27>c4 tap:27>c7 drag:27>c4 tap:27>c7 tap:27>c4 tap:27>c7 stray:12 tap:27>c4 tap:2>fd0 dead-end tap:2>fd0 dead-end tap:2>fd0 dead-end tap:27>c7 tap:27>c4 tap:27>c7 tap:27>c4 drag:2>fd0 dead-end drag:27>c7 stray:41 tap:27>c4 tap:2>fd0 dead-end tap:2>fd0 dead-end drag:27>c7 drag:27>c4 drag:27>c7 tap:27>c4 tap:2>fd0 dead-end drag:2>fd0 dead-end tap:27>c7 tap:27>c4 tap:27>c4 drag:27>c7 tap:27>c4 tap:2>fd0 dead-end tap:27>c7 drag:27>c4 drag:2>fd0 dead-end stray:7 tap:2>fd0 dead-end drag:2>fd0 dead-end stray:20 drag:2>fd0 dead-end tap:27>c7 tap:27>c4 tap:2>fd0 dead-end tap:2>fd0 dead-end tap:27>c7 stray:41 stray:8 tap:27>c4 tap:2>fd0 dead-end stray:27 drag:27>c4 tap:2>fd0 dead-end drag:2>fd0 dead-end tap:27>c7 tap:27>c4 tap:2>fd0 dead-end tap:2>fd0 dead-end drag:29>fr0 tap:10>c7 tap:6>fr1 tap:10>fr2 tap:36>fr3 drag:37>c1 tap:10>c1 drag:1>fr2 drag:17>c5 tap:46>c3 tap:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 stray:12 drag:17>c4 drag:17>c5 tap:17>c4 drag:17>c5 drag:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 drag:17>c4 drag:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 drag:17>c5 stray:48 drag:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 drag:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 drag:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 stray:49 tap:17>c5 tap:17>c4 tap:17>c5 stray:39 stray:11 drag:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 stray:13 tap:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 stray:28 stray:50 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 drag:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 tap:17>c5 stray:41 tap:17>c4 stray:31 stray:1 tap:17>c5 tap:17>c4 drag:17>c5 tap:17>c4 stray:33 tap:17>c5 tap:17>c4 tap:17>c5 tap:17>c4 drag:46>fr0 tap:27>fr1 tap:18>fr2 tap:36>fr3 drag:45>c6 tap:18>c6 tap:42>fr2 tap:16>c0 dead-end tap:4>c6 drag:16>c6 tap:14>c0 dead-end tap:41>c6 tap:27>c6 tap:25>fr1 dead-end tap:15>fr1 dead-end tap:25>fr1 dead-end tap:28>fr1 dead-end drag:25>fr1 dead-end tap:14>fr1 dead-end drag:19>fr1 drag:15>c4 dead-end drag:28>c4 dead-end tap:28>c4 dead-end tap:28>c4 dead-end tap:28>c4 dead-end tap:28>c4 dead-end tap:28>c4 dead-end tap:28>c4 dead-end tap:15>c4 dead-end stray:39 drag:15>c4 dead-end stray:44", "seed": 32, - "trace": "9568b3982e3c1fdd8ef381adfb95f315b13b797fa6732a1363d21266d4f087ff3861099cb35918fbcc1515f77c15fe22d42af37127a415f0b5127543d2c5c70fc6e45ffe963c99777ce101afc74690227a773005f881b7979d8ea10aaa53a6c9c2088578e0b4763c02f1086dc004e1b627cdd40cce63e50612622fd0ac2ee6bfd91a5cc34d2df00637886f33748a6bf5ec3148f1a0b6a293482e9c5260ea290f71da2d25a0064e6981f88f68142b63c5181ac9b3ed4305fa897c90fea67d2c4c04aca2489cfbd41cefb8b0893df5faed90102d4d10ab4f20168e59f4411979dbae53794128c3328c44565c9c322e476801caf299180816c05cd030b5d83f32cc4ea903c3297d1bee7174f6bc4608a0ea0400fd31f28361cc3b617936e31573f69b2887b9f3b1a3ca1c68ca9a100bfe25429866d69033b5f613e8aca6ec02559e54f2114c9d32687e44c45f48656adecc323e1915b5da151d4ebb4779768654827ca33101fba3ea9afed07ffff02b5c4963e0e12b0121ea0213563baf19b085b6001d3d1d70af6972cf07d136e1c3758257cc50a930d9083af2beefac18f33eb7d1272043cd86c46eda841da9005276854cc4e604018f0b240bf8ff3b88782387fb1733ec3e428fd38f3f4340d8b079f916881bab811155c551a8f6f1d98274ff0f49f8d209103ee000784138a83e01d7609c49d94ec66afd75788849a16f7f12e3436c122373e948b7f7ce59cad0817bc213b61dd9b3f77f3523804c74ee01f7a52343d5406007064faec50f306e73a096ac626986513f13b6d1897b0780c7b5167584a18f6fe330a7bcdd75fdeb06c4d0d5ca9cd37da4597813d8d41b164961309e21530ae03c907bbffe8ca58a2b55a0aab91f46b2e24c326c77b77fa4201eacd3d0a930a854ed4bfb4fb67b1e251edd18cf7bd987f4b920a5f5680cf249eb45e7b59616a09ca91137bfeee5b61d00318268047bb0b652b78e0c8886d5ef9a9522dd2f7f2c424f376b3aede47168c90c26aa8a3334b9760883d380639045daae125e974404c5cfb048b624180338bb62d244b25c76c8837fe82b8859ea71a34c6fba87272be475c54d98eea3f6ec6d03ca6a0c818acde609cd3449fa1e00be125a05db983f78c519f9da49c17b38aa9f47f38d41e19d5461ea97d168d874b2cbc0b5ebcee563d25199719f1486d9aa5b0230454eca2685f9c81d0975ba494929304b5c47e282062072b4d3190f37cf2787187d102d0914ae2144094187dbdc095f82e09975ad1cb676fe4a5ce01b51c7d194542d9ce440ca54369ca716991677ad60874ba00e6d7b440b0f00ffa75c4e0b8e3e810aaacedadd4f6914db23e68b22a74b986b9d1dd8da822cd404262c1fe55d90134133cfd0fab3ba61554874e48a16248b23b10d3abd68b5c6ee8fc319ddb8f6f4602d9dd5d15411c9082313c0d5f4c4eabe036117e20a8dfe67eaf1b3b8a241b58dab6d233d28cbfc4db77d7a0f00bb4eb645deecba18e9d083ad99172ee91608a83294cbf364f909061efec201ed1ef813e69afca6a204807557d67d6c457d41bdd77cdce22e597f9a9f059cfc9acb1c7b46bdad85ce4b71213d1ae8b47a8fd2c1d28cc673d5819e189880ac28161b8fb668c746c3485c3d606e32e6e5250dbe806cf67f151f8a71d58ad3d447644bb0112dab700d781c2b12ba2e74129ba74999a698a59303b99a12d85aec0649485df10c090cc0818e7e500217cd687cd9f2da6f24aee59643c74a74209d1dd89e64be70b088a7c70ea4dec1bb53e241048fd854df02ddcf935dffbdf2dfeb21bba7359f3569401f305c5d70d87d1a4a67" + "trace": "9568b3982e3c1fdd8ef381adfb95f315b13b797fa6732a1363d21266d4f087ff3861099cb35918fbcc1515f77c15fe22d42af37127a415f0b5127543d2c5c70fc6e45ffe963c99777ce101afc74690227a773005f881b7979d8ea10aaa53a6c9c2088578e0b4763c02f1086dc004e1b627cdd40cce63e50612622fd0ac2ee6bfd91a5cc34d2df00637886f33748a6bf5ec3148f1a0b6a293482e9c5260ea290f71da2d25a0064e6981f88f68142b63c5181ac9b3ed4305fa897c90fea67d2c4c04aca2489cfbd41cefb8b0893df5faed90102d4d10ab4f20168e59f4411979dbae53794128c3328c44565c9c322e476801caf299180816c05cd030b5d83f32cc4ea903c3297d1bee7174f6bc4608a0ea0400fd31f28361cc3b617936e31573f69b2887b9f3b1a3ca1c68ca9a100bfe25429866d69033b5f613e8aca6ec02559e54f2114c9d32687e44c45f48656adecc323e1915b5da151d4ebb4779768654827ca33101fba3ea9afed07ffff02b5c4963e0e12b0121ea0213563baf19b085b6001d3d1d70af6972cf07d136e1c3758257cc50a930d9083af2beefac18f33eb7d1272043cd86c46eda841da9005276854cc4e604018f0b240bf8ff3b88782387fb1733ec3e428fd38f3f4340d8b079f916881bab811155c551a8f6f1d98274ff0f49f8d209103ee000784138a83e01d7609c49d94ec66afd75788849a16f7f12e3436c122373e948b7f7ce59cad0817bc213b61dd9b3f77f3523804c74ee01f7a52343d5406007064faec50f306e73a096ac626986513f13b6d1897b0780c7b5167584a18f6fe330a7bcdd75fdeb06c4d0d5ca9cd37da4597813d8d41b164961309e21530ae03c907bbffe8ca58a2b55a0aab91f46b2e24c326c77b77fa4201eacd3d0a930a854ed4bfb4fb67b1e251edd18cf7bd987f4b920a5f5680cf249eb45e7b59616a09ca91137bfeee5b61d00318268047bb0b652b78e0c8886d5ef9a9522dd2f7f2c424f376b3aede47168c90c26aa8a3334b9760883d380639045daae125e974404c5cfb048b624180338bb62d244b25c76c8837fe82b8859ea71a34c6fba87272be475c54d98eea3f6ec6d03ca6a0c818acde609cd3449fa1e00be125a05db983f78c519f9da49c17b38aa9f47f38d41e19d5461ea97d168d874b2cbc0b5ebcee563d25199719f1486d9aa5b0230454eca2685f9c81d0975ba494929304b5c47e282062072b4d3190f37cf2787187d102d0914ae2144094187dbdc095f82e09975ad1cb676fe4a5ce01b51c7d194542d9ce440ca54369ca716991677ad60874ba00e6d7b440b0f00ffa75c4e0b8e3e810aaacedadd4f6914db23e68b22a74b986b9d1dd8da822cd404262c1fe55d90134133cfd0fab3ba61554874e48a16248b23b10d3abd68b5c6ee8fc319ddb8f6f4602d9dd5d15411c9082313c0d5f4c4eabe036117e20a8dfe67eaf1b3b8a241b58dab6d233d28cbfc4db77d7a0f00bb4eb645deecba18e9d083ad99172ee91608a83294cbf364f909061efec201ed1ef813e69afca6a204807557d67d6c457d41bdd77cdce22e597f9a9f059cfc9acb1c7b46bdad85ce4b71213d1ae8b47a8fd2c1d28cc673d5819e189880ac28161b8fb668c746c3485c3d606e32e6e5250dbe806cf67f151f8a71d58ad3d447644bb0112dab700d781c2b12ba2e74129ba74999a698a59303b99a12d85aec0649485df10c090cc0818e7e500217cd687cd9f2da6f24aee59643c74a74209d1dd89e64be70b088a7c70ea4dec1bb53e241048fd854df02ddcf935dffbdf2dfeb21bba7359f3569401f30ad82d4de8a755d3d" } diff --git a/tests/fixtures/games_solitaire/golf.json b/tests/fixtures/games_solitaire/golf.json index bceee8087..e5afc117c 100644 --- a/tests/fixtures/games_solitaire/golf.json +++ b/tests/fixtures/games_solitaire/golf.json @@ -134,7 +134,7 @@ "fact": "", "label": "shell new game", "moves": 0, - "sheet": "GolfNew gameSettingsHow to playHistoryStatsAbout this game", + "sheet": "GolfNew gameSettingsHow to playHistoryStatsAbout this game\u00a9 Zimi", "stat": "0:00", "state": "6b2cb8e5", "sub": "", @@ -148,5 +148,5 @@ "hseed": 45, "plays": "stray:7 stock stock stock tap:44>waste tap:32>waste tap:7>waste tap:34>waste stock stock stock tap:29>waste drag:41>waste stock stock tap:10>waste drag:50>waste tap:38>waste stock stock stock stock drag:22>waste stray:30 stock tap:39>waste tap:40>waste drag:15>waste tap:16>waste stock stray:42 drag:20>waste stray:5 tap:47>waste tap:46>waste stock tap:48>waste stock drag:28>waste tap:3>waste drag:3>waste tap:47>waste stock tap:8>waste stock stock stock stock tap:6>waste stock tap:36>waste tap:19>waste", "seed": 35, - "trace": "ff1346e04e53ea3e4e60bbb1dc0cb86f20b795763778332cf857274983a3432c081dc85267e853a1430906fa617e301fad66aa23794f2782002fe09760210a0d8bd02e66a496cbe122cc39e91450e7f27ec32c3131ccf6fae8c572593831b3f44c6bbac4de87f6523f8a4a7241ebaa54977a410746153f1283ef3d8e31411b417965cc371b01f6dd24f78446fe350199937bbcdd1a00b0f7ba07b0c3876321a5963ad10f4bbe9384371f7107f2665517aa5b33ce63ffcf488e7de81f34f1dec042d89ea0c00f9780713e827de3d9f5b081e10f4103f4a8c4cbf746da70e595977f2fea89fb2f72d29a5c4030448540d9c224d2cf36c3c62e78ab38fbcd6ec56f34fb96565fbfd1917d1a35de4c981e51" + "trace": "ff1346e04e53ea3e4e60bbb1dc0cb86f20b795763778332cf857274983a3432c081dc85267e853a1430906fa617e301fad66aa23794f2782002fe09760210a0d8bd02e66a496cbe122cc39e91450e7f27ec32c3131ccf6fae8c572593831b3f44c6bbac4de87f6523f8a4a7241ebaa54977a410746153f1283ef3d8e31411b417965cc371b01f6dd24f78446fe350199937bbcdd1a00b0f7ba07b0c3876321a5963ad10f4bbe9384371f7107f2665517aa5b33ce63ffcf488e7de81f34f1dec042d89ea0c00f9780713e827de3d9f5b081e10f4103f4a8c4cbf746da70e595977f2fea89fb2f72d29a5c4030448540d9c224d2cf36c3c62e78ab38fbcd6ec56f34fb96565fbfd19185517a709061113b" } diff --git a/tests/fixtures/games_solitaire/pyramid.json b/tests/fixtures/games_solitaire/pyramid.json index d77eb1325..1df1542dc 100644 --- a/tests/fixtures/games_solitaire/pyramid.json +++ b/tests/fixtures/games_solitaire/pyramid.json @@ -134,7 +134,7 @@ "fact": "2 redeals", "label": "shell new game", "moves": 0, - "sheet": "PyramidNew gameSettingsHow to playHistoryStatsAbout this game", + "sheet": "PyramidNew gameSettingsHow to playHistoryStatsAbout this game\u00a9 Zimi", "stat": "0:00", "state": "45879585", "sub": "", @@ -148,5 +148,5 @@ "hseed": 44, "plays": "pair:p6_1>p6_3 stock pair:p6_1>p6_3 pair:p6_1>p6_3 pair:p6_1>p6_3 pair:p6_1>p6_3 pair:p6_2>p6_5 pair:p6_2>p6_5 pair:p6_4>waste pair:p6_4>waste pair:p5_4>out stock stock stock stock stock stock stock stock stock pair:p6_6>waste pair:p6_6>waste stock stock pair:waste>out stray:23 stock stock stock stock stock stock pair:p5_5>waste pair:p5_5>waste stock pair:p5_1>waste stray:8 stock stock stock pair:p6_0>waste stray:1 pair:p6_0>waste stock pair:p5_1>waste pair:p5_1>waste stock stock stock stock stock stock stock stock stock stock stray:45 stock stock pair:p5_0>waste pair:p5_0>waste pair:p4_0>p5_3 stock pair:p4_0>p5_3 pair:p4_0>p5_3 pair:p4_0>p5_3 pair:p4_0>p5_3 pair:p4_3>out stock stock stock pair:p5_2>waste stock stock stock stock stock stock stock stock stock stock stock stock stock stock pair:p4_4>waste pair:p4_4>waste stock stock stock stock pair:p5_2>waste pair:p5_2>waste pair:p3_3>p4_2 pair:p3_3>p4_2 pair:p3_2>waste stray:16 pair:p3_2>waste stock stock stock pair:p2_2>waste pair:p2_2>waste stock stock pair:p6_1>p6_6 stray:21 stock pair:p6_1>p6_6 pair:p6_1>p6_6 pair:p6_3>out stray:45 stock stray:2 stock stock stock pair:p6_0>waste pair:p6_0>waste stray:28 stock pair:p6_5>waste pair:p6_5>waste stock pair:p5_0>waste pair:p6_2>waste pair:p6_2>waste stock pair:p6_4>out stock pair:p6_2>waste pair:p6_2>waste pair:p6_2>waste pair:p6_2>waste pair:p6_2>waste pair:p6_2>waste pair:p6_2>waste stock stock pair:p6_2>waste pair:p6_2>waste pair:p6_2>waste stray:19", "seed": 34, - "trace": "2f1aeb1da569dc4459777bf40e0674badf8d93e3b13cdd6d770cf88b714af69cf915bf84cf8c036e465ebcdbc6a439b57e152022abb479cfbbdb755786aa1c12acfe558ddb2688b5440075d52dff33ce16da9e3025baacd90bc14f753598b624856b8b32a7f1ba56010af12756ac35f27c5404cce221604a1d6ded6ad1f195acbc653fe178ecb199f8b7d25eca178022497a410a0b673d8b8c73acf09de138df07186db5e5108e2486705c4dc1206eb9b0b26fd4a6ee82f21ad70111dc167d55093eff70170c3c32a03f0eb15f06ddbf75caf934e10739cf332dcdc060bf0ed9225aa35626dde3d4fe1921e7fcaa3f908ea27f9ab38fb0b73574b62c528a6ea15b3fd05a3921b1a05843a4a79fa31eed3b8327a12195ea23db18fd6e3b852d40cbcbb8eb9374697bab0b67dd361d4bba612a8fb6ff789dbd28378ee12eb4dc3d6673e0348d65b02031e4fa4058f56930e9fbcfc944aab3546a0b761525f9797002490382ec5af8f9e8b8c97d5c8f1865d565d68524a485fb373423c731e99b2c09151a7c789a8386588b6406d56fb177fe13ffbd6a56a1f9c5cdad2a4aa0fd7bb09d820e0b9c24c6698c13e6973c701b730b7637d0956307c29b6338f0c53c9adc9e99b990052c5453e2217677eb19611282608681cf61918047a440fbded64676f404231bf1bad3d2a168f5ce4ad09e496bee1426a447521a412b0ad0ec32901b8d7bf11f94ebe709b46acc5c8aa8ed76067486fc4fb24b6c3542afff8286ad4e533d1b3511cd9a7b30071a51095dbbf99ea6e91c5184d719fedc0ea7be0b209147ebe7da4ae67bb6be117e790e945825d40a9fe65f3664e44f52f338eed7e9e9bb8f3790dc452e1cc64e1b4b02c03cf2621f52af1566dbbeefddd0b6dc8fb4e2b8a1ae" + "trace": "2f1aeb1da569dc4459777bf40e0674badf8d93e3b13cdd6d770cf88b714af69cf915bf84cf8c036e465ebcdbc6a439b57e152022abb479cfbbdb755786aa1c12acfe558ddb2688b5440075d52dff33ce16da9e3025baacd90bc14f753598b624856b8b32a7f1ba56010af12756ac35f27c5404cce221604a1d6ded6ad1f195acbc653fe178ecb199f8b7d25eca178022497a410a0b673d8b8c73acf09de138df07186db5e5108e2486705c4dc1206eb9b0b26fd4a6ee82f21ad70111dc167d55093eff70170c3c32a03f0eb15f06ddbf75caf934e10739cf332dcdc060bf0ed9225aa35626dde3d4fe1921e7fcaa3f908ea27f9ab38fb0b73574b62c528a6ea15b3fd05a3921b1a05843a4a79fa31eed3b8327a12195ea23db18fd6e3b852d40cbcbb8eb9374697bab0b67dd361d4bba612a8fb6ff789dbd28378ee12eb4dc3d6673e0348d65b02031e4fa4058f56930e9fbcfc944aab3546a0b761525f9797002490382ec5af8f9e8b8c97d5c8f1865d565d68524a485fb373423c731e99b2c09151a7c789a8386588b6406d56fb177fe13ffbd6a56a1f9c5cdad2a4aa0fd7bb09d820e0b9c24c6698c13e6973c701b730b7637d0956307c29b6338f0c53c9adc9e99b990052c5453e2217677eb19611282608681cf61918047a440fbded64676f404231bf1bad3d2a168f5ce4ad09e496bee1426a447521a412b0ad0ec32901b8d7bf11f94ebe709b46acc5c8aa8ed76067486fc4fb24b6c3542afff8286ad4e533d1b3511cd9a7b30071a51095dbbf99ea6e91c5184d719fedc0ea7be0b209147ebe7da4ae67bb6be117e790e945825d40a9fe65f3664e44f52f338eed7e9e9bb8f3790dc452e1cc64e1b4b02c03cf2621f52af1566dbbeefddd0b00e4e7a27de2ad4" } diff --git a/tests/fixtures/games_solitaire/solitaire.json b/tests/fixtures/games_solitaire/solitaire.json index e3ebddde3..4e3ef59c5 100644 --- a/tests/fixtures/games_solitaire/solitaire.json +++ b/tests/fixtures/games_solitaire/solitaire.json @@ -121,7 +121,7 @@ "fact": "", "label": "shell menu", "moves": 9, - "sheet": "SolitaireNew gameSettingsHow to playWatch and learnHistoryStatsAbout this game", + "sheet": "SolitaireNew gameSettingsHow to playWatch and learnHistoryStatsAbout this game\u00a9 Zimi", "stat": "0:00", "state": "549e162e", "sub": "", @@ -213,5 +213,5 @@ "hseed": 41, "plays": "tap:24>t6 tap:10>t6 tap:19>t3 tap:5>t3 stray:47 tap:51>t0 drag:17>t3 stock stock drag:42>t3 stock stock stock tap:20>t2 drag:20>t5 tap:20>t2 stray:4 stock tap:20>t5 tap:20>t2 drag:20>t5 tap:20>t2 stock tap:20>t5 drag:20>t2 tap:20>t5 stray:10 stray:49 stock stock tap:20>t2 drag:20>t5 stock tap:20>t2 tap:20>t5 tap:28>t3 tap:35>t0 tap:8>t0 drag:20>t0 tap:20>t5 drag:20>t0 drag:18>t2 stock tap:13>f0 tap:14>f0 tap:39>f1 stray:38 drag:6>t0 stray:38 tap:20>t5 tap:7>t4 tap:20>t0 stock tap:20>t5 stray:51 tap:18>t2 tap:5>t3 tap:18>t5 drag:5>t4 tap:18>t2 stock tap:5>t3 tap:18>t5 tap:18>t2 drag:18>t5 stock tap:18>t2 drag:20>t0 tap:18>t0 tap:18>t2 stock tap:5>t4 tap:5>t3 stock drag:18>t0 drag:5>t4 tap:1>t4 tap:20>t5 stray:14 stock tap:20>t0 tap:18>t2 tap:5>t3 tap:20>t5 tap:18>t5 tap:5>t4 stock stock tap:50>t6 drag:18>t2 tap:36>t6 tap:26>f2 tap:20>t0 tap:25>t1 tap:20>t5 tap:20>t0 stock tap:5>t3 tap:20>t5 drag:18>t5 tap:18>t2 drag:50>t1 drag:20>t0 tap:18>t0 tap:20>t5 stock tap:33>t0 tap:18>t2 stock drag:26>t3 drag:6>t0 drag:43>t2 tap:45>t5 tap:5>t4 tap:50>t6 tap:18>t0 tap:9>t6 tap:5>t3 drag:26>f2 stock drag:5>t4 tap:5>t3 drag:38>t2 tap:26>t3 tap:26>f2 tap:5>t4 tap:0>f3 tap:26>t4 tap:18>t5 tap:26>t4 tap:21>t2 tap:18>t5 drag:26>f2 drag:18>t0 tap:50>t1 tap:35>t4 stock tap:40>f1 drag:18>t5 tap:5>t3 tap:50>t2 stray:23 stray:40 tap:35>t0 tap:26>t3 tap:26>f2 stock tap:26>t3 tap:35>t4 tap:50>t1 tap:18>t4 tap:26>f2 stray:17 tap:1>f3 tap:50>t2 tap:40>t3 tap:40>f1 drag:5>t2 tap:5>t3 tap:50>t1 drag:18>t5 drag:5>t1 tap:5>t3 tap:18>t4 tap:1>t3 tap:5>t1 drag:1>f3 stock drag:18>t5 stock stock drag:1>t1 tap:50>t2 stray:30 tap:1>f3 tap:5>t3 drag:18>t4 tap:2>f3 tap:5>t2 tap:35>t0 tap:50>t1 tap:5>t3 tap:40>t3 tap:35>t4 tap:5>t1 stock drag:16>t4 tap:35>t0 drag:2>t0 tap:2>t3 tap:20>t1 stock stock stock drag:11>t5 tap:23>t5 tap:14>t3 stock stock stock stray:48 tap:39>f0 stock tap:39>t3 stock stray:11 stray:15 drag:39>f0 tap:21>t5 tap:47>t4 drag:6>t4 stock tap:39>t3 tap:39>f0 stray:51 tap:38>t1 stock tap:20>t5 tap:39>t3 tap:39>f0 tap:20>t4 tap:20>t5 tap:39>t3 tap:20>t4 drag:20>t5 tap:39>f0 tap:39>t3 tap:20>t4 drag:39>f0 stock tap:20>t5 tap:39>t3 tap:39>f0 tap:20>t4 stray:22 tap:39>t3 stock tap:46>t1 tap:39>f0 drag:20>t5 tap:20>t4 drag:20>t5 stray:34 drag:39>t3 tap:39>f0 tap:20>t4 tap:20>t5 drag:39>t3 tap:39>f0 drag:39>t3 stock stock drag:20>t4 tap:39>f0 drag:20>t5 tap:13>f1 tap:39>t3 tap:39>f0 tap:20>t4 drag:13>t2 drag:20>t5 drag:39>t3 drag:20>t4 tap:20>t5 tap:20>t4 tap:20>t5 drag:13>f0 stray:41 tap:13>t2 tap:20>t4 stray:51 tap:20>t5 stock tap:13>f0 tap:13>t2 stock stock drag:39>f0 tap:20>t4 drag:13>f1 drag:14>f1 tap:20>t5 drag:20>t4 drag:14>t3 tap:39>t3 tap:13>t2 tap:39>f0 tap:39>t3 stray:28 tap:39>f0 stock stray:14 drag:13>f1 tap:20>t5 tap:19>t1 tap:13>t2 tap:20>t4 drag:39>t3 tap:13>f0 stock tap:39>f1 tap:39>t3 stray:16 tap:20>t5 tap:13>t2 tap:13>f0 tap:39>f1 tap:39>t3 tap:20>t4 tap:20>t5 drag:13>t2 tap:13>f0 drag:20>t4 tap:13>t2 tap:20>t5 stock drag:39>f0 tap:39>t3 stray:31 tap:13>f0 tap:20>t4 tap:39>f1 tap:13>t2 tap:13>f0 stock drag:14>f0 stray:26 tap:20>t5 tap:20>t4 tap:20>t5 tap:14>t3 tap:20>t4 tap:13>t2 drag:20>t5 drag:20>t4 stock tap:39>t3 tap:13>f0 tap:20>t5 tap:39>f1 tap:39>t3 tap:20>t4 tap:20>t5 tap:13>t2 stock tap:39>f0 tap:20>t4 drag:39>t3 stock tap:13>f0 tap:39>f1 tap:39>t3 tap:13>t2 tap:13>f0 tap:20>t5 drag:39>f1 tap:20>t4 tap:13>t2 drag:20>t5 tap:13>f0 drag:20>t4 tap:14>f0 tap:20>t5 tap:14>t3 tap:39>t3 stray:8 tap:39>f1 tap:39>t3 drag:39>f1 drag:13>t2 tap:20>t4 stock tap:20>t5 drag:39>t3 drag:39>f0 drag:20>t4 drag:13>f1 drag:13>t2 tap:20>t5 drag:28>t2 stock tap:20>t4 stock stock stock stray:8 stray:21 drag:44>t0 tap:44>t3 tap:44>t0 drag:44>t3 tap:39>f0 tap:44>t0 tap:44>t3 tap:44>t0 tap:44>t3 tap:44>t0 tap:44>t3 stock tap:25>t2 tap:24>t0 tap:12>t3 stray:38 tap:25>t0 tap:51>t0 tap:38>t0 tap:38>t0 tap:25>t0 tap:38>t0 tap:25>t0 tap:38>t0 tap:38>t0 drag:51>t0 tap:25>t0 stray:51 tap:51>t0 tap:38>t0 tap:38>t0 drag:38>t0 drag:25>t0 drag:25>t0 drag:51>t0 tap:38>t0 drag:51>t0 stray:24 tap:38>t0 stray:9 tap:25>t0 tap:51>t2 drag:51>f3 dead-end tap:51>f3 dead-end drag:51>f3 dead-end tap:51>f3 dead-end drag:25>t0 drag:24>t2 tap:38>t4 tap:38>f2 dead-end tap:25>t0 tap:24>t3 drag:37>t3 drag:37>t3 drag:25>t0 drag:25>t0 tap:25>t0 tap:25>t0 drag:25>t0 stray:11 tap:51>t0 tap:25>t2 tap:51>t0 tap:51>t0 tap:51>t0 tap:38>t0 tap:51>t0 tap:51>t0 tap:25>t0 tap:51>t0 tap:25>t0 tap:38>t0 drag:25>t0 tap:38>t0 tap:25>t0 stray:25 tap:38>t0 drag:38>t0 stray:37 tap:51>t0 tap:38>t2 tap:37>t3 drag:38>t0 tap:38>t0 tap:51>t0 drag:51>t0 tap:25>t0 tap:51>t0 tap:25>t0 drag:38>t0 drag:38>t0 tap:51>t0 drag:38>t0 drag:51>t0 tap:38>t0 tap:51>t0 drag:25>t0 tap:51>t0 tap:38>t0 tap:51>t0 tap:51>t0 drag:51>t0 drag:38>t0 tap:38>t0 drag:51>t0 tap:25>t0 drag:38>t0 drag:38>t0 tap:51>t0 tap:51>t0 tap:51>t0 tap:51>t0 drag:25>t0 tap:25>t0 tap:51>t0 stray:25 tap:51>t0 drag:38>t0 tap:25>t0 drag:51>t0 drag:51>t0 tap:25>t0 drag:51>t0 drag:51>t0 tap:38>t0 drag:51>t0 drag:51>t0 tap:25>t0 tap:25>t0 tap:51>t0 drag:25>t0 tap:38>t0 tap:25>t0 drag:51>t0 drag:38>t0 tap:25>t0 tap:51>t0 tap:38>t0 tap:38>t0 stray:50 tap:51>t0 tap:38>t2 tap:25>t0 drag:51>t0 tap:51>t0 tap:25>t0 tap:25>t0 stray:38 tap:38>t0 tap:25>t0 drag:38>t0 tap:25>t0 tap:38>t0 stray:38 tap:25>t0 drag:51>t0 drag:38>t0 tap:25>t0 tap:38>t0 stray:24 tap:51>t0 tap:38>t2 tap:38>f2 dead-end drag:37>t3 drag:37>f2 drag:25>t0 tap:51>t0 drag:38>t0 drag:51>t0 tap:38>t0 tap:25>t0 tap:38>t0 tap:38>t0 drag:38>t0 stray:37 tap:51>t0 tap:38>t2 tap:37>t3 drag:38>t0 tap:25>t0 drag:25>t0 tap:25>t0 tap:51>t0 tap:25>t0 tap:25>t0 stray:38 tap:25>t0 tap:38>t0 drag:38>t0 tap:38>t0 drag:38>t0 tap:25>t0 drag:51>t0 drag:38>t0 tap:38>t0 tap:38>t0 tap:38>t0 tap:25>t0 drag:25>t0 drag:38>t0 tap:25>t0 tap:38>t0 tap:51>t0 drag:51>t0 drag:38>t0 tap:25>t0 drag:38>t0 tap:51>t0 drag:38>t0 drag:38>t0 tap:38>t0 tap:51>t0 tap:25>t0 tap:38>t0 drag:25>t0 tap:51>t0 drag:25>t0 drag:25>t0 tap:25>t0 tap:51>t0 tap:51>t0 tap:51>t0 tap:51>t0 tap:25>t0 drag:38>t0 tap:38>t0 stray:51 drag:25>t0 tap:38>t0 tap:51>t0 tap:51>t0 drag:51>t0 tap:25>t0 tap:38>t0 drag:25>t0 drag:51>t0 tap:25>t0 tap:38>t0 drag:38>t0 tap:51>t0 drag:25>t0 drag:25>t0 drag:25>t0 drag:51>t0 tap:38>t0 drag:51>t0 tap:51>t0 stray:51 tap:25>t0 stray:10 tap:51>t0 drag:25>t2 drag:24>t3 drag:38>t0 tap:51>t0 tap:25>t0 tap:38>t0 tap:38>t0 tap:25>t0 tap:25>t0 stray:24 drag:25>t0 tap:24>t3 drag:24>t3 drag:51>t0 tap:25>t0 tap:25>t0 drag:38>t0 tap:25>t0 drag:51>t0 tap:38>t0 tap:25>t0 tap:38>t0 stray:37 tap:38>t0 tap:38>f2 dead-end tap:38>f2 dead-end tap:51>t2 stray:25 tap:50>t4 tap:25>f1 dead-end tap:38>t0 tap:37>t3 drag:11>t0 tap:12>f0 stray:21 drag:13>f0 drag:13>t2 tap:13>f0 tap:13>t2 drag:13>f0 drag:13>t2 stock stock drag:13>f0 tap:1>t5 tap:26>t5 tap:19>t0 tap:26>f0 drag:16>t1 stock tap:16>t6 tap:16>t1 stray:26 tap:26>f0 tap:26>t5 tap:26>f0 drag:16>t6 tap:26>t5 tap:16>t1 tap:36>t3 drag:26>f0 stray:14 tap:10>t2 tap:26>t5 tap:16>t6 drag:16>t1 stray:32 tap:16>t6 drag:16>t1 drag:26>f0 drag:16>t6 tap:16>t1 tap:15>t4 tap:16>t6", "seed": 31, - "trace": "de246486cf439ed4a95df10d0177091b94ef2f54647e6024dd381b65f5f352abceafc7866b7522931705e3a222d9bd6867214e53c865c4f1818b7567865cfca0896e03bc07af356eeba1d0d4519ff1139992b5f8de8320fadb95c6e6a1d88c99869cd3b6a48b1025c75048782a5a53f2ee69d922452c2f4b6a6e01df4f572eac0ff52b4b47830bdac26121dc7d9c22f5355238285ab7433d3f0b720b3399c34bacfcae06277cd3b38cdc2fb5985f6d8e134360f6c4f88e8bd7e53518cf95e78d6e46e90822b7623c9319d782627062cde01f6793c34426d627d53284201521b62197acf36be1656dc7b7cb07923fe57a711387773dbd720a8c9c212d599ae8f0242f9a2257609997354725b8fc09a2e61ed3fc406d1cc6cf4e047a66e9250e34d49af5ac5891c581b2c98693f0390501949c1e8989608a641270d21303ff44855b3c3c4c1e8809a6eecfbdeae9ea6b3942826f63af216387f0fa15cdcd7cb9c4b61b9e7bb92a824ccfd07c30902e42dc6ba10c89bf5d2de1c669b9e4cc28220695c3e167cc8052a50f2bf9dad2e6a90910a2e055d08824acfe80ca387209339276dfc05ca44038ca079fffe07d41ad21d749be6cdd2444003f5345309a5fa0050e760be916319fbf50b3fd3309657bcdd510e235225813b8a52c4246c74cd1e98ebf9d7fc69cfc297820134a587b45b5911e79d428a837b094ad6d2f7d54aa25448d09ff39a42048bc2f60c3f9497869ca3db4c66c20b094696a51a4d793f9630d81638a2f470c5ad6d5245047cca67568e0c7efd8f2431ceb2b2408858194cc3224f6540a72e0ae3a79e116f4e05d32f65339505d7c9d0039955119ac3b52fe753cf5c372c3917cf4103250dd8f7a7cc7f967f378287c0045528fdbf2f2ff5ae2e555ba6d8177d8c325e34966d5a80611b15bdbde6cbb1ce0d5b53311f0a0712716f65e6c1aebafeffc6e3efee727ac4db183c7d4e25968d99b2bfd6e1d170fdc79e5eacea25bd9c5fc73e8e6d8fbd5765f3050d4e89336db02d7947149eb7c5a4cfc76acfb458c10a2b4a909ff5dd385235b9b1d15e559d41b2423ca35c140d8866f01492a29a53524ca21240854baece700432cb4effaa576db2a70b99968c1952295bdc288a784d7414787a75913cc6551f5a37136aa747bc9a1eedbf3a8066bffa0568adddee5832e14b450111f2bc42f55bd26a144ec6b670f862463f7641aca3c346e0730cf19da591aef39d318192e5a80e53d0ccd00a806fa29fe999c9576c9a73dd1fe48df92dca9c68192fc2196cfd14d2738d1dfc4d47511cbfc1803a4f256575729b2b1b977f9048e1cf375303fba604a8d602a9fc339326a4e17a5e4981a9d69e638881690dfd2cab7f87a67821d09c5221b2654d883f4b3a4b4f2725a1bf52c636c30d34dfc40fa42748137a18533a98be62f561f5d72eb0835ad4911a16de341a960da1a2321bce21aa38632e0a8b1c2bf1073654f6ba45b6d6cd024f3c3c68ff076a9f7462bc48a5acd6eb5d80fd68f0a4beef7bfab39bffcc0c0477d1a3954452d0fcbf17347ccbba827be611b5b6ba53772debd82fca89d999e167a25f0526ca728ad4f6de5194fc64eac452c18aa669a1af67d2b99967088a94ad119ab1630756be4fd16db9477860ca38b55c2d5d1652d092cc827df0a081c93f714c06925ab770b32545ed27c7a4a707b19c06cf76ad24e485c42e3496979958c6561762c233b0d862772ac7720810eb7cd3a6b68dcf84bad9fabc3875481d7a3f6e0782472a8be757465b10488751244758b81454a047ac24150d09abd5d468a5abda41e3d67c56ca6bcf2b6f0af9d4dfb1cd477057db182e94a3dbf03b09d65e21ddd472eb7523da515320a40fa80037275f1f3c1a469e7a6229dfce75cabc8a44330caefd8e08b6781d4aa3f37d5addf9ff8409c9e20a42e6d0366d9e6943f187e9769d5a4192aecc0f982b8a050e9f2a206141e9ad8ceb6753a57a172ee53cd3b3d593f2a0bc96f25ba87db87068d261181f95cc381a9140e5387fefcd2805f493fb4264d8a53ded2525e9d6d280e60ebe5e1113a2ddde550859983c7aa75453e65d17c16d682416cd2f5c5f17ebfd3b58d9939a91e930471f2b9d89cfba05b71c42b8d523585f94a79d25e83ad879b855ebd9561c78a1b972af4ae574535b7c0a05faad90c33072648a0d91e62758bdc721aeb0c657f4eb426d5c21ec900ae9fcacf74c3d6a1fe2fe5034a37550ed753bc8c8e80d2b1cf00fb44f99536983f113e3f9143b407668d76889b44dff3eca54ecc415067921d9f0e1a3f3be2a2b7f673385098e7a290b809e38a8589bfd838b0923768e79be40778f5316253195bd746d22b1904fff669424b61aef72576009339de3b42e81a4afd02f248d2f479ad6df08eff8ee18196c082abc0cbc2d17004fcc016abe4d6d1a1581a2265db2dd2c7e3b39a2788b415512ce96eca52d2c2020839d437f4ae1ffce8026e527bced0554576c257f8329846781bf0011462dd68595041bcabcacb495880c3c32b7126d534243dd024e581f6e285906d767b9213398212f828df8d8be2b5bcedfb91667d988af8c34b6e978952103fc5ad83925deb5a9c42baf0491ffc6ebc772bc4551fbf1fe151bae05e9ffe189ead1db711909907792df695e600a3e9feaafaf836b70595c532bac346dfb6995d6091ba057b2652741009408c54f0b10fa3f3f1dc14ab5a37c271e4d9ed1dca7faca6b48a3150b381e80d95ff11315cc314daacad16f11ff5a6453e042228355e0f99913f591076ad4bac511d5287b61841169d9d2cd9e7dd3983143eac809e77abf520879f16514245e2700b2e452e83149d402155f8adcbc47d3f1df270aa5c7eab3de0c8ec878504de2bceeb632768292002e79f8105393cc0db0b0881e7c50983261dc8add613674e5951148cd8efbeea086bf74f067a4625c465f44c78b6e491268b33cedfdc89b2df9b56f2bf22448d8552fbd38dd2fd3a04ba40dc44719e58974f42e2390437029bc574d7a2e5909e68277ec4e8923ebb6e3883e4d693dfc84c8879adbc738478aa65e88567172271619d3a10b156c53187dcad501f90e3595f4000150bfb7d8d23a513ca0a0c4b6ce4e63ab3178e2e6c3fe28282966938ad13736b77c3b760562924b774b1be3361a861dba1b135357c118b04e49f2c003f2dd33e3ce73dcb2bd4e61366d14bbdb783e58bc6f0317c47d17d4ad2eb9ffe9759a607b0a98d608247c4a59afafb7579ed1640fe857fb7e317cbb82c816b7da64cb62eb12d511103155b7e3cd42d71e33b635e1893233f456801ccf22662d43dfbff3f319a5d26c6ef6808edac3448537e19dd9842d3e25551fdbd92c9a6122dedc31d0829fad02b7873c0e69f4a017b2678a587850f6c71e468dd23d046830c6348cb9d48239f080c419755bc257efc61717ec331cd9ea19a4eca1fbc5531691ccd68720707d679a6997624ed8c1f33a9f9889078571084ff08b08b59b6f4475798071c92f19b99bd4bd6318a382fb0bc7bda03bb26d35737467328f63af96a12aac82c464a6ba83dcd033825b5d27842ce00289fdbb01e8a1ae92f4c495f608f4ea1fc6a2ba1fb0336d309a141c11c46ccabf236603b8d824660b201a90a05bc19b052daad4da1a7335f9ef80618fd9805f3371a65aac97fb2bdc317baa7f2ef148f318ec701734b04272d15c381ee7927418401c1eecc0b70f576ebfbed2020f2198c77379b931070674b2d3c6fef55f67fcc90344059ea0711d12e73881e56372ff6318acd75e315ce39792274b25d7f6cd410738def8ac5c34b4e0e52c502077ad7e2a8a52cc68d9faa2feb36b3199dcf229ff300c750788068737fa48e26d3bea7e6ffc53751b514de6059afd9c2081c55a9502d619e84d168e02c9944726bf73b6eb849ce15966b80ce0da3ac4dca1bc89f120b53d5a8feaea392ecc847f9532128bba0cc68ebcaced0cae7bf7dfbf740e488a0c0146ad187be4a6e08b474134f4ee5deb82c25beeff1961a4fd3d707518f7782f6b6f15b461d4b2e7d421352a4b5a7e3a469ea3704bbe42ec77f971aba5b21e7536ba3a252d0e3d16e98344b50783e4a83d5bc33541e47bf47bef038ff3d38ae49e2f95858736076" + "trace": "de246486cf439ed4a95df10d0177091b94ef2f54647e6024dd381b65f5f352abceafc7866b7522931705e3a222d9bd6867214e53c865c4f1818b7567865cfca0896e03bc07af356eeba1d0d4519ff1139992b5f8de8320fadb95c6e6a1d88c99869cd3b6a48b1025c75048782a5a53f2ee69d922452c2f4b6a6e01df4f572eac0ff52b4b47830bdac26121dc7d9c22f5355238285ab7433d3f0b720b3399c34bacfcae06277cd3b38cdc2fb5985f6d8e134360f6c4f88e8bd7e53518cf95e78d6e46e90822b7623c9319d782627062cde01f6793c34426d627d53284201521b62197acf36be1656dc7b7cb07923fe57a711387773dbd720a8c9c212d599ae8f0242f9a2257609997354725b8fc09a2e61ed3fc406d1cc6cf4e047a66e9250e34d49af5ac5891c581b2c98693f0390501949c1e8989608a641270d21303ff44855b3c3c4c1e8809a6eecfbdeae9ea6b3942826f63af216387f0fa15cdcd7cb9c4b61b9e7bb92a824ccfd07c30902e42dc6ba10c89bf5d2de1c669b9e4cc28220695c3e167cc8052a50f2bf9dad2e6a90910a2e055d08824acfe80ca387209339276dfc05ca44038ca079fffe07d41ad21d749be6cdd2444003f5345309a5fa0050e760be916319fbf50b3fd3309657bcdd510e235225813b8a52c4246c74cd1e98ebf9d7fc69cfc297820134a587b45b5911e79d428a837b094ad6d2f7d54aa25448d09ff39a42048bc2f60c3f9497869ca3db4c66c20b094696a51a4d793f9630d81638a2f470c5ad6d5245047cca67568e0c7efd8f2431ceb2b2408858194cc3224f6540a72e0ae3a79e116f4e05d32f65339505d7c9d0039955119ac3b52fe753cf5c372c3917cf4103250dd8f7a7cc7f967f378287c0045528fdbf2f2ff5ae2e555ba6d8177d8c325e34966d5a80611b15bdbde6cbb1ce0d5b53311f0a0712716f65e6c1aebafeffc6e3efee727ac4db183c7d4e25968d99b2bfd6e1d170fdc79e5eacea25bd9c5fc73e8e6d8fbd5765f3050d4e89336db02d7947149eb7c5a4cfc76acfb458c10a2b4a909ff5dd385235b9b1d15e559d41b2423ca35c140d8866f01492a29a53524ca21240854baece700432cb4effaa576db2a70b99968c1952295bdc288a784d7414787a75913cc6551f5a37136aa747bc9a1eedbf3a8066bffa0568adddee5832e14b450111f2bc42f55bd26a144ec6b670f862463f7641aca3c346e0730cf19da591aef39d318192e5a80e53d0ccd00a806fa29fe999c9576c9a73dd1fe48df92dca9c68192fc2196cfd14d2738d1dfc4d47511cbfc1803a4f256575729b2b1b977f9048e1cf375303fba604a8d602a9fc339326a4e17a5e4981a9d69e638881690dfd2cab7f87a67821d09c5221b2654d883f4b3a4b4f2725a1bf52c636c30d34dfc40fa42748137a18533a98be62f561f5d72eb0835ad4911a16de341a960da1a2321bce21aa38632e0a8b1c2bf1073654f6ba45b6d6cd024f3c3c68ff076a9f7462bc48a5acd6eb5d80fd68f0a4beef7bfab39bffcc0c0477d1a3954452d0fcbf17347ccbba827be611b5b6ba53772debd82fca89d999e167a25f0526ca728ad4f6de5194fc64eac452c18aa669a1af67d2b99967088a94ad119ab1630756be4fd16db9477860ca38b55c2d5d1652d092cc827df0a081c93f714c06925ab770b32545ed27c7a4a707b19c06cf76ad24e485c42e3496979958c6561762c233b0d862772ac7720810eb7cd3a6b68dcf84bad9fabc3875481d7a3f6e0782472a8be757465b10488751244758b81454a047ac24150d09abd5d468a5abda41e3d67c56ca6bcf2b6f0af9d4dfb1cd477057db182e94a3dbf03b09d65e21ddd472eb7523da515320a40fa80037275f1f3c1a469e7a6229dfce75cabc8a44330caefd8e08b6781d4aa3f37d5addf9ff8409c9e20a42e6d0366d9e6943f187e9769d5a4192aecc0f982b8a050e9f2a206141e9ad8ceb6753a57a172ee53cd3b3d593f2a0bc96f25ba87db87068d261181f95cc381a9140e5387fefcd2805f493fb4264d8a53ded2525e9d6d280e60ebe5e1113a2ddde550859983c7aa75453e65d17c16d682416cd2f5c5f17ebfd3b58d9939a91e930471f2b9d89cfba05b71c42b8d523585f94a79d25e83ad879b855ebd9561c78a1b972af4ae574535b7c0a05faad90c33072648a0d91e62758bdc721aeb0c657f4eb426d5c21ec900ae9fcacf74c3d6a1fe2fe5034a37550ed753bc8c8e80d2b1cf00fb44f99536983f113e3f9143b407668d76889b44dff3eca54ecc415067921d9f0e1a3f3be2a2b7f673385098e7a290b809e38a8589bfd838b0923768e79be40778f5316253195bd746d22b1904fff669424b61aef72576009339de3b42e81a4afd02f248d2f479ad6df08eff8ee18196c082abc0cbc2d17004fcc016abe4d6d1a1581a2265db2dd2c7e3b39a2788b415512ce96eca52d2c2020839d437f4ae1ffce8026e527bced0554576c257f8329846781bf0011462dd68595041bcabcacb495880c3c32b7126d534243dd024e581f6e285906d767b9213398212f828df8d8be2b5bcedfb91667d988af8c34b6e978952103fc5ad83925deb5a9c42baf0491ffc6ebc772bc4551fbf1fe151bae05e9ffe189ead1db711909907792df695e600a3e9feaafaf836b70595c532bac346dfb6995d6091ba057b2652741009408c54f0b10fa3f3f1dc14ab5a37c271e4d9ed1dca7faca6b48a3150b381e80d95ff11315cc314daacad16f11ff5a6453e042228355e0f99913f591076ad4bac511d5287b61841169d9d2cd9e7dd3983143eac809e77abf520879f16514245e2700b2e452e83149d402155f8adcbc47d3f1df270aa5c7eab3de0c8ec878504de2bceeb632768292002e79f8105393cc0db0b0881e7c50983261dc8add613674e5951148cd8efbeea086bf74f067a4625c465f44c78b6e491268b33cedfdc89b2df9b56f2bf22448d8552fbd38dd2fd3a04ba40dc44719e58974f42e2390437029bc574d7a2e5909e68277ec4e8923ebb6e3883e4d693dfc84c8879adbc738478aa65e88567172271619d3a10b156c53187dcad501f90e3595f4000150bfb7d8d23a513ca0a0c4b6ce4e63ab3178e2e6c3fe28282966938ad13736b77c3b760562924b774b1be3361a861dba1b135357c118b04e49f2c003f2dd33e3ce73dcb2bd4e61366d14bbdb783e58bc6f0317c47d17d4ad2eb9ffe9759a607b0a98d608247c4a59afafb7579ed1640fe857fb7e317cbb82c816b7da64cb62eb12d511103155b7e3cd42d71e33b635e1893233f456801ccf22662d43dfbff3f319a5d26c6ef6808edac3448537e19dd9842d3e25551fdbd92c9a6122dedc31d0829fad02b7873c0e69f4a017b2678a587850f6c71e468dd23d046830c6348cb9d48239f080c419755bc257efc61717ec331cd9ea19a4eca1fbc5531691ccd68720707d679a6997624ed8c1f33a9f9889078571084ff08b08b59b6f4475798071c92f19b99bd4bd6318a382fb0bc7bda03bb26d35737467328f63af96a12aac82c464a6ba83dcd033825b5d27842ce00289fdbb01e8a1ae92f4c495f608f4ea1fc6a2ba1fb0336d309a141c11c46ccabf236603b8d824660b201a90a05bc19b052daad4da1a7335f9ef80618fd9805f3371a65aac97fb2bdc317baa7f2ef148f318ec701734b04272d15c381ee7927418401c1eecc0b70f576ebfbed2020f2198c77379b931070674b2d3c6fef55f67fcc90344059ea0711d12e73881e56372ff6318acd75e315ce39792274b25d7f6cd410738def8ac5c34b4e0e52c502077ad7e2a8a52cc68d9faa2feb36b3199dcf229ff300c750788068737fa48e26d3bea7e6ffc53751b514de6059afd9c2081c55a9502d619e84d168e02c99e1c43a897777f147240c4fe1252a852b7db87d3379a81a2376e2ddb6dfe6bd9481708ffb1659fbb841ff3fc2d53e2a6f0768d73fbbb209d8e5ba17a9f5ada9467a0a8beb9fc378d6cb95ea3674e6fc826bcf3d1fb8ec1d1aaeb534f30b47dcb6a55045da7971171bf99348af20212786d399897285e560cf5cc88efab644e689fb61b6630ac59ac27499c9fb90dceb1726f244302c0ce2862e9c33c01f1ba19e" } diff --git a/tests/fixtures/games_solitaire/spider.json b/tests/fixtures/games_solitaire/spider.json index 9894605e8..931c50b5c 100644 --- a/tests/fixtures/games_solitaire/spider.json +++ b/tests/fixtures/games_solitaire/spider.json @@ -108,7 +108,7 @@ "fact": "", "label": "shell menu", "moves": 0, - "sheet": "SpiderNew gameSettingsHow to playHistoryStatsAbout this game", + "sheet": "SpiderNew gameSettingsHow to playHistoryStatsAbout this game\u00a9 Zimi", "stat": "0:00", "state": "e95c585", "sub": "", @@ -135,5 +135,5 @@ "hseed": 43, "plays": "tap:358>c6 tap:92>c4 stray:41 stray:96 tap:255>c0 drag:43>c3 tap:255>c5 tap:255>c0 drag:91>c2 tap:355>c7 drag:255>c5 tap:301>c8 tap:412>c4 tap:301>c9 tap:301>c8 drag:406>c3 drag:100>c8 tap:356>c0 tap:42>c0 tap:255>c8 tap:406>c7 tap:91>c6 drag:301>c0 stray:300 tap:406>c3 tap:42>c7 tap:253>c8 tap:253>c0 stray:355 drag:39>c2 stray:198 tap:301>c3 tap:255>c4 tap:356>c5 stray:199 tap:406>c5 tap:91>c5 tap:42>c3 tap:44>c0 drag:39>c6 tap:253>c4 drag:39>c2 tap:406>c7 stock tap:310>c7 tap:403>c3 stock tap:250>c0 drag:354>c1 tap:45>c2 tap:252>c2 drag:50>c4 drag:308>c8 drag:354>c5 tap:354>c1 tap:309>c4 drag:45>c0 stock tap:50>c6 tap:304>c1 tap:308>c5 tap:308>c6 tap:252>c3 tap:304>c0 drag:205>c9 tap:45>c2 drag:355>c2 tap:250>c2 tap:45>c0 drag:254>c6 drag:414>c4 tap:149>c2 tap:411>c8 tap:411>c6 tap:252>c1 tap:250>c1 tap:411>c8 tap:304>c2 tap:304>c0 tap:201>c8 tap:50>c7 tap:355>c5 tap:50>c6 tap:355>c0 tap:355>c5 tap:308>c4 stock tap:154>c1 stock drag:360>c3 tap:247>c4 drag:150>c7 tap:150>c8 tap:99>c2 tap:150>c7 tap:150>c2 tap:409>c2 drag:99>c3 drag:361>c0 drag:47>c2 stray:403 drag:411>c6 drag:360>c3 tap:48>c0 tap:47>c8 tap:413>c1 tap:47>c0 tap:150>c0 tap:154>c2 tap:254>c2 tap:99>c8 tap:47>c2 drag:99>c0 drag:307>c8 tap:248>c9 drag:150>c6 tap:150>c2 tap:254>c6 drag:150>c0 drag:201>c4 drag:410>c2 tap:409>c6 drag:410>c8 tap:150>c2 drag:47>c4 tap:409>c4 drag:307>c2 stray:154 tap:201>c6 stray:404 drag:150>c0 tap:254>c4 tap:411>c8 tap:409>c1 tap:414>c2 stray:257 drag:409>c0 tap:307>c6 drag:410>c8 tap:414>c4 tap:47>c1 tap:362>c4 drag:303>c0 tap:409>c8 tap:47>c2 tap:99>c1 drag:410>c6 stray:299 tap:409>c1 tap:305>c6 tap:362>c7 tap:99>c7 tap:154>c4 tap:304>c2 tap:254>c8 tap:254>c2 tap:356>c0 drag:99>c4 tap:356>c4 tap:150>c8 drag:411>c7 stray:43 drag:154>c1 tap:306>c1 tap:362>c4 tap:154>c7 drag:93>c0 drag:307>c8 tap:308>c9 tap:308>c2 drag:154>c1 stray:408 tap:308>c9 tap:100>c2 tap:356>c1 tap:307>c6 tap:47>c2 tap:304>c4 tap:304>c2 drag:99>c9 stock drag:291>c2 stock drag:148>c4 drag:296>c7 drag:147>c4 drag:392>c9 tap:393>c4 tap:48>c7 tap:294>c3 stock stock drag:146>c2 drag:154>c3 drag:43>c7 tap:80>c9 stock stray:250 stray:353 tap:290>c6 tap:88>c5 dead-end drag:49>c5 tap:44>c4 tap:258>c0 tap:258>c8 tap:258>c0 stray:248 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 drag:258>c8 drag:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 stray:145 drag:258>c8 drag:258>c0 drag:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 stray:398 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 drag:258>c8 drag:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 tap:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 drag:258>c8 stray:51 tap:258>c0 tap:258>c8 drag:258>c0 stray:398 drag:258>c8 stray:394 tap:258>c0 tap:258>c8 tap:258>c0 drag:258>c8 stray:79 drag:258>c0 tap:258>c8 tap:258>c0 stray:83 drag:258>c8 drag:258>c0 stray:360 tap:258>c8 tap:258>c0 drag:258>c8 drag:258>c0 drag:258>c8 tap:258>c0 tap:258>c8 drag:258>c0 tap:258>c8 drag:258>c0 stray:48 tap:258>c8 tap:258>c0 drag:258>c8 tap:258>c0 drag:403>c0", "seed": 33, - "trace": "c736db11db2f74f51e20cf5990e6c50546d772ba456752ee9cffe2a1bf0c6523f51af2003d3be5d7f7dd0cc1bb25eed8bc5dd51dc2955b6b293f4faf506cc6f279ae66de5c27d2ef62424c73bd6409c9ff718b8aaa51df6a12104e6bd6cf33389cc745ad35f87d74bd103f783cab2a02235cc447e14efeab63fa0fb8cf5edc6f2e2c4d1999628e602f01a9ea00fba19b3b8c6d126f46d314b72a8382e911dd34782ef176d52e584ccab9f4661067f7959d803fdf2b73762ab3ae0dc3cae33df1395392310706a36e37758277a7d1f32d5c65dbfb60db43935174452de10736cb48d93cd6689f1d7dac51234d9e4681e300f9fdff038928da70964c37659d735b3df8abd3c735c6fadfeeac5a4b71f4cea550441163e32e46e037b26f6ae91256b0dbec9f14ead58040ced76d48721722500d54991b295e4c5f29ba40a6a95e79e9d8e257ce8406ae2ca02dec583fb9b16fe609730c624d0a6321634ead39b281c11caf3c8fa54a22fe4e6328644838e7a8bd5447e14ac75bc4f08ade7e7f6c3ce30d9199e3eb3eb0129ff653a5d092c1c84921f37ff71191e811ca218662546880333e1309e1fa6ebef375e24471184fbe508d618fb311e106ddf59c40a2cefd11107a5511ca1ac86407e4fc0be9d3bd676e0f7c98b0f6ada8a3658bdb581945eba724e4690c1eb4debeba623de89a09ff8d8be3ba4be3eb5a1437c37663c5b6cab5e4fd052b0cf3803d9ab5dab94c6f532f3ceb0144da8c04c8c4801d446d25d8d8c5bf9770e61fea0366c03ac7374202bfa86abed86fce519f1a5d986fffd1f5b4489c7158469c82c4eaeeebc37a3d5dd39ccf58d7f0fc7010c494a54b3101b2ddaa979ee74038f761ad1bdb4b0eb2710b98cae88b695237118fa9df7e51f88c1e5b57fe10e49282520907df26c24d43cdde9a5cb8a10f9d945d40b4979454369fc07db2c3cb07c290916652d9b996cce40dc7609de8f1605cf3dbe1b1df0dd461ddf6100c2706d314741d6b347517b46b3bda2367ab040d198652d25e83a775e72b0df38fed5e31eac0924fb127b1752dc61a1de9ae53a4d5fbca5186c8f7196015b79e4496f859c2bc76db65084f68aed39efe8c2273d8cb02f96ff60cccfe40e5ee22e2d69c1c130acf32fbb9b4b592fccbe80f8372b09a42a84a82121caf9635b4db3c0da680885f368c7a28a25476ebf1828ee1702b9a7f9318bfe4bda3ba6740e7fe504d221dacdfea47ab7d890b14eb17b0ba766717babbed89169ecfd6ecd0c57ad83cf784284a689911058b782335c566165cd40b4f5bb2a731a2033a42e59bec3ce18a405f80b8181f750a7b559dab60c2d2deecb007f36e3c606a481523b21a934cfb0fa6e2c025f31024eadba510737d6c2bf373afb4579e7eded48c7142982cbc6a736c350ae9b181e18a9c5b88eed9ef581ca81ecad677e0bad148cbf5a8973b98aeeb66051064e7d3f1bebc5e3f30a5e846990270d871d78017314e9afed87055c1a32046af1ad3d3b0a8fc1d4bf58765571fd7f40e5ff585c59b0db2e024701a25869195f0884fd9a58278235486aca38b3cb5a5bd646b0028caadd52b51595e29bff4d4c2ddf96865213ea52f94128a3f9d0b696233da634dd591f5c96fdea9d22247c9366b9f9c5b2f8018de7883435e5e8a95e6cbc9cd4d0cd42e4373661d005120d95b0c6d826becea993320600c561526af465175e0643f1945668d8e034ddc3f37c1bfe6bedd655503044023f0a8dd7f74f89caa2b97a13d1e85611ac9f0924bd7bf227191201925a43dd93671074a5fcfa3a031faeed81c03406232573a97944d68c2e341563cf1bb6f8b105c702cf0a39d6249ae05676172377ac30e7adf1e6c5da9378f8573098aa5cb71ee03fa601a8e3fbe0b6e6faccb986e411adddd6bbfcd3624f7afaf788a9f719c" + "trace": "c736db11db2f74f51e20cf5990e6c50546d772ba456752ee9cffe2a1bf0c6523f51af2003d3be5d7f7dd0cc1bb25eed8bc5dd51dc2955b6b293f4faf506cc6f279ae66de5c27d2ef62424c73bd6409c9ff718b8aaa51df6a12104e6bd6cf33389cc745ad35f87d74bd103f783cab2a02235cc447e14efeab63fa0fb8cf5edc6f2e2c4d1999628e602f01a9ea00fba19b3b8c6d126f46d314b72a8382e911dd34782ef176d52e584ccab9f4661067f7959d803fdf2b73762ab3ae0dc3cae33df1395392310706a36e37758277a7d1f32d5c65dbfb60db43935174452de10736cb48d93cd6689f1d7dac51234d9e4681e300f9fdff038928da70964c37659d735b3df8abd3c735c6fadfeeac5a4b71f4cea550441163e32e46e037b26f6ae91256b0dbec9f14ead58040ced76d48721722500d54991b295e4c5f29ba40a6a95e79e9d8e257ce8406ae2ca02dec583fb9b16fe609730c624d0a6321634ead39b281c11caf3c8fa54a22fe4e6328644838e7a8bd5447e14ac75bc4f08ade7e7f6c3ce30d9199e3eb3eb0129ff653a5d092c1c84921f37ff71191e811ca218662546880333e1309e1fa6ebef375e24471184fbe508d618fb311e106ddf59c40a2cefd11107a5511ca1ac86407e4fc0be9d3bd676e0f7c98b0f6ada8a3658bdb581945eba724e4690c1eb4debeba623de89a09ff8d8be3ba4be3eb5a1437c37663c5b6cab5e4fd052b0cf3803d9ab5dab94c6f532f3ceb0144da8c04c8c4801d446d25d8d8c5bf9770e61fea0366c03ac7374202bfa86abed86fce519f1a5d986fffd1f5b4489c7158469c82c4eaeeebc37a3d5dd39ccf58d7f0fc7010c494a54b3101b2ddaa979ee74038f761ad1bdb4b0eb2710b98cae88b695237118fa9df7e51f88c1e5b57fe10e49282520907df26c24d43cdde9a5cb8a10f9d945d40b4979454369fc07db2c3cb07c290916652d9b996cce40dc7609de8f1605cf3dbe1b1df0dd461ddf6100c2706d314741d6b347517b46b3bda2367ab040d198652d25e83a775e72b0df38fed5e31eac0924fb127b1752dc61a1de9ae53a4d5fbca5186c8f7196015b79e4496f859c2bc76db65084f68aed39efe8c2273d8cb02f96ff60cccfe40e5ee22e2d69c1c130acf32fbb9b4b592fccbe80f8372b09a42a84a82121caf9635b4db3c0da680885f368c7a28a25476ebf1828ee1702b9a7f9318bfe4bda3ba6740e7fe504d221dacdfea47ab7d890b14eb17b0ba766717babbed89169ecfd6ecd0c57ad83cf784284a689911058b782335c566165cd40b4f5bb2a731a2033a42e59bec3ce18a405f80b8181f750a7b559dab60c2d2deecb007f36e3c606a481523b21a934cfb0fa6e2c025f31024eadba510737d6c2bf373afb4579e7eded48c7142982cbc6a736c350ae9b181e18a9c5b88eed9ef581ca81ecad677e0bad148cbf5a8973b98aeeb66051064e7d3f1bebc5e3f30a5e846990270d871d78017314e9afed87055c1a32046af1ad3d3b0a8fc1d4bf58765571fd7f40e5ff585c59b0db2e024701a25869195f0884fd9a58278235486aca38b3cb5a5bd646b0028caadd52b51595e29bff4d4c2ddf96865213ea52f94128a3f9d0b696233da634dd591f5c96fdea9d22247c9366b9f9c5b2f8018de7883435e5e8a95e6cbc9cd4d0cd42e4373661d005120d95b0c6d826becea993320600c561526af465175e0643f1945668d8e034ddc3f37c1bfe6bedd655503044023f0a8dd7f74f89caa2b97a13d1e85611ac9f0924bd7bf227191201925a43dd93671074a5fcfa3a031faeed81c03406232573a97944d68c2e341563cf1bb6f8b105c702cf0a39d6249ae05676172377ac30e7adf1e6c5da9378f8573098aa5cb71ee03fa601a8e3fbe0b6e6faccb986e411adddd6b8556306ac9303052c1c5a046" } diff --git a/tests/fixtures/games_solitaire/tripeaks.json b/tests/fixtures/games_solitaire/tripeaks.json index aeeb9c059..17e0f1298 100644 --- a/tests/fixtures/games_solitaire/tripeaks.json +++ b/tests/fixtures/games_solitaire/tripeaks.json @@ -134,7 +134,7 @@ "fact": "", "label": "shell new game", "moves": 0, - "sheet": "TriPeaksNew gameSettingsHow to playHistoryStatsAbout this game", + "sheet": "TriPeaksNew gameSettingsHow to playHistoryStatsAbout this game\u00a9 Zimi", "stat": "0:00", "state": "89683c36", "sub": "", @@ -148,5 +148,5 @@ "hseed": 47, "plays": "tap:37>waste tap:51>waste tap:0>waste tap:25>waste stray:20 stock drag:34>waste tap:35>waste tap:23>waste tap:24>waste stock stock tap:6>waste tap:5>waste tap:45>waste tap:46>waste stock stray:17 stock drag:27>waste drag:28>waste tap:16>waste tap:41>waste drag:1>waste stock stock stock drag:42>waste stock stray:22 stock drag:20>waste stock tap:22>waste stock stock stray:18 stray:2 tap:50>waste stock drag:29>waste tap:15>waste stock stock tap:17>waste stray:17 drag:18>waste tap:19>waste stock stock stock stock stray:9 stock stock stock stock tap:15>waste tap:16>waste tap:30>waste stock stock tap:1>waste stock stock stray:25 tap:39>waste", "seed": 36, - "trace": "adf82fa0849aa15f3094467f4902fa8f719e1666cf6dab6314280ef3250d2599f658639dc8d4e47b67f93fe4da831d08de112904c0f393bc48928c5fed85e7ecf7fbe7113439b107fcb249f54a3171c3699898189aeeb9955bb8acf100ccfd548c9301531061c94fa856884c5e7cfaa8b3984215b06967cabad7a7f3be16dcadceac16e8e59dc97c48830cf06bae71032fd436f170d059d075d93e518475d216a45856b4fbd2a9ecf342544afa521e8f8c216fd7ed2678341f410a242ed9512df04824a39b6c4595357e18e8305e03e8d841a56e7b3aa5c39b487fedfc9db7f320387d68c13a344e52ff7e5f77572470cf9d84e7fd32f481bde027c3d2e95aacc17eb3208ce5efb1fc66348f7d9ff6fc5589f3b3e9dd60ff965889acd56c32452822e0630d8c63d35347702c651829a85b1bf6d9386a103f596c5e24aefc0adeddbe79c6e47dc251e66da989" + "trace": "adf82fa0849aa15f3094467f4902fa8f719e1666cf6dab6314280ef3250d2599f658639dc8d4e47b67f93fe4da831d08de112904c0f393bc48928c5fed85e7ecf7fbe7113439b107fcb249f54a3171c3699898189aeeb9955bb8acf100ccfd548c9301531061c94fa856884c5e7cfaa8b3984215b06967cabad7a7f3be16dcadceac16e8e59dc97c48830cf06bae71032fd436f170d059d075d93e518475d216a45856b4fbd2a9ecf342544afa521e8f8c216fd7ed2678341f410a242ed9512df04824a39b6c4595357e18e8305e03e8d841a56e7b3aa5c39b487fedfc9db7f320387d68c13a344e52ff7e5f77572470cf9d84e7fd32f481bde027c3d2e95aacc17eb3208ce5efb1fc66348f7d9ff6fc5589f3b3e9dd60ff965889acd56c32452822e0630d8c63d35347702c651829a85b1bf6d9386a103f596c5e24aefc0adeddbe79c610562d4701d96037" } diff --git a/tests/fixtures/games_tricks/hearts_watch.json b/tests/fixtures/games_tricks/hearts_watch.json index 962510f92..0e44d4b8f 100644 --- a/tests/fixtures/games_tricks/hearts_watch.json +++ b/tests/fixtures/games_tricks/hearts_watch.json @@ -131,5 +131,5 @@ "hseed": 12, "plays": "2:1 3:3 0:4 1:2 0:41 1:42 2:40 3:51 3:15 0:22 1:21 2:19 0:44 1:46 2:43 3:26 1:16 2:14 3:20 0:13 0:45 1:49 2:48 3:38 1:5 2:0 3:10 0:7 2:17 3:33 0:24 1:23 0:29 1:36 2:34 3:32 1:18 2:39 3:31 0:37 1:11 2:30 3:9 0:12 0:47 1:50 2:28 3:8 1:25 2:27 3:6 0:35", "seed": 18, - "trace": "a5b5b6ef29cb502e48cf9d90c43d81923b51b031d7d8746ba39e88f5896d3073612ea2c180b290a0351001bdecf6e030138076f5c72de82b5734e62f6c86a2e99783dc8dd7a90d4d9a607117cc282f9821a6834826f7f9bdedc9f57944103693260c10efc234a20c096a5fbde5f814a49c8d4b433c75bbb0c79c7b00bedecdaf78e5706ecbf15f6a0b19d5a3f9ee675781da33a68272c7271cde62c63464158df9eef36dd76a8f7b6fcffb098ae0595438e35ceb1310c25b2bff6c32ae23af996b93f9f4b264705521bcd80ba9ea94cd2009e6394a2bb5da6c639f393117f7b56fb1508aab8eb1575ca1d40eda29ca87689a4fb3f69dee99dd0e3c5be40f90ef5c2a5c8e371b40330e1c093cc411a5fa19551a6b7d864a0ee3734825471d762590708c685a2cbfe3ae3fb22f2dcbe2a5e61a184b0750a758701b59d1" + "trace": "a5b5b6efdd777590111d4a1adf4f0270131ac53b4bb057215a7195ffc392a3ddecf7070fdf478902041e7bab66719a9a0ba2fd8b19812d29375567bdc45dc497bdbed69301f57cb32b8eedc55bcdc876d6f488da72c656670b9ef5f78d8aed21981d280d946a8742a4ef8f5fd3b590d25b722fe599f910d6372b5402c03098a92a94ab0cb1f136e8c8232b4d2a35afc947a95758ccc66e49981d1450b289fb9b92920ab7af0c61c57d8e5b1b6492950ab813be41d95cd379a34694e00989a0c73082dc56be430fbb2f2ff8312cb8d8b77a443e8327dc87c82ed8d0274cfe846b62a4a408cbda6999b2fa24780f8082bd99149f9d48a8decb14fb5f618846131553b66ce8ba38e2e57a663b825722a98c4c6280a110fa7c3cb7ba10bf6fba66271ebaeb5631a24719db5d7aa5aa5e79efc5d1f69d4a03167af2e8f3a3" } diff --git a/tests/test_almanac_corners_browser.py b/tests/test_almanac_corners_browser.py new file mode 100644 index 000000000..0985c8310 --- /dev/null +++ b/tests/test_almanac_corners_browser.py @@ -0,0 +1,140 @@ +"""The Almanac page's corners on a phone, as the ZIM's readers meet them in ten languages. + +- the clock reads 18:32, not 32:18, in Hebrew and Arabic, and a calendar's Latin month name is its own run in a right-to-left row +- no card label in the head is cut off, at 360 px, in any of the ten languages, and a row's tiles share a height and a value line + +Run: pytest tests/test_almanac_corners_browser.py -v +""" + +import os +import sys +import threading + +import pytest + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.dirname(HERE)) +sys.path.insert(0, HERE) + +LANGS = "ar de en es fr he hi pt ru zh".split() +NEW_YORK = '{"lat":40.71,"lon":-74.0,"name":"New York"}' +SYDNEY = '{"lat":-33.87,"lon":151.2,"name":"Sydney, Australia"}' +LONG = '{"lat":-77.8,"lon":166.7,"name":"McMurdo Station Antarctica Research Base"}' + + +@pytest.fixture(scope="module") +def base(tmp_path_factory): + import zimi.renderer as renderer + + if not renderer.browser_available(): + pytest.skip("playwright + chromium are not usable here") + from http.server import ThreadingHTTPServer + + import zimi.server as srv + from zimi.http import ZimHandler + + env = pytest.MonkeyPatch() + env.setenv("ZIMI_TORRENT", "0") + env.setenv("ZIMI_OFFLINE", "1") + root = tmp_path_factory.mktemp("alm_corners") + (root / "zims").mkdir() + (root / "data").mkdir() + saved = (srv.ZIM_DIR, srv.ZIMI_DATA_DIR) + srv.ZIM_DIR, srv.ZIMI_DATA_DIR = str(root / "zims"), str(root / "data") + srv.load_cache(force=True) + httpd = ThreadingHTTPServer(("127.0.0.1", 0), ZimHandler) + threading.Thread(target=httpd.serve_forever, daemon=True).start() + yield "http://127.0.0.1:%d" % httpd.server_address[1] + httpd.shutdown() + srv.ZIM_DIR, srv.ZIMI_DATA_DIR = saved + env.undo() + + +def _open(pw, base, lang="en", width=390, place=NEW_YORK, init=""): + br = pw.chromium.launch() + ctx = br.new_context( + viewport={"width": width, "height": 844}, + device_scale_factor=2, + has_touch=True, + is_mobile=True, + service_workers="block", + locale=lang, + ) + ctx.add_init_script( + "try{localStorage.setItem('zimi_almanac_place',%r);localStorage.setItem('zimi_ui_lang',%r)}catch(e){};%s" + % (place, lang, init) + ) + pg = ctx.new_page() + errs = [] + pg.on("pageerror", lambda e: errs.append(str(e)[:300])) + pg.goto(base + "/#almanac") + pg.wait_for_selector("#almanac-head-time .ep", timeout=60000) + # Settled: the panels are built and the head's tiles are drawn (a state, not a fixed wait). + pg.wait_for_function("() => window._almPanelsReady && document.querySelectorAll('#almanac-head .alm-card').length >= 5", timeout=60000) + return br, pg, errs + + +@pytest.mark.parametrize("lang", ["he", "ar"]) +def test_the_clock_reads_left_to_right_in_a_right_to_left_language(base, lang): + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + br, pg, errs = _open(pw, base, lang) + x = pg.evaluate( + "() => { const h = document.querySelector('#almanac-head-time .ep[data-p=\"hour\"]')," + " m = document.querySelector('#almanac-head-time .ep[data-p=\"min\"]');" + " return [h.getBoundingClientRect().left, m.getBoundingClientRect().left]; }" + ) + assert x[0] < x[1], "hours must stand left of minutes: %r" % x + br.close() + assert not errs, errs + + +def test_a_latin_month_is_its_own_run_in_a_hebrew_calendar_row(base): + # A fixed day inside Aban (the Persian month Oct 23 to Nov 21): the row's Latin month name is there whatever today is. + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + br, pg, _ = _open(pw, base, "he") + rows = pg.evaluate( + "() => { const d = document.createElement('div'); d.innerHTML = _almRenderCrossRef(_gregorianToJDN(2026, 11, 10));" + " return [...d.querySelectorAll('.alm-crossref-date')].map(e => e.innerHTML); }" + ) + latin = [r for r in rows if "Aban" in r] + assert latin and 'Aban' in latin[0], rows + # A row with no Latin in it is left alone. + assert any("bdi" not in r for r in rows), rows + br.close() + + +@pytest.mark.parametrize("lang", LANGS) +def test_no_head_label_is_cut_off_at_360(base, lang): + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + br, pg, _ = _open(pw, base, lang, width=360) + cut = pg.evaluate( + "() => [...document.querySelectorAll('#almanac-head .alm-card-lbl')].filter(e => e.offsetParent)" + ".map(e => { const s = getComputedStyle(e); return [e.innerText, e.scrollWidth - e.clientWidth, e.scrollHeight - e.clientHeight, s.textOverflow, s.whiteSpace]; })" + ".filter(r => r[1] > 0 || r[2] > 0 || r[3] === 'ellipsis' || r[4] === 'nowrap')" + ) + assert not cut, cut + # Every tile is as tall as the others in its row, and its value sits on the same line as theirs. + rows = pg.evaluate( + "() => { const by = {}; [...document.querySelectorAll('#almanac-head .alm-card')].filter(e => e.offsetParent).forEach(e => {" + " const r = e.getBoundingClientRect(), v = e.querySelector('.alm-card-val').getBoundingClientRect();" + " (by[Math.round(r.top)] = by[Math.round(r.top)] || []).push([Math.round(r.height), Math.round(v.top)]); }); return Object.values(by); }" + ) + assert sum(len(r) for r in rows) >= 5, rows + for row in rows: + assert max(h for h, _ in row) - min(h for h, _ in row) <= 1, rows + assert max(v for _, v in row) - min(v for _, v in row) <= 1, rows + # A row whose labels all fit on one line has no empty line above them. + gaps = pg.evaluate( + "() => { const by = {}; [...document.querySelectorAll('#almanac-head .alm-card')].filter(e => e.offsetParent).forEach(e => {" + " const l = e.querySelector('.alm-card-lbl'); if (!l) return; const rg = document.createRange(); rg.selectNodeContents(l);" + " const t = rg.getBoundingClientRect(), c = e.getBoundingClientRect();" + " (by[Math.round(c.top)] = by[Math.round(c.top)] || []).push(Math.round(t.top - c.top)); }); return Object.values(by).map(r => Math.min(...r)); }" + ) + assert gaps and max(gaps) <= 13, gaps + br.close() diff --git a/tests/test_almanac_landmarks_bodies_browser.py b/tests/test_almanac_landmarks_bodies_browser.py index ee0f5119f..3ae050e5d 100644 --- a/tests/test_almanac_landmarks_bodies_browser.py +++ b/tests/test_almanac_landmarks_bodies_browser.py @@ -152,8 +152,10 @@ def test_landmarks_on_every_body_and_a_flight_to_a_rover(served): ] ) pg.evaluate("_aePreset('mars')") + # Pluto's place comes from the probes' table, fetched once the view is among the planets (not on the Earth + # it opened on): the frame after the table is in places it. pg.wait_for_function( - "() => { _ae.dirty = true; _aeKick(); return !_ae.fly && !!_ae.gl.planets.mars.pos; }", + "() => { _ae.dirty = true; _aeKick(); return !_ae.fly && !!_ae.gl.planets.mars.pos && !!_ae.gl.planets.pluto.pos; }", timeout=60_000, polling=200, ) diff --git a/tests/test_almanac_layout_browser.py b/tests/test_almanac_layout_browser.py index 7149030f8..13b3390c9 100644 --- a/tests/test_almanac_layout_browser.py +++ b/tests/test_almanac_layout_browser.py @@ -160,13 +160,20 @@ def test_the_moons_numbers_and_the_skys_are_one_grid_with_the_caption_over_the_s # Two rows of three, one idea each: the Moon (how lit, when it rises or sets, when it is next full), then the # Sun (when it rises, when it sets, how long the day is). assert got["reading"] == [ - "alm-hc-illum-card", "alm-sf-moon", "alm-hc-nextfull-card", "alm-sf-sunrise", "alm-sf-sunset", "alm-sf-daylight", + "alm-hc-illum-card", + "alm-sf-moon", + "alm-hc-nextfull-card", + "alm-sf-sunrise", + "alm-sf-sunset", + "alm-sf-daylight", ], got["reading"] assert got["rows"] == [3, 3], got["rows"] assert got["cap"] and got["facts"] == 4, got # None says how lit the Moon is twice (the hero's tile does), and none is the Sun's time by the clock. assert "lit" not in got["factText"].lower(), got["factText"] - assert not any("solar" in l or "dark" in l for l in got["factLabels"]), got["factLabels"] + assert not any("solar" in l or "dark" in l for l in got["factLabels"]), got[ + "factLabels" + ] # Six tiles, every one a label and one value: no third line, and no tile taller than another in its row. assert got["tiles"] == 6 and got["subs"] == 0, got assert got["rowsEven"], got @@ -207,7 +214,9 @@ def test_the_moon_is_its_picture_and_the_solar_system_has_no_flown_view( ctx, pg, errors = _page(browser, served) try: # The 3D view is made ready when the Moon is touched, not behind the page (a page only looked at never loads it). - pg.evaluate("() => new Promise(r => { const t = setInterval(() => { if (typeof _almMoonPrepare === 'function') { clearInterval(t); _almMoonPrepare(); r(); } }, 50); })") + pg.evaluate( + "() => new Promise(r => { const t = setInterval(() => { if (typeof _almMoonPrepare === 'function') { clearInterval(t); _almMoonPrepare(); r(); } }, 50); })" + ) pg.wait_for_function( "() => typeof _aeReady === 'function' && _aeReady()", timeout=240_000, @@ -280,30 +289,54 @@ def test_opening_the_almanac_holds_still(browser, served, dark): filled them), the canvas waited at its default size, and the sky's caption was empty until its first tick, each moving the sky when it came.""" ctx = browser.new_context( - viewport=VIEW, device_scale_factor=2, has_touch=True, is_mobile=True, service_workers="block", - timezone_id="America/Los_Angeles", color_scheme="dark" if dark else "light", + viewport=VIEW, + device_scale_factor=2, + has_touch=True, + is_mobile=True, + service_workers="block", + timezone_id="America/Los_Angeles", + color_scheme="dark" if dark else "light", + ) + ctx.add_init_script( + "localStorage.setItem('zimi_almanac_place', %s);" + % json.dumps(json.dumps(PLACE)) ) - ctx.add_init_script("localStorage.setItem('zimi_almanac_place', %s);" % json.dumps(json.dumps(PLACE))) pg = ctx.new_page() errors = [] pg.on("pageerror", lambda e: errors.append(str(e))) try: pg.goto(served + "/", wait_until="load") - pg.wait_for_function("() => typeof openAlmanac === 'function'", timeout=60_000, polling=POLL_MS) + pg.wait_for_function( + "() => typeof openAlmanac === 'function'", timeout=60_000, polling=POLL_MS + ) for entry in ("cold", "again"): pg.evaluate(_ENTRY_SAMPLER) pg.evaluate("openAlmanac()") - pg.wait_for_function("() => window.__entry.length && performance.now() > 0", timeout=60_000, polling=POLL_MS) + pg.wait_for_function( + "() => window.__entry.length && performance.now() > 0", + timeout=60_000, + polling=POLL_MS, + ) pg.wait_for_function( # settled: the sky's own state has written its tiles and caption "() => typeof _skyState !== 'undefined' && _skyState && _skyState.eph && _skyState.factsAt", - timeout=60_000, polling=POLL_MS, + timeout=60_000, + polling=POLL_MS, ) pg.wait_for_timeout(600) frames = pg.evaluate("window.__entry") final = frames[-1] assert final["cards"] == 6, (entry, final) - moved = [f for f in frames if (f["cards"], f["top"], f["h"]) != (final["cards"], final["top"], final["h"])] - assert not moved, (entry, "first frame %s, settled %s" % (frames[0], final), moved[:5]) + moved = [ + f + for f in frames + if (f["cards"], f["top"], f["h"]) + != (final["cards"], final["top"], final["h"]) + ] + assert not moved, ( + entry, + "first frame %s, settled %s" % (frames[0], final), + moved[:5], + ) pg.evaluate("closeAlmanac()") pg.wait_for_timeout(300) assert not errors, errors diff --git a/tests/test_almanac_pan_browser.py b/tests/test_almanac_pan_browser.py index 20cc40b91..7b624b4f6 100644 --- a/tests/test_almanac_pan_browser.py +++ b/tests/test_almanac_pan_browser.py @@ -8,9 +8,11 @@ Run: pytest tests/test_almanac_pan_browser.py -v """ +import json import os import sys import threading +from datetime import datetime import pytest @@ -29,6 +31,25 @@ MAX_ROLL_STEP_DEG = 30 +def _station_over_the_equator_ms(): + """The instant the shipped elements' station next crosses the equator northward after their epoch, in ms. + + The view is pinned there (its clock stopped): the station's place was the wall clock's, and within a few degrees + of its highest latitude (51.6) the zenith sweep below runs past the celestial pole, where roll is measured from a + north that turns over (180) though the picture does not. The tests use the shipped snapshot (ZIMI_OFFLINE and an + empty data directory: no cache, no fetch), so this instant and the station's place at it are the same every run. + """ + with open(os.path.join(ROOT, "zimi", "assets", "satellites-snapshot.json")) as f: + iss = json.load(f)["iss"] + epoch = datetime.fromisoformat(iss["EPOCH"].replace("Z", "+00:00")).timestamp() * 1000 + # Argument of latitude ~ perigee + mean anomaly (eccentricity ~0.0007); the node is a revolution's fraction away. + to_node = (-(iss["ARG_OF_PERICENTER"] + iss["MEAN_ANOMALY"])) % 360 / 360 + return round(epoch + to_node / iss["MEAN_MOTION"] * 86_400_000) + + +PIN_MS = _station_over_the_equator_ms() + + @pytest.fixture(scope="module") def served(tmp_path_factory): import zimi.renderer as renderer @@ -85,6 +106,15 @@ def station(served): timeout=READY_MS, polling=200, ) + # One instant for the whole module, the clock stopped: the station is over the equator. + pg.evaluate("(ms) => { _almFocus = new Date(ms); _almClockSetRate(0); }", PIN_MS) + pg.wait_for_function( + "(ms) => { _ae.dirty = true; _aeKick(); return !_ae.fly && _aeDisplayMs() === ms && !!_ae.issPos" + " && Math.abs(_aeAzElOf(_aeNorm(_ae.issPos)).el) < 0.1; }", + arg=PIN_MS, + timeout=60_000, + polling=200, + ) yield pg, ctx.new_cdp_session(pg), errors finally: br.close() @@ -143,6 +173,11 @@ def test_two_fingers_slide_the_view_across_the_station_and_pinch_zooms(station): touches(cdp, "touchStart", [(135, 400), (255, 400)]) touches(cdp, "touchMove", [(115, 415), (275, 415)]) touches(cdp, "touchMove", [(155, 430), (315, 430)]) + # Moves reach the page aligned to its frames: the state is read once the last one has, not while it is on its way. + pg.wait_for_function( + "() => !!_ae.pinch && _ae.pinch.span === 160 && _ae.pinch.mx === 235 && _ae.pinch.my === 430", + timeout=10_000, + ) state = pg.evaluate( "() => ({ pan: _ae.pan, dist: _ae.dist, az: _ae.az, el: _ae.el_ })" ) @@ -151,12 +186,46 @@ def test_two_fingers_slide_the_view_across_the_station_and_pinch_zooms(station): assert state["pan"] and state["pan"]["t"] == "iss" assert state["dist"] < dist0 # fingers spread: closer # The station follows the fingers: right and down. - assert after[0] - before[0] > 10 and after[1] - before[1] > 10, (before, after) + # (The pinch ends at the station's nearest, where a slide of the fingers moves it least on screen: 9 px down at 30 px of finger.) + assert after[0] - before[0] > 5 and after[1] - before[1] > 5, (before, after) reach = pg.evaluate("() => AE_TARGETS.iss.surface") assert sum(x * x for x in state["pan"]["v"]) ** 0.5 <= reach * 1.0001 assert not errors, errors +# One pinch spreading from 120 px to 160 px, its pointer events in a given order: each finger's move is its own event, +# and the order a frame's touches arrive in is the browser's (it was a coin toss in CI). +PINCH_IN_ORDER = """(order) => { + var cv = _aeById('ae-canvas'), ev = function (type, id, x, y) { + cv.dispatchEvent(new PointerEvent(type, { pointerId: id, clientX: x, clientY: y, pointerType: 'touch', isPrimary: id === 901, bubbles: true })); + }; + cv.setPointerCapture = function () {}; // synthetic pointers have nothing to capture + _ae.fly = null; _ae.pan = null; _ae.dist = AE_TARGETS.iss.min * 1.2; + var dist0 = _ae.dist; + ev('pointerdown', 901, 135, 400); ev('pointerdown', 902, 255, 400); + order.forEach(function (m) { ev('pointermove', m[0], m[1], m[2]); }); + var out = { dist0: dist0, dist: _ae.dist, min: AE_TARGETS.iss.min }; + ev('pointercancel', 901, 0, 0); ev('pointercancel', 902, 0, 0); + delete cv.setPointerCapture; + return out; +}""" + + +def test_a_pinch_ends_where_the_fingers_do_whatever_order_their_moves_arrive_in(station): + """Spread from 120 to 160 px near the station's nearest: the view ends closer (at that nearest), in either order. + + Each move zoomed by its own ratio, clamped at the nearest; one finger's step past it was clamped, the other's step + back out was not, and the same spread ended 4.5% farther than it began (CI's 1.928e-05 < 1.846e-05). + """ + pg, _, errors = station + first = [[901, 115, 415], [902, 275, 415]] + for second in ([[901, 155, 430], [902, 315, 430]], [[902, 315, 430], [901, 155, 430]]): + got = pg.evaluate(PINCH_IN_ORDER, first + second) + assert got["dist"] < got["dist0"], (second, got) + assert got["dist"] == pytest.approx(got["min"], rel=1e-9), (second, got) + assert not errors, errors + + def test_the_slide_is_bounded_and_one_finger_still_turns(station): pg, cdp, _ = station pg.evaluate( diff --git a/tests/test_almanac_tables_browser.py b/tests/test_almanac_tables_browser.py index eb222f426..28893dc62 100644 --- a/tests/test_almanac_tables_browser.py +++ b/tests/test_almanac_tables_browser.py @@ -242,6 +242,28 @@ def test_the_orrery_is_never_wider_than_its_box(page): assert _no_side_scroll(page) +def test_a_print_leaves_the_page_its_width(page): + """The page laid out on paper and back (the view's Print): it never scrolls sideways after. + + Paper sets the scroller's padding aside (almanac-reference.css), and Chromium can keep that 0 once the print is + over: the tiles' and chips' -16px edges and an orrery sized meanwhile ran 16px past the screen (406 of 390), a + failure that came and went with whether the page was laid out while in print.""" + _open(page, "sunmoon") + for _ in range(3): + page.evaluate("_tbPrintOn()") + page.emulate_media(media="print") + page.evaluate("getComputedStyle(document.getElementById('almanac-content')).paddingLeft") + page.emulate_media(media="screen") + page.evaluate("_tbPrintOff()") + page.evaluate("_tbClose()") + page.wait_for_function("() => !document.getElementById('alm-ref')") + page.evaluate("_initOrrery()") # a panel drawn now is drawn at the page's width + assert _no_side_scroll(page) + edge = page.evaluate("() => document.querySelector('.alm-tile').getBoundingClientRect().left") + assert edge >= 16, edge # the first tile still starts at the page's gutter + assert not page.errors, page.errors + + @pytest.mark.parametrize("id_", TABLES) def test_every_table_opens_and_its_window_changes_its_rows(page, id_): _open(page, id_) diff --git a/tests/test_almanac_zim_languages_browser.py b/tests/test_almanac_zim_languages_browser.py new file mode 100644 index 000000000..f42eeed44 --- /dev/null +++ b/tests/test_almanac_zim_languages_browser.py @@ -0,0 +1,100 @@ +"""The Almanac's ZIM speaks Zimi's ten languages: the browser's language picks the strings (English under any that is missing), + and dir follow (Arabic and Hebrew right to left), dates and numbers go through the language, and no raw key shows. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_almanac_zim_languages_browser.py -v +""" + +import functools +import json +import http.server +import os +import sys +import tempfile +import threading + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import browser # noqa: E402,F401 + +from zimi import almanacstage # noqa: E402 + +RAW_KEY = r"\b(alm|gr|ae|env|save)_[a-z0-9_]{3,}\b" +# locale -> (html lang, dir, what the first tile's label must not be: the English one) +CASES = [ + ("de-DE", "de", ""), + ("he-IL", "he", "rtl"), + ("zh-CN", "zh", ""), + ("ar-EG", "ar", "rtl"), + ("en-US", "en", ""), + ("sv-SE", "en", ""), +] +ENGLISH_FIRST_TILE = "ILLUMINATED" + + +@pytest.fixture(scope="module") +def served(): + tmp = tempfile.mkdtemp(prefix="zimi-alm-lang-") + almanacstage.stage(tmp, community=True) + handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=tmp) + httpd = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler) + threading.Thread(target=httpd.serve_forever, daemon=True).start() + yield {"base": "http://127.0.0.1:%d" % httpd.server_address[1], "dir": tmp} + httpd.shutdown() + + +def test_all_ten_languages_are_packed_in(served): + for lang in almanacstage.LANGUAGES: + assert ( + os.path.getsize(os.path.join(served["dir"], "i18n", lang + ".json")) > 1000 + ), lang + assert len(almanacstage.LANGUAGES) == 10 + + +@pytest.mark.parametrize("locale,lang,direction", CASES) +def test_the_page_follows_the_browsers_language( + browser, served, locale, lang, direction +): + ctx = browser.new_context( + viewport={"width": 390, "height": 844}, locale=locale, service_workers="block" + ) + page = ctx.new_page() + errors = [] + page.on("pageerror", lambda e: errors.append(str(e))) + page.goto(served["base"] + "/index.html") + page.wait_for_selector("#almanac-head .alm-card", timeout=120_000) + page.wait_for_timeout(1500) + assert page.evaluate("document.documentElement.lang") == lang + assert page.evaluate("document.documentElement.dir") == direction + first = page.evaluate( + "document.querySelector('#almanac-head .alm-card .alm-card-lbl').innerText.trim()" + ) + assert (first.upper() == ENGLISH_FIRST_TILE) == (lang == "en"), first + # It is that language's own word for it (the strings file of the language the page picked), not another language's. + with open(os.path.join(served["dir"], "i18n", lang + ".json"), encoding="utf-8") as f: + assert first.lower() == json.load(f)["alm_illuminated"].lower(), (lang, first) + view = "document.getElementById('almanac-view').innerText" + assert ( + page.evaluate("(re => (%s.match(new RegExp(re, 'g')) || []))" % view, RAW_KEY) + == [] + ) + assert ( + page.evaluate( + "document.documentElement.scrollWidth - document.documentElement.clientWidth" + ) + <= 0 + ) + assert not errors, errors + ctx.close() + + +def test_a_language_in_the_address_wins(browser, served): + ctx = browser.new_context( + viewport={"width": 390, "height": 844}, locale="en-US", service_workers="block" + ) + page = ctx.new_page() + page.goto(served["base"] + "/index.html#lang=de") + page.wait_for_selector("#almanac-head .alm-card", timeout=120_000) + assert page.evaluate("document.documentElement.lang") == "de" + ctx.close() diff --git a/tests/test_app_top_hairline_live.py b/tests/test_app_top_hairline_live.py index e1c843b63..332c4d2be 100644 --- a/tests/test_app_top_hairline_live.py +++ b/tests/test_app_top_hairline_live.py @@ -78,7 +78,12 @@ def test_nothing_light_shows_above_an_app(served, scheme): # Over an app the header steps aside only when held (a video playing # sideways), and stays while focus is in it, so nothing is focused. pg.evaluate("() => { document.activeElement.blur(); _chromeImmersive(true); }") - pg.wait_for_timeout(400) # past the slide + # Past the slide: it is a CSS transition, so a loaded machine takes longer than any fixed wait. The + # wait ends when the header is above the screen or the slide has finished, and the assertion below is + # then about where it came to rest. + pg.wait_for_function( + "() => !document.getAnimations().some(a => a.transitionProperty)", timeout=15000 + ) s = pg.evaluate(STATE) assert s["away"], s assert s["topbarBottom"] <= -1, s diff --git a/tests/test_apps_live_prefs_browser.py b/tests/test_apps_live_prefs_browser.py index c6e9dec79..900522b1a 100644 --- a/tests/test_apps_live_prefs_browser.py +++ b/tests/test_apps_live_prefs_browser.py @@ -133,6 +133,9 @@ def test_pdf_reader_follows_dark_pages(served, browser_ctx): def test_manage_maps_pane_redraws_when_the_source_changes(served, browser_ctx): pg = browser_ctx.new_page() pg.goto(served + "/", wait_until="load") + # The boot paints "Loading library" over #output before it asks for the list (init); Manage opened before that + # point is wiped with it, and drillCategory finds no #catalog-results. Open it once the list is in. + pg.wait_for_function("() => zimsCache !== null", timeout=WAIT_MS) pg.evaluate("enterManage()") pg.wait_for_function( "() => typeof drillCategory === 'function' && !!document.getElementById('catalog-results')", diff --git a/tests/test_behaviors_npm_failure.py b/tests/test_behaviors_npm_failure.py new file mode 100644 index 000000000..eb471761c --- /dev/null +++ b/tests/test_behaviors_npm_failure.py @@ -0,0 +1,25 @@ +"""Looking for an operator's npm install must not break the bundled behaviors: npm timing out or failing to start falls back.""" + +import os +import subprocess +import sys + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from zimi import behaviors # noqa: E402 + + +def test_npm_that_times_out_or_will_not_start_falls_back_to_the_bundled_file( + monkeypatch, +): + monkeypatch.delenv(behaviors._ENV_VAR, raising=False) + monkeypatch.setattr(behaviors, "_NODE_ROOTS", ()) + monkeypatch.setattr(behaviors.shutil, "which", lambda name: "/usr/bin/npm") + monkeypatch.setattr(behaviors.os.path, "isfile", lambda p: p == behaviors._BUNDLED) + for failure in (subprocess.TimeoutExpired("npm", 20), OSError("no such program")): + + def run(*a, **k): + raise failure + + monkeypatch.setattr("zimi.subproc.run", run) + assert behaviors.behaviors_path() == behaviors._BUNDLED diff --git a/tests/test_build_child_priority.py b/tests/test_build_child_priority.py index bd3305de3..9dbc15395 100644 --- a/tests/test_build_child_priority.py +++ b/tests/test_build_child_priority.py @@ -12,6 +12,8 @@ def test_the_build_child_lowers_its_own_priority_first(monkeypatch, tmp_path): asked = [] + # The child's main sets the process's data dir to its argument, as a child process would: put the old one back afterwards. + monkeypatch.setattr(search._srv, "ZIMI_DATA_DIR", search._srv.ZIMI_DATA_DIR) monkeypatch.setattr(search.os, "nice", lambda n: asked.append(n) or n, raising=False) # Windows has no os.nice with pytest.raises(SystemExit): search._build_index_child_main("no-such-kind", str(tmp_path), "x", str(tmp_path / "x.zim")) diff --git a/tests/test_create_folder_tree.py b/tests/test_create_folder_tree.py index d362d458c..7c211bd80 100644 --- a/tests/test_create_folder_tree.py +++ b/tests/test_create_folder_tree.py @@ -299,6 +299,8 @@ def _mixed_folder(at): (at / "zimi.txt").write_text( "Title: Family Archive\nDescription: Everything from the attic\nLanguage: fra\n" "Creator: The Lees\nPublisher: Lee Press\nTags: family; photos\nIcon: icon.png\n" + "LongDescription: Everything from the attic, in boxes: letters, a book, photos and a home movie.\n" + "License: CC-BY-4.0\nSource: https://example.org/attic\n" , encoding="utf-8") (at / "icon.png").write_bytes(_png("red")) (at / "letter.txt").write_text("Dear all,\n\n the attic is full.", encoding="utf-8") @@ -343,6 +345,8 @@ def meta(k): assert meta("Description") == "Everything from the attic" assert meta("Language") == "fra" and meta("Creator") == "The Lees" assert meta("Publisher") == "Lee Press" + assert meta("LongDescription").startswith("Everything from the attic, in boxes") + assert meta("License") == "CC-BY-4.0" and meta("Source") == "https://example.org/attic" assert "family" in meta("Tags").split(";") and "photos" in meta("Tags").split(";") assert info["unsupported"] == [ {"path": "budget.xlsx", "reason": "office"}, diff --git a/tests/test_deploy_relaunch_live.py b/tests/test_deploy_relaunch_live.py index c96037bbe..86c97726c 100644 --- a/tests/test_deploy_relaunch_live.py +++ b/tests/test_deploy_relaunch_live.py @@ -109,6 +109,27 @@ def slow_get(self): _forget_served_files(ZimHandler) +def _wait_for_the_almanac_kept_whole(page, server): + """Every file the worker keeps for the Almanac is in its cache, not just the first of them. + + The worker fetches them on its own after the page asks, and closing the page does not stop it. A file still on + its way when the test goes on is asked for after the held state begins, so it is held, and a worker with a + request in flight is not replaced by the browser until that request ends (Chromium): the new worker then sits + waiting for a reason that is the test's own. The device this test describes has the Almanac kept whole. + """ + # An async predicate is done when its promise settles, whatever it says, so the loop is in the page. + page.wait_for_function( + """async urls => { + for (;;) { + if ((await Promise.all(urls.map(u => caches.match(u)))).every(Boolean)) return true; + await new Promise(r => setTimeout(r, 100)); + } + }""", + arg=server.http._almanac_pack_urls(), + timeout=90000, + ) + + def _gen(page): return page.evaluate("() => window.__gen") @@ -128,10 +149,7 @@ def test_relaunch_after_a_deploy_runs_the_new_code(served): pg.wait_for_function("() => typeof _almanacOpen !== 'undefined' && _almanacOpen", timeout=30000) # The worker in charge, and the Almanac kept whole pg.wait_for_function("() => navigator.serviceWorker.controller", timeout=30000) - pg.wait_for_function( - "() => caches.keys().then(ks => Promise.all(ks.map(k => caches.open(k).then(c => c.keys())))).then(r => r.flat().some(q => /almanac-earth\\.js/.test(q.url)))", - timeout=60000, - ) + _wait_for_the_almanac_kept_whole(pg, server) assert _gen(pg) == 0 pg.close() @@ -141,6 +159,9 @@ def test_relaunch_after_a_deploy_runs_the_new_code(served): log = [] pg = ctx.new_page() pg.on("request", lambda r: log.append(r.url) if r.resource_type == "document" and r.frame.parent_frame is None else None) + console = [] + pg.on("console", lambda m: console.append("%s: %s" % (m.type, m.text[:160]))) + pg.on("requestfailed", lambda r: console.append("failed: %s %s" % (r.url[-60:], r.failure))) pg.goto(server.base + "/", wait_until="commit") t0 = time.time() gens = [] @@ -165,7 +186,7 @@ def test_relaunch_after_a_deploy_runs_the_new_code(served): br.close() # The new code runs on the first launch, with the Almanac's files still held, and its reload followed the new # worker taking charge, never the page's wait for one that does not come. - assert first == 1 and by != "timeout", (engine, gens, by, diag) + assert first == 1 and by != "timeout", (engine, gens[-3:], by, diag, console[-12:]) def _kept_almanac_on_device(ctx, server): @@ -173,10 +194,7 @@ def _kept_almanac_on_device(ctx, server): pg.goto(server.base + "/#almanac") pg.wait_for_function("() => typeof _almanacOpen !== 'undefined' && _almanacOpen", timeout=30000) pg.wait_for_function("() => navigator.serviceWorker.controller", timeout=30000) - pg.wait_for_function( - "() => caches.keys().then(ks => Promise.all(ks.map(k => caches.open(k).then(c => c.keys())))).then(r => r.flat().some(q => /almanac-earth\\.js/.test(q.url)))", - timeout=60000, - ) + _wait_for_the_almanac_kept_whole(pg, server) pg.close() diff --git a/tests/test_download_batch.py b/tests/test_download_batch.py index 364daea11..208e2e99c 100644 --- a/tests/test_download_batch.py +++ b/tests/test_download_batch.py @@ -15,6 +15,13 @@ import zimi.server as server # noqa: E402 +def _empty_the_queue(): + with library._download_lock: + library._active_downloads.clear() + library._download_queue.clear() + library._download_counter = 0 + + @pytest.fixture(autouse=True) def _reset(tmp_path, monkeypatch): monkeypatch.setattr(server, "ZIM_DIR", str(tmp_path)) @@ -27,10 +34,7 @@ def _reset(tmp_path, monkeypatch): "disk_usage", lambda p: SimpleNamespace(total=10**13, used=0, free=10**13), ) - with library._download_lock: - library._active_downloads.clear() - library._download_queue.clear() - library._download_counter = 0 + _empty_the_queue() # Skip auth gate monkeypatch.setattr(manage, "_check_manage_auth", lambda h: None) @@ -45,6 +49,9 @@ def start(self): monkeypatch.setattr(library.threading, "Thread", _FakeThread) monkeypatch.setattr(library, "_fetch_mirrors", lambda url: []) yield + # The queue is process-wide: what these tests queued would otherwise be written into the next test's + # downloads.json by any persist (resume_pending_downloads) that runs in the same worker. + _empty_the_queue() def _fake_handler(): diff --git a/tests/test_fieldguide.py b/tests/test_fieldguide.py index b9a77f0ec..76e2bf29a 100644 --- a/tests/test_fieldguide.py +++ b/tests/test_fieldguide.py @@ -1353,7 +1353,16 @@ def test_a_fresh_install_still_gets_the_words(served, monkeypatch): def test_a_signed_in_visitor_gets_the_library_with_the_words(served): - status, body = _get(served, "/fieldguide/situation?id=flood") + import time + + # The pages come from the library's ZIM list as the server holds it: right after another test of the module reloaded it + # (served_empty puts it back), the list may be a moment behind, so the answer is waited for, not read once. + end = time.time() + 20 + while True: + status, body = _get(served, "/fieldguide/situation?id=flood") + if (status == 200 and body["answers"]) or time.time() > end: + break + time.sleep(0.25) assert status == 200 and body["answers"], "the installed pages are listed" diff --git a/tests/test_games_axe.py b/tests/test_games_axe.py index 6bc60dcc1..fed2ace10 100644 --- a/tests/test_games_axe.py +++ b/tests/test_games_axe.py @@ -65,8 +65,9 @@ def scan(browser, served, path, width, theme, lang): page.goto("%s/%s#lang=%s" % (served, path, lang)) page.wait_for_load_state("load") quiet(page, 1200) # built: nothing changing, nothing animating (at most the 1.2 s this once waited) - page.mouse.click(width // 2, 420) - quiet(page, 500) + if path != "index.html": # the shelf's middle is a game's tile at desktop width: a tap there leaves the page + page.mouse.click(width // 2, 420) + quiet(page, 500) page.add_script_tag(content=AXE) return page.evaluate(RUN) finally: diff --git a/tests/test_games_bar_stack_browser.py b/tests/test_games_bar_stack_browser.py new file mode 100644 index 000000000..8b45f74a3 --- /dev/null +++ b/tests/test_games_bar_stack_browser.py @@ -0,0 +1,56 @@ +"""The game bar on a phone: a stat that would cut the title ("2048" as "2." beside "148 · Bestwert 148" at 390 px in +German) goes on a second line under the title; where it fits beside the title (English) the bar is as it was. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_games_bar_stack_browser.py -v +""" + +import os +import sys + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import browser, served # noqa: E402,F401 + +BAR = """() => { const bar = document.querySelector('.ar-bar'), h1 = bar.querySelector('h1'); + return { stack: bar.classList.contains('gs-bar-stack'), cut: h1.scrollWidth > h1.clientWidth + 0.5, + h: Math.round(bar.getBoundingClientRect().height), right: Math.round(bar.lastElementChild.getBoundingClientRect().right) }; }""" + + +@pytest.mark.parametrize( + "lang,stat,stacked", + [("de", "148 · Bestwert 148", True), ("en", "148 · Best 148", False)], +) +def test_2048_keeps_its_name_whole(browser, served, lang, stat, stacked): + ctx = browser.new_context(viewport={"width": 390, "height": 700}) + page = ctx.new_page() + page.goto("%s/2048.html#lang=%s&dir=ltr" % (served, lang)) + page.wait_for_selector(".gs-ready .ar-bar") + page.evaluate("s => { document.getElementById('tf-stat').textContent = s; }", stat) + page.wait_for_timeout(300) + got = page.evaluate(BAR) + assert not got["cut"], got + assert got["stack"] is stacked, got + assert got["h"] == 56, got # the bar keeps its height + assert got["right"] <= 390 - 16 + 1, got # Menu stays inside the gutter + ctx.close() + + +def test_snake_keeps_its_name_whole_when_pause_turns_to_resume(browser, served): + """A bar is laid out again when a button's words change, not only the stat's: Pause becoming Resume (wider) cut + "Snake" beside "Apples 0 · Best 0" at 390 px.""" + ctx = browser.new_context(viewport={"width": 390, "height": 844}) + page = ctx.new_page() + page.goto("%s/snake.html#lang=en&dir=ltr" % served) + page.wait_for_selector(".gs-sp-play") + page.click(".gs-sp-play") + page.wait_for_timeout(300) + page.click("#sn-pause") + page.wait_for_function( + "document.getElementById('sn-pause').textContent.trim() === 'Resume'" + ) + page.wait_for_timeout(200) + got = page.evaluate(BAR) + assert not got["cut"], got + assert got["h"] == 56 and got["right"] <= 390 - 16 + 1, got + ctx.close() diff --git a/tests/test_games_batch2_browser.py b/tests/test_games_batch2_browser.py index a975a6735..7dbf4d390 100644 --- a/tests/test_games_batch2_browser.py +++ b/tests/test_games_batch2_browser.py @@ -102,8 +102,10 @@ def test_hearts_game_over_sheet_names_the_winner_and_every_total(browser, served ZimiHearts.session.reset(st); }""") frames(page, 3) + # Lift, then play: a person taps the card both times. The lifted card stands over its slot, so the slot is no target for the + # second tap (the card's own picture would take it). for _ in range(2): - page.locator("[data-pile^='h']").first.click() + page.locator(".zc-card[data-id='0']").first.click() frames(page, 2) visible(page, ".ar-sheet-card h2", 8000) text = page.locator(".ar-sheet-card").inner_text() diff --git a/tests/test_games_bluff_kiwix_words_browser.py b/tests/test_games_bluff_kiwix_words_browser.py new file mode 100644 index 000000000..3e38855ba --- /dev/null +++ b/tests/test_games_bluff_kiwix_words_browser.py @@ -0,0 +1,128 @@ +"""Dictionary Bluff in kiwix-serve draws its words from the library's English Wiktionary: the deal never waits (built-in +words first, under 1.2 s), a burst in the idle time asks the server at most 12 times (title suggestions for a word stem, then +pages), and a later round takes a library word with its real definition. A random page of a real Wiktionary is seldom a +usable English word, so the old draw fell back to the built-in words every time. + +The kiwix-serve here is the page's own routes: its catalog, /suggest and the pages of a Wiktionary. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_games_bluff_kiwix_words_browser.py -v +""" + +import functools +import http.server +import json +import os +import re +import sys +import threading +import time + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import GAMES, browser # noqa: E402,F401 + +BOOK = "wiktionary_en_all_nopic_2026-02" +CATALOG = ( + 'Wiktionaryengwiktionary_en_all' + '9800000' + % BOOK +) +# English words of different stems, none of them built in, each with an English section and a meaning of its own. +WORDS = { + "garrulous": "Excessively talkative, especially about trivial things.", + "querulous": "Given to complaining; peevish, whining, fretful.", + "perfidious": "Of, relating to, or showing a deliberate breaking of trust; faithless, disloyal; treacherous.", + "lachrymal": "Of or pertaining to tears or the glands that produce them.", + "vacillatingly": "In a vacillating manner; uncertainly, waveringly.", +} + + +def page_html(word): + return ( + '

%s

English

Adjective

  1. %s
' + '

Latin

' % (word, WORDS[word]) + ) + + +@pytest.fixture(scope="module") +def kiwix_games(): + class H(http.server.SimpleHTTPRequestHandler): + def log_message(self, *a, **k): + pass + + def translate_path(self, path): + path = path.split("?")[0] + return ( + os.path.join(GAMES, path[len("/content/games/") :]) + if path.startswith("/content/games/") + else "/nonexistent" + ) + + srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H) + threading.Thread(target=srv.serve_forever, daemon=True).start() + yield "http://127.0.0.1:%d" % srv.server_address[1] + srv.shutdown() + + +def test_bluff_deals_at_once_and_takes_library_words_in_a_later_round( + browser, kiwix_games +): + ctx = browser.new_context(viewport={"width": 390, "height": 844}) + page = ctx.new_page() + asks = [] + + def route(r): + u = r.request.url + if "/catalog/v2/entries" in u: + return r.fulfill(body=CATALOG, content_type="application/atom+xml") + if "/suggest" in u: + asks.append(u) + # Suggestions as the real list gives them: other languages' words and a capitalised title among English ones. + rows = [ + {"value": w, "label": w, "kind": "path", "path": w} + for w in ["perspicacia", "perspicaz", "Garrulus"] + list(WORDS) + ] + return r.fulfill(body=json.dumps(rows), content_type="application/json") + m = re.search(r"/content/%s/(.+)$" % BOOK, u) + if m: + asks.append(u) + w = m.group(1) + return ( + r.fulfill(body=page_html(w), content_type="text/html") + if w in WORDS + else r.fulfill(status=404, body="") + ) + if re.search(r"/(random|health)", u): + asks.append(u) + return r.fulfill(status=404, body="") + return r.continue_() + + page.route( + re.compile( + r".*/(catalog/v2/entries|suggest|random|health|content/%s/).*" % BOOK + ), + route, + ) + t0 = time.time() + page.goto("%s/content/games/bluff.html" % kiwix_games) + page.wait_for_function( + "window.__bluff && __bluff.g && __bluff.g.words && __bluff.g.words.length === 3" + ) + assert ( + time.time() - t0 < 1.2 + 1.0 + ) # the deal does not wait for the library (a second of page load allowed) + assert page.evaluate("__bluff.dict") == BOOK + # Round two and three take library words as the burst of round one brings them. + page.wait_for_function("__bluff.g.words.slice(1).every(w => w.path)", timeout=15000) + later = page.evaluate("__bluff.g.words.slice(1)") + for w in later: + assert ( + w["word"] in WORDS + and w["real"].rstrip(".").lower() in WORDS[w["word"]].lower() + ), w + page.wait_for_timeout(1000) + library = [u for u in asks if "/suggest" in u or "/content/" in u] + assert len(library) <= 12, library # one burst: at most 12 asks of the Wiktionary + assert not any("/random" in u for u in asks), asks + ctx.close() diff --git a/tests/test_games_card_table_foot_browser.py b/tests/test_games_card_table_foot_browser.py new file mode 100644 index 000000000..82a24c5ce --- /dev/null +++ b/tests/test_games_card_table_foot_browser.py @@ -0,0 +1,30 @@ +"""A card table runs to the foot of the screen. On an iPhone the home indicator's strip (--safe-b, 34 px) was body padding, so +the page colour showed there: a white band under Blackjack. The felt fills it now, every card game alike. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_games_card_table_foot_browser.py -v +""" + +import os +import sys + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import browser, served # noqa: E402,F401 + +FOOT = """inset => { document.documentElement.style.setProperty('--safe-b', inset); + return new Promise(r => requestAnimationFrame(() => requestAnimationFrame(() => + r([20, 195, 370].map(x => document.elementFromPoint(x, innerHeight - 2).tagName.toLowerCase()))))); }""" + + +@pytest.mark.parametrize("game", ["blackjack", "solitaire", "hearts"]) +def test_the_felt_reaches_the_foot(browser, served, game): + ctx = browser.new_context(viewport={"width": 390, "height": 844}) + page = ctx.new_page() + page.goto("%s/%s.html" % (served, game)) + page.wait_for_selector(".gs-ready .zc-table") + page.wait_for_timeout(500) + for inset in ("0px", "34px"): + bottom = page.evaluate(FOOT, inset) + assert "body" not in bottom and "html" not in bottom, (inset, bottom) + ctx.close() diff --git a/tests/test_games_library_more.cjs b/tests/test_games_library_more.cjs index 8bcc57c6f..95fc965a5 100644 --- a/tests/test_games_library_more.cjs +++ b/tests/test_games_library_more.cjs @@ -35,6 +35,19 @@ const rng = seed => load(['librarykit.js']).GamesLib.rng(seed); check(cat[1].project === 'gutenberg' && cat[1].kind === 'zim' && Lib.pickByName(cat, 'gutenberg', 'en').name === 'gutenberg_en_all_2026-02', 'kit: Gutenberg is found by name, not as a wiki'); check(Lib.pickZim(cat, 'wikipedia', 'fr').zim.name === 'wikipedia_fr_all_maxi_2026-01', 'kit: the catalog works with pickZim'); check(Lib.pickByName(cat, 'wikivoyage', 'en') === null, 'kit: no such book gives null'); + // The real kiwix-serve (3.8.2): is the ZIM's Name, the book's address is its file's name, in the text/html link. + const real = Lib.parseCatalog('Wikipediaengwikipedia_en_all9' + + ''); + const hrefFirst = Lib.parseCatalog('Wikipediaengwikipedia_en_all9' + + ''); + check(hrefFirst.length === 1 && hrefFirst[0].name === 'wikipedia_en_all_nopic_2026-01', 'kit: the link\'s attributes may come in any order'); + // The word games read the biggest English Wiktionary, not the first listed (a real kiwix-serve listed Simple English first). + const twoWikt = [{ name: 'wiktionary_en-simple_all_nopic_2026-10', kind: 'wiki', project: 'wiktionary', language: 'en', article_count: 54668 }, + { name: 'wiktionary_fr_all_nopic_2026-01', kind: 'wiki', project: 'wiktionary', language: 'fr', article_count: 9000000 }, + { name: 'wiktionary_en_all_nopic_2026-02', kind: 'wiki', project: 'wiktionary', language: 'en', article_count: 9800000 }]; + check(Lib.englishWiktionary(twoWikt).name === 'wiktionary_en_all_nopic_2026-02' && Lib.englishWiktionary(twoWikt.slice(1, 2)) === null && Lib.englishWiktionary([]) === null, + 'kit: the word games take the biggest English Wiktionary, never another language\'s'); + check(real.length === 1 && real[0].name === 'wikipedia_en_all_nopic_2026-01' && real[0].project === 'wikipedia' && real[0].language === 'en', 'kit: a book is addressed by its kiwix-serve link, not its Name'); check(Lib.number('1,404,890,000') === 1404890000 && Lib.number('8,848.86 m (29,031.7 ft)') === 8848.86 && Lib.number('9.6 million') === 9600000 && Lib.number('17,098,246 (6,601,667)') === 17098246 && isNaN(Lib.number('n/a')), 'kit: a number as a table writes it'); check(Lib.number('−5') === -5 && Lib.number('1.4 billion') === 1.4e9 && Lib.number('6,650(7,088)') === 6650, 'kit: a minus sign, billions, a figure with another in brackets'); @@ -247,6 +260,7 @@ const rng = seed => load(['librarykit.js']).GamesLib.rng(seed); const longClue = E.clueFrom('A very long definition that goes on and on past the eighty character limit for a crossword clue indeed.', 'house'); check(longClue.length <= 82 && longClue.endsWith('…'), 'crossword: a long definition is cut to a line'); check(Lib.firstDefinition('
  1. A fruit that is red.
    • An example sentence.
  2. Second.
') === 'A fruit that is red.' && Lib.firstDefinition('

none

') === '', 'crossword: the first definition of a Wiktionary page'); + check(Lib.firstDefinition('
  1. Rudeness, insolence. [16th\u201319th c.]
') === 'Rudeness, insolence.', 'kit: a definition loses the style block and the date a real Wiktionary puts in it'); } { diff --git a/tests/test_games_library_social.py b/tests/test_games_library_social.py index c7d012ef2..ef0ac9b6f 100644 --- a/tests/test_games_library_social.py +++ b/tests/test_games_library_social.py @@ -349,6 +349,16 @@ def begin(page): page.wait_for_function("() => !document.querySelector('.rc-card .gm-play')") +def follow_a_link(page, end): + """Follow the page's first link that is not the end, and wait for it to land. The end is a random walk away, so the + start can link straight to it (about one race in eight on the fixture), and a race already won has nothing to give up. + A link is inline and often wraps, so the middle of its box can be the gap between its lines: Playwright's click aims + at a point of the link itself (and checks nothing covers it), where tap() at the box's middle can miss.""" + steps = page.evaluate("__race.race.steps.length") + page.locator(".rc-link:not([data-path=%s])" % json.dumps(end)).first.click() + page.wait_for_function(truthy("__race.race.steps.length === %d" % (steps + 1))) + + def give_up(page, then): """Give up from the Menu; `then` is the page's own sign that it was taken (the next card, or the end sheet).""" page.get_by_role("button", name="Menu").click() @@ -365,7 +375,7 @@ def test_wiki_race_for_two(browser, world, mode, gone): assert "Player 1" in page.locator(".rc-card h2").inner_text() first = page.evaluate("[__race.race.pair.start.path, __race.race.pair.end.path]") begin(page) - tap(page, page.locator(".rc-link").first) + follow_a_link(page, first[1]) give_up(page, "__race.race.hot.res.length === 1 && document.querySelector('.rc-card h2')") assert "Pass the phone to Player 2" in page.locator(".rc-card h2").inner_text() # between the two races: leaving and coming back keeps player 1's result and the hand-over @@ -386,7 +396,7 @@ def test_wiki_race_for_two(browser, world, mode, gone): ), "the same race for both" begin(page) if page.locator(".rc-link").count(): # (with the library gone there is no article to follow) - tap(page, page.locator(".rc-link").first) + follow_a_link(page, first[1]) give_up(page, "document.querySelector('.ar-sheet:not([hidden])')") assert ( "Draw" in page.locator(".ar-sheet:not([hidden])").inner_text() diff --git a/tests/test_games_new_row_browser.py b/tests/test_games_new_row_browser.py new file mode 100644 index 000000000..59f18fbe2 --- /dev/null +++ b/tests/test_games_new_row_browser.py @@ -0,0 +1,140 @@ +"""The shelf's "New" row: the games that arrived with this release, one row under the table, while that release is current. + +games.json carries an `added` release on each; the shelf shows the games of the highest one. A search, a room or a type chip +takes the row away like the Daily row. Each kind is dealt in turn so the row is not one picture. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_games_new_row_browser.py -v +""" + +import json +import os +import re +import sys + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from games_wait import frames # noqa: E402 +from test_games_persist_browser import GAMES, VIEW, browser, served # noqa: E402,F401 + + +def rows(): + with open(os.path.join(GAMES, "games.json"), encoding="utf-8") as f: + return json.load(f) + + +def test_added_is_a_release_and_names_a_real_page(): + for r in rows(): + if "added" in r: + assert re.fullmatch(r"\d+\.\d+", r["added"]), r + assert os.path.exists(os.path.join(GAMES, r["path"])), r["path"] + + +def test_the_row_lists_the_latest_release_only(browser, served): + if not any("added" in r for r in rows()): + pytest.skip("no game in games.json says which release added it") + ctx = browser.new_context( + viewport=VIEW, has_touch=True, is_mobile=True, reduced_motion="reduce" + ) + page = ctx.new_page() + page.goto("%s/index.html" % served) + page.wait_for_selector(".ar-new a.ar-game") + frames(page) + latest = max( + (tuple(map(int, r["added"].split("."))) for r in rows() if "added" in r) + ) + want = { + r["path"] + for r in rows() + if "added" in r and tuple(map(int, r["added"].split("."))) == latest + } + got = page.eval_on_selector_all( + ".ar-new a.ar-game", "els => els.map(e => e.getAttribute('href'))" + ) + assert set(got) == want and len(got) == len(want) + # Directly under the table, ahead of the Daily row. + order = page.eval_on_selector_all( + ".sh-top > section", + "els => els.map(e => e.className.split(' ').filter(c => /^ar-(continue|world|new|daily)$/.test(c))[0])", + ) + # The table, the world's favorites, what is new, then the rest: the games that use your library are not what the shelf opens on. + assert order[:3] == ["ar-continue", "ar-world", "ar-new"], order + assert order.index("ar-new") < order.index("ar-daily") + world = page.eval_on_selector_all( + ".ar-world a.ar-game", "els => els.map(e => e.getAttribute('href'))" + ) + assert ( + world[:3] == ["chess.html", "solitaire.html", "checkers.html"] + and len(world) == 13 + ), world # chess is in the row even while the idle table suggests it + sections = page.eval_on_selector_all( + ".sh-list > section", "els => els.map(e => e.querySelector('h2').id)" + ) + assert sections[-1] == "ar-library" and sections[0] != "ar-library", sections + # Not one picture ten times: the first six are not all one kind. + kinds = {r["path"]: r["kind"] for r in rows() if "kind" in r} + assert len({kinds[p] for p in got[:6]}) >= 3 + # A search takes it away, clearing the search brings it back. + page.fill(".sh-search input", "chess") + frames(page) + assert page.locator(".ar-new").is_hidden() + page.fill(".sh-search input", "") + frames(page) + assert page.locator(".ar-new").is_visible() + ctx.close() + + +def test_no_added_no_row(browser, served): + ctx = browser.new_context( + viewport=VIEW, has_touch=True, is_mobile=True, reduced_motion="reduce" + ) + page = ctx.new_page() + plain = [{k: v for k, v in r.items() if k != "added"} for r in rows()] + page.route( + "**/games.json", + lambda route: route.fulfill( + body=json.dumps(plain), content_type="application/json" + ), + ) + page.goto("%s/index.html" % served) + page.wait_for_selector(".ar-daily a.ar-game") + assert page.locator(".ar-new").count() == 0 + # Without a New row the shelf still opens on the table and the world's favorites, and the library games come last. + order = page.eval_on_selector_all( + ".sh-top > section", + "els => els.map(e => e.className.split(' ').filter(c => /^ar-(continue|world|daily)$/.test(c))[0])", + ) + assert order[:2] == ["ar-continue", "ar-world"], order + sections = page.eval_on_selector_all( + ".sh-list > section", "els => els.map(e => e.querySelector('h2').id)" + ) + assert sections[-1] == "ar-library" and sections[0] != "ar-library", sections + ctx.close() + + +def test_kiwix_viewer_links_keep_the_opening_rows(browser, served): + """kiwix-serve 3.8's viewer rewrites every link of the framed page to "/viewer#/" once it has loaded, before + games.json comes back: the table, World favorites and the Daily row still find their tiles (the shelf opened on the + Library group in Kiwix without this).""" + ctx = browser.new_context(viewport=VIEW, has_touch=True, is_mobile=True, reduced_motion="reduce") + page = ctx.new_page() + body = json.dumps(rows()) + + def late(route): + page.wait_for_timeout(300) + route.fulfill(body=body, content_type="application/json") + + page.route("**/games.json", late) + page.add_init_script( + "document.addEventListener('DOMContentLoaded', function () {" + " document.querySelectorAll('a[href]').forEach(function (a) { var h = a.getAttribute('href');" + " if (!/^(https?:|#|\\/)/.test(h)) a.setAttribute('href', '/viewer#zimi_games_2026-11/' + h); }); });" + ) + page.goto("%s/index.html" % served) + page.wait_for_selector(".ar-daily a.ar-game") + order = page.eval_on_selector_all( + ".sh-top > section", + "els => els.map(e => e.className.split(' ').filter(c => /^ar-(continue|world|daily)$/.test(c))[0])", + ) + assert order[:2] == ["ar-continue", "ar-world"] and "ar-daily" in order, order + ctx.close() diff --git a/tests/test_games_script_hygiene.py b/tests/test_games_script_hygiene.py new file mode 100644 index 000000000..05d57a44b --- /dev/null +++ b/tests/test_games_script_hygiene.py @@ -0,0 +1,56 @@ +"""No function is declared twice in one scope of a games script. + +A second `function name()` at the same level silently replaces the first (declarations hoist): shell.js once got a credit-line +loader named loadScript that replaced the page's own loadScript, and Watch and learn stopped starting in every game. + +Run: pytest tests/test_games_script_hygiene.py -v +""" + +import glob +import os +import re + +import pytest + +GAMES = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + "zimi", + "builtin", + "games", +) +DECL = re.compile(r"^(\s*)function\s+([A-Za-z_$][\w$]*)\s*\(", re.M) +SCRIPTS = sorted( + glob.glob(os.path.join(GAMES, "*.js")) + + glob.glob(os.path.join(GAMES, "puzzles", "*.js")) +) + + +def _duplicates(text): + """(indent, name) pairs declared twice with the same indent, and no `})(`-style scope close between them (same IIFE).""" + seen, dup = {}, [] + for m in DECL.finditer(text): + key = (len(m.group(1)), m.group(2)) + if key in seen: + between = text[seen[key] : m.start()] + # A line closing the scope the first one sat in (less indented than it) means a different scope. + closes = [ + ln + for ln in between.split("\n") + if ln.strip() and len(ln) - len(ln.lstrip()) < key[0] + ] + if not closes: + dup.append(key[1]) + seen[key] = m.start() + return dup + + +@pytest.mark.parametrize("path", SCRIPTS, ids=lambda p: os.path.relpath(p, GAMES)) +def test_no_function_is_declared_twice_in_one_scope(path): + with open(path, encoding="utf-8") as f: + assert _duplicates(f.read()) == [] + + +def test_the_guard_sees_the_shell_bug(): + two = " function loadScript(src, done) {}\n var x = 1;\n function loadScript(name, then) {}\n" + assert _duplicates(two) == ["loadScript"] + assert _duplicates(" function a() {\n }\n}\n function a() {}\n") == [] diff --git a/tests/test_games_snake_walls_browser.py b/tests/test_games_snake_walls_browser.py new file mode 100644 index 000000000..c5ea35fd2 --- /dev/null +++ b/tests/test_games_snake_walls_browser.py @@ -0,0 +1,76 @@ +"""Snake's walls in Menu > Settings: Solid (the default, as before) or Wrap through, remembered, in every language. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_games_snake_walls_browser.py -v +""" + +import json +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import GAMES, browser, served # noqa: E402,F401 + +PRESSED = "() => Array.from(document.querySelectorAll('.gs-card .gs-row')).filter(r => r.querySelector('label').textContent === %s).map(r => Array.from(r.querySelectorAll('button')).map(b => b.textContent + (b.getAttribute('aria-pressed') === 'true' ? '*' : '')))" + + +def open_settings(page): + page.click(".gs-menu-btn") + page.locator(".gs-card button", has_text="Settings").first.click() + page.wait_for_selector(".gs-card .gs-row") + + +def test_walls_live_in_settings_and_are_remembered(browser, served): + ctx = browser.new_context(viewport={"width": 390, "height": 844}) + page = ctx.new_page() + page.goto("%s/snake.html#lang=en&dir=ltr" % served) + page.wait_for_selector(".gs-ready .gs-menu-btn") + open_settings(page) + assert page.evaluate(PRESSED % json.dumps("Walls")) == [ + ["Solid*", "Wrap through"] + ] # the default is as it was + page.locator(".gs-card .gs-row button", has_text="Wrap through").click() + assert ( + page.evaluate( + "JSON.parse(localStorage.getItem('zimi.games.snake.settings')).wrap" + ) + is True + ) + assert ( + page.evaluate("__snake.g.wrap") is True + ) # a board not yet started takes it at once + page.reload() + page.wait_for_selector(".gs-ready .gs-menu-btn") + open_settings(page) + assert page.evaluate(PRESSED % json.dumps("Walls")) == [["Solid", "Wrap through*"]] + assert page.evaluate("__snake.g.wrap") is True + ctx.close() + + +def test_walls_say_so_in_every_language(): + for lang in ("en", "de", "es", "fr", "pt", "ru", "zh", "hi", "ar", "he"): + with open(os.path.join(GAMES, "text", "%s.json" % lang), encoding="utf-8") as f: + table = json.load(f) + assert all( + table.get(k) + for k in ("snake.walls", "snake.walls.solid", "snake.walls.wrap") + ), lang + + +def test_a_walls_change_mid_game_does_not_move_the_game_to_the_other_walls_best(browser, served): + """The walls of the board in play decide whose best it is: switching the setting during a game applies to the next one.""" + ctx = browser.new_context(viewport={"width": 390, "height": 844}) + page = ctx.new_page() + page.add_init_script("localStorage.setItem('zimi.games.snake.best', JSON.stringify({ walls: 7, wrap: 0 }));") + page.goto("%s/snake.html#lang=en&dir=ltr" % served) + page.wait_for_selector(".gs-sp-play") + page.click(".gs-sp-play") + page.wait_for_function("__snake.mode === 'playing'") + open_settings(page) + page.locator(".gs-card .gs-row button", has_text="Wrap through").click() + page.keyboard.press("Escape") + assert page.evaluate("__snake.g.wrap") is False, "the board in play keeps its walls" + page.evaluate("() => { const b = document.getElementById('sn-pause'); if (/^resume/i.test(b.textContent)) b.click(); }") + page.wait_for_function("__snake.mode === 'over'", timeout=60_000) # it runs into the solid wall + stat = page.evaluate("document.querySelector('.ar-stat').textContent") + assert "Best 7" in stat, stat + ctx.close() diff --git a/tests/test_games_wikirace_one_result_browser.py b/tests/test_games_wikirace_one_result_browser.py new file mode 100644 index 000000000..fe1a1f824 --- /dev/null +++ b/tests/test_games_wikirace_one_result_browser.py @@ -0,0 +1,86 @@ +"""Wiki Race: one race, one result. Tap a link, give up before its page arrives (a slow disk, a slow kiwix-serve), and the +late page counts for nothing: no step, no second end sheet, no "You won" after "You gave up". + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_games_wikirace_one_result_browser.py -v +""" + +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import VIEW, browser, served # noqa: E402,F401 + +# The fewest links from where the race stands to its target, over the race's own provider. +ROUTE = """async () => { const R = __race.race, P = __race.provider, to = R.pair.end.path; + const prev = {}, q = [R.steps[R.steps.length - 1].path]; prev[q[0]] = null; + for (let i = 0; i < q.length && i < 400; i++) { const pg = await P.open(q[i]); + for (const l of (pg.links || [])) { const p = l.path || l; if (p in prev) continue; prev[p] = q[i]; + if (p === to) { const out = [p]; let x = q[i]; while (prev[x] !== null) { out.unshift(x); x = prev[x]; } return out; } q.push(p); } } + return null; }""" +SLOW_MS = 1500 + + +def test_a_page_that_lands_after_give_up_counts_for_nothing(browser, served): + ctx = browser.new_context(viewport=VIEW) + page = ctx.new_page() + page.goto("%s/wikirace.html" % served) + page.wait_for_function("window.__race && __race.race && __race.provider") + page.evaluate( + "() => { window.__sheets = []; const real = ZimiShell.endSheet;" + " ZimiShell.endSheet = function (o) { __sheets.push(o.result); return real.apply(this, arguments); }; }" + ) + page.click("button.gm-play") + page.wait_for_function("__race.race.begun && __race.race.page") + route = page.evaluate(ROUTE) + assert route, "the built-in set has a route to the target" + for path in route[:-1]: + page.click('.rc-link[data-path="%s"]' % path) + page.wait_for_function( + "p => __race.race.steps[__race.race.steps.length - 1].path === p", arg=path + ) + steps = page.evaluate("__race.race.steps.length") + # From here every page takes SLOW_MS to come. + page.evaluate( + "ms => { const P = __race.provider, real = P.open.bind(P);" + " P.open = p => real(p).then(pg => new Promise(r => setTimeout(() => r(pg), ms))); }", + SLOW_MS, + ) + page.click( + '.rc-link[data-path="%s"]' % route[-1] + ) # the winning link, still loading... + page.evaluate( + "document.getElementById('rc-give').click()" + ) # ...when the player gives up + page.wait_for_timeout(SLOW_MS * 2) + assert page.evaluate("__sheets") == ["lose"], page.evaluate("__sheets") + assert ( + page.evaluate("__race.race.steps.length") == steps + ), "the late page is not a step of the race" + assert page.evaluate("__race.race.gave") is True + ctx.close() + + +def test_a_page_the_first_player_was_loading_does_not_land_in_the_seconds_turn(browser, served): + """Two on one phone: the first player gives up with a link still loading; the second player's turn reuses the race, and + the late page must not become a step of it.""" + ctx = browser.new_context(viewport=VIEW) + page = ctx.new_page() + page.goto("%s/wikirace.html" % served) + page.wait_for_function("window.__race && __race.race && __race.provider") + page.click("button.gm-play") + page.wait_for_function("__race.race.begun && __race.race.page") + # Two on one phone: the race the page runs is the hot-seat one (its own code paths: give up hands the phone over). + page.evaluate("() => { __race.race.mode = 'hotseat'; __race.race.hot = { turn: 0, res: [] }; }") + link = page.evaluate("document.querySelector('.rc-link').dataset.path") + page.evaluate( + "ms => { const P = __race.provider, real = P.open.bind(P);" + " P.open = p => real(p).then(pg => new Promise(r => setTimeout(() => r(pg), ms))); }", + SLOW_MS, + ) + page.click('.rc-link[data-path="%s"]' % link) + page.evaluate("document.getElementById('rc-give').click()") + page.click("button.gm-play") # the hand-off: Ready, player 2 + page.wait_for_function("__race.race.hot.turn === 1") + page.wait_for_timeout(SLOW_MS * 2) + assert page.evaluate("__race.race.steps.length") == 1, "the first player's late page is not a step of the second player's turn" + ctx.close() diff --git a/tests/test_games_zimcity_browser.py b/tests/test_games_zimcity_browser.py index d371e5cea..f089e58bb 100644 --- a/tests/test_games_zimcity_browser.py +++ b/tests/test_games_zimcity_browser.py @@ -854,7 +854,8 @@ def test_on_an_iphone_reporting_no_inset_the_tray_still_clears_the_indicator(bro pg = iphone(browser, site, 844) assert pg.evaluate(LOWEST_CONTROL) <= 844 - 34 pg = iphone(browser, site, 664) - assert pg.evaluate("() => getComputedStyle(document.documentElement).getPropertyValue('--safe-b').trim()") == "0px" + # --safe-b is a calc() (the inset plus the Kiwix JS toolbar's room, 0 here): its used value is what must be 0. + assert pg.evaluate("() => { const p = document.createElement('i'); p.style.cssText = 'position:fixed;padding-bottom:var(--safe-b)'; document.body.appendChild(p); const v = getComputedStyle(p).paddingBottom; p.remove(); return v; }") == "0px" MAP_ON_SCREEN = """() => { const v = window.__zimcity.view, m = v.city.map, s = v.cam.s, l = -v.cam.x * s, t = -v.cam.y * s, r = l + m.width * 16 * s, b = t + m.height * 16 * s; diff --git a/tests/test_german_du.py b/tests/test_german_du.py index 4c8377c71..8c0158789 100644 --- a/tests/test_german_du.py +++ b/tests/test_german_du.py @@ -18,6 +18,7 @@ # The strings where "Sie"/"Ihr" is genuinely third person (they/it/their), each about a thing named in the same string. THIRD_PERSON_SIE = { "alm_dt_tilt_desc", # Sie = die Neigung + "alm_gr_note", # Sie = die Bilder "backup_mydata_intro", # Sie = Lesezeichen, Verlauf, Einstellungen "backup_mydata_intro_account", "catalog_snapshot_note", # Sie = die Bibliothek diff --git a/tests/test_golden_record.py b/tests/test_golden_record.py new file mode 100644 index 000000000..e93518fe6 --- /dev/null +++ b/tests/test_golden_record.py @@ -0,0 +1,253 @@ +"""The Golden Record's pictures: every one credited, and the Almanac built for Kiwix carries only the free ones. + +The Almanac shows 49 of the record's pictures (static/golden-record/). Eight are NASA photographs, in the public +domain; the other 41 are copyright their owners (NASA: "All of these images are copyright protected"). +credits.json is the table the gallery draws from: each file, its caption, who it is by, public domain or not. + + 1. The table covers every picture in the folder, once, and nothing that is not there; each caption exists. + 2. Exactly 8 are public domain, all NASA's; every owner of the other 41 is named in SOURCES.txt and zimi.txt. + 3. Zimi's own Almanac (the normal stage, and the ZIM built from it) carries all 49. + 4. The community Almanac (openZIM/Kiwix) carries exactly the 8, with the 41 marked omitted in its table (the + gallery names those in its list as text), and its zimi.txt says so. + +Run: pytest tests/test_golden_record.py -v +""" + +import json +import os +import sys + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from zimi import almanacstage # noqa: E402 + +STATIC = almanacstage.STATIC +GR_DIR = os.path.join(STATIC, almanacstage.GOLDEN_RECORD) +PICTURE_EXT = (".gif", ".jpg", ".jpeg", ".png", ".webp") +PUBLIC_DOMAIN = 8 +ALL = 49 +OWNERS_NAMED_IN = ( + os.path.join(STATIC, "earth", "SOURCES.txt"), + os.path.join(almanacstage.HOST, "zimi.txt"), +) + + +def _pictures(folder): + return sorted(f for f in os.listdir(folder) if f.lower().endswith(PICTURE_EXT)) + + +def _table(folder): + with open(os.path.join(folder, "credits.json"), encoding="utf-8") as f: + return json.load(f)["images"] + + +def test_the_table_covers_every_picture_once(): + images = almanacstage.golden_record_images() + files = [im["file"] for im in images] + assert len(files) == len(set(files)) == ALL + assert sorted(files) == _pictures(GR_DIR) + with open(os.path.join(STATIC, "i18n", "en.json"), encoding="utf-8") as f: + en = json.load(f) + caps = [im["cap"] for im in images] + assert sorted(caps) == list(range(ALL)), "each caption once" + assert all("gr_cap_%d" % c in en for c in caps) + assert all(im["by"].strip() and isinstance(im["pd"], bool) for im in images) + assert not any(im.get("omitted") for im in images), "the source table omits nothing" + + +def test_eight_are_public_domain_and_every_other_owner_is_named(): + images = almanacstage.golden_record_images() + pd = [im for im in images if im["pd"]] + assert len(pd) == PUBLIC_DOMAIN + assert {im["by"] for im in pd} == {"NASA"} + owners = {im["by"] for im in images if not im["pd"]} + assert "NASA" not in owners + for path in OWNERS_NAMED_IN: + with open(path, encoding="utf-8") as f: + text = f.read() + missing = [o for o in owners if o not in text] + assert not missing, (os.path.basename(path), missing) + + +def test_the_gallery_says_no_picture_is_nasa_public_domain_wholesale(): + with open(os.path.join(STATIC, "almanac.js"), encoding="utf-8") as f: + src = f.read() + assert "(NASA public domain)" not in src + assert "_GR_IMAGES" not in src, "the gallery draws from credits.json" + gallery = src[src.index("function _renderGoldenRecordGallery") :] + gallery = gallery[: gallery.index("\n}\n")] + assert "gr-list" in gallery and "gr-row-text" in gallery, "one list; an omitted picture is a line of text" + + +@pytest.fixture(scope="module") +def staged(tmp_path_factory): + out = {} + for community in (False, True): + dest = tmp_path_factory.mktemp("community" if community else "full") + almanacstage.stage(str(dest), community=community) + out[community] = str(dest) + return out + + +def test_zimis_own_almanac_carries_all_49(staged): + folder = os.path.join(staged[False], almanacstage.GOLDEN_RECORD) + assert len(_pictures(folder)) == ALL + assert not any(im.get("omitted") for im in _table(folder)) + with open(os.path.join(staged[False], "zimi.txt"), encoding="utf-8") as f: + assert almanacstage.GOLDEN_LINE_FULL in f.read() + + +def test_the_community_almanac_carries_exactly_the_public_domain_eight(staged): + folder = os.path.join(staged[True], almanacstage.GOLDEN_RECORD) + table = _table(folder) + kept = sorted(im["file"] for im in table if im["pd"]) + assert _pictures(folder) == kept and len(kept) == PUBLIC_DOMAIN + omitted = [im for im in table if im.get("omitted")] + assert len(omitted) == ALL - PUBLIC_DOMAIN + assert all( + not im["pd"] and im["by"] for im in omitted + ), "each omitted row keeps its caption and credit" + assert len(table) == ALL, "the sequence stays whole" + with open(os.path.join(staged[True], "zimi.txt"), encoding="utf-8") as f: + meta = f.read() + assert ( + almanacstage.GOLDEN_LINE_COMMUNITY in meta + and almanacstage.GOLDEN_LINE_FULL not in meta + ) + + +def _zim_pictures(path): + from libzim.reader import Archive + + from zimi.libzimcompat import entry_by_id + + a = Archive(path) + prefix = almanacstage.GOLDEN_RECORD + "/" + names = [] + for i in range(a.all_entry_count): + p = entry_by_id(a, i).path + if p.startswith(prefix) and p.lower().endswith(PICTURE_EXT): + names.append(p[len(prefix) :]) + credits = json.loads( + bytes(a.get_entry_by_path(prefix + "credits.json").get_item().content) + ) + return sorted(names), credits["images"] + + +def test_the_built_zims_hold_49_and_8(tmp_path): + sys.path.insert( + 0, + os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "scripts" + ), + ) + import build_almanac_kiwix + from zimi import ownzims + + own = next(o for o in ownzims.OWN if o.name == "zimi_almanac") + full, full_table = _zim_pictures(ownzims.write_zim(own, str(tmp_path / "full.zim"))) + assert len(full) == ALL and not any(im.get("omitted") for im in full_table) + kiwix, kiwix_table = _zim_pictures( + build_almanac_kiwix.build(str(tmp_path), "kiwix.zim") + ) + assert len(kiwix) == PUBLIC_DOMAIN + assert kiwix == sorted(im["file"] for im in kiwix_table if im["pd"]) + assert sum(1 for im in kiwix_table if im.get("omitted")) == ALL - PUBLIC_DOMAIN + from libzim.reader import Archive + + meta = Archive(str(tmp_path / "kiwix.zim")) + assert meta.get_metadata("Name").decode() == build_almanac_kiwix.DEFAULT_NAME == "zimi_mul_almanac" + assert meta.get_metadata("Title").decode() == build_almanac_kiwix.DEFAULT_TITLE == "Zimi Almanac" + assert meta.get_metadata("Language").decode() == "eng,zho,hin,spa,ara,fra,por,rus,deu,heb" + + +# The gallery's own code, run in node on each edition's table: what the list holds. +_RENDER = r""" +const fs = require('fs'), vm = require('vm'); +const src = fs.readFileSync(process.argv[1], 'utf8'); +function grab(re) { const m = src.match(re); if (!m) throw new Error('missing ' + re); return m[0]; } +const code = [/var _GR_DIR = [^\n]*/, /function _grCap\(idx\)[^\n]*/, /function _grCredit\(idx\) \{[\s\S]*?\n\}/, + /function _renderGoldenRecordGallery\(\) \{[\s\S]*?\n\}/].map(grab).join('\n'); +const ctx = { t: (k) => k, _almEsc: (x) => String(x), _grImages: JSON.parse(fs.readFileSync(process.argv[2], 'utf8')).images }; +vm.createContext(ctx); vm.runInContext(code, ctx); +const html = ctx._renderGoldenRecordGallery(); +const count = (re) => (html.match(re) || []).length; +console.log(JSON.stringify({ rows: count(/
  • { calls++; if (calls === 1) throw new Error('offline'); return { json: async () => ({ images: [{ file: 'a.gif' }] }) }; } }; +vm.createContext(ctx); vm.runInContext(code, ctx); +(async () => { + const first = await ctx._loadGrCredits(), second = await ctx._loadGrCredits(), third = await ctx._loadGrCredits(); + console.log(JSON.stringify({ first: first.length, second: second.length, third: third.length, calls })); +})(); +""" + ) + assert got == {"first": 0, "second": 1, "third": 1, "calls": 2}, got + + +def test_a_picture_file_name_is_escaped_in_both_renderers(): + got = _node( + r""" +const code = [/var _GR_DIR = [^\n]*/, /function _grCap\(idx\)[^\n]*/, /function _grCredit\(idx\) \{[\s\S]*?\n\}/, + /function _renderGoldenRecordGallery\(\) \{[\s\S]*?\n\}/].map(grab).join('\n'); +const ctx = { t: (k) => k, _almEsc: (x) => String(x).replace(/"/g, '"'), _grImages: [{ file: 'x" onerror="boom', cap: 'c', by: 'b', pd: true }] }; +vm.createContext(ctx); vm.runInContext(code, ctx); +console.log(JSON.stringify({ raw: ctx._renderGoldenRecordGallery().includes('onerror="boom') })); +""" + ) + assert got == {"raw": False}, got diff --git a/tests/test_home_apps_live.py b/tests/test_home_apps_live.py index 03b769940..c33def3d9 100644 --- a/tests/test_home_apps_live.py +++ b/tests/test_home_apps_live.py @@ -385,7 +385,15 @@ def test_the_dot_says_what_lit_it(served, touch): if touch: pg.locator(dot).tap() else: - pg.locator(dot).hover() + # The pointer goes to the dot as a mouse does, with no scroll. Home redraws once more when its late data + # lands (_renderHomeSoon); a locator.hover() that meets the redraw retries by scrolling the page, and a + # scroll closes the popover, under a pointer that never moves again. The dot's middle is read in the page, + # in one go, so a redraw between finding it and measuring it cannot leave nothing to measure. + x, y = pg.wait_for_function( + "(s) => { const d = document.querySelector(s), b = d && d.getBoundingClientRect(); return b && b.width ? [b.x + b.width / 2, b.y + b.height / 2] : null; }", + arg=dot, + ).json_value() + pg.mouse.move(x, y) pg.wait_for_function("() => { const p = document.getElementById('dot-why'); return p && p.querySelector('.upd'); }", timeout=10000) text = pg.inner_text("#dot-why") assert "CrashCourse" in text and pg.evaluate("t('upd_updated')") in text, text diff --git a/tests/test_home_discover_live.py b/tests/test_home_discover_live.py index ec1971216..00f6facf6 100644 --- a/tests/test_home_discover_live.py +++ b/tests/test_home_discover_live.py @@ -239,9 +239,12 @@ def test_discover_drawn_before_the_library_fills_in_when_it_arrives(served): try: pg.goto(served + "/") pg.wait_for_function(READY, timeout=30000) + # The two draws below are the test's own: the page's follow-up draws for late data (collections, the + # provenance walk) are set aside, or one landing between the two steps is counted as a third ask. pg.evaluate( """() => { window.__asked = 0; const load = _loadDiscover; - window._loadDiscover = function() { window.__asked++; return load.apply(this, arguments); }; }""" + window._loadDiscover = function() { window.__asked++; return load.apply(this, arguments); }; + clearTimeout(_homeRerenderTimer); window._renderHomeSoon = function() {}; }""" ) # The list not in yet: home draws Discover from nothing. pg.evaluate("() => { window.__lib = zimsCache; zimsCache = []; _rebuildZimsMap(); renderHome(); }") diff --git a/tests/test_keep_pdf_live.py b/tests/test_keep_pdf_live.py index 4b5725f72..1d1275e99 100644 --- a/tests/test_keep_pdf_live.py +++ b/tests/test_keep_pdf_live.py @@ -68,7 +68,9 @@ def test_a_kept_document_library_reads_offline(pw, world): poll(pg, "async (z) => !!(await caches.match('/catalog?zim=' + encodeURIComponent(z)))", timeout_s=30, arg=NAME) world.stop() pg.goto(world.base + "/", wait_until="load") - pg.wait_for_function("() => typeof enterSource === 'function'") + # enterSource reads the library list the boot fetches (here from the worker); asked before it lands, the ZIM is + # unknown and opens at its front page instead of its list of documents. + pg.wait_for_function("(z) => typeof enterSource === 'function' && !!_zimInfo(z)", arg=NAME, timeout=30000) pg.evaluate("(z) => enterSource(z)", NAME) pg.wait_for_selector("a.zg-doc", timeout=15000) titles = pg.eval_on_selector_all("a.zg-doc .title", "els => els.map(e => e.innerText)") diff --git a/tests/test_moon_handoff_live.py b/tests/test_moon_handoff_live.py index fae270af2..bf4ce131a 100644 --- a/tests/test_moon_handoff_live.py +++ b/tests/test_moon_handoff_live.py @@ -106,6 +106,7 @@ def _almanac(browser, served, reduced=False, init=None): ) if init: ctx.add_init_script(init) + ctx.add_init_script(EVENT_LOG) pg = ctx.new_page() errors = [] pg.on("pageerror", lambda e: errors.append(str(e))) @@ -330,6 +331,59 @@ def test_leaving_restores_the_page(browser, served, reduced): ctx.close() +# A touch is the browser's to scroll with unless the page answers its first moves in time (Chromium gives a touch handler about +# 200 ms, then lets the compositor scroll and cancels the pointer): on a runner whose software GL is still busy with the 3D view's +# first frames the answer comes late, and the gesture ends as a scroll. The finger goes down once the page answers promptly: a +# measured state (CALM_TICKS timer ticks in a row, each under CALM_GAP_MS late), not a fixed wait. +CALM_TICKS = 12 +CALM_GAP_MS = 60 +CALM_CEILING_MS = 60_000 +CALM = """([ticks, gap, ceiling]) => new Promise((done) => { let last = performance.now(), calm = 0; const t0 = last; + const id = setInterval(() => { const now = performance.now(); calm = now - last - 16 < gap ? calm + 1 : 0; last = now; + if (calm >= ticks || now - t0 > ceiling) { clearInterval(id); done({ calm: calm, ms: Math.round(now - t0) }); } }, 16); })""" + + +def _wait_for_the_veil_to_go(pg): + """The loading veil stands over the whole page until the first screen is drawn, and takes the pointer with it: a finger put + down before it has gone lands on the veil, not on the Moon (the failure's event log: pointerdown on alm-veil, then a cancel).""" + pg.wait_for_function( + "() => { const v = document.getElementById('alm-veil'); return !v || v.hidden || getComputedStyle(v).pointerEvents === 'none' || v.classList.contains('alm-veil-out'); }", + timeout=CALM_CEILING_MS, + polling=POLL_MS, + ) + # And the Moon is what answers at its own middle. + pg.wait_for_function( + "(s) => { const r = document.querySelector(s).getBoundingClientRect(), e = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2);" + " return !!e && !!e.closest(s); }", + arg=HERO, + timeout=CALM_CEILING_MS, + polling=POLL_MS, + ) + + +def _wait_until_the_page_answers_promptly(pg): + got = pg.evaluate(CALM, [CALM_TICKS, CALM_GAP_MS, CALM_CEILING_MS]) + assert got["calm"] >= CALM_TICKS, "the page never settled: %r" % got + + +# The pointer events the page saw, newest last: what a failed hand-off says it was given. +EVENT_LOG = """(() => { window.__ev = []; const at = performance.now(); + ['pointerdown', 'pointermove', 'pointerup', 'pointercancel', 'lostpointercapture', 'dragstart', 'touchcancel'].forEach(t => + document.addEventListener(t, e => { const l = window.__ev; if (l.length > 60) l.shift(); l.push(t + '@' + Math.round(performance.now() - at) + (e.target && e.target.className ? ':' + String(e.target.className).slice(0, 18) : '')); }, true)); })();""" +HANDOFF_STATE = """() => ({ open: typeof _aeIsOpen !== 'undefined' && _aeIsOpen, hand: !!(window._ae && _ae.hand), press: JSON.stringify(window._almMoonPress), + lifter: typeof window.openAlmanacEarth, ready: typeof _aeReady === 'function' && _aeReady(), lifted: !!document.querySelector('.alm-moon-lifted'), + ev: (window.__ev || []).slice(-14).join(' '), hidden: document.hidden, scroll: document.getElementById('almanac-content').scrollTop, + under: (function () { var e = document.querySelector('%s'); if (!e) return null; var r = e.getBoundingClientRect(), h = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2); return h ? (h.className || h.tagName) : null; })() })""" % HERO + + +def _handoff_done(pg): + """The 3D view is open and has let go of the hand-in: a state. When it does not come, the page's own state is in the message.""" + try: + pg.wait_for_function("() => _aeIsOpen && !_ae.hand", timeout=HANDOFF_MS, polling=POLL_MS) + except Exception as e: + raise AssertionError("the hand-off did not finish: %s; the page: %r" % (type(e).__name__, pg.evaluate(HANDOFF_STATE))) from None + + def _touch_drag_turns(pg, cdp, x, y, steps, dx, dy): for i in range(1, steps + 1): cdp.send( @@ -349,6 +403,7 @@ def test_one_finger_lifts_and_keeps_turning(browser, served, pointer): ctx = browser.new_context( viewport=VIEW, device_scale_factor=DPR, has_touch=True, is_mobile=True ) + ctx.add_init_script(EVENT_LOG) pg = ctx.new_page() errors = [] pg.on("pageerror", lambda e: errors.append(str(e))) @@ -368,6 +423,10 @@ def test_one_finger_lifts_and_keeps_turning(browser, served, pointer): r = _rect(pg) x, y = r["x"] + r["width"] / 2, r["y"] + r["height"] / 2 scroll0 = pg.evaluate("document.getElementById('almanac-content').scrollTop") + _wait_for_the_veil_to_go(pg) + r = _rect(pg) + x, y = r["x"] + r["width"] / 2, r["y"] + r["height"] / 2 + _wait_until_the_page_answers_promptly(pg) if pointer == "touch": cdp = ctx.new_cdp_session(pg) cdp.send( @@ -382,9 +441,7 @@ def test_one_finger_lifts_and_keeps_turning(browser, served, pointer): for i in range(1, 7): pg.mouse.move(x + i * 4, y + i) x, y = x + 24, y + 6 - pg.wait_for_function( - "() => _aeIsOpen && !_ae.hand", timeout=HANDOFF_MS, polling=POLL_MS - ) + _handoff_done(pg) az0, el0 = pg.evaluate("[_ae.az, _ae.el_]") if pointer == "touch": x, y = _touch_drag_turns(pg, cdp, x, y, 10, 3, 6) diff --git a/tests/test_offline_mode.py b/tests/test_offline_mode.py index cb109a642..8cde79374 100644 --- a/tests/test_offline_mode.py +++ b/tests/test_offline_mode.py @@ -34,6 +34,8 @@ def _env(tmp_path, monkeypatch): monkeypatch.setattr(server, "ZIM_DIR", str(zim_dir)) monkeypatch.setattr(server, "ZIMI_DATA_DIR", str(tmp_path / "data")) monkeypatch.setattr(lib, "_opds_disk_loaded", True) + # Nothing a test earlier in this worker left in the catalog's memory: these tests start with no catalog at all. + monkeypatch.setattr(lib, "_opds_cache", {}) # Offline tests assert the synchronous stale-serve path — no background # revalidation threads reaching for a (dead) network. monkeypatch.setattr(lib, "_OPDS_BG_REFRESH", False) @@ -107,7 +109,9 @@ def test_catalog_torrent_archive_retries_next_run_when_offline(_env, monkeypatch lib._catalog_torrents_archived = False monkeypatch.setattr(p2p, "is_torrent_enabled", lambda: True) monkeypatch.setattr(p2p, "is_mirror_enabled", lambda: True) - # No cache at all: fetch fails offline -> archive defers, not marked done + # No cache at all: the catalog fetch fails offline -> archive defers, not marked done. The fetch itself is + # what is under test here, so no page left anywhere in the process can stand in for it. + monkeypatch.setattr(lib, "_fetch_kiwix_catalog", lambda *a, **k: (0, [], "network is gone")) assert lib.archive_catalog_torrents(spacing=0) == 0 assert lib._catalog_torrents_archived is False diff --git a/tests/test_open_zim_live_browser.py b/tests/test_open_zim_live_browser.py index 598050f73..c14cb9cb7 100644 --- a/tests/test_open_zim_live_browser.py +++ b/tests/test_open_zim_live_browser.py @@ -73,8 +73,22 @@ def test_a_replaced_zim_shows_new_at_the_same_place(served): assert pg.evaluate(heading) == "first" pg.evaluate("() => document.getElementById('reader-frame').contentWindow.scrollTo(0, 900)") pg.wait_for_function("() => typeof _liveSource !== 'undefined' && _liveSource && _liveSource.readyState === 1") # the window has its stream open + from zimi import changes + + seq0 = changes._seq served["swap"]() - pg.wait_for_function("() => { %s }" % ("const h = (%s)(); return h === 'second';" % heading), timeout=30000) + try: + pg.wait_for_function("() => { %s }" % ("const h = (%s)(); return h === 'second';" % heading), timeout=30000) + except Exception as e: + # Where it stopped: did the server announce, did the window hear, did its list change? + seen = pg.evaluate( + "() => ({ since: _liveSince, state: _liveSource && _liveSource.readyState, hidden: document.hidden," + " zims: (zimsCache || []).map(z => [z.name, z.size_bytes, z.entries]) })" + ) + raise AssertionError( + "the open window did not reload onto the replaced ZIM: %s; announced since the swap: %d; the window: %r" + % (type(e).__name__, changes._seq - seq0, seen) + ) from None y = pg.evaluate("() => document.getElementById('reader-frame').contentWindow.scrollY") assert abs(y - 900) < 60, y finally: diff --git a/tests/test_own_zims_kiwix_serve.py b/tests/test_own_zims_kiwix_serve.py index 5c3df893f..e411619a4 100644 --- a/tests/test_own_zims_kiwix_serve.py +++ b/tests/test_own_zims_kiwix_serve.py @@ -39,6 +39,16 @@ RANDOM_TRIES = 12 #: Games pages opened in Kiwix: one of each kind the shelf has (cards, board, a Logic puzzle). GAME_PAGES = ("solitaire.html", "chess.html", "puzzles/net.html") +#: Errors Kiwix's own viewer throws (kiwix-tools 3.8.2), never a book's page: it names its iframe's onload handler +#: before its script defines it ("on_content_load is not defined" on a fast frame load), and reads the framed page's +#: body for its scroll position before the frame has one ("Cannot read properties of null (reading 'scrollTop')"). +#: Either can happen on any viewer load, so every viewer step drops both, and only those. +VIEWER_ERRORS = ("on_content_load is not defined", "(reading 'scrollTop')") + + +def _not_viewer(errors): + """The page errors that are not Kiwix's viewer's own (VIEWER_ERRORS).""" + return [e for e in errors if not any(v in e for v in VIEWER_ERRORS)] def _kiwix_serve(): @@ -74,10 +84,23 @@ def kiwix(tmp_path_factory): "almanac": "zimi_almanac_%s" % MONTH, "maxi": build_almanac_maxi.FILE_FMT[:-4] % MONTH, } - ownzims.write_zim(own["zimi_games"], str(zims / (books["games"] + ".zim"))) - ownzims.write_zim(own["zimi_almanac"], str(zims / (books["almanac"] + ".zim"))) - _build_hd(str(tmp / "stage"), str(tmp / "tiles.zim")) - build_almanac_maxi.build(str(tmp / "tiles.zim"), str(zims), month=MONTH) + # ZIMI_KIWIX_TEST_FILES=games=,almanac=: the files a release (or an openZIM request) ships, as they are, + # instead of fresh builds; the HD flavour's tests skip then. + given = dict( + kv.split("=", 1) + for kv in os.environ.get("ZIMI_KIWIX_TEST_FILES", "").split(",") + if "=" in kv + ) + if given: + books = {} + for kind, path in given.items(): + books[kind] = os.path.basename(path)[: -len(".zim")] + shutil.copyfile(path, str(zims / os.path.basename(path))) + else: + ownzims.write_zim(own["zimi_games"], str(zims / (books["games"] + ".zim"))) + ownzims.write_zim(own["zimi_almanac"], str(zims / (books["almanac"] + ".zim"))) + _build_hd(str(tmp / "stage"), str(tmp / "tiles.zim")) + build_almanac_maxi.build(str(tmp / "tiles.zim"), str(zims), month=MONTH) port = _free_port() proc = subprocess.Popen( [binary, "--address=127.0.0.1", "--port=%d" % port] @@ -150,6 +173,8 @@ def _content_frame(pg, book): @pytest.mark.parametrize("kind", ["almanac", "maxi"]) def test_the_almanac_starts_in_kiwix_and_its_3d_view_opens(browser, kiwix, kind): + if kind not in kiwix["books"]: + pytest.skip("no %s file among ZIMI_KIWIX_TEST_FILES" % kind) book = kiwix["books"][kind] ctx, pg, errors = _page(browser) reqs = [] @@ -197,14 +222,14 @@ def test_the_almanac_starts_in_kiwix_and_its_3d_view_opens(browser, kiwix, kind) and "/random" not in u ] assert not stray, stray[:5] - # Kiwix's viewer names its iframe's onload handler before its script defines it; a fast frame load throws - # "on_content_load is not defined" in the viewer (kiwix-tools 3.8.2), not in the Almanac. - assert [e for e in errors if "on_content_load" not in e] == [], errors + assert _not_viewer(errors) == [], errors finally: ctx.close() def test_the_games_shelf_and_a_game_of_each_kind_start_in_kiwix(browser, kiwix): + if "games" not in kiwix["books"]: + pytest.skip("no games file among ZIMI_KIWIX_TEST_FILES") book = kiwix["books"]["games"] with open( os.path.join(ROOT, "zimi", "builtin", "games", "games.json"), encoding="utf-8" @@ -222,10 +247,8 @@ def test_the_games_shelf_and_a_game_of_each_kind_start_in_kiwix(browser, kiwix): arg=[want, book], timeout=60_000, ) - # The viewer's own script reads the framed page's body for its scroll position and throws "Cannot read properties of - # null (reading 'scrollTop')" when the frame has no body yet (kiwix-tools 3.8.2, viewer, not a game page): only that - # error is dropped, and only from the viewer step; every game page below is opened bare, on its own. - assert [e for e in errors if "'scrollTop'" not in e] == [], errors + # Only the viewer step drops the viewer's own errors; every game page below is opened bare, on its own. + assert _not_viewer(errors) == [], errors del errors[:] for page in GAME_PAGES: pg.goto(kiwix["base"] + "/content/%s/%s" % (book, page), wait_until="load") @@ -239,6 +262,8 @@ def test_the_games_shelf_and_a_game_of_each_kind_start_in_kiwix(browser, kiwix): @pytest.mark.parametrize("kind", ["games", "almanac", "maxi"]) def test_kiwix_random_lands_on_a_front_article(kiwix, kind): """Random in Kiwix lands on what zimi.txt's Articles names: a game or the Almanac, never a licence or a tile.""" + if kind not in kiwix["books"]: + pytest.skip("no %s file among ZIMI_KIWIX_TEST_FILES" % kind) book = kiwix["books"][kind] seen = set() for _ in range(RANDOM_TRIES): diff --git a/tests/test_search_requests_live.py b/tests/test_search_requests_live.py index 87b3f1255..12c6a1732 100644 --- a/tests/test_search_requests_live.py +++ b/tests/test_search_requests_live.py @@ -173,9 +173,11 @@ def test_a_fast_typists_minute_stays_well_under_the_public_budget(served): box.press("Enter") _done(pg, text) pg.mouse.wheel(0, 2500) - more = pg.locator(".load-more button, .result-more") + # "More from" one named source: which source ranks first is not fixed (the result count itself moves by a + # few between runs), and the searches after this one are the ones that source answers. + more = pg.locator('.result-more[data-zim="alpha_en_test"]') if more.count(): - more.first.click() + more.click() pg.wait_for_function( "() => allResults && !allResults.partial && _snippetsStreamSeq === 0", timeout=30000, diff --git a/tests/test_subproc_external.py b/tests/test_subproc_external.py new file mode 100644 index 000000000..8e07ac026 --- /dev/null +++ b/tests/test_subproc_external.py @@ -0,0 +1,148 @@ +"""A frozen app's children that are not part of it get the machine's environment (issue #151). + +PyInstaller's bootloader points LD_LIBRARY_PATH at the bundle and keeps the user's own in +LD_LIBRARY_PATH_ORIG. The machine's python3 started with the bundle's path loads the bundle's older +libssl and cannot import ssl: "the ssl module in Python is not available" while setting up voices. + +Run: pytest tests/test_subproc_external.py -v +""" + +import os +import subprocess +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) + +from zimi import subproc # noqa: E402 + +BUNDLE = "/opt/zimi/_internal" + + +def _frozen(monkeypatch): + monkeypatch.setattr(sys, "frozen", True, raising=False) + monkeypatch.setattr(sys, "_MEIPASS", BUNDLE, raising=False) + monkeypatch.setattr(sys, "executable", "/opt/zimi/zimi") + + +def test_an_outside_program_gets_the_users_library_path(monkeypatch): + _frozen(monkeypatch) + env = { + "LD_LIBRARY_PATH": BUNDLE, + "LD_LIBRARY_PATH_ORIG": "/usr/local/lib", + "PYTHONHOME": BUNDLE, + "_PYI_ARCHIVE_FILE": "x", + "PATH": "/usr/bin", + } + out = subproc.external_env(env) + assert out["LD_LIBRARY_PATH"] == "/usr/local/lib" + assert "LD_LIBRARY_PATH_ORIG" not in out and "PYTHONHOME" not in out + assert "_PYI_ARCHIVE_FILE" not in out and out["PATH"] == "/usr/bin" + assert env["LD_LIBRARY_PATH"] == BUNDLE, "the input is not changed" + + +def test_with_no_original_the_library_path_goes(monkeypatch): + _frozen(monkeypatch) + out = subproc.external_env({"LD_LIBRARY_PATH": BUNDLE, "DYLD_LIBRARY_PATH": BUNDLE}) + assert "LD_LIBRARY_PATH" not in out and "DYLD_LIBRARY_PATH" not in out + + +def test_a_source_install_is_untouched(monkeypatch): + monkeypatch.delattr(sys, "frozen", raising=False) + env = {"LD_LIBRARY_PATH": "/x", "LD_LIBRARY_PATH_ORIG": "/y"} + assert subproc.external_env(env) == env + + +def test_popen_scrubs_for_outside_programs_only(monkeypatch): + _frozen(monkeypatch) + seen = [] + monkeypatch.setattr(subprocess, "Popen", lambda cmd, **kw: seen.append(kw)) + monkeypatch.setenv("LD_LIBRARY_PATH", BUNDLE) + monkeypatch.setenv("LD_LIBRARY_PATH_ORIG", "/usr/local/lib") + subproc.popen(["/usr/bin/python3", "-c", "1"]) + assert seen[-1]["env"]["LD_LIBRARY_PATH"] == "/usr/local/lib" + subproc.popen( + ["/opt/zimi/zimi", "--child"] + ) # the app itself keeps the bundle's environment + assert "env" not in seen[-1] + subproc.popen(["/usr/bin/uv"], env={"LD_LIBRARY_PATH": BUNDLE, "A": "1"}) + assert "LD_LIBRARY_PATH" not in seen[-1]["env"] and seen[-1]["env"]["A"] == "1" + + +def test_run_follows_the_same_rule(monkeypatch): + _frozen(monkeypatch) + seen = [] + monkeypatch.setattr(subprocess, "run", lambda cmd, **kw: seen.append(kw)) + monkeypatch.setenv("LD_LIBRARY_PATH", BUNDLE) + subproc.run(["/usr/bin/npm", "root"]) + assert "LD_LIBRARY_PATH" not in seen[0]["env"] + + +def test_doctor_probe_passes_with_the_fix_and_catches_a_leak(monkeypatch, tmp_path): + """The probe `zimi doctor --check` runs in the frozen smoke test: a real python3 child.""" + from zimi import runtimes + + machine_python = sys.executable + monkeypatch.setattr(sys, "frozen", True, raising=False) + monkeypatch.setattr(sys, "_MEIPASS", str(tmp_path), raising=False) + monkeypatch.setattr(sys, "executable", str(tmp_path / "zimi")) + monkeypatch.setenv("LD_LIBRARY_PATH", str(tmp_path)) + assert runtimes.outside_python_problem(machine_python) is None + monkeypatch.setattr(subproc, "run", subprocess.run) # the old behaviour: the environment inherited as is + assert "library path" in runtimes.outside_python_problem(machine_python) + + +def test_doctor_probe_is_silent_when_not_frozen(monkeypatch): + from zimi import runtimes + + monkeypatch.delattr(sys, "frozen", raising=False) + assert runtimes.outside_python_problem() is None + + +def test_inside_the_bundle_by_either_platforms_rules(): + import ntpath + import posixpath + + assert subproc._under("/opt/zimi/_internal/lib/x", BUNDLE, posixpath) + assert subproc._under("/opt/zimi/_internal", BUNDLE + "/", posixpath) + assert not subproc._under("/opt/zimi/_internal2", BUNDLE, posixpath) + win = "C:\\Program Files\\Zimi\\_internal" + assert subproc._under("c:/program files/zimi/_internal/python314.dll", win, ntpath), "slashes and case are one spelling" + assert subproc._under("C:\\Program Files\\Zimi\\_internal\\", win, ntpath) + assert not subproc._under("C:\\Program Files\\Zimi\\_internal_x", win, ntpath) + assert not subproc._under("D:\\Program Files\\Zimi\\_internal", win, ntpath) + + +def test_a_python_path_list_naming_the_bundle_is_dropped_whatever_its_spelling(monkeypatch): + _frozen(monkeypatch) + out = subproc.external_env({"PYTHONPATH": os.pathsep.join(["/somewhere/else", BUNDLE + "/lib-dynload"]), "PYTHONHOME": BUNDLE + "/"}) + assert out["PYTHONPATH"] == "/somewhere/else" and "PYTHONHOME" not in out + mixed = subproc.external_env({"PYTHONPATH": os.pathsep.join([BUNDLE + "/lib", "/my/modules"])}) + assert mixed["PYTHONPATH"] == "/my/modules", "only the bundle's entries go" + kept = subproc.external_env({"PYTHONPATH": "/somewhere/else", "PYTHONHOME": "/usr/lib/python3"}) + assert kept == {"PYTHONPATH": "/somewhere/else", "PYTHONHOME": "/usr/lib/python3"} + + +def test_a_bare_program_name_is_looked_up_on_the_childs_path_not_in_the_bundle(monkeypatch, tmp_path): + """Started from the bundle's folder, "piper" must not be taken for the bundle's own file of that name: it is what PATH finds.""" + app, outside = tmp_path / "app", tmp_path / "bin" + app.mkdir() + outside.mkdir() + name = "piper.exe" if sys.platform == "win32" else "piper" # Windows finds a program by its extension (PATHEXT) + for folder in (app, outside): + exe = folder / name + exe.write_text("#!/bin/sh\n", encoding="utf-8") + exe.chmod(0o755) + monkeypatch.setattr(sys, "frozen", True, raising=False) + monkeypatch.setattr(sys, "_MEIPASS", str(app), raising=False) + monkeypatch.setattr(sys, "executable", str(app / "zimi")) + seen = [] + monkeypatch.setattr(subprocess, "Popen", lambda cmd, **kw: seen.append(kw)) + monkeypatch.setenv("LD_LIBRARY_PATH", str(app)) + monkeypatch.setenv("LD_LIBRARY_PATH_ORIG", "/usr/local/lib") + monkeypatch.setenv("PATH", str(outside)) + # POSIX looks a bare name up on PATH only; Windows looks in the current folder first, so there the bundle's own file can be the one found. + monkeypatch.chdir(tmp_path if sys.platform == "win32" else app) + subproc.popen(["piper", "--help"]) + assert seen[-1]["env"]["LD_LIBRARY_PATH"] == "/usr/local/lib" + assert os.path.normcase(subproc._resolved("piper")) == os.path.normcase(str(outside / name)) + assert not subproc._in_bundle("piper") diff --git a/tests/test_verify_games_qids.py b/tests/test_verify_games_qids.py new file mode 100644 index 000000000..638cac1f5 --- /dev/null +++ b/tests/test_verify_games_qids.py @@ -0,0 +1,63 @@ +"""The games' Q-ID audit: its judging is offline, and the 2026-11 findings stay fixed.""" + +import os +import sys +import unittest + +sys.path.insert( + 0, + os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "scripts" + ), +) +import verify_games_qids as audit # noqa: E402 + + +def _res(q=None, missing=False, disambig=False): + return {"q": q, "title": "x", "disambig": disambig, "missing": missing} + + +class AuditTests(unittest.TestCase): + def test_flags_missing_disambiguation_and_wrong_item(self): + found = [ + ("Q1", "A", "a.html"), + ("Q2", "B", "b.html"), + ("Q3", "C", "c.html"), + ("Q4", "D", "d.html"), + ] + res = { + "A": _res("Q1"), + "B": _res(missing=True), + "C": _res("Q3", disambig=True), + "D": _res("Q9"), + } + bad = audit.audit(found, res) + assert [(b[0], b[3]) for b in bad] == [ + ("Q2", "missing"), + ("Q3", "disambiguation page"), + ("Q4", "is Q9"), + ] + + def test_a_redirect_the_item_itself_is_filed_under_still_fits(self): + found = [("Q5", "Old name", "e.html"), ("Q6", "Other", "f.html")] + res = {"Old name": _res("Q50"), "Other": _res("Q60")} + bad = audit.audit( + found, res, lambda qids: {"Q5": "Old name", "Q6": "Not Other"} + ) + assert [b[0] for b in bad] == ["Q6"] + + +class ShelfTests(unittest.TestCase): + def test_games_that_had_no_article_do_not_claim_one(self): + rows = {r[2]: r for r in audit.entries()} + assert "puzzles/net.html" not in rows # NetWalk has no English article + assert ( + rows["tripeaks.html"][1] == "Tri Peaks (game)" + ) # "Tri Peaks" is a disambiguation page + assert ( + rows["blast.html"][0] == "Q3444160" + ) # the series; the 1990 item's page differs from the 1983 game + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_voices_setup_only.py b/tests/test_voices_setup_only.py new file mode 100644 index 000000000..b54c32cb2 --- /dev/null +++ b/tests/test_voices_setup_only.py @@ -0,0 +1,125 @@ +"""A voice whose files are here and whose engine is not needs one tap, not a download. + +The 1.16 Docker image no longer carries Piper and Kokoro. A data folder from the image before still has the +voices (files and installed.json) but no engines venv: the voice read as downloaded in the data and as not +there in the page, and Get did nothing, because the server answered "installed" before looking for the engine. + +Run: pytest tests/test_voices_setup_only.py -v +""" + +import os +import sys + +import pytest + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) +sys.path.insert(0, os.path.dirname(__file__)) + +from test_voices import _fake_build, bare, data # noqa: E402,F401 (fixtures) +from zimi import voices # noqa: E402 + + +def _put_files_here(tag): + """The voice as the old image left it: every pinned file at its pinned size, and its record.""" + pin = voices.VOICES[tag] + folder = voices._engine_dir(pin.engine) + os.makedirs(folder, exist_ok=True) + for name, _url, size in pin.files: + with open(os.path.join(folder, name), "wb") as f: + f.write(b"x" * size) + voices._set_installed( + pin.engine, + tag, + { + "id": pin.id, + "revision": pin.revision, + "bytes": voices._bytes(tag), + "files": [n for n, _u, _s in pin.files], + "voice": pin.voice, + }, + ) + + +@pytest.fixture +def no_network(monkeypatch): + def refuse(*a, **k): + raise AssertionError("a file that is already here was fetched again") + + monkeypatch.setattr(voices.urllib.request, "urlopen", refuse) + + +def test_the_row_says_needs_setup_with_the_engines_size_only(bare, monkeypatch): + monkeypatch.setattr(voices, "_kokoro_python", lambda: None) # Piper alone, so Piper is the offer + _put_files_here("fr") + row = {r["tag"]: r for r in voices.manage_payload()["voices"]}["fr"] + assert row["installed"] and row["needs_setup"] + assert ( + row["bytes"] == voices.setup_bytes(voices.PIPER) > 0 + ), "the engines, not the voice again" + lang = {r["lang"]: r for r in voices.manage_payload()["langs"]}["fr"] + assert lang["piper"]["tag"] == "fr" and lang["piper"]["setup"] + assert lang["piper"]["bytes"] == row["bytes"] + assert voices.page_payload()["offers"]["fr"]["bytes"] == row["bytes"] + + +def test_one_tap_sets_the_engine_up_and_fetches_nothing_again( + bare, no_network, monkeypatch +): + from zimi import importer + + _put_files_here("fr") + calls = [] + monkeypatch.setattr(importer, "build_venv", _fake_build(calls)) + assert voices.start_download("fr") == ( + True, + None, + ) # the old code answered (False, "installed") + voices._fetcher.join(10) + assert calls == [list(voices.ENGINE_REQUIREMENTS)] + assert voices.downloading() == {} + assert voices.piper_command() + row = {r["tag"]: r for r in voices.manage_payload()["voices"]}["fr"] + assert row["installed"] and not row["needs_setup"] + assert voices.start_download("fr") == ( + False, + "installed", + ), "and now it is simply there" + + +def test_a_failed_setup_says_why_and_keeps_the_files(bare, no_network, monkeypatch): + from zimi import importer + + _put_files_here("fr") + monkeypatch.setattr(importer, "build_venv", _fake_build([], ok=False)) + assert voices.start_download("fr")[0] + voices._fetcher.join(10) + assert voices.downloading()["error"] == "fr" and voices.downloading()["reason"] + assert "fr" in voices.installed() + assert {r["tag"]: r for r in voices.manage_payload()["voices"]}["fr"]["needs_setup"] + + +def test_automatically_sets_the_engine_up_on_the_first_word( + bare, no_network, monkeypatch +): + from zimi import importer, outbound + + _put_files_here("fr") + calls = [] + monkeypatch.setattr(importer, "build_venv", _fake_build(calls)) + monkeypatch.setattr(voices.POLICY, "mode", lambda: (outbound.AUTO, False)) + voices._maybe_fetch("fr", "") + voices._fetcher.join(10) + assert calls, "Automatically does what the tap does" + + +def test_a_voice_with_its_engine_is_not_offered_again(data, monkeypatch): + from test_voices import install + + install("en-US") + monkeypatch.setattr(voices, "runtime", lambda engine: ["/engine"]) + row = {r["tag"]: r for r in voices.manage_payload()["voices"]}["en-US"] + assert row["installed"] and not row["needs_setup"] + assert ( + "en" not in voices.page_payload()["offers"] + or voices.page_payload()["offers"]["en"]["tag"] != "en-US" + ) diff --git a/tests/test_voices_setup_only_browser.py b/tests/test_voices_setup_only_browser.py new file mode 100644 index 000000000..66cc3ba21 --- /dev/null +++ b/tests/test_voices_setup_only_browser.py @@ -0,0 +1,165 @@ +"""Settings > Voices, on a phone, for a voice whose files are here and whose engine is not. + +The 1.16 Docker image no longer carries Piper and Kokoro. A data folder from the image before keeps the voices. +Natural then read as not downloaded and Get did nothing. Now its row says Set up with the engines' size, one tap +sets them up (no model file is fetched again), and the voice is simply there. + +At 390x844. Run: pytest tests/test_voices_setup_only_browser.py -v +""" + +import os +import sys +import threading + +import pytest + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, ROOT) +sys.path.insert(0, os.path.dirname(__file__)) + +from test_voices import _fake_build, bare, data # noqa: E402,F401 (fixtures and helper) +from zimi import voices # noqa: E402 + +VIEW = {"width": 390, "height": 844} +SHOTS = os.environ.get("ZIMI_SHOTS", "") # a folder: keep the screenshots there +NATURAL = "#ms-voices-wrap .voice-engine[data-engine='kokoro']" +STATE_MS = 30_000 + + +def _natural_on_disk(): + """Natural as the old image left it: each pinned file at its size (sparse, so no disk), and the record.""" + pin = voices.VOICES[voices.KOKORO_TAG] + folder = voices._engine_dir(pin.engine) + os.makedirs(folder, exist_ok=True) + for name, _url, size in pin.files: + with open(os.path.join(folder, name), "wb") as f: + f.truncate(size) + voices._set_installed( + pin.engine, + voices.KOKORO_TAG, + { + "id": pin.id, + "revision": pin.revision, + "bytes": voices._bytes(voices.KOKORO_TAG), + "files": [n for n, _u, _s in pin.files], + "voice": pin.voice, + }, + ) + + +@pytest.fixture +def served(bare, monkeypatch): + import zimi.renderer as renderer + + if not renderer.browser_available(): + pytest.skip("playwright + chromium are not usable here") + from http.server import ThreadingHTTPServer + + from zimi.http import ZimHandler + + def refuse(*a, **k): + raise AssertionError("a file that is already here was fetched again") + + monkeypatch.setattr(voices.urllib.request, "urlopen", refuse) + _natural_on_disk() + httpd = ThreadingHTTPServer(("127.0.0.1", 0), ZimHandler) + threading.Thread(target=httpd.serve_forever, daemon=True).start() + yield "http://127.0.0.1:%d" % httpd.server_address[1] + httpd.shutdown() + + +def _shot(pg, name): + if SHOTS: + os.makedirs(SHOTS, exist_ok=True) + pg.screenshot(path=os.path.join(SHOTS, name + ".png")) + + +def test_natural_says_set_up_and_one_tap_brings_it_back(served, monkeypatch): + from playwright.sync_api import sync_playwright + + from zimi import importer + + calls = [] + build = _fake_build(calls) + release = threading.Event() + + def slow_build(*a, **k): + release.wait(20) # the page sees the setup while it runs + return build(*a, **k) + + monkeypatch.setattr(importer, "build_venv", slow_build) + setup_mb = "%d" % round(voices.setup_bytes(voices.KOKORO) / 1_000_000) + + with sync_playwright() as pw: + br = pw.chromium.launch() + try: + ctx = br.new_context( + viewport=VIEW, + device_scale_factor=2, + has_touch=True, + is_mobile=True, + service_workers="block", + ) + pg = ctx.new_page() + errors = [] + pg.on("pageerror", lambda e: errors.append(str(e))) + pg.goto(served + "/?manage=languages") + pg.wait_for_function("() => window._voicesHere", timeout=20000) + pg.wait_for_selector(NATURAL, timeout=STATE_MS) + pg.eval_on_selector( + "#ms-voices-wrap", "e => e.scrollIntoView({ block: 'start' })" + ) + # Not "Get ": the engines' size, worded as setting up. + label = pg.inner_text(NATURAL + " button[data-primary]") + assert "Set up" in label and setup_mb in label, label + assert not pg.query_selector( + NATURAL + " .voice-hear" + ), "it cannot be heard until the engine is there" + _shot(pg, "1-needs-setup") + + pg.tap(NATURAL + " button[data-primary]") + pg.wait_for_selector(NATURAL + " .voice-dl", timeout=STATE_MS) + assert pg.inner_text( + NATURAL + " .voice-progress" + ), "the setup shows on the page" + _shot(pg, "2-setting-up") + release.set() + pg.wait_for_selector(NATURAL + " .voice-hear", timeout=STATE_MS) + assert not pg.query_selector( + NATURAL + " button[data-primary]" + ), "no second Get once it is here" + _shot(pg, "3-there-again") + assert calls == [list(voices.ENGINE_REQUIREMENTS)] + assert not errors, errors + finally: + release.set() + br.close() + + +def test_a_failed_setup_shows_its_reason_and_a_retry(served, monkeypatch): + from playwright.sync_api import sync_playwright + + from zimi import importer + + monkeypatch.setattr(importer, "build_venv", _fake_build([], ok=False)) + with sync_playwright() as pw: + br = pw.chromium.launch() + try: + ctx = br.new_context( + viewport=VIEW, + device_scale_factor=2, + has_touch=True, + is_mobile=True, + service_workers="block", + ) + pg = ctx.new_page() + pg.goto(served + "/?manage=languages") + pg.wait_for_function("() => window._voicesHere", timeout=20000) + pg.wait_for_selector(NATURAL + " button[data-primary]", timeout=STATE_MS) + pg.tap(NATURAL + " button[data-primary]") + pg.wait_for_selector(".voice-problem", timeout=STATE_MS) + assert "failed" in pg.inner_text(".voice-problem").lower() + assert pg.inner_text(NATURAL + " button[data-primary]") == "Retry" + _shot(pg, "4-failed") + finally: + br.close() diff --git a/tests/test_zimi_home_line_browser.py b/tests/test_zimi_home_line_browser.py new file mode 100644 index 000000000..efe6fd30b --- /dev/null +++ b/tests/test_zimi_home_line_browser.py @@ -0,0 +1,251 @@ +"""The credit line ("© Zimi" after the mark, Zimi a link), drawn where the Games and the Almanac are read outside Zimi +(Kiwix, a browser tab) and never inside Zimi's reader: under the shelf's title, the foot of a game's Menu, the Almanac's foot. +The address is written once, in games/zimihome.js (the Almanac's ZIM carries a copy); the year is the build's, zimibuild.js, +which ownzims writes into each ZIM beside its Date. The mark sits on the digits, measured. + +Run: ZIMI_TORRENT=0 ZIMI_OFFLINE=1 pytest tests/test_zimi_home_line_browser.py -v +""" + +import os +import re +import sys +import tempfile + +import pytest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_games_persist_browser import GAMES, VIEW, browser, served # noqa: E402,F401 + + +def home_url(): + with open(os.path.join(GAMES, "zimihome.js"), encoding="utf-8") as f: + return re.search(r"ZIMI_HOME = '([^']+)'", f.read()).group(1) + + +# The mark's centre against the centre of the digits' height (baseline up to the top of "0"), in px: the optical seat. +MARK_OFFSET = """sel => { const line = document.querySelector(sel), img = line.querySelector('img'), span = line.querySelector('span'); + const probe = document.createElement('i'); probe.style.cssText = 'display:inline-block;width:0;height:0;vertical-align:baseline'; + span.appendChild(probe); const base = probe.getBoundingClientRect().bottom; probe.remove(); + const c = document.createElement('canvas').getContext('2d'); const cs = getComputedStyle(span); c.font = cs.fontWeight + ' ' + cs.fontSize + ' ' + cs.fontFamily; + const digits = c.measureText('0').actualBoundingBoxAscent; const r = img.getBoundingClientRect(); + return (r.top + r.height / 2) - (base - digits / 2); }""" + + +def test_outside_zimi_the_shelf_and_the_menu_credit_zimi(browser, served): + url = home_url() + ctx = browser.new_context(viewport=VIEW) + page = ctx.new_page() + # The year is the build's (zimibuild.js, which ownzims writes into the ZIM), never the reader's clock: a year no clock says. + page.route( + "**/zimibuild.js", + lambda r: r.fulfill( + body="window.ZIMI_BUILT_YEAR = 2031;\n", content_type="text/javascript" + ), + ) + page.goto("%s/index.html" % served) + line = page.wait_for_selector(".ar-shelf > .gs-home") + assert ( + line.is_visible() and line.inner_text().strip() == "© 2031 Zimi" + ), line.inner_text() + link = line.query_selector("a") + assert link.inner_text() == "Zimi" and link.get_attribute("href") == url + # The shelf's very last line: under Credits, nothing of the page below it. + below = page.evaluate( + "() => { const b = document.querySelector('.ar-shelf > .gs-home').getBoundingClientRect().bottom;" + " return Array.from(document.querySelectorAll('body *')).filter(e => e.offsetWidth && e.getBoundingClientRect().top >= b - 0.5" + " && !e.closest('.gs-home') && (e.innerText || '').trim()).map(e => e.innerText.trim().slice(0, 30)); }" + ) + assert below == [], below + assert page.evaluate( + "document.querySelector('.ar-shelf').lastElementChild.classList.contains('gs-home')" + ) + # The shipped default (zimihome.js ZIMI_HOME_MARK = 'none'): no mark in the line, the words alone. + assert line.query_selector("img") is None + page.goto("%s/chess.html" % served) + page.click(".gs-menu-btn") + menu_line = page.wait_for_selector(".gs-card .gs-home") + assert ( + menu_line.is_visible() + and menu_line.query_selector("a").get_attribute("href") == url + ) + assert "2031" in menu_line.inner_text() + assert menu_line.query_selector("img") is None + ctx.close() + + +def test_a_page_read_from_its_folder_has_no_year(browser, served): + ctx = browser.new_context(viewport=VIEW) + page = ctx.new_page() + page.goto("%s/index.html" % served) # no zimibuild.js in the source folder + line = page.wait_for_selector(".ar-shelf > .gs-home") + assert line.inner_text().strip() == "© Zimi" + ctx.close() + + +def test_the_build_writes_its_year_beside_the_date(): + import datetime + + from zimi import ownzims + from libzim.reader import Archive + + for own in ownzims.OWN: + archive = Archive(ownzims.zim_path(own)) + year = archive.get_metadata("Date").decode()[:4] + body = bytes( + archive.get_entry_by_path(ownzims.BUILD_FILE).get_item().content + ).decode() + assert body == "window.ZIMI_BUILT_YEAR = %s;\n" % year, (own.name, body) + assert int(year) <= datetime.date.today().year + + +def test_inside_zimis_reader_nothing_is_drawn(browser, served): + ctx = browser.new_context(viewport=VIEW) + page = ctx.new_page() + # Zimi's reader, as shell.js recognises it: a same-origin parent whose #reader-frame holds the page. + page.route( + "%s/host.html" % served, + lambda r: r.fulfill( + body='', + content_type="text/html", + ), + ) + page.goto("%s/host.html" % served) + frame = page.frame_locator("#reader-frame") + frame.locator(".ar-game").first.wait_for() + assert frame.locator(".gs-home").count() == 0 + inner = next(f for f in page.frames if f.url.endswith("/index.html")) + assert inner.evaluate("!!(window.ZimiShell && ZimiShell.hosted)") + assert inner.evaluate("typeof window.ZIMI_HOME") == "undefined" # not even fetched + ctx.close() + + +def test_the_almanac_carries_the_same_address(): + from zimi import almanacstage + + with tempfile.TemporaryDirectory() as tmp: + almanacstage.stage(tmp) + with ( + open(os.path.join(tmp, "zimihome.js"), encoding="utf-8") as f, + open(os.path.join(GAMES, "zimihome.js"), encoding="utf-8") as g, + ): + assert f.read() == g.read() + assert os.path.exists(os.path.join(tmp, "mark.svg")) + with open(os.path.join(tmp, "index.html"), encoding="utf-8") as f: + page = f.read() + assert ( + '' in page + and '' in page + ) + # The line is drawn by local.js: an href written in index.html's own script is a dead link to zimcheck. + assert "href=" not in page.split(" + + @@ -43,6 +61,7 @@
    +

    The Almanac needs scripts. In Kiwix JS, turn on ServiceWorker mode in Configuration.

    Loading the Almanac…
    @@ -53,12 +72,27 @@ // what needs a Zimi server or a library, and what stands in for it here. // // Not in this page, said plainly: links into an article library, the almanac's -// age table, the PDF reader, the account and settings sync, other languages than -// English. The satellites and the tide stations are packed in (data/, local.js). +// age table, the PDF reader, the account and settings sync. The satellites and the tide stations are packed in (data/, local.js). var _almanacOpen = false; var zimsCache = []; // no library here: every name in the Almanac stays plain text -var _currentLang = 'en'; +// The page's language: ?lang in the address's hash (#lang=de), else the first of the browser's languages that is one of the +// ten Zimi speaks, else English. English strings stand under every other language's (_i18nFallback). +var ALM_LANGS = ['ar', 'de', 'en', 'es', 'fr', 'he', 'hi', 'pt', 'ru', 'zh']; +var ALM_RTL_LANGS = ['ar', 'he']; +function _almPickLang() { + var want = [], m = /[#&]lang=([a-z]{2})/i.exec(location.hash); + if (m) want.push(m[1]); + try { want = want.concat(navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language]); } catch (e) {} + for (var i = 0; i < want.length; i++) { + var primary = String(want[i] || '').split('-')[0].toLowerCase(); + if (ALM_LANGS.indexOf(primary) >= 0) return primary; + } + return 'en'; +} +var _currentLang = _almPickLang(); +document.documentElement.lang = _currentLang; +if (ALM_RTL_LANGS.indexOf(_currentLang) >= 0) document.documentElement.setAttribute('dir', 'rtl'); var _i18n = {}; var _i18nFallback = {}; var _ALM_TIDES_JS = 'almanac-tides.js'; @@ -74,21 +108,22 @@ function tH(key, vars) { return _htmlEsc(t(key, vars)); } function tPlural(base, n, vars) { var cat = 'other'; - try { cat = new Intl.PluralRules('en').select(Number(n) || 0); } catch (e) {} + try { cat = new Intl.PluralRules(_uiLangPrimary()).select(Number(n) || 0); } catch (e) {} var key = base + '_' + cat; if (_i18n[key] === undefined && _i18nFallback[key] === undefined) key = base + '_other'; - var v = { n: typeof n === 'number' ? n.toLocaleString('en') : n }; + var v = { n: typeof n === 'number' ? fmtNum(n) : n }; if (vars) for (var k in vars) v[k] = vars[k]; return t(key, v); } function esc(s) { return String(s == null ? '' : s).replace(/&/g, '&').replace(//g, '>'); } function escAttr(s) { return esc(s).replace(/'/g, ''').replace(/"/g, '"'); } -function cmpText(a, b) { return new Intl.Collator('en', { numeric: true }).compare(a == null ? '' : String(a), b == null ? '' : String(b)); } +function cmpText(a, b) { return new Intl.Collator(_uiLocale(), { numeric: true }).compare(a == null ? '' : String(a), b == null ? '' : String(b)); } function _langPrimary(tag) { return String(tag || '').split('-')[0]; } -function _uiLangPrimary() { return 'en'; } +function _uiLangPrimary() { return String(_currentLang || 'en').split('-')[0]; } +// The language, in the browser's region when the browser speaks that language (en-GB: 20/10/2026), else the language. function _uiLocale() { - var phone = (typeof navigator !== 'undefined' && navigator.language) || ''; - return _langPrimary(phone).toLowerCase() === 'en' ? phone : 'en'; + var lang = _uiLangPrimary(), phone = (typeof navigator !== 'undefined' && navigator.language) || ''; + return _langPrimary(phone).toLowerCase() === lang ? phone : lang; } function _setWindowTitle(title) { document.title = title; } function _showToast(msg) { @@ -113,6 +148,11 @@ return !!f && f.contentWindow === window && typeof window.parent.openReader === 'function'; } catch (e) { return false; } })(); +// Kiwix JS draws a toolbar of this height over the bottom of the page's frame; kiwix-serve's viewer (/content/) does not. +var KIWIX_JS_TOOLBAR_PX = 48; +if (!HOSTED_IN_ZIMI && window.parent !== window && location.pathname.indexOf('/content/') < 0) { + document.documentElement.style.setProperty('--host-bottom', KIWIX_JS_TOOLBAR_PX + 'px'); +} var PDF_URL = '/almanac/pdf'; if (HOSTED_IN_ZIMI) { window.openReader = function(url) { window.parent.openReader(url); }; @@ -161,7 +201,12 @@ } (function() { - var strings = fetch('i18n/en.json').then(function(r) { return r.json(); }).then(function(d) { _i18n = d; }, function() {}); + // A language's strings, or null when they cannot be had (a missing file, a bad answer): English stands under it then. + function words(lang) { return fetch('i18n/' + lang + '.json').then(function(r) { return r.ok ? r.json() : null; }).catch(function() { return null; }); } + var strings = Promise.all([words('en'), _currentLang === 'en' ? null : words(_currentLang)]).then(function(got) { + _i18nFallback = got[0] || {}; + _i18n = got[1] || _i18nFallback; + }); strings.then(function() { return loadScripts(['shell.js'].concat(ALMANAC_SCRIPTS)); }).then(function() { _openAlmanacInner(true); }).catch(function(e) { diff --git a/zimi/builtin/almanac/local.js b/zimi/builtin/almanac/local.js index 255e07cd3..cdd900961 100644 --- a/zimi/builtin/almanac/local.js +++ b/zimi/builtin/almanac/local.js @@ -136,4 +136,16 @@ }; Local._prepare = prepare; root.ZimiAlmanacLocal = Local; + + // Outside Zimi, the foot of the Almanac carries the credit line "© Zimi" (zimihome.js's ZIMI_HOME_MARK can add the + // mark before or after the name, one link with it): the address is zimihome.js's (the Games' file, staged in), the year the + // build's (zimibuild.js, written into the ZIM by ownzims), never the reader's clock. Inside Zimi's reader nothing is drawn. + // Here, not in index.html: zimcheck reads an href written in the page's own script as a link of the page. + root._almHomeLine = function () { + var url = root.ZIMI_HOME, year = root.ZIMI_BUILT_YEAR, at = root.ZIMI_HOME_MARK, esc = root.esc, escAttr = root.escAttr; + if (root.HOSTED_IN_ZIMI || !url) return ''; + var mark = at === 'before' || at === 'after' ? '' : ''; + return '
    © ' + (year ? esc(year) + ' ' : '') + '' + + (at === 'after' ? 'Zimi' + mark : mark + 'Zimi') + '
    '; + }; })(typeof window !== 'undefined' ? window : globalThis); diff --git a/zimi/builtin/almanac/zimi.txt b/zimi/builtin/almanac/zimi.txt index aead9cd57..6ddeb8e5a 100644 --- a/zimi/builtin/almanac/zimi.txt +++ b/zimi/builtin/almanac/zimi.txt @@ -1,8 +1,11 @@ Title: Almanac · Zimi -Description: Explore the sky, your planet and the universe, for any place and day, offline +Description: Explore the sky, your planet and the universe, for any place and day +LongDescription: A reference for space and time, worked out fresh for any place and any day. It runs from this file in a web browser, with no network: Moon phase, Sun and Moon rise and set, a live sky of stars and planets, the solar system, a 3D Earth, Moon and planets with the satellites over them, tides, calendars and tables. It follows the browser's language: Arabic, Chinese, English, French, German, Hebrew, Hindi, Portuguese, Russian or Spanish, with English where the browser speaks none of them. Every figure is computed in the page; the data it needs is inside the ZIM. This is the standard edition, without the high-resolution map tiles. In Kiwix JS it needs ServiceWorker mode (in Configuration); without scripts it shows a short note. It also opens in kiwix-serve. Code: GPL-3.0-or-later (Zimi). Data and libraries keep their own licences, listed in earth/SOURCES.txt inside the ZIM: NASA imagery and the Yale Bright Star Catalogue (public domain), ESO Milky Way panorama (CC BY 4.0), three.js and satellite.js (MIT), d3-celestial (BSD 3-Clause), Temml (MIT), CelesTrak satellite elements (a snapshot) and NOAA tide data (a snapshot). Voyager Golden Record pictures (golden-record/credits.json): all 49 shown, each with its credit; 8 are NASA photographs (public domain) and the other 41 are copyright their owners: Jon Lomberg, UN Photo, Frank Drake, the National Astronomy and Ionosphere Center, Jay M. Pasachoff and Picturepoint, London. Language: eng Creator: Zimi Publisher: Zimi Tags: _category:education;astronomy;zimi;zimi:own +License: GPL-3.0-or-later; third-party licences inside the ZIM +Source: https://github.com/epheterson/zimi Icon: icon.png Articles: index.html diff --git a/zimi/builtin/games/about.html b/zimi/builtin/games/about.html index d8e2caea7..a1704010b 100644 --- a/zimi/builtin/games/about.html +++ b/zimi/builtin/games/about.html @@ -19,7 +19,7 @@

    About