refactor(updates): pass typed runtime policy to deskup

This commit is contained in:
lingjhf committed 2026-10-06 13:38:11 +08:00
1 parent 1ef8edc8bc
commit d83f94afd5
13 files changed
+158 -102

No files matched your search

@@ -1,46 +0,0 @@
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
@unittest.skipUnless(shutil.which('cmake'), 'CMake required')
class UpdateConfigurationTests(unittest.TestCase):
def configuration(self, flavor, **overrides):
environment = {name: value for name, value in os.environ.items()
if not name.startswith('CUTDEX_WINDOWS_UPDATE_') and name != 'CUTDEX_UPDATE_TEST_HTTP'}
environment.update(overrides)
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
script = root / 'config.cmake'
script.write_text(f'set(FLUTTER_APP_FLAVOR "{flavor}")\n'
'function(configure_updates)\n'
f'include("{ROOT.as_posix()}/windows/runner/update_configuration.cmake")\n'
'endfunction()\nconfigure_updates()\n'
f'file(WRITE "{root.as_posix()}/result.txt" '
'"${DESKUP_WINDOWS_UPDATE_SOURCE}|${DESKUP_WINDOWS_UPDATE_URL}|${DESKUP_UPDATE_PACKAGE_ID}|${DESKUP_ALLOW_LOCAL_HTTP}|${DESKUP_GITEA_INCLUDE_PRERELEASES}")\n')
result = subprocess.run(['cmake', '-P', str(script)], env=environment,
capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
return (root / 'result.txt').read_text().split('|')
def test_production_always_uses_public_gitea_repository(self):
values = self.configuration('production', CUTDEX_WINDOWS_UPDATE_SOURCE='web',
CUTDEX_WINDOWS_UPDATE_URL='http://127.0.0.1:9999', CUTDEX_UPDATE_TEST_HTTP='1')
self.assertEqual(values, ['gitea', 'https://git.orangraph.com/lingjhf/cutdex', 'Cutdex', '0', 'OFF'])
def test_development_has_no_implicit_production_feed(self):
self.assertEqual(self.configuration('development'), ['gitea', '', 'Cutdex.Dev', '0', 'OFF'])
def test_development_supports_explicit_loopback_web_test_feed(self):
self.assertEqual(self.configuration('development', CUTDEX_WINDOWS_UPDATE_SOURCE='web',
CUTDEX_WINDOWS_UPDATE_URL='http://127.0.0.1:8765', CUTDEX_UPDATE_TEST_HTTP='1'),
['web', 'http://127.0.0.1:8765', 'Cutdex.Dev', '1', 'OFF'])
if __name__ == '__main__':
unittest.main()
+5 -9
View File
@@ -15,7 +15,7 @@ import sys
import threading
import time
from windows_updates import DESKUP_VERSION, ROOT, check_tool, pack_release, update_version, vpk_command
from windows_updates import DESKUP_ROOT, ROOT, check_tool, pack_release, update_version, vpk_command
class TestHandler(SimpleHTTPRequestHandler):
@@ -52,26 +52,22 @@ def main():
command = vpk_command(args.vpk)
check_tool(command)
definitions = work / 'defines.json'
definitions.write_text(json.dumps({'CUTDEX_UPDATE_SMOKE_ROOT': work.as_posix()}), encoding='utf-8')
environment = dict(os.environ, CUTDEX_WINDOWS_UPDATE_URL=f'http://127.0.0.1:{args.port}',
CUTDEX_WINDOWS_UPDATE_SOURCE='web',
CUTDEX_UPDATE_TEST_HTTP='1')
definitions.write_text(json.dumps({'CUTDEX_UPDATE_SMOKE_ROOT': work.as_posix(),
'CUTDEX_WINDOWS_UPDATE_URL': f'http://127.0.0.1:{args.port}'}), encoding='utf-8')
environment = dict(os.environ)
# Isolate Flutter caches, generated runner files and output from live builds.
source = work / 'source'
source.mkdir()
for name in ['windows']:
shutil.copytree(ROOT / name, source / name,
ignore=shutil.ignore_patterns('ephemeral', 'build', '__pycache__'))
configuration = source / 'windows/runner/update_configuration.cmake'
configuration.write_text(configuration.read_text().replace(
r'Software\\\\Cutdex\\\\', r'Software\\\\Cutdex\\\\UpdateSmoke\\\\'))
# Exercise the real Runner/update bridge with a small Flutter test entry.
# Media processing is covered separately and need not be rebuilt here.
(source / 'pubspec.yaml').write_text(
'name: cutdex_update_smoke\nversion: 1.0.0+1\n'
'environment:\n sdk: ^3.13.4\n'
'dependencies:\n flutter:\n sdk: flutter\n'
f' deskup: {DESKUP_VERSION}\n'
f' deskup:\n path: {DESKUP_ROOT.as_posix()}\n'
'flutter:\n uses-material-design: true\n', encoding='utf-8')
entry = source / 'tool/testing/windows_update_smoke.dart'
entry.parent.mkdir(parents=True)
+7 -3
View File
@@ -117,9 +117,13 @@ def package_app(app, output, vpk, *, development=False, require_processing=True)
check_tool(command)
version = file_version(app)
package_id = 'Cutdex.Dev' if development else 'Cutdex'
# deskup compiles the identity into the plugin, rather than the runner.
identity = package_id.encode('ascii') + b'\0'
if identity not in (app / 'deskup_plugin.dll').read_bytes():
# The updater is generic; verify the host flavor through its PE branding.
import pefile
with pefile.PE(str(app / 'cutdex.exe')) as pe:
products = [table.entries.get(b'ProductName', b'').decode('utf-8')
for group in pe.FileInfo for block in group
if block.Key == b'StringFileInfo' for table in block.StringTable]
if ('Cutdex Dev' if development else 'Cutdex') not in products:
raise ValueError('Package identity does not match the Flutter build flavor')
validate_previous(output, package_id, version)
output.mkdir(parents=True, exist_ok=True)