[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).
This commit is contained in:
Renn F
2026-06-28 16:36:21 +02:00
parent 7f63e50623
commit 54fc69c499
2 changed files with 14 additions and 8 deletions
@@ -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 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 commits atomically with the transition, not fire-and-forget on a separate
connection), so we assert on the ``AuditLogTable`` added to the session.""" connection), so we assert on the ``AuditLogTable`` added to the session."""
svc = _service() session = MagicMock()
session.flush = AsyncMock()
added: list[object] = [] 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( task = MagicMock(
id=uuid4(), id=uuid4(),
parent_task_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 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 with the transition, not fire-and-forget), so we assert on the
``AuditLogTable`` added to the session.""" ``AuditLogTable`` added to the session."""
svc = _service() session = MagicMock()
session.flush = AsyncMock()
added: list[object] = [] 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( task = MagicMock(
id=uuid4(), id=uuid4(),
status=TaskStatus.BLOCKED, status=TaskStatus.BLOCKED,
+6 -4
View File
@@ -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 audit trail diverges from real state and corrupts every downstream metric
reconstructed from `task.<status>` events (cycle time, bottlenecks). reconstructed from `task.<status>` events (cycle time, bottlenecks).
""" """
svc = TaskService(MagicMock()) session = MagicMock()
svc.session.flush = AsyncMock() session.flush = AsyncMock()
svc = TaskService(session)
task = _build_task( task = _build_task(
status=TaskStatus.PENDING, 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 ``session.add``-ed (same txn) with the metric-reconstruction details, and
NO fire-and-forget background task is spawned. NO fire-and-forget background task is spawned.
""" """
svc = TaskService(MagicMock()) session = MagicMock()
added: list[object] = [] 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) prior_bg = set(svc._background_tasks)
task = MagicMock(id=uuid4(), claimed_by=uuid4(), team=Team.BACKEND) task = MagicMock(id=uuid4(), claimed_by=uuid4(), team=Team.BACKEND)