fix(cd): 支持已合入主干的现场基线
build / build (push) Successful in 1m40s

This commit is contained in:
姚章浩
2026-11-23 13:48:07 +08:00
parent 922ff66533
commit 8faabdcf9e
3 changed files with 50 additions and 7 deletions
+38
View File
@@ -1,5 +1,9 @@
from pathlib import Path
import subprocess
import tempfile
import unittest
from types import SimpleNamespace
from unittest.mock import patch
import candidate_release as candidate
import production_cd as cd
@@ -28,6 +32,40 @@ class CandidateReleaseTest(unittest.TestCase):
with self.assertRaisesRegex(cd.CDError, 'merged into main'):
candidate.check_scope(self.plan, self.prs.__getitem__, [A, B])
def test_merged_runtime_baseline_requires_full_main_scope(self):
with tempfile.TemporaryDirectory() as tmp:
repo = Path(tmp)
def git(*args):
return subprocess.check_output(['git', *args], cwd=repo, text=True).strip()
git('init', '-q')
git('config', 'user.name', 'Test')
git('config', 'user.email', 'test@example.invalid')
tree = git('hash-object', '-w', '-t', 'tree', '/dev/null')
def commit(message, *parents):
return git('commit-tree', tree, '-m', message, *(part for p in parents for part in ('-p', p)))
root = commit('root')
live = commit('running baseline', root)
control = commit('control plane', root)
integration = commit('bring the running version into main', control, live)
landed = commit('land business PR', integration)
git('update-ref', 'refs/remotes/origin/main', landed)
plan = dict(self.plan, base=live, sha=landed, items=[{'task': QA1, 'pr': 20}],
extra=[control, integration])
pr = dict(self.prs[20], merge_commit_sha=landed)
with patch.object(candidate, 'read_forge', return_value=pr), patch.object(cd, 'verify_contexts'):
candidate.verify_source(plan, repo)
with self.assertRaisesRegex(cd.CDError, 'outside the release scope'):
candidate.verify_source(dict(plan, extra=[integration]), repo)
unrelated = commit('unmerged branch', root)
with self.assertRaisesRegex(cd.CDError, 'baseline must be an ancestor'):
candidate.verify_source(dict(plan, base=unrelated), repo)
with self.assertRaisesRegex(cd.CDError, 'candidate must be on main'):
candidate.verify_source(dict(plan, base=root, sha=live), repo)
def test_require_all_qa_reports_and_shared_regression(self):
sources = {QA1: (self.report, self.result()), QA2: (self.report, self.result())}
with self.assertRaisesRegex(cd.CDError, 'every requirement and the release task'):