test(mcp): Fix two failing integration tests and linting errors

1. Fix `test_default_beads_path_auto_detection`
    - Changed beads_path to use `Field(default_factory=_default_beads_path)` so the default is evaluated at instance
    creation time, not class definition time
    - Updated test to mock both `shutil.which` and `os.access`
2. Fix `test_init_creates_beads_directory`
    - Fixed test to pass `working_dir=temp_dir` to `BdClient` instead of using `os.chdir()`
    - The `_get_working_dir()` method checks `PWD` env var first, which isn't updated by `os.chdir()`
3. Fix minor linting errors reported by `ruff` tool
4. Update `beads` version to `0.9.6` in `uv.lock` file

MCP Server test coverage is now excellent, at 92% overall maintaining our high-standards of production level quality.

```
Name                         Stmts   Miss  Cover
------------------------------------------------
src/beads_mcp/__init__.py        1      0   100%
src/beads_mcp/__main__.py        3      3     0%
src/beads_mcp/bd_client.py     214     14    93%
src/beads_mcp/config.py         51      2    96%
src/beads_mcp/models.py         92      1    99%
src/beads_mcp/server.py         58     16    72%
src/beads_mcp/tools.py          59      0   100%
------------------------------------------------
TOTAL                          478     36    92%
```
This commit is contained in:
Baishampayan Ghose
2025-10-15 16:48:39 +05:30
parent 953858b853
commit 4353592fe6
7 changed files with 38 additions and 71 deletions

View File

@@ -101,12 +101,8 @@ class BdClient:
self.bd_path = bd_path if bd_path is not None else config.beads_path
self.beads_db = beads_db if beads_db is not None else config.beads_db
self.actor = actor if actor is not None else config.beads_actor
self.no_auto_flush = (
no_auto_flush if no_auto_flush is not None else config.beads_no_auto_flush
)
self.no_auto_import = (
no_auto_import if no_auto_import is not None else config.beads_no_auto_import
)
self.no_auto_flush = no_auto_flush if no_auto_flush is not None else config.beads_no_auto_flush
self.no_auto_import = no_auto_import if no_auto_import is not None else config.beads_no_auto_import
self.working_dir = working_dir if working_dir is not None else config.beads_working_dir
def _get_working_dir(self) -> str:
@@ -161,9 +157,7 @@ class BdClient:
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
raise BdNotFoundError(
BdNotFoundError.installation_message(self.bd_path)
) from e
raise BdNotFoundError(BdNotFoundError.installation_message(self.bd_path)) from e
if process.returncode != 0:
raise BdCommandError(
@@ -205,9 +199,7 @@ class BdClient:
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
raise BdNotFoundError(
BdNotFoundError.installation_message(self.bd_path)
) from e
raise BdNotFoundError(BdNotFoundError.installation_message(self.bd_path)) from e
if process.returncode != 0:
raise BdCommandError(
@@ -220,9 +212,7 @@ class BdClient:
version_output = stdout.decode().strip()
match = re.search(r"(\d+)\.(\d+)\.(\d+)", version_output)
if not match:
raise BdVersionError(
f"Could not parse bd version from: {version_output}"
)
raise BdVersionError(f"Could not parse bd version from: {version_output}")
version = tuple(int(x) for x in match.groups())
@@ -418,9 +408,7 @@ class BdClient:
)
_stdout, stderr = await process.communicate()
except FileNotFoundError as e:
raise BdNotFoundError(
BdNotFoundError.installation_message(self.bd_path)
) from e
raise BdNotFoundError(BdNotFoundError.installation_message(self.bd_path)) from e
if process.returncode != 0:
raise BdCommandError(
@@ -446,9 +434,7 @@ class BdClient:
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
raise BdNotFoundError(
BdNotFoundError.installation_message(self.bd_path)
) from e
raise BdNotFoundError(BdNotFoundError.installation_message(self.bd_path)) from e
if process.returncode != 0:
raise BdCommandError(
@@ -513,9 +499,7 @@ class BdClient:
)
stdout, stderr = await process.communicate()
except FileNotFoundError as e:
raise BdNotFoundError(
BdNotFoundError.installation_message(self.bd_path)
) from e
raise BdNotFoundError(BdNotFoundError.installation_message(self.bd_path)) from e
if process.returncode != 0:
raise BdCommandError(