douyinWEB/scripts/_selftest_neko5.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

111 lines
4.1 KiB
Python

# -*- coding: utf-8 -*-
"""Honest end-to-end self-test for neko/5 vs neko/1."""
from __future__ import annotations
import json
import re
import sys
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def check_public(c: httpx.Client, path: str) -> dict:
# no follow first
r0 = c.get(f"https://dy.nomadro.com{path}", follow_redirects=False)
r = c.get(f"https://dy.nomadro.com{path}", follow_redirects=True)
assets = re.findall(r'(?:src|href)=["\']([^"\']+)["\']', r.text)
rel = [a for a in assets if not a.startswith("http") and not a.startswith("data:")]
ok_assets = 0
bad_assets = []
base = str(r.url)
if not base.endswith("/"):
base = base.rsplit("/", 1)[0] + "/"
for a in rel:
if a.startswith("/"):
url = f"https://dy.nomadro.com{a}"
else:
url = base + a
ar = c.get(url)
if ar.status_code == 200 and len(ar.content) > 100:
ok_assets += 1
else:
bad_assets.append((a, ar.status_code, len(ar.content), url))
return {
"path": path,
"bare_status": r0.status_code,
"bare_loc": r0.headers.get("location"),
"final": str(r.url),
"html": r.status_code,
"html_len": len(r.content),
"assets_ok": ok_assets,
"assets_bad": bad_assets[:8],
"has_noscript_blurb": "self hosted virtual browser" in r.text.lower(),
}
def main():
print("=== PUBLIC ===")
with httpx.Client(timeout=30, verify=True) as c:
for p in ["/neko/5", "/neko/5/", "/neko/1/", "/neko/6/"]:
try:
print(json.dumps(check_public(c, p), ensure_ascii=False, indent=2))
except Exception as e:
print(p, "ERR", type(e).__name__, e)
print("\n=== PHYSICAL ===")
g = paramiko.SSHClient()
g.set_missing_host_key_policy(paramiko.AutoAddPolicy())
g.connect("107.173.30.245", 4014, "eric", "4669805", timeout=45, allow_agent=False, look_for_keys=False)
cmd = r"""
echo '4669805' | sudo -S -p '' bash -lc '
set -e
echo --- services ---
systemctl is-active douyinweb-api || true
ss -lntp | grep -E ":9199|:9204|:9200" || true
echo --- docker ---
docker ps -a --filter name=douyinweb-neko- --format "{{.Names}} {{.Status}}" | sort
echo --- redirect ---
curl -sS -m 5 -D - -o /dev/null http://127.0.0.1:9199/neko/5 | head -15
echo --- gateway html asset path ---
curl -sS -m 5 http://127.0.0.1:9199/neko/5/ | grep -oE "src=\"[^\"]+\"" | head
echo --- gateway js ---
curl -sS -m 5 -o /dev/null -w "gw_js=%{http_code} size=%{size_download}\n" http://127.0.0.1:9199/neko/5/js/app.5d9731bf.js
echo --- direct js ---
curl -sS -m 5 -o /dev/null -w "dir_js=%{http_code} size=%{size_download}\n" http://127.0.0.1:9204/js/app.5d9731bf.js
echo --- wg from overseas perspective via local ---
curl -sS -m 5 -o /dev/null -w "local5=%{http_code}\n" http://127.0.0.1:9204/
echo --- gateway logs / api journal ---
journalctl -u douyinweb-api -n 40 --no-pager | tail -40
'
"""
_, o, e = g.exec_command(cmd, timeout=90)
print((o.read() + e.read()).decode("utf-8", "replace"))
g.close()
v = paramiko.SSHClient()
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
_, o, e = v.exec_command(
r"""
echo --- caddy neko ---
grep -nE 'neko|9199' /etc/caddy/sites/dy.nomadro.com.caddy
echo --- from vps via wg to gateway ---
curl -sS -m 8 -D - -o /dev/null http://10.8.0.2:9199/neko/5 | head -15
curl -sS -m 8 -o /dev/null -w "wg_slash=%{http_code}\n" http://10.8.0.2:9199/neko/5/
curl -sS -m 8 -o /dev/null -w "wg_js=%{http_code} size=%{size_download}\n" http://10.8.0.2:9199/neko/5/js/app.5d9731bf.js
curl -sS -m 8 -o /dev/null -w "pub5=%{http_code} url=%{url_effective}\n" -L https://dy.nomadro.com/neko/5
curl -sS -m 8 -o /dev/null -w "pub5js=%{http_code} size=%{size_download}\n" https://dy.nomadro.com/neko/5/js/app.5d9731bf.js
""",
timeout=60,
)
print("\n=== OVERSEAS ===")
print((o.read() + e.read()).decode("utf-8", "replace"))
v.close()
if __name__ == "__main__":
main()