fix(native): meet DSH 0.1.6-alpha.2 guide-id and turn-tail contracts
DSH 0.1.6-alpha.2 made two plugin-facing contracts stricter, and both broke
this plugin silently:
- `SidebarRightGuideEntry.id` is now required and unique per provider. The
native tab registrations sent guide entries without one, so the second kind
collided on `undefined` and `SidebarRightTabRegistry.register` threw
'duplicate guide entry id'. The throw happens inside `ctx.inject`'s callback
body, which cordis swallows, so the whole native surface stayed empty with no
symptom beyond a missing guide row.
- `conversation.chat.turnTail` changed from a `chain` to an additive `list`.
The chain's `select` made one entry render and let this plugin REPLACE the
host's produced-files row; a list cannot express that, and the registration
now throws 'list slot ... requires options.id'. Upstream chose the list
deliberately ('An additive list lets both plugins contribute without either
knowing the other's data or rendering'), so the plugin's row can only ever
duplicate the host's deliverables row -- which itself opens files through the
host's openFile, i.e. into this plugin's editor. The contribution is removed
and the row is the host's alone.
The file-opening half survives as `sidebar-file.ts` (the changes tab and the
editor host still use it), and `resolveSidebarPath` moves to the `paths.ts`
path-helper module beside its siblings. `registerNativeSurface` grows an
optional `reportFailure` so a future contract break reaches the visible
diagnostic strip instead of a silently empty guide, and one bad descriptor can
no longer take the remaining registrations down with it.
This commit is contained in:
1 parent
1fcf43ccbe
commit
58ba17d462
17 files changed
+135
-611
No files matched your search
@@ -297,6 +297,21 @@ describe('registerNativeSurface lifecycle (service-driven registration)', () =>
|
||||
expect(browserGuide?.[0]?.description).toBeUndefined()
|
||||
expect('description' in (browserGuide?.[0] ?? {})).toBe(false)
|
||||
expect(browserGuide?.[0]?.title?.()).toBe('Browser')
|
||||
// DSH 0.1.6-alpha.2 made `SidebarRightGuideEntry.id` REQUIRED and unique
|
||||
// per provider: a registration whose guide entries carry no id collides
|
||||
// on `undefined` and `SidebarRightTabRegistry.register` throws
|
||||
// `duplicate guide entry id`, which cordis swallows — leaving the whole
|
||||
// native surface silently empty (no guide row, no plugin tab types).
|
||||
const guideIds: string[] = []
|
||||
for (const entry of registered) {
|
||||
const guide = entry.guide as Array<{ id?: unknown }> | undefined
|
||||
for (const item of guide ?? []) {
|
||||
expect(typeof item.id, `guide id of ${entry.kind}`).toBe('string')
|
||||
guideIds.push(item.id as string)
|
||||
}
|
||||
}
|
||||
expect(guideIds.length).toBeGreaterThan(0)
|
||||
expect(new Set(guideIds).size).toBe(guideIds.length)
|
||||
|
||||
dispose()
|
||||
})
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isAbsolutePath, relativeTo } from '../src/client/paths.ts'
|
||||
import { resolveSidebarPath } from '../src/client/produced-files.ts'
|
||||
import { resolveSidebarPath } from '../src/client/paths.ts'
|
||||
import { htmlUrl } from '../src/client/api.ts'
|
||||
|
||||
describe('path helpers', () => {
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { producedForClosing, resolveSidebarPath, selectProducedFiles } from '../src/client/produced-files.ts'
|
||||
|
||||
describe('produced-files derivation', () => {
|
||||
const diffResult = (path: string) => ({
|
||||
kind: 'tool-result', isError: false, callView: { card: 'diff', locations: [{ path }] },
|
||||
})
|
||||
const editResult = (path: string) => ({
|
||||
kind: 'tool-result', isError: false, callView: { card: 'generic', kind: 'edit', locations: [{ path }] },
|
||||
})
|
||||
|
||||
it('collects diff/edit locations of the closing turn, first-seen order', () => {
|
||||
const nodes = [
|
||||
{ kind: 'assistant', seq: 1, turn: 1 },
|
||||
diffResult('a.ts'),
|
||||
editResult('b.ts'),
|
||||
diffResult('a.ts'),
|
||||
{ kind: 'assistant', seq: 2, turn: 1 },
|
||||
]
|
||||
expect(producedForClosing(nodes, 2)).toEqual(['a.ts', 'b.ts'])
|
||||
})
|
||||
|
||||
it('resets on user messages and turn changes', () => {
|
||||
const nodes = [
|
||||
{ kind: 'assistant', seq: 1, turn: 1 },
|
||||
diffResult('old.ts'),
|
||||
{ kind: 'user' },
|
||||
{ kind: 'assistant', seq: 2, turn: 2 },
|
||||
diffResult('new.ts'),
|
||||
{ kind: 'assistant', seq: 3, turn: 2 },
|
||||
]
|
||||
expect(producedForClosing(nodes, 3)).toEqual(['new.ts'])
|
||||
})
|
||||
|
||||
it('ignores reads, deletes, errors, and unknown cards', () => {
|
||||
const nodes = [
|
||||
{ kind: 'assistant', seq: 1, turn: 1 },
|
||||
{ kind: 'tool-result', isError: true, callView: { card: 'diff', locations: [{ path: 'x.ts' }] } },
|
||||
{ kind: 'tool-result', isError: false, callView: { card: 'read', locations: [{ path: 'r.ts' }] } },
|
||||
{ kind: 'tool-result', isError: false, callView: { card: 'generic', kind: 'delete', locations: [{ path: 'd.ts' }] } },
|
||||
]
|
||||
expect(producedForClosing(nodes, 1)).toEqual([])
|
||||
})
|
||||
|
||||
it('selector claims only when files exist', () => {
|
||||
expect(selectProducedFiles({ nodes: [{ kind: 'assistant', seq: 1, turn: 1 }], seq: 1 })).toBeNull()
|
||||
expect(selectProducedFiles({ nodes: [diffResult('a.ts'), { kind: 'assistant', seq: 1, turn: 1 }], seq: 1 })).toEqual(['a.ts'])
|
||||
expect(selectProducedFiles(null)).toBeNull()
|
||||
})
|
||||
|
||||
it('resolves relative paths against the session cwd', () => {
|
||||
expect(resolveSidebarPath('/work/proj', 'src/a.ts')).toBe('/work/proj/src/a.ts')
|
||||
expect(resolveSidebarPath('/work/proj', '/abs/x.ts')).toBe('/abs/x.ts')
|
||||
expect(resolveSidebarPath(undefined, 'a.ts')).toBe('a.ts')
|
||||
})
|
||||
})
|
||||
@@ -1,200 +0,0 @@
|
||||
/**
|
||||
* Turn-tail interception registration spec (issue #15): `registerTurnTailInterception`
|
||||
* must go through `ctx.slots.inject` — the slot is a CHILD slot the host's
|
||||
* ui-conversation declares in its `conversation.chat.node` children table, so a
|
||||
* direct `slots.register` races the declaration and the ui-slots core throws
|
||||
* "not declared (a parent entry's children table must declare it)".
|
||||
*
|
||||
* The fake `slots` mirrors SlotRegistry.inject's semantics: run the callback
|
||||
* synchronously when the slot is already declared; otherwise wait and run it
|
||||
* when the declaration commits; the returned disposer cancels a pending wait
|
||||
* and disposes any active registration; the register disposer is idempotent.
|
||||
*/
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createSidebarStore } from '../src/client/state.ts'
|
||||
import { registerTurnTailInterception } from '../src/client/intercept.tsx'
|
||||
import type { Context } from '../src/context-types.ts'
|
||||
|
||||
interface RegisteredSlot {
|
||||
options: Record<string, unknown>
|
||||
component: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* A structural fake of the client slots service. `declared` selects the
|
||||
* timing: already-on-ledger (callback runs synchronously) vs. pending
|
||||
* (callback runs on `declare()`, unless the controller was disposed first).
|
||||
*/
|
||||
const fakeSlots = (declared: boolean) => {
|
||||
const registered: RegisteredSlot[] = []
|
||||
const disposals: number[] = []
|
||||
const pendings: Array<() => void> = []
|
||||
return {
|
||||
registered,
|
||||
disposals,
|
||||
pendings,
|
||||
slots: {
|
||||
register: (options: Record<string, unknown>, component: unknown) => {
|
||||
registered.push({ options, component })
|
||||
return () => { disposals.push(1) }
|
||||
},
|
||||
inject: (key: string, callback: () => () => void) => {
|
||||
if (key !== 'conversation.chat.turnTail') {
|
||||
throw new Error(`unexpected injected key "${key}"`)
|
||||
}
|
||||
let active: (() => void) | undefined
|
||||
let stopped = false
|
||||
const run = (): void => {
|
||||
if (stopped || active !== undefined) return
|
||||
active = callback()
|
||||
}
|
||||
if (declared) run()
|
||||
else pendings.push(run)
|
||||
return () => {
|
||||
stopped = true
|
||||
active?.()
|
||||
active = undefined
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** A produced-files owner currency: one closing assistant seq + its nodes. */
|
||||
const producedOwner = (paths: string[]): unknown => ({
|
||||
nodes: [
|
||||
{ kind: 'assistant', seq: 1, turn: 1 },
|
||||
...paths.map(path => ({
|
||||
kind: 'tool-result', isError: false, callView: { card: 'diff', locations: [{ path }] },
|
||||
})),
|
||||
{ kind: 'assistant', seq: 2, turn: 1 },
|
||||
],
|
||||
seq: 2,
|
||||
})
|
||||
|
||||
const emptyOwner = (): unknown => ({ nodes: [{ kind: 'assistant', seq: 1, turn: 1 }], seq: 1 })
|
||||
|
||||
/** The minimal client-context fake the registration (and its seats) touch. */
|
||||
const clientCtx = (slots: unknown): Context => {
|
||||
const betterSidebar = { openTab: vi.fn() }
|
||||
return {
|
||||
slots,
|
||||
sessions: {
|
||||
list: { getSnapshot: () => ({ current: 's1', byId: { s1: { id: 's1', cwd: '/w', displayTitle: 's1' } } }) },
|
||||
},
|
||||
betterSidebar,
|
||||
get: (name: string) => name === 'betterSidebar' ? betterSidebar : undefined,
|
||||
} as unknown as Context
|
||||
}
|
||||
|
||||
describe('turn-tail interception registration (issue #15)', () => {
|
||||
it('registers through slots.inject and lands once the slot is already declared', () => {
|
||||
const fake = fakeSlots(true)
|
||||
const store = createSidebarStore()
|
||||
const restore = registerTurnTailInterception(clientCtx(fake.slots), store)
|
||||
|
||||
// Exactly one registration, with the takeover descriptor.
|
||||
expect(fake.registered).toHaveLength(1)
|
||||
const { options, component } = fake.registered[0]!
|
||||
expect(options.name).toBe('conversation.chat.turnTail')
|
||||
expect(options.priority).toBe(-1)
|
||||
expect(options.registrant).toBe('dsh-better-sidebar')
|
||||
expect(options.select).toBeTypeOf('function')
|
||||
expect(options.inject).toBeTypeOf('function')
|
||||
expect(component).toBeTypeOf('function')
|
||||
|
||||
// Disposal removes the registration; the disposer is idempotent.
|
||||
restore()
|
||||
expect(fake.disposals).toHaveLength(1)
|
||||
restore()
|
||||
expect(fake.disposals).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('waits for the host declaration instead of throwing (the pre-fix race)', () => {
|
||||
const fake = fakeSlots(false)
|
||||
const store = createSidebarStore()
|
||||
const restore = registerTurnTailInterception(clientCtx(fake.slots), store)
|
||||
|
||||
// The slot is undeclared: nothing registered yet, no error.
|
||||
expect(fake.registered).toHaveLength(0)
|
||||
|
||||
// The host's ui-conversation commits the declaration → the entry lands.
|
||||
expect(fake.pendings).toHaveLength(1)
|
||||
fake.pendings[0]!()
|
||||
expect(fake.registered).toHaveLength(1)
|
||||
|
||||
// A later re-declaration does not double-register while the entry is live.
|
||||
fake.pendings[0]!()
|
||||
expect(fake.registered).toHaveLength(1)
|
||||
|
||||
restore()
|
||||
expect(fake.disposals).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('a disposal before the declaration cancels the wait permanently', () => {
|
||||
const fake = fakeSlots(false)
|
||||
const store = createSidebarStore()
|
||||
const restore = registerTurnTailInterception(clientCtx(fake.slots), store)
|
||||
restore()
|
||||
|
||||
// The declaration arrives after the controller was disposed: ignored.
|
||||
fake.pendings[0]!()
|
||||
expect(fake.registered).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('declines the takeover while the editor tab is disabled in the settings', () => {
|
||||
const fake = fakeSlots(true)
|
||||
const store = createSidebarStore()
|
||||
const restore = registerTurnTailInterception(clientCtx(fake.slots), store)
|
||||
const select = fake.registered[0]!.options.select as (owner: unknown) => unknown
|
||||
|
||||
// Enabled (default): a produced turn claims the chain; an empty one declines.
|
||||
expect(select(producedOwner(['a.ts', 'b.ts']))).toEqual(['a.ts', 'b.ts'])
|
||||
expect(select(emptyOwner())).toBeNull()
|
||||
// The engine Turn data path (the real owner currency: { turn, seq,
|
||||
// openFile }) claims through the deliverables record too.
|
||||
expect(select({
|
||||
turn: { data: { get: (key: string) => key === 'deliverables' ? { produced: [{ seq: 1, path: 'a.ts' }] } : undefined } },
|
||||
seq: 1,
|
||||
})).toEqual(['a.ts'])
|
||||
|
||||
// Editor tab disabled: even a produced turn falls back to the default
|
||||
// deliverables row (chips that cannot open must not be offered).
|
||||
store.setPrefs({ ...store.getPrefs(), tabsEnabled: { editor: false } })
|
||||
expect(select(producedOwner(['a.ts']))).toBeNull()
|
||||
|
||||
restore()
|
||||
})
|
||||
|
||||
it('wires the openInSidebar and onShowInFolder seats', () => {
|
||||
const fake = fakeSlots(true)
|
||||
const ctx = clientCtx(fake.slots)
|
||||
const store = createSidebarStore()
|
||||
const restore = registerTurnTailInterception(ctx, store)
|
||||
const inject = fake.registered[0]!.options.inject as (sessionId: string) => {
|
||||
openInSidebar: (path: string) => void
|
||||
onShowInFolder: (files: readonly string[]) => void
|
||||
}
|
||||
|
||||
// The seat hands the session-scoped opener to the chips row.
|
||||
const seat = inject('s1')
|
||||
expect(seat.openInSidebar).toBeTypeOf('function')
|
||||
seat.openInSidebar('/w/src/a.ts')
|
||||
expect(ctx.betterSidebar.openTab).toHaveBeenCalledWith({
|
||||
type: 'editor',
|
||||
title: 'a.ts',
|
||||
path: '/w/src/a.ts',
|
||||
id: 'editor:/w/src/a.ts',
|
||||
})
|
||||
|
||||
// The show-in-folder seat reveals the produced files in the files window
|
||||
// (the editor home tab) — the panel expands and the rows highlight.
|
||||
expect(seat.onShowInFolder).toBeTypeOf('function')
|
||||
seat.onShowInFolder(['/w/src/a.ts'])
|
||||
expect(ctx.betterSidebar.openTab).toHaveBeenLastCalledWith(expect.objectContaining({
|
||||
type: 'editor',
|
||||
}))
|
||||
|
||||
restore()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user