test.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. """Static verification of /cmd_check_tool runtime path (without actually pulling)."""
  3. import sys, re, os, subprocess
  4. err = []
  5. src_path = "core/webgui.py"
  6. with open(src_path, encoding="utf-8") as f:
  7. src = f.read()
  8. m = re.search(r'if page == "/cmd_check_tool":\s*\n\s+self\.pages\["/cmd_check_tool"\]\s*=\s*"([^"]+)"', src)
  9. if not m:
  10. err.append("/cmd_check_tool handler not found in webgui.py")
  11. else:
  12. placeholder = m.group(1)
  13. if "Waiting" not in placeholder:
  14. err.append("/cmd_check_tool placeholder missing 'Waiting': " + placeholder)
  15. m2 = re.search(r'if page == "/cmd_check_tool":[\s\S]{0,600}', src)
  16. if not m2:
  17. err.append("/cmd_check_tool runcmd not found near handler")
  18. else:
  19. region = m2.group(0)
  20. if "ufonet --update" not in region:
  21. err.append("runcmd doesn't call 'ufonet --update'")
  22. if "/tmp/out" not in region:
  23. err.append("runcmd doesn't redirect to /tmp/out")
  24. if not re.search(r'if page == "/cmd_check_tool_update":', src):
  25. err.append("/cmd_check_tool_update handler missing")
  26. with open("core/update.py", encoding="utf-8") as f:
  27. upd = f.read()
  28. if "git pull" not in upd:
  29. err.append("update.py doesn't invoke 'git pull'")
  30. if "github.com/epsylon/ufonet" not in upd:
  31. err.append("update.py missing GitHub mirror URL")
  32. r = subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], capture_output=True, text=True)
  33. if r.returncode != 0 or "true" not in r.stdout:
  34. err.append("Not inside a git working tree; --update would fail on this checkout")
  35. print(f"webgui /cmd_check_tool handler: OK={m is not None}")
  36. print(f"webgui runcmd build: OK={m2 is not None}")
  37. print(f"update.py git pull present: OK={'git pull' in upd}")
  38. print(f"inside git workdir: OK={r.returncode == 0}")
  39. for e in err:
  40. print("FAIL:", e)
  41. sys.exit(0 if not err else 1)