Files
qwenpaw/tests/unit/backup/test_manager.py
T
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

136 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import asyncio
import threading
import pytest
from qwenpaw.backup import manager as manager_module
from qwenpaw.backup._ops.create import BackupCancelled
from qwenpaw.backup.manager import BackupManager, BackupOperationConflict
from qwenpaw.backup.models import (
BackupJobStatus,
BackupScope,
CreateBackupRequest,
)
def _request() -> CreateBackupRequest:
return CreateBackupRequest(
name="test",
scope=BackupScope(
include_agents=False,
include_global_config=False,
include_secrets=False,
include_skill_pool=False,
),
)
async def _wait_for_status(
manager: BackupManager,
job_id: str,
status: BackupJobStatus,
):
for _ in range(200):
snapshot = manager.get_job(job_id)
if snapshot and snapshot.status == status:
return snapshot
await asyncio.sleep(0.01)
raise AssertionError(f"job did not reach {status}")
async def test_unsubscribe_does_not_cancel_running_job(monkeypatch):
release = threading.Event()
observed_stop_events: list[threading.Event] = []
def fake_create(meta, _agents, progress, stop_event):
observed_stop_events.append(stop_event)
progress({"type": "start", "total_agents": 0, "percent": 0})
assert release.wait(timeout=2)
return meta
monkeypatch.setattr(manager_module, "create_backup", fake_create)
manager = BackupManager()
initial = manager.start_job(_request())
queue = manager.subscribe(initial.job_id)
assert queue is not None
await queue.get()
manager.unsubscribe(initial.job_id, queue)
release.set()
completed = await _wait_for_status(
manager,
initial.job_id,
BackupJobStatus.COMPLETED,
)
assert completed.result is not None
assert observed_stop_events[0].is_set() is False
async def test_explicit_cancel_stops_job(monkeypatch):
def fake_create(_meta, _agents, _progress, stop_event):
assert stop_event.wait(timeout=2)
raise BackupCancelled()
monkeypatch.setattr(manager_module, "create_backup", fake_create)
manager = BackupManager()
initial = manager.start_job(_request())
requested = manager.cancel_job(initial.job_id)
assert requested is not None
assert requested.status == BackupJobStatus.CANCEL_REQUESTED
cancelled = await _wait_for_status(
manager,
initial.job_id,
BackupJobStatus.CANCELLED,
)
repeated = manager.cancel_job(initial.job_id)
assert repeated is not None
assert repeated.status == cancelled.status
async def test_create_and_restore_reservations_conflict(monkeypatch):
release = threading.Event()
def fake_create(meta, _agents, _progress, _stop_event):
assert release.wait(timeout=2)
return meta
monkeypatch.setattr(manager_module, "create_backup", fake_create)
manager = BackupManager()
with manager.reserve_restore():
with pytest.raises(BackupOperationConflict):
manager.start_job(_request())
initial = manager.start_job(_request())
with pytest.raises(BackupOperationConflict):
with manager.reserve_restore():
pass
release.set()
await _wait_for_status(
manager,
initial.job_id,
BackupJobStatus.COMPLETED,
)
async def test_shutdown_requests_active_job_cancellation(monkeypatch):
def fake_create(_meta, _agents, _progress, stop_event):
assert stop_event.wait(timeout=2)
raise BackupCancelled()
monkeypatch.setattr(manager_module, "create_backup", fake_create)
manager = BackupManager()
initial = manager.start_job(_request())
await manager.shutdown(timeout=1)
snapshot = manager.get_job(initial.job_id)
assert snapshot is not None
assert snapshot.status == BackupJobStatus.CANCELLED