[F139] scope active_task_owns_branch to the polled project

active_task_owns_branch did an unscoped WHERE branch_name = ? — a cross-project
branch_name collision (UUID-derived 8-char prefixes, theoretical) made the
internal-PR reviewer skip the WRONG project's PR (project A's leftover PR
skipped because project B happened to have an active task with the same
branch). Pass project_id (in scope at the orchestrator call site) and add
TaskTable.project_id == project_id to the WHERE. Correct for single-project
tasks and MegaTask multi-repo batches alike: each root-subtask carries its own
project_id matching its own repo, so a branch on project A's repo is owned
only by a task whose project_id == A.
This commit is contained in:
Renn F
2026-06-29 00:49:36 +02:00
parent e8f5d531c7
commit fb850e8235
4 changed files with 138 additions and 6 deletions
@@ -146,17 +146,18 @@ def _branch_service(*, found: bool) -> TaskService:
@pytest.mark.asyncio
async def test_active_task_owns_branch_true_when_live_task_holds_it() -> None:
assert (
await _branch_service(found=True).active_task_owns_branch("feature/x") is True
await _branch_service(found=True).active_task_owns_branch("feature/x", uuid4())
is True
)
@pytest.mark.asyncio
async def test_active_task_owns_branch_false_when_no_live_task() -> None:
svc = _branch_service(found=False)
assert await svc.active_task_owns_branch("feature/x") is False
assert await svc.active_task_owns_branch("feature/x", uuid4()) is False
@pytest.mark.asyncio
async def test_active_task_owns_branch_false_for_empty_branch() -> None:
# No branch → cannot be owned; never hits the DB.
assert await TaskService(MagicMock()).active_task_owns_branch("") is False
assert await TaskService(MagicMock()).active_task_owns_branch("", uuid4()) is False