修复:Windows 更新备份使用写句柄刷盘,保留失败阶段诊断

This commit is contained in:
2026-11-05 15:06:16 +08:00
parent 4843768694
commit 2315c83067
5 changed files with 87 additions and 11 deletions
+31
View File
@@ -232,6 +232,37 @@ class UpdateTests(unittest.TestCase):
update.worker(987654, 'a' * 32, self.root)
return calls, restores, queries
def test_windows_flush_requires_write_handle_through_complete_update(self):
import os
if os.name != 'nt':
import fcntl
real_fsync = os.fsync
flushed = []
def windows_fsync(fd):
mode = fcntl.fcntl(fd, fcntl.F_GETFL) & os.O_ACCMODE if os.name != 'nt' else os.O_RDWR
if mode == os.O_RDONLY:
raise OSError(9, 'Windows _commit requires writable file descriptor')
flushed.append(fd)
return real_fsync(fd)
with patch.object(update.os, 'fsync', side_effect=windows_fsync):
self.worker_harness()
state = update.read(self.root / '.runtime/update/status.json')
self.assertEqual('completed', state['state'], state['message'])
self.assertTrue(flushed)
backup = next((self.root / '.runtime/update').glob('backup-*'))
self.assertEqual(self.config, update.read(backup / 'private/deployment.json'))
self.assertEqual(b'{"apiKey":"keep-private"}', (backup / 'private/analysis-api-settings.json').read_bytes())
def test_failure_receipt_records_stage_and_codes_without_private_details(self):
error = OSError(5, 'privatePasswordValue must never be logged')
update.record_failure(self.root, 'backupProgram', error)
receipt = update.read(self.root / '.runtime/update/failure.json')
self.assertEqual('backupProgram', receipt['stage'])
self.assertEqual(5, receipt['errno'])
self.assertNotIn('privatePasswordValue', json.dumps(receipt))
with patch.object(update, 'atomic', side_effect=OSError('disk full')):
update.record_failure(self.root, 'backupProgram', error)
def test_complete_update_orchestration_with_isolated_database_backup(self):
calls, restores, queries = self.worker_harness()
self.assertEqual([('stop', False), ('serve', True), ('stop', False), ('verify', False), ('serve', False)], calls)