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

+2
View File
@@ -75,6 +75,8 @@ python3 tool/windows/windows_updates.py pack --help
提升应用构建号,保留当前线上更新索引供版本检查;development 与 production 使用独立发布目录。脚本只生成产物,不上传。完整升级模拟使用各平台的 `test_*_updates.py`,参数见 `--help`,测试包不用于分发。
deskup 0.3.0 的开发更新源由 Dart 参数配置。Windows 的编译期配置示例见 [Windows 更新文档](../docs/windows-updates.md)。macOS 本地 HTTP 更新测试的源应用需使用 `--flavor development --dart-define=CUTDEX_UPDATE_TEST_HTTP=true` 构建,再运行 `test_macos_updates.py`;签名公钥和 appcast 仍由打包工具写入应用 Info.plist。
## 诊断与共享测试入口
- `diagnostics/frame_budget.py`:读取 `CUTDEX_FRAME_TIMINGS` JSONL,可带阶段标记文件;报告帧耗时。
+31 -3
View File
@@ -5,11 +5,15 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:deskup/deskup.dart';
const channel = MethodChannel('deskup');
const smokeRoot = String.fromEnvironment('CUTDEX_UPDATE_SMOKE_ROOT');
void main() {
List<String> restartArguments = [];
void main(List<String> arguments) {
restartArguments = arguments;
WidgetsFlutterBinding.ensureInitialized();
// The isolated smoke fixture depends only on Flutter, without Riverpod.
// ignore: riverpod_lint/missing_provider_scope
@@ -48,13 +52,33 @@ Future<void> runSmoke() async {
throw StateError('Set CUTDEX_UPDATE_SMOKE_ROOT for this test app');
}
try {
await channel.invokeMethod<void>('ready');
final updater = Deskup(
windows: WindowsUpdateConfiguration(
source: WebUpdateSource(
url: Uri.parse(
const String.fromEnvironment('CUTDEX_WINDOWS_UPDATE_URL'),
),
allowLocalHttp: true,
),
expectedPackageId: 'Cutdex.Dev',
preferenceNamespace: 'Cutdex.UpdateSmoke',
automaticCheckInterval: const Duration(minutes: 5),
maximumDeltas: -1,
),
);
await updater.initialize();
final initial = await waitFor(
(value) => value['configured'] == true && value['canCheck'] == true,
);
await channel.invokeMethod<void>('check');
var checked = await waitFor((value) => value['canCheck'] == true);
if (initial['build'] == '900002') {
if (!restartArguments.contains('--deskup-smoke-restart') ||
!restartArguments.contains('文档 with spaces')) {
throw StateError(
'Restart arguments were not preserved: $restartArguments',
);
}
if (checked['phase'] != 'current') {
throw StateError('Updated version was offered again: $checked');
}
@@ -78,7 +102,11 @@ Future<void> runSmoke() async {
}
await record('before', checked);
await channel.invokeMethod<void>('validateInstall');
await channel.invokeMethod<void>('install');
await updater.install(
silent: true,
restart: true,
restartArguments: ['--deskup-smoke-restart', '文档 with spaces'],
);
} catch (error, stack) {
await record('failure', {'error': '$error', 'stack': '$stack'});
exit(1);
@@ -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)