Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_fastapi_v1_dashboard.py" line_range="3248" />
<code_context>
+ body = response.json()
+ result = body["data"]["results"][0] if batch else body
+ assert result["status"] == "error"
+ manager.reload.assert_awaited_once_with("demo")
+ refresh.assert_not_awaited()
+
</code_context>
<issue_to_address>
**Second reload goes undetected**
When a second reload is reintroduced in the service after a successful manager update, in `test_v1_plugin_update_reports_reload_failure`, line 3248 still observes one reload because the simulated failure makes `PluginManager.update_plugin` raise before the service can reach a reintroduced second reload; duplicate reloads after successful updates therefore pass this test.
Add a successful-update case that asserts the reload is awaited exactly once.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and restoring an empty directory now replaces the existing directory contents, but the importer first moves them to a .bak directory, so they can be recovered even if the restore was unintended. A failed plugin reload will also be reported as an update error, though the plugin update itself is not rolled back.
Blocking findings: tests/test_fastapi_v1_dashboard.py:3248
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/backup/importer.py" line_range="908-909" />
<code_context>
if name.startswith(archive_prefix) and name != archive_prefix
]
- if not dir_files:
- continue
-
# 备份现有目录(如果存在)
</code_context>
<issue_to_address>
**Restore replaces data with empty directories**
When a listed directory has no archived files because export failed or omitted them, `_import_directories` treats the directory as an empty snapshot, moves the live directory to `.bak`, and creates an empty target. With duplicate manifest entries, the second pass can delete that `.bak`, so the restore loses the original files.
Do not replace an existing target when the directory has no archived content, while still handling explicitly archived empty directories.
</issue_to_address>
### Comment 2
<location path="tests/test_fastapi_v1_dashboard.py" line_range="3232" />
<code_context>
+ plugin = SimpleNamespace(reserved=False, root_dir_name=None)
+ manager = SimpleNamespace(
+ context=SimpleNamespace(get_registered_star=lambda name: plugin),
+ _updater=SimpleNamespace(update=AsyncMock()),
+ reload=AsyncMock(
+ return_value=(reload_success, None if reload_success else "initialize failed")
</code_context>
<issue_to_address>
**Skipped updates still pass**
When `PluginManager.update_plugin` is changed to skip `_updater.update`, the test never asserts that `_updater.update` is awaited, so `PluginManager.update_plugin` can skip the actual update and still reload once; the mocked reload succeeds, letting the test report a successful update that never happened.
Assert that `manager._updater.update` is awaited once with the plugin and expected update arguments.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and restoring an empty directory now moves the existing target to a .bak directory and leaves the active target empty; reverting the code will not put those files back automatically, but they remain recoverable from the backup. A reload failure is now reported after the plugin update, without rolling the update back.
Blocking findings: astrbot/core/backup/importer.py:909, tests/test_fastapi_v1_dashboard.py:3232
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. Restoring an empty directory snapshot can replace the current directory with an empty one, but the importer first moves the existing contents to a .bak directory, so they can be recovered. Reverting this change would not undo a restore that already happened, though recovery is bounded.
…-and-empty-backup-restore # Conflicts: # tests/test_fastapi_v1_dashboard.py
Plugin updates can report success after initialization fails, and restoring an empty directory snapshot leaves later-added files behind.
Modifications / 改动点
Propagate reload failures to single and batch update responses; remove the redundant second reload.
Export explicit ZIP entries for confirmed empty directories and restore them through the existing
.bakreplacement flow. Skip missing content with a warning and process duplicate directory names only once. Legacy archives without directory content or an explicit empty entry leave live data unchanged.Reuse two parameterized tests (five cases) to cover update execution/reload results and empty and failed-export restores with duplicate manifest entries.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
uv run pytest tests/test_backup.py tests/test_fastapi_v1_dashboard.py -q -k "restore_directory_snapshot or update_reports_reload_result or update_all_hides_internal_exceptions"ruff format .,ruff check ., andgit diff --check: passed.cd docs && pnpm run docs:build: passed.Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Report plugin reload failures accurately and restore confirmed empty directory snapshots without altering data when archive content is missing.
Bug Fixes:
Enhancements:
Tests: