修复:Windows 更新检查仅探测程序路径,避免慢磁盘校验超时
This commit is contained in:
@@ -52,3 +52,9 @@ python3 deploy/offline/publish_update.py \
|
|||||||
工具只在本地产生 `quality-update-<version>.zip` 和签名 `latest.json`,不会上传或发布文件。每个版本请使用新的输出目录;发布到更新服务器由维护人员另行完成。
|
工具只在本地产生 `quality-update-<version>.zip` 和签名 `latest.json`,不会上传或发布文件。每个版本请使用新的输出目录;发布到更新服务器由维护人员另行完成。
|
||||||
|
|
||||||
参考:[Java 21 官方发行](https://adoptium.net/temurin/releases?version=21)、[MySQL Windows 安装要求](https://dev.mysql.com/doc/refman/8.4/en/windows-installation.html)、[MySQL Linux 二进制安装](https://dev.mysql.com/doc/refman/8.4/en/binary-installation.html)、[Python standalone](https://github.com/astral-sh/python-build-standalone)、[nao-core 0.3.26](https://pypi.org/project/nao-core/0.3.26/)、[Microsoft 运行库](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist/)。
|
参考:[Java 21 官方发行](https://adoptium.net/temurin/releases?version=21)、[MySQL Windows 安装要求](https://dev.mysql.com/doc/refman/8.4/en/windows-installation.html)、[MySQL Linux 二进制安装](https://dev.mysql.com/doc/refman/8.4/en/binary-installation.html)、[Python standalone](https://github.com/astral-sh/python-build-standalone)、[nao-core 0.3.26](https://pypi.org/project/nao-core/0.3.26/)、[Microsoft 运行库](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist/)。
|
||||||
|
|
||||||
|
### Windows 检查更新校验超时修复(2026-11-05)
|
||||||
|
|
||||||
|
旧版检查会逐个探测完整运行环境清单的磁盘路径,慢磁盘上可能超过接口等待时间。新版仅探测会替换、删除或备份的程序路径;完整清单语法、重复项、运行环境指纹、公钥及签名验证仍保留。
|
||||||
|
|
||||||
|
已有部署若无法通过界面更新,将生成的“修复更新检查.cmd”放入原 QualityCenter 文件夹双击,再回到“任务与监控 → 系统更新”检查更新。修复只接受已知程序摘要,备份后原子替换更新检查程序及其清单摘要;保留版本、数据、配置、缓存修复和信任公钥,不重启服务、不导入数据库。更新或恢复任务运行期间拒绝修复。
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -83,6 +83,26 @@ class UpdateTests(unittest.TestCase):
|
|||||||
self.assertEqual('2026.11.04', self.validate()['version'])
|
self.assertEqual('2026.11.04', self.validate()['version'])
|
||||||
self.assertEqual(update.runtime_fingerprint(self.manifest), update.runtime_fingerprint(copy.deepcopy(self.manifest)))
|
self.assertEqual(update.runtime_fingerprint(self.manifest), update.runtime_fingerprint(copy.deepcopy(self.manifest)))
|
||||||
|
|
||||||
|
def test_check_does_not_probe_fourteen_thousand_immutable_runtime_paths(self):
|
||||||
|
self.manifest['files'] += [{'path': f'runtimes/python/Lib/library-{i}.py', 'sha256': 'a' * 64}
|
||||||
|
for i in range(14000)]
|
||||||
|
update.atomic(self.root / 'manifest.json', self.manifest)
|
||||||
|
with patch.object(update, 'destination', wraps=update.destination) as probe:
|
||||||
|
self.validate()
|
||||||
|
names = [call.args[1] for call in probe.call_args_list]
|
||||||
|
self.assertFalse(any(name.startswith('runtimes/') for name in names))
|
||||||
|
self.assertLess(len(names), 100)
|
||||||
|
self.assertIn(update.KEY, names)
|
||||||
|
self.assertIn('app/web/obsolete.js', names)
|
||||||
|
|
||||||
|
def test_obsolete_program_symlink_is_still_rejected_before_replacement(self):
|
||||||
|
target = self.root / 'app/web/obsolete-link'
|
||||||
|
target.symlink_to(Path(self.temp.name), target_is_directory=True)
|
||||||
|
self.manifest['files'].append({'path': 'app/web/obsolete-link/file.js', 'sha256': 'a' * 64})
|
||||||
|
update.atomic(self.root / 'manifest.json', self.manifest)
|
||||||
|
with self.assertRaises(update.UpdateError):
|
||||||
|
self.validate()
|
||||||
|
|
||||||
def test_wrong_signature_key_and_modified_payload_are_rejected(self):
|
def test_wrong_signature_key_and_modified_payload_are_rejected(self):
|
||||||
with self.assertRaises(update.UpdateError):
|
with self.assertRaises(update.UpdateError):
|
||||||
update.validate_release(self.envelope(private=Ed25519PrivateKey.generate()), self.root)
|
update.validate_release(self.envelope(private=Ed25519PrivateKey.generate()), self.root)
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
HERE = Path(__file__).resolve().parent
|
||||||
|
sys.path.insert(0, str(HERE))
|
||||||
|
import repair_windows_update_check as fix
|
||||||
|
ORIGINAL_SHA = fix.OLD_SHA
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateCheckRepairTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.temp = tempfile.TemporaryDirectory(prefix='quality source path repair ')
|
||||||
|
self.addCleanup(self.temp.cleanup)
|
||||||
|
self.root = Path(self.temp.name) / '中文 QualityCenter & files'
|
||||||
|
self.root.mkdir()
|
||||||
|
self.original = b'original source fixture\n'
|
||||||
|
self.old_sha = hashlib.sha256(self.original).hexdigest()
|
||||||
|
self.guard = patch.object(fix, 'OLD_SHA', self.old_sha)
|
||||||
|
self.guard.start()
|
||||||
|
self.addCleanup(self.guard.stop)
|
||||||
|
for name, value in {fix.SCRIPT: self.original,
|
||||||
|
'deploy/bootstrap/windows-start.ps1': b'original bootstrap',
|
||||||
|
'migration/database.sql.gz': b'existing migration payload',
|
||||||
|
'.runtime/deployment.json': b'original private configuration',
|
||||||
|
'runtimedata/mysql/retained-database': b'imported database data'}.items():
|
||||||
|
target = self.root / name
|
||||||
|
target.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
target.write_bytes(value)
|
||||||
|
self.manifest = {'platform': 'windows', 'updateVersion': '2026.11.04.1', 'updateSequence': 1,
|
||||||
|
'runtimeFingerprint': 'unchanged', 'otherMetadata': {'keep': True},
|
||||||
|
'files': [{'path': fix.SCRIPT, 'sha256': self.old_sha},
|
||||||
|
{'path': 'deploy/bootstrap/windows-start.ps1', 'sha256': 'unchanged'}]}
|
||||||
|
self.manifest_path = self.root / 'manifest.json'
|
||||||
|
self.manifest_path.write_text(json.dumps(self.manifest), encoding='utf-8')
|
||||||
|
|
||||||
|
def test_backup_manifest_and_script_only_preserving_database_and_configuration(self):
|
||||||
|
private = {name: (self.root / name).read_bytes() for name in
|
||||||
|
['migration/database.sql.gz', '.runtime/deployment.json', 'runtimedata/mysql/retained-database']}
|
||||||
|
result = fix.repair(self.root)
|
||||||
|
self.assertTrue(result['updateCheckRepaired'])
|
||||||
|
self.assertEqual((self.root / fix.SCRIPT).read_bytes(), fix.PATCHED_SCRIPT)
|
||||||
|
expected = json.loads(json.dumps(self.manifest))
|
||||||
|
expected['files'][0]['sha256'] = fix.NEW_SHA
|
||||||
|
self.assertEqual(json.loads(self.manifest_path.read_text()), expected)
|
||||||
|
backup = self.root / result['backup']
|
||||||
|
self.assertEqual((backup / 'update_manager.py').read_bytes(), self.original)
|
||||||
|
self.assertEqual(json.loads((backup / 'manifest.json').read_text()), self.manifest)
|
||||||
|
for name, value in private.items():
|
||||||
|
self.assertEqual((self.root / name).read_bytes(), value)
|
||||||
|
self.assertTrue(fix.repair(self.root)['alreadyRepaired'])
|
||||||
|
|
||||||
|
def test_modified_script_or_manifest_is_not_approved_as_a_repair(self):
|
||||||
|
before = self.manifest_path.read_bytes()
|
||||||
|
(self.root / fix.SCRIPT).write_bytes(b'unrecognized source')
|
||||||
|
with self.assertRaisesRegex(RuntimeError, '版本'):
|
||||||
|
fix.repair(self.root)
|
||||||
|
self.assertEqual(self.manifest_path.read_bytes(), before)
|
||||||
|
|
||||||
|
def test_failed_second_write_restores_original_program_and_manifest(self):
|
||||||
|
before = self.manifest_path.read_bytes()
|
||||||
|
original_atomic = fix.atomic
|
||||||
|
calls = []
|
||||||
|
def failing(path, data):
|
||||||
|
calls.append(path)
|
||||||
|
if len(calls) == 2:
|
||||||
|
raise OSError('simulated manifest write failure')
|
||||||
|
original_atomic(path, data)
|
||||||
|
with patch.object(fix, 'atomic', side_effect=failing), self.assertRaises(OSError):
|
||||||
|
fix.repair(self.root)
|
||||||
|
self.assertEqual((self.root / fix.SCRIPT).read_bytes(), self.original)
|
||||||
|
self.assertEqual(self.manifest_path.read_bytes(), before)
|
||||||
|
|
||||||
|
def test_retry_completes_an_interrupted_script_manifest_pair(self):
|
||||||
|
(self.root / fix.SCRIPT).write_bytes(fix.PATCHED_SCRIPT)
|
||||||
|
fix.repair(self.root)
|
||||||
|
self.assertEqual(json.loads(self.manifest_path.read_text())['files'][0]['sha256'], fix.NEW_SHA)
|
||||||
|
|
||||||
|
def test_cmd_payload_runs_with_bundled_standard_library_without_service_restart(self):
|
||||||
|
# 真实原包脚本由交付包集成验证;此单元测试使用受控旧源码摘要。
|
||||||
|
command = self.root / '修复更新检查.cmd'
|
||||||
|
body = fix.command_file().decode('utf-8').replace(ORIGINAL_SHA, self.old_sha)
|
||||||
|
command.write_bytes(body.encode('utf-8'))
|
||||||
|
code = body.split(' -c "', 1)[1].split('" "%~f0"', 1)[0]
|
||||||
|
result = subprocess.run([sys.executable, '-I', '-S', '-B', '-X', 'utf8', '-c', code, str(command)], capture_output=True, text=True)
|
||||||
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
|
self.assertEqual((self.root / fix.SCRIPT).read_bytes(), fix.PATCHED_SCRIPT)
|
||||||
|
self.assertNotIn('powershell.exe', body)
|
||||||
|
self.assertIn('无需停止服务或重新导入数据库', body)
|
||||||
|
|
||||||
|
def test_active_update_lock_blocks_patching(self):
|
||||||
|
before = self.manifest_path.read_bytes()
|
||||||
|
with fix.update_lock(self.root), self.assertRaisesRegex(RuntimeError, '仍在运行'):
|
||||||
|
fix.repair(self.root)
|
||||||
|
self.assertEqual(self.manifest_path.read_bytes(), before)
|
||||||
|
|
||||||
|
def test_worker_or_unfinished_journal_blocks_repair(self):
|
||||||
|
for name, data in [('worker.json', {}), ('journal.json', {'phase': 'installing'})]:
|
||||||
|
path = self.root / '.runtime/update' / name
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text(json.dumps(data))
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
fix.repair(self.root)
|
||||||
|
self.assertEqual((self.root / fix.SCRIPT).read_bytes(), self.original)
|
||||||
|
path.unlink()
|
||||||
|
|
||||||
|
def test_embedded_program_matches_reviewed_source(self):
|
||||||
|
self.assertEqual(fix.PATCHED_SCRIPT, (HERE / 'update_manager.py').read_bytes())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
@@ -197,7 +197,10 @@ def validate_release(envelope, root=ROOT):
|
|||||||
raise UpdateError('更新缺少必要程序文件。')
|
raise UpdateError('更新缺少必要程序文件。')
|
||||||
if KEY not in old_files or digest(destination(root, KEY)) != old_files[KEY]['sha256']:
|
if KEY not in old_files or digest(destination(root, KEY)) != old_files[KEY]['sha256']:
|
||||||
raise UpdateError('更新信任公钥校验失败。')
|
raise UpdateError('更新信任公钥校验失败。')
|
||||||
for name in set(old_files) | set(files):
|
# 只探测本次会备份、删除或替换的程序路径;运行环境保持原样。
|
||||||
|
# 完整清单仍逐项验证路径语法、重复项、摘要以及运行环境指纹。
|
||||||
|
old_program = {name for name in old_files if program_path(name)}
|
||||||
|
for name in old_program | set(files):
|
||||||
destination(root, name)
|
destination(root, name)
|
||||||
return release
|
return release
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user