From 34d74cba0421ac88505ac620158882f90cf5db7e Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Sat, 19 Sep 2026 17:22:20 +0200 Subject: fix(hub): a track with no artist tag reaches the Music grid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The grid's unit is an album, so a track whose artist tag is empty was drawn nowhere — while `empty` counted it and stayed false, so no message appeared either. An untagged library rendered a toolbar over a blank page, with every track one mode-switch away and nothing saying so. It gets a card, the same shape the singleton folding already mints. No cover is looked up for it, or for any album this file invented: the release name is one the browser wrote, and the request cannot match. music_untagged_probe.py renders the real grid and reads the page back. Co-Authored-By: Claude Opus 5 --- .../tests/harness/music_untagged_probe.py | 283 +++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 packages/meshbay-hub/tests/harness/music_untagged_probe.py (limited to 'packages/meshbay-hub/tests/harness') diff --git a/packages/meshbay-hub/tests/harness/music_untagged_probe.py b/packages/meshbay-hub/tests/harness/music_untagged_probe.py new file mode 100644 index 0000000..f4c484c --- /dev/null +++ b/packages/meshbay-hub/tests/harness/music_untagged_probe.py @@ -0,0 +1,283 @@ +#!/usr/bin/env python3 +""" +What the Music tab draws when a track carries no artist tag. + +The grid's unit is an album, and a track with no artist at all belongs to +none — so it was drawn nowhere, while `empty` counted it and therefore stayed +false. A library nothing has tagged rendered a toolbar over a blank page with +no message, every one of its tracks reachable only by switching to the flat +list and nothing on screen saying so. + +Reading `music-app.js` does not show this: both halves are correct on their own +and the fault is that they disagree about what "nothing" means. So this renders +the shipped `GroupPage` against a stub node and reads back what is actually on +the page — cards, messages, and the rows the flat list draws for the same +entries. + + music_untagged_probe.py +""" + +import http.server +import json +import socketserver +import subprocess +import sys +import tempfile +import threading +import time +from pathlib import Path + +STATIC = Path(__file__).resolve().parents[2] / "src" / "meshbay_hub" / "static" +PORT = 8759 +RECORDS = [] +socketserver.TCPServer.allow_reuse_address = True + +# (name, tagged albums of three tracks, tracks with no artist at all, +# one-track albums under a single artist) +CASES = [ + # The reported shape: a node serving an index it has not re-read the tags + # for yet, and a genuinely untagged library, are the same page. + ("nothing tagged", 0, 7, 0), + # The ordinary shape — the pile must not displace real albums. + ("some tagged", 3, 4, 0), + # Nothing at all: the one case that really is empty, and must say so. + ("no audio", 0, 0, 0), + # The *other* album this file invents: one artist's one-track albums, folded + # into a single " - Various" card. A real release name nowhere, so + # a cover lookup for it cannot match — and this case is the only one that + # can tell that gate from a card that was simply never drawn. + ("singletons only", 0, 0, 3), +] + +FRAME = r""" + + +
+ +""" + +PAGE = r""" +
""" + + +class H(http.server.BaseHTTPRequestHandler): + def log_message(self, *a): + pass + + def do_POST(self): + length = int(self.headers.get("Content-Length") or 0) + if self.path == "/log": + RECORDS.extend(json.loads(self.rfile.read(length).decode())) + else: + self.rfile.read(length) + self.send_response(204) + self.end_headers() + + def _send(self, body: bytes, ctype: str) -> None: + self.send_response(200) + self.send_header("Content-Type", ctype) + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def do_GET(self): + path = self.path.split("?")[0] + if path == "/": + self._send((PAGE % {"count": len(CASES)}).encode(), "text/html; charset=utf-8") + elif path == "/case": + n = int(self.path.split("n=")[1]) + _, albums, loose, singles = CASES[n] + body = FRAME % {"index": n, "albums": albums, "loose": loose, + "singles": singles} + self._send(body.encode(), "text/html; charset=utf-8") + elif path == "/v1/groups/g1/nodes": + self._send(b'{"nodes": [{"node_id": "n1"}]}', "application/json") + else: + asset = (STATIC / path.lstrip("/")).resolve() + if not str(asset).startswith(str(STATIC)) or not asset.is_file(): + self.send_response(404) + self.end_headers() + return + self._send(asset.read_bytes(), + "text/css" if asset.suffix == ".css" + else "text/javascript" if asset.suffix == ".js" + else "application/octet-stream") + + +def main() -> int: + with socketserver.TCPServer(("127.0.0.1", PORT), H) as srv: + threading.Thread(target=srv.serve_forever, daemon=True).start() + with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as profile: + proc = subprocess.Popen( + ["google-chrome", "--headless=new", "--disable-gpu", "--no-sandbox", + f"--user-data-dir={profile}", "--window-size=1100,900", + f"http://127.0.0.1:{PORT}/"], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + deadline = time.time() + 120 + while len(RECORDS) < len(CASES) and time.time() < deadline: + time.sleep(0.2) + proc.terminate() + proc.wait(timeout=20) + if len(RECORDS) < len(CASES): + print(f"only {len(RECORDS)} of {len(CASES)} cases reported", file=sys.stderr) + print(json.dumps(RECORDS, indent=1), file=sys.stderr) + return 1 + out = [] + for rec in sorted(RECORDS, key=lambda r: r["case"]): + out.append({**rec, "name": CASES[rec["case"]][0]}) + print(json.dumps(out)) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) -- cgit v1.2.3