#!/usr/bin/env python3 """ harness_cube_panel.py - REAL verification harness for the CUBE (Squared Plus) control-panel circuit. Asserts on every check; exits non-zero on any failure. Circuit exercised (end-to-end, against the LIVE system): A. FRONTEND - both consoles served; renamed to CUBE; HTML well-formed (validated by stdlib HTMLParser; node is root-only here). B. BACKEND - full worker-profile loop via /api/cube-vm/*: create -> list(shows) -> read(matches) -> status(running) -> delete -> list(gone). C. PERSIST - schematic DUAL-CUBE-WORKING-PLAN title == CUBE (Squared Plus); project-continuity registry seeded. D. SYSTEMD - both refresh timers enabled+active; last service fire exit 0. """ import os, sys, json, base64, subprocess, urllib.request, datetime, socket from html.parser import HTMLParser API = "http://127.0.0.1" SOCK = ( os.environ.get("CUBE_SOCKET") or "/run/user/1000/cubelinux/cubed-names.sock" ) NS_SCHEMA = "cube-schematic" NS_PROJ = "project-continuity" TEST_ID = "_harness_%d" % os.getpid() results = [] def check(name, ok, detail=""): results.append((name, ok, detail)) line = (" PASS " if ok else " FAIL ") + name if (not ok) and detail: line += " -- " + detail print(line) return ok def cubed_rpc(req, timeout=5): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM); s.settimeout(timeout) s.connect(SOCK); s.sendall((json.dumps(req) + "\n").encode()) buf = b"" while b"\n" not in buf: c = s.recv(4096) if not c: break buf += c s.close(); return json.loads(buf.split(b"\n", 1)[0]) def get_json(path): return json.loads(urllib.request.urlopen(API + path, timeout=5).read().decode()) def post_json(path, body): req = urllib.request.Request(API + path, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"}, method="POST") return json.loads(urllib.request.urlopen(req, timeout=10).read().decode()) def html_well_formed(url): """Real HTML well-formedness via stdlib HTMLParser (tag balance, no stray closes).""" class V(HTMLParser): def __init__(s): super().__init__(convert_charrefs=True) s.void = {'meta','link','br','img','input','hr','area','base', 'col','embed','source','track','wbr','!doctype'} s.stack = []; s.errs = [] def handle_starttag(s, t, a): if t not in s.void: s.stack.append(t) def handle_endtag(s, t): if t in s.void: return if s.stack and s.stack[-1] == t: s.stack.pop() elif t in s.stack: while s.stack and s.stack.pop() != t: pass else: s.errs.append(t) try: data = urllib.request.urlopen(url, timeout=10).read().decode("utf-8", "replace") except Exception: return False v = V(); v.feed(data) return (not v.stack) and (not v.errs) def systemd_state(unit): en = subprocess.run(["systemctl", "--user", "is-enabled", unit], capture_output=True, text=True).stdout.strip() ac = subprocess.run(["systemctl", "--user", "is-active", unit], capture_output=True, text=True).stdout.strip() res = subprocess.run(["systemctl", "--user", "show", "-p", "Result", unit.replace(".timer", ".service")], capture_output=True, text=True).stdout.strip() return en, ac, res def circuit(): ok_all = True print("\n[A] FRONTEND") idx = urllib.request.urlopen(API + "/", timeout=5).read().decode() vm = urllib.request.urlopen(API + "/cube-vm.html", timeout=5).read().decode() ok_all &= check("console served + renamed CUBE⊞", "CUBE⊞ · Squared Plus · AI Command Center" in idx, "title mark missing") ok_all &= check("panel served + renamed CUBE⊞", "