Implements the #420 recovery umbrella: keyed persistent issue locks with own-branch adoption, structured branch ownership parsing, create_pr lock resolution after MCP restart, and workflow docs forbidding destructive branch deletion as the default recovery path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Unit tests for own-branch lock adoption decision (#442 / #443)."""
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from issue_lock_adoption import ( # noqa: E402
|
|
ADOPT,
|
|
BLOCK_COMPETING,
|
|
NO_MATCH,
|
|
assess_own_branch_adoption,
|
|
build_adoption_proof,
|
|
)
|
|
|
|
REQ = "feat/issue-420-server-code-parity"
|
|
|
|
|
|
class TestAssessOwnBranchAdoption(unittest.TestCase):
|
|
def test_exact_own_branch_is_adopted(self):
|
|
result = assess_own_branch_adoption(
|
|
issue_number=420,
|
|
requested_branch=REQ,
|
|
existing_branches=[{"name": REQ, "commit_sha": "934688a"}],
|
|
)
|
|
self.assertEqual(result["outcome"], ADOPT)
|
|
self.assertTrue(result["adopt"])
|
|
|
|
def test_different_branch_same_issue_blocks(self):
|
|
result = assess_own_branch_adoption(
|
|
issue_number=420,
|
|
requested_branch=REQ,
|
|
existing_branches=[{"name": "feat/issue-420-other-work"}],
|
|
)
|
|
self.assertEqual(result["outcome"], BLOCK_COMPETING)
|
|
self.assertTrue(result["block"])
|
|
|
|
def test_no_matching_branch_is_normal_path(self):
|
|
result = assess_own_branch_adoption(
|
|
issue_number=420,
|
|
requested_branch=REQ,
|
|
existing_branches=[{"name": "feat/issue-999-unrelated"}],
|
|
)
|
|
self.assertEqual(result["outcome"], NO_MATCH)
|
|
|
|
def test_issue_number_substring_collision_is_ignored(self):
|
|
result = assess_own_branch_adoption(
|
|
issue_number=420,
|
|
requested_branch=REQ,
|
|
existing_branches=[{"name": "feat/issue-4200-unrelated"}],
|
|
)
|
|
self.assertEqual(result["outcome"], NO_MATCH)
|
|
|
|
|
|
class TestBuildAdoptionProof(unittest.TestCase):
|
|
def test_proof_has_required_fields(self):
|
|
assessment = assess_own_branch_adoption(
|
|
issue_number=420,
|
|
requested_branch=REQ,
|
|
existing_branches=[{"name": REQ, "commit_sha": "934688a"}],
|
|
)
|
|
proof = build_adoption_proof(
|
|
issue_number=420,
|
|
branch_name=REQ,
|
|
assessment=assessment,
|
|
open_pr_checked=True,
|
|
competing_lock_checked=True,
|
|
lock_file_path="/tmp/example-lock.json",
|
|
lock_file_status="written",
|
|
)
|
|
self.assertEqual(proof["branch_head_commit"], "934688a")
|
|
self.assertTrue(proof["no_existing_pr_proof"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main() |