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

@@ -5,7 +5,7 @@ import shutil
import sys
from pathlib import Path
from pydantic import field_validator
from pydantic import Field, field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -31,7 +31,7 @@ class Config(BaseSettings):
model_config = SettingsConfigDict(env_prefix="")
beads_path: str = _default_beads_path()
beads_path: str = Field(default_factory=_default_beads_path)
beads_db: str | None = None
beads_actor: str | None = None
beads_no_auto_flush: bool = False
@@ -71,9 +71,7 @@ class Config(BaseSettings):
)
if not os.access(v, os.X_OK):
raise ValueError(
f"bd executable at {v} is not executable.\nPlease check file permissions."
)
raise ValueError(f"bd executable at {v} is not executable.\nPlease check file permissions.")
return v
@@ -97,8 +95,7 @@ class Config(BaseSettings):
path = Path(v)
if not path.exists():
raise ValueError(
f"BEADS_DB points to non-existent file: {v}\n"
+ "Please verify the database path is correct."
f"BEADS_DB points to non-existent file: {v}\n" + "Please verify the database path is correct."
)
return v
@@ -124,7 +121,7 @@ def load_config() -> Config:
except Exception as e:
default_path = _default_beads_path()
error_msg = (
f"Beads MCP Server Configuration Error\n\n"
"Beads MCP Server Configuration Error\n\n"
+ f"{e}\n\n"
+ "Common fix: Install the bd CLI first:\n"
+ " curl -fsSL https://raw.githubusercontent.com/steveyegge/beads/main/install.sh | bash\n\n"