fix(discord): post the rendered screen, not the raw stream, as the alert tail

A full-screen UI repaints in place, so the raw output stream read as garbage. Read capture-pane instead and drop rules, blanks and escape codes.
This commit is contained in:
Devvyn committed 2026-10-29 21:31:37 +08:00
1 parent 1c4338e8b5
commit dcf51b1715
3 files changed
+69 -11

No files matched your search

+41
View File
@@ -12,6 +12,7 @@ import {
DISCORD_STARTUP_HINT,
isDiscordCdnUrl,
safeAttachmentName,
screenTail,
DEFAULT_DISCORD_CONFIG,
DiscordApi,
DiscordBridge,
@@ -643,3 +644,43 @@ describe('DiscordBridge files and startup hint', () => {
off.stop();
});
});
describe('screenTail', () => {
it('keeps the last lines of a rendered screen and drops rules, blanks and escape codes', () => {
const screen = [
'old line',
'',
'\u001b[1mWhich option?\u001b[0m',
'─────────────────────────',
' 1. Cap GPUs',
' 2. Cap CPU',
'\u001b(B',
' 4. Type something.',
'━━━━━━━━━━━━━━━━━━━━━━━━━',
'Enter to select · Esc to cancel\u001b(B',
].join('\n');
expect(screenTail(screen)).toBe(
[
'old line',
'Which option?',
' 1. Cap GPUs',
' 2. Cap CPU',
' 4. Type something.',
'Enter to select · Esc to cancel',
].join('\n')
);
});
it('caps lines and characters, cutting on a line', () => {
const many = Array.from({ length: 40 }, (_v, i) => `line ${i}`).join('\n');
expect(screenTail(many).split('\n')).toHaveLength(14);
expect(screenTail(many).endsWith('line 39')).toBe(true);
const wide = Array.from({ length: 5 }, () => 'x'.repeat(400)).join('\n');
expect(screenTail(wide).length).toBeLessThanOrEqual(900);
});
it('is empty for nothing', () => {
expect(screenTail('')).toBe('');
expect(screenTail('\n\n ───── \n')).toBe('');
});
});