|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | + |
| 5 | +interface SmokeCheck { |
| 6 | + name: string |
| 7 | + durationMs: number |
| 8 | +} |
| 9 | + |
| 10 | +interface SmokeResult { |
| 11 | + runId: string |
| 12 | + baseUrl: string |
| 13 | + rootSandboxId: string |
| 14 | + forkSandboxId: string |
| 15 | + checks: SmokeCheck[] |
| 16 | +} |
| 17 | + |
| 18 | +export default function SmokePage() { |
| 19 | + const [isRunning, setIsRunning] = useState(false) |
| 20 | + const [error, setError] = useState<string | null>(null) |
| 21 | + const [result, setResult] = useState<SmokeResult | null>(null) |
| 22 | + |
| 23 | + async function handleRun() { |
| 24 | + setIsRunning(true) |
| 25 | + setError(null) |
| 26 | + setResult(null) |
| 27 | + |
| 28 | + try { |
| 29 | + const response = await fetch('/api/smoke', { method: 'POST' }) |
| 30 | + const body = (await response.json().catch(() => ({ error: 'Request failed' }))) as |
| 31 | + | SmokeResult |
| 32 | + | { error: string } |
| 33 | + |
| 34 | + if (!response.ok || 'error' in body) { |
| 35 | + throw new Error('error' in body ? body.error : `Request failed (${response.status})`) |
| 36 | + } |
| 37 | + |
| 38 | + setResult(body) |
| 39 | + } catch (runError) { |
| 40 | + setError(runError instanceof Error ? runError.message : 'Unknown error') |
| 41 | + } finally { |
| 42 | + setIsRunning(false) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + return ( |
| 47 | + <div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}> |
| 48 | + <div className="page-header"> |
| 49 | + <h1 className="page-title">Sandbox Smoke</h1> |
| 50 | + </div> |
| 51 | + |
| 52 | + <div className="card" style={{ display: 'flex', flexDirection: 'column', gap: '0.875rem' }}> |
| 53 | + <div style={{ display: 'flex', flexDirection: 'column', gap: '0.375rem' }}> |
| 54 | + <div className="card-title">Production Lifecycle Test</div> |
| 55 | + <p className="text-weak" style={{ fontSize: '0.8125rem', lineHeight: 1.6 }}> |
| 56 | + Runs the full sandbox lifecycle from the admin server using configured environment |
| 57 | + credentials. The flow creates live sandboxes, exercises exec/session/file/fork paths, |
| 58 | + and attempts cleanup in all cases. |
| 59 | + </p> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div style={{ display: 'flex', gap: '0.75rem', alignItems: 'center', flexWrap: 'wrap' }}> |
| 63 | + <button className="btn btn-primary" onClick={handleRun} disabled={isRunning}> |
| 64 | + {isRunning ? 'Running smoke test...' : 'Run smoke test'} |
| 65 | + </button> |
| 66 | + <span className="text-weak" style={{ fontSize: '0.75rem' }}> |
| 67 | + Uses `SANDCHEST_SMOKE_API_KEY` or `SANDCHEST_API_KEY` on the admin server. |
| 68 | + </span> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + |
| 72 | + {error ? ( |
| 73 | + <div className="card feedback-card feedback-danger"> |
| 74 | + Smoke test failed: {error} |
| 75 | + </div> |
| 76 | + ) : null} |
| 77 | + |
| 78 | + {result ? ( |
| 79 | + <div className="card" style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}> |
| 80 | + <div className="card-header" style={{ marginBottom: 0 }}> |
| 81 | + <div> |
| 82 | + <div className="card-title">Last Run</div> |
| 83 | + <div className="card-subtitle">{result.runId}</div> |
| 84 | + </div> |
| 85 | + <span className="badge badge-online"> |
| 86 | + <span className="badge-dot" /> |
| 87 | + passed |
| 88 | + </span> |
| 89 | + </div> |
| 90 | + |
| 91 | + <div className="card-metrics"> |
| 92 | + <div style={{ display: 'flex', justifyContent: 'space-between', gap: '1rem', fontSize: '0.8125rem' }}> |
| 93 | + <span className="text-weak">Base URL</span> |
| 94 | + <span>{result.baseUrl}</span> |
| 95 | + </div> |
| 96 | + <div style={{ display: 'flex', justifyContent: 'space-between', gap: '1rem', fontSize: '0.8125rem' }}> |
| 97 | + <span className="text-weak">Root sandbox</span> |
| 98 | + <span>{result.rootSandboxId}</span> |
| 99 | + </div> |
| 100 | + <div style={{ display: 'flex', justifyContent: 'space-between', gap: '1rem', fontSize: '0.8125rem' }}> |
| 101 | + <span className="text-weak">Fork sandbox</span> |
| 102 | + <span>{result.forkSandboxId}</span> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + |
| 106 | + <div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}> |
| 107 | + <div className="card-section-title">Checks</div> |
| 108 | + {result.checks.map((check) => ( |
| 109 | + <div |
| 110 | + key={check.name} |
| 111 | + style={{ |
| 112 | + display: 'flex', |
| 113 | + justifyContent: 'space-between', |
| 114 | + gap: '1rem', |
| 115 | + fontSize: '0.8125rem', |
| 116 | + paddingTop: '0.5rem', |
| 117 | + borderTop: '1px solid var(--color-border-weak)', |
| 118 | + }} |
| 119 | + > |
| 120 | + <span>{check.name}</span> |
| 121 | + <span className="text-weak">{check.durationMs}ms</span> |
| 122 | + </div> |
| 123 | + ))} |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + ) : null} |
| 127 | + </div> |
| 128 | + ) |
| 129 | +} |
0 commit comments