Skip to content

chore(message-parser): Fix incomplete ASTNode union type#39212

Closed
Harshit2405-2004 wants to merge 9 commits intoRocketChat:developfrom
Harshit2405-2004:chore-fix-astnode-completeness
Closed

chore(message-parser): Fix incomplete ASTNode union type#39212
Harshit2405-2004 wants to merge 9 commits intoRocketChat:developfrom
Harshit2405-2004:chore-fix-astnode-completeness

Conversation

@Harshit2405-2004
Copy link
Copy Markdown
Contributor

@Harshit2405-2004 Harshit2405-2004 commented Mar 1, 2026

Description

Currently, packages/message-parser/src/definitions.ts manually maintains an ASTNode union type that is decoupled from the exhaustive Types interface. Several valid AST node types produced by the message parser are missing from the union:

  • Image
  • Timestamp
  • OrderedList
  • UnorderedList
  • ListItem
  • Task
  • LineBreak
  • KaTeX
  • InlineKaTeX
  • Blockquote

This PR bridges this gap by directly mapping the ASTNode union to the exhaustive Types interface (ASTNode = Types[keyof Types]). This guarantees zero-drift type safety when writing type guards like isNodeOfType(...) across the repository.

Checklist

  • I have added a changeset

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for additional message types including timestamps, blockquotes, and mathematical formulas.
    • Improved heading parsing to correctly handle emoji and other inline content.
  • Bug Fixes

    • Fixed a crash in data export when processing users with empty email arrays.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Mar 1, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 1, 2026

🦋 Changeset detected

Latest commit: 276176a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@rocket.chat/message-parser Patch
@rocket.chat/meteor Patch
@rocket.chat/core-services Patch
@rocket.chat/core-typings Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/rest-typings Patch
@rocket.chat/pdf-worker Patch
rocketchat-services Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/models Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 348ab55 and 4803c0a.

📒 Files selected for processing (2)
  • .changeset/fix-astnode-exhaustiveness.md
  • .changeset/fix-data-export-crash.md
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.
🔇 Additional comments (2)
.changeset/fix-data-export-crash.md (1)

1-5: Changeset entry is clear and correctly scoped.

Frontmatter is valid and the patch note communicates user impact and failure mode well.

.changeset/fix-astnode-exhaustiveness.md (1)

1-5: Release note matches the type-system fix and is well-formed.

Package target, bump level, and description are consistent with the ASTNode exhaustiveness objective.


Walkthrough

This PR refactors the ASTNode type to ensure exhaustiveness by mapping it to the Types interface, updates heading grammar rules to properly handle inline content including emojis, extends heading test coverage for emoji parsing, and includes a separate data export crash fix for the Rocket.Chat meteor package.

Changes

Cohort / File(s) Summary
ASTNode Type Exhaustiveness
packages/message-parser/src/definitions.ts, .changeset/fix-astnode-completeness.md, .changeset/fix-astnode-exhaustiveness.md
Added new type mappings (TIMESTAMP, BLOCKQUOTE, KATEX, INLINE_KATEX) to the Types interface and redefined ASTNode as Types[keyof Types] to ensure exhaustive union coverage instead of explicit type enumeration.
Heading Parser Enhancement
packages/message-parser/src/grammar.pegjs, packages/message-parser/tests/heading.test.ts
Updated heading grammar rule to pass unwrapped text from Inline rule instead of array-wrapped plain text; HeadingChunk now returns Inline result directly. Added test cases for emoji tokens within headings at levels 1, 2, and 3.
Data Export Crash Fix
.changeset/fix-data-export-crash.md
Changeset documenting a patch for @rocket.chat/meteor that prevents TypeError when sendViaEmail encounters an empty emails array, fixing data export loop crashes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the incomplete ASTNode union type by making it exhaustive through mapping to the Types interface.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/message-parser/src/definitions.ts (1)

75-79: ⚠️ Potential issue | 🟠 Major

Type mismatch: Heading.value should be Inlines[], not Plain[].

The test cases explicitly include emojis in heading values (e.g., heading([emoji('newspaper'), plain(' Headline')], 1)), but the type definition restricts it to Plain[]. Similar container types in the same file—ListItem (line 18) and Task (line 29)—correctly use Inlines[] for their value fields. The Emoji type is part of the Inlines union and must be supported in heading content.

🛠️ Proposed fix
 export type Heading = {
 	type: 'HEADING';
 	level: 1 | 2 | 3 | 4;
-	value: Plain[];
+	value: Inlines[];
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/message-parser/src/definitions.ts` around lines 75 - 79,
Heading.value is incorrectly typed as Plain[] but must allow emojis and other
inline nodes; change the Heading type's value from Plain[] to Inlines[]
(matching ListItem and Task) so heading content can include Emoji and other
Inlines. Update the Heading type definition (symbol: Heading) to use Inlines[]
instead of Plain[] and run type checks/tests to confirm compatibility with
existing heading test cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/message-parser/src/definitions.ts`:
- Around line 75-79: Heading.value is incorrectly typed as Plain[] but must
allow emojis and other inline nodes; change the Heading type's value from
Plain[] to Inlines[] (matching ListItem and Task) so heading content can include
Emoji and other Inlines. Update the Heading type definition (symbol: Heading) to
use Inlines[] instead of Plain[] and run type checks/tests to confirm
compatibility with existing heading test cases.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c30636 and 348ab55.

📒 Files selected for processing (5)
  • .changeset/fix-astnode-completeness.md
  • .changeset/fix-heading-emoji-parsing.md
  • packages/message-parser/src/definitions.ts
  • packages/message-parser/src/grammar.pegjs
  • packages/message-parser/tests/heading.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/message-parser/src/definitions.ts
  • packages/message-parser/tests/heading.test.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 0
File: :0-0
Timestamp: 2026-02-24T19:05:56.710Z
Learning: Rocket.Chat repo context: When a workspace manifest on develop already pins a dependency version (e.g., packages/web-ui-registration → "rocket.chat/ui-contexts": "27.0.1"), a lockfile change in a feature PR that upgrades only that dependency’s resolution is considered a manifest-driven sync and can be kept, preferably as a small "chore: sync yarn.lock with manifests" commit.
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/message-parser/src/definitions.ts
  • packages/message-parser/tests/heading.test.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/message-parser/src/definitions.ts
  • packages/message-parser/tests/heading.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files

Applied to files:

  • packages/message-parser/tests/heading.test.ts
📚 Learning: 2025-11-19T18:20:07.720Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: packages/i18n/src/locales/en.i18n.json:918-921
Timestamp: 2025-11-19T18:20:07.720Z
Learning: Repo: RocketChat/Rocket.Chat — i18n/formatting
Learning: This repository uses a custom message formatting parser in UI blocks/messages; do not assume standard Markdown rules. For keys like Call_ended_bold, Call_not_answered_bold, Call_failed_bold, and Call_transferred_bold in packages/i18n/src/locales/en.i18n.json, retain the existing single-asterisk emphasis unless maintainers request otherwise.

Applied to files:

  • .changeset/fix-heading-emoji-parsing.md
🧬 Code graph analysis (1)
packages/message-parser/tests/heading.test.ts (2)
packages/message-parser/src/utils.ts (3)
  • heading (36-40)
  • emoji (143-147)
  • plain (65-65)
packages/message-parser/tests/helpers.ts (3)
  • heading (14-18)
  • emoji (71-75)
  • plain (34-34)
🔇 Additional comments (6)
.changeset/fix-heading-emoji-parsing.md (1)

1-5: LGTM!

Changeset correctly documents the patch-level fix for emoji and inline element parsing within headings.

packages/message-parser/src/definitions.ts (1)

202-208: LGTM! Clean approach to ensure ASTNode exhaustiveness.

Using Types[keyof Types] guarantees the union automatically stays in sync with the Types interface, eliminating manual drift.

packages/message-parser/src/grammar.pegjs (1)

147-152: LGTM!

The grammar changes correctly pass Inline results directly to heading(), consistent with how other constructs like Task and OrderedListItem handle inline content. This enables proper parsing of emojis and other inline elements within headings.

packages/message-parser/tests/heading.test.ts (2)

2-2: LGTM!

Import updated correctly to include emoji helper for the new test cases.


47-50: LGTM!

Good test coverage for emoji parsing in headings: emoji at start (level 1), at end (level 2), and multiple emojis with interleaved text (level 3).

.changeset/fix-astnode-completeness.md (1)

1-5: LGTM!

Changeset accurately documents the ASTNode type exhaustiveness fix.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".changeset/fix-heading-emoji-parsing.md">

<violation number="1" location=".changeset/fix-heading-emoji-parsing.md:5">
P1: Changeset description incorrectly describes a runtime parser bug fix (nested emojis/markdown in headings) when the actual change is purely TypeScript type definitions (`ASTNode = Types[keyof Types]`). This will publish misleading release notes implying behavioral changes that don't exist.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread .changeset/fix-heading-emoji-parsing.md Outdated
@Harshit2405-2004
Copy link
Copy Markdown
Contributor Author

Thanks for catching that! The changeset was incorrectly copied over from a previous branch. I've updated .changeset/fix-astnode-exhaustiveness.md to accurately reflect the ASTNode union exhaustiveness fix.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".changeset/fix-data-export-crash.md">

<violation number="1" location=".changeset/fix-data-export-crash.md:1">
P2: Changeset content does not match the PR's described scope. The PR title indicates a message-parser ASTNode type fix, but this changeset declares a patch for @rocket.chat/meteor describing a sendViaEmail data-export crash. This mismatch would cause incorrect package versioning and changelog entries.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread .changeset/fix-data-export-crash.md Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/message-parser/src/grammar.pegjs">

<violation number="1" location="packages/message-parser/src/grammar.pegjs:151">
P2: Missing EndOfLine consumption in HeadingChunk will cause spurious empty paragraph nodes after headings</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread packages/message-parser/src/grammar.pegjs Outdated
Harshit2405-2004 and others added 2 commits March 19, 2026 02:48
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@ggazzo
Copy link
Copy Markdown
Member

ggazzo commented Apr 17, 2026

Hey @Harshit2405-2004, thank you for your contribution! 🙏

Your changes have been consolidated into #39853, where we merged all message-parser PRs together to make it easier to test and validate everything as a single unit.

That PR has already been merged into develop, so your work is included. Closing this one — thanks again!

@ggazzo ggazzo closed this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants