2026-03-26 12:13:36 +08:00
|
|
|
|
import {
|
2026-03-27 16:01:28 +08:00
|
|
|
|
assistantSegmentMessageId,
|
2026-03-26 12:13:36 +08:00
|
|
|
|
lastSegmentPreview,
|
2026-03-27 16:01:28 +08:00
|
|
|
|
normalizeAssistantContentForSplit,
|
2026-05-19 14:55:10 +08:00
|
|
|
|
parseAssistantSplitListKey,
|
|
|
|
|
|
playbackListKeyMatchesBubble,
|
2026-03-26 12:13:36 +08:00
|
|
|
|
splitMessageParts,
|
|
|
|
|
|
splitStreamingSegments,
|
|
|
|
|
|
} from '@/features/conversation/message-split';
|
|
|
|
|
|
|
|
|
|
|
|
describe('message-split', () => {
|
|
|
|
|
|
it('splitMessageParts is case-insensitive on delimiter', () => {
|
|
|
|
|
|
expect(splitMessageParts('a [SPLIT] b')).toEqual(['a', 'b']);
|
|
|
|
|
|
expect(splitMessageParts('a [split] b')).toEqual(['a', 'b']);
|
|
|
|
|
|
expect(splitMessageParts('a [Split] b')).toEqual(['a', 'b']);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-27 16:01:28 +08:00
|
|
|
|
it('splitMessageParts handles spaces inside brackets and fullwidth brackets', () => {
|
|
|
|
|
|
expect(splitMessageParts('a [ SPLIT ] b')).toEqual(['a', 'b']);
|
|
|
|
|
|
expect(splitMessageParts('a[SPLIT]b')).toEqual(['a', 'b']);
|
|
|
|
|
|
expect(splitMessageParts('a【SPLIT】b')).toEqual(['a', 'b']);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-26 12:13:36 +08:00
|
|
|
|
it('splitMessageParts trims and drops empty segments', () => {
|
|
|
|
|
|
expect(splitMessageParts(' x [SPLIT] y ')).toEqual(['x', 'y']);
|
|
|
|
|
|
expect(splitMessageParts('[SPLIT]only')).toEqual(['only']);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-27 16:01:28 +08:00
|
|
|
|
it('splitMessageParts splits multi-segment content as persisted / WS-joined', () => {
|
|
|
|
|
|
expect(splitMessageParts('第一段[SPLIT]第二段')).toEqual([
|
|
|
|
|
|
'第一段',
|
|
|
|
|
|
'第二段',
|
|
|
|
|
|
]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('splitMessageParts falls back to double-newline paragraphs (no [SPLIT] in DB)', () => {
|
|
|
|
|
|
const a = '太为你高兴了!在上海大剧院的舞台绽放,聚光灯下的你。';
|
|
|
|
|
|
const b =
|
|
|
|
|
|
'说到舞台,我忽然想起你黄浦江边的童年。从看着江水流淌,到在舞台上演绎别人的悲欢。';
|
|
|
|
|
|
expect(splitMessageParts(`${a}\n\n${b}`)).toEqual([a, b]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-26 12:13:36 +08:00
|
|
|
|
it('splitStreamingSegments keeps empty tail after delimiter', () => {
|
feat(i18n): persist language preference and thread through chat, memoir, TTS
- Add users.language_preference (Alembic 0018, default zh); capture at signup/SMS
only; expose on auth and profile APIs
- Lite English prompts for chat and memoir; localized stage labels and agent
names (Life Echo / 岁月知己)
- Tencent TTS: language-aware synthesis, ModelType=1 for 501004, English chunking
- WebSocket pipeline: emit all AGENT_RESPONSE segments when TTS cancels; INFO logs
for tts_this_turn and TTS decisions; on-demand TTS logging
- Expo: device language on auth, i18n tiers/agent name, [SPLIT] streaming UX fixes
- Tests for migration, prompts, pipeline, router tts_this_turn, reply segments
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 16:16:49 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 流式上下文(!isComplete)下保留尾部空段,让 UI 能在分隔符已出现、第二段尚未到字时
|
|
|
|
|
|
* 渲染「上一段已完成气泡 + 空流式气泡」。`StreamingBubbles` 在 isComplete=true 时
|
|
|
|
|
|
* 会过滤掉这只空尾段(见 conversation/[id].tsx 与对应注释),所以底部不会再永久挂一只
|
|
|
|
|
|
* 假装的「Replying…」气泡。
|
|
|
|
|
|
*/
|
2026-03-26 12:13:36 +08:00
|
|
|
|
expect(splitStreamingSegments('first [SPLIT]')).toEqual(['first', '']);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
feat(i18n): persist language preference and thread through chat, memoir, TTS
- Add users.language_preference (Alembic 0018, default zh); capture at signup/SMS
only; expose on auth and profile APIs
- Lite English prompts for chat and memoir; localized stage labels and agent
names (Life Echo / 岁月知己)
- Tencent TTS: language-aware synthesis, ModelType=1 for 501004, English chunking
- WebSocket pipeline: emit all AGENT_RESPONSE segments when TTS cancels; INFO logs
for tts_this_turn and TTS decisions; on-demand TTS logging
- Expo: device language on auth, i18n tiers/agent name, [SPLIT] streaming UX fixes
- Tests for migration, prompts, pipeline, router tts_this_turn, reply segments
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 16:16:49 +08:00
|
|
|
|
it('splitStreamingSegments handles lowercase / fullwidth split markers', () => {
|
|
|
|
|
|
expect(splitStreamingSegments('a [split] b')).toEqual(['a', 'b']);
|
|
|
|
|
|
expect(splitStreamingSegments('a【SPLIT】b')).toEqual(['a', 'b']);
|
|
|
|
|
|
expect(splitStreamingSegments('a [ SPLIT ] b')).toEqual(['a', 'b']);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('splitMessageParts accepts spaced / lowercase delimiters', () => {
|
|
|
|
|
|
expect(splitMessageParts('first [ SPLIT ] second')).toEqual([
|
|
|
|
|
|
'first',
|
|
|
|
|
|
'second',
|
|
|
|
|
|
]);
|
|
|
|
|
|
expect(splitMessageParts('first [split] second')).toEqual([
|
|
|
|
|
|
'first',
|
|
|
|
|
|
'second',
|
|
|
|
|
|
]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-26 12:13:36 +08:00
|
|
|
|
it('lastSegmentPreview uses last non-empty part', () => {
|
|
|
|
|
|
expect(lastSegmentPreview('a [SPLIT] b', 10)).toBe('b');
|
|
|
|
|
|
expect(lastSegmentPreview('hello', 3)).toBe('hel');
|
|
|
|
|
|
});
|
2026-03-27 16:01:28 +08:00
|
|
|
|
|
|
|
|
|
|
it('assistantSegmentMessageId matches WS / TTS segment binding', () => {
|
|
|
|
|
|
expect(assistantSegmentMessageId('uuid-a', 0)).toBe('uuid-a_seg_0');
|
|
|
|
|
|
expect(assistantSegmentMessageId('uuid-a', 1)).toBe('uuid-a_seg_1');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-19 14:55:10 +08:00
|
|
|
|
it('playbackListKeyMatchesBubble aligns seg playback with part listKey', () => {
|
|
|
|
|
|
const uuid = '78b32c06-d2f9-453b-9cc4-354e68fbcb2d';
|
|
|
|
|
|
expect(
|
|
|
|
|
|
playbackListKeyMatchesBubble(
|
|
|
|
|
|
`${uuid}_seg_1`,
|
|
|
|
|
|
`${uuid}_part_1`,
|
|
|
|
|
|
uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
).toBe(true);
|
|
|
|
|
|
expect(
|
|
|
|
|
|
playbackListKeyMatchesBubble(
|
|
|
|
|
|
`${uuid}_seg_0`,
|
|
|
|
|
|
`${uuid}_part_1`,
|
|
|
|
|
|
uuid,
|
|
|
|
|
|
),
|
|
|
|
|
|
).toBe(false);
|
|
|
|
|
|
expect(parseAssistantSplitListKey(`${uuid}_part_0`)).toEqual({
|
|
|
|
|
|
messageId: uuid,
|
|
|
|
|
|
segmentIndex: 0,
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-27 16:01:28 +08:00
|
|
|
|
it('normalizeAssistantContentForSplit maps fullwidth brackets', () => {
|
|
|
|
|
|
expect(normalizeAssistantContentForSplit('[x]')).toBe('[x]');
|
|
|
|
|
|
expect(normalizeAssistantContentForSplit('【x】')).toBe('[x]');
|
|
|
|
|
|
});
|
2026-03-26 12:13:36 +08:00
|
|
|
|
});
|