将发布人的状态变更与业务验收报告绑定,复用 Gitea 发布及回滚链路。 从部署回执写入运行身份、镜像及主站登录入口,避免重复调度和回写。
This commit is contained in:
@@ -3,9 +3,10 @@ import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import production_cd as cd
|
||||
import hifox_release_trigger as trigger
|
||||
|
||||
|
||||
SHA = 'a' * 40
|
||||
@@ -134,6 +135,74 @@ class ProductionCD(unittest.TestCase):
|
||||
with self.assertRaisesRegex(cd.CDError, 'dispatch proof'):
|
||||
cd.verify_guard_log(log + log, self.request, trusted)
|
||||
|
||||
def hifox_fixture(self):
|
||||
task = self.host.task.return_value
|
||||
report = 'ba3ced78-e648-47de-9c17-bccb8f31f36f'
|
||||
event = 'a3aa1dbe-4082-4972-8e29-ed3e39e26b30'
|
||||
task.update(url='https://app.hifox.com/example/task/TEST-42', statusChangedAt='2026-11-22T18:00:00Z')
|
||||
self.acceptance['evidence'] = task['url'] + '#comment-' + report
|
||||
task['metadata']['cd_acceptance'] = json.dumps(self.acceptance)
|
||||
timeline = [dict(id=report, event='commented', createdAt='2026-11-22T17:59:00Z',
|
||||
content=f'验收通过 {SHA} {self.request["bundle"]}'),
|
||||
dict(id=event, event='status_changed', createdAt=task['statusChangedAt'],
|
||||
actor={'type': 'human', 'id': cd.RELEASE_OWNER}, metadata={'to': '待发布'})]
|
||||
return task, timeline
|
||||
|
||||
def test_hifox_dispatch_claims_one_transition(self):
|
||||
task, timeline = self.hifox_fixture()
|
||||
cd.atomic_write(self.root / 'active-since', b'2026-11-22T17:55:00Z\n')
|
||||
with patch.object(trigger, 'hifox', side_effect=[task, timeline, task, timeline]), \
|
||||
patch.object(trigger, 'forge', return_value={'workflow_run_id': 42}) as dispatch:
|
||||
first = trigger.queue(TASK, 'unused', self.root)
|
||||
replay = trigger.queue(TASK, 'unused', self.root)
|
||||
self.assertEqual(first, replay)
|
||||
self.assertEqual(first['run_id'], '42')
|
||||
dispatch.assert_called_once_with('POST', trigger.DISPATCH, {'ref': 'main', 'inputs': first['inputs']})
|
||||
self.assertEqual(first['inputs']['approval_event'], timeline[-1]['id'])
|
||||
|
||||
def test_unknown_dispatch_outcome_is_held(self):
|
||||
task, timeline = self.hifox_fixture()
|
||||
cd.atomic_write(self.root / 'active-since', b'2026-11-22T17:55:00Z\n')
|
||||
with patch.object(trigger, 'hifox', side_effect=[task, timeline, task, timeline]), \
|
||||
patch.object(trigger, 'forge', side_effect=TimeoutError()) as dispatch:
|
||||
with self.assertRaises(TimeoutError):
|
||||
trigger.queue(TASK, 'unused', self.root)
|
||||
with self.assertRaisesRegex(cd.CDError, 'outcome unknown'):
|
||||
trigger.queue(TASK, 'unused', self.root)
|
||||
dispatch.assert_called_once()
|
||||
|
||||
def test_hifox_gate_requires_owner_and_existing_candidate_report(self):
|
||||
for failure in ('agent', 'other human', 'mismatched report', 'updated report', 'stale transition', 'no evidence'):
|
||||
with self.subTest(failure=failure):
|
||||
task, timeline = self.hifox_fixture()
|
||||
if failure == 'agent':
|
||||
timeline[-1]['actor']['type'] = 'agent'
|
||||
if failure == 'other human':
|
||||
timeline[-1]['actor']['id'] = TASK
|
||||
if failure == 'mismatched report':
|
||||
timeline[0]['content'] = SHA
|
||||
if failure == 'updated report':
|
||||
timeline[0]['updatedAt'] = '2026-11-22T19:00:00Z'
|
||||
if failure == 'stale transition':
|
||||
task['statusChangedAt'] = '2026-11-22T19:00:00Z'
|
||||
if failure == 'no evidence':
|
||||
task['metadata'] = {}
|
||||
with patch.object(trigger, 'hifox', side_effect=[task, timeline]), patch.object(trigger, 'forge') as forge:
|
||||
with self.assertRaises(cd.CDError):
|
||||
trigger.queue(TASK, 'unused', self.root)
|
||||
forge.assert_not_called()
|
||||
|
||||
def test_auto_approval_is_checked_again_before_switch(self):
|
||||
task, timeline = self.hifox_fixture()
|
||||
approval, _ = cd.release_approval(task, timeline, self.request)
|
||||
self.request.update(approval)
|
||||
self.host.timeline.side_effect = [timeline, timeline[:-1]]
|
||||
proof = cd.guard_proof(self.request, 'f' * 40)
|
||||
self.assertNotEqual(proof, cd.guard_proof({**self.request, 'acceptance_digest': 'e' * 64}, 'f' * 40))
|
||||
with self.assertRaisesRegex(cd.CDError, 'status history'):
|
||||
self.execute()
|
||||
self.host.switch.assert_not_called()
|
||||
|
||||
def test_target_lock_is_exclusive(self):
|
||||
path = self.root / 'lock'
|
||||
with cd.deploy_lock(path):
|
||||
|
||||
Reference in New Issue
Block a user