Skip to content

Commit 5a4d43d

Browse files
SonAIengineclaude
andcommitted
style: ruff format the CDC + MCP work
CI lint job has been red since 918aa23 because the CDC commits ran ruff check locally but never `ruff format --check`. This is a purely cosmetic pass — `ruff format` over the 13 files the CI run flagged. Tests still 761 passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dd13889 commit 5a4d43d

13 files changed

Lines changed: 42 additions & 121 deletions

src/synaptic/extensions/cdc/state.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ async def find_deleted_pks(
418418
# force schema-fresh state — `IF NOT EXISTS` would let stale
419419
# rows from a prior run leak through.
420420
await self._conn.execute("DROP TABLE IF EXISTS cdc_current_pks")
421-
await self._conn.execute(
422-
"CREATE TEMP TABLE cdc_current_pks (pk TEXT PRIMARY KEY)"
423-
)
421+
await self._conn.execute("CREATE TEMP TABLE cdc_current_pks (pk TEXT PRIMARY KEY)")
424422

425423
payload = [(canonical_pk(p),) for p in live_pks]
426424
if payload:

src/synaptic/extensions/cdc/sync.py

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ async def detect_deletes(
162162
else:
163163
live_pks = live_result # type: ignore[assignment]
164164

165-
deleted_rows = await self._store.find_deleted_pks(
166-
self._source_url, schema.name, live_pks
167-
)
165+
deleted_rows = await self._store.find_deleted_pks(self._source_url, schema.name, live_pks)
168166
if not deleted_rows:
169167
return 0
170168

@@ -274,14 +272,10 @@ async def sync_table(
274272
row_is_new.append(False)
275273
continue
276274
pk_str = canonical_pk(pk_val)
277-
existing = await self._store.get_node_id(
278-
self._source_url, schema.name, pk_str
279-
)
275+
existing = await self._store.get_node_id(self._source_url, schema.name, pk_str)
280276
row_is_new.append(existing is None)
281277
if existing is not None and fk_map:
282-
snapshot = await self._store.get_fk_edges(
283-
self._source_url, schema.name, pk_str
284-
)
278+
snapshot = await self._store.get_fk_edges(self._source_url, schema.name, pk_str)
285279
if snapshot:
286280
prior_fks[pk_str] = snapshot
287281

@@ -335,11 +329,7 @@ async def sync_table(
335329
node_id = deterministic_row_id(self._source_url, schema.name, pk_val)
336330
fk_snapshot: dict[str, str] | None = None
337331
if fk_map:
338-
fk_snapshot = {
339-
col: str(row[col])
340-
for col in fk_map
341-
if row.get(col) is not None
342-
}
332+
fk_snapshot = {col: str(row[col]) for col in fk_map if row.get(col) is not None}
343333
pk_batch.append((canonical_pk(pk_val), node_id, None, fk_snapshot))
344334

345335
change_val = row.get(change_col)
@@ -384,9 +374,7 @@ async def _prune_stale_fk_edges(
384374
rows: list[dict[str, Any]],
385375
prior_fks: dict[str, dict[str, str]],
386376
) -> int:
387-
return await _prune_stale_fk_edges(
388-
graph, schema, fk_map, rows, prior_fks, self._source_url
389-
)
377+
return await _prune_stale_fk_edges(graph, schema, fk_map, rows, prior_fks, self._source_url)
390378

391379

392380
async def _prune_stale_fk_edges(
@@ -429,19 +417,14 @@ async def _prune_stale_fk_edges(
429417
if target_table is None:
430418
continue
431419

432-
old_target_node = deterministic_row_id(
433-
source_url, target_table, old_target_pk
434-
)
420+
old_target_node = deterministic_row_id(source_url, target_table, old_target_pk)
435421

436422
if source_node not in edge_cache:
437423
edge_cache[source_node] = await graph.backend.get_edges(
438424
source_node, direction="outgoing"
439425
)
440426
for edge in edge_cache[source_node]:
441-
if (
442-
edge.target_id == old_target_node
443-
and edge.kind == EdgeKind.RELATED
444-
):
427+
if edge.target_id == old_target_node and edge.kind == EdgeKind.RELATED:
445428
await graph.backend.delete_edge(edge.id)
446429
removed += 1
447430
edge_cache[source_node] = [
@@ -506,9 +489,7 @@ async def sync_table(
506489
# Hash mode always does a full read — there is no watermark
507490
# to filter on. Pass `where_clause=None` so the SQLite
508491
# reader still applies the LIMIT but skips the WHERE.
509-
reader_result = row_reader(
510-
schema.name, where_clause=None, where_params=()
511-
)
492+
reader_result = row_reader(schema.name, where_clause=None, where_params=())
512493
if hasattr(reader_result, "__await__"):
513494
rows = await reader_result # type: ignore[misc]
514495
else:
@@ -535,12 +516,8 @@ async def sync_table(
535516
new_hash = row_hash(row)
536517
new_hashes[pk_str] = new_hash
537518

538-
prior_hash = await self._store.get_row_hash(
539-
self._source_url, schema.name, pk_str
540-
)
541-
existing_node = await self._store.get_node_id(
542-
self._source_url, schema.name, pk_str
543-
)
519+
prior_hash = await self._store.get_row_hash(self._source_url, schema.name, pk_str)
520+
existing_node = await self._store.get_node_id(self._source_url, schema.name, pk_str)
544521

545522
if existing_node is None:
546523
stats.added += 1
@@ -549,19 +526,15 @@ async def sync_table(
549526
stats.updated += 1
550527
to_ingest.append(row)
551528
if fk_map:
552-
snapshot = await self._store.get_fk_edges(
553-
self._source_url, schema.name, pk_str
554-
)
529+
snapshot = await self._store.get_fk_edges(self._source_url, schema.name, pk_str)
555530
if snapshot:
556531
prior_fks[pk_str] = snapshot
557532
# else: unchanged — skip
558533

559534
if not to_ingest:
560535
# Nothing changed; no state advance needed beyond the
561536
# last_sync_at heartbeat for monitoring.
562-
prior_state = await self._store.load_state(
563-
self._source_url, schema.name
564-
)
537+
prior_state = await self._store.load_state(self._source_url, schema.name)
565538
new_state = TableSyncState(
566539
source_url=self._source_url,
567540
table_name=schema.name,
@@ -611,27 +584,15 @@ async def sync_table(
611584
if pk_val is None:
612585
continue
613586
pk_str = canonical_pk(pk_val)
614-
node_id = deterministic_row_id(
615-
self._source_url, schema.name, pk_val
616-
)
587+
node_id = deterministic_row_id(self._source_url, schema.name, pk_val)
617588
fk_snapshot: dict[str, str] | None = None
618589
if fk_map:
619-
fk_snapshot = {
620-
col: str(row[col])
621-
for col in fk_map
622-
if row.get(col) is not None
623-
}
624-
pk_batch.append(
625-
(pk_str, node_id, new_hashes.get(pk_str), fk_snapshot)
626-
)
590+
fk_snapshot = {col: str(row[col]) for col in fk_map if row.get(col) is not None}
591+
pk_batch.append((pk_str, node_id, new_hashes.get(pk_str), fk_snapshot))
627592

628-
await self._store.upsert_pk_batch(
629-
self._source_url, schema.name, pk_batch
630-
)
593+
await self._store.upsert_pk_batch(self._source_url, schema.name, pk_batch)
631594

632-
prior_state = await self._store.load_state(
633-
self._source_url, schema.name
634-
)
595+
prior_state = await self._store.load_state(self._source_url, schema.name)
635596
row_count = (prior_state.row_count if prior_state else 0) + stats.added
636597
new_state = TableSyncState(
637598
source_url=self._source_url,

src/synaptic/extensions/db_ingester.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ async def _read_pg_pks(dsn: str, table: str, pk_col: str) -> list[str]:
364364
def _pg_row_reader(dsn: str, row_limit: int):
365365
"""Bind a PG row reader closure for the CDC orchestrator."""
366366

367-
async def reader(
368-
table: str, *, where_clause: str | None = None, where_params: tuple = ()
369-
):
367+
async def reader(table: str, *, where_clause: str | None = None, where_params: tuple = ()):
370368
return await _read_pg_rows(
371369
dsn,
372370
table,
@@ -592,9 +590,7 @@ async def _read_mysql_pks(dsn: str, table: str, pk_col: str) -> list[str]:
592590
def _mysql_row_reader(dsn: str, row_limit: int):
593591
"""Bind a MySQL row reader closure for the CDC orchestrator."""
594592

595-
async def reader(
596-
table: str, *, where_clause: str | None = None, where_params: tuple = ()
597-
):
593+
async def reader(table: str, *, where_clause: str | None = None, where_params: tuple = ()):
598594
return await _read_mysql_rows(
599595
dsn,
600596
table,

src/synaptic/graph.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,7 @@ async def from_database(
736736
row_limit=row_limit,
737737
)
738738
return graph
739-
if connection_string.startswith("mysql") or connection_string.startswith(
740-
"mariadb"
741-
):
739+
if connection_string.startswith("mysql") or connection_string.startswith("mariadb"):
742740
await ingester.sync_from_mysql(
743741
connection_string,
744742
graph,
@@ -846,9 +844,7 @@ async def sync_from_database(
846844
tables=tables,
847845
row_limit=row_limit,
848846
)
849-
if connection_string.startswith("mysql") or connection_string.startswith(
850-
"mariadb"
851-
):
847+
if connection_string.startswith("mysql") or connection_string.startswith("mariadb"):
852848
return await ingester.sync_from_mysql(
853849
connection_string,
854850
self,

tests/test_cdc_dialects.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def test_pg_numbers_placeholders(self):
1616
assert _translate_placeholders('"updated_at" >= ?', "pg") == '"updated_at" >= $1'
1717

1818
def test_pg_numbers_multiple(self):
19-
assert (
20-
_translate_placeholders('a = ? AND b = ?', "pg")
21-
== 'a = $1 AND b = $2'
22-
)
19+
assert _translate_placeholders("a = ? AND b = ?", "pg") == "a = $1 AND b = $2"
2320

2421
def test_mysql_uses_percent_s(self):
2522
assert _translate_placeholders('"col" >= ?', "mysql") == '"col" >= %s'
@@ -28,7 +25,7 @@ def test_sqlite_passthrough(self):
2825
assert _translate_placeholders('"col" >= ?', "sqlite") == '"col" >= ?'
2926

3027
def test_unknown_dialect_passthrough(self):
31-
assert _translate_placeholders('? ? ?', "made-up") == '? ? ?'
28+
assert _translate_placeholders("? ? ?", "made-up") == "? ? ?"
3229

3330
def test_question_mark_only_in_placeholder_position(self):
3431
# `?` inside a literal would be a footgun in real SQL but

tests/test_cdc_ids.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
class TestNormalizeSourceURL:
2525
def test_lowercases_scheme_and_host(self):
26-
assert normalize_source_url("Postgres://user@HOST:5432/db") == \
27-
normalize_source_url("postgresql://user@host:5432/db".replace("postgresql", "postgres"))
26+
assert normalize_source_url("Postgres://user@HOST:5432/db") == normalize_source_url(
27+
"postgresql://user@host:5432/db".replace("postgresql", "postgres")
28+
)
2829

2930
def test_strips_trailing_slash(self):
3031
a = normalize_source_url("postgres://user@host/db/")
@@ -155,8 +156,5 @@ def test_no_collision_synthetic_50k(self):
155156
Not a formal collision proof — just guards against regressions
156157
like hashing only the table name.
157158
"""
158-
ids = {
159-
deterministic_row_id("postgres://h/d", "t", f"row_{i}")
160-
for i in range(50_000)
161-
}
159+
ids = {deterministic_row_id("postgres://h/d", "t", f"row_{i}") for i in range(50_000)}
162160
assert len(ids) == 50_000

tests/test_cdc_search_regression.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ async def two_graphs(self):
7373
_seed(src_path)
7474
conn_str = f"sqlite:////{str(src_path).lstrip('/')}"
7575

76-
full_graph = await SynapticGraph.from_database(
77-
conn_str, db=str(full_db), mode="full"
78-
)
79-
cdc_graph = await SynapticGraph.from_database(
80-
conn_str, db=str(cdc_db), mode="cdc"
81-
)
76+
full_graph = await SynapticGraph.from_database(conn_str, db=str(full_db), mode="full")
77+
cdc_graph = await SynapticGraph.from_database(conn_str, db=str(cdc_db), mode="cdc")
8278
yield full_graph, cdc_graph
8379
await full_graph.backend.close()
8480
await cdc_graph.backend.close()
@@ -98,13 +94,12 @@ async def test_korean_query_top_result_matches(self, two_graphs):
9894
assert cdc_top, f"cdc graph returned nothing for {query!r}"
9995
# Top-1 must agree on the same data point.
10096
assert full_top[0] == cdc_top[0], (
101-
f"top result diverged for {query!r}: "
102-
f"full={full_top[0]} cdc={cdc_top[0]}"
97+
f"top result diverged for {query!r}: full={full_top[0]} cdc={cdc_top[0]}"
10398
)
10499

105100
async def test_topk_set_matches(self, two_graphs):
106101
full_graph, cdc_graph = two_graphs
107-
for query in ("운동", "겨울", "정장"):
102+
for query in ("운동", "겨울", "정장"):
108103
full_top = set(await _topk_titles(full_graph, query, k=5))
109104
cdc_top = set(await _topk_titles(cdc_graph, query, k=5))
110105
# The top-k *set* should match — internal ordering can
@@ -126,9 +121,7 @@ async def graph_and_src(self):
126121
_seed(src_path)
127122
conn_str = f"sqlite:////{str(src_path).lstrip('/')}"
128123

129-
graph = await SynapticGraph.from_database(
130-
conn_str, db=str(graph_db), mode="cdc"
131-
)
124+
graph = await SynapticGraph.from_database(conn_str, db=str(graph_db), mode="cdc")
132125
yield graph, conn_str
133126
await graph.backend.close()
134127

tests/test_cdc_sync_delete.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ async def test_delete_row_removes_node_and_edges(self, graph_and_src):
8989

9090
# PK index forgot the row.
9191
store = graph.backend.cdc_state_store()
92-
assert (
93-
await store.get_node_id(conn_str, "products", "1")
94-
) is None
92+
assert (await store.get_node_id(conn_str, "products", "1")) is None
9593

9694
async def test_other_rows_untouched(self, graph_and_src):
9795
graph, conn_str, src_path = graph_and_src

tests/test_cdc_sync_fk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ async def test_fk_repoint_removes_old_edge_and_creates_new(self, graph_and_src):
8989

9090
# Repoint product 1 from category 1 → category 3.
9191
con = sqlite3.connect(src_path)
92-
con.execute(
93-
"UPDATE products SET category_id = 3, updated_at = 5000 WHERE id = 1"
94-
)
92+
con.execute("UPDATE products SET category_id = 3, updated_at = 5000 WHERE id = 1")
9593
con.commit()
9694
con.close()
9795

tests/test_cdc_sync_hash.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ async def test_value_change_propagates(self, graph_and_src):
142142
# bind us to the digest function. Just make sure it changed.)
143143
from synaptic.extensions.cdc.hashing import row_hash as rh
144144

145-
assert new_hash == rh(
146-
{"id": 1, "key": "theme", "value": "light"}
147-
)
145+
assert new_hash == rh({"id": 1, "key": "theme", "value": "light"})
148146

149147
async def test_insert_propagates(self, graph_and_src):
150148
graph, conn_str, src_path = graph_and_src

0 commit comments

Comments
 (0)