mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
fix(cloud): Set up once cancel and the refusal gap (design-squad P1)
- Escape after "Set up once": the clicked button is replaced by the paste step, which dropped focus to the page, and Escape only listens inside the strip, so the attempt stayed open. The strip now keeps focus when its focused control goes away, so Escape (and the x) cancels and the strip returns to "Set up once". Main already kills the CLI and goes idle; tested both sides. - After a refusal, until the CLI shows its fresh link, the field and "Open again" stay in place, disabled, with the detail visible, instead of disappearing. Fixture notSetUpBrowserCodeGapNarrow.
This commit is contained in:
@@ -235,6 +235,24 @@ describe('service: the code from the strip, Settings or the chat UI', () => {
|
||||
expect(service.setups().claude).toMatchObject({ phase: 'browser', canReopen: false })
|
||||
})
|
||||
|
||||
it('Cancel ends the attempt: the CLI is killed and setup goes back to idle, even mid-paste', async () => {
|
||||
const { service, children, broadcasts } = setup()
|
||||
service.start('claude')
|
||||
await tick()
|
||||
children[0]!.emit(`${AUTHORIZE}\n${PROMPT}`)
|
||||
service.submitClaudeCode(CODE)
|
||||
await service.cancel('claude')
|
||||
await tick()
|
||||
expect(children[0]!.kill).toHaveBeenCalled()
|
||||
expect(service.setups().claude).toEqual({ phase: 'idle' })
|
||||
expect(broadcasts.at(-1)?.claude).toEqual({ phase: 'idle' })
|
||||
// Nothing the dead run says afterwards brings the paste state back.
|
||||
children[0]!.emit(`${AUTHORIZE}\n${PROMPT}`)
|
||||
children[0]!.exit()
|
||||
await tick()
|
||||
expect(service.setups().claude).toEqual({ phase: 'idle' })
|
||||
})
|
||||
|
||||
it('the 10-minute timeout also ends as expired, not a silent spin', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
|
||||
@@ -237,3 +237,8 @@ export const notSetUpBrowserCodeRejectedNarrow = fixture({
|
||||
},
|
||||
width: 420
|
||||
})
|
||||
/** The moment after a refusal, before the fresh link: field and "Open again" stay, disabled. */
|
||||
export const notSetUpBrowserCodeGapNarrow = fixture({
|
||||
setUp: { setup: { phase: 'browser', startedAt: 0, canReopen: false, code: 'rejected' } },
|
||||
width: 420
|
||||
})
|
||||
|
||||
@@ -147,6 +147,15 @@ export function CloudAgentSignInStrip({
|
||||
wrap?: boolean
|
||||
}): React.JSX.Element {
|
||||
const sectionRef = useRef<HTMLElement | null>(null)
|
||||
// The strip had focus and its focused control went away with a state change ("Set up once" becomes
|
||||
// the paste step): focus stays on the strip, so Escape still cancels (it only listens inside).
|
||||
const focusInside = useRef(false)
|
||||
useLayoutEffect(() => {
|
||||
const section = sectionRef.current
|
||||
if (focusInside.current && section && document.activeElement === document.body) {
|
||||
section.focus({ preventScroll: true })
|
||||
}
|
||||
})
|
||||
const width = useLiveStripWidth(sectionRef, initialWidth)
|
||||
const compact = width === 'compact'
|
||||
// The detail leaves the line when there's no room for it beside the title: below 360 px, and on the
|
||||
@@ -174,6 +183,15 @@ export function CloudAgentSignInStrip({
|
||||
aria-labelledby={titleId}
|
||||
aria-describedby={detailId}
|
||||
tabIndex={-1}
|
||||
onFocus={() => {
|
||||
focusInside.current = true
|
||||
}}
|
||||
onBlur={(event) => {
|
||||
// A control removed under focus blurs with no next target: the strip keeps the focus.
|
||||
if (event.relatedTarget !== null && !event.currentTarget.contains(event.relatedTarget)) {
|
||||
focusInside.current = false
|
||||
}
|
||||
}}
|
||||
data-cloud-sign-in-strip
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Escape') {
|
||||
@@ -321,7 +339,10 @@ export function CloudAgentSignInStrip({
|
||||
</div>
|
||||
{stacked && setupCode ? (
|
||||
// Row 2, under the text: [Paste code ……] [Finish setup] then "Open again" as a quiet button.
|
||||
<div data-strip-code-row className="col-span-2 col-start-2 flex min-w-0 flex-wrap items-center gap-1.5">
|
||||
<div
|
||||
data-strip-code-row
|
||||
className="col-span-2 col-start-2 flex min-w-0 flex-wrap items-center gap-1.5"
|
||||
>
|
||||
<div className="min-w-0 flex-1 basis-56">
|
||||
<CloudStripPasteForm
|
||||
fill
|
||||
@@ -335,7 +356,12 @@ export function CloudAgentSignInStrip({
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
onClick={() => (model.primary ? actions.primary(model.primary.action) : undefined)}
|
||||
aria-disabled={model.primary.busy || undefined}
|
||||
onClick={() =>
|
||||
model.primary && !model.primary.busy
|
||||
? actions.primary(model.primary.action)
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{model.primary.label}
|
||||
</Button>
|
||||
|
||||
@@ -30,7 +30,7 @@ export function CloudStripPasteForm({
|
||||
const [code, setCode] = useState('')
|
||||
const inputRef = useRef<HTMLInputElement | null>(null)
|
||||
const setupCode = paste.setupCode
|
||||
const busy = paste.submitting
|
||||
const busy = paste.submitting || paste.disabled === true
|
||||
// A refused code: the field is already empty; keep the person's place in it.
|
||||
useEffect(() => {
|
||||
if (paste.refusal) {
|
||||
@@ -79,11 +79,7 @@ export function CloudStripPasteForm({
|
||||
}
|
||||
}}
|
||||
variant="code"
|
||||
className={cn(
|
||||
'h-7 min-w-0',
|
||||
setupCode && !fill && 'w-40',
|
||||
fill && 'flex-1'
|
||||
)}
|
||||
className={cn('h-7 min-w-0', setupCode && !fill && 'w-40', fill && 'flex-1')}
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
|
||||
@@ -30,7 +30,9 @@ function base(agent: string, t: Translate): CloudStripModel {
|
||||
export function setupCodePaste(
|
||||
agent: HostAgentSignInAgent,
|
||||
code: 'checking' | 'rejected' | undefined,
|
||||
t: Translate
|
||||
t: Translate,
|
||||
/** The CLI hasn't shown the fresh link yet: the field shows, disabled. */
|
||||
options: { waiting?: boolean } = {}
|
||||
): NonNullable<CloudStripModel['paste']> {
|
||||
const name = HOST_AGENT_SIGN_IN_AGENT_NAME[agent]
|
||||
return {
|
||||
@@ -45,6 +47,7 @@ export function setupCodePaste(
|
||||
secretLabel: t('agentSignInStrip.setupCodeLabel', 'Code from {{agent}}’s sign-in page', {
|
||||
agent: name
|
||||
}),
|
||||
...(options.waiting ? { disabled: true } : {}),
|
||||
setupCode: {
|
||||
placeholder: t('agentSignInStrip.setupCodePlaceholder', 'Paste code'),
|
||||
submitLabel:
|
||||
@@ -117,13 +120,20 @@ export function cloudAgentSetupStripModel(args: {
|
||||
)
|
||||
: t('agentSignInStrip.finishInBrowser', 'Finish in your browser'),
|
||||
// Claude's page shows a code to bring back: [Paste code] [Finish setup] [Open again].
|
||||
paste: setup.acceptsCode ? setupCodePaste(args.agent, setup.code, t) : null,
|
||||
primary: setup.canReopen
|
||||
? {
|
||||
label: t('agentSignInStrip.openAgain', 'Open again'),
|
||||
action: { kind: 'reopenSetup' }
|
||||
}
|
||||
: null,
|
||||
// After a refusal the CLI takes a moment to show a fresh link: the field and "Open again" stay
|
||||
// in place, disabled, so nothing actionable disappears (design-squad).
|
||||
paste:
|
||||
setup.acceptsCode || setup.code === 'rejected'
|
||||
? setupCodePaste(args.agent, setup.code, t, { waiting: !setup.acceptsCode })
|
||||
: null,
|
||||
primary:
|
||||
setup.canReopen || setup.code === 'rejected'
|
||||
? {
|
||||
label: t('agentSignInStrip.openAgain', 'Open again'),
|
||||
action: { kind: 'reopenSetup' },
|
||||
...(setup.canReopen ? {} : { busy: true })
|
||||
}
|
||||
: null,
|
||||
announcement: t(
|
||||
'agentSignInStrip.waitingAnnounce',
|
||||
'Waiting for you to approve in your browser.'
|
||||
|
||||
@@ -48,6 +48,8 @@ export type CloudStripModel = {
|
||||
* once sent, and sent on its own when a whole code is pasted.
|
||||
*/
|
||||
setupCode?: { placeholder: string; submitLabel: string }
|
||||
/** Shown but not usable yet (the fresh sign-in link is on its way). */
|
||||
disabled?: boolean
|
||||
} | null
|
||||
/** "Other ways" under ⋯: the code fallback and the key path. */
|
||||
otherWays: boolean
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// @vitest-environment happy-dom
|
||||
// Set up once → Escape: the "Set up once" button is replaced by the paste step, so focus must stay on
|
||||
// the strip for Escape (which only listens inside it) to cancel the attempt. Also the refusal gap:
|
||||
// the field and "Open again" stay in place, disabled, until the fresh link arrives.
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import type { Translate } from '@/i18n/use-translate'
|
||||
import { CloudAgentSignInStrip, type CloudStripActions } from './CloudAgentSignInStrip'
|
||||
import { cloudAgentSetupStripModel } from './cloud-agent-setup-strip-model'
|
||||
import type { OrcaCloudAgentSetup } from '../../../../shared/orca-cloud-agents/orca-cloud-agents-wire'
|
||||
|
||||
const t: Translate = (_key, fallback, options) =>
|
||||
fallback.replace(/\{\{(\w+)\}\}/g, (_m, name: string) => String(options?.[name] ?? ''))
|
||||
|
||||
function actions(): CloudStripActions & { cancel: ReturnType<typeof vi.fn> } {
|
||||
return {
|
||||
primary: vi.fn(),
|
||||
submitCode: vi.fn(),
|
||||
submitSetupCode: vi.fn(),
|
||||
useCode: vi.fn(),
|
||||
pasteCode: vi.fn(),
|
||||
useApiKey: vi.fn(),
|
||||
cancel: vi.fn()
|
||||
}
|
||||
}
|
||||
|
||||
const strip = (setup: OrcaCloudAgentSetup, a: CloudStripActions) => (
|
||||
<TooltipProvider>
|
||||
<CloudAgentSignInStrip
|
||||
model={cloudAgentSetupStripModel({ agent: 'claude', setup, ready: false, t })}
|
||||
prompt={null}
|
||||
width="wide"
|
||||
actions={a}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
)
|
||||
|
||||
afterEach(() => cleanup())
|
||||
|
||||
describe('the setup strip', () => {
|
||||
it('keeps focus when "Set up once" turns into the paste step, so Escape cancels the attempt', () => {
|
||||
const a = actions()
|
||||
const view = render(strip({ phase: 'idle' }, a))
|
||||
const setUp = screen.getByRole('button', { name: 'Set up once' })
|
||||
setUp.focus()
|
||||
view.rerender(strip({ phase: 'browser', startedAt: 0, canReopen: false }, a))
|
||||
const region = screen.getByRole('region')
|
||||
expect(region.contains(document.activeElement)).toBe(true)
|
||||
fireEvent.keyDown(document.activeElement!, { key: 'Escape' })
|
||||
expect(a.cancel).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('in the gap after a refusal, the field and "Open again" stay, disabled', () => {
|
||||
const a = actions()
|
||||
render(strip({ phase: 'browser', startedAt: 0, canReopen: false, code: 'rejected' }, a))
|
||||
const field = screen.getByLabelText('Code from Claude’s sign-in page')
|
||||
expect(field).toHaveProperty('disabled', true)
|
||||
const openAgain = screen.getByRole('button', { name: 'Open again' })
|
||||
expect(openAgain.getAttribute('aria-disabled')).toBe('true')
|
||||
fireEvent.click(openAgain)
|
||||
expect(a.primary).not.toHaveBeenCalled()
|
||||
expect(
|
||||
screen.getByText('Paste the newest code from the sign-in page, or open it again.')
|
||||
).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -187,10 +187,10 @@ export function SetupRow({
|
||||
}
|
||||
>
|
||||
{/* Line 2 (design-squad): [Paste code ………] [Finish setup], the field filling the column. */}
|
||||
{setup.acceptsCode ? (
|
||||
{setup.acceptsCode || setup.code === 'rejected' ? (
|
||||
<CloudStripPasteForm
|
||||
fill
|
||||
paste={setupCodePaste(agent, setup.code, t)}
|
||||
paste={setupCodePaste(agent, setup.code, t, { waiting: !setup.acceptsCode })}
|
||||
onSubmitCode={() => undefined}
|
||||
onSubmitSetupCode={(code) => actions.submitSetupCode?.(code)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user