diff --git a/src/chatpanel/app/bootstrap.ts b/src/chatpanel/app/bootstrap.ts index a62b827..e1c559a 100644 --- a/src/chatpanel/app/bootstrap.ts +++ b/src/chatpanel/app/bootstrap.ts @@ -278,8 +278,7 @@ export function mountChatPanel(): void { }); const messageRenderOptions: MessageRenderOptions = { - shouldAutoScroll: (reason) => - reason === 'render-all' || messageListAutoScrollState.shouldAutoScroll(), + shouldAutoScroll: () => messageListAutoScrollState.shouldAutoScroll(), onAssistantAction: (action, message) => { if (!conversationFlow) { return; diff --git a/tests/unit/chatpanel/app/regen-flow.test.ts b/tests/unit/chatpanel/app/regen-flow.test.ts index 35d92f7..5fd8994 100644 --- a/tests/unit/chatpanel/app/regen-flow.test.ts +++ b/tests/unit/chatpanel/app/regen-flow.test.ts @@ -1027,6 +1027,9 @@ describe('chatpanel regenerate flow', () => { await flushMicrotasks(6); expect(messageList.scrollTop).toBe(700); + messageList.scrollTop = 600; + messageList.dispatchEvent(new testWindow.Event('scroll')); + currentMessages = [ { id: 'persisted-user-2', role: 'user', content: 'second prompt' }, { @@ -1048,7 +1051,11 @@ describe('chatpanel regenerate flow', () => { }, }, }); - await flushMicrotasks(20); + simulatedScrollHeight = 760; + const loadCountBeforeSecondCompletion = loadRequests.length; + await flushMicrotasks(80); + expect(loadRequests.length).toBeGreaterThan(loadCountBeforeSecondCompletion); + expect(messageList.scrollTop).toBe(600); }); it('shows image previews inline within the chatpanel for staged and message attachments', async () => { diff --git a/tests/unit/plugins/page-text-extraction/nga-bbs-cn.plugin.test.ts b/tests/unit/plugins/page-text-extraction/nga-bbs-cn.plugin.test.ts deleted file mode 100644 index 6c77207..0000000 --- a/tests/unit/plugins/page-text-extraction/nga-bbs-cn.plugin.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; -import { ngaBbsCnPlugin } from '../../../../plugins/page-text-extraction/local-nga-bbs-cn.plugin.js'; -import { - type InstalledDomEnvironment, - installDomTestEnvironment, -} from '../../helpers/dom-test-env'; - -describe('nga bbs cn plugin', () => { - let env: InstalledDomEnvironment | null = null; - - beforeEach(() => { - env = installDomTestEnvironment(); - }); - - afterEach(() => { - env?.restore(); - env = null; - }); - - it('matches all pages under bbs.nga.cn only', () => { - expect(ngaBbsCnPlugin.matches('https://bbs.nga.cn/read.php?tid=46260077')).toBe(true); - expect(ngaBbsCnPlugin.matches('https://bbs.nga.cn/thread.php?fid=-7&page=3')).toBe(true); - expect(ngaBbsCnPlugin.matches('https://bbs.nga.cn/')).toBe(true); - expect(ngaBbsCnPlugin.matches('https://ngabbs.com/read.php?tid=46260077')).toBe(false); - expect(ngaBbsCnPlugin.matches('https://nga.178.com/read.php?tid=46260077')).toBe(false); - expect(ngaBbsCnPlugin.matches('https://foo.bbs.nga.cn/read.php?tid=46260077')).toBe(false); - }); - - it('normalizes post table html into readable article sections', () => { - const sourceHtml = ` - - Sample NGA Thread - - Author A - 2026-02-25 12:00 - - First line
- Second line - -
- - - `; - - const parser = env?.window.DOMParser; - if (!parser) { - throw new Error('DOMParser is unavailable in test environment.'); - } - - const normalizedHtml = ngaBbsCnPlugin.preprocess({ - sourceHtml, - sourceUrl: 'https://bbs.nga.cn/read.php?tid=46260077', - parseHtmlToDocument: (html) => new parser().parseFromString(html, 'text/html'), - }); - - const parsed = new parser().parseFromString(normalizedHtml, 'text/html'); - expect(parsed.querySelector('article[data-speakeasy-source="nga-bbs-cn"]')).not.toBeNull(); - expect(parsed.querySelector('h1')?.textContent).toBe('Sample NGA Thread'); - expect(parsed.querySelector('h2')?.textContent).toContain('#0 Author A'); - expect(parsed.querySelector('p')?.textContent).toBe('2026-02-25 12:00'); - expect(parsed.querySelector('img[src="about:blank"]')).toBeNull(); - }); - - it('keeps text around smile emojis by converting smile images to inline text', () => { - const sourceHtml = ` - - Emoji Thread - - Author A - 2026-02-25 12:00 - - 从标题到正文全是错误,也是没谁了 - 怕 - - - - - `; - - const parser = env?.window.DOMParser; - if (!parser) { - throw new Error('DOMParser is unavailable in test environment.'); - } - - const normalizedHtml = ngaBbsCnPlugin.preprocess({ - sourceHtml, - sourceUrl: 'https://bbs.nga.cn/read.php?tid=46260077', - parseHtmlToDocument: (html) => new parser().parseFromString(html, 'text/html'), - }); - - const parsed = new parser().parseFromString(normalizedHtml, 'text/html'); - const section = parsed.querySelector('section[data-floor="0"]'); - expect(section?.textContent?.replace(/\s+/g, ' ').trim()).toContain( - '从标题到正文全是错误,也是没谁了 [怕]', - ); - expect(section?.querySelector('img.smile_ac')).toBeNull(); - expect(section?.querySelector('.smile_alt_text')).toBeNull(); - }); -});