mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix(test): patch API fallback in project_context tests for Postgres
In Postgres test mode, stale dependency_overrides on the module-level FastAPI app allow _resolve_default_project_from_api() to query a live database and return 'test-project' even when the test sets default_project=None. Monkeypatch the async fallback in the three affected tests to isolate config-based resolution from API leakage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
@@ -31,17 +31,33 @@ async def test_returns_none_when_no_default_and_no_project(config_manager, monke
|
||||
config_manager.save_config(cfg)
|
||||
|
||||
monkeypatch.delenv("BASIC_MEMORY_MCP_PROJECT", raising=False)
|
||||
# Prevent API fallback from returning a project via stale dependency overrides
|
||||
async def _no_api_fallback():
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(
|
||||
"basic_memory.mcp.project_context._resolve_default_project_from_api",
|
||||
_no_api_fallback,
|
||||
)
|
||||
assert await resolve_project_parameter(project=None, allow_discovery=False) is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_allows_discovery_when_enabled(config_manager):
|
||||
async def test_allows_discovery_when_enabled(config_manager, monkeypatch):
|
||||
from basic_memory.mcp.project_context import resolve_project_parameter
|
||||
|
||||
cfg = config_manager.load_config()
|
||||
cfg.default_project = None
|
||||
config_manager.save_config(cfg)
|
||||
|
||||
# Prevent API fallback from returning a project via stale dependency overrides
|
||||
async def _no_api_fallback():
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(
|
||||
"basic_memory.mcp.project_context._resolve_default_project_from_api",
|
||||
_no_api_fallback,
|
||||
)
|
||||
assert await resolve_project_parameter(project=None, allow_discovery=True) is None
|
||||
|
||||
|
||||
@@ -101,6 +117,14 @@ async def test_returns_none_when_no_default(config_manager, monkeypatch):
|
||||
config_manager.save_config(cfg)
|
||||
|
||||
monkeypatch.delenv("BASIC_MEMORY_MCP_PROJECT", raising=False)
|
||||
# Prevent API fallback from returning a project via stale dependency overrides
|
||||
async def _no_api_fallback():
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(
|
||||
"basic_memory.mcp.project_context._resolve_default_project_from_api",
|
||||
_no_api_fallback,
|
||||
)
|
||||
assert await resolve_project_parameter(project=None) is None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user