feat(gui): goal wire domain, client goal state, and docked goal bar
- apiproxy goals RPC domain (get/create/edit/pause/resume/complete/clear) with CAS refs, zod schemas, and fetch client/handler wiring - client runtime session goal state: live goal/change meta triggers a coalesced refetch; mutations fold transport errors into RpcResult - web GoalBar: docked strip above the composer (sparkle, phase label, truncated objective, inline edit, clear; resume when paused); creation stays on the /goal command - GoalBarActions in the ui-conversation contract layer; IconSparkle16 moves to ui-primitives icons
This commit is contained in:
@@ -39,7 +39,7 @@ function snapshotBase(): ConversationSnapshot {
|
||||
return {
|
||||
sessionId: ROOT, nodes: [], foldDegraded: false, partial: null, runningCalls: [],
|
||||
pending: [], running: false, removed: false, openState: 'open', openError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null, goal: undefined,
|
||||
} as ConversationSnapshot
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ function snapshotBase(): ConversationSnapshot {
|
||||
sessionId: SID, nodes: [], foldDegraded: false, partial: null, runningCalls: [],
|
||||
pending: [], running: false, removed: false, openState: 'open', openError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null,
|
||||
goal: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ function snapshotBase(): ConversationSnapshot {
|
||||
sessionId: SID, nodes: [], foldDegraded: false, partial: null, runningCalls: [],
|
||||
pending: [], running: false, removed: false, openState: 'open', openError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null,
|
||||
goal: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ function snapshotBase(): ConversationSnapshot {
|
||||
return {
|
||||
sessionId: SID, nodes: [], foldDegraded: false, partial: null, runningCalls: [],
|
||||
pending: [], running: false, removed: false, openState: 'open', openError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null, goal: undefined,
|
||||
} as ConversationSnapshot
|
||||
}
|
||||
|
||||
|
||||
116
packages/client/ui-conversation/tests/goalbar.spec.tsx
Normal file
116
packages/client/ui-conversation/tests/goalbar.spec.tsx
Normal file
@@ -0,0 +1,116 @@
|
||||
// @vitest-environment jsdom
|
||||
// GoalBar behavior: the docked strip above the composer — phase labels,
|
||||
// inline edit form, and resume/clear icon actions — driven purely through
|
||||
// props, no wire. Loading, absent, and complete goals render nothing.
|
||||
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { GoalView } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { GoalBar } from '../src/client/skeleton/GoalBar.tsx'
|
||||
import type { GoalBarActions } from '../src/client/contract/slots.ts'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
function makeGoal(over: Partial<GoalView> = {}): GoalView {
|
||||
return {
|
||||
id: 'g1' as GoalView['id'],
|
||||
revision: 1,
|
||||
objective: 'Ship the redesign',
|
||||
phase: 'active',
|
||||
maxGoalRounds: 4,
|
||||
roundsStarted: 1,
|
||||
createdAt: 1,
|
||||
updatedAt: 2,
|
||||
activation: 'armed',
|
||||
...over,
|
||||
}
|
||||
}
|
||||
|
||||
function makeActions(): { [K in keyof GoalBarActions]: ReturnType<typeof vi.fn<GoalBarActions[K]>> } {
|
||||
return {
|
||||
onEdit: vi.fn<GoalBarActions['onEdit']>(),
|
||||
onResume: vi.fn<GoalBarActions['onResume']>(),
|
||||
onClear: vi.fn<GoalBarActions['onClear']>(),
|
||||
}
|
||||
}
|
||||
|
||||
describe('GoalBar', () => {
|
||||
it('renders nothing while loading, absent, or when the goal is complete', () => {
|
||||
const actions = makeActions()
|
||||
const loading = render(<GoalBar goal={undefined} {...actions} />)
|
||||
expect(loading.container.firstChild).toBeNull()
|
||||
cleanup()
|
||||
|
||||
const absent = render(<GoalBar goal={null} {...actions} />)
|
||||
expect(absent.container.firstChild).toBeNull()
|
||||
cleanup()
|
||||
|
||||
const complete = render(<GoalBar goal={makeGoal({ phase: 'complete' })} {...actions} />)
|
||||
expect(complete.container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('active goal: sparkle, "Ongoing Goal", truncated objective, edit and clear actions', () => {
|
||||
const actions = makeActions()
|
||||
render(<GoalBar goal={makeGoal()} {...actions} />)
|
||||
expect(screen.getByText('Ongoing Goal')).toBeTruthy()
|
||||
expect(screen.getByText('Ship the redesign')).toBeTruthy()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Clear goal' }))
|
||||
expect(actions.onClear).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('edit swaps the strip for a prefilled form; Enter saves, empty stays disabled', () => {
|
||||
const actions = makeActions()
|
||||
render(<GoalBar goal={makeGoal()} {...actions} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit goal' }))
|
||||
const box = screen.getByRole('textbox', { name: 'Goal objective' })
|
||||
expect((box as HTMLInputElement).value).toBe('Ship the redesign')
|
||||
|
||||
fireEvent.change(box, { target: { value: ' ' } })
|
||||
expect((screen.getByRole('button', { name: 'Save goal' }) as HTMLButtonElement).disabled).toBe(true)
|
||||
|
||||
fireEvent.change(box, { target: { value: 'Ship v2' } })
|
||||
fireEvent.keyDown(box, { key: 'Enter' })
|
||||
expect(actions.onEdit).toHaveBeenCalledWith('Ship v2')
|
||||
expect(screen.getByText('Ongoing Goal')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('Esc cancels the edit without calling onEdit', () => {
|
||||
const actions = makeActions()
|
||||
render(<GoalBar goal={makeGoal()} {...actions} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit goal' }))
|
||||
fireEvent.keyDown(screen.getByRole('textbox', { name: 'Goal objective' }), { key: 'Escape' })
|
||||
expect(actions.onEdit).not.toHaveBeenCalled()
|
||||
expect(screen.getByText('Ongoing Goal')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('paused goal: "Paused Goal" with a resume action before edit', () => {
|
||||
const actions = makeActions()
|
||||
render(<GoalBar goal={makeGoal({ phase: 'paused' })} {...actions} />)
|
||||
expect(screen.getByText('Paused Goal')).toBeTruthy()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Resume goal' }))
|
||||
expect(actions.onResume).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('a new goal identity drops the edit form (no stale draft over the new goal)', () => {
|
||||
const actions = makeActions()
|
||||
const { rerender } = render(<GoalBar goal={makeGoal()} {...actions} />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Edit goal' }))
|
||||
fireEvent.change(screen.getByRole('textbox', { name: 'Goal objective' }), { target: { value: 'stale draft' } })
|
||||
|
||||
rerender(<GoalBar goal={makeGoal({ id: 'g2' as GoalView['id'], objective: 'New goal' })} {...actions} />)
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
expect(screen.getByText('Ongoing Goal')).toBeTruthy()
|
||||
expect(screen.getByText('New goal')).toBeTruthy()
|
||||
|
||||
rerender(<GoalBar goal={null} {...actions} />)
|
||||
expect(screen.queryByText('Ongoing Goal')).toBeNull()
|
||||
})
|
||||
|
||||
it('blocked goal: "Blocked Goal" with the block reason as the strip tooltip', () => {
|
||||
const actions = makeActions()
|
||||
const goal = makeGoal({ phase: 'blocked', blockedReason: { code: 'stalled', message: 'No progress in 3 rounds' } })
|
||||
render(<GoalBar goal={goal} {...actions} />)
|
||||
expect(screen.getByText('Blocked Goal')).toBeTruthy()
|
||||
expect(screen.getByText('Blocked Goal').closest('[title]')?.getAttribute('title')).toBe('No progress in 3 rounds')
|
||||
})
|
||||
})
|
||||
@@ -20,7 +20,7 @@ function snapshotBase(): ConversationSnapshot {
|
||||
return {
|
||||
sessionId: SID, nodes: [], foldDegraded: false, partial: null, runningCalls: [],
|
||||
pending: [], running: false, removed: false, openState: 'open', openError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null,
|
||||
hasMore: false, loadingOlder: false, promptError: null, lastAgentError: null, goal: undefined,
|
||||
} as ConversationSnapshot
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,92 @@ describe('ConversationRoot', () => {
|
||||
fireEvent.keyDown(box, { key: 'Enter' })
|
||||
expect(send).toHaveBeenCalledWith('queue')
|
||||
})
|
||||
|
||||
it('renders GoalBar when goalActions and an active goal are provided', () => {
|
||||
const goal = {
|
||||
id: 'g1' as never,
|
||||
revision: 1,
|
||||
objective: 'test-objective',
|
||||
phase: 'active' as const,
|
||||
maxGoalRounds: 256,
|
||||
roundsStarted: 0,
|
||||
createdAt: 100,
|
||||
updatedAt: 100,
|
||||
activation: 'armed' as const,
|
||||
}
|
||||
const store = createSnapshotStore<FakeSnapshot & { goal: typeof goal }>({
|
||||
nodes: [], runningCalls: [], running: false, removed: false, promptError: null, goal,
|
||||
})
|
||||
const useSession = bindSnapshotSelector(store) as unknown as UseSession
|
||||
const activeStore = createSnapshotStore<string | undefined>('chat')
|
||||
const views = [view('chat', 'Chat')]
|
||||
render(
|
||||
<ConversationRoot
|
||||
sessionId={sid('s1')}
|
||||
useSession={useSession}
|
||||
useAncestry={() => []}
|
||||
views={{
|
||||
list: () => views,
|
||||
subscribe: () => () => {},
|
||||
version: () => 1,
|
||||
}}
|
||||
useActiveView={() => activeStore.useSelector(s => s) as ViewId | undefined}
|
||||
composer={{
|
||||
useDraft: () => '',
|
||||
setDraft: () => {},
|
||||
send: () => {},
|
||||
stop: () => {},
|
||||
}}
|
||||
actions={{ openView: vi.fn() as (v: never) => void, open: vi.fn() }}
|
||||
renderView={() => null}
|
||||
goalActions={{
|
||||
onEdit: vi.fn(),
|
||||
onResume: vi.fn(),
|
||||
onClear: vi.fn(),
|
||||
}}
|
||||
/>)
|
||||
expect(screen.getByText('Ongoing Goal')).toBeTruthy()
|
||||
expect(screen.getByText('test-objective')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides GoalBar when goalActions is undefined (even with an active goal in the store)', () => {
|
||||
const goal = {
|
||||
id: 'g1' as never,
|
||||
revision: 1,
|
||||
objective: 'test-objective',
|
||||
phase: 'active' as const,
|
||||
maxGoalRounds: 256,
|
||||
roundsStarted: 0,
|
||||
createdAt: 100,
|
||||
updatedAt: 100,
|
||||
activation: 'armed' as const,
|
||||
}
|
||||
const store = createSnapshotStore<FakeSnapshot & { goal: typeof goal }>({
|
||||
nodes: [], runningCalls: [], running: false, removed: false, promptError: null, goal,
|
||||
})
|
||||
const useSession = bindSnapshotSelector(store) as unknown as UseSession
|
||||
render(
|
||||
<ConversationRoot
|
||||
sessionId={sid('s1')}
|
||||
useSession={useSession}
|
||||
useAncestry={() => []}
|
||||
views={{
|
||||
list: () => [],
|
||||
subscribe: () => () => {},
|
||||
version: () => 1,
|
||||
}}
|
||||
useActiveView={() => 'chat' as ViewId}
|
||||
composer={{
|
||||
useDraft: () => '',
|
||||
setDraft: () => {},
|
||||
send: () => {},
|
||||
stop: () => {},
|
||||
}}
|
||||
actions={{ openView: vi.fn() as (v: never) => void, open: vi.fn() }}
|
||||
renderView={() => null}
|
||||
/>)
|
||||
expect(screen.queryByText('Ongoing Goal')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('DetailsPanel', () => {
|
||||
|
||||
Reference in New Issue
Block a user