Frun1na opened a new pull request, #6823:
URL: https://github.com/apache/rocketmq-dashboard/pull/6823
### Which Issue(s) This PR Fixes
- Fixes #6821
### Brief Description
Saving a prompt template clamps its title (80), body (6000) and each tag
(24) with `String.prototype.slice`
(`web/src/pages/ai/promptTemplates.ts:219-222`), which counts UTF-16 units. A
supplementary character that straddles the cap is cut in half: a title of 79
`a`s followed by `🚀` is 81 units, so the saved title kept the 79 `a`s **and**
the emoji's high surrogate, and the template list
(`PromptTemplateModal.tsx:275`) renders it as the replacement glyph. The same
clamp also runs on the way back in, through `sanitizeCustomTemplate`, so a
stored value that carries half a character is re-clamped to the same broken
string.
`normalizeText` now clamps through `clampText`, which drops the character
straddling the cut whole and otherwise keeps the same budget in UTF-16 units.
That unit is deliberate: 8192 of them is what the backend's `@Size` counts for
the composer draft that becomes a template body, so the cap itself must not
change. This is the copy #5213 did not cover — it fixed the same defect for
conversation titles by routing them through `TextBounds.truncate`, and the
"whole-or-drop" behaviour here matches it.
User-visible behaviour: a template whose text is clamped ends in a readable
character instead of a replacement glyph, and the stored value no longer
contains an unpaired surrogate.
### How Did You Test This Change?
```
$ ./wb test --filter src/pages/ai/promptTemplates.test.ts
✓ npx eslint src/pages/ai/promptTemplates.test.ts
src/pages/ai/promptTemplates.ts
✓ npx prettier --check src/pages/ai/promptTemplates.test.ts
src/pages/ai/promptTemplates.ts
✓ npx vitest run src/pages/ai/promptTemplates.test.ts --maxWorkers=1
--fileParallelism=false
✓ npx tsc -b
$ ./wb test
✓ npx vitest related --run src/pages/ai/promptTemplates.test.ts
src/pages/ai/promptTemplates.ts --maxWorkers=1 --fileParallelism=false
--passWithNoTests
✓ npx eslint / prettier / tsc -b
```
The two new cases save a template whose title is 79 units plus an emoji and
one whose body is 5999 units plus an emoji, and assert the straddling character
is dropped whole.
The new tests fail without the fix (the long runs of `a`s are elided below;
the reporter prints
them in full and the received value ends in the unpaired surrogate it
renders as `\ufffd`):
```
FAIL src/pages/ai/promptTemplates.test.ts > AI prompt templates > does not
split a supplementary
character when it clamps a saved title
AssertionError: expected 'aaa…' to be 'aaa…' // Object.is equality
Expected: "…aaaa" (79 a's)
Received: "…aaaa\ufffd"
❯ src/pages/ai/promptTemplates.test.ts:236:36
FAIL … > does not split a supplementary character when it clamps a saved
body
❯ src/pages/ai/promptTemplates.test.ts:248:35
Test Files 1 failed (1)
Tests 2 failed | 12 passed (14)
```
That run is the branch with the sixteen product lines reverted (`git stash
push` of `promptTemplates.ts`) and the new cases kept, so both failures are the
defect itself and not a fixture problem.
### Other consumers
- `useComposerDraft.readDraft`
(`web/src/pages/ai/hooks/useComposerDraft.ts:47`) clamps a restored draft the
same way. Its budget mirrors the backend's `@Size(max = 8192)` on
`AiMessageDTO.message` — the same UTF-16 count — and two open changes are
already editing that file (#5922 adds its test file), so it is left to a
separate change rather than widened here.
- `buildPromptTemplatePreview` (`promptTemplates.ts:427`) makes the same cut
at 160 units, but nothing outside its own test calls it, so changing it would
be cleanup rather than a fix.
- The transcript's two-line template-body clamp is CSS
(`-webkit-line-clamp`, `PromptTemplateModal.tsx:265-270`), which cuts at glyph
boundaries by construction.
- Server-side equivalents are already correct: conversation titles and
rename caps go through `TextBounds.truncate` (#5213), and the tool-output cap
uses a byte-boundary helper (`AgentEventProjector.truncateOnCharacterBoundary`).
### 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`
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks)
- [ ] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed (README / `docs/` /
in-app help)
--
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]