Skip to content

fix: enable default message prompts - #30

Merged
FlanChanXwO merged 2 commits into
masterfrom
codex/hotfix-default-message-prompts
Jul 1, 2026
Merged

fix: enable default message prompts#30
FlanChanXwO merged 2 commits into
masterfrom
codex/hotfix-default-message-prompts

Conversation

@FlanChanXwO

@FlanChanXwO FlanChanXwO commented Jun 14, 2026

Copy link
Copy Markdown
Member

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。

  • 将所有内置提示消息默认改为 enabled=true,并保留可通过 message_overrides 关闭或改写单条提示。

  • MessagesConfig 增加缺省文本补全:当某条内置提示配置只写 enabled、省略 text 时,自动使用内置默认文案;管理员显式写空文本时不覆盖。

  • 更新 _conf_schema.json、README、配置文档和 2.1.0 changelog 中关于提示默认值的说明。

  • 更新配置模型和发送链路测试,传输类测试显式关闭交付提示以隔离测试目标。

Screenshots or Test Results / 运行截图或测试结果

PYTHONPATH=/Users/flanchan/Development/SourceCode/GithubProjects/astrbot-plugin-dev/data/plugins /Users/flanchan/Development/SourceCode/GithubProjects/astrbot-plugin-dev/.venv/bin/python -m pytest -q
181 passed in 0.41s

/Users/flanchan/.local/bin/ruff check src/shared/config/models.py tests/shared/test_config_models.py tests/infrastructure/test_image_sender.py tests/conftest.py tests/test_main_config_source.py
All checks passed!

/Users/flanchan/.local/bin/pre-commit run --files CHANGELOG.md README.md _conf_schema.json docs/usage/configuration.md src/shared/config/models.py tests/conftest.py tests/infrastructure/test_image_sender.py tests/shared/test_config_models.py tests/test_main_config_source.py
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
ruff (legacy alias)......................................................Passed
ruff format..............................................................Passed

git diff --check
# no output

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed them 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 have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

默认启用内置的用户可见消息,并确保配置和文档反映新的默认行为,同时保留对单条消息进行覆写的能力。

New Features:

  • 当仅配置 enabled 标志时,为所有内置消息提供默认文案;如果未提供文本,则回退到内部默认值。

Enhancements:

  • 调整与消息相关的配置模型,使所有内置提示在默认情况下均启用,且具有非空文本,并为覆写提供合理的默认值。
  • 调整以传输为主的测试,使其显式禁用投递通知,从而将消息行为与传输逻辑解耦。

Documentation:

  • 更新 README、配置文档、变更日志以及 schema 默认值,说明内置提示在默认情况下是启用的,并且可以通过覆写进行自定义或禁用。

Tests:

  • 新增并更新测试,用于断言消息默认启用的新行为、默认文本填充逻辑,以及消息相关 schema 的默认值。
Original summary in English

Summary by Sourcery

Enable built-in user-facing messages by default and ensure configuration and docs reflect the new defaults while preserving per-message override behavior.

New Features:

  • Provide default texts for all built-in messages when only the enabled flag is configured, falling back to internal defaults if text is omitted.

Enhancements:

  • Change message-related config models so all built-in prompts are enabled by default with non-empty text and sensible defaults for overrides.
  • Adjust transport-focused tests to explicitly disable delivery notices, decoupling message behavior from transport logic.

Documentation:

  • Update README, configuration docs, changelog, and schema defaults to describe that built-in prompts are enabled by default and can be customized or disabled via overrides.

Tests:

  • Add and update tests to assert new default-enabled message behavior, default text filling, and schema defaults for messages.

Summary by CodeRabbit

  • 新功能

    • 内置提示消息现默认启用,提供默认文本内容及占位符支持
  • 改进

    • 调整自动撤回提示的触发时机,受消息配置开关控制
  • 文档

    • 更新消息配置覆盖说明,反映提示默认启用的新行为
  • Chores

    • 版本升级至 v2.1.1
    • 依赖项调整:移除 Playwright,新增 python-docx

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c596605-7484-4fa0-ab8a-578a746a839b

📥 Commits

Reviewing files that changed from the base of the PR and between da510c5 and f21be19.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • README.md
  • _conf_schema.json
  • docs/usage/configuration.md
  • metadata.yaml
  • requirements.txt
  • src/shared/config/models.py
  • tests/conftest.py
  • tests/infrastructure/test_image_sender.py
  • tests/shared/test_config_models.py
  • tests/test_main_config_source.py
💤 Files with no reviewable changes (1)
  • requirements.txt

📝 Walkthrough

Walkthrough

将所有内置消息提示(fetching、found、send_failed 等)的 enabled 默认值从 false 改为 true,并为其提供默认文案模板。MessagesConfig 新增 _DEFAULT_TEXTS 映射与前置 validator 自动补全缺失的 text 字段。同步移除 playwright 依赖,版本升至 v2.1.1,并更新 Schema、文档及测试。

Changes

内置消息提示默认启用 & 移除 Playwright 依赖

Layer / File(s) Summary
配置模型默认值与文案补全 validator
src/shared/config/models.py
新增 ClassVarmodel_validator 导入;将四个消息配置类的 enabled 默认值改为 True 并提供默认文案;在 MessagesConfig 新增 _DEFAULT_TEXTS 映射和 fill_missing_message_text 前置 validator,当输入 dict 缺少 text 时自动补齐。
Schema 与文档同步更新
_conf_schema.json, docs/usage/configuration.md, README.md, CHANGELOG.md
_conf_schema.jsonenabled 默认值改为 true 并更新 hint 文案;文档更新 message_overrides 默认行为描述,补充 revoke_scheduled 占位符;CHANGELOG 更新 v2.1.1/v2.1.0 变更记录。
依赖与版本号更新
requirements.txt, metadata.yaml
新增 python-docx>=1.0.0,移除 playwright>=1.45.0;版本号升至 v2.1.1
配置模型测试更新
tests/conftest.py, tests/shared/test_config_models.py, tests/test_main_config_source.py
conftest.py 将测试配置中三项 enabled 改为 Truetest_config_models.py 新增默认启用、自动补全文案、MessageOverrideConfig 默认字段等测试,删除旧的默认 False 测试;test_main_config_source.py 更新 message_items 断言。
image_sender 测试隔离送达提示
tests/infrastructure/test_image_sender.py
新增 without_delivery_notices 辅助函数,将 found/send_failed/revoke_scheduled 的 enabled 置为 False;多个发送降级/回退测试改用该函数构造配置,以隔离默认开启的送达提示对断言的影响。

估算代码审查工作量

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 小兔翻翻配置表,
提示文案默认亮,
Playwright 轻装跑,
默认文本自动填,
测试隔离无烦恼,
v2.1.1 悄然上场~ ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了 PR 的主要变更:启用默认消息提示,与所有核心改动相符。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

默认启用所有内置的面向用户的消息并提供合理的默认文案,自动为配置中缺失的消息文本回填默认内容,并更新测试和文档以匹配新的默认行为,同时将传输层测试与投递通知隔离。

File-Level Changes

Change Details Files
默认启用内置消息和覆盖配置,并提供非空默认文本。
  • 将 MessagesFetchingConfig、MessagesFoundConfig、MessagesSendFailedConfig 和 MessageTextConfig 的 enabled 默认值设为 true,并提供非空的文本默认值。
  • 更新 MessageOverrideConfig 的默认值,使覆盖配置默认启用,默认目标为 fetching 键,并携带默认的 fetching 文本。
  • 调整 sample_config_dict fixture,使其反映 fetching、found 和 send_failed 消息默认启用的行为。
src/shared/config/models.py
tests/conftest.py
在配置缺失消息文本时自动填充默认文本。
  • 在 MessagesConfig 中新增 _DEFAULT_TEXTS 映射,用于将消息键映射到内置默认字符串。
  • 在 MessagesConfig 上添加 @model_validator,当仅缺失 text 字段时,从 _DEFAULT_TEXTS 中回填默认文本,同时尊重显式设置的空字符串。
  • 确保在采用新的默认行为时,message_overrides 仍然保持可配置。
src/shared/config/models.py
将测试与新的“消息默认启用”行为对齐,并将传输层测试与投递通知隔离。
  • 将原本期望 send_failed 消息被禁用的断言替换为“默认启用且具体现解析文本”的断言。
  • 新增测试覆盖消息默认值、覆盖默认值,以及仅提供 enabled 时文本回填的行为。
  • 为图片发送器测试新增 without_delivery_notices 辅助方法,并在所有以传输为重点的测试用例中使用它以禁用可选的投递后通知。
tests/shared/test_config_models.py
tests/infrastructure/test_image_sender.py
更新 schema、变更日志和文档以描述新的消息默认行为。
  • 修改变更日志措辞,说明内置提示默认启用,并且 revoke_scheduled 遵循消息配置的开关。
  • 更新配置文档和 README,说明在提示默认启用的情况下如何使用 message_overrides,以及 revoke_scheduled 现在默认启用。
  • 调整 _conf_schema.json 中消息模板的默认值,使 enabled 为 true,text 为非空默认值,并更新测试以断言这些新默认值。
CHANGELOG.md
docs/usage/configuration.md
README.md
_conf_schema.json
tests/test_main_config_source.py

Tips and commands

Interacting with Sourcery

  • 触发新一次代码审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 回复 Sourcery 的审查评论,请求从该评论创建 issue。你也可以直接在该审查评论下回复 @sourcery-ai issue 来基于该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审查者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,将所有 Sourcery 评论标记为已解决。如果你已经处理了所有评论且不想再看到它们,这会非常有用。
  • 忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审查。如果你想从一次全新的审查开始,这尤其有用——别忘了随后评论 @sourcery-ai review 来触发新的审查!

Customizing Your Experience

打开你的 dashboard 以:

  • 启用或禁用审查功能,例如 Sourcery 自动生成的 pull request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查指令。
  • 调整其他审查设置。

Getting Help

Original review guide in English

Reviewer's Guide

Enables all built-in user-facing messages by default with sensible default texts, adds automatic backfilling of missing message texts in configuration, and updates tests and documentation to match the new defaults while isolating transport tests from delivery notices.

File-Level Changes

Change Details Files
Enable built-in messages and overrides by default with non-empty text.
  • Set MessagesFetchingConfig, MessagesFoundConfig, MessagesSendFailedConfig, and MessageTextConfig enabled defaults to true with non-empty text defaults.
  • Updated MessageOverrideConfig defaults so overrides are enabled by default, target the 'fetching' key, and carry the default fetching text.
  • Adjusted sample_config_dict fixture to reflect enabled-by-default messaging for fetching, found, and send_failed.
src/shared/config/models.py
tests/conftest.py
Automatically fill default message text when configuration omits it.
  • Introduced MessagesConfig._DEFAULT_TEXTS mapping of message keys to built-in default strings.
  • Added a @model_validator on MessagesConfig to backfill missing 'text' fields from _DEFAULT_TEXTS while respecting explicit empty strings.
  • Ensured message_overrides remains configurable while using the new defaulting behavior.
src/shared/config/models.py
Align tests with new default-enabled messaging behavior and isolate transport tests from delivery notices.
  • Replaced expectations of disabled send_failed message with enabled defaults and concrete resolved text.
  • Added tests for message defaults, override defaults, and text backfilling behavior when only 'enabled' is provided.
  • Introduced without_delivery_notices helper for image sender tests and applied it across transport-focused test cases to disable optional post-delivery notices.
tests/shared/test_config_models.py
tests/infrastructure/test_image_sender.py
Update schema, changelog, and documentation to describe new message defaults.
  • Changed changelog wording to state that built-in prompts are enabled by default and that revoke_scheduled follows message config toggles.
  • Updated configuration docs and README to describe message_overrides usage when prompts are enabled by default and that revoke_scheduled is now enabled by default.
  • Adjusted _conf_schema.json message template defaults so 'enabled' is true and 'text' has a non-empty default, and updated tests to assert these new defaults.
CHANGELOG.md
docs/usage/configuration.md
README.md
_conf_schema.json
tests/test_main_config_source.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题,并给出了一些整体反馈:

  • 目前默认消息文案及其键同时出现在 _DEFAULT_TEXTS、各个 *Config 的默认值、MessageOverrideConfig、测试辅助方法(例如 without_delivery_notices)以及 fixtures 中,形成了重复。建议将这些字符串集中在单一可信来源中,以避免不同步并简化后续更新。
  • 由于 MessagesConfig._DEFAULT_TEXTS 旨在完整反映所有可配置的消息键(包括与运势相关的键),你可能需要添加一个小的防护(例如测试或静态检查),用来断言这张映射表与 schema/选项列表保持一致,从而防止新增键时没有对应默认值。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The default message texts and keys are now duplicated across `_DEFAULT_TEXTS`, the individual `*Config` defaults, `MessageOverrideConfig`, test helpers (e.g. `without_delivery_notices`), and fixtures; consider centralizing these strings in a single source of truth to avoid drift and ease future updates.
- Since `MessagesConfig._DEFAULT_TEXTS` is intended to mirror all configurable message keys (including fortune-related ones), you may want to add a small guard (e.g. a test or static check) that asserts this map is consistent with the schema/options list, so new keys cannot be added without a corresponding default.

## Individual Comments

### Comment 1
<location path="tests/shared/test_config_models.py" line_range="81" />
<code_context>
+    assert config.resolve_message("send_failed") == "图片发送失败,请稍后再试。"
+
+
+def test_message_defaults_fill_text_when_message_object_omits_text() -> None:
+    config = SetuPluginConfig(
+        messages={
</code_context>
<issue_to_address>
**issue (testing):** Add a test to cover the explicit empty-text case where defaults must not override admin-provided empty strings.

The validator must distinguish between omitted `text` (where defaults apply) and explicitly empty `text` (which must be preserved). The current test only covers the omitted case. Please add a complementary test where `text` is set to `""` for a couple of message keys and assert that `resolve_message(...)` returns `""`, confirming that defaults are not injected over admin-provided empty strings.
</issue_to_address>

Sourcery 对开源项目免费使用——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The default message texts and keys are now duplicated across _DEFAULT_TEXTS, the individual *Config defaults, MessageOverrideConfig, test helpers (e.g. without_delivery_notices), and fixtures; consider centralizing these strings in a single source of truth to avoid drift and ease future updates.
  • Since MessagesConfig._DEFAULT_TEXTS is intended to mirror all configurable message keys (including fortune-related ones), you may want to add a small guard (e.g. a test or static check) that asserts this map is consistent with the schema/options list, so new keys cannot be added without a corresponding default.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The default message texts and keys are now duplicated across `_DEFAULT_TEXTS`, the individual `*Config` defaults, `MessageOverrideConfig`, test helpers (e.g. `without_delivery_notices`), and fixtures; consider centralizing these strings in a single source of truth to avoid drift and ease future updates.
- Since `MessagesConfig._DEFAULT_TEXTS` is intended to mirror all configurable message keys (including fortune-related ones), you may want to add a small guard (e.g. a test or static check) that asserts this map is consistent with the schema/options list, so new keys cannot be added without a corresponding default.

## Individual Comments

### Comment 1
<location path="tests/shared/test_config_models.py" line_range="81" />
<code_context>
+    assert config.resolve_message("send_failed") == "图片发送失败,请稍后再试。"
+
+
+def test_message_defaults_fill_text_when_message_object_omits_text() -> None:
+    config = SetuPluginConfig(
+        messages={
</code_context>
<issue_to_address>
**issue (testing):** Add a test to cover the explicit empty-text case where defaults must not override admin-provided empty strings.

The validator must distinguish between omitted `text` (where defaults apply) and explicitly empty `text` (which must be preserved). The current test only covers the omitted case. Please add a complementary test where `text` is set to `""` for a couple of message keys and assert that `resolve_message(...)` returns `""`, confirming that defaults are not injected over admin-provided empty strings.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

assert config.resolve_message("send_failed") == "图片发送失败,请稍后再试。"


def test_message_defaults_fill_text_when_message_object_omits_text() -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (testing): 请添加一个测试,覆盖“显式设置空文本”的场景,在该场景中默认值不应覆盖管理员提供的空字符串。

验证逻辑必须区分省略 text(此时应应用默认值)和显式为空的 text(此时必须保留)。目前的测试只覆盖了省略 text 的情况。请补充一个测试:为若干条消息键将 text 设置为 "",并断言 resolve_message(...) 返回 "",以确认不会在管理员提供的空字符串之上注入默认值。

Original comment in English

issue (testing): Add a test to cover the explicit empty-text case where defaults must not override admin-provided empty strings.

The validator must distinguish between omitted text (where defaults apply) and explicitly empty text (which must be preserved). The current test only covers the omitted case. Please add a complementary test where text is set to "" for a couple of message keys and assert that resolve_message(...) returns "", confirming that defaults are not injected over admin-provided empty strings.

移除未使用的 playwright 依赖(requirements.txt),版本升至 v2.1.1。经全仓库引用面诊断确认插件代码零 playwright 引用,运势渲染走 AstrBot html_renderer.render_custom_template() 的 network t2i 终结点(HTTP),本插件进程无需 Playwright。渲染行为与失败语义不变。
@FlanChanXwO FlanChanXwO self-assigned this Jun 15, 2026
@FlanChanXwO
FlanChanXwO merged commit e7023a1 into master Jul 1, 2026
3 checks passed
@FlanChanXwO
FlanChanXwO deleted the codex/hotfix-default-message-prompts branch July 1, 2026 13:22
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.

1 participant