smoke-addon.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. # Smoke test for the sm121 add-on image (specs/tech-architecture/
  3. # ha-addon-recipe-repos.md): run the entrypoint with a `file://` recipe
  4. # repo (mounted) + a token, and assert the dashboard answers on 3100
  5. # (curl /api/state).
  6. #
  7. # The thin image compiles sm121 from the launcher repo on first boot —
  8. # hermetically, from THIS checkout via file:// (SM121_LAUNCHER_URL), with
  9. # the cargo target dir persisted in a volume (re-runs are incremental).
  10. #
  11. # scripts/smoke-addon.sh [image] (default sm121-addon:latest)
  12. set -euo pipefail
  13. cd "$(dirname "$0")/.."
  14. IMG="${1:-sm121-addon:latest}"
  15. TOKEN=smoke-test
  16. # A minimal `file://` recipe repo, mounted read-only at /repos. It lives
  17. # under target/ (gitignored) so it sits on a volume the docker VM shares
  18. # — colima only mounts /Volumes here; a $HOME tmpdir would mount empty.
  19. REPO="$(pwd)/target/smoke-addon-repo"
  20. rm -rf "$REPO"; mkdir -p "$REPO"
  21. git init -q "$REPO"
  22. mkdir -p "$REPO/recipes/demo"
  23. echo 'engine = "vllm"' > "$REPO/recipes/demo/recipe.toml"
  24. git -C "$REPO" add -A
  25. git -C "$REPO" -c user.email=t@sm121.test -c user.name=sm121-test commit -qm init
  26. # Persistent HOME (the add-on data folder in HA; here: the sm121 binary +
  27. # the cargo target cache, so re-runs don't rebuild the world).
  28. HOMEV="$(pwd)/target/smoke-addon-home"
  29. mkdir -p "$HOMEV"
  30. CID="$(docker run -d \
  31. -p 3100:3100 \
  32. -v "$REPO":/repos:ro \
  33. -v "$HOMEV":/root \
  34. -v "$(pwd)":/src-launcher:ro \
  35. -e SM121_RECIPE_REPOS='[{"url":"file:///repos"}]' \
  36. -e SM121_LAUNCHER_URL="file:///src-launcher" \
  37. -e SM121_LAUNCHER_REV=HEAD \
  38. -e SM121_SSH_USER=u \
  39. -e SM121_WEB_TOKEN="$TOKEN" \
  40. "$IMG")"
  41. trap 'docker rm -f "$CID" >/dev/null 2>&1 || true; rm -rf "$REPO"' EXIT
  42. # Wait for the dashboard (up to 8 min — the first run compiles sm121 from
  43. # source; a warm cache is seconds).
  44. ok=""
  45. for _ in $(seq 1 480); do
  46. if curl -sf -H "Authorization: Bearer $TOKEN" \
  47. http://127.0.0.1:3100/api/state >/dev/null 2>&1; then
  48. ok=1
  49. break
  50. fi
  51. sleep 1
  52. done
  53. echo "--- container log (tail) ---"
  54. docker logs "$CID" 2>&1 | tail -5
  55. if [ -n "$ok" ]; then
  56. echo "--- /api/state (first 200 chars) ---"
  57. curl -sf -H "Authorization: Bearer $TOKEN" http://127.0.0.1:3100/api/state | head -c 200
  58. echo
  59. echo "smoke OK: the add-on dashboard answered on 3100"
  60. else
  61. echo "smoke FAILED: no answer on 3100" >&2
  62. exit 1
  63. fi