feat(release): 从预检评论接单并固定候选版本
build / build (push) Successful in 2m28s

This commit is contained in:
姚章浩
2026-11-24 14:39:43 +08:00
parent 8d873680cc
commit 4a12b20e9b
9 changed files with 447 additions and 8 deletions
+38
View File
@@ -0,0 +1,38 @@
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
import release_handoff as h
class ReleaseHandoffTest(unittest.TestCase):
def setUp(self):
self.task = {'id': 'task'}
self.review = {'id': 'comment', 'taskId': 'task', 'createdAt': '2', 'author': {'id': h.WHITE},
'content': '🚦 可测试 ✅|[任务](mention://task/task)\n落地 `abcdef1`'}
def test_latest_passing_review_and_task_identity(self):
self.assertEqual(h.review_identity(self.task, [self.review], 'comment')[0], 'abcdef1')
for invalid in (dict(self.review, author={'id': 'other'}), dict(self.review, taskId='other'),
dict(self.review, content='🚦 不可测试,引用「可测试」')):
with self.assertRaises(h.cd.CDError):
h.review_identity(self.task, [invalid], 'comment')
newer = dict(self.review, id='new', createdAt='3', content='🚦 未通过')
with self.assertRaises(h.cd.CDError):
h.review_identity(self.task, [self.review, newer], 'comment')
def test_owner_approval_is_bound_to_exact_preview_and_parent(self):
with tempfile.TemporaryDirectory() as tmp, patch.object(h, 'DIRECTORY', Path(tmp)):
saved = {'content': 'reviewed scope', 'comment': 'preview', 'plan': {'frozen': True}}
h.cd.record(Path(tmp) / 'task.preview.json', saved)
parent = {'id': 'preview', 'content': saved['content']}
reply = {'id': 'ok', 'createdAt': '2', 'content': '确认范围', 'parentId': 'preview',
'author': {'id': h.cd.RELEASE_OWNER, 'type': 'human'}}
with patch.object(h, 'comments', return_value=[parent, reply]):
self.assertEqual(h.frozen_approval('task'), saved['plan'])
for bad in (dict(reply, parentId=None), dict(reply, runId='agent-run'), dict(reply, content='先不确认范围')):
with patch.object(h, 'comments', return_value=[parent, bad]):
self.assertIsNone(h.frozen_approval('task'))
with patch.object(h, 'comments', return_value=[dict(parent, content='changed'), reply]), self.assertRaises(h.cd.CDError):
h.frozen_approval('task')