Skip to content

🐛 reject sending received system messages - #176

Merged
StarHeartHunt merged 1 commit into
masterfrom
fix/reject-received-system-message
Nov 7, 2026
Merged

StarHeartHunt merged 1 commit into
masterfrom
fix/reject-received-system-message

Conversation

@StarHeartHunt

Copy link
Copy Markdown
Member

Stacked on #174, which is the base branch of this PR, because the error points to MessageSegment.system_divider().

MessageSegment.system() and received system messages use the received fields (template, from_user, to_chatters). Feishu's send format uses type, params, and options, so system passed the msg_type allowlist from #173 while its content did not match the documentation.

Changes

Message.serialize() now raises ValueError for these segments before any request is made, both alone and combined with other segments:

Cannot send a received system message, use MessageSegment.system_divider instead

The check uses the System class, so these are not affected:

  • MessageSegment.system_divider().
  • A raw MessageSegment("system", ...) with content in the documented format.
  • Message.deserialize() and str() for received system messages.

MessageSegment.system() stays available because Message.deserialize() uses it, and its docstring now says it cannot be used for sending.

Behaviour change

Sending a received system message again, or sending a segment built with MessageSegment.system(), now raises ValueError.

Verification

  • Added tests for received messages, the builder, and raw segments. 2 of them fail without the code change; the raw segment test passes both ways and guards against over-blocking.
  • Removed the system case from test_serialize_rejects_segment_not_supported_in_post, because that test required the behaviour changed here.
  • Full suite: 90 passed, run locally on macOS with Python 3.12.
  • ruff and the pre-commit hooks pass.
  • Called the real send() with a stub bot and confirmed that no request is made when it raises.

Not tested against the live Feishu API.

@StarHeartHunt StarHeartHunt added the bug Something isn't working label Nov 7, 2026
@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.82%. Comparing base (dc375cd) to head (c9c6ba2).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
+ Coverage   83.80%   83.82%   +0.01%     
==========================================
  Files          15       15              
  Lines        1717     1719       +2     
==========================================
+ Hits         1439     1441       +2     
  Misses        278      278              
Flag Coverage Δ
unittests 83.82% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@StarHeartHunt
StarHeartHunt added this pull request to stack #177 November 7, 2026 02:24
Base automatically changed from feat/system-divider to master November 7, 2026 02:25
MessageSegment.system and received system messages use the received fields, which do not match the documented send format. Raise ValueError before any request and point to MessageSegment.system_divider.
@StarHeartHunt
StarHeartHunt merged commit 990464b into master Nov 7, 2026
18 checks passed
@StarHeartHunt
StarHeartHunt deleted the fix/reject-received-system-message branch November 7, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant