From 54fc69c499a010073ee6eb98b8f3bee16d34961e Mon Sep 17 00:00:00 2001 From: Renn F Date: Sun, 28 Jun 2026 16:36:21 +0200 Subject: [PATCH] [F061] drop type:ignore from audit-emit tests Convention: no type:ignore/noqa. The F061 in-session audit-emit tests used '# type: ignore[assignment]' to assign a MagicMock to AsyncSession.add, and the F060 test assigned to .flush the same way. Rewritten to hold a local 'session: MagicMock' variable (mypy sees its auto-children as MagicMock, so .add.side_effect / .flush assign cleanly with no suppression). Verified via 'mypy tests/' that both files are now type-clean (the F060/F061 commits had skipped tests/ in mypy, masking two method-assign errors). --- tests/unit/services/test_escalation_board_guard.py | 12 ++++++++---- tests/unit/services/test_task.py | 10 ++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/unit/services/test_escalation_board_guard.py b/tests/unit/services/test_escalation_board_guard.py index 115585f2..43825477 100644 --- a/tests/unit/services/test_escalation_board_guard.py +++ b/tests/unit/services/test_escalation_board_guard.py @@ -533,9 +533,11 @@ async def test_apply_escalation_emits_blocked_audit_event() -> None: The audit row is written into the caller's session (F061/F073/F075: it commits atomically with the transition, not fire-and-forget on a separate connection), so we assert on the ``AuditLogTable`` added to the session.""" - svc = _service() + session = MagicMock() + session.flush = AsyncMock() added: list[object] = [] - svc.session.add = MagicMock(side_effect=added.append) # type: ignore[assignment] + session.add.side_effect = added.append + svc = TaskService(session) task = MagicMock( id=uuid4(), parent_task_id=uuid4(), @@ -573,9 +575,11 @@ async def test_unblock_with_restore_emits_audit_event() -> None: The audit row is written into the caller's session (F061/F073/F075: atomic with the transition, not fire-and-forget), so we assert on the ``AuditLogTable`` added to the session.""" - svc = _service() + session = MagicMock() + session.flush = AsyncMock() added: list[object] = [] - svc.session.add = MagicMock(side_effect=added.append) # type: ignore[assignment] + session.add.side_effect = added.append + svc = TaskService(session) task = MagicMock( id=uuid4(), status=TaskStatus.BLOCKED, diff --git a/tests/unit/services/test_task.py b/tests/unit/services/test_task.py index 36987392..1355b77b 100644 --- a/tests/unit/services/test_task.py +++ b/tests/unit/services/test_task.py @@ -1076,8 +1076,9 @@ async def test_finalize_claim_rollback_emits_reversal_audit() -> None: audit trail diverges from real state and corrupts every downstream metric reconstructed from `task.` events (cycle time, bottlenecks). """ - svc = TaskService(MagicMock()) - svc.session.flush = AsyncMock() + session = MagicMock() + session.flush = AsyncMock() + svc = TaskService(session) task = _build_task( status=TaskStatus.PENDING, @@ -1134,9 +1135,10 @@ async def test_emit_status_transition_audit_writes_in_session_atomically() -> No ``session.add``-ed (same txn) with the metric-reconstruction details, and NO fire-and-forget background task is spawned. """ - svc = TaskService(MagicMock()) + session = MagicMock() added: list[object] = [] - svc.session.add = MagicMock(side_effect=added.append) # type: ignore[assignment] + session.add.side_effect = added.append + svc = TaskService(session) prior_bg = set(svc._background_tasks) task = MagicMock(id=uuid4(), claimed_by=uuid4(), team=Team.BACKEND)