From 494f5e80d06b64f528e71237b1452d94dcfa278a Mon Sep 17 00:00:00 2001 From: ymac <707337118@qq.com> Date: Sun, 18 Oct 2026 20:38:20 +0800 Subject: [PATCH] =?UTF-8?q?test(e2e):=20=E8=A6=86=E7=9B=96=E3=80=8C?= =?UTF-8?q?=E4=B8=A4=E6=AC=A1=E6=8F=92=E5=85=A5=E4=B9=8B=E9=97=B4=E5=A4=B9?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E3=80=8D=E4=B8=8E=E3=80=8C=E5=A4=9A=E8=A1=8C?= =?UTF-8?q?=E9=80=89=E5=8C=BA=E5=BC=95=E7=94=A8=E3=80=8D=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E8=A1=A5=E4=B8=80=E6=9D=A1=E5=A4=9A=E8=A1=8C=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 真机 lane 的这条用例现在跑四种形状:两次文件 @(chip)、一次目录 @(纯文本 token)、 中间夹打字文本后再插一个文件 @、以及从 markdown 预览里框选多行后用选区弹窗插入 (payload 是带围栏的多行串)。每一段之后都要求既有 chip 数量与身份不变、纯文本 token 数量不变、且引文逐字落地(围栏与换行都在)。写成这样是因为旧实现在**任何一次**插入时 都会整份重写草稿,四种形状都会红。 lane 里踩到的两个选择器坑,注释已经写在用例上,避免下次再踩: - 宿主为每个保留会话渲染隐藏 seat,`[data-sidebar-right-panel]` 会同时匹配隐藏副本, 沿它取 `.first()` 拿到的可能是不可见的那个(boundingBox 为 null / 文本节点没有 rect); - markdown 预览模式会把 CodeMirror 宿主**保留但隐藏**(未保存草稿),所以定位必须 `filter({ visible: true })`,否则会选中隐藏的那份。 单测侧补一条:多行 payload 逐字交给宿主(围栏与换行不动)、既有 chip 的 occurrence 仍在、 `setDraft` 不被调用。 --- tests/conversation-draft.spec.ts | 17 ++++++++++ tests/e2e/mount.e2e.ts | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/tests/conversation-draft.spec.ts b/tests/conversation-draft.spec.ts index e3777c1b..2da0f892 100644 --- a/tests/conversation-draft.spec.ts +++ b/tests/conversation-draft.spec.ts @@ -328,6 +328,23 @@ describe('appendToDraft', () => { expect(composer.setDrafts).toEqual([]) }) + it('hands a multi-line payload to the host verbatim and keeps the chip (selection quote)', () => { + const composer = fakeComposer({ + draft: '@notes/ENV.md ', + draftRev: 1, + occurrences: [{ offset: 0, length: 13 }], + }) + const quote = ['```diagram.md:1-9', '# Diagram', 'tail text', '```'].join('\n') + expect(appendToDraft(composer.ctx, 's1', quote)).toBe(true) + // The draft already ends with whitespace, so the payload arrives untouched: + // no leading separator, every newline intact (the host renders them under + // the composer's `white-space: pre-wrap`). + expect(composer.events[0]?.payload.text).toBe(quote) + expect(composer.read().draft).toBe(`@notes/ENV.md ${quote}`) + expect(composer.read().occurrences).toEqual([{ offset: 0, length: 13 }]) + expect(composer.setDrafts).toEqual([]) + }) + it('reports false — logs, and leaves the draft alone — when no listener handled the event', () => { const consoleWarn = vi.spyOn(console, 'warn').mockImplementation(() => undefined) const composer = fakeComposer({ draft: 'hi', draftRev: 2 }) diff --git a/tests/e2e/mount.e2e.ts b/tests/e2e/mount.e2e.ts index b0153761..747a2009 100644 --- a/tests/e2e/mount.e2e.ts +++ b/tests/e2e/mount.e2e.ts @@ -988,6 +988,64 @@ test('the explorer @-reference button keeps earlier chips (no whole-draft rewrit ).toHaveCount(1, { timeout: 15_000 }) await expect(chips, 'the folder insert must leave both chips intact').toHaveCount(2) + // Text typed BETWEEN two references must not change how either insert + // behaves: the next reference still lands as its own chip, and the earlier + // ones stay chips (the flattened-draft bug used to eat them on any insert). + const composer = chips.first().locator('xpath=ancestor::*[@contenteditable="true"][1]') + const typeInComposer = async (text: string): Promise => { + await composer.click() + await page.keyboard.press('End') + await page.keyboard.type(text) + } + + await typeInComposer('prose between mentions ') + await expect(chips, 'typing must not touch the chips').toHaveCount(2) + await referenceRow(SEEDED_README_FILE) + await expect( + chips, + 'a reference inserted after interleaved prose must add its own chip and keep the rest', + ).toHaveCount(3, { timeout: 15_000 }) + await expect(chips.first(), 'the first chip must still carry its own file').toContainText(SEEDED_FILE) + await expect( + page.locator('[data-composer-text-ref]'), + 'the folder token stays the only plain-text reference', + ).toHaveCount(1) + + // The viewer's selection popup: its payload is a fenced MULTI-LINE string + // that rides the same plain-text insert. It must arrive verbatim (newlines + // included) and leave every chip alone. + const mdRow = pane.locator(`[role="button"][title$="${SEEDED_MD_FILE}"]:visible`) + await expect(mdRow).toHaveCount(1, { timeout: 30_000 }) + await mdRow.click({ position: { x: 8, y: 8 } }) // open the file (not the @ action) + await expect(pane.getByText('tail text')).toHaveCount(1, { timeout: 30_000 }) + // A multi-line selection in the code viewer (CodeMirror): the editor path + // raises the same popup with a fenced payload carrying the file and its line + // range — the multi-line shape this module has to hand over verbatim. + // The preview keeps a hidden CodeMirror host mounted (unsaved edits), so + // every locator here has to filter for the VISIBLE copy. + const heading = pane.getByText('Diagram', { exact: true }).filter({ visible: true }).first() + const tail = pane.getByText('tail text', { exact: true }).filter({ visible: true }).first() + const headingBox = await heading.boundingBox() + const tailBox = await tail.boundingBox() + expect(headingBox, 'the visible preview heading must be laid out').not.toBeNull() + expect(tailBox, 'the visible preview line must be laid out').not.toBeNull() + await page.mouse.move(headingBox!.x + 2, headingBox!.y + headingBox!.height / 2) + await page.mouse.down() + await page.mouse.move(tailBox!.x + tailBox!.width - 2, tailBox!.y + tailBox!.height / 2, { steps: 8 }) + await page.mouse.up() + + const quoteButton = page.getByRole('button', { name: /Add to conversation|添加到对话/ }) + await expect(quoteButton, 'the selection popup must offer the quote').toHaveCount(1, { timeout: 10_000 }) + await quoteButton.click() + await expect( + chips, + 'the multi-line quote must leave every chip intact', + ).toHaveCount(3, { timeout: 15_000 }) + const composed = await composer.evaluate((element) => element.textContent ?? '') + expect(composed, 'the quote must arrive verbatim, fences and newlines included').toContain('```') + expect(composed, 'the quote must keep its line breaks').toContain('\n') + expect(composed).toContain('tail text') + expect(pageErrors, 'no page error while inserting references').toEqual([]) })