Skip to content

Rename translation keys to sakuraflow namespace and add CI/tests - #3

Merged
Sakura-Ex merged 7 commits into
devfrom
feat/test-workflow
Feb 7, 2026
Merged

Rename translation keys to sakuraflow namespace and add CI/tests#3
Sakura-Ex merged 7 commits into
devfrom
feat/test-workflow

Conversation

@Sakura-Ex

Copy link
Copy Markdown
Owner
  • 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

- 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
Copilot AI review requested due to automatic review settings February 7, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 and lang/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 .gitignore for 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.

Comment thread tests/test_translation_keys.py Outdated
Comment on lines +24 to +25
# 假设翻译键都以 sakuraflow. 开头
pattern = re.compile(r'["\'](sakuraflow\.[a-zA-Z0-9_.]+)["\']')

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scan_used_keys() 的正则会在遇到类似 server.tr(f"sakuraflow.prop.{prop}") 的 f-string 时匹配到不完整的键(例如 sakuraflow.prop.),从而导致 test_translation_keys_exist 误报并失败。建议改用不允许尾随 . 的正则(按 . 分段匹配),或在收集结果时过滤掉以 . 结尾/明显不完整的匹配;更稳妥的是用 ast 解析仅收集常量字符串键。

Suggested change
# 假设翻译键都以 sakuraflow. 开头
pattern = re.compile(r'["\'](sakuraflow\.[a-zA-Z0-9_.]+)["\']')
# 假设翻译键都以 sakuraflow. 开头,并且按 . 分段且不以 . 结尾
pattern = re.compile(r'["\'](sakuraflow(?:\.[a-zA-Z0-9_]+)+)["\']')

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +60
# 1. 检查严重错误和不安全的导入习惯
# E9: 语法错误
# F63: 总是为真的测试
# F7: 编译错误
# F82: 未定义的变量
# F401: 导入但未使用的模块
# F403: 使用了 'from module import *'
flake8 . --count --select=E9,F63,F7,F82,F401,F403 --show-source --statistics

# 2. 其他风格检查 (作为警告,不中断构建)

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI 这里启用了 flake8 的 F403(禁止 import *),但当前代码仍存在 from .constants import *(例如 sakura_flow/interface.pysakura_flow/utils.py),会导致该步骤直接失败。要么把这些通配符导入改成显式导入,要么从该严格检查集合中移除 F403(如果项目暂时允许 import *)。

Suggested change
# 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 等)

Copilot uses AI. Check for mistakes.
Comment thread sakura_flow/utils.py Outdated
Comment on lines 5 to 6
from .constants import *
from .constants import ITEMIZE_PREFIX

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里仍然使用了 from .constants import *,会触发本 PR 新增 CI 中 flake8 的 F403 检查并导致失败。建议改为仅显式导入本文件实际用到的常量/对象(同时避免与下一行的显式导入混用)。

Suggested change
from .constants import *
from .constants import ITEMIZE_PREFIX
from .constants import LIST_ITEM_SEPERATOR, ITEMIZE_PREFIX

Copilot uses AI. Check for mistakes.
Comment thread tests/test_smoke.py Outdated
Comment on lines +19 to +21
"""
import os
assert os.path.exists('mcdreforged.plugin.json'), "缺少 mcdreforged.plugin.json 文件"

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该测试使用相对路径 os.path.exists('mcdreforged.plugin.json'),当 pytest 的工作目录不是仓库根目录时会出现误报失败。建议与其它测试一致基于 __file__ 计算项目根目录后再拼接文件路径进行断言。

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copilot AI commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

@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.

Copilot AI and others added 5 commits February 7, 2026 10:24
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`
@Sakura-Ex
Sakura-Ex merged commit 07741bc into dev Feb 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants