Repository navigation
refactor: validate the shape of chat.sendMessage blocks in its schema - #42978
Conversation
The checks that actions and context blocks carry a list of elements, that section fields are objects and that an input block has an element now live in the chat.sendMessage AJV schema. The code keeps only what a schema cannot express: the linear scale point limit and the nesting depth.
|
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 4
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix-sendmessage-issues #42978 +/- ##
==========================================================
+ Coverage 71.03% 71.05% +0.02%
==========================================================
Files 5432 5432
Lines 231833 231810 -23
Branches 42236 42293 +57
==========================================================
+ Hits 164680 164717 +37
+ Misses 61864 61802 -62
- Partials 5289 5291 +2 Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|

Proposed changes (including videos or screenshots)
Stacked on #42975.
assertValidMessageBlockschecked the shape ofblocksin code. The checks that a JSON Schema can express now live in thechat.sendMessageAJV schema:actionsandcontextblocks must haveelements, a list of objects.sectionfields, when present, must be a list of objects.inputblocks must have anelementobject.The code keeps only what a schema cannot express: the 100-point limit of
linear_scale, its integer bounds wherever it is nested, and the nesting depth.The accepted and rejected inputs do not change. Every unit case keeps its result; the unit spec now runs each case through the schema and the code, as the route does. For the shape errors the API now returns AJV's
invalid-paramsmessage (e.g.must have required property 'elements') instead ofInvalid blocks: …, so the e2e assertions match the new message. The status stays 400.tis not touched, so video conference messages keep working.Issue(s)
https://rocketchat.atlassian.net/browse/VLN-706
Steps to test or reproduce
chat.sendMessagewithblocks: [{ type: 'actions' }]returns 400.Further comments
The schema could also reject more fields (
t,content,e2eMentions,location), but that would refuse requests that are accepted today, so it is left out of this change.