mirror of
https://github.com/baketnk/frame-yap.git
synced 2026-10-06 01:00:04 +02:00
Add opt-in Settings release check and attended update handoff
This commit is contained in:
1 parent
dd164aacee
commit
eb054199e1
13 files changed
+544
-13
No files matched your search
+18
-4
@@ -14,7 +14,7 @@ SurfaceEvent click(PanelSurface& surface, float x, float y, unsigned cursor = 0)
|
||||
}
|
||||
void no_action(const SurfaceEvent& event) {
|
||||
assert(!event.action && !event.mount && !event.lasers_anytime && !event.advanced_debug && !event.auto_insert &&
|
||||
!event.close_mic_when_idle && !event.lock_layout && !event.wrist_world_fallback && !event.clock_24h && !event.date_format && !event.recenter && !event.open_bindings && !event.model_action && !event.launch_companion);
|
||||
!event.close_mic_when_idle && !event.lock_layout && !event.wrist_world_fallback && !event.clock_24h && !event.date_format && !event.recenter && !event.open_bindings && !event.model_action && !event.launch_companion && !event.check_updates && !event.install_update);
|
||||
}
|
||||
void snapshot(PanelSurface& surface, const std::string& path) {
|
||||
std::ofstream out(path, std::ios::binary);
|
||||
@@ -337,15 +337,29 @@ int main(int argc, char** argv) {
|
||||
assert(!surface.scroll(200, 610, -1.f)); // fixed footer
|
||||
assert(surface.scroll(200, 400, -2.f));
|
||||
assert(surface.render(p));
|
||||
assert(!surface.scroll(200, 400, -1.f)); // bottom clamp
|
||||
no_action(click(surface, 180, 231)); // scrolled settings cannot be clicked above the viewport
|
||||
auto fallback = click(surface, 200, 520);
|
||||
auto fallback = click(surface, 200, 485);
|
||||
assert(fallback.wrist_world_fallback == false && !fallback.action);
|
||||
assert(!surface.render(p));
|
||||
surface.set_wrist_world_fallback(false); assert(surface.render(p));
|
||||
fallback = click(surface, 200, 520);
|
||||
fallback = click(surface, 200, 485);
|
||||
assert(fallback.wrist_world_fallback == true);
|
||||
surface.set_wrist_world_fallback(true); assert(surface.render(p));
|
||||
assert(surface.scroll(200, 400, -2.f)); // reveal bottom update row and status
|
||||
assert(surface.render(p));
|
||||
assert(!surface.scroll(200, 400, -1.f)); // bottom clamp
|
||||
no_action(click(surface, 700, 486)); // no install button until a newer release is checked
|
||||
assert(click(surface, 180, 486).check_updates);
|
||||
surface.set_update_status(UpdateStatus::Checking); assert(surface.render(p));
|
||||
no_action(click(surface, 180, 486)); no_action(click(surface, 700, 486));
|
||||
surface.set_update_status(UpdateStatus::Available, "0.1.202609292232"); assert(surface.render(p));
|
||||
if (argc >= 3) snapshot(surface, std::string(argv[2]) + "-updates.ppm");
|
||||
assert(click(surface, 700, 486).install_update);
|
||||
surface.set_update_status(UpdateStatus::Current); assert(surface.render(p));
|
||||
no_action(click(surface, 700, 486));
|
||||
assert(click(surface, 180, 486).check_updates);
|
||||
surface.set_update_status(UpdateStatus::Failed); assert(surface.render(p));
|
||||
no_action(click(surface, 700, 486));
|
||||
assert(click(surface, 280, 610).action == UiAction::Cancel); // footer stays fixed
|
||||
assert(surface.scroll(200, 400, 4.f));
|
||||
assert(surface.render(p));
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Offline checks for the manual release lookup and attended installer handoff."""
|
||||
import importlib.util
|
||||
import io
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def load(name, filename):
|
||||
spec = importlib.util.spec_from_file_location(name, ROOT / 'scripts' / filename)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class UpdateTests(unittest.TestCase):
|
||||
def test_tags(self):
|
||||
check = load('frameyap_update', 'check-update.py')
|
||||
current = '0.1.202609282232'
|
||||
self.assertEqual(check.outcome('{"tag_name":"v0.1.202609292232"}', current),
|
||||
'AVAILABLE 0.1.202609292232')
|
||||
for tag in ('v0.1.202609282232', 'v0.1.202609272232'):
|
||||
self.assertEqual(check.outcome('{"tag_name":"' + tag + '"}', current), 'CURRENT')
|
||||
for tag in ('v0.1.202613292232', '0.1.202609292232', 'v0.1.202609292232;sh',
|
||||
'v0.1.20260929', '../v0.1.202609292232'):
|
||||
with self.assertRaises(ValueError, msg=tag):
|
||||
check.outcome('{"tag_name":"' + tag + '"}', current)
|
||||
with self.assertRaises(ValueError):
|
||||
check.outcome('{"tag_name":"v0.1.202609292232"}', '0.1.invalid')
|
||||
|
||||
def test_network_only_on_explicit_check(self):
|
||||
check = load('frameyap_update_2', 'check-update.py')
|
||||
with patch.object(check.request, 'build_opener') as build:
|
||||
with self.assertRaises(SystemExit):
|
||||
check.main(['--current', '0.1.202609282232'])
|
||||
build.assert_not_called()
|
||||
class Response:
|
||||
def __enter__(self): return self
|
||||
def __exit__(self, *args): return False
|
||||
def read(self, limit):
|
||||
self.limit = limit
|
||||
return b'{"tag_name":"v0.1.202609292232"}'
|
||||
class Opener:
|
||||
def open(self, req, timeout):
|
||||
self.url, self.timeout = req.full_url, timeout
|
||||
return Response()
|
||||
opener = Opener()
|
||||
with patch.object(check.request, 'build_opener', return_value=opener):
|
||||
self.assertEqual(check.check('0.1.202609282232'), 'AVAILABLE 0.1.202609292232')
|
||||
self.assertEqual(opener.url, 'https://api.github.com/repos/baketnk/frame-yap/releases/latest')
|
||||
self.assertEqual(opener.timeout, 6)
|
||||
|
||||
def test_terminal_command_is_fixed_and_version_checked(self):
|
||||
helper = load('frameyap_installer_handoff', 'install-update.py')
|
||||
cmd = helper.installer_command(Path('/owned/bin/install.sh'), '0.1.202609292232')
|
||||
self.assertEqual(cmd, ['sh', '/owned/bin/install.sh', '--mode', 'binary',
|
||||
'--version', '0.1.202609292232', '--yes'])
|
||||
for bad in ('0.1.202609292232;rm', 'v0.1.202609292232', 'latest'):
|
||||
with self.assertRaises(ValueError):
|
||||
helper.installer_command(Path('/owned/bin/install.sh'), bad)
|
||||
|
||||
def test_terminal_handoff_requires_tty_before_install(self):
|
||||
helper = load('frameyap_installer_handoff_2', 'install-update.py')
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
(root / 'scripts').mkdir()
|
||||
(root / 'bin').mkdir()
|
||||
(root / 'bin/install.sh').write_text('#!/bin/sh\nexit 0\n')
|
||||
helper.__file__ = str(root / 'scripts/install-update.py')
|
||||
with patch.object(helper.sys, 'stdin', io.StringIO('\n')), patch.object(helper.subprocess, 'run') as run:
|
||||
self.assertEqual(helper.main(['--version', '0.1.202609292232']), 1)
|
||||
run.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "update_check.hpp"
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace frameyap;
|
||||
namespace {
|
||||
UpdateResult finish(UpdateCheck& checker) {
|
||||
for (int i = 0; i < 300; ++i) {
|
||||
if (auto result = checker.poll()) return *result;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
assert(false && "update helper did not complete");
|
||||
return {UpdateResult::State::Failed, {}};
|
||||
}
|
||||
}
|
||||
int main(int argc, char** argv) {
|
||||
assert(argc == 2);
|
||||
char pattern[] = "/tmp/frameyap-update-XXXXXX";
|
||||
const auto root = fs::path(::mkdtemp(pattern));
|
||||
const auto helper = root / "fixture.py";
|
||||
UpdateCheck check(helper, "0.1.202609282232", argv[1]);
|
||||
assert(!check.busy() && !check.poll());
|
||||
assert(!check.start()); // missing file; no child, no network
|
||||
std::ofstream(helper) << "import time\ntime.sleep(.2)\nprint('AVAILABLE 0.1.202609292232')\n";
|
||||
assert(check.start() && check.busy());
|
||||
assert(!check.start()); // one explicit check at a time
|
||||
assert(!check.poll()); // interaction loop does not wait for network/child
|
||||
auto result = finish(check);
|
||||
assert(result.state == UpdateResult::State::Available && result.version == "0.1.202609292232");
|
||||
assert(!check.busy());
|
||||
std::ofstream(helper) << "print('CURRENT')\n";
|
||||
assert(check.start());
|
||||
assert(finish(check).state == UpdateResult::State::Current);
|
||||
std::ofstream(helper) << "print('AVAILABLE 0.1.20260929;echo surprise')\n";
|
||||
assert(check.start());
|
||||
assert(finish(check).state == UpdateResult::State::Failed);
|
||||
std::ofstream(helper) << "print('x'*400)\n";
|
||||
assert(check.start());
|
||||
assert(finish(check).state == UpdateResult::State::Failed);
|
||||
std::ofstream(helper) << "raise SystemExit(1)\n";
|
||||
assert(check.start());
|
||||
assert(finish(check).state == UpdateResult::State::Failed);
|
||||
assert(!open_update_terminal(root / "missing.py", "0.1.202609292232"));
|
||||
assert(!open_update_terminal(helper, "0.1.20260929;echo surprise"));
|
||||
const char* path = ::getenv("PATH");
|
||||
const std::string old_path = path ? path : "";
|
||||
::setenv("PATH", root.c_str(), 1);
|
||||
assert(!open_update_terminal(helper, "0.1.202609292232")); // no Konsole
|
||||
::setenv("PATH", old_path.c_str(), 1);
|
||||
fs::remove_all(root);
|
||||
}
|
||||
Reference in new issue
Block a user