feat(mcp): Add reopen command support for closed issues

Implements the `bd` reopen command across the entire MCP stack, enabling
agents to reopen closed issues with optional reason tracking for audit
trails. This addresses the need to handle regressions and incorrectly
closed issues without manual `bd` CLI intervention.

The reopen command is more explicit than `bd update --status open` and
emits a dedicated Reopened event in the audit log, making it easier to
track why issues were reopened during analysis.

Changes:
  - `models.py`: Add ReopenIssueParams with issue_ids list and optional reason
  - `bd_client.py`: Implement reopen() method with JSON response parsing
  - `tools.py`: Add beads_reopen_issue() wrapper with Annotated types for MCP
  - `server.py`: Register 'reopen' MCP tool with description and parameters

Testing (10 new):
  - `test_bd_client.py`: 4 unit tests (mocked subprocess)
  - `test_bd_client_integration.py`: 3 integration tests (real `bd` CLI)
  - `test_mcp_server_integration.py`: 3 MCP integration tests (FastMCP Client)
  - `test_tools.py`: 3 tools wrapper tests (mocked BdClient)

Also updated `README.md`.
This commit is contained in:
Baishampayan Ghose
2025-10-16 18:08:37 +05:30
committed by Steve Yegge
parent 331a435418
commit 32a718dacd
10 changed files with 390 additions and 26 deletions

View File

@@ -14,6 +14,7 @@ from beads_mcp.tools import (
beads_list_issues,
beads_quickstart,
beads_ready_work,
beads_reopen_issue,
beads_show_issue,
beads_stats,
beads_update_issue,
@@ -168,6 +169,66 @@ async def test_beads_close_issue(sample_issue):
mock_client.close.assert_called_once()
@pytest.mark.asyncio
async def test_beads_reopen_issue(sample_issue):
"""Test beads_reopen_issue tool."""
reopened_issue = sample_issue.model_copy(
update={"status": "open", "closed_at": None}
)
mock_client = AsyncMock()
mock_client.reopen = AsyncMock(return_value=[reopened_issue])
with patch("beads_mcp.tools._get_client", return_value=mock_client):
issues = await beads_reopen_issue(issue_ids=["bd-1"])
assert len(issues) == 1
assert issues[0].status == "open"
assert issues[0].closed_at is None
mock_client.reopen.assert_called_once()
@pytest.mark.asyncio
async def test_beads_reopen_multiple_issues(sample_issue):
"""Test beads_reopen_issue with multiple issues."""
reopened_issue1 = sample_issue.model_copy(
update={"id": "bd-1", "status": "open", "closed_at": None}
)
reopened_issue2 = sample_issue.model_copy(
update={"id": "bd-2", "status": "open", "closed_at": None}
)
mock_client = AsyncMock()
mock_client.reopen = AsyncMock(return_value=[reopened_issue1, reopened_issue2])
with patch("beads_mcp.tools._get_client", return_value=mock_client):
issues = await beads_reopen_issue(issue_ids=["bd-1", "bd-2"])
assert len(issues) == 2
assert issues[0].status == "open"
assert issues[1].status == "open"
assert all(issue.closed_at is None for issue in issues)
mock_client.reopen.assert_called_once()
@pytest.mark.asyncio
async def test_beads_reopen_issue_with_reason(sample_issue):
"""Test beads_reopen_issue with reason parameter."""
reopened_issue = sample_issue.model_copy(
update={"status": "open", "closed_at": None}
)
mock_client = AsyncMock()
mock_client.reopen = AsyncMock(return_value=[reopened_issue])
with patch("beads_mcp.tools._get_client", return_value=mock_client):
issues = await beads_reopen_issue(
issue_ids=["bd-1"], reason="Found regression"
)
assert len(issues) == 1
assert issues[0].status == "open"
assert issues[0].closed_at is None
mock_client.reopen.assert_called_once()
@pytest.mark.asyncio
async def test_beads_add_dependency_success():
"""Test beads_add_dependency tool success."""