yyqdbngt opened a new pull request, #4707:
URL: https://github.com/apache/rocketmq-dashboard/pull/4707
<!-- Base branch: `rocketmq-studio`, the RocketMQ Studio trunk. -->
### Which Issue(s) This PR Fixes
- No open issue tracks this exact defect. #4687 caps AI conversation titles
on code point boundaries
on the Java side and #4370 does the same for message properties; this is
the web-side prompt
template store, a different file, layer and storage format.
### Brief Description
`web/src/pages/ai/promptTemplates.ts` capped the persisted template text
with `slice`, which counts
UTF-16 units:
```ts
const normalizeText = (value: unknown, maxLength: number): string =>
text.length > maxLength ? text.slice(0, maxLength) : text; //
title/description/tag
const buildPromptTemplatePreview = (body: string, maxLength = 160) =>
`${compact.slice(0, maxLength)}...`; //
list preview
```
A supplementary character - an emoji, a CJK extension character - is two
units, so a cut that lands
on one keeps the high surrogate without its low half. The lone surrogate is
not a character and has
no UTF-8 encoding, so the title that is written to
`rocketmq-studio-ai-prompt-templates` and rendered
as the label of the template list, and the preview shown next to it, both
carry U+FFFD instead of the
character they were cut out of. A title of 79 ASCII characters followed by
an emoji is the shortest
reproduction, and the CJK extension characters an operator is likely to type
have the same shape.
Both cut sites now count code points, the rule `AiConversationService`
applies to conversation titles
and `MessagePropertyDisplay` applies to message property values.
### How Did You Test This Change?
Two new cases in `web/src/pages/ai/promptTemplates.test.ts`: one saves a
template whose title is
`79 x 'a' + emoji + "tail"` and expects the stored title to be exactly `79 x
'a' + emoji`, the other
asks the preview builder for `159 x 'a' + emoji + "tail"` and expects `159 x
'a' + emoji + "..."`.
Both runs below use the project's own test runner through the
workspace-local binary
(`web/node_modules/.bin/vitest.cmd`, vitest 4.1.10 as pinned by
`web/package.json`), not a
downloaded one.
Red - on the unmodified base (new tests copied in, `promptTemplates.ts`
untouched):
```
$ cd web && .\node_modules\.bin\vitest.cmd run
src/pages/ai/promptTemplates.test.ts
❯ src/pages/ai/promptTemplates.test.ts (13 tests | 2 failed) 2.72s
× caps a stored title on code point boundaries 8ms
× cuts an over-long preview on code point boundaries 2ms
FAIL src/pages/ai/promptTemplates.test.ts > AI prompt templates > caps a
stored title on code point boundaries
AssertionError: expected 'aaaa…' to be 'aaaa…' // Object.is equality
Expected:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀"
Received:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ufffd"
Test Files 1 failed (1)
Tests 2 failed | 11 passed (13)
```
Green - with the fix, including the 11 pre-existing cases of the file:
```
$ cd web && .\node_modules\.bin\vitest.cmd run
src/pages/ai/promptTemplates.test.ts
Test Files 1 passed (1)
Tests 13 passed (13)
Duration 2.51s
```
```
$ cd web && npx tsc -b # exit 0, no output
$ cd web && .\node_modules\.bin\eslint.cmd src/pages/ai/promptTemplates.ts
src/pages/ai/promptTemplates.test.ts
# exit 0, no output
```
The existing `bounds custom template count and body size` case still holds:
the caps keep their
values (`MAX_PROMPT_TEMPLATE_TITLE_LENGTH` 80,
`MAX_PROMPT_TEMPLATE_BODY_LENGTH` 6000) and are now
code-point budgets, so an ASCII body is still truncated to exactly 6000
units.
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits (`feat:` / `fix:` /
`refactor:` / `chore:` / `docs:` / `perf:`)
- [x] Tests added or updated for non-trivial changes, test methods named
`...Test`
- [x] New UI text has both Chinese and English entries under `web/src/i18n/`
(no UI text is added)
- [x] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks); no server file is touched, so the Java suite is not affected
- [x] New source files carry the ASF license header (no new source file)
- [x] Documentation touched where behaviour changed (no README / `docs/`
page documents the template caps)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]