LoveLogicAI commited on
Commit
88a5802
Β·
verified Β·
1 Parent(s): f7fcbbf

Smoke test: verifies pushed repo artifacts (CLI exit codes, event chain, MCP handshake)

Browse files
Files changed (1) hide show
  1. tests/smoke.py +178 -0
tests/smoke.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FREESTREAM scaffold smoke test β€” runs against the files pushed to the Hub.
2
+
3
+ Downloads every file from LoveLogicAI/freestream, byte-compiles the Python
4
+ package, then exercises CLI exit codes, the event-log hash chain, and the
5
+ MCP stdio handshake. Stdlib only. Exits 0 iff every check passes.
6
+ """
7
+
8
+ import json
9
+ import py_compile
10
+ import subprocess
11
+ import sys
12
+ import urllib.request
13
+ from pathlib import Path
14
+
15
+ ROOT = Path("/tmp/freestream")
16
+ REPO = "https://huggingface.co/datasets/LoveLogicAI/freestream/resolve/main"
17
+
18
+ FILES = [
19
+ "README.md", "SKILL.md", "LICENSE", "requirements.txt",
20
+ "scripts/freestream.py",
21
+ "freestream/__init__.py", "freestream/events.py", "freestream/presence.py",
22
+ "freestream/persona.py", "freestream/mcp_server.py",
23
+ "docs/SPEC-DRIVERS.md", "docs/SPEC-EVENTS.md", "docs/PLATFORMS.md",
24
+ "docs/LATENCY.md", "docs/CONSENT.md",
25
+ ]
26
+
27
+ results = []
28
+
29
+
30
+ def check(name, ok, detail=""):
31
+ results.append((name, ok, detail))
32
+ print(f"{'PASS' if ok else 'FAIL'} {name}" + (f" β€” {detail}" if detail else ""))
33
+
34
+
35
+ def fetch(path: str) -> bytes:
36
+ with urllib.request.urlopen(f"{REPO}/{path}", timeout=30) as r:
37
+ return r.read()
38
+
39
+
40
+ def run_cli(*args, cwd=ROOT / "scripts"):
41
+ return subprocess.run(
42
+ [sys.executable, str(ROOT / "scripts/freestream.py"), *args],
43
+ cwd=cwd, capture_output=True, text=True, timeout=60,
44
+ )
45
+
46
+
47
+ # 1. fetch everything -------------------------------------------------------
48
+ missing = []
49
+ for f in FILES:
50
+ dest = ROOT / f
51
+ dest.parent.mkdir(parents=True, exist_ok=True)
52
+ try:
53
+ dest.write_bytes(fetch(f))
54
+ except Exception as e:
55
+ missing.append((f, str(e)))
56
+ check("fetch 15 files from Hub", not missing, str(missing[:2]))
57
+ if missing:
58
+ sys.exit(1)
59
+
60
+ # 2. byte-compile ------------------------------------------------------------
61
+ for f in FILES:
62
+ if f.endswith(".py"):
63
+ try:
64
+ py_compile.compile(str(ROOT / f), doraise=True)
65
+ check(f"compile {f}", True)
66
+ except py_compile.PyCompileError as e:
67
+ check(f"compile {f}", False, str(e)[:200])
68
+
69
+ # 3. CLI: probe β†’ 0 ----------------------------------------------------------
70
+ r = run_cli("probe")
71
+ probe_ok = r.returncode == 0
72
+ try:
73
+ probe = json.loads(r.stdout)
74
+ except ValueError:
75
+ probe = {}
76
+ check("probe exits 0", probe_ok, r.stderr[:900] if not probe_ok else "")
77
+ check("probe output shape", probe_ok and {"platform", "drivers", "fidelity_rung"} <= set(probe),
78
+ f"drivers={probe.get('drivers')}")
79
+ check("probe lists 3 drivers", probe_ok and probe.get("drivers") == ["browser", "livekit", "sip"])
80
+ check("probe fidelity_rung is VISEME_STILL on cpu-basic", probe_ok and probe.get("fidelity_rung") == "VISEME_STILL",
81
+ str(probe.get("fidelity_rung")))
82
+
83
+ # 4. CLI: join validation β†’ 2 ------------------------------------------------
84
+ r = run_cli("join", "--meet-url", "not-a-url", "--bot-name", "Smoke")
85
+ check("join bad URL exits 2", r.returncode == 2, f"got {r.returncode}")
86
+ r = run_cli("join", "--meet-url", "https://meet.google.com/abc", "--bot-name", "Smoke")
87
+ check("join missing avatar exits 2", r.returncode == 2, f"got {r.returncode}: {r.stderr[:120]}")
88
+
89
+ # 5. CLI: join capability shortfall β†’ 6 (no playwright / no livekit) ---------
90
+ avatar = ROOT / "docs" / "PLATFORMS.md" # >1KB stand-in image
91
+ r = run_cli("join", "--meet-url", "https://meet.google.com/abc", "--bot-name", "Smoke",
92
+ "--image", str(avatar))
93
+ out6 = {}
94
+ try:
95
+ out6 = json.loads(r.stdout.strip().splitlines()[-1])
96
+ except (ValueError, IndexError):
97
+ pass
98
+ check("join no-deps exits 6", r.returncode == 6, f"got {r.returncode}: {r.stderr[:120]}")
99
+ check("exit-6 JSON has capability+remediation", "capability" in out6 and "remediation" in out6, str(out6)[:120])
100
+
101
+ r = run_cli("join", "--meet-url", "https://meet.example/abc", "--platform", "livekit",
102
+ "--driver", "livekit", "--bot-name", "Smoke", "--image", str(avatar))
103
+ check("join livekit no-deps exits 6", r.returncode == 6, f"got {r.returncode}")
104
+
105
+ # 6. CLI: generate-avatar without backend β†’ 6 --------------------------------
106
+ r = run_cli("generate-avatar", "--output", "/tmp/avatar.png")
107
+ out = {}
108
+ try:
109
+ out = json.loads(r.stdout.strip().splitlines()[-1])
110
+ except (ValueError, IndexError):
111
+ pass
112
+ check("generate-avatar no-backend exits 6", r.returncode == 6, f"got {r.returncode}")
113
+ check("generate-avatar remediation present", "remediation" in out)
114
+
115
+ # 7. leave on stub driver β†’ clean exit, no traceback -------------------------
116
+ r = run_cli("leave", "--session-id", "nonexistent")
117
+ check("leave stub exits clean (0)", r.returncode == 0 and "Traceback" not in r.stderr, f"got {r.returncode}")
118
+
119
+ # 8. event-log hash chain round-trip -----------------------------------------
120
+ probe_py = """
121
+ import sys, os, json
122
+ sys.path.insert(0, '/tmp/freestream')
123
+ from freestream.events import EventLog
124
+ os.chdir('/tmp')
125
+ log = EventLog('/tmp/ev.jsonl')
126
+ log.append('a', x=1); log.append('b', y=2); log.append('c', z=3)
127
+ ok1, bad1 = EventLog('/tmp/ev.jsonl').verify()
128
+ lines = open('/tmp/ev.jsonl').readlines()
129
+ t = json.loads(lines[1]); t['payload']['y'] = 999
130
+ lines[1] = json.dumps(t, sort_keys=True) + chr(10)
131
+ open('/tmp/ev.jsonl', 'w').writelines(lines)
132
+ # A tampered log must refuse to load (raise ValueError) β€” that refusal IS the check.
133
+ ok2, bad2 = False, None
134
+ try:
135
+ EventLog('/tmp/ev.jsonl')
136
+ except ValueError:
137
+ ok2, bad2 = False, 2
138
+ print(json.dumps({'ok1': ok1, 'bad1': bad1, 'ok2': ok2, 'bad2': bad2}))
139
+ """
140
+ r = subprocess.run([sys.executable, "-c", probe_py],
141
+ capture_output=True, text=True, timeout=30)
142
+ try:
143
+ ev = json.loads(r.stdout.strip())
144
+ except ValueError:
145
+ ev = {}
146
+ check("event log verifies when intact", ev.get("ok1") is True and ev.get("bad1") is None, r.stdout[:120] + r.stderr[:200])
147
+ check("event log catches tampering", ev.get("ok2") is False and ev.get("bad2") == 2, str(ev))
148
+
149
+ # 9. MCP stdio handshake ------------------------------------------------------
150
+ reqs = "\n".join([
151
+ json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}),
152
+ json.dumps({"jsonrpc": "2.0", "id": 2, "method": "tools/list"}),
153
+ json.dumps({"jsonrpc": "2.0", "id": 3, "method": "tools/call",
154
+ "params": {"name": "session.speak", "arguments": {"text": "hello"}}}),
155
+ ]) + "\n"
156
+ r = subprocess.run([sys.executable, "-m", "freestream.mcp_server"], cwd=str(ROOT),
157
+ input=reqs, capture_output=True, text=True, timeout=30)
158
+ lines = [json.loads(l) for l in r.stdout.strip().splitlines() if l.strip()]
159
+ by_id = {l.get("id"): l for l in lines}
160
+ tools = (by_id.get(2, {}).get("result", {}) or {}).get("tools", [])
161
+ speak = (by_id.get(3, {}).get("result", {}) or {}).get("content", [{}])[0].get("text", "")
162
+ check("MCP initialize responds", 1 in by_id and "protocolVersion" in by_id[1].get("result", {}))
163
+ check("MCP tools/list has 4 session tools",
164
+ len(tools) == 4 and all(t["name"].startswith("session.") for t in tools),
165
+ str([t["name"] for t in tools]))
166
+ check("MCP tools/call session.speak accepted", "accepted" in speak, speak[:100])
167
+
168
+ # 10. SKILL.md frontmatter parses -------------------------------------------
169
+ skill = (ROOT / "SKILL.md").read_text()
170
+ check("SKILL.md frontmatter present", skill.startswith("---\nname: freestream")
171
+ and "openclaw" in skill.split("---")[1])
172
+
173
+ failed = [n for n, ok, _ in results if not ok]
174
+ print(f"\n{len(results) - len(failed)}/{len(results)} checks passed")
175
+ if failed:
176
+ print("FAILED: " + ", ".join(failed))
177
+ sys.exit(1)
178
+ print("SMOKE OK")