style: apply ruff format to paw-print + decision trace files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rohit Kushwaha
2026-04-13 12:35:37 +05:30
parent 620f64a0f6
commit 75b4ec3996
8 changed files with 26 additions and 40 deletions

View File

@@ -81,9 +81,7 @@ class CorrectionSoulBridge:
except Exception:
logger.exception("Failed to observe correction — continuing without soul record")
async def _maybe_promote_to_procedural(
self, soul: object, correction: Correction
) -> None:
async def _maybe_promote_to_procedural(self, soul: object, correction: Correction) -> None:
"""When a path has been corrected _PROMOTION_THRESHOLD times, synthesize a rule."""
if not hasattr(soul, "remember"):
return

View File

@@ -116,7 +116,7 @@ class TraceCollector:
args_hash = _hash_args(args)
preview = str(result)
if len(preview) > _PREVIEW_CHARS:
preview = preview[:_PREVIEW_CHARS - 3] + "..."
preview = preview[: _PREVIEW_CHARS - 3] + "..."
# Dedupe identical tool+args pairs within a single trace.
for existing in self.trace.tool_calls:

View File

@@ -327,9 +327,7 @@ async def _pass_through_guardian(event: PawPrintEvent) -> bool:
return not getattr(verdict, "blocked", False)
async def _apply_event_mapping(
widget: PawPrintWidget, event: PawPrintEvent
) -> str | None:
async def _apply_event_mapping(widget: PawPrintWidget, event: PawPrintEvent) -> str | None:
"""Turn a PawPrintEvent into a Fabric object when a mapping exists."""
mapping = widget.event_mapping.get(event.type)
if mapping is None:

View File

@@ -102,7 +102,8 @@ class PawPrintStore:
async with self._conn() as db:
db.row_factory = aiosqlite.Row
async with db.execute(
"SELECT * FROM paw_print_widgets WHERE id = ?", (widget_id,),
"SELECT * FROM paw_print_widgets WHERE id = ?",
(widget_id,),
) as cur:
row = await cur.fetchone()
return self._row_to_widget(row) if row else None
@@ -130,9 +131,7 @@ class PawPrintStore:
) as cur:
return [self._row_to_widget(row) async for row in cur]
async def update_spec(
self, widget_id: str, spec: PawPrintSpec
) -> PawPrintWidget | None:
async def update_spec(self, widget_id: str, spec: PawPrintSpec) -> PawPrintWidget | None:
existing = await self.get_widget(widget_id)
if existing is None:
return None
@@ -163,7 +162,8 @@ class PawPrintStore:
await self._ensure_schema()
async with self._conn() as db:
cur = await db.execute(
"DELETE FROM paw_print_widgets WHERE id = ?", (widget_id,),
"DELETE FROM paw_print_widgets WHERE id = ?",
(widget_id,),
)
await db.commit()
return (cur.rowcount or 0) > 0
@@ -188,9 +188,7 @@ class PawPrintStore:
await db.commit()
return event
async def recent_events(
self, widget_id: str, limit: int = 100
) -> list[PawPrintEvent]:
async def recent_events(self, widget_id: str, limit: int = 100) -> list[PawPrintEvent]:
await self._ensure_schema()
async with self._conn() as db:
db.row_factory = aiosqlite.Row
@@ -238,7 +236,9 @@ class PawPrintStore:
if total >= overall_per_min:
return False
per_customer = await self.count_events_since(
widget_id, window_start, customer_ref=customer_ref,
widget_id,
window_start,
customer_ref=customer_ref,
)
return per_customer < per_customer_per_min

View File

@@ -295,9 +295,7 @@ class TestFabricSnapshotStore:
assert [r.object_id for r in rows] == ["a", "b"]
@pytest.mark.asyncio
async def test_snapshots_for_object_orders_newest_first(
self, store: InstinctStore
) -> None:
async def test_snapshots_for_object_orders_newest_first(self, store: InstinctStore) -> None:
older = FabricObjectSnapshot(object_id="obj_x", audit_id="aud_1")
newer = FabricObjectSnapshot(object_id="obj_x", audit_id="aud_2")
await store.record_fabric_snapshot(older)

View File

@@ -49,9 +49,7 @@ def client(app_with_store):
class TestProposeWithTrace:
@pytest.mark.asyncio
async def test_reasoning_trace_lands_in_audit_context(
self, store: InstinctStore
) -> None:
async def test_reasoning_trace_lands_in_audit_context(self, store: InstinctStore) -> None:
trace = ReasoningTrace(
fabric_queries=["obj_acme"],
soul_memories=["mem_q4_pricing"],
@@ -81,9 +79,7 @@ class TestProposeWithTrace:
assert decoded.backend == "claude_agent_sdk"
@pytest.mark.asyncio
async def test_fabric_snapshots_are_keyed_to_the_audit_row(
self, store: InstinctStore
) -> None:
async def test_fabric_snapshots_are_keyed_to_the_audit_row(self, store: InstinctStore) -> None:
snapshots = [
FabricObjectSnapshot(
object_id="obj_acme",
@@ -201,9 +197,7 @@ class TestHydrationEndpoint:
assert body["fabric_current"] == []
@pytest.mark.asyncio
async def test_hydrate_one_returns_snapshots(
self, app_with_store, client: TestClient
) -> None:
async def test_hydrate_one_returns_snapshots(self, app_with_store, client: TestClient) -> None:
_, store = app_with_store
await store.propose(
pocket_id="pocket-1",

View File

@@ -277,9 +277,7 @@ class TestEventStore:
assert allowed_other is True
@pytest.mark.asyncio
async def test_within_rate_limit_respects_overall_ceiling(
self, store: PawPrintStore
) -> None:
async def test_within_rate_limit_respects_overall_ceiling(self, store: PawPrintStore) -> None:
widget = await store.create_widget(_widget())
now = datetime.now()
for i in range(5):

View File

@@ -156,7 +156,8 @@ class TestSpecEndpoint:
def test_empty_allowlist_allows_any_origin(self, client: TestClient) -> None:
created = client.post(
"/paw-print/widgets", json=_widget_payload(allowed_domains=[]),
"/paw-print/widgets",
json=_widget_payload(allowed_domains=[]),
).json()
res = client.get(
f"/paw-print/spec/{created['id']}",
@@ -171,9 +172,7 @@ class TestSpecEndpoint:
class TestEventIngest:
def test_ingest_happy_path_records_event(
self, app_with_store, client: TestClient
) -> None:
def test_ingest_happy_path_records_event(self, app_with_store, client: TestClient) -> None:
_, store = app_with_store
created = client.post("/paw-print/widgets", json=_widget_payload()).json()
@@ -243,7 +242,8 @@ class TestEventIngest:
return False
monkeypatch.setattr(
"ee.paw_print.router._pass_through_guardian", AsyncMock(return_value=False),
"ee.paw_print.router._pass_through_guardian",
AsyncMock(return_value=False),
)
created = client.post("/paw-print/widgets", json=_widget_payload()).json()
res = client.post(
@@ -256,9 +256,7 @@ class TestEventIngest:
assert body["accepted"] is False
assert body["reason"] == "guardian_rejected"
def test_event_mapping_creates_fabric_object(
self, client: TestClient, monkeypatch
) -> None:
def test_event_mapping_creates_fabric_object(self, client: TestClient, monkeypatch) -> None:
fabric = MagicMock()
created_obj = MagicMock()
created_obj.id = "obj_created_123"
@@ -291,7 +289,9 @@ class TestEventIngest:
}
obj = fabric.create_object(
_FakeFabricObject(
type_name="Order", properties=props, source_connector="paw_print",
type_name="Order",
properties=props,
source_connector="paw_print",
),
)
awaited = await obj if hasattr(obj, "__await__") else obj