test(e2e): 挂载 lane 钉住 @ 引用插入不会整份重写草稿(chip 不被展平)
上游一旦改动 composer 的内部事件或坐标投影,这条链路的表现是「点击无效」而不是报错 (我们发的是非公开的 session 作用域事件),单测用假宿主钉不住这一点,所以补一条真机断言: 真实 composer 里经文件树点两次文件 @(两个 `[data-composer-chip]`,第一个仍带自己的文件名) 再点一次目录 @(落成宿主装饰的纯文本 token),四条断言都在;旧实现第二次点击就会把第一个 chip 展平成文本,前三条会红。 顺带把 `context-types.ts` 的 `setDraft` 注释补一句:上游若改该语义(保留 chip 或提供公开 插入面),要与 `conversation-draft.ts` 的两条插入路径一起复核。
This commit is contained in:
1 parent
3757f75ca7
commit
70eb6b7276
2 files changed
+88
-1
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<void> => {
|
||||
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([])
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user