From fd6eae0d1d24123824b166461e2e65ed250cc473 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 18 Jul 2024 12:34:42 +0200 Subject: [PATCH] [IMP] runbot_merge: ensure inconsistent batches don't merge I was pretty sure it wouldn't happen but it doesn't hurt to make sure, also to check that splitting the batch does correctly make things work out. --- runbot_merge/tests/test_batch_consistency.py | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/runbot_merge/tests/test_batch_consistency.py b/runbot_merge/tests/test_batch_consistency.py index e99e1fc2..9298f143 100644 --- a/runbot_merge/tests/test_batch_consistency.py +++ b/runbot_merge/tests/test_batch_consistency.py @@ -81,7 +81,7 @@ def test_close_multiple(env, make_repo2): assert not batch_id.active assert Batches.search_count([]) == 0 -def test_inconsistent_target(env, project, make_repo2, users, page): +def test_inconsistent_target(env, project, make_repo2, users, page, config): """If a batch's PRs have inconsistent targets, - only open PRs should count @@ -97,8 +97,8 @@ def test_inconsistent_target(env, project, make_repo2, users, page): project.write({'branch_ids': [(0, 0, {'name': 'other'})]}) with repo1: - repo1.make_commits(None, Commit("a", tree={"a": "a"}), ref='heads/master') - repo1.make_commits(None, Commit("a", tree={"a": "a"}), ref='heads/other') + [m] = repo1.make_commits(None, Commit("a", tree={"a": "a"}), ref='heads/master') + repo1.make_ref('heads/other', m) repo1.make_commits('master', Commit('b', tree={"b": "b"}), ref='heads/a_pr') pr1 = repo1.make_pr(head='a_pr', target='master') @@ -161,6 +161,19 @@ Inconsistent targets: assert b.target.name == False assert to_pr(env, pr_other).label == f'{owner}:something_else' + # try staging + with repo1: + pr1.post_comment("hansen r+", config['role_reviewer']['token']) + repo1.post_status(pr1.head, "success") + with repo2: + pr2.post_comment("hansen r+", config['role_reviewer']['token']) + repo2.post_status(pr2.head, "success") + env.run_crons() + assert not pr1_id.blocked + assert not pr2_id.blocked + assert b.blocked + assert env['runbot_merge.stagings'].search_count([]) == 0 + act = pr2_id.button_split() assert act['type'] == 'ir.actions.act_window' assert act['views'] == [[False, 'form']] @@ -178,3 +191,11 @@ Inconsistent targets: assert len(b.prs) == 1, "the PR has been moved off of this batch entirely" assert len(b.all_prs) == 2 # endregion + + assert not pr1_id.blocked + assert not pr1_id.batch_id.blocked + assert not pr2_id.blocked + assert not pr2_id.batch_id.blocked + env.run_crons() + + assert env['runbot_merge.stagings'].search_count([])