fix(extension): harden chat and target tab lifecycle

This commit is contained in:
Timo
2026-07-31 09:48:22 +02:00
parent 0b6ae803c8
commit 8050748e61
26 changed files with 776 additions and 226 deletions
+21
View File
@@ -19,4 +19,25 @@ describe('chat formatting', () => {
{ type: 'em', text: 'italic' }
]);
});
it('splits up to 5000 Unicode code points into at most ten ordered chat-v1 messages', () => {
const split = globalThis.KoalaSyncChatFormat.splitChatText;
expect(split('hello world', 500, 10)).toEqual(['hello world']);
const emojiChunks = split('😀'.repeat(1001), 500, 10);
expect(emojiChunks.map(chunk => [...chunk].length)).toEqual([500, 500, 1]);
const maximumChunks = split('x'.repeat(5000), 500, 10);
expect(maximumChunks).toHaveLength(10);
expect(maximumChunks.every(chunk => [...chunk].length === 500)).toBe(true);
expect(maximumChunks.join('')).toBe('x'.repeat(5000));
expect(() => split('x'.repeat(5001), 500, 10)).toThrow(RangeError);
});
it('prefers whitespace boundaries without creating more chunks than the limit allows', () => {
const split = globalThis.KoalaSyncChatFormat.splitChatText;
const chunks = split(`${'a'.repeat(420)} ${'b'.repeat(179)}`, 500, 10);
expect(chunks).toEqual(['a'.repeat(420), 'b'.repeat(179)]);
});
});