test(ui-conversation): cover the placeholder slot with demo bundles

Split the placeholder coverage out of fixture-input-extension: one bundle renders keycaps and a Plan outline, another matches a single configured Session.
This commit is contained in:
EricMoin committed 2026-11-20 16:41:36 +08:00
1 parent 36426e319b
commit 7cb77eade7
11 files changed
+288 -19

No files matched your search

@@ -1 +1,4 @@
- textbox "/ to browse commands"
- textbox "/ Browse commands · @ Mention files or sessions"
- textbox "Plan outline Goal · Constraints · Success criteria"
- textbox "Review Changes Risks Tests"
- textbox "Describe what you want to build, / commands, @ files or sessions"
@@ -0,0 +1,92 @@
/** Shows a three-step review outline in the empty composer of the configured Session. */
window.__ModuleLoader__.load({
id: '@fixture/composer-review-session',
factory(require) {
const { createElement } = require('react')
const slot = 'conversation.input.placeholder'
const locale = 'demoComposerReviewSession'
const steps = [
{ key: 'changes', accent: 'var(--dsw-alias-state-business-primary)' },
{ key: 'risks', accent: 'var(--dsw-alias-state-warn-primary)' },
{ key: 'tests', accent: 'var(--dsw-alias-state-done-primary)' },
]
const leadStyle = {
color: 'var(--dsw-alias-label-secondary)',
fontWeight: 500,
marginInlineEnd: '4px',
}
const stepStyle = {
display: 'inline-block',
paddingInline: '7px',
borderRadius: 'var(--dsw-radius-xs)',
fontSize: '0.875em',
lineHeight: '18px',
color: 'var(--dsw-alias-label-secondary)',
verticalAlign: 'baseline',
}
const connectorStyle = {
display: 'inline-block',
inlineSize: '8px',
blockSize: '1px',
marginInline: '1px 5px',
verticalAlign: 'middle',
backgroundColor: 'var(--dsw-alias-border-l4)',
}
function ReviewStep({ id, accent, label, linked }) {
return createElement('span', { style: { whiteSpace: 'nowrap' } },
linked && createElement('span', { 'aria-hidden': true, style: connectorStyle }),
createElement('span', {
'data-demo-review-step': id,
style: {
...stepStyle,
backgroundColor: `color-mix(in srgb, ${accent} 13%, transparent)`,
boxShadow: `inset 2px 0 ${accent}`,
},
}, label),
)
}
function ReviewHint({ t }) {
return createElement('span', { 'data-demo-review-path': '' },
createElement('span', { style: leadStyle }, t('review')),
...steps.flatMap(({ key, accent }, index) => [
' ',
createElement(ReviewStep, { key, id: key, accent, label: t(key), linked: index > 0 }),
]),
)
}
return {
inject: ['slots', 'locale'],
apply(ctx, config) {
ctx.effect(() => ctx.locale.register(locale, {
en: { review: 'Review', changes: 'Changes', risks: 'Risks', tests: 'Tests' },
zh: { review: '审查', changes: '改动', risks: '风险', tests: '测试' },
}))
ctx.slots.inject(slot, () => {
function register() {
const targetSessionId = config.sessionId.get()
return ctx.slots.register({
name: slot,
locale,
priority: -1,
select: ({ sessionId }) => sessionId === targetSessionId ? sessionId : null,
}, ReviewHint)
}
let dispose = register()
const unsubscribe = config.sessionId.subscribe(() => {
dispose()
dispose = register()
})
return () => {
unsubscribe()
dispose()
}
})
},
}
},
})
@@ -0,0 +1,3 @@
- insert:
- id: demo-composer-review-session
name: '@fixture/composer-review-session'
@@ -0,0 +1,10 @@
/** Host configuration for the session-specific composer hint. */
import z from '@deepseek-ai/schemastery'
/** Copy a Session ID into `sessionId` to give its composer the review checklist. */
export const Config = z.object({
sessionId: z.string().default('').volatile(),
})
/** Publish config to the client half without mounting a Host service. */
export function apply() {}
@@ -0,0 +1,13 @@
{
"name": "@fixture/composer-review-session",
"version": "0.0.1",
"private": true,
"type": "module",
"main": "index.js",
"exports": { ".": "./index.js", "./client": "./client.js" },
"dependencies": { "@deepseek-ai/schemastery": "*" },
"dsh": {
"bundle": { "patch": "./cordis.patch.yml" },
"client": { "platform": "web" }
}
}
@@ -0,0 +1,75 @@
/** Offers shortcuts or a planning outline according to the current Session's mode. */
window.__ModuleLoader__.load({
id: '@fixture/composer-shortcuts',
factory(require) {
const { createElement } = require('react')
const locale = 'demo.composerShortcuts'
const placeholder = 'conversation.input.placeholder'
const messages = {
en: {
commands: 'Browse commands',
mentions: 'Mention files or sessions',
plan: 'Plan outline',
goal: 'Goal',
constraints: 'Constraints',
criteria: 'Success criteria',
},
zh: {
commands: '浏览命令',
mentions: '引用文件或会话',
plan: '规划提纲',
goal: '目标',
constraints: '约束',
criteria: '验收标准',
},
}
const fieldStyle = {
borderRadius: 'var(--dsw-radius-xs)',
backgroundColor: 'var(--dsw-alias-bg-module-platform)',
color: 'var(--dsw-alias-label-secondary)',
padding: '1px 5px',
whiteSpace: 'nowrap',
}
const headingStyle = {
...fieldStyle,
backgroundColor: 'var(--dsw-alias-state-business-tertiary)',
color: 'var(--dsw-alias-state-business-primary)',
fontWeight: 500,
}
const keyStyle = {
...fieldStyle,
border: '1px solid var(--dsw-alias-border-l2)',
font: 'inherit',
}
function PlanOutline({ t }) {
return createElement('span', { 'data-demo-composer-plan': '' },
createElement('span', { style: headingStyle }, t('plan')), ' ',
createElement('span', { style: fieldStyle }, t('goal')), ' · ',
createElement('span', { style: fieldStyle }, t('constraints')), ' · ',
createElement('span', { style: fieldStyle }, t('criteria')),
)
}
function ShortcutHint({ t, useProjection }) {
const planning = useProjection('plan', plan => plan !== undefined && (plan.pending ? !plan.active : plan.active))
if (planning) return createElement(PlanOutline, { t })
return createElement('span', null,
createElement('kbd', { style: keyStyle }, '/'), ' ', t('commands'), ' · ',
createElement('kbd', { style: keyStyle }, '@'), ' ', t('mentions'),
)
}
return {
inject: ['slots', 'locale'],
apply(ctx) {
ctx.effect(() => ctx.locale.register(locale, messages))
ctx.slots.inject(placeholder, () => ctx.slots.register({
name: placeholder,
locale,
select: () => true,
}, ShortcutHint))
},
}
},
})
@@ -0,0 +1,3 @@
- insert:
- id: demo-composer-shortcuts
name: '@fixture/composer-shortcuts'
@@ -0,0 +1,2 @@
/** Declares the browser-only shortcut demo to the Host loader. */
export function apply() {}
@@ -0,0 +1,12 @@
{
"name": "@fixture/composer-shortcuts",
"version": "0.0.1",
"private": true,
"type": "module",
"main": "index.js",
"exports": { ".": "./index.js", "./client": "./client.js" },
"dsh": {
"bundle": { "patch": "./cordis.patch.yml" },
"client": { "platform": "web" }
}
}
@@ -5,21 +5,14 @@ window.__ModuleLoader__.load({
const React = require('react')
const { Button, Modal, IconApiOutlineRegular } = require('@deepseek-ai/dsh-client-ui-primitives')
const h = React.createElement
function CommandHint({ t }) {
return h('span', null, h('kbd', null, '/'), ' ', t('browseCommands'))
}
return {
inject: ['slots', 'locale'],
apply(ctx) {
const labels = {
start: 'Input activity', cancel: 'Cancel activity', insert: 'Insert result', stale: 'Draft changed',
setup: 'Input plugin setup', details: 'Open setup', later: 'Later', config: 'Input plugin configuration',
browseCommands: 'to browse commands',
}
ctx.effect(() => ctx.locale.register('fixtureInput', { en: labels, zh: labels }))
ctx.slots.inject('conversation.input.placeholder', () => ctx.slots.register({
name: 'conversation.input.placeholder', locale: 'fixtureInput', select: ({ sessionId }) => sessionId,
}, CommandHint))
ctx.slots.inject('conversation.input.activity', () => ctx.slots.register({
name: 'conversation.input.activity', locale: 'fixtureInput',
}, ({ inputActions, onActiveChange, locked, t }) => {
+74 -11
View File
@@ -1,5 +1,9 @@
/** Optional input contributions mount through the real Loader and preserve editor ownership. */
import { cp, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { parseEntryYaml, stringifyEntryYaml } from '@deepseek-ai/cordis-plugin-include'
import { chromium, type Browser } from 'playwright'
import { expect, it, onTestFinished } from 'vitest'
import {
@@ -8,14 +12,17 @@ import {
import { connectFreshWorkspace, newEnglishPage } from './support.ts'
const bundle = fileURLToPath(new URL('./fixtures/plugins/fixture-input-extension', import.meta.url))
const shortcutsBundle = fileURLToPath(new URL('./fixtures/plugins/demo-composer-shortcuts', import.meta.url))
const reviewBundle = fileURLToPath(new URL('./fixtures/plugins/demo-composer-review-session', import.meta.url))
const schemastery = fileURLToPath(new URL('../../../vendor/schemastery', import.meta.url))
const expected = fileURLToPath(new URL('./expected/input-plugin-extensions.expected.md', import.meta.url))
async function fixture(enabled: boolean) {
async function fixture(packages: { dir: string; enabled: boolean }[]) {
const resources: { scaffold?: WebScaffold; browser?: Browser } = {}
onTestFinished(async () => {
try { await resources.browser?.close() } finally { await resources.scaffold?.close() }
})
const scaffold = await launchWebScaffold({ profile: { packages: [{ dir: bundle, enabled }] } })
const scaffold = await launchWebScaffold({ profile: { packages } })
resources.scaffold = scaffold
const browser = await chromium.launch()
resources.browser = browser
@@ -24,16 +31,26 @@ async function fixture(enabled: boolean) {
return { scaffold, browser, page, tripwire }
}
it('renders an inline command hint and restores the built-in placeholder when the plugin unloads', async () => {
const { scaffold, browser, page, tripwire } = await fixture(true)
it('shows shortcuts, a Plan outline, and Session review steps before restoring the built-in placeholder', async () => {
// Install a private copy so the review bundle can resolve its Host schema dependency.
const installedReview = await mkdtemp(join(tmpdir(), 'dsh-composer-review-session-'))
onTestFinished(() => rm(installedReview, { recursive: true, force: true }))
await cp(reviewBundle, installedReview, { recursive: true })
const scopeDir = join(installedReview, 'node_modules', '@deepseek-ai')
await mkdir(scopeDir, { recursive: true })
await symlink(schemastery, join(scopeDir, 'schemastery'), 'junction')
const { scaffold, browser, page, tripwire } = await fixture([
{ dir: shortcutsBundle, enabled: true },
{ dir: installedReview, enabled: true },
])
await connectFreshWorkspace(page, scaffold.workspaceCwd)
const input = page.getByRole('textbox', { name: '/ to browse commands', exact: true })
const input = page.getByRole('textbox', { name: '/ Browse commands · @ Mention files or sessions', exact: true })
const placeholder = page.locator('[data-composer-placeholder]')
await input.waitFor()
expect(await placeholder.locator('kbd').innerText()).toBe('/')
expect(await placeholder.locator('kbd').allTextContents()).toEqual(['/', '@'])
expect((await input.innerText()).trim()).toBe('')
await compareOrRefreshGolden(fileURLToPath(new URL('./expected/input-plugin-placeholder.expected.md', import.meta.url)),
await captureStableAria(page, '[data-composer-input]', scaffold.workspaceCwd), webSnapshotMode())
const captureInput = () => captureStableAria(page, '[data-composer-input]', scaffold.workspaceCwd)
const shortcutsAria = await captureInput()
await input.focus()
const editor = page.locator('[data-composer-input]')
@@ -42,19 +59,65 @@ it('renders an inline command hint and restores the built-in placeholder when th
await editor.dispatchEvent('compositionend', { data: '' })
await placeholder.waitFor({ state: 'visible' })
await editor.fill('/plan ')
await editor.press('Enter')
const planButton = page.getByRole('button', { name: 'Plan mode on, press to turn off', exact: true })
const planInput = page.getByRole('textbox', {
name: 'Plan outline Goal · Constraints · Success criteria', exact: true,
})
await planButton.waitFor()
await planInput.waitFor()
const outline = placeholder.locator('[data-demo-composer-plan]')
for (const step of ['Goal', 'Constraints', 'Success criteria']) {
expect(await outline.getByText(step, { exact: true }).isVisible()).toBe(true)
}
const planAria = await captureInput()
await planButton.click()
await planButton.waitFor({ state: 'hidden' })
await input.waitFor()
expect(await placeholder.locator('kbd').allTextContents()).toEqual(['/', '@'])
const session = await page.locator('[data-conversation-session]').getAttribute('data-conversation-session')
if (session === null || session === '') throw new Error('The composer has no Session ID')
const patchFile = join(scaffold.harnessHome, 'profiles', 'scaffold', 'cordis.patch.yml')
const parsed = parseEntryYaml(await readFile(patchFile, 'utf8'))
if (!Array.isArray(parsed)) throw new Error('The scaffold profile patch is not a list')
const profilePatches: readonly unknown[] = parsed
const configureReviewSession = (sessionId: string) => writeFile(patchFile, stringifyEntryYaml([
...profilePatches,
{ id: 'demo-composer-review-session', config: { sessionId } },
]))
const reviewInput = page.getByRole('textbox', {
name: 'Review Changes Risks Tests', exact: true,
})
await configureReviewSession(session)
await reviewInput.waitFor()
const reviewSteps = placeholder.locator('[data-demo-review-path] [data-demo-review-step]')
expect(await reviewSteps.allTextContents()).toEqual(['Changes', 'Risks', 'Tests'])
const reviewAria = await captureInput()
await configureReviewSession(`${session}-other`)
await input.waitFor()
await configureReviewSession(session)
await reviewInput.waitFor()
const plugins = await newEnglishPage(browser)
await plugins.goto(scaffold.authenticatedUrl)
await plugins.getByRole('button', { name: 'Plugins', exact: true }).click()
await plugins.getByRole('switch', { name: 'Enable @fixture/input-extension', exact: true, checked: true }).click()
await plugins.getByRole('switch', { name: 'Enable @fixture/composer-review-session', exact: true, checked: true }).click()
await input.waitFor()
await plugins.getByRole('switch', { name: 'Enable @fixture/composer-shortcuts', exact: true, checked: true }).click()
const homePrompt = 'Describe what you want to build, / commands, @ files or sessions'
await page.getByRole('textbox', { name: homePrompt, exact: true }).waitFor()
expect(await placeholder.innerText()).toBe(homePrompt)
expect(await placeholder.locator('kbd').count()).toBe(0)
await compareOrRefreshGolden(fileURLToPath(new URL('./expected/input-plugin-placeholder.expected.md', import.meta.url)),
[shortcutsAria, planAria, reviewAria, await captureInput()].join('\n'), webSnapshotMode())
expect(tripwire.pageErrors).toEqual([])
})
it('expands an input activity and inserts one undoable result without overwriting subsequent edits', async () => {
const { scaffold, page, tripwire } = await fixture(true)
const { scaffold, page, tripwire } = await fixture([{ dir: bundle, enabled: true }])
await connectFreshWorkspace(page, scaffold.workspaceCwd)
const input = page.locator('[data-composer-input]')
const start = page.getByRole('button', { name: 'Input activity', exact: true })
@@ -90,7 +153,7 @@ it('expands an input activity and inserts one undoable result without overwritin
})
it('offers bundle guidance only after explicit activation and navigates to its configuration', async () => {
const { page, tripwire } = await fixture(false)
const { page, tripwire } = await fixture([{ dir: bundle, enabled: false }])
await page.getByRole('button', { name: 'Plugins', exact: true }).click()
const toggle = page.getByRole('switch', { name: 'Enable @fixture/input-extension', exact: true })
await toggle.waitFor()