mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-30 06:17:06 +00:00
fix(chat): dismiss Codex plan actions when continuing planning
This commit is contained in:
@@ -26,22 +26,48 @@ function fixture(overrides: Partial<HappyChatContextValue> = {}) {
|
||||
tool: { id: 'plan', name: 'ExitPlanMode', input: { plan: '# Durable proposal' }, state: 'completed',
|
||||
createdAt: 1, startedAt: 1, completedAt: 2, execStartedAt: null, execCompletedAt: null, description: null, result: null }
|
||||
}
|
||||
let cardMount = 0
|
||||
const ui = () => <HappyChatProvider value={{ ...ctx }}>
|
||||
<ToolCard block={block} api={ctx.api} sessionId={ctx.sessionId} metadata={ctx.metadata}
|
||||
<ToolCard key={`${block.id}:${cardMount}`} block={{ ...block, tool: { ...block.tool } }} api={ctx.api} sessionId={ctx.sessionId} metadata={ctx.metadata}
|
||||
disabled={ctx.disabled} onDone={ctx.onRefresh} terminalToolDisplayMode="compact" />
|
||||
</HappyChatProvider>
|
||||
const view = render(ui())
|
||||
return { ctx, implement, continued, refresh, rerender: () => view.rerender(ui()) }
|
||||
return {
|
||||
ctx, block, implement, continued, refresh,
|
||||
remount: () => { cardMount++; view.rerender(ui()) },
|
||||
rerender: () => view.rerender(ui())
|
||||
}
|
||||
}
|
||||
|
||||
describe('shared Codex plan card', () => {
|
||||
it('offers execution and composer focus without creating an approval request', () => {
|
||||
it('dismisses actions and focuses the composer without creating an approval request', () => {
|
||||
const f = fixture()
|
||||
expect(screen.getByText('# Durable proposal')).toBeInTheDocument()
|
||||
expect(screen.queryByText('tool.waitingForApproval')).not.toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'tool.plan.continue' }))
|
||||
expect(f.continued).toHaveBeenCalledOnce()
|
||||
expect(f.implement).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('button', { name: 'tool.plan.continue' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'tool.plan.implement' })).not.toBeInTheDocument()
|
||||
expect(screen.getByText('# Durable proposal')).toBeInTheDocument()
|
||||
// Recycling the card and a stale live proposal must not revive the menu.
|
||||
f.remount()
|
||||
f.ctx.codexPlanProposalId = null
|
||||
f.rerender()
|
||||
f.ctx.codexPlanProposalId = 'plan'
|
||||
f.rerender()
|
||||
expect(screen.queryByRole('button', { name: 'tool.plan.continue' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('offers actions for a new proposal after continuing the previous one', () => {
|
||||
const f = fixture()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'tool.plan.continue' }))
|
||||
f.ctx.codexPlanProposalId = 'new-plan'
|
||||
f.block.id = 'new-plan'
|
||||
f.block.tool.id = 'new-plan'
|
||||
f.rerender()
|
||||
expect(screen.getByRole('button', { name: 'tool.plan.continue' })).toBeEnabled()
|
||||
expect(screen.getByRole('button', { name: 'tool.plan.implement' })).toBeEnabled()
|
||||
})
|
||||
|
||||
it('submits once and keeps pending feedback while the native action removes the available id', async () => {
|
||||
@@ -71,6 +97,16 @@ describe('shared Codex plan card', () => {
|
||||
expect(f.implement).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('dismisses an earlier implementation error along with the actions', async () => {
|
||||
const f = fixture()
|
||||
f.implement.mockRejectedValue(new Error('Try again'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'tool.plan.implement' }))
|
||||
await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Try again'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'tool.plan.continue' }))
|
||||
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'tool.plan.implement' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([null, 'child-plan', 'newer-plan'])('keeps historical plans read-only when the current id is %s', codexPlanProposalId => {
|
||||
fixture({ codexPlanProposalId })
|
||||
expect(screen.getByText('# Durable proposal')).toBeInTheDocument()
|
||||
|
||||
@@ -13,7 +13,7 @@ export function CodexPlanFooter(props: { planId: string }) {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const available = ctx?.metadata?.flavor === 'codex' && ctx.codexPlanProposalId === props.planId
|
||||
|
||||
if (!ctx || (!available && !pending && !error)) return null
|
||||
if (!ctx || ctx.continuedPlanIds?.has(props.planId) || (!available && !pending && !error)) return null
|
||||
|
||||
const implement = async () => {
|
||||
if (!available || ctx.disabled || inFlight.current) return
|
||||
@@ -41,7 +41,7 @@ export function CodexPlanFooter(props: { planId: string }) {
|
||||
{t('tool.plan.implement')}
|
||||
</Button>
|
||||
{ctx.onContinuePlan ? (
|
||||
<Button size="sm" variant="outline" disabled={!available || ctx.disabled || pending} onClick={ctx.onContinuePlan}>
|
||||
<Button size="sm" variant="outline" disabled={!available || ctx.disabled || pending} onClick={() => ctx.onContinuePlan?.(props.planId)}>
|
||||
{t('tool.plan.continue')}
|
||||
</Button>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user