From 70eb6b7276b03eb7b09b4cd32f652198b99a9e63 Mon Sep 17 00:00:00 2001 From: ymac <707337118@qq.com> Date: Sun, 18 Oct 2026 20:05:58 +0800 Subject: [PATCH] =?UTF-8?q?test(e2e):=20=E6=8C=82=E8=BD=BD=20lane=20?= =?UTF-8?q?=E9=92=89=E4=BD=8F=20@=20=E5=BC=95=E7=94=A8=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E6=95=B4=E4=BB=BD=E9=87=8D=E5=86=99=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=EF=BC=88chip=20=E4=B8=8D=E8=A2=AB=E5=B1=95=E5=B9=B3?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上游一旦改动 composer 的内部事件或坐标投影,这条链路的表现是「点击无效」而不是报错 (我们发的是非公开的 session 作用域事件),单测用假宿主钉不住这一点,所以补一条真机断言: 真实 composer 里经文件树点两次文件 @(两个 `[data-composer-chip]`,第一个仍带自己的文件名) 再点一次目录 @(落成宿主装饰的纯文本 token),四条断言都在;旧实现第二次点击就会把第一个 chip 展平成文本,前三条会红。 顺带把 `context-types.ts` 的 `setDraft` 注释补一句:上游若改该语义(保留 chip 或提供公开 插入面),要与 `conversation-draft.ts` 的两条插入路径一起复核。 --- src/context-types.ts | 4 +- tests/e2e/mount.e2e.ts | 85 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/context-types.ts b/src/context-types.ts index 19dd6aa0..42af56ec 100644 --- a/src/context-types.ts +++ b/src/context-types.ts @@ -670,7 +670,9 @@ export interface SidebarSessionInput { * Replace the whole draft text. **Not an insert API**: it removes inline * reference chips (the draft comes back as plain text), so both insertion * paths emit scoped composer events instead — see - * `client/conversation-draft.ts`. + * `client/conversation-draft.ts`. If a future host changes that semantic + * (chip-preserving replacement, or a public insert/`captureInsertion` face), + * revisit this note together with both paths in that module. */ setDraft(text: string): void } diff --git a/tests/e2e/mount.e2e.ts b/tests/e2e/mount.e2e.ts index 3b04f49c..b0153761 100644 --- a/tests/e2e/mount.e2e.ts +++ b/tests/e2e/mount.e2e.ts @@ -906,3 +906,88 @@ test('the custom-CSS escape hatch injects the user stylesheet live', async ({ re await request.post(sidebarApi('settings.update'), { data: { patch: { customCss: '' } } }) } }) + +/** + * The explorer's @-reference button, twice in a row, against a real composer. + * + * The shipped regression this pins: the plugin's insert used to rewrite the + * whole draft through DSH's `setDraft`, whose contract is "replace the whole + * draft with plain text, removing inline reference chips" — so the second + * click flattened the first chip into `@dir/file` text (which the host then + * decorates as `@dir/` plus an undecorated file name, i.e. the "two-piece" + * mention). A chip-free second insert is what the host's own picker does; the + * composer must therefore hold exactly two chips and no plain-text reference. + */ +test('the explorer @-reference button keeps earlier chips (no whole-draft rewrite)', async ({ page }) => { + const pageErrors: string[] = [] + page.on('pageerror', (error) => pageErrors.push(String(error))) + + // One workspace directory for the folder-reference half of this test; it is + // created before the page loads so the tree's first listing already has it. + const refDir = 'refs' + mkdirSync(join(WORKSPACE_PATH, refDir), { recursive: true }) + + await gotoPage(page) + await dismissOnboarding(page) + // A session with content: the native sidebar's entry point and the composer + // both need one. + await sendFirstMessage(page) + + // Chips exist only in the composer, so the marker itself is the anchor + // (locale-proof, unlike the composer's aria-label). + const chips = page.locator('[data-composer-chip]') + + // The plugin's explorer, through the host's own right sidebar. + const pane = page.locator('[data-sidebar-right-panel]') + await page.locator('[data-sidebar-right-expand]').first().click() + await expect(pane).toBeVisible({ timeout: 30_000 }) + if (await page.locator('[data-sidebar-right-guide]').count() === 0) { + await page.locator('[data-dockkit-add-tab]').first().click() + } + await page.locator('[data-sidebar-right-guide-entry="files"]').click() + + /** Reveal and click one row's @-reference action (hover-revealed at the row end). */ + const referenceRow = async (file: string): Promise => { + const row = pane.locator(`[role="button"][title$="${file}"]:visible`) + await expect(row, `the seeded "${file}" file must appear in the plugin's explorer`).toHaveCount(1, { timeout: 30_000 }) + await row.hover() + // "@file" (en) / "@文件" (zh) — match the leading trigger instead of a locale. + await row.getByRole('button', { name: /^@/ }).click({ timeout: 10_000 }) + } + + await referenceRow(SEEDED_FILE) + await expect( + chips, + 'the explorer @-reference must reach the composer as one chip', + ).toHaveCount(1, { timeout: 15_000 }) + + await referenceRow(SEEDED_MD_FILE) + await expect( + chips, + 'the second @-reference must leave the first chip intact (a whole-draft rewrite would flatten it)', + ).toHaveCount(2, { timeout: 15_000 }) + await expect( + chips.first(), + 'the first chip must still carry its own file, not the flattened mention text', + ).toContainText(SEEDED_FILE, { timeout: 10_000 }) + await expect( + page.locator('[data-composer-text-ref]'), + 'no mention may degrade into plain decorated text', + ).toHaveCount(0) + + // The folder branch stays on purpose the host's plain-text insert (its own + // folder-drill path): one folder reference must land as DSH's decorated + // `@refs/` token — and it must not disturb the chips. + const dirRow = pane.locator(`[class*="explorerDir"]:has([class*="explorerName"]:text-is("${refDir}"))`) + await expect(dirRow, `the seeded "${refDir}" directory must be listed`).toHaveCount(1, { timeout: 30_000 }) + await dirRow.hover() + await dirRow.getByRole('button', { name: /^@/ }).click({ timeout: 10_000 }) + await expect( + page.locator('[data-composer-text-ref]'), + 'the folder insert must reach the composer as the host-decorated plain-text token', + ).toHaveCount(1, { timeout: 15_000 }) + await expect(chips, 'the folder insert must leave both chips intact').toHaveCount(2) + + expect(pageErrors, 'no page error while inserting references').toEqual([]) +}) +