|
28 | 28 | from astrbot.core.db.po import ( |
29 | 29 | ConversationV2, |
30 | 30 | ) |
| 31 | +from astrbot.core.db.sqlite import SQLiteDatabase |
31 | 32 | from astrbot.core.utils.upload import UploadTooLargeError |
32 | 33 | from astrbot.core.utils.version_comparator import VersionComparator |
33 | 34 | from astrbot.dashboard.services.backup_service import ( |
@@ -1048,6 +1049,36 @@ def test_kb_metadata_models_contain_expected_tables(self): |
1048 | 1049 | class TestBackupIntegration: |
1049 | 1050 | """备份集成测试""" |
1050 | 1051 |
|
| 1052 | + @pytest.mark.asyncio |
| 1053 | + async def test_cron_jobs_roundtrip(self, tmp_path): |
| 1054 | + """Preserve a scheduled task through backup export and import.""" |
| 1055 | + source = SQLiteDatabase(str(tmp_path / "source.db")) |
| 1056 | + target = SQLiteDatabase(str(tmp_path / "target.db")) |
| 1057 | + try: |
| 1058 | + job = await source.create_cron_job( |
| 1059 | + name="Daily reminder", |
| 1060 | + job_type="active_agent", |
| 1061 | + cron_expression="0 9 * * *", |
| 1062 | + timezone="Asia/Taipei", |
| 1063 | + payload={"message": "Reminder"}, |
| 1064 | + ) |
| 1065 | + exporter = AstrBotExporter( |
| 1066 | + main_db=source, config_path=str(tmp_path / "missing-config.json") |
| 1067 | + ) |
| 1068 | + with patch( |
| 1069 | + "astrbot.core.backup.exporter.get_backup_directories", return_value={} |
| 1070 | + ): |
| 1071 | + zip_path = await exporter.export_all(output_dir=str(tmp_path / "backups")) |
| 1072 | + |
| 1073 | + result = await AstrBotImporter(main_db=target).import_all(zip_path) |
| 1074 | + assert result.success, result.errors |
| 1075 | + restored = await target.list_cron_jobs() |
| 1076 | + assert len(restored) == 1 |
| 1077 | + assert restored[0].model_dump() == job.model_dump() |
| 1078 | + finally: |
| 1079 | + await source.engine.dispose() |
| 1080 | + await target.engine.dispose() |
| 1081 | + |
1051 | 1082 | @pytest.mark.asyncio |
1052 | 1083 | async def test_export_import_roundtrip(self, tmp_path): |
1053 | 1084 | """测试导出-导入往返""" |
|
0 commit comments