fix(mention): restore organization and group mentions - #1598
Conversation
Migrating `DirectoryEntity` to Zod changed `DirectoryEntityType` values from the Markdown notation prefixes (`user`/`org`/`group`) to display names, but the mention regexp kept matching the old lowercase prefixes. Since then `createMention` emitted an unparsable `@Organization/code`, and a hand-written `@org/code` fell through to the user lookup, which could silently mention an unrelated user sharing that code.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
There was a problem hiding this comment.
🟡 Not ready to approve
The new test file uses a non-standard toHaveBeenCalledExactlyOnceWith matcher that is not defined in the Vitest setup and will likely fail in CI.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR fixes mention parsing/rendering for organizations and groups after the DirectoryEntityType enum migration by centralizing the Markdown mention prefix mapping inside MentionReplacer, and ensuring the regexp, emitted mention text, and rendered data-*-mention-id attributes are derived from the same source. It also adds unit tests to lock in round-trip behavior and cross-module compatibility with extractReplyMentions.
Changes:
- Introduce explicit mention-prefix mappings and a derived mention regexp in
MentionReplacer, avoiding the previous silent fallback behavior that masked type mismatches. - Update mention creation, lookup, and anchor attribute naming to consistently use the new prefix mapping (
org/group) rather than enum display names. - Add a new test suite covering mention round trips per entity type and verifying anchors are readable by
extractReplyMentions.
File summaries
| File | Description |
|---|---|
src/app/markdown/replacer/mention-replacer.ts |
Centralizes prefix/type mapping and derives parsing + rendered anchor attribute naming from it to restore org/group mentions. |
tests/unit/app/markdown/replacer/mention-replacer.test.ts |
Adds coverage for mention creation/lookup/rendering and verifies extractReplyMentions interoperability. |
Review details
Suppressed comments (1)
tests/unit/app/markdown/replacer/mention-replacer.test.ts:119
- Same issue here:
toHaveBeenCalledExactlyOnceWithisn't provided by default in Vitest/Jest (and isn’t added intests/setup.ts). Replace with standard call count + argument assertions.
expect(kintoneClient.findUserByCode).toHaveBeenCalledExactlyOnceWith(
"org/",
);
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Migrating
DirectoryEntityto Zod (#869) changedDirectoryEntityTypevalues from the Markdown notation prefixes (user/org/group) to display names, but the mention regexp kept matching the old lowercase prefixes. Since then, picking an organization or a group from the autocomplete inserted an unparsable@Organization/code, which was looked up as a user, missed, and stayed plain text. A hand-written@org/codewas worse: the switch on the captured prefix never matched the new enum values, so it fell through to the user lookup and could silently mention an unrelated user sharing that code.The notation prefix is now a mapping owned by
MentionReplacer, and the regexp, the emitted text and thedata-*-mention-idattribute name are all derived from it. The reverse lookup deliberately does not reusetoDirectoryEntityType, whose silentUserfallback is what hid this for over a year.MentionReplacerhad no tests, which is why this shipped green. The new suite pins the round trip (createMention→fetchDirectoryEntityInText→replaceMention) per entity type, the exact anchor attributes, and — across modules — thatextractReplyMentionscan read those anchors back. 6 of its 12 cases fail against the unfixed source.Verification
pnpm run test/typecheck/lint/buildall pass.Verified by hand on the legacy UI of a dev environment (space thread comments):
@org/test_org/@group/Administrators, rendering anchors withdata-org-mention-id/data-group-mention-idmentions/groupMentions/orgMentionscorrectly derived from them@org/test_organd@group/AdministratorsNote: mentioning the root organization is rejected by kintone with
CB_IL02regardless of the markup (orgMentions:["<root org id>"]fails even with a plain body), so verification used a regular organization.Summary by CodeRabbit
Bug Fixes
@,@org/, and@group/.Tests