Skip to content

chore(message-parser): align ASTNode union with parser output#39058

Open
Shreyas2004wagh wants to merge 2 commits intoRocketChat:developfrom
Shreyas2004wagh:fix/message-parser-astnode-coverage
Open

chore(message-parser): align ASTNode union with parser output#39058
Shreyas2004wagh wants to merge 2 commits intoRocketChat:developfrom
Shreyas2004wagh:fix/message-parser-astnode-coverage

Conversation

@Shreyas2004wagh
Copy link
Copy Markdown
Contributor

@Shreyas2004wagh Shreyas2004wagh commented Feb 25, 2026

Summary

  • align ASTNode with runtime parser output by deriving it from Types[keyof Types]
  • include missing parser-emitted node types in Types (KATEX, INLINE_KATEX, TIMESTAMP)
  • improve isNodeOfType typing to narrow via Extract<ASTNode, { type: T }>
  • add coverage tests for narrowing TIMESTAMP, ORDERED_LIST, and IMAGE nodes

Testing

  • yarn workspace '@rocket.chat/message-parser' exec eslint src/definitions.ts src/guards.ts tests/guards.test.ts

Fix #39057
Fix #39295

Summary by CodeRabbit

  • New Features

    • Added support for KaTeX, InlineKaTeX, and Timestamp message types.
  • Refactor

    • Enhanced type system architecture for improved type safety and precision in message parsing.
  • Tests

    • Added test coverage for type narrowing across multiple message node kinds.

COMM-144

Ensure ASTNode includes all parser-emitted node types via Types map and improve isNodeOfType narrowing.\n\nAdd guard tests for TIMESTAMP, ORDERED_LIST, and IMAGE nodes.\n\nRefs RocketChat#39057
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Feb 25, 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 targeting the wrong base branch. It should target 8.4.0, but it targets 8.3.0

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 Feb 25, 2026

⚠️ No Changeset found

Latest commit: 95b807e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

No issues found across 3 files

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 25, 2026

Walkthrough

The PR addresses an incomplete ASTNode union in the message parser by adding missing node types (KATEX, INLINE_KATEX, TIMESTAMP) to the central Types registry, deriving ASTNode automatically from it using a generic alias pattern, and refining the isNodeOfType guard's type signature for more precise type narrowing. Tests validate the corrections.

Changes

Cohort / File(s) Summary
Type Registry and ASTNode Alias
packages/message-parser/src/definitions.ts
Added three missing node types (KATEX, INLINE_KATEX, TIMESTAMP) to the Types map. Replaced manual ASTNode union with ASTNode = Types[keyof Types], automatically deriving ASTNode from the expanded registry and ensuring completeness.
Type Guard Signature Refinement
packages/message-parser/src/guards.ts
Updated isNodeOfType generic constraint from N extends ASTNode to T extends ASTNode['type'] with return type Extract<ASTNode, { type: T }> for more precise type narrowing. Runtime behavior unchanged.
Guard Test Suite
packages/message-parser/tests/guards.test.ts
Added comprehensive test coverage for isNodeOfType guard validating type narrowing for Timestamp, OrderedList, Image, and Paragraph nodes with both positive and negative test cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR fully addresses issue #39057 by adding missing node types (KATEX, INLINE_KATEX, TIMESTAMP) to the Types map, deriving ASTNode from Types[keyof Types], improving type narrowing in isNodeOfType, and adding comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the ASTNode union alignment and type narrowing; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The PR title accurately reflects the main objective: aligning the ASTNode union type with the actual parser output by deriving it from the Types map and adding missing node types.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.64%. Comparing base (b1b1d6c) to head (95b807e).
⚠️ Report is 103 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #39058   +/-   ##
========================================
  Coverage    70.64%   70.64%           
========================================
  Files         3190     3190           
  Lines       112732   112732           
  Branches     20421    20440   +19     
========================================
+ Hits         79642    79645    +3     
+ Misses       31047    31040    -7     
- Partials      2043     2047    +4     
Flag Coverage Δ
e2e 60.33% <ø> (-0.03%) ⬇️
e2e-api 47.79% <ø> (-0.08%) ⬇️
unit 71.28% <ø> (+0.02%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo ggazzo changed the title fix(message-parser): align ASTNode union with parser output chore(message-parser): align ASTNode union with parser output Feb 25, 2026
@ggazzo ggazzo added this to the 8.3.0 milestone Feb 25, 2026
@Shreyas2004wagh
Copy link
Copy Markdown
Contributor Author

Hi @ggazzo , just following up on #39058 since it was added to the 8.3.0 milestone on February 25, 2026. The checks are passing on my side. Could you let me know if there’s anything else needed from me for review or merge?

@scuciatto scuciatto modified the milestones: 8.3.0, 8.4.0 Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants