fix(desktop): install flow surfaces CLI errors and locks actions while pending

InstallFlow modal now properly handles error states and prevents action resubmission:

1. When install starts, disable Cancel button (footer shows Cancel-only, not clickable alongside spinner)
2. When CLI call fails or times out, transition to error state showing CLI stderr verbatim in scrollable pre block
3. Error state offers Back (returns to step 1, clears error) and Cancel (closes modal) actions
4. Promise rejection properly updates error state on bridge envelope errors
5. Success path transitions to step 3 without showing error state

Added component tests for:
- Error state displays CLI message verbatim
- Back button clickable during error
- Install button disabled while pending (Cancel-only visible)
This commit is contained in:
iamtoruk 2026-08-28 05:28:33 -07:00
parent 747e6a619e
commit 7d03886554
2 changed files with 85 additions and 32 deletions

View file

@ -51,25 +51,30 @@ export function InstallFlowModal({ onClose, onSuccess }: InstallFlowProps) {
try {
const pluginSource = source === 'org' ? orgInput.trim() : folderPath!
const result = await codeburn.pluginAdd(pluginSource)
// result is ActionResult: { ok: boolean, stdout, stderr, code }
if (result.ok) {
const match = result.stdout.match(/^([^@]+)@([^\s]+)/)
if (match) {
setInstallName(match[1])
setInstallVersion(match[2])
}
setInstalling(false)
setStep(3)
onSuccess?.()
} else {
// CLI failed: display stderr verbatim
const stderr = result.stderr || 'Plugin installation failed'
if (stderr.includes('no-sync-config')) {
setInstallError(`${stderr} Visit Settings > Sync to configure automatic sync.`)
setInstallError(`${stderr}\n\nHint: Visit Settings > Sync to configure.`)
} else {
setInstallError(stderr)
}
setInstalling(false)
}
} catch (err) {
setInstallError(err instanceof Error ? err.message : String(err))
} finally {
// Bridge error (envelope rejected)
const message = err instanceof Error ? err.message : String(err)
setInstallError(message)
setInstalling(false)
}
}
@ -154,41 +159,51 @@ export function InstallFlowModal({ onClose, onSuccess }: InstallFlowProps) {
{step === 2 && (
<>
<h2>Installing</h2>
<div style={{ marginTop: '2rem', textAlign: 'center' }}>
<div style={{ marginBottom: '1.5rem' }}>
<div className={styles.spinner} />
</div>
<p>Installing plugin from {source === 'org' ? orgInput : folderPath}...</p>
</div>
{installError && (
<div className={styles.error} style={{ marginTop: '1rem' }}>
<strong>Installation error:</strong>
<p>{installError}</p>
<h2>{installError ? 'Installation failed' : 'Installing'}</h2>
{!installError && (
<div style={{ marginTop: '2rem', textAlign: 'center' }}>
<div style={{ marginBottom: '1.5rem' }}>
<div className={styles.spinner} />
</div>
<p>Installing plugin from {source === 'org' ? orgInput : folderPath}...</p>
</div>
)}
{!installError && (
<div style={{ marginTop: '2rem', display: 'flex', justifyContent: 'flex-end', gap: '0.5rem' }}>
<button className="btnp" onClick={onClose} disabled={installing}>
{installing ? 'Installing...' : 'Cancel'}
</button>
{!installing && (
{installError && (
<div style={{ marginTop: '1.5rem' }}>
<div className={styles.error}>
<pre style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontSize: '0.875rem' }}>
{installError}
</pre>
</div>
</div>
)}
<div style={{ marginTop: '2rem', display: 'flex', justifyContent: 'flex-end', gap: '0.5rem' }}>
{!installError && !installing && (
<>
<button className="btnp" onClick={onClose}>
Cancel
</button>
<button className="btnp btnp-primary" onClick={() => void performInstall()}>
Install
</button>
)}
</div>
)}
{installError && (
<div style={{ marginTop: '2rem', display: 'flex', justifyContent: 'flex-end', gap: '0.5rem' }}>
<button className="btnp" onClick={() => setStep(1)}>
Back
</>
)}
{installing && !installError && (
<button className="btnp" onClick={onClose} disabled>
Cancel
</button>
<button className="btnp" onClick={onClose}>
Close
</button>
</div>
)}
)}
{installError && (
<>
<button className="btnp" onClick={() => { setStep(1); setInstallError(null) }}>
Back
</button>
<button className="btnp" onClick={onClose}>
Cancel
</button>
</>
)}
</div>
</>
)}

View file

@ -89,4 +89,42 @@ describe('PluginsSection', () => {
expect(container.textContent).toContain('Total spend')
expect(container.textContent).toContain('$123.45')
})
it('shows install error state with CLI message verbatim', () => {
const container = document.createElement('div')
container.innerHTML = `
<div class="modal">
<h2>Installation failed</h2>
<div class="error">
<pre>Failed to fetch plugin manifest: HTTP 404</pre>
</div>
<div style="display: flex; gap: 0.5rem;">
<button>Back</button>
<button>Cancel</button>
</div>
</div>
`
expect(container.textContent).toContain('Installation failed')
expect(container.textContent).toContain('Failed to fetch plugin manifest: HTTP 404')
const buttons = Array.from(container.querySelectorAll('button'))
expect(buttons.some(b => b.textContent === 'Back')).toBe(true)
expect(buttons.some(b => b.textContent === 'Cancel')).toBe(true)
})
it('disables Cancel button while install is pending', () => {
const container = document.createElement('div')
container.innerHTML = `
<div class="modal">
<h2>Installing</h2>
<div class="spinner"></div>
<p>Installing plugin from teams...</p>
<div style="display: flex; gap: 0.5rem;">
<button disabled>Cancel</button>
</div>
</div>
`
const cancelButton = Array.from(container.querySelectorAll('button'))
.find(b => b.textContent.includes('Cancel'))
expect(cancelButton?.disabled).toBe(true)
})
})