Skip to content

refactor(message-parser): make skip flags parse-local#39477

Open
Shreyas2004wagh wants to merge 1 commit intoRocketChat:developfrom
Shreyas2004wagh:refactor/message-parser-parse-local-skip-flags
Open

refactor(message-parser): make skip flags parse-local#39477
Shreyas2004wagh wants to merge 1 commit intoRocketChat:developfrom
Shreyas2004wagh:refactor/message-parser-parse-local-skip-flags

Conversation

@Shreyas2004wagh
Copy link
Contributor

@Shreyas2004wagh Shreyas2004wagh commented Mar 9, 2026

Summary

  • move message-parser skip flags from grammar-global mutable state into parse-local state
  • preserve existing parser behavior while isolating emphasis/reference/emoji skip toggles per parse call
  • add regression coverage for repeated parse calls across emphasis, emoticon, and spoiler flows

Testing

  • ran the full packages/message-parser test suite locally: 29 suites passed, 591 tests passed
  • built @rocket.chat/message-parser
  • ran eslint on the changed test files

Refs #39295

Summary by CodeRabbit

  • Bug Fixes

    • Fixed state leakage issue in the message parser that could affect parsing across consecutive operations.
  • Tests

    • Added comprehensive test coverage to ensure message parsing consistency and reliability across repeated invocations.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 9, 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

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: e66f08d

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

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: 933ccecc-08e6-4197-a297-30442306c0b5

📥 Commits

Reviewing files that changed from the base of the PR and between 692a891 and e66f08d.

📒 Files selected for processing (4)
  • packages/message-parser/src/grammar.pegjs
  • packages/message-parser/tests/emphasis.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/spoiler.test.ts
📜 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
📓 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/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/emphasis.test.ts
🧠 Learnings (12)
📓 Common learnings
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.
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
📚 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 : Maintain test isolation between test cases in Playwright tests

Applied to files:

  • packages/message-parser/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/emphasis.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 : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • packages/message-parser/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/emphasis.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 : Use `test.step()` for complex test scenarios to improve organization in Playwright tests

Applied to files:

  • packages/message-parser/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/emphasis.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/spoiler.test.ts
  • packages/message-parser/tests/emphasis.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 : Ensure clean state for each test execution in Playwright tests

Applied to files:

  • packages/message-parser/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasis.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 **/*.spec.ts : Use descriptive test names that clearly communicate expected behavior in Playwright tests

Applied to files:

  • packages/message-parser/tests/spoiler.test.ts
📚 Learning: 2025-12-10T21:00:54.909Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.

Applied to files:

  • packages/message-parser/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasis.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 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/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/emphasis.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/tests/spoiler.test.ts
  • packages/message-parser/tests/emphasisWithEmoticons.test.ts
  • packages/message-parser/tests/emphasis.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 : Use `expect` matchers for assertions (`toEqual`, `toContain`, `toBeTruthy`, `toHaveLength`, etc.) instead of `assert` statements in Playwright tests

Applied to files:

  • packages/message-parser/tests/emphasis.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/**/*.{ts,spec.ts} : Follow Page Object Model pattern consistently in Playwright tests

Applied to files:

  • packages/message-parser/tests/emphasis.test.ts
🔇 Additional comments (6)
packages/message-parser/tests/emphasis.test.ts (1)

132-167: Good regression coverage for parse-local emphasis state.

Re-parsing the same ambiguous emphasis/reference inputs in one test is a solid guard against skip-flag bleed between consecutive parse() calls.

packages/message-parser/tests/emphasisWithEmoticons.test.ts (1)

60-80: Nice coverage for emoticon-specific skip resets.

These cases hit the bold/italic paths that previously relied on shared emoji-skip flags, so the double pass should catch the original leak well.

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

42-52: Good use of a parser initializer for skip state.

Putting the mutable flags in the parse-local initializer gives each parse() invocation an isolated state bag without changing the existing action flow.


202-205: skipInlineEmoji reset points look consistent.

The list-item, inline, and spoiler paths now all re-enter with a clean inline-emoji state and clear it again after preferential matches, which is exactly what this refactor needs.

Also applies to: 260-313


474-520: The emphasis/reference state migration preserves the old control pattern.

The Maybe* guards and the bold/italic content rules still flip the same skip toggles at the same decision points, just with parse-local storage now.

Also applies to: 535-590

packages/message-parser/tests/spoiler.test.ts (1)

51-65: LGTM on the spoiler regression coverage.

Repeating mixed spoiler cases in one test is a good way to prove skipInlineEmoji no longer bleeds across parse calls.


Walkthrough

The PR refactors the message parser grammar's state management by consolidating multiple scattered boolean skip flags (skipBold, skipItalic, skipStrikethrough, etc.) into a single centralized state object. Grammar rules are updated to reference the new state structure. Test coverage is added to verify parsing state doesn't leak between consecutive parse invocations.

Changes

Cohort / File(s) Summary
Grammar State Refactoring
packages/message-parser/src/grammar.pegjs
Consolidated multiple top-level skip boolean flags into a single state object (state.skipX). Updated all grammar rules including UnorderedListItemContentItem, Inline, Spoiler, and formatting-related constructs (Bold, Italic, References) to reference and mutate the new state object instead of individual flags.
State Leakage Tests
packages/message-parser/tests/emphasis.test.ts, packages/message-parser/tests/emphasisWithEmoticons.test.ts, packages/message-parser/tests/spoiler.test.ts
Added test coverage to verify skip flags do not persist across consecutive parse calls. Each test performs two identical parse passes on the same inputs and asserts identical AST output, confirming no state leakage between invocations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: bug

🚥 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 'refactor(message-parser): make skip flags parse-local' clearly and specifically describes the main change: converting skip flags from grammar-global state to parse-local state.
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.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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
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 4 files

@Shreyas2004wagh
Copy link
Contributor Author

Hi @ggazzo , I’ve finished the remaining message-parser findings and opened the related PRs. Could you take a look when you have time? I’ve linked everything in the tracking issue #39295 for easier follow-up.

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.

1 participant