Fix sandbox lifecycle workflows
This commit is contained in:
@@ -299,9 +299,16 @@ export async function POST(request: Request) {
|
|||||||
}, { status: 500 })
|
}, { status: 500 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const verification = await verifySandboxCreation(sandboxName)
|
const readiness = await waitForSandboxReady(sandboxName, 90000, 2000)
|
||||||
const created = verification.verified
|
const verification = readiness.verification ?? {
|
||||||
console.log(`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} elapsedMs=${elapsedMs(requestStartedAt)}`)
|
verified: false,
|
||||||
|
summary: "Sandbox readiness polling produced no verification result.",
|
||||||
|
error: "Sandbox readiness polling produced no verification result.",
|
||||||
|
}
|
||||||
|
const created = readiness.verified
|
||||||
|
console.log(
|
||||||
|
`[sandbox/create] request:complete sandbox=${sandboxName} created=${created} readinessAttempts=${readiness.attempts} elapsedMs=${elapsedMs(requestStartedAt)}`,
|
||||||
|
)
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
ok: created,
|
ok: created,
|
||||||
@@ -314,6 +321,10 @@ export async function POST(request: Request) {
|
|||||||
enableTailscale,
|
enableTailscale,
|
||||||
setupPath: NEMOCLAW_SETUP,
|
setupPath: NEMOCLAW_SETUP,
|
||||||
hostPath: HOST_PATH,
|
hostPath: HOST_PATH,
|
||||||
|
readiness: {
|
||||||
|
attempts: readiness.attempts,
|
||||||
|
elapsedMs: readiness.elapsedMs,
|
||||||
|
},
|
||||||
stdout: result.stdout,
|
stdout: result.stdout,
|
||||||
stderr: result.stderr,
|
stderr: result.stderr,
|
||||||
note: created
|
note: created
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { execFile } from "node:child_process"
|
||||||
|
import { promisify } from "node:util"
|
||||||
|
|
||||||
|
const execFileAsync = promisify(execFile)
|
||||||
|
const HOME = process.env.HOME || ""
|
||||||
|
const OPENSHELL_BIN = process.env.OPENSHELL_BIN || `${HOME}/.local/bin/openshell`
|
||||||
|
const HOST_PATH = [
|
||||||
|
`${HOME}/.local/bin`,
|
||||||
|
`${HOME}/.nvm/versions/node/v22.22.2/bin`,
|
||||||
|
`${HOME}/.nvm/versions/node/v22.22.1/bin`,
|
||||||
|
"/opt/homebrew/bin",
|
||||||
|
"/usr/local/bin",
|
||||||
|
"/usr/bin",
|
||||||
|
"/bin",
|
||||||
|
"/usr/sbin",
|
||||||
|
"/sbin",
|
||||||
|
process.env.PATH || "",
|
||||||
|
].filter(Boolean).join(":")
|
||||||
|
|
||||||
|
function elapsedMs(start: number) {
|
||||||
|
return Date.now() - start
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateSandboxName(name: string) {
|
||||||
|
if (!name || typeof name !== "string") throw new Error("sandbox name is required")
|
||||||
|
if (name.length > 63) throw new Error("sandbox name too long (max 63 chars)")
|
||||||
|
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(name)) {
|
||||||
|
throw new Error("sandbox name must be lowercase alphanumeric with optional internal hyphens")
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteSandbox(sandboxName: string) {
|
||||||
|
const startedAt = Date.now()
|
||||||
|
console.log(`[sandbox/delete] command:start sandbox=${sandboxName}`)
|
||||||
|
try {
|
||||||
|
const { stdout, stderr } = await execFileAsync(OPENSHELL_BIN, ["sandbox", "delete", sandboxName], {
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
PATH: HOST_PATH,
|
||||||
|
NO_COLOR: "1",
|
||||||
|
CLICOLOR: "0",
|
||||||
|
CLICOLOR_FORCE: "0",
|
||||||
|
},
|
||||||
|
maxBuffer: 20 * 1024 * 1024,
|
||||||
|
})
|
||||||
|
console.log(`[sandbox/delete] command:done sandbox=${sandboxName} elapsedMs=${elapsedMs(startedAt)}`)
|
||||||
|
return { ok: true as const, stdout: String(stdout).trim(), stderr: String(stderr).trim() }
|
||||||
|
} catch (error: any) {
|
||||||
|
const message = error instanceof Error ? error.message : String(error ?? "Sandbox delete failed")
|
||||||
|
console.log(`[sandbox/delete] command:error sandbox=${sandboxName} elapsedMs=${elapsedMs(startedAt)} message=${message}`)
|
||||||
|
return {
|
||||||
|
ok: false as const,
|
||||||
|
stdout: String(error?.stdout || "").trim(),
|
||||||
|
stderr: String(error?.stderr || "").trim(),
|
||||||
|
error: message,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const startedAt = Date.now()
|
||||||
|
console.log("[sandbox/delete] request:start")
|
||||||
|
try {
|
||||||
|
const body = await request.json()
|
||||||
|
const sandboxName = validateSandboxName(
|
||||||
|
typeof body?.sandboxName === "string" ? body.sandboxName.trim() : typeof body?.sandboxId === "string" ? body.sandboxId.trim() : "",
|
||||||
|
)
|
||||||
|
const result = await deleteSandbox(sandboxName)
|
||||||
|
if (!result.ok) {
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: false,
|
||||||
|
deleted: false,
|
||||||
|
sandboxName,
|
||||||
|
error: result.error,
|
||||||
|
stdout: result.stdout,
|
||||||
|
stderr: result.stderr,
|
||||||
|
}, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[sandbox/delete] request:complete sandbox=${sandboxName} elapsedMs=${elapsedMs(startedAt)}`)
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: true,
|
||||||
|
deleted: true,
|
||||||
|
sandboxName,
|
||||||
|
stdout: result.stdout,
|
||||||
|
stderr: result.stderr,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Sandbox delete failed"
|
||||||
|
const status = /required|must be|too long/.test(message) ? 400 : 500
|
||||||
|
console.log(`[sandbox/delete] request:error elapsedMs=${elapsedMs(startedAt)} message=${message}`)
|
||||||
|
return NextResponse.json({ ok: false, deleted: false, error: message }, { status })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ interface ConfigurationPanelProps {
|
|||||||
sandboxId: string
|
sandboxId: string
|
||||||
mode?: 'existing' | 'create'
|
mode?: 'existing' | 'create'
|
||||||
onCreateSuccess?: (sandboxId: string) => void | Promise<void>
|
onCreateSuccess?: (sandboxId: string) => void | Promise<void>
|
||||||
onInventoryRefresh?: () => Promise<unknown>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldHelp({ text }: { text: string }) {
|
function FieldHelp({ text }: { text: string }) {
|
||||||
@@ -75,7 +74,7 @@ function blocksToPolicy(blocks: NetworkPolicyBlock[]): OpenShellPolicy["network_
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCreateSuccess, onInventoryRefresh }: ConfigurationPanelProps) {
|
export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCreateSuccess }: ConfigurationPanelProps) {
|
||||||
const [policy, setPolicy] = useState<OpenShellPolicy>(defaultPolicy)
|
const [policy, setPolicy] = useState<OpenShellPolicy>(defaultPolicy)
|
||||||
const [blocks, setBlocks] = useState<NetworkPolicyBlock[]>([])
|
const [blocks, setBlocks] = useState<NetworkPolicyBlock[]>([])
|
||||||
const [loading, setLoading] = useState(mode === 'existing')
|
const [loading, setLoading] = useState(mode === 'existing')
|
||||||
@@ -132,9 +131,6 @@ export default function ConfigurationPanel({ sandboxId, mode = 'existing', onCre
|
|||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
if (!res.ok) throw new Error([data.error, data.verification?.summary, data.verification?.error, data.stdout, data.stderr].filter(Boolean).join('\n\n'))
|
if (!res.ok) throw new Error([data.error, data.verification?.summary, data.verification?.error, data.stdout, data.stderr].filter(Boolean).join('\n\n'))
|
||||||
const createdSandboxId = data.verification?.details?.id || data.verification?.details?.name || data.sandboxName
|
const createdSandboxId = data.verification?.details?.id || data.verification?.details?.name || data.sandboxName
|
||||||
if (onInventoryRefresh) {
|
|
||||||
await onInventoryRefresh()
|
|
||||||
}
|
|
||||||
setMessage([
|
setMessage([
|
||||||
`Sandbox '${data.sandboxName}' created.`,
|
`Sandbox '${data.sandboxName}' created.`,
|
||||||
data.verification?.summary,
|
data.verification?.summary,
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ export default function SandboxList({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ConfigurationPanel sandboxId={selectedSandbox.id} mode="existing" onInventoryRefresh={onInventoryRefresh} />
|
<ConfigurationPanel sandboxId={selectedSandbox.id} mode="existing" />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ interface InventoryResponse {
|
|||||||
nemoclaw?: NemoClawSummary | null
|
nemoclaw?: NemoClawSummary | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RefreshOptions = {
|
||||||
|
force?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeStatus(status: unknown): SandboxInventoryItem['status'] {
|
function normalizeStatus(status: unknown): SandboxInventoryItem['status'] {
|
||||||
const value = typeof status === 'string' ? status.toLowerCase() : 'unknown'
|
const value = typeof status === 'string' ? status.toLowerCase() : 'unknown'
|
||||||
if (value === 'running' || value === 'pending' || value === 'stopped' || value === 'error') return value
|
if (value === 'running' || value === 'pending' || value === 'stopped' || value === 'error') return value
|
||||||
@@ -79,12 +83,16 @@ export function useSandboxInventory(options?: { enabled?: boolean; refreshInterv
|
|||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const inFlightRef = useRef<Promise<SandboxInventoryItem[]> | null>(null)
|
const inFlightRef = useRef<Promise<SandboxInventoryItem[]> | null>(null)
|
||||||
|
const requestIdRef = useRef(0)
|
||||||
|
|
||||||
const refresh = useCallback(async () => {
|
const refresh = useCallback(async (refreshOptions?: RefreshOptions) => {
|
||||||
if (inFlightRef.current) {
|
if (!refreshOptions?.force && inFlightRef.current) {
|
||||||
return inFlightRef.current
|
return inFlightRef.current
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const requestId = requestIdRef.current + 1
|
||||||
|
requestIdRef.current = requestId
|
||||||
|
|
||||||
const run = (async () => {
|
const run = (async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/telemetry/real', { cache: 'no-store' })
|
const response = await fetch('/api/telemetry/real', { cache: 'no-store' })
|
||||||
@@ -92,19 +100,27 @@ export function useSandboxInventory(options?: { enabled?: boolean; refreshInterv
|
|||||||
if (!response.ok) throw new Error(data.error || 'Failed to fetch sandbox inventory')
|
if (!response.ok) throw new Error(data.error || 'Failed to fetch sandbox inventory')
|
||||||
|
|
||||||
const nextSandboxes = normalizeFromResponse(data)
|
const nextSandboxes = normalizeFromResponse(data)
|
||||||
setSandboxes(nextSandboxes)
|
if (requestId === requestIdRef.current) {
|
||||||
setNemoclaw(data?.nemoclaw ?? null)
|
setSandboxes(nextSandboxes)
|
||||||
setError(null)
|
setNemoclaw(data?.nemoclaw ?? null)
|
||||||
|
setError(null)
|
||||||
|
}
|
||||||
return nextSandboxes
|
return nextSandboxes
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = err instanceof Error ? err.message : 'Failed to fetch sandbox inventory'
|
const message = err instanceof Error ? err.message : 'Failed to fetch sandbox inventory'
|
||||||
setSandboxes([])
|
if (requestId === requestIdRef.current) {
|
||||||
setNemoclaw(null)
|
setSandboxes([])
|
||||||
setError(message)
|
setNemoclaw(null)
|
||||||
|
setError(message)
|
||||||
|
}
|
||||||
throw err
|
throw err
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
if (requestId === requestIdRef.current) {
|
||||||
inFlightRef.current = null
|
setLoading(false)
|
||||||
|
}
|
||||||
|
if (requestId === requestIdRef.current) {
|
||||||
|
inFlightRef.current = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|||||||
+68
-12
@@ -19,6 +19,8 @@ export default function Dashboard() {
|
|||||||
const [activeView, setActiveView] = useState<'settings' | 'sandboxes'>('sandboxes')
|
const [activeView, setActiveView] = useState<'settings' | 'sandboxes'>('sandboxes')
|
||||||
const [deletingSandboxId, setDeletingSandboxId] = useState<string | null>(null)
|
const [deletingSandboxId, setDeletingSandboxId] = useState<string | null>(null)
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||||
|
const [lifecycleMessage, setLifecycleMessage] = useState<string | null>(null)
|
||||||
|
const [deleteInProgress, setDeleteInProgress] = useState(false)
|
||||||
const inventoryEnabled = activeView === 'sandboxes' || isCreateMode || isDestroyMode
|
const inventoryEnabled = activeView === 'sandboxes' || isCreateMode || isDestroyMode
|
||||||
const { sandboxes, nemoclaw, loading, error, refresh } = useSandboxInventory({
|
const { sandboxes, nemoclaw, loading, error, refresh } = useSandboxInventory({
|
||||||
enabled: inventoryEnabled,
|
enabled: inventoryEnabled,
|
||||||
@@ -40,6 +42,10 @@ export default function Dashboard() {
|
|||||||
() => sandboxes.find((sandbox) => sandbox.id === dashboardSession.selectedSandboxId) ?? null,
|
() => sandboxes.find((sandbox) => sandbox.id === dashboardSession.selectedSandboxId) ?? null,
|
||||||
[sandboxes, dashboardSession.selectedSandboxId]
|
[sandboxes, dashboardSession.selectedSandboxId]
|
||||||
)
|
)
|
||||||
|
const deletingSandbox = useMemo(
|
||||||
|
() => sandboxes.find((sandbox) => sandbox.id === deletingSandboxId) ?? null,
|
||||||
|
[sandboxes, deletingSandboxId]
|
||||||
|
)
|
||||||
|
|
||||||
const toggleTheme = () => {
|
const toggleTheme = () => {
|
||||||
setTheme(theme === 'light' ? 'dark' : 'light')
|
setTheme(theme === 'light' ? 'dark' : 'light')
|
||||||
@@ -58,20 +64,56 @@ export default function Dashboard() {
|
|||||||
setDashboardSession((current) => updateDashboardSessionSelection(current, null))
|
setDashboardSession((current) => updateDashboardSessionSelection(current, null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sleep = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms))
|
||||||
|
|
||||||
|
const refreshUntilSandboxVisible = async (sandboxRef: string) => {
|
||||||
|
for (let attempt = 0; attempt < 8; attempt += 1) {
|
||||||
|
const latest = await refresh({ force: true })
|
||||||
|
const sandbox = latest.find((item) => item.id === sandboxRef || item.name === sandboxRef)
|
||||||
|
if (sandbox) return sandbox
|
||||||
|
await sleep(1500)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const handleCreateSuccess = async (createdSandboxId: string) => {
|
const handleCreateSuccess = async (createdSandboxId: string) => {
|
||||||
setIsCreateMode(false)
|
setIsCreateMode(false)
|
||||||
setIsDestroyMode(false)
|
setIsDestroyMode(false)
|
||||||
setActiveView('sandboxes')
|
setActiveView('sandboxes')
|
||||||
const latest = await refresh()
|
setLifecycleMessage(`Refreshing inventory for ${createdSandboxId}...`)
|
||||||
const created = latest.find((sandbox) => sandbox.id === createdSandboxId || sandbox.name === createdSandboxId)
|
const created = await refreshUntilSandboxVisible(createdSandboxId)
|
||||||
setDashboardSession((current) => updateDashboardSessionSelection(current, created?.id ?? createdSandboxId))
|
setLifecycleMessage(created ? `Sandbox ${created.name} is ready.` : `Sandbox ${createdSandboxId} was created, but inventory has not reported it yet.`)
|
||||||
|
setDashboardSession((current) => updateDashboardSessionSelection(current, created?.id ?? null))
|
||||||
}
|
}
|
||||||
|
|
||||||
const confirmDelete = () => {
|
const confirmDelete = async () => {
|
||||||
console.log('Destroying sandbox:', deletingSandboxId)
|
if (!deletingSandboxId || deleteInProgress) return
|
||||||
setShowDeleteConfirm(false)
|
const sandbox = sandboxes.find((item) => item.id === deletingSandboxId)
|
||||||
setDeletingSandboxId(null)
|
const sandboxName = sandbox?.name ?? deletingSandboxId
|
||||||
setIsDestroyMode(false)
|
|
||||||
|
try {
|
||||||
|
setDeleteInProgress(true)
|
||||||
|
setLifecycleMessage(`Destroying sandbox ${sandboxName}...`)
|
||||||
|
const response = await fetch('/api/sandbox/delete', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ sandboxName }),
|
||||||
|
})
|
||||||
|
const data = await response.json()
|
||||||
|
if (!response.ok) throw new Error([data.error, data.stdout, data.stderr].filter(Boolean).join('\n\n') || 'Failed to destroy sandbox')
|
||||||
|
|
||||||
|
const latest = await refresh({ force: true })
|
||||||
|
const stillPresent = latest.find((item) => item.id === deletingSandboxId || item.name === sandboxName)
|
||||||
|
setDashboardSession((current) => updateDashboardSessionSelection(current, current.selectedSandboxId === deletingSandboxId ? null : current.selectedSandboxId))
|
||||||
|
setLifecycleMessage(stillPresent ? `Delete started for ${sandboxName}. Inventory still reports it while cleanup finishes.` : `Sandbox ${sandboxName} destroyed.`)
|
||||||
|
setShowDeleteConfirm(false)
|
||||||
|
setDeletingSandboxId(null)
|
||||||
|
setIsDestroyMode(false)
|
||||||
|
} catch (err) {
|
||||||
|
setLifecycleMessage(err instanceof Error ? err.message : 'Failed to destroy sandbox')
|
||||||
|
} finally {
|
||||||
|
setDeleteInProgress(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cancelDelete = () => {
|
const cancelDelete = () => {
|
||||||
@@ -103,11 +145,13 @@ export default function Dashboard() {
|
|||||||
setIsCreateMode(true)
|
setIsCreateMode(true)
|
||||||
setIsDestroyMode(false)
|
setIsDestroyMode(false)
|
||||||
clearSelection()
|
clearSelection()
|
||||||
|
setLifecycleMessage(null)
|
||||||
}}
|
}}
|
||||||
onDestroyClick={() => {
|
onDestroyClick={() => {
|
||||||
setActiveView('sandboxes')
|
setActiveView('sandboxes')
|
||||||
setIsDestroyMode(true)
|
setIsDestroyMode(true)
|
||||||
setIsCreateMode(false)
|
setIsCreateMode(false)
|
||||||
|
setLifecycleMessage(null)
|
||||||
}}
|
}}
|
||||||
onSettingsClick={() => {
|
onSettingsClick={() => {
|
||||||
setActiveView('settings')
|
setActiveView('settings')
|
||||||
@@ -157,7 +201,7 @@ export default function Dashboard() {
|
|||||||
Choose a blueprint, name the sandbox, and create it.
|
Choose a blueprint, name the sandbox, and create it.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<ConfigurationPanel sandboxId="new-sandbox" mode="create" onCreateSuccess={handleCreateSuccess} onInventoryRefresh={refresh} />
|
<ConfigurationPanel sandboxId="new-sandbox" mode="create" onCreateSuccess={handleCreateSuccess} />
|
||||||
</div>
|
</div>
|
||||||
) : isDestroyMode ? (
|
) : isDestroyMode ? (
|
||||||
<div className="panel p-8 border-2 border-[var(--status-stopped)]">
|
<div className="panel p-8 border-2 border-[var(--status-stopped)]">
|
||||||
@@ -198,6 +242,12 @@ export default function Dashboard() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{lifecycleMessage && (
|
||||||
|
<div className="panel mb-6 p-4 text-xs text-[var(--foreground-dim)] whitespace-pre-wrap" data-testid="sandbox-lifecycle-message">
|
||||||
|
{lifecycleMessage}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{inventoryEnabled && loading ? (
|
{inventoryEnabled && loading ? (
|
||||||
<div className="flex items-center justify-center h-64" data-testid="inventory-loading-state">
|
<div className="flex items-center justify-center h-64" data-testid="inventory-loading-state">
|
||||||
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
|
<div className="text-xs text-[var(--foreground-dim)] font-mono uppercase tracking-wider">
|
||||||
@@ -249,14 +299,20 @@ export default function Dashboard() {
|
|||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-[var(--foreground)] mb-6">
|
<p className="text-sm text-[var(--foreground)] mb-6">
|
||||||
Destroying this sandbox will permanently delete it and it will not be recoverable. Are you sure?
|
Destroying {deletingSandbox?.name ?? 'this sandbox'} will permanently delete it and it will not be recoverable. Are you sure?
|
||||||
</p>
|
</p>
|
||||||
|
{lifecycleMessage && (
|
||||||
|
<div className="mb-4 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3 text-xs text-[var(--foreground-dim)] whitespace-pre-wrap">
|
||||||
|
{lifecycleMessage}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<button
|
<button
|
||||||
onClick={confirmDelete}
|
onClick={confirmDelete}
|
||||||
className="flex-1 px-4 py-2 rounded-sm bg-[var(--status-stopped)] text-white text-xs font-mono uppercase tracking-wider hover:bg-[#b91c1c] transition-colors"
|
disabled={deleteInProgress}
|
||||||
|
className="flex-1 px-4 py-2 rounded-sm bg-[var(--status-stopped)] text-white text-xs font-mono uppercase tracking-wider hover:bg-[#b91c1c] transition-colors disabled:opacity-50"
|
||||||
>
|
>
|
||||||
YES — DESTROY
|
{deleteInProgress ? 'DESTROYING...' : 'YES — DESTROY'}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={cancelDelete}
|
onClick={cancelDelete}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readFile } from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
const root = process.cwd()
|
||||||
|
const createRoutePath = path.join(root, 'app/api/sandbox/create/route.ts')
|
||||||
|
const deleteRoutePath = path.join(root, 'app/api/sandbox/delete/route.ts')
|
||||||
|
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
|
||||||
|
const pagePath = path.join(root, 'app/page.tsx')
|
||||||
|
const configPanelPath = path.join(root, 'app/components/ConfigurationPanel.tsx')
|
||||||
|
|
||||||
|
const createRouteSource = await readFile(createRoutePath, 'utf8')
|
||||||
|
const deleteRouteSource = await readFile(deleteRoutePath, 'utf8')
|
||||||
|
const hookSource = await readFile(hookPath, 'utf8')
|
||||||
|
const pageSource = await readFile(pagePath, 'utf8')
|
||||||
|
const configPanelSource = await readFile(configPanelPath, 'utf8')
|
||||||
|
|
||||||
|
assert.match(
|
||||||
|
createRouteSource,
|
||||||
|
/const readiness = await waitForSandboxReady\(sandboxName, 90000, 2000\)/,
|
||||||
|
'blueprint create must poll authoritative readiness before returning success',
|
||||||
|
)
|
||||||
|
assert.match(
|
||||||
|
createRouteSource,
|
||||||
|
/readiness:\s*\{\s*attempts: readiness\.attempts,\s*elapsedMs: readiness\.elapsedMs,/,
|
||||||
|
'blueprint create response must expose readiness polling metadata',
|
||||||
|
)
|
||||||
|
|
||||||
|
assert.match(hookSource, /type RefreshOptions = \{\s*force\?: boolean\s*\}/, 'inventory refresh must accept a force option')
|
||||||
|
assert.match(hookSource, /!refreshOptions\?\.force && inFlightRef\.current/, 'forced inventory refresh must bypass existing in-flight reads')
|
||||||
|
assert.match(hookSource, /requestIdRef = useRef\(0\)/, 'inventory refresh must guard against stale concurrent responses')
|
||||||
|
|
||||||
|
assert.match(deleteRouteSource, /OPENSHELL_BIN.*openshell/, 'delete route must use the OpenShell CLI')
|
||||||
|
assert.match(deleteRouteSource, /\["sandbox", "delete", sandboxName\]/, 'delete route must call openshell sandbox delete with the sandbox name')
|
||||||
|
assert.match(deleteRouteSource, /validateSandboxName/, 'delete route must validate sandbox names before execution')
|
||||||
|
|
||||||
|
assert.match(pageSource, /fetch\('\/api\/sandbox\/delete'/, 'destroy workflow must call the real sandbox delete endpoint')
|
||||||
|
assert.match(pageSource, /refresh\(\{ force: true \}\)/, 'create and destroy workflows must force fresh inventory reads')
|
||||||
|
assert.match(pageSource, /refreshUntilSandboxVisible/, 'create workflow must wait for the new sandbox to appear in inventory')
|
||||||
|
assert.doesNotMatch(pageSource, /console\.log\('Destroying sandbox:'/, 'destroy workflow must not be a UI-only placeholder')
|
||||||
|
assert.doesNotMatch(configPanelSource, /onInventoryRefresh/, 'create panel must leave post-create inventory orchestration to the parent')
|
||||||
|
|
||||||
|
console.log('sandbox-lifecycle-check: PASS create/destroy lifecycle assertions')
|
||||||
Reference in New Issue
Block a user