任务更新时间与状态事件分别写入,允许小幅时间偏差。 仍以最近事件验证操作者,并要求验收证据早于两条时间记录。
This commit is contained in:
@@ -201,8 +201,16 @@ def release_approval(task, timeline, request):
|
||||
require(bool(changes), 'missing HiFox status history')
|
||||
approval = changes[-1]
|
||||
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') == '待发布'
|
||||
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 matches(UUID, approval.get('id')), 'the latest transition must be an approval by the release owner')
|
||||
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')
|
||||
report = reports[0]
|
||||
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,
|
||||
'the unchanged report must identify the candidate and predate approval')
|
||||
binding = {'approval_event': approval['id'], 'acceptance_digest': acceptance_digest(evidence)}
|
||||
require(all(request.get(key, value) == value for key, value in binding.items()),
|
||||
'HiFox approval or acceptance changed after dispatch')
|
||||
return binding, approval['createdAt']
|
||||
return binding, min(event_at, status_at)
|
||||
|
||||
|
||||
def accepted_task(host, request):
|
||||
|
||||
@@ -150,6 +150,7 @@ class ProductionCD(unittest.TestCase):
|
||||
|
||||
def test_hifox_dispatch_claims_one_transition(self):
|
||||
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')
|
||||
with patch.object(trigger, 'hifox', side_effect=[task, timeline, task, timeline]), \
|
||||
patch.object(trigger, 'forge', return_value={'workflow_run_id': 42}) as dispatch:
|
||||
|
||||
Reference in New Issue
Block a user