Merge pull request 'fix(deploy): 兼容 HiFox 确认事件跨秒写入' (#22) from fix/hifox-approval-timestamps into main
build / build (push) Successful in 1m28s
build / build (push) Successful in 1m28s
This commit was merged in pull request #22.
This commit is contained in:
@@ -201,8 +201,16 @@ def release_approval(task, timeline, request):
|
|||||||
require(bool(changes), 'missing HiFox status history')
|
require(bool(changes), 'missing HiFox status history')
|
||||||
approval = changes[-1]
|
approval = changes[-1]
|
||||||
approver = approval.get('actor') or {}
|
approver = approval.get('actor') or {}
|
||||||
|
event_at = approval.get('createdAt') or ''
|
||||||
|
status_at = task.get('statusChangedAt') or ''
|
||||||
|
try:
|
||||||
|
difference = abs((datetime.fromisoformat(event_at.replace('Z', '+00:00'))
|
||||||
|
- datetime.fromisoformat(status_at.replace('Z', '+00:00'))).total_seconds())
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
difference = float('inf')
|
||||||
|
# HiFox logs the status change after saving the task, sometimes across a second boundary.
|
||||||
require((approval.get('metadata') or {}).get('to') == '待发布'
|
require((approval.get('metadata') or {}).get('to') == '待发布'
|
||||||
and approval.get('createdAt') and approval['createdAt'] == task.get('statusChangedAt')
|
and difference <= 2
|
||||||
and approver.get('id') == RELEASE_OWNER and approver.get('type') == 'human'
|
and approver.get('id') == RELEASE_OWNER and approver.get('type') == 'human'
|
||||||
and matches(UUID, approval.get('id')), 'the latest transition must be an approval by the release owner')
|
and matches(UUID, approval.get('id')), 'the latest transition must be an approval by the release owner')
|
||||||
task_url = task.get('url', '')
|
task_url = task.get('url', '')
|
||||||
@@ -215,13 +223,13 @@ def release_approval(task, timeline, request):
|
|||||||
require(len(reports) == 1, 'acceptance report missing from task history')
|
require(len(reports) == 1, 'acceptance report missing from task history')
|
||||||
report = reports[0]
|
report = reports[0]
|
||||||
body = report.get('content') or ''
|
body = report.get('content') or ''
|
||||||
require(report.get('createdAt') and (report.get('updatedAt') or report['createdAt']) < approval['createdAt']
|
require(report.get('createdAt') and (report.get('updatedAt') or report['createdAt']) < min(event_at, status_at)
|
||||||
and request['sha'] in body and request['bundle'] in body,
|
and request['sha'] in body and request['bundle'] in body,
|
||||||
'the unchanged report must identify the candidate and predate approval')
|
'the unchanged report must identify the candidate and predate approval')
|
||||||
binding = {'approval_event': approval['id'], 'acceptance_digest': acceptance_digest(evidence)}
|
binding = {'approval_event': approval['id'], 'acceptance_digest': acceptance_digest(evidence)}
|
||||||
require(all(request.get(key, value) == value for key, value in binding.items()),
|
require(all(request.get(key, value) == value for key, value in binding.items()),
|
||||||
'HiFox approval or acceptance changed after dispatch')
|
'HiFox approval or acceptance changed after dispatch')
|
||||||
return binding, approval['createdAt']
|
return binding, min(event_at, status_at)
|
||||||
|
|
||||||
|
|
||||||
def accepted_task(host, request):
|
def accepted_task(host, request):
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ class ProductionCD(unittest.TestCase):
|
|||||||
|
|
||||||
def test_hifox_dispatch_claims_one_transition(self):
|
def test_hifox_dispatch_claims_one_transition(self):
|
||||||
task, timeline = self.hifox_fixture()
|
task, timeline = self.hifox_fixture()
|
||||||
|
timeline[-1]['createdAt'] = '2026-11-22T18:00:01Z'
|
||||||
cd.atomic_write(self.root / 'active-since', b'2026-11-22T17:55:00Z\n')
|
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]), \
|
with patch.object(trigger, 'hifox', side_effect=[task, timeline, task, timeline]), \
|
||||||
patch.object(trigger, 'forge', return_value={'workflow_run_id': 42}) as dispatch:
|
patch.object(trigger, 'forge', return_value={'workflow_run_id': 42}) as dispatch:
|
||||||
|
|||||||
Reference in New Issue
Block a user