update_check.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # update_check.sh <vm> <app dir | .deb> - we_manager's update flow in a VM's desktop session against fake_github.py on
  3. # this host: an app release (the candidate's .deb with a newer Version) and an engine release (the portable tarball under
  4. # a newer tag). Checks that both updates are offered, the engine update installs, and for a .deb install that the app
  5. # update downloads, installs through polkit (a rule for the lab user stands in for the dialog) and the package version
  6. # changes. Also: a manual "check now" with the automatic checks off, "close" (until the next start) against "don't notify
  7. # again" (kept), the version picker's list (only v-tagged releases, a libnode-arch helper release is left out) and going back
  8. # to an older engine (prebuilt) and app (.deb) release. Other install kinds (an unpacked AppImage, Flatpak) are expected to only get the notice. Needs the session
  9. # running (sessenv) and the candidate's we_manager unpacked/installed the way wem_check.sh does.
  10. # APP_DEB .deb to serve as the new app release (default: the one next to the app dir's dist folder)
  11. # ENGINE_TARBALL portable engine tarball to serve (default ~/.local/share/distro-rootfs/out/linux-wallpaperengine-kde-portable-x86_64.tar.gz)
  12. HERE=$(cd "$(dirname "$0")" && pwd)
  13. vm=$1 app=$2
  14. sshv() { "$HERE/linuxvm.sh" ssh "$vm" "$@" </dev/null; }
  15. status=0
  16. pass() { echo "PASS $1"; }
  17. fail() { echo "FAIL $1"; status=1; }
  18. cdp() { sshv ". ~/sessenv; cd ~/wem; NODE_EXTRA_CA_CERTS= timeout ${CDP_TIMEOUT:-90} python3 cdp.py \"$1\" 2>&1 | cut -c1-${2:-700}"; }
  19. work=$(mktemp -d)
  20. engine_tag=v99.0.$(date +%s) # newer than whatever engine the VM has, a golden disk may hold an earlier run's
  21. engine_old=v98.0.${engine_tag##*.}
  22. deb=${APP_DEB:-}
  23. if [ -z "$deb" ]; then
  24. for candidate in "$(dirname "$app")"/*.deb "$(dirname "$app")"/../*.deb; do [ -f "$candidate" ] && deb=$candidate && break; done
  25. fi
  26. engine=${ENGINE_TARBALL:-$HOME/.local/share/distro-rootfs/out/linux-wallpaperengine-kde-portable-x86_64.tar.gz}
  27. app_release=()
  28. if [ -f "$deb" ]; then
  29. python3 "$HERE/bump_deb.py" "$deb" "$work/we-manager_0.9.9_amd64.deb" 0.9.9
  30. python3 "$HERE/bump_deb.py" "$deb" "$work/we-manager_0.9.7_amd64.deb" 0.9.7
  31. app_release=(--release "WallpaperEngineLover/we_manager=v0.9.9:$work/we-manager_0.9.9_amd64.deb"
  32. --release "WallpaperEngineLover/we_manager=v0.9.7:$work/we-manager_0.9.7_amd64.deb")
  33. else
  34. echo "SKIP app update: no .deb to serve as the new app release (APP_DEB), only the engine update is checked"
  35. fi
  36. cp "$engine" "$work/linux-wallpaperengine-kde-portable-x86_64.tar.gz"
  37. cp "$engine" "$work/linux-wallpaperengine-generic-portable-x86_64.tar.gz"
  38. echo helper > "$work/libnode-arch.pkg.tar.zst"
  39. mkdir -p "$work/certs"
  40. . "$HERE/fake_github_lib.sh"
  41. fgh_start "$vm" "$work" \
  42. "${app_release[@]}" \
  43. --release "WallpaperEngineLover/linux-wallpaperengine-kde=$engine_tag:$work/linux-wallpaperengine-kde-portable-x86_64.tar.gz,$work/linux-wallpaperengine-generic-portable-x86_64.tar.gz" \
  44. --release "WallpaperEngineLover/linux-wallpaperengine-kde=!libnode-arch:$work/libnode-arch.pkg.tar.zst" \
  45. --release "WallpaperEngineLover/linux-wallpaperengine-kde=$engine_old:$work/linux-wallpaperengine-kde-portable-x86_64.tar.gz,$work/linux-wallpaperengine-generic-portable-x86_64.tar.gz"
  46. trap 'kill $fake 2>/dev/null; rm -rf "$work"' EXIT
  47. sleep 3
  48. kill -0 $fake 2>/dev/null || { cat "$work/fake.log"; echo "fake_github did not start (port 443?)"; exit 2; }
  49. sshv 'mkdir -p ~/wem'
  50. if [ -d "$app" ] && ! sshv "test -x ~/wem/$(basename "$app")/we-manager"; then # the app is not on the VM yet: copy it like wem_check.sh
  51. tar -C "$(dirname "$app")" -cf - "$(basename "$app")" | ssh -i "$HOME/.local/share/linuxvm/id_ed25519" -p "$(cat "$HOME/.local/share/linuxvm/vms/$vm/port")" \
  52. -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR lab@127.0.0.1 'mkdir -p ~/wem && tar -C ~/wem -xf -'
  53. fi
  54. "$HERE/linuxvm.sh" scp "$vm" "$work/certs/ca.pem" wem/fake-ca.pem
  55. "$HERE/linuxvm.sh" scp "$vm" "$HERE/cdp.py" wem/cdp.py
  56. sshv 'grep -q "api.github.com" /etc/hosts || echo "10.0.2.2 api.github.com" | sudo tee -a /etc/hosts >/dev/null
  57. sudo mkdir -p /etc/polkit-1/rules.d
  58. printf "polkit.addRule(function(action, subject) { if (subject.user == \"lab\") return polkit.Result.YES; });\n" | sudo tee /etc/polkit-1/rules.d/49-lab-test.rules >/dev/null
  59. pkill -f "[w]e-manager" 2>/dev/null; for _ in $(seq 20); do pgrep -f "[w]e-manager" >/dev/null || break; sleep 1; done; true'
  60. sleep 2
  61. if [[ $app == *.deb ]]; then
  62. "$HERE/linuxvm.sh" scp "$vm" "$app" wem/app.deb
  63. sshv 'sudo DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=300 install -y --allow-downgrades ./wem/app.deb >/tmp/wem-deb.log 2>&1'
  64. fi
  65. if [[ $app == *.deb ]]; then start="${WEM_LAUNCH:-} we-manager ${WEM_FLAGS:-}"; else start="${WEM_LAUNCH:-} ~/wem/$(basename "$app")/we-manager --no-sandbox ${WEM_FLAGS:-}"; fi
  66. sshv ". ~/sessenv; export NODE_EXTRA_CA_CERTS=\$HOME/wem/fake-ca.pem; (setsid nohup $start --remote-debugging-port=9222 > ~/wem/app-update.log 2>&1 </dev/null &); for _ in \$(seq 40); do grep -q 'DevTools listening' ~/wem/app-update.log 2>/dev/null && break; sleep 1; done; sleep 8"
  67. [ "$(sshv 'pgrep -fc "[w]e-manager"')" -gt 0 ] && pass "we_manager starts" || { fail "we_manager did not start: $(sshv 'tail -3 ~/wem/app-update.log')"; exit 1; }
  68. val() { cdp "$1" 400 | tr -d '"'; }
  69. cdp 'window.electronAPI.updates.setChecks({app: false, engine: false})' 300 >/dev/null
  70. sleep 3
  71. manual=$(val "window.electronAPI.updates.check().then(s => [s.app && s.app.version, s.checked.app, s.checked.engine].join(' '))")
  72. want="v0.9.9 true true"
  73. [ -f "$deb" ] || want=" true true"
  74. [ "$manual" = "$want" ] && pass "manual check with automatic checks off looked at everything ($manual)" || fail "manual check with automatic checks off: '$manual', wanted '$want'"
  75. out=$(cdp 'window.electronAPI.updates.setChecks({app: true, engine: true})' 1500)
  76. out=$(cdp 'window.electronAPI.updates.check()' 2500); echo " $out" | tr '\n' ' ' | cut -c1-600; echo
  77. kind=$(echo "$out" | grep -o '"appInstall": "[^"]*"' | cut -d'"' -f4)
  78. if [ -f "$deb" ]; then
  79. echo "$out" | grep -q '"version": "0.9.9"\|"version": "v0.9.9"' && pass "app update 0.9.9 offered (install kind $kind)" || fail "app update not offered"
  80. fi
  81. if echo "$out" | grep -q "$engine_tag"; then pass "engine update $engine_tag offered"
  82. elif echo "$out" | grep -q '"engineInstall": null'; then echo "SKIP engine update offer: no engine installed through we_manager on this VM yet"
  83. else fail "engine update not offered"; fi
  84. r=$(val "window.electronAPI.updates.dismiss('app', 'v0.9.9', false).then(s => [s.snoozed.app, s.dismissed.app].join('|'))")
  85. [ "$r" = "v0.9.9|" ] && pass "closing a notice only snoozes it" || fail "close: '$r'"
  86. r=$(val "window.electronAPI.updates.dismiss('app', 'v0.9.9', true).then(s => s.dismissed.app)")
  87. [ "$r" = v0.9.9 ] && pass "don't notify me again keeps the version dismissed" || fail "dismiss for good: '$r'"
  88. r=$(val "window.electronAPI.updates.check().then(s => Object.keys(s.dismissed).length + '/' + Object.keys(s.snoozed).length)")
  89. [ "$r" = 0/0 ] && pass "check now brings dismissed notices back" || fail "check now after dismissing: '$r'"
  90. r=$(val "window.electronAPI.updates.versions('engine').then(v => v.map(x => x.tag).join(' '))")
  91. if [[ $r == *"$engine_tag"* && $r == *"$engine_old"* && $r != *libnode* ]]; then pass "engine versions listed without the libnode release ($r)"; else fail "engine versions: '$r'"; fi
  92. if [ -f "$deb" ]; then
  93. r=$(val "window.electronAPI.updates.versions('app').then(v => v.map(x => x.tag).join(' '))")
  94. [ "$r" = "v0.9.9 v0.9.7" ] && pass "app versions listed newest first ($r)" || fail "app versions: '$r'"
  95. fi
  96. if [ "$kind" = deb ]; then
  97. out=$(cdp 'window.electronAPI.updates.installApp()' 1500); sleep 20
  98. version=$(sshv 'dpkg-query -W -f="\${Version}" we-manager 2>/dev/null')
  99. [ "$version" = 0.9.9 ] && pass "the .deb update installed (we-manager $version)" || fail "after installApp the package is $version: $out"
  100. else
  101. echo "SKIP app install: install kind '$kind' only gets the notice"
  102. fi
  103. # the app restarts after its own .deb update, a loaded guest takes a while before the debugging port answers again
  104. for _ in $(seq 30); do [ "$(cdp '1 + 1' 20)" = 2 ] && break; sleep 3; done
  105. # an app that restarts after its own update can drop the first call (empty answer), ask again
  106. for _ in 1 2 3; do
  107. out=$(sshv ". ~/sessenv; cd ~/wem; timeout 400 python3 cdp.py 'window.electronAPI.lwe.installPrebuilt()' 2>&1 | cut -c1-300")
  108. [ -n "$out" ] && break
  109. sleep 20
  110. done
  111. if echo "$out" | grep -q '"installed": true'; then pass "engine update installed through the prebuilt install: $(echo "$out" | grep -o '"version": "[^"]*"')"; else fail "engine update failed: $out"; fi
  112. # the .deb needs apt's --allow-downgrades to go back
  113. if echo "$out" | grep -q '"installed": true'; then
  114. out=$(sshv ". ~/sessenv; cd ~/wem; timeout 400 python3 cdp.py \"window.electronAPI.lwe.installPrebuilt('$engine_old')\" 2>&1 | cut -c1-300")
  115. echo "$out" | grep -q "\"version\": \"$engine_old\"" && pass "engine went back to $engine_old" || fail "engine downgrade to $engine_old: $out"
  116. out=$(sshv ". ~/sessenv; cd ~/wem; timeout 400 python3 cdp.py \"window.electronAPI.lwe.installPrebuilt('libnode-arch')\" 2>&1 | cut -c1-300")
  117. echo "$out" | grep -q "\"version\": \"$engine_old\"" && pass "a non-version release is refused, the engine stays on $engine_old" || fail "libnode-arch changed the engine: $out"
  118. fi
  119. if [ "$kind" = deb ]; then
  120. for _ in $(seq 30); do [ "$(cdp '1 + 1' 20)" = 2 ] && break; sleep 3; done
  121. out=$(cdp "window.electronAPI.updates.installApp('v0.9.7')" 1500); sleep 20
  122. version=$(sshv 'dpkg-query -W -f="\${Version}" we-manager 2>/dev/null')
  123. [ "$version" = 0.9.7 ] && pass "the .deb went back to 0.9.7" || fail "after installApp('v0.9.7') the package is $version: $out"
  124. fi
  125. grep -c "GET" "$work/fake.log" | xargs -I{} echo " {} requests reached the fake api.github.com"
  126. sshv 'pkill -f "[w]e-manager" 2>/dev/null; for _ in $(seq 20); do pgrep -f "[w]e-manager" >/dev/null || break; sleep 1; done; sudo rm -f /etc/polkit-1/rules.d/49-lab-test.rules; sudo sed -i "/api.github.com/d" /etc/hosts; true'
  127. exit $status