""" Every way a file is saved goes through a name that can be written everywhere (docs/MESHBAY_DESIGN.md ยง10, `static/portable-name.js`). The rule itself is held to Python's by `test_portable_name_parity.py`. What this holds is that the save paths use it: a single file under `portableName`, the entries of a folder's zip and the archive's own name under `portablePath` / `portableName`, and the node's own name never handed to a save target directly. Read from the source, because these paths need a browser and a disk to run. """ import re from pathlib import Path STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static" FILE_UTILS = (STATIC / "file-utils.js").read_text(encoding="utf-8") def _body(name: str) -> str: m = re.search(rf"^async function {name}\(.*?^\}}", FILE_UTILS, re.M | re.S) assert m, f"file-utils.js no longer has {name}" return m.group(0) def test_a_single_file_is_saved_under_a_portable_name(): body = _body("downloadEntry") assert "portableName(entry.name)" in body assert "_openTargetInTurn(saveName" in body assert "_saveBlob(blob, saveName)" in body assert "_openTargetInTurn(entry.name" not in body assert "_saveBlob(blob, entry.name)" not in body def test_a_zip_writes_portable_names_and_is_named_portably(): body = _body("downloadDirectory") assert "zip.begin(portablePath(name)" in body assert "portableName(dir.split('/').pop()" in body def test_a_renamed_file_is_said_so_on_its_row(): assert "t('transfers.renamed'" in _body("downloadEntry") assert "t('transfers.renamed_n'" in _body("downloadDirectory")