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

@@ -370,30 +370,22 @@ async def test_init_creates_beads_directory(bd_executable):
# Ensure .beads doesn't exist yet
assert not beads_dir.exists()
# Create client WITHOUT beads_db set (this was the bug!)
client = BdClient(bd_path=bd_executable, beads_db=None)
# Create client WITHOUT beads_db set and WITH working_dir set to temp_dir
client = BdClient(bd_path=bd_executable, beads_db=None, working_dir=temp_dir)
# Change to temp directory and run init
original_cwd = os.getcwd()
try:
os.chdir(temp_dir)
# Initialize with custom prefix (no need to chdir!)
params = InitParams(prefix="test")
result = await client.init(params)
# Initialize with custom prefix
params = InitParams(prefix="test")
result = await client.init(params)
# Verify .beads directory was created in temp directory
assert beads_dir.exists(), f".beads directory not created in {temp_dir}"
assert beads_dir.is_dir(), f".beads exists but is not a directory"
# Verify .beads directory was created in current directory
assert beads_dir.exists(), f".beads directory not created in {temp_dir}"
assert beads_dir.is_dir(), f".beads exists but is not a directory"
# Verify database file was created with correct prefix
db_files = list(beads_dir.glob("*.db"))
assert len(db_files) > 0, "No database file created in .beads/"
assert any("test" in str(db.name) for db in db_files), \
f"Database file doesn't contain prefix 'test': {[db.name for db in db_files]}"
# Verify database file was created with correct prefix
db_files = list(beads_dir.glob("*.db"))
assert len(db_files) > 0, "No database file created in .beads/"
assert any("test" in str(db.name) for db in db_files), \
f"Database file doesn't contain prefix 'test': {[db.name for db in db_files]}"
# Verify success message
assert "initialized" in result.lower() or "created" in result.lower()
finally:
os.chdir(original_cwd)
# Verify success message
assert "initialized" in result.lower() or "created" in result.lower()