fix: return promoted default state from project create API

When add_project promotes a new project because the configured default is missing from the database, return the persisted default flag instead of echoing the request flag.

Signed-off-by: rudi193-cmd <rudi193@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
rudi193-cmd
2026-06-12 07:40:25 -06:00
committed by Paul Hernandez
parent b92b0340d5
commit 25732b2fe2
2 changed files with 42 additions and 1 deletions
@@ -193,7 +193,7 @@ async def add_project(
return ProjectStatusResponse( # pyright: ignore [reportCallIssue]
message=f"Project '{new_project.name}' added successfully",
status="success",
default=project_data.set_default,
default=new_project.is_default or False,
new_project=ProjectItem(
id=new_project.id,
external_id=new_project.external_id,
+41
View File
@@ -6,6 +6,7 @@ from pathlib import Path
import pytest
from httpx import AsyncClient
from basic_memory.config import ProjectEntry
from basic_memory.models import Project
from basic_memory.schemas.project_info import ProjectItem, ProjectStatusResponse
from basic_memory.schemas.v2 import ProjectResolveResponse
@@ -54,6 +55,46 @@ async def test_get_project_by_id_not_found(client: AsyncClient, v2_projects_url)
assert "not found" in response.json()["detail"].lower()
@pytest.mark.asyncio
async def test_add_project_response_reflects_promoted_default(
client: AsyncClient,
v2_projects_url,
app_config,
config_manager,
config_home,
project_repository,
):
"""Regression #974/#985: POST response should echo persisted default promotion."""
main_home = config_home / "basic-memory"
main_home.mkdir(parents=True, exist_ok=True)
qa_path = config_home / "qa-notes"
qa_path.mkdir(parents=True, exist_ok=True)
fresh_config = app_config.model_copy(
update={
"projects": {"main": ProjectEntry(path=str(main_home))},
"default_project": "main",
}
)
config_manager.save_config(fresh_config)
for project in await project_repository.find_all():
await project_repository.delete(project.id)
response = await client.post(
f"{v2_projects_url}/",
json={"name": "qa", "path": str(qa_path), "set_default": False},
)
assert response.status_code == 201
status_response = ProjectStatusResponse.model_validate(response.json())
assert status_response.status == "success"
assert status_response.default is True
new_project = _project_item(status_response.new_project)
assert new_project.name == "qa"
assert new_project.is_default is True
@pytest.mark.asyncio
async def test_update_project_path_by_id(
client: AsyncClient, test_project: Project, v2_projects_url