feat(multi-run): always run fusions in a new worktree

This commit is contained in:
Chris Scott committed 2026-10-07 13:12:25 -04:00
1 parent 30783c49ec
commit ec96ac0d55
9 files changed
+69 -210

No files matched your search

+34 -89
View File
@@ -1,4 +1,4 @@
import { useId, useState, type ReactNode } from 'react'
import { useId, useState } from 'react'
import { ArrowRight, ArrowUpRight, Combine, Loader2 } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Label } from '@/components/ui/label'
@@ -15,7 +15,6 @@ import {
export interface FusionComposerSubmission {
model: string
isolate: boolean
baseRef: string
instructions: string
}
@@ -50,85 +49,54 @@ export function FusionComposer({
onOpenSession,
}: FusionComposerProps) {
const optionsId = useId()
const destinationLabelId = useId()
const [model, setModel] = useState('')
const [isolate, setIsolate] = useState(true)
const [baseRef, setBaseRef] = useState(run.baseRef ?? '')
const [instructions, setInstructions] = useState('')
const [optionsOpen, setOptionsOpen] = useState(false)
const requiresIsolation = run.entries.some((entry) => selectedEntryIds.includes(entry.id) && !entry.isolated)
const effectiveIsolate = requiresIsolation || isolate
const totalEntries = run.entries.filter((entry) => entry.status !== 'discarded').length
const canSubmit = selectedEntryIds.length >= MULTI_RUN_FUSION_MIN_SOURCES && model !== '' && !isPending
const handleSubmit = () => {
if (!canSubmit) return
onSubmit({ model, isolate: effectiveIsolate, baseRef: effectiveIsolate ? baseRef : '', instructions: instructions.trim() })
onSubmit({ model, baseRef, instructions: instructions.trim() })
}
return (
<div className="shrink-0 space-y-3 border-t border-border bg-background px-4 pt-3 pb-[calc(env(safe-area-inset-bottom)+0.75rem)]">
<div id={optionsId} className={cn('space-y-3', !optionsOpen && 'hidden sm:block')}>
<div className="grid gap-3 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end">
<div className="space-y-1.5">
<Label htmlFor="fusion-model">Synthesis model</Label>
<ModelCombobox
id="fusion-model"
ariaLabel="Synthesis model"
value={model}
onChange={setModel}
directory={directory}
placeholder="Select a model"
allowCustomValue={false}
emptyMeansDefault={false}
<div className="space-y-1.5">
<Label htmlFor="fusion-model">Synthesis model</Label>
<ModelCombobox
id="fusion-model"
ariaLabel="Synthesis model"
value={model}
onChange={setModel}
directory={directory}
placeholder="Select a model"
allowCustomValue={false}
emptyMeansDefault={false}
listClassName={UPWARD_LIST_CLASS}
/>
</div>
<div className="flex items-center gap-3">
<Label htmlFor="fusion-base-ref" className="shrink-0">
Base ref
</Label>
<div className="min-w-0 flex-1">
<BranchCombobox
id="fusion-base-ref"
repoId={repoId}
value={baseRef}
onValueChange={setBaseRef}
placeholder="Current HEAD"
clearable
listClassName={UPWARD_LIST_CLASS}
/>
</div>
<div className="space-y-1.5">
<span id={destinationLabelId} className="text-sm font-medium leading-none">
Destination
</span>
<div
role="radiogroup"
aria-labelledby={destinationLabelId}
className="grid grid-cols-2 gap-1 rounded-md border border-border bg-muted/40 p-1"
>
<DestinationOption checked={effectiveIsolate} onSelect={() => setIsolate(true)}>
Isolated
</DestinationOption>
<DestinationOption checked={!effectiveIsolate} disabled={requiresIsolation} onSelect={() => setIsolate(false)}>
Repository checkout
</DestinationOption>
</div>
</div>
</div>
{requiresIsolation ? (
<p className="text-xs text-muted-foreground">
Isolation is required because a selected result ran in the repository checkout.
</p>
) : null}
{effectiveIsolate ? (
<div className="flex items-center gap-3">
<Label htmlFor="fusion-base-ref" className="shrink-0">
Base ref
</Label>
<div className="min-w-0 flex-1">
<BranchCombobox
id="fusion-base-ref"
repoId={repoId}
value={baseRef}
onValueChange={setBaseRef}
placeholder="Current HEAD"
clearable
listClassName={UPWARD_LIST_CLASS}
/>
</div>
</div>
) : null}
<details className="group rounded-md border border-border">
<summary className="cursor-pointer select-none px-3 py-2 text-sm font-medium">Instructions (optional)</summary>
<div className="px-3 pb-3">
@@ -153,10 +121,12 @@ export function FusionComposer({
</span>
<span className="sm:hidden">
{' '}
<ArrowRight className="inline h-3 w-3" aria-hidden="true" /> {model || 'no model'} ·{' '}
{effectiveIsolate ? 'isolated' : 'repository checkout'}
<ArrowRight className="inline h-3 w-3" aria-hidden="true" /> {model || 'no model'} · new worktree
</span>
<span className="hidden sm:inline">
{' '}
· runs in a new worktree; blank base ref uses the current HEAD; sources are never modified.
</span>
<span className="hidden sm:inline"> · blank base ref uses the current HEAD; sources are never modified.</span>
</p>
<div className="grid grid-cols-2 gap-2 sm:flex sm:shrink-0">
<Button
@@ -181,31 +151,6 @@ export function FusionComposer({
)
}
interface DestinationOptionProps {
checked: boolean
disabled?: boolean
onSelect: () => void
children: ReactNode
}
function DestinationOption({ checked, disabled, onSelect, children }: DestinationOptionProps) {
return (
<button
type="button"
role="radio"
aria-checked={checked}
disabled={disabled}
onClick={onSelect}
className={cn(
'min-h-9 rounded-sm px-3 py-1.5 text-sm font-medium leading-tight transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
checked ? 'bg-background text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground',
)}
>
{children}
</button>
)
}
interface ComposerErrorProps {
error: unknown
run: MultiRun
@@ -575,7 +575,7 @@ describe('MultiRunSheet', () => {
expect(submit).toBeEnabled()
})
it('submits the selected sources, model, instructions and isolated destination', async () => {
it('submits the selected sources, model, instructions and base ref', async () => {
const user = userEvent.setup()
mocks.fuseMultiRun.mockResolvedValue(fuseRun)
renderSheet()
@@ -593,28 +593,11 @@ describe('MultiRunSheet', () => {
entryIds: [11, 13],
model: 'openai/gpt-4o',
instructions: 'Merge the best ideas',
isolate: true,
baseRef: 'main',
})
})
it('runs in the repository checkout without a base ref when chosen', async () => {
const user = userEvent.setup()
mocks.fuseMultiRun.mockResolvedValue(fuseRun)
renderSheet()
await selectSourcesAndModel(user)
await user.click(screen.getByRole('radio', { name: 'Repository checkout' }))
expect(screen.queryByRole('combobox', { name: 'Base ref' })).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: /start fusion/i }))
await waitFor(() => expect(mocks.fuseMultiRun).toHaveBeenCalledTimes(1))
const [, request] = mocks.fuseMultiRun.mock.calls[0] as [number, FuseMultiRunRequest]
expect(request).toMatchObject({ isolate: false })
expect(request).not.toHaveProperty('baseRef')
})
it('forces isolation when a selected source ran in the repository checkout', async () => {
it('always runs the fusion in a new worktree without a destination choice', async () => {
const user = userEvent.setup()
mocks.listMultiRuns.mockResolvedValue([
{ ...fuseRun, entries: fuseRun.entries.map((item) => (item.id === 11 ? { ...item, isolated: false } : item)) },
@@ -623,11 +606,8 @@ describe('MultiRunSheet', () => {
await selectSourcesAndModel(user)
expect(screen.getByRole('radio', { name: 'Repository checkout' })).toBeDisabled()
expect(screen.getByRole('radio', { name: 'Isolated' })).toHaveAttribute('aria-checked', 'true')
expect(
screen.getByText('Isolation is required because a selected result ran in the repository checkout.'),
).toBeInTheDocument()
expect(screen.queryByRole('radio', { name: 'Repository checkout' })).not.toBeInTheDocument()
expect(screen.getByRole('combobox', { name: 'Base ref' })).toBeInTheDocument()
})
it('shows the new fusion as Starting while the request is pending', async () => {
@@ -116,8 +116,7 @@ export function MultiRunSheet({ repoId, directory, defaultBaseRef, open, onOpenC
entryIds: selection.entryIds,
model: submission.model,
...(submission.instructions ? { instructions: submission.instructions } : {}),
isolate: submission.isolate,
...(submission.isolate && submission.baseRef ? { baseRef: submission.baseRef } : {}),
...(submission.baseRef ? { baseRef: submission.baseRef } : {}),
}
fuse.mutate(
{ runId: selection.runId, request },