Skip to content

Commit 3178a37

Browse files
phernandezclaude
andcommitted
style: apply ruff formatting fixes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 1957eac commit 3178a37

10 files changed

Lines changed: 40 additions & 49 deletions

src/basic_memory/alembic/versions/j3d4e5f6g7h8_rename_entity_type_to_note_type.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ def table_exists(connection, table_name: str) -> bool:
2222
"""Check if a table exists (idempotent migration support)."""
2323
if connection.dialect.name == "postgresql":
2424
result = connection.execute(
25-
text(
26-
"SELECT 1 FROM information_schema.tables "
27-
"WHERE table_name = :table_name"
28-
),
25+
text("SELECT 1 FROM information_schema.tables WHERE table_name = :table_name"),
2926
{"table_name": table_name},
3027
)
3128
return result.fetchone() is not None

src/basic_memory/mcp/prompts/continue_conversation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _format_continuation_results(result: SearchResponse, topic: str) -> str:
125125
lines.append(f"### {title}")
126126
if permalink:
127127
lines.append(f"permalink: {permalink}")
128-
lines.append(f"Read with: `read_note(\"{permalink}\")`")
128+
lines.append(f'Read with: `read_note("{permalink}")`')
129129
if item.content:
130130
content = item.content[:300] + "..." if len(item.content) > 300 else item.content
131131
lines.append(f"\n{content}")

src/basic_memory/mcp/tools/search.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ async def search_notes(
466466
effective_query = (query or "").strip()
467467
if effective_query:
468468
valid_search_types = {
469-
"text", "title", "permalink", "vector", "semantic", "hybrid",
469+
"text",
470+
"title",
471+
"permalink",
472+
"vector",
473+
"semantic",
474+
"hybrid",
470475
}
471476
if effective_search_type == "text":
472477
search_query.text = effective_query

src/basic_memory/repository/postgres_search_repository.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,7 @@ async def search(
689689
for idx, note_type in enumerate(note_types):
690690
param_name = f"note_type_{idx}"
691691
params[param_name] = json.dumps({"note_type": note_type})
692-
type_conditions.append(
693-
f"search_index.metadata @> CAST(:{param_name} AS jsonb)"
694-
)
692+
type_conditions.append(f"search_index.metadata @> CAST(:{param_name} AS jsonb)")
695693
conditions.append(f"({' OR '.join(type_conditions)})")
696694

697695
# Handle date filter

src/basic_memory/services/project_service.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -977,16 +977,13 @@ async def get_embedding_status(self, project_id: int) -> EmbeddingStatus:
977977
total_indexed_entities=total_indexed_entities,
978978
vector_tables_exist=False,
979979
reindex_recommended=True,
980-
reindex_reason=(
981-
"Vector tables not initialized — run: bm reindex --embeddings"
982-
),
980+
reindex_reason=("Vector tables not initialized — run: bm reindex --embeddings"),
983981
)
984982

985983
# --- Count queries (tables exist) ---
986984
si_result = await self.repository.execute_query(
987985
text(
988-
"SELECT COUNT(DISTINCT entity_id) FROM search_index "
989-
"WHERE project_id = :project_id"
986+
"SELECT COUNT(DISTINCT entity_id) FROM search_index WHERE project_id = :project_id"
990987
),
991988
{"project_id": project_id},
992989
)
@@ -1040,9 +1037,7 @@ async def get_embedding_status(self, project_id: int) -> EmbeddingStatus:
10401037
"WHERE c.project_id = :project_id AND e.rowid IS NULL"
10411038
)
10421039

1043-
orphan_result = await self.repository.execute_query(
1044-
orphan_sql, {"project_id": project_id}
1045-
)
1040+
orphan_result = await self.repository.execute_query(orphan_sql, {"project_id": project_id})
10461041
orphaned_chunks = orphan_result.scalar() or 0
10471042

10481043
# --- Reindex recommendation logic (priority order) ---
@@ -1051,9 +1046,7 @@ async def get_embedding_status(self, project_id: int) -> EmbeddingStatus:
10511046

10521047
if total_indexed_entities > 0 and total_chunks == 0:
10531048
reindex_recommended = True
1054-
reindex_reason = (
1055-
"Embeddings have never been built — run: bm reindex --embeddings"
1056-
)
1049+
reindex_reason = "Embeddings have never been built — run: bm reindex --embeddings"
10571050
elif orphaned_chunks > 0:
10581051
reindex_recommended = True
10591052
reindex_reason = (
@@ -1063,9 +1056,7 @@ async def get_embedding_status(self, project_id: int) -> EmbeddingStatus:
10631056
elif total_indexed_entities > total_entities_with_chunks:
10641057
missing = total_indexed_entities - total_entities_with_chunks
10651058
reindex_recommended = True
1066-
reindex_reason = (
1067-
f"{missing} entities missing embeddings — run: bm reindex --embeddings"
1068-
)
1059+
reindex_reason = f"{missing} entities missing embeddings — run: bm reindex --embeddings"
10691060

10701061
return EmbeddingStatus(
10711062
semantic_search_enabled=True,

test-int/cli/test_cli_tool_edit_note_integration.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,14 @@ def test_edit_note_json_format_contract(app, app_config, test_project, config_ma
262262

263263
assert result.exit_code == 0, result.output
264264
data = json.loads(result.stdout)
265-
assert set(data.keys()) == {"title", "permalink", "file_path", "operation", "checksum", "fileCreated"}
265+
assert set(data.keys()) == {
266+
"title",
267+
"permalink",
268+
"file_path",
269+
"operation",
270+
"checksum",
271+
"fileCreated",
272+
}
266273
assert data["operation"] == "append"
267274
assert data["fileCreated"] is False
268275
assert data["title"] == "Edit JSON Note"

tests/api/v2/test_knowledge_router.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,7 @@ async def test_delete_directory_v2_nested_structure(client: AsyncClient, v2_proj
836836

837837

838838
@pytest.mark.asyncio
839-
async def test_entity_response_includes_user_tracking_fields(
840-
client: AsyncClient, v2_project_url
841-
):
839+
async def test_entity_response_includes_user_tracking_fields(client: AsyncClient, v2_project_url):
842840
"""EntityResponseV2 includes created_by and last_updated_by fields (null for local)."""
843841
entity_data = {
844842
"title": "UserTrackingTest",

tests/repository/test_hybrid_fusion.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ async def test_dual_source_result_keeps_vector_matched_chunk():
248248
]
249249
vector_results = [
250250
FakeRow(
251-
id=1, score=0.9, title="both",
252-
content_snippet=content, matched_chunk_text=vector_chunk,
251+
id=1,
252+
score=0.9,
253+
title="both",
254+
content_snippet=content,
255+
matched_chunk_text=vector_chunk,
253256
),
254257
]
255258

tests/repository/test_postgres_search_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ async def test_postgres_note_types_sql_injection_returns_empty(session_maker, te
580580
repo = PostgresSearchRepository(session_maker, project_id=test_project.id)
581581

582582
malicious_payloads = [
583-
'note"}}\' OR \'1\'=\'1',
584-
"note\"; DROP TABLE search_index;--",
583+
"note\"}}' OR '1'='1",
584+
'note"; DROP TABLE search_index;--',
585585
'note"}} UNION SELECT * FROM entity--',
586586
]
587587
for payload in malicious_payloads:

tests/services/test_project_service_embedding_status.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ async def test_embedding_status_vector_tables_missing(
4040
"""When vector tables don't exist, recommend reindex."""
4141
# Drop the chunks table created by the fixture to simulate missing vector tables
4242
# Postgres requires CASCADE (due to index dependencies); SQLite doesn't support it
43-
drop_sql = "DROP TABLE IF EXISTS search_vector_chunks CASCADE" if _is_postgres() else "DROP TABLE IF EXISTS search_vector_chunks"
43+
drop_sql = (
44+
"DROP TABLE IF EXISTS search_vector_chunks CASCADE"
45+
if _is_postgres()
46+
else "DROP TABLE IF EXISTS search_vector_chunks"
47+
)
4448
await project_service.repository.execute_query(text(drop_sql), {})
4549

4650
with patch.object(
@@ -112,9 +116,7 @@ async def test_embedding_status_orphaned_chunks(
112116
# SQLite queries join on rowid which aliases INTEGER PRIMARY KEY.
113117
await project_service.repository.execute_query(
114118
text(
115-
"CREATE TABLE IF NOT EXISTS search_vector_embeddings ("
116-
" chunk_id INTEGER PRIMARY KEY"
117-
")"
119+
"CREATE TABLE IF NOT EXISTS search_vector_embeddings ( chunk_id INTEGER PRIMARY KEY)"
118120
),
119121
{},
120122
)
@@ -141,14 +143,10 @@ async def test_embedding_status_orphaned_chunks(
141143

142144

143145
@pytest.mark.asyncio
144-
async def test_embedding_status_healthy(
145-
project_service: ProjectService, test_graph, test_project
146-
):
146+
async def test_embedding_status_healthy(project_service: ProjectService, test_graph, test_project):
147147
"""When all entities have embeddings, no reindex recommended."""
148148
# Clear any leftover data from prior tests
149-
await project_service.repository.execute_query(
150-
text("DELETE FROM search_vector_chunks"), {}
151-
)
149+
await project_service.repository.execute_query(text("DELETE FROM search_vector_chunks"), {})
152150

153151
# Drop any existing virtual table (may have been created by search_service init)
154152
# and recreate as a simple regular table for testing the join logic.
@@ -158,19 +156,13 @@ async def test_embedding_status_healthy(
158156
text("DROP TABLE IF EXISTS search_vector_embeddings"), {}
159157
)
160158
await project_service.repository.execute_query(
161-
text(
162-
"CREATE TABLE search_vector_embeddings ("
163-
" chunk_id INTEGER PRIMARY KEY"
164-
")"
165-
),
159+
text("CREATE TABLE search_vector_embeddings ( chunk_id INTEGER PRIMARY KEY)"),
166160
{},
167161
)
168162

169163
# Insert a chunk + matching embedding for every search_index entity
170164
entity_result = await project_service.repository.execute_query(
171-
text(
172-
"SELECT DISTINCT entity_id FROM search_index WHERE project_id = :project_id"
173-
),
165+
text("SELECT DISTINCT entity_id FROM search_index WHERE project_id = :project_id"),
174166
{"project_id": test_project.id},
175167
)
176168
entity_ids = [row[0] for row in entity_result.fetchall()]

0 commit comments

Comments
 (0)