feat(dsh): adapt to DSH 0.1.5-alpha.2

Baseline moves to DSH 0.1.5-alpha.2 only (peer floor ^0.1.5-alpha.2,
CI pin, manifest engines); alpha.1 users stay on v0.19.0-alpha.0.

Host-contract changes handled:
- the native guide entry lost its `description` field (entries are
  icon+title capsules now): `TabDescriptor.description` and the six
  `guideDesc*` keys plus the `nativeGuideDesc` fallback are removed.
- the file address grammar changed: `fileAddressFor` always returns a
  session-scoped address (absolute paths keep their leading `/`),
  `parseFileAddress` is prefix-based and strips `?`/`#`. The plugin's
  purity-gated mirror follows.
- global main panels replaced the `conversation` root slot with the
  keyed `main` slot (`main.conversation`): the bottom workbench's
  center-column locator now accepts both keys and skips
  `display: contents` slot hosts.

Fixes a pre-existing fill bug the alpha.2 probe made obvious: the native
tab body host is a block scroller with a definite height, so tab roots
that only declared `flex: 1` collapsed to content height and the side
chat composer drifted off the pane bottom. The native adapter now wraps
every tab body in a `height: 100%` column flex host.

Also promotes the dependencies `dsh-client-ui-primitives@0.1.5-alpha.2`
dropped from its manifest (anser / shiki / mdast-util-* / micromark-* /
katex / @shikijs/langs) and the newly unmet `dsh-session-persistence`
peer into devDependencies.
This commit is contained in:
Menghuan1918 committed 2026-09-09 23:09:48 +08:00
1 parent d4765819c0
commit 0b6ac5d267
43 files changed
+944 -930

No files matched your search

+11 -9
View File
@@ -44,20 +44,22 @@ describe('built-in tab registrations', () => {
expect(changes?.component).toBeDefined()
})
it('every visible tab declares a real guide line (no generic fallback)', () => {
// The native new-tab list renders `description()` under the title; a tab
// without one reads the same generic sentence as every other plugin page.
it('every visible tab declares a non-empty, mutually distinct title', () => {
// The native new-tab list (guide page) is an icon+title capsule at DSH
// 0.1.5-alpha.2 — the `description` field is gone from the host contract.
// The title is therefore the only per-tab guide text: it must exist, and
// no two visible tabs may share one (identical capsules would be
// indistinguishable in the guide and the tab strip).
const { service } = setup()
const visible = service.getTabs().filter(descriptor => descriptor.hidden !== true)
expect(visible.length).toBeGreaterThan(0)
for (const descriptor of visible) {
expect(descriptor.description, `${descriptor.id} must declare a description`).toBeDefined()
const line = typeof descriptor.description === 'function' ? descriptor.description() : descriptor.description
expect(line, `${descriptor.id} description must be non-empty`).toBeTruthy()
const title = typeof descriptor.title === 'function' ? descriptor.title() : descriptor.title
expect(title, `${descriptor.id} must declare a title`).toBeTruthy()
}
const lines = visible.map(descriptor =>
typeof descriptor.description === 'function' ? descriptor.description() : descriptor.description)
expect(new Set(lines).size, 'descriptions must differ per tab').toBe(visible.length)
const titles = visible.map(descriptor =>
typeof descriptor.title === 'function' ? descriptor.title() : descriptor.title)
expect(new Set(titles).size, 'titles must differ per tab').toBe(visible.length)
})
it('the changes tab declares no settings of its own (the diff always docks)', () => {
+38 -1
View File
@@ -1,5 +1,5 @@
// @vitest-environment jsdom
import { describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import {
CENTER_COLUMN_REVALIDATE_MS,
resolveCenterColumn,
@@ -20,6 +20,43 @@ function connectedColumn(doc = document.implementation.createHTMLDocument()): Fi
return { doc, col, slot }
}
// alpha.2 fixture: a real #root in the jsdom global document, because the
// contents-skip walk needs a live defaultView.getComputedStyle (inline
// `display: contents` on the wrapper). Build:
// #root > col > wrapper[display: contents] > host[data-slot="main.conversation"].
function alphaColumn(hostSlot: string): { col: HTMLDivElement; host: HTMLDivElement } {
const root = document.createElement('div')
root.id = 'root'
const col = document.createElement('div')
const wrapper = document.createElement('div')
wrapper.style.display = 'contents'
const host = document.createElement('div')
host.dataset.slot = hostSlot
wrapper.append(host)
col.append(wrapper)
root.append(col)
document.body.append(root)
return { col, host }
}
// The alpha fixtures append into the shared jsdom document; drop them so
// later tests' querySelector scans stay deterministic.
afterEach(() => {
for (const root of document.body.querySelectorAll('div#root')) root.remove()
})
describe('center-column anchor keys (DSH 0.1.5-alpha.2)', () => {
it('skips display:contents slot hosts above a main.conversation host', () => {
const { col } = alphaColumn('main.conversation')
expect(resolveCenterColumn(null, { now: () => 0 })).toBe(col)
})
it('still resolves the alpha.1 conversation key through the default selector', () => {
const { col } = alphaColumn('conversation')
expect(resolveCenterColumn(null, { now: () => 0 })).toBe(col)
})
})
describe('center-column locator (issue #403)', () => {
it('reuses a connected cached column without querying during the hot-path window', () => {
const { doc, col, slot } = connectedColumn()
+33
View File
@@ -314,6 +314,39 @@ test('plugin mounts into the DSH shell and survives a built-in tab sweep', async
)
.toBe(true)
// The native tab body host is a BLOCK scroller with a definite height, not a
// flex container, so a tab root that only declares `flex: 1` collapses to its
// content height — exactly how the side-chat composer used to drift away from
// the pane bottom. The native adapter wraps every body in a full-height column
// host; assert the box really fills its pane and the composer sits on the
// pane's floor. This is the regression guard for that fill contract.
await expect
.poll(
() => page.evaluate(() => {
const hosts = [...document.querySelectorAll('[data-dsh-native-tab-host]')]
const host = hosts.find(element => element.getBoundingClientRect().height > 0)
if (host === undefined) return 'no visible native tab host'
// The wrapper's parent is the SLOT HOST, which renders with
// `display: contents` and therefore has no box of its own; the pane
// body is the first ancestor that actually draws one.
const view = host.ownerDocument.defaultView
let paneBody = host.parentElement
while (paneBody !== null && (view?.getComputedStyle(paneBody).display ?? '') === 'contents') {
paneBody = paneBody.parentElement
}
if (paneBody === null) return 'the native tab host has no boxed ancestor'
const fillGap = Math.round(paneBody.getBoundingClientRect().height - host.getBoundingClientRect().height)
if (Math.abs(fillGap) > 2) return `tab body does not fill its pane: gap ${fillGap}px`
const composer = document.querySelector('[class*="sidechatComposer"]')
if (composer === null) return 'the side-chat composer is not rendered'
// The composer's own 8px bottom margin is the only allowed gap.
const bottomGap = Math.round(paneBody.getBoundingClientRect().bottom - composer.getBoundingClientRect().bottom)
return bottomGap <= 12 ? 'filled' : `the composer sits ${bottomGap}px above the pane bottom`
}),
{ timeout: 30_000 },
)
.toBe('filled')
// Side Chat host-route smoke against the REAL host: create a thread child
// under the seeded session (custom-seed creation through AgentRegistry),
// deliver a follow-up, cancel, and release it. The turn itself cannot run
+73 -10
View File
@@ -5,7 +5,10 @@
* (src/client/service.ts `setSurface`).
*/
import { describe, expect, it, vi } from 'vitest'
import { createNativeTabRecords } from '../src/client/native/tab-adapter.tsx'
import { createElement } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { act } from 'react-dom/test-utils'
import { createNativeTabRecords, NativeTabBody } from '../src/client/native/tab-adapter.tsx'
import { registerNativeSurface } from '../src/client/native/index.ts'
import { createBetterSidebarService, type SidebarSurface } from '../src/client/service.ts'
import { createSidebarStore } from '../src/client/state.ts'
@@ -162,8 +165,8 @@ describe('registerNativeSurface lifecycle (service-driven registration)', () =>
const store = createSidebarStore()
store.setSession('s1')
const service = createBetterSidebarService(store)
service.registerTab({ id: 'terminal', title: 'Terminal', component: () => null, description: () => 'Runs a shell' })
service.registerTab({ id: 'editor', title: 'Files', component: () => null, icon: () => null, description: () => 'Browse the tree' })
service.registerTab({ id: 'terminal', title: 'Terminal', component: () => null })
service.registerTab({ id: 'editor', title: 'Files', component: () => null, icon: () => null })
const records = createNativeTabRecords()
const registered: Array<{ id: string; kind: string; title: (address: string) => string; guide: unknown }> = []
@@ -225,16 +228,76 @@ describe('registerNativeSurface lifecycle (service-driven registration)', () =>
expect(filesType?.guide).toBeDefined()
// The takeover carries the editor's glyph, so the "Files" guide row is
// not the only one with a blank icon slot.
const filesGuide = filesType?.guide as Array<{ icon?: unknown; description?: () => string }> | undefined
const filesGuide = filesType?.guide as Array<{ icon?: unknown; title: () => string; description?: unknown }> | undefined
expect(filesGuide?.[0]?.icon).toBeDefined()
// The guide line is the descriptor's OWN description (the takeover reuses
// the editor's), and a descriptor that declares none falls back to the
// generic line — otherwise every plugin page would read identically.
expect(filesGuide?.[0]?.description?.()).toBe('Browse the tree')
// DSH 0.1.5-alpha.2 renders guide entries as icon+title capsules — the
// `description` field is GONE from the host contract, so no entry may
// carry one (a leftover would be silently ignored, not rendered).
expect(filesGuide?.[0]?.description).toBeUndefined()
expect('description' in (filesGuide?.[0] ?? {})).toBe(false)
expect(filesGuide?.[0]?.title?.()).toBe('Files')
const terminalGuide = registered.find(entry => entry.kind === 'terminal')?.guide as
Array<{ description?: () => string }> | undefined
expect(terminalGuide?.[0]?.description?.()).toBe('Runs a shell')
Array<{ title: () => string; description?: unknown }> | undefined
expect(terminalGuide?.[0]?.description).toBeUndefined()
expect('description' in (terminalGuide?.[0] ?? {})).toBe(false)
expect(terminalGuide?.[0]?.title?.()).toBe('Terminal')
dispose()
})
})
describe('NativeTabBody full-height host wrapper', () => {
it('renders the descriptor component inside the [data-dsh-native-tab-host] wrapper', () => {
// DSH's native tab body host (`.paneBody`) is a BLOCK scroller with a
// definite height, not a flex container — our tab roots (`flex: 1;
// min-height: 0`) collapse there without a column-flex wrapper of
// height:100%. The stable `data-dsh-native-tab-host` marker (mirroring
// `data-dsh-better-sidebar`) lets the e2e lane assert the fill; this
// unit check pins the structure: the marker wrapper exists and the
// descriptor's output is INSIDE it (before the fix the component was
// rendered bare, with no wrapper at all).
const store = createSidebarStore()
store.setSession('s1')
const service = createBetterSidebarService(store)
service.registerTab({
id: 'stub',
title: 'Stub',
component: () => createElement('div', { 'data-stub-body': '' }, 'stub body'),
})
const records = createNativeTabRecords()
const sessions = { list: { subscribe: () => () => {}, getSnapshot: () => ({ byId: {} }) } }
const ctx = { sessions } as never
const info = {
tab: {
id: 'native-9',
kind: 'stub',
title: 'Stub',
contentId: 'sidebar://stub',
visible: true,
navigation: { address: 'sidebar://stub', params: undefined, revision: 0 },
signal: new AbortController().signal,
},
}
const host = document.createElement('div')
document.body.appendChild(host)
let root: Root | undefined
act(() => {
root = createRoot(host)
root.render(createElement(NativeTabBody, {
sessionId: 's1',
ctx,
store,
service,
records,
descriptorId: 'stub',
useTabInfo: () => info,
}))
})
const wrapper = host.querySelector('[data-dsh-native-tab-host=""]')
expect(wrapper, 'the full-height host wrapper must exist').not.toBeNull()
expect(wrapper!.querySelector('[data-stub-body]'), 'the descriptor component renders inside the wrapper').not.toBeNull()
expect(wrapper!.childElementCount).toBe(1)
act(() => { root?.unmount() })
host.remove()
})
})
+34 -4
View File
@@ -2,7 +2,8 @@
* Unit tests for the file-address grammar (src/client/resource-address.ts):
* the plugin parses DSH's `dsh-resource://file/…` addresses itself (the
* client bundle's purity gate forbids value-importing the upstream util), so
* these tests pin the upstream shapes it must agree with.
* these tests pin the upstream shapes it must agree with — DSH 0.1.5-alpha.2
* (`packages/util/workspace-path` in github.com/deepseek-ai/deepseek-harness).
*/
import { describe, expect, it } from 'vitest'
import {
@@ -19,6 +20,12 @@ describe('parseFileAddress', () => {
})
})
it('reads a session-scoped address whose path is absolute inside the scope', () => {
expect(parseFileAddress('dsh-resource://file/session/s1//outside/a.ts')).toEqual({
scope: 'session', sessionId: 's1', path: '/outside/a.ts',
})
})
it('reads an absolute address (POSIX, drive, UNC)', () => {
expect(parseFileAddress('dsh-resource://file/absolute/home/me/notes.txt')).toEqual({
scope: 'absolute', path: '/home/me/notes.txt',
@@ -37,14 +44,31 @@ describe('parseFileAddress', () => {
})
})
it('strips a query or fragment suffix', () => {
expect(parseFileAddress('dsh-resource://file/session/s1/src/a.ts? freshness=2')).toEqual({
scope: 'session', sessionId: 's1', path: 'src/a.ts',
})
expect(parseFileAddress('dsh-resource://file/session/s1/src/a.ts#L12')).toEqual({
scope: 'session', sessionId: 's1', path: 'src/a.ts',
})
// The first `?` or `#` ends the path; everything after is ignored.
expect(parseFileAddress('dsh-resource://file/session/s1/src/a%3Fb.ts#c%3Fd')).toEqual({
scope: 'session', sessionId: 's1', path: 'src/a?b.ts',
})
})
it('refuses anything that is not a file address', () => {
for (const address of [
'sidebar://guide',
'dsh-resource://attachment/session/s1/a.png',
'dsh-resource://file/other/s1/a.ts',
'dsh-resource://file/session/s1',
// Empty session id (alpha.2: leading `/` is a path, not an empty id).
'dsh-resource://file/session//a.ts',
'dsh-resource://file/absolute/',
'not a url',
// Malformed percent escape: decodeURIComponent throws inside the try.
'dsh-resource://file/session/s1/a%zz.ts',
]) {
expect(parseFileAddress(address), address).toBeUndefined()
}
@@ -58,6 +82,12 @@ describe('address builders', () => {
expect(parseFileAddress(address)).toEqual({ scope: 'session', sessionId: 's1', path: 'src/a b.ts' })
})
it('keeps an absolute path absolute inside the session scope (round-trip)', () => {
const address = sessionFileAddress('s1', '/outside/a.ts')
expect(address).toBe('dsh-resource://file/session/s1//outside/a.ts')
expect(parseFileAddress(address)).toEqual({ scope: 'session', sessionId: 's1', path: '/outside/a.ts' })
})
it('builds an absolute address and round-trips it', () => {
for (const [path, address] of [
['/home/me/x.txt', 'dsh-resource://file/absolute/home/me/x.txt'],
@@ -88,8 +118,8 @@ describe('fileAddressFor', () => {
expect(fileAddressFor('s1', '/work', '/work')).toBe('dsh-resource://file/session/s1/')
})
it('falls back to an absolute address outside the workspace (or with no cwd)', () => {
expect(fileAddressFor('s1', '/work', '/other/a.ts')).toBe('dsh-resource://file/absolute/other/a.ts')
expect(fileAddressFor('s1', undefined, '/other/a.ts')).toBe('dsh-resource://file/absolute/other/a.ts')
it('keeps an absolute path outside the workspace session-scoped with its leading slash', () => {
expect(fileAddressFor('s1', '/work', '/outside/a.ts')).toBe('dsh-resource://file/session/s1//outside/a.ts')
expect(fileAddressFor('s1', undefined, '/outside/a.ts')).toBe('dsh-resource://file/session/s1//outside/a.ts')
})
})