Repair production automation truth and schedule cleanup
This commit is contained in:
parent
8bcb416285
commit
944fd158de
19 changed files with 441 additions and 64 deletions
|
|
@ -38,6 +38,7 @@ async def test_sync_schedule_rows_reports_drift_counts_and_preserves_one_shots(
|
|||
orphan_id = uuid.uuid4()
|
||||
upserted: list[tuple[uuid.UUID, bool, str]] = []
|
||||
deleted: list[str] = []
|
||||
cancelled_one_shots: list[uuid.UUID] = []
|
||||
|
||||
async def fake_upsert_schedule(client: object, defn: object) -> None:
|
||||
upserted.append((
|
||||
|
|
@ -65,9 +66,13 @@ async def test_sync_schedule_rows_reports_drift_counts_and_preserves_one_shots(
|
|||
async def fake_delete_schedule(client: object, activity_id: str) -> None:
|
||||
deleted.append(activity_id)
|
||||
|
||||
async def fake_cancel_scheduled(client: object, activity_id: uuid.UUID) -> None:
|
||||
cancelled_one_shots.append(activity_id)
|
||||
|
||||
monkeypatch.setattr(sync_schedules, "upsert_schedule", fake_upsert_schedule)
|
||||
monkeypatch.setattr(sync_schedules, "list_schedules", fake_list_schedules)
|
||||
monkeypatch.setattr(sync_schedules, "delete_schedule", fake_delete_schedule)
|
||||
monkeypatch.setattr(sync_schedules, "cancel_scheduled", fake_cancel_scheduled)
|
||||
|
||||
result = await sync_schedules.sync_schedule_rows(
|
||||
object(),
|
||||
|
|
@ -125,6 +130,49 @@ async def test_sync_schedule_rows_reports_drift_counts_and_preserves_one_shots(
|
|||
(one_shot_id, True, "scheduled"),
|
||||
]
|
||||
assert deleted == [str(orphan_id)]
|
||||
assert cancelled_one_shots == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_schedule_rows_removes_disabled_one_shot(monkeypatch) -> None:
|
||||
one_shot_id = uuid.uuid4()
|
||||
cancelled: list[uuid.UUID] = []
|
||||
|
||||
async def fake_upsert_schedule(client: object, defn: object) -> None:
|
||||
raise AssertionError("disabled one-shot must not be upserted")
|
||||
|
||||
async def fake_cancel_scheduled(client: object, activity_id: uuid.UUID) -> None:
|
||||
cancelled.append(activity_id)
|
||||
|
||||
async def fake_list_schedules(client: object) -> list[dict[str, str]]:
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(sync_schedules, "upsert_schedule", fake_upsert_schedule)
|
||||
monkeypatch.setattr(sync_schedules, "cancel_scheduled", fake_cancel_scheduled)
|
||||
monkeypatch.setattr(sync_schedules, "list_schedules", fake_list_schedules)
|
||||
|
||||
result = await sync_schedules.sync_schedule_rows(
|
||||
object(),
|
||||
[
|
||||
_row(
|
||||
activity_id=one_shot_id,
|
||||
enabled=False,
|
||||
trigger_config={
|
||||
"trigger_type": "scheduled",
|
||||
"at": datetime(2026, 8, 17, 6, 0, tzinfo=timezone.utc),
|
||||
"timezone": "UTC",
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
assert cancelled == [one_shot_id]
|
||||
assert result.to_dict() == {
|
||||
"upserted": 0,
|
||||
"paused": 1,
|
||||
"deleted_orphans": 0,
|
||||
"errors": 0,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue