From 084ee1b176219031e0d93944dddd04fae6e33be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Mon, 23 Nov 2026 03:01:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E5=85=BC=E5=AE=B9=20HiFox=20?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E4=BA=8B=E4=BB=B6=E8=B7=A8=E7=A7=92=E5=86=99?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 任务更新时间与状态事件分别写入,允许小幅时间偏差。 仍以最近事件验证操作者,并要求验收证据早于两条时间记录。 --- scripts/production_cd.py | 14 +++++++++++--- scripts/test_production_cd.py | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/production_cd.py b/scripts/production_cd.py index d0286a6..d3c0617 100644 --- a/scripts/production_cd.py +++ b/scripts/production_cd.py @@ -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): diff --git a/scripts/test_production_cd.py b/scripts/test_production_cd.py index f4345b7..dde0301 100644 --- a/scripts/test_production_cd.py +++ b/scripts/test_production_cd.py @@ -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: