Skip to content

Commit 989e513

Browse files
committed
fix(static): resolve basedpyright warnings that fail CI
basedpyright's default exit code is non-zero whenever any diagnostics are reported, so the 8 warnings introduced by the fork-only commits were failing the Static Analysis job on PR #3 even though there were no errors. - src/deriver/queue_manager.py: drop `item.created_at is not None` guards. created_at is `Mapped[datetime.datetime]` (non-nullable), so the checks were always True and basedpyright flagged them as reportUnnecessaryComparison. - tests/sdk/test_session.py: factor out the shared mock-response body into a single helper and give the per-branch closures distinct names. This clears reportRedeclaration on `calls` / `fake_post` and lets the `# pyright: ignore` comments target the actual warning (reportPrivateUsage on `_http` / `_async_http_client`) instead of the irrelevant reportAttributeAccessIssue that was flagged as an unnecessary ignore.
1 parent 4a17a21 commit 989e513

2 files changed

Lines changed: 50 additions & 61 deletions

File tree

src/deriver/queue_manager.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,15 +1161,14 @@ async def mark_queue_items_as_processed(
11611161
)
11621162
now_utc = datetime.now(timezone.utc)
11631163
for item in items:
1164-
if item.created_at is not None:
1165-
prometheus_metrics.observe_deriver_queue_item_latency(
1166-
workspace_name=work_unit.workspace_name,
1167-
task_type=work_unit.task_type,
1168-
outcome="processed",
1169-
latency_seconds=max(
1170-
0.0, (now_utc - item.created_at).total_seconds()
1171-
),
1172-
)
1164+
prometheus_metrics.observe_deriver_queue_item_latency(
1165+
workspace_name=work_unit.workspace_name,
1166+
task_type=work_unit.task_type,
1167+
outcome="processed",
1168+
latency_seconds=max(
1169+
0.0, (now_utc - item.created_at).total_seconds()
1170+
),
1171+
)
11731172

11741173
async def mark_queue_item_as_errored(
11751174
self, item: QueueItem, work_unit_key: str, error: str
@@ -1201,18 +1200,17 @@ async def mark_queue_item_as_errored(
12011200
workspace_name=work_unit.workspace_name,
12021201
task_type=work_unit.task_type,
12031202
)
1204-
if item.created_at is not None:
1205-
prometheus_metrics.observe_deriver_queue_item_latency(
1206-
workspace_name=work_unit.workspace_name,
1207-
task_type=work_unit.task_type,
1208-
outcome="errored",
1209-
latency_seconds=max(
1210-
0.0,
1211-
(
1212-
datetime.now(timezone.utc) - item.created_at
1213-
).total_seconds(),
1214-
),
1215-
)
1203+
prometheus_metrics.observe_deriver_queue_item_latency(
1204+
workspace_name=work_unit.workspace_name,
1205+
task_type=work_unit.task_type,
1206+
outcome="errored",
1207+
latency_seconds=max(
1208+
0.0,
1209+
(
1210+
datetime.now(timezone.utc) - item.created_at
1211+
).total_seconds(),
1212+
),
1213+
)
12161214

12171215
async def _cleanup_work_unit(
12181216
self,

tests/sdk/test_session.py

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -394,38 +394,46 @@ async def test_session_add_messages_chunks_batches_over_limit(
394394
):
395395
honcho_client, client_type = client_fixture
396396
total_messages = 217
397+
calls: list[dict[str, Any]] = []
398+
399+
def _fake_response(
400+
route: str,
401+
body: dict[str, Any] | None,
402+
query: Any,
403+
session_id: str,
404+
peer_id: str,
405+
) -> list[dict[str, Any]]:
406+
assert body is not None
407+
calls.append({"route": route, "body": body, "query": query})
408+
return [
409+
{
410+
"id": f"msg-{len(calls)}-{idx}",
411+
"workspace_id": honcho_client.workspace_id,
412+
"session_id": session_id,
413+
"peer_id": peer_id,
414+
"content": item["content"],
415+
"metadata": item.get("metadata") or {},
416+
"configuration": item.get("configuration") or {},
417+
"created_at": "2026-04-02T00:00:00Z",
418+
"token_count": 1,
419+
}
420+
for idx, item in enumerate(body["messages"])
421+
]
397422

398423
if client_type == "async":
399424
session = await honcho_client.aio.session(id="test-session-add-msg-chunk-async")
400425
assert isinstance(session, Session)
401426
user = await honcho_client.aio.peer(id="user-add-msg-chunk-async")
402427
assert isinstance(user, Peer)
403428

404-
calls: list[dict[str, Any]] = []
405-
406-
async def fake_post(
429+
async def fake_post_async(
407430
route: str,
408431
body: dict[str, Any] | None = None,
409432
query: Any = None,
410433
) -> list[dict[str, Any]]:
411-
assert body is not None
412-
calls.append({"route": route, "body": body, "query": query})
413-
return [
414-
{
415-
"id": f"msg-{len(calls)}-{idx}",
416-
"workspace_id": honcho_client.workspace_id,
417-
"session_id": session.id,
418-
"peer_id": user.id,
419-
"content": item["content"],
420-
"metadata": item.get("metadata") or {},
421-
"configuration": item.get("configuration") or {},
422-
"created_at": "2026-04-02T00:00:00Z",
423-
"token_count": 1,
424-
}
425-
for idx, item in enumerate(body["messages"])
426-
]
434+
return _fake_response(route, body, query, session.id, user.id)
427435

428-
honcho_client._async_http_client.post = AsyncMock(side_effect=fake_post) # pyright: ignore[reportAttributeAccessIssue]
436+
honcho_client._async_http_client.post = AsyncMock(side_effect=fake_post_async) # pyright: ignore[reportPrivateUsage]
429437

430438
result = await session.aio.add_messages(
431439
[user.message(f"message {i}") for i in range(total_messages)]
@@ -436,31 +444,14 @@ async def fake_post(
436444
user = honcho_client.peer(id="user-add-msg-chunk-sync")
437445
assert isinstance(user, Peer)
438446

439-
calls: list[dict[str, Any]] = []
440-
441-
def fake_post(
447+
def fake_post_sync(
442448
route: str,
443449
body: dict[str, Any] | None = None,
444450
query: Any = None,
445451
) -> list[dict[str, Any]]:
446-
assert body is not None
447-
calls.append({"route": route, "body": body, "query": query})
448-
return [
449-
{
450-
"id": f"msg-{len(calls)}-{idx}",
451-
"workspace_id": honcho_client.workspace_id,
452-
"session_id": session.id,
453-
"peer_id": user.id,
454-
"content": item["content"],
455-
"metadata": item.get("metadata") or {},
456-
"configuration": item.get("configuration") or {},
457-
"created_at": "2026-04-02T00:00:00Z",
458-
"token_count": 1,
459-
}
460-
for idx, item in enumerate(body["messages"])
461-
]
452+
return _fake_response(route, body, query, session.id, user.id)
462453

463-
honcho_client._http.post = Mock(side_effect=fake_post) # pyright: ignore[reportAttributeAccessIssue]
454+
honcho_client._http.post = Mock(side_effect=fake_post_sync) # pyright: ignore[reportPrivateUsage]
464455

465456
result = session.add_messages(
466457
[user.message(f"message {i}") for i in range(total_messages)]

0 commit comments

Comments
 (0)