修正游客发布验收模拟并覆盖回滚清理

This commit is contained in:
2026-10-30 12:25:55 +08:00
parent 439241dd83
commit 8853ea2dfa
+21 -1
View File
@@ -41,7 +41,17 @@ elif name == 'curl' and '-w' in args:
if scenario == 'proxy-unsafe':
print('200', end='')
sys.exit(0)
print('401', end='')
path = '/' + args[-1].split('://', 1)[-1].partition('/')[2]
if '-c' in args:
pathlib.Path(args[args.index('-c') + 1]).write_text('fixture-visitor-cookie')
if '-b' in args:
assert pathlib.Path(args[args.index('-b') + 1]).read_text() == 'fixture-visitor-cookie'
status = '200' if path == '/' or path == '/api/visitor/session' or (path == '/api/get_history' and '-b' in args) else '401'
if scenario == 'visitor-bootstrap-fail' and path == '/api/visitor/session':
status = '503'
if scenario == 'visitor-history-fail' and path == '/api/get_history' and '-b' in args:
status = '503'
print(status, end='')
elif name == 'sleep':
pass
'''
@@ -97,6 +107,7 @@ class GrayActivationTests(unittest.TestCase):
env=environment, capture_output=True, text=True, timeout=30)
self.assertEqual((root / 'data/history.db').read_bytes(), b'preserve-existing-data')
self.assertEqual(unrelated.read_text(), '# unrelated site\n')
self.assertFalse(list(release.glob('.visitor-smoke.*')), 'Temporary visitor cookies must be removed on success and rollback')
calls = [json.loads(line) for line in log.read_text().splitlines()]
return result, root, proxy, previous, release, old_site, calls
@@ -119,6 +130,7 @@ class GrayActivationTests(unittest.TestCase):
self.assertEqual((proxy.parent / 'baiyue-logistics-chat-gray-proxy/access.htpasswd').read_text(), 'previous-auth-hash\n')
self.assertTrue(any(name == 'docker' and 'up' in args and str(previous / 'release.env') in args
for name, args in calls), result.stderr)
return result
def test_failed_application_restores_previous_release(self):
self.assert_rolled_back('app-fail')
@@ -132,6 +144,14 @@ class GrayActivationTests(unittest.TestCase):
def test_unprotected_proxy_never_publishes_the_release_pointer(self):
self.assert_rolled_back('proxy-unsafe')
def test_failed_visitor_bootstrap_rolls_back_and_removes_cookie_file(self):
result = self.assert_rolled_back('visitor-bootstrap-fail')
self.assertIn('Guest session bootstrap verification failed.', result.stderr)
def test_failed_cookie_history_rolls_back_and_removes_cookie_file(self):
result = self.assert_rolled_back('visitor-history-fail')
self.assertIn('Guest history verification failed.', result.stderr)
def test_image_retagged_after_verified_load_is_rejected_before_activation(self):
result, root, proxy, previous, release, old_site, calls = self.run_activation('image-mismatch')
self.assertNotEqual(result.returncode, 0)