mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
fix(block-ci): refresh test evidence before reporting readiness
This commit is contained in:
1 parent
58347a55f0
commit
9a8a3b81fb
2 files changed
+63
-1
No files matched your search
@@ -183,6 +183,63 @@ class PortTests(unittest.TestCase):
|
||||
lines = [line.strip() for line in text.splitlines() if line.strip().startswith("runs-on:")]
|
||||
self.assertEqual(lines, ["runs-on: " + expected])
|
||||
|
||||
def test_rerun_during_local_checks_cannot_report_ready(self):
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
spec = importlib.util.spec_from_file_location("safe_merge", HERE / "safe-merge-check.py")
|
||||
check = importlib.util.module_from_spec(spec); spec.loader.exec_module(check)
|
||||
def pr(number):
|
||||
return {"number": number, "state": "open", "draft": False, "mergeable": True,
|
||||
"base": {"ref": "master"}, "head": {"sha": str(number)}}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
evidence = Path(tmp) / "acceptance"; evidence.write_text("accepted")
|
||||
members = [pr(1), pr(2)]
|
||||
manifest = {"base": "base", "head": "3", "batch_pr": 3,
|
||||
"prs": [{"number": n, "head": str(n), "evidence": str(evidence)} for n in (1, 2)]}
|
||||
path = Path(tmp) / "batch.json"; path.write_text(json.dumps(manifest))
|
||||
for batch in (False, True):
|
||||
for outcome in ("in_progress", "failed_run", "failed_job", "new_run", "success"):
|
||||
with self.subTest(batch=batch, outcome=outcome):
|
||||
changed = False
|
||||
observations = []
|
||||
number = 3 if batch else 1
|
||||
def api(endpoint):
|
||||
if endpoint == "git/ref/heads/master": return {"object": {"sha": "base"}}
|
||||
if endpoint.startswith("pulls/"): return pr(int(endpoint.split("/")[-1]))
|
||||
if endpoint == "git/commits/3": return {"tree": {"sha": "tree"}}
|
||||
observations.append(("run", changed))
|
||||
run = {"id": 10, "run_attempt": 2 if changed else 1, "created_at": "1",
|
||||
"path": check.WORKFLOW_PATH, "name": "Block Test", "head_sha": str(number),
|
||||
"status": "completed", "conclusion": "success",
|
||||
"pull_requests": [{"number": number, "base": {"sha": "base"}}]}
|
||||
if changed and outcome in ("in_progress", "new_run"):
|
||||
run.update(status="in_progress", conclusion=None)
|
||||
if outcome == "new_run": run.update(id=11, created_at="2")
|
||||
if changed and outcome == "failed_run": run["conclusion"] = "failure"
|
||||
return {"workflow_runs": [run]}
|
||||
def jobs(*args, **kwargs):
|
||||
observations.append(("jobs", changed))
|
||||
result = [{"name": name, "conclusion": "success"} for name in check.JOBS]
|
||||
if changed and outcome == "failed_job": result[0]["conclusion"] = "failure"
|
||||
return json.dumps([{"jobs": result}]).encode()
|
||||
def local(*args):
|
||||
nonlocal changed
|
||||
changed = True
|
||||
output = io.StringIO()
|
||||
with patch.object(check, "api", side_effect=api), patch.object(check.subprocess, "check_output", side_effect=jobs), patch.object(check, "fetch_review_head"), patch.object(check, "local_checks", side_effect=local), contextlib.redirect_stdout(output):
|
||||
if outcome == "success":
|
||||
check.main(["--batch", str(path)] if batch else ["1"])
|
||||
else:
|
||||
with self.assertRaises(ValueError):
|
||||
check.main(["--batch", str(path)] if batch else ["1"])
|
||||
if outcome == "success":
|
||||
self.assertTrue(json.loads(output.getvalue())["ready"])
|
||||
else:
|
||||
self.assertNotIn('"ready": true', output.getvalue())
|
||||
self.assertIn(("run", True), observations)
|
||||
self.assertIn(("jobs", True), observations)
|
||||
|
||||
def test_batch_preserves_pinned_base_heads_order_and_evidence(self):
|
||||
spec = importlib.util.spec_from_file_location("safe_merge", HERE / "safe-merge-check.py")
|
||||
check = importlib.util.module_from_spec(spec); spec.loader.exec_module(check)
|
||||
|
||||
@@ -103,7 +103,10 @@ def main(args):
|
||||
if api("git/ref/heads/master")["object"]["sha"] != current: raise ValueError("master moved; recheck")
|
||||
for pr in prs + [batch]:
|
||||
if api("pulls/" + str(pr["number"]))["head"]["sha"] != pr["head"]["sha"]: raise ValueError("head moved; recheck")
|
||||
print(json.dumps({"ready": True, "base": current, "head": manifest["head"], "run": run["id"], "tree": api("git/commits/" + manifest["head"])["tree"]["sha"], "order": [p["number"] for p in prs]}))
|
||||
tree = api("git/commits/" + manifest["head"])["tree"]["sha"]
|
||||
# A rerun can invalidate the earlier success while local checks execute.
|
||||
run = successful_run(batch, current)
|
||||
print(json.dumps({"ready": True, "base": current, "head": manifest["head"], "run": run["id"], "tree": tree, "order": [p["number"] for p in prs]}))
|
||||
return
|
||||
if len(args) != 1 or not args[0].isdecimal(): raise ValueError("expected PR, --batch MANIFEST or --verify-tree TREE")
|
||||
pr = api("pulls/" + args[0])
|
||||
@@ -111,6 +114,8 @@ def main(args):
|
||||
local_checks(pr, current)
|
||||
if api("git/ref/heads/master")["object"]["sha"] != current or api("pulls/" + args[0])["head"]["sha"] != pr["head"]["sha"]:
|
||||
raise ValueError("base or head moved; recheck")
|
||||
# Refresh the latest run and both jobs after every potentially slow check.
|
||||
run = successful_run(pr, current)
|
||||
print(json.dumps({"ready": True, "head": pr["head"]["sha"], "base": current, "run": run["id"], "merge_mode": "squash"}))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user