From 8853ea2dfa00bca408ee0150dbd79a18c5a11521 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Fri, 30 Oct 2026 12:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B8=B8=E5=AE=A2=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E9=AA=8C=E6=94=B6=E6=A8=A1=E6=8B=9F=E5=B9=B6=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E5=9B=9E=E6=BB=9A=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_gray_activation.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_gray_activation.py b/tests/test_gray_activation.py index 9d9b24a..1073ceb 100644 --- a/tests/test_gray_activation.py +++ b/tests/test_gray_activation.py @@ -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)