43 lines
2.5 KiB
Python
43 lines
2.5 KiB
Python
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'])
|
|
quoted = dict(reply, content='「确认范围」')
|
|
with patch.object(h, 'comments', return_value=[parent, quoted]):
|
|
self.assertEqual(h.frozen_approval('task', 'ok'), saved['plan'])
|
|
self.assertIsNone(h.frozen_approval('task', 'other'))
|
|
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')
|