Rename translation keys to sakuraflow namespace and add CI/tests - #3
Conversation
- Migrate all translation keys from `todo.*` prefix to `sakuraflow.*` in `zh_cn.json` and source code - Add GitHub Actions workflow for automated linting (flake8) and testing (pytest) - Create test suite including smoke tests, command registration checks, and translation key validation - Optimize imports to remove wildcard usage in `mcdr_entry.py`, `interface.py`, and `__init__.py` - Update `.gitignore` for pytest cache and build output
There was a problem hiding this comment.
Pull request overview
This PR migrates the plugin’s i18n translation keys from the todo.* namespace to sakuraflow.*, and adds automated CI (lint + tests) to prevent regressions in command registration and translation-key usage.
Changes:
- Renamed translation keys to the
sakuraflow.*namespace across Python sources andlang/zh_cn.json. - Added pytest-based test suite (smoke import, command registration, translation-key validation).
- Added GitHub Actions workflow to run flake8 + pytest, and updated
.gitignorefor Python/pytest artifacts.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/test.yml |
Adds CI workflow to lint (flake8) and run pytest. |
.gitignore |
Ignores common Python caches, pytest cache, and package/ output. |
lang/zh_cn.json |
Renames all translation keys from todo.* to sakuraflow.*. |
sakura_flow/__init__.py |
Narrows MCDR imports and wires plugin load/command registration. |
sakura_flow/controller.py |
Updates error message keys returned by controller to sakuraflow.*. |
sakura_flow/enums.py |
Updates enum translation key references to sakuraflow.*. |
sakura_flow/interface.py |
Updates UI translation calls to sakuraflow.* and refines MCDR imports. |
sakura_flow/mcdr_entry.py |
Updates command handlers to use sakuraflow.* keys and refines MCDR imports. |
sakura_flow/utils.py |
Refines MCDR imports (but still uses constants wildcard import). |
tests/conftest.py |
Adds fixtures for mocked MCDR server/controller. |
tests/test_command_registration.py |
Validates command tree registration doesn’t error and registers a root node. |
tests/test_smoke.py |
Smoke tests for package import and plugin metadata presence. |
tests/test_translation_keys.py |
Scans code for used sakuraflow.* keys and verifies they exist in zh_cn.json. |
Comments suppressed due to low confidence (1)
sakura_flow/interface.py:5
- 这里仍然使用了
from .constants import *。在本 PR 新增的 CI 中 flake8 会检查F403(禁止import *),因此会导致工作流失败。建议改为从constants显式导入实际使用到的常量(并顺便移除对PAGE_SIZE的重复导入模式,避免混用*与显式导入)。
from . import TodoManager
from .constants import *
from .constants import PAGE_SIZE
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # 假设翻译键都以 sakuraflow. 开头 | ||
| pattern = re.compile(r'["\'](sakuraflow\.[a-zA-Z0-9_.]+)["\']') |
There was a problem hiding this comment.
scan_used_keys() 的正则会在遇到类似 server.tr(f"sakuraflow.prop.{prop}") 的 f-string 时匹配到不完整的键(例如 sakuraflow.prop.),从而导致 test_translation_keys_exist 误报并失败。建议改用不允许尾随 . 的正则(按 . 分段匹配),或在收集结果时过滤掉以 . 结尾/明显不完整的匹配;更稳妥的是用 ast 解析仅收集常量字符串键。
| # 假设翻译键都以 sakuraflow. 开头 | |
| pattern = re.compile(r'["\'](sakuraflow\.[a-zA-Z0-9_.]+)["\']') | |
| # 假设翻译键都以 sakuraflow. 开头,并且按 . 分段且不以 . 结尾 | |
| pattern = re.compile(r'["\'](sakuraflow(?:\.[a-zA-Z0-9_]+)+)["\']') |
| # 1. 检查严重错误和不安全的导入习惯 | ||
| # E9: 语法错误 | ||
| # F63: 总是为真的测试 | ||
| # F7: 编译错误 | ||
| # F82: 未定义的变量 | ||
| # F401: 导入但未使用的模块 | ||
| # F403: 使用了 'from module import *' | ||
| flake8 . --count --select=E9,F63,F7,F82,F401,F403 --show-source --statistics | ||
|
|
||
| # 2. 其他风格检查 (作为警告,不中断构建) |
There was a problem hiding this comment.
CI 这里启用了 flake8 的 F403(禁止 import *),但当前代码仍存在 from .constants import *(例如 sakura_flow/interface.py、sakura_flow/utils.py),会导致该步骤直接失败。要么把这些通配符导入改成显式导入,要么从该严格检查集合中移除 F403(如果项目暂时允许 import *)。
| # 1. 检查严重错误和不安全的导入习惯 | |
| # E9: 语法错误 | |
| # F63: 总是为真的测试 | |
| # F7: 编译错误 | |
| # F82: 未定义的变量 | |
| # F401: 导入但未使用的模块 | |
| # F403: 使用了 'from module import *' | |
| flake8 . --count --select=E9,F63,F7,F82,F401,F403 --show-source --statistics | |
| # 2. 其他风格检查 (作为警告,不中断构建) | |
| # 1. 严格检查严重错误和重要的导入问题 | |
| # E9: 语法错误 | |
| # F63: 总是为真的测试 | |
| # F7: 编译错误 | |
| # F82: 未定义的变量 | |
| # F401: 导入但未使用的模块 | |
| flake8 . --count --select=E9,F63,F7,F82,F401 --show-source --statistics | |
| # 2. 其他风格检查 (作为警告,不中断构建,包括 F403 等) |
| from .constants import * | ||
| from .constants import ITEMIZE_PREFIX |
There was a problem hiding this comment.
这里仍然使用了 from .constants import *,会触发本 PR 新增 CI 中 flake8 的 F403 检查并导致失败。建议改为仅显式导入本文件实际用到的常量/对象(同时避免与下一行的显式导入混用)。
| from .constants import * | |
| from .constants import ITEMIZE_PREFIX | |
| from .constants import LIST_ITEM_SEPERATOR, ITEMIZE_PREFIX |
| """ | ||
| import os | ||
| assert os.path.exists('mcdreforged.plugin.json'), "缺少 mcdreforged.plugin.json 文件" |
There was a problem hiding this comment.
该测试使用相对路径 os.path.exists('mcdreforged.plugin.json'),当 pytest 的工作目录不是仓库根目录时会出现误报失败。建议与其它测试一致基于 __file__ 计算项目根目录后再拼接文件路径进行断言。
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@Sakura-Ex I've opened a new pull request, #4, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: Sakura-Ex <49809606+Sakura-Ex@users.noreply.github.com>
Fix test_smoke.py to use absolute paths for cross-directory compatibility
- Update `test_translation_keys.py` to use `ast` for parsing source code instead of regex - Replace wildcard imports with explicit imports in `interface.py` and `utils.py`
- Update `test_translation_keys.py` to use `ast` for parsing source code instead of regex - Replace wildcard imports with explicit imports in `interface.py` and `utils.py`
todo.*prefix tosakuraflow.*inzh_cn.jsonand source codemcdr_entry.py,interface.py, and__init__.py.gitignorefor pytest cache and build output