@spunto/design-system 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/package.json +1 -1
- package/src/components/workers/index.ts +4 -4
- package/src/components/workers/worker-card.tsx +20 -2
- package/src/components/workers/worker-cockpit.tsx +65 -8
- package/src/components/workers/worker-status-history.tsx +41 -0
- package/src/components/workers/worker-status.test.ts +20 -1
- package/src/components/workers/worker-status.tsx +33 -0
package/README.md
CHANGED
|
@@ -239,6 +239,9 @@ opinions a dashboard doesn't want, so it gets an entry too.
|
|
|
239
239
|
at the top of its panel, drawn by `WorkerTaskHistory` (`/tasks`) — the live task
|
|
240
240
|
as a card, then every other task that ran on the workspace, most recent first.
|
|
241
241
|
The project's task list can be passed as is; the panel keeps this worker's.
|
|
242
|
+
- **`WorkerCockpit`** takes `actions` (since 0.42.0): the host's own actions
|
|
243
|
+
(`{ id, label, icon?, hint?, onClick, busy?, disabled? }`), drawn like Rebuild at the
|
|
244
|
+
top of the Actions section — a sandbox's "Create snapshot" and "Fork".
|
|
242
245
|
- **Its bricks, exported individually** because the table view assembles them
|
|
243
246
|
differently: `WorkerStatusDot`/`WorkerStatusPill` (+`resolveWorkerStatus`,
|
|
244
247
|
`workerStatusConfig`), `SetupProgress` (+`setupProgress`, `phaseLabel`,
|
package/package.json
CHANGED
|
@@ -18,9 +18,9 @@ export { ActionMenu } from "../action-menu"
|
|
|
18
18
|
export type { ActionMenuProps, ActionMenuItem, ActionMenuEntry, ActionMenuLinkRender } from "../action-menu"
|
|
19
19
|
|
|
20
20
|
export { WorkerCockpit } from "./worker-cockpit"
|
|
21
|
-
export type { WorkerCockpitProps } from "./worker-cockpit"
|
|
21
|
+
export type { WorkerCockpitAction, WorkerCockpitProps } from "./worker-cockpit"
|
|
22
22
|
|
|
23
|
-
export { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
|
|
23
|
+
export { IN_FLIGHT_STATUSES, WorkerStatusDot, WorkerStatusPill, inFlightMessage, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
|
|
24
24
|
export type { WorkerStatus, WorkerStatusConfig, WorkerStatusKey } from "./worker-status"
|
|
25
25
|
|
|
26
26
|
export { SetupProgress, StepIndicator, phaseLabel, setupProgress, setupTotalMs } from "./setup-progress"
|
|
@@ -29,8 +29,8 @@ export type { SetupProgressProps, StepState } from "./setup-progress"
|
|
|
29
29
|
export { WorkerSetupTimeline } from "./worker-setup-timeline"
|
|
30
30
|
export { SetupWaterfall } from "./setup-waterfall"
|
|
31
31
|
|
|
32
|
-
export { WorkerStatusHistory, statusHistorySpans } from "./worker-status-history"
|
|
33
|
-
export type { WorkerStatusHistoryProps, WorkerStatusSpan } from "./worker-status-history"
|
|
32
|
+
export { WorkerStatusHistory, WorkerStatusHistoryTip, statusHistorySpans } from "./worker-status-history"
|
|
33
|
+
export type { WorkerStatusHistoryProps, WorkerStatusSpan, WorkerStatusHistoryTipProps } from "./worker-status-history"
|
|
34
34
|
|
|
35
35
|
export { ResourceBars } from "./resource-bars"
|
|
36
36
|
export type { ResourceBarsProps, WorkerStats } from "./resource-bars"
|
|
@@ -20,7 +20,9 @@ import { GitBranchChips, type GitRepoStatus } from "./git-branch-chips"
|
|
|
20
20
|
import { ResourceBars, type WorkerStats } from "./resource-bars"
|
|
21
21
|
import { SetupProgress, setupTotalMs } from "./setup-progress"
|
|
22
22
|
import { TagChips } from "./tag-chips"
|
|
23
|
-
import type { WorkerCardWorker, WorkerCreator } from "./types"
|
|
23
|
+
import type { WorkerCardWorker, WorkerCreator, WorkerStatusEvent } from "./types"
|
|
24
|
+
import { WorkerStatusHistoryTip } from "./worker-status-history"
|
|
25
|
+
import { Tooltip } from "../tooltip"
|
|
24
26
|
import { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus } from "./worker-status"
|
|
25
27
|
|
|
26
28
|
/** Renders the "View" affordance. A slot, so the package never imports `next/link`. */
|
|
@@ -113,6 +115,12 @@ export interface WorkerCardProps {
|
|
|
113
115
|
* finished task is drawn muted: the machine is free. Absent → no line.
|
|
114
116
|
*/
|
|
115
117
|
task?: { entry: WorkerTask; href: string }
|
|
118
|
+
/**
|
|
119
|
+
* Its status journal (`WorkerStatusEvent[]`, the same one `WorkerCockpit.statusHistory` takes):
|
|
120
|
+
* shown on hover (and focus) of the status pill, as `WorkerStatusHistoryTip` — the time spent in
|
|
121
|
+
* each state and the last stays. Omitted or empty → a plain pill.
|
|
122
|
+
*/
|
|
123
|
+
statusHistory?: WorkerStatusEvent[]
|
|
116
124
|
/** Replaces the default "View" footer entirely (extra buttons, an IDE link…). */
|
|
117
125
|
footer?: ReactNode
|
|
118
126
|
/** Label of the default footer button. */
|
|
@@ -160,6 +168,7 @@ export function WorkerCard({
|
|
|
160
168
|
actions,
|
|
161
169
|
task,
|
|
162
170
|
footer,
|
|
171
|
+
statusHistory,
|
|
163
172
|
viewLabel = "View",
|
|
164
173
|
className,
|
|
165
174
|
}: WorkerCardProps) {
|
|
@@ -211,7 +220,16 @@ export function WorkerCard({
|
|
|
211
220
|
{/* A worker name is one unbreakable token ("spunto-fix-tunnel-42"):
|
|
212
221
|
without the cap it pushes the card wider than its column. */}
|
|
213
222
|
<span className="max-w-full truncate text-sm leading-none font-semibold">{title}</span>
|
|
214
|
-
|
|
223
|
+
{statusHistory?.length ? (
|
|
224
|
+
// Its history on hover of its status, not as a band: the card stays what it is.
|
|
225
|
+
<Tooltip content={<WorkerStatusHistoryTip events={statusHistory} />} side="bottom" align="start">
|
|
226
|
+
<span tabIndex={0} data-slot="worker-status-history-trigger" className="inline-flex cursor-default rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring/40">
|
|
227
|
+
<WorkerStatusPill status={status} />
|
|
228
|
+
</span>
|
|
229
|
+
</Tooltip>
|
|
230
|
+
) : (
|
|
231
|
+
<WorkerStatusPill status={status} />
|
|
232
|
+
)}
|
|
215
233
|
{worker.projectVersion != null && (
|
|
216
234
|
<span className="inline-flex items-center rounded-full border border-border bg-muted px-2 py-0.5 font-mono text-[10px] leading-none text-muted-foreground">
|
|
217
235
|
v{worker.projectVersion}
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
LoaderIcon,
|
|
27
27
|
Maximize2Icon,
|
|
28
28
|
PanelRightOpenIcon,
|
|
29
|
+
PauseIcon,
|
|
29
30
|
PlayIcon,
|
|
30
31
|
RefreshCwIcon,
|
|
31
32
|
SquareIcon,
|
|
@@ -47,13 +48,24 @@ import { TagChips } from "./tag-chips"
|
|
|
47
48
|
import type { WorkerCockpitWorker, WorkerCreator, WorkerStatusEvent } from "./types"
|
|
48
49
|
import { type LinkRender } from "./worker-card"
|
|
49
50
|
import { WorkerSetupTimeline } from "./worker-setup-timeline"
|
|
50
|
-
import { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus } from "./worker-status"
|
|
51
|
+
import { IN_FLIGHT_STATUSES, WorkerStatusDot, WorkerStatusPill, inFlightMessage, resolveWorkerStatus } from "./worker-status"
|
|
51
52
|
import { WorkerStatusHistory } from "./worker-status-history"
|
|
52
53
|
import { WorkerTaskHistory } from "../tasks/worker-link"
|
|
53
54
|
import type { TaskItem } from "../tasks/types"
|
|
54
55
|
|
|
55
56
|
type CockpitTab = "logs" | "terminal"
|
|
56
57
|
|
|
58
|
+
export interface WorkerCockpitAction {
|
|
59
|
+
id: string
|
|
60
|
+
label: string
|
|
61
|
+
icon?: ComponentType<{ className?: string }>
|
|
62
|
+
hint?: string
|
|
63
|
+
onClick: () => void
|
|
64
|
+
/** In flight: the button is disabled and its icon spins. */
|
|
65
|
+
busy?: boolean
|
|
66
|
+
disabled?: boolean
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
export interface WorkerCockpitProps {
|
|
58
70
|
worker: WorkerCockpitWorker
|
|
59
71
|
/** Above the worker name, e.g. "my-project /". Omitted → no breadcrumb. */
|
|
@@ -97,6 +109,12 @@ export interface WorkerCockpitProps {
|
|
|
97
109
|
|
|
98
110
|
onStop?: () => void
|
|
99
111
|
stopping?: boolean
|
|
112
|
+
/**
|
|
113
|
+
* "Pause", next to Stop: stopped with its memory kept (a sandbox in a microVM, RFC 0039 § 20).
|
|
114
|
+
* Omitted → no button. A worker in `paused` is offered "Resume" (`onStart`) rather than "Start".
|
|
115
|
+
*/
|
|
116
|
+
onPause?: () => void
|
|
117
|
+
pausing?: boolean
|
|
100
118
|
onStart?: () => void
|
|
101
119
|
starting?: boolean
|
|
102
120
|
onRebuild?: () => void
|
|
@@ -107,6 +125,13 @@ export interface WorkerCockpitProps {
|
|
|
107
125
|
/** Fetches the one-shot SSH command; the cockpit copies it to the clipboard and owns the button's own idle/loading/copied state. */
|
|
108
126
|
onCopySsh?: () => Promise<string>
|
|
109
127
|
|
|
128
|
+
/**
|
|
129
|
+
* More of the worker's own actions, drawn like Rebuild in the Actions section — before it, in this
|
|
130
|
+
* order. What a host offers beyond the built-in ones (a sandbox's "Create snapshot", "Fork"…).
|
|
131
|
+
* `hint`: the muted words on the right. Shown whatever the worker's state: pass only what applies now.
|
|
132
|
+
*/
|
|
133
|
+
actions?: WorkerCockpitAction[]
|
|
134
|
+
|
|
110
135
|
/**
|
|
111
136
|
* The worker's status transitions, as journaled by the control plane. Omitted or empty → no
|
|
112
137
|
* History section. The current stay is measured up to `now` at render time.
|
|
@@ -147,6 +172,7 @@ const BANNER_TONES = {
|
|
|
147
172
|
offline: "border-orange-500/25 bg-orange-500/5 text-orange-600 dark:text-orange-400",
|
|
148
173
|
warn: "border-amber-500/25 bg-amber-500/5 text-amber-600 dark:text-amber-400",
|
|
149
174
|
error: "border-destructive/25 bg-destructive/5 text-destructive",
|
|
175
|
+
busy: "border-yellow-500/25 bg-yellow-500/5 text-yellow-700 dark:text-yellow-400",
|
|
150
176
|
} as const
|
|
151
177
|
|
|
152
178
|
function Banner({ tone, children }: { tone: keyof typeof BANNER_TONES; children: ReactNode }) {
|
|
@@ -190,6 +216,8 @@ export function WorkerCockpit({
|
|
|
190
216
|
onRemoveTag,
|
|
191
217
|
editorHref,
|
|
192
218
|
onStop,
|
|
219
|
+
onPause,
|
|
220
|
+
pausing,
|
|
193
221
|
stopping = false,
|
|
194
222
|
onStart,
|
|
195
223
|
starting = false,
|
|
@@ -198,6 +226,7 @@ export function WorkerCockpit({
|
|
|
198
226
|
onDelete,
|
|
199
227
|
deleting = false,
|
|
200
228
|
onCopySsh,
|
|
229
|
+
actions = [],
|
|
201
230
|
statusHistory,
|
|
202
231
|
tasks,
|
|
203
232
|
taskHref,
|
|
@@ -217,8 +246,11 @@ export function WorkerCockpit({
|
|
|
217
246
|
|
|
218
247
|
const status = resolveWorkerStatus(worker)
|
|
219
248
|
const settled = status.running && !status.settingUp
|
|
220
|
-
const
|
|
249
|
+
const isPaused = status.key === "paused"
|
|
250
|
+
const isStopped = worker.dockerState === "stopped" || worker.dockerState === "exited" || isPaused
|
|
221
251
|
const isDeleting = status.key === "deleting"
|
|
252
|
+
// Its memory being written, or on its way down: nothing else is offered meanwhile.
|
|
253
|
+
const inFlight = IN_FLIGHT_STATUSES.has(status.key)
|
|
222
254
|
const hasContainer = worker.containerId != null
|
|
223
255
|
const title = worker.name || (worker.index != null ? `Workspace #${worker.index}` : worker.id)
|
|
224
256
|
const outdated =
|
|
@@ -244,7 +276,7 @@ export function WorkerCockpit({
|
|
|
244
276
|
}
|
|
245
277
|
}
|
|
246
278
|
|
|
247
|
-
const showActions = !!((settled && onCopySsh) || (hasContainer && !status.settingUp && !isDeleting && onRebuild) || ((hasContainer || isDeleting) && nodeOnline !== false && onDelete))
|
|
279
|
+
const showActions = !!(actions.length > 0 || (settled && onCopySsh) || (hasContainer && !status.settingUp && !isDeleting && onRebuild) || ((hasContainer || isDeleting) && nodeOnline !== false && onDelete))
|
|
248
280
|
const hasTasks = !!taskHref && !!tasks?.some((t) => t.workerId === worker.id)
|
|
249
281
|
const showTags = (worker.tags?.length ?? 0) > 0 || !!onAddTag
|
|
250
282
|
|
|
@@ -260,6 +292,14 @@ export function WorkerCockpit({
|
|
|
260
292
|
)}
|
|
261
293
|
</Banner>
|
|
262
294
|
)}
|
|
295
|
+
{inFlight && inFlightMessage[status.key] && (
|
|
296
|
+
<Banner tone="busy">
|
|
297
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
298
|
+
<LoaderIcon className="h-3.5 w-3.5 shrink-0 animate-spin" />
|
|
299
|
+
{inFlightMessage[status.key]}
|
|
300
|
+
</span>
|
|
301
|
+
</Banner>
|
|
302
|
+
)}
|
|
263
303
|
{nodeOnline === false && (
|
|
264
304
|
<Banner tone="offline">
|
|
265
305
|
<span className="flex min-w-0 items-center gap-2">
|
|
@@ -406,15 +446,25 @@ export function WorkerCockpit({
|
|
|
406
446
|
<span className="text-[10px] text-muted-foreground/50">5 min token</span>
|
|
407
447
|
</button>
|
|
408
448
|
)}
|
|
449
|
+
{actions.map((a) => {
|
|
450
|
+
const Icon = a.icon
|
|
451
|
+
return (
|
|
452
|
+
<button key={a.id} type="button" disabled={a.disabled || a.busy || inFlight} onClick={a.onClick} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
|
|
453
|
+
{a.busy ? <LoaderIcon className="h-3.5 w-3.5 animate-spin text-muted-foreground" /> : Icon ? <Icon className="h-3.5 w-3.5 text-muted-foreground" /> : null}
|
|
454
|
+
<span className="font-medium">{a.label}</span>
|
|
455
|
+
{a.hint && <span className="ml-auto text-[10px] text-muted-foreground/50">{a.hint}</span>}
|
|
456
|
+
</button>
|
|
457
|
+
)
|
|
458
|
+
})}
|
|
409
459
|
{hasContainer && !status.settingUp && !isDeleting && onRebuild && (
|
|
410
|
-
<button type="button" disabled={rebuilding} onClick={onRebuild} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
|
|
460
|
+
<button type="button" disabled={rebuilding || inFlight} onClick={onRebuild} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
|
|
411
461
|
<RefreshCwIcon className={cn("h-3.5 w-3.5 text-muted-foreground", rebuilding && "animate-spin")} />
|
|
412
462
|
<span className="font-medium">Rebuild container</span>
|
|
413
463
|
<span className="ml-auto text-[10px] text-muted-foreground/50">keeps workspace</span>
|
|
414
464
|
</button>
|
|
415
465
|
)}
|
|
416
466
|
{(hasContainer || isDeleting) && nodeOnline !== false && onDelete && (
|
|
417
|
-
<button type="button" disabled={deleting ||
|
|
467
|
+
<button type="button" disabled={deleting || inFlight} onClick={onDelete} className="flex w-full items-center gap-2 rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50">
|
|
418
468
|
{isDeleting ? <LoaderIcon className="h-3.5 w-3.5 animate-spin" /> : <Trash2Icon className="h-3.5 w-3.5" />}
|
|
419
469
|
<span className="font-medium">Delete workspace</span>
|
|
420
470
|
<span className="ml-auto text-[10px] opacity-60">permanent</span>
|
|
@@ -498,14 +548,21 @@ export function WorkerCockpit({
|
|
|
498
548
|
<Code2Icon className="h-3.5 w-3.5" />Open IDE<ExternalLinkIcon className="h-2.5 w-2.5 opacity-70" />
|
|
499
549
|
</Link>
|
|
500
550
|
)}
|
|
501
|
-
{settled &&
|
|
502
|
-
<Button variant="ghost" size="sm" className="h-8 gap-1.5 px-3 text-xs text-muted-foreground
|
|
551
|
+
{settled && onPause && (
|
|
552
|
+
<Button variant="ghost" size="sm" className="h-8 gap-1.5 px-3 text-xs text-muted-foreground" disabled={pausing || stopping} onClick={onPause}>
|
|
553
|
+
<PauseIcon className="h-3.5 w-3.5" />Pause
|
|
554
|
+
</Button>
|
|
555
|
+
)}
|
|
556
|
+
{/* A paused box can be stopped too: its memory dropped. */}
|
|
557
|
+
{(settled || isPaused) && onStop && (
|
|
558
|
+
<Button variant="ghost" size="sm" className="h-8 gap-1.5 px-3 text-xs text-muted-foreground hover:bg-destructive/10 hover:text-destructive" disabled={stopping || pausing} onClick={onStop}>
|
|
503
559
|
<SquareIcon className="h-3.5 w-3.5" />Stop
|
|
504
560
|
</Button>
|
|
505
561
|
)}
|
|
506
562
|
{(isStopped || worker.dockerState === "error") && nodeOnline !== false && onStart && (
|
|
507
563
|
<Button variant="outline" size="sm" className="h-8 gap-1.5 px-3 text-xs" disabled={starting} onClick={onStart}>
|
|
508
|
-
<PlayIcon className="h-3.5 w-3.5" />
|
|
564
|
+
<PlayIcon className="h-3.5 w-3.5" />
|
|
565
|
+
{isPaused ? "Resume" : "Start"}
|
|
509
566
|
</Button>
|
|
510
567
|
)}
|
|
511
568
|
</div>
|
|
@@ -164,3 +164,44 @@ export function WorkerStatusHistory({ events, now, limit = 5, className }: Worke
|
|
|
164
164
|
</div>
|
|
165
165
|
)
|
|
166
166
|
}
|
|
167
|
+
|
|
168
|
+
export interface WorkerStatusHistoryTipProps {
|
|
169
|
+
/** The journal, in any order. Empty → nothing is drawn. */
|
|
170
|
+
events: WorkerStatusEvent[]
|
|
171
|
+
now?: number | Date
|
|
172
|
+
/** Stays listed, newest first. */
|
|
173
|
+
recent?: number
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The same journal, for a tooltip (`WorkerCard.statusHistory`, on hover of the status pill): the
|
|
178
|
+
* strip of time spent in each state, then the last stays, newest first. Drawn for the tooltip's
|
|
179
|
+
* inverted colours — the cockpit's `WorkerStatusHistory` has the reasons and the sources.
|
|
180
|
+
*/
|
|
181
|
+
export function WorkerStatusHistoryTip({ events, now, recent = 6 }: WorkerStatusHistoryTipProps) {
|
|
182
|
+
const nowMs = now instanceof Date ? now.getTime() : (now ?? Date.now())
|
|
183
|
+
const spans = statusHistorySpans(events, nowMs)
|
|
184
|
+
if (!spans.length) return null
|
|
185
|
+
const total = spans.reduce((sum, s) => sum + s.duration, 0)
|
|
186
|
+
const newestFirst = [...spans].reverse()
|
|
187
|
+
const shown = newestFirst.slice(0, recent)
|
|
188
|
+
return (
|
|
189
|
+
<div data-slot="worker-status-history-tip" className="w-56 space-y-2 py-1">
|
|
190
|
+
<div className="flex h-1.5 gap-px overflow-hidden rounded-sm" aria-hidden>
|
|
191
|
+
{spans.map((s, i) => (
|
|
192
|
+
<span key={i} className={cn("min-w-[3px] basis-0", s.status.dotClass)} style={{ flexGrow: total > 0 ? s.duration : 1 }} />
|
|
193
|
+
))}
|
|
194
|
+
</div>
|
|
195
|
+
<ol className="space-y-1">
|
|
196
|
+
{shown.map((s) => (
|
|
197
|
+
<li key={`${s.event.seq ?? ""}-${s.event.at}`} className={cn("flex items-center gap-1.5", !s.current && "opacity-75")}>
|
|
198
|
+
<WorkerStatusDot status={s.status} className="h-1.5 w-1.5" />
|
|
199
|
+
<span className="min-w-0 flex-1 truncate font-medium">{s.label}</span>
|
|
200
|
+
<span className="shrink-0 font-mono text-[10px] tabular-nums">{formatElapsed(s.duration)}</span>
|
|
201
|
+
</li>
|
|
202
|
+
))}
|
|
203
|
+
</ol>
|
|
204
|
+
{newestFirst.length > shown.length && <p className="text-[10px] opacity-60">+ {newestFirst.length - shown.length} earlier</p>}
|
|
205
|
+
</div>
|
|
206
|
+
)
|
|
207
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest"
|
|
2
|
-
import { resolveWorkerStatus, workerStatusConfig } from "./worker-status"
|
|
2
|
+
import { IN_FLIGHT_STATUSES, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
|
|
3
3
|
|
|
4
4
|
describe("resolveWorkerStatus — le node injoignable", () => {
|
|
5
5
|
it("ne prétend rien, et ne prétend surtout pas qu'un setup est en cours", () => {
|
|
@@ -85,3 +85,22 @@ describe("resolveWorkerStatus — la tolérance qui fait vivre la table", () =>
|
|
|
85
85
|
}
|
|
86
86
|
})
|
|
87
87
|
})
|
|
88
|
+
|
|
89
|
+
describe("resolveWorkerStatus — pause, stop, snapshot (RFC 0039 § 20)", () => {
|
|
90
|
+
it("une boîte en pause n'est pas arrêtée : sa propre pastille, et rien ne tourne", () => {
|
|
91
|
+
const s = resolveWorkerStatus({ id: "s", state: "paused", dockerState: "stopped" })
|
|
92
|
+
expect(s).toMatchObject({ key: "paused", label: "Paused", running: false, settingUp: false })
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it("pendant qu'elle écrit sa mémoire, elle n'est ni en marche ni en setup : en vol", () => {
|
|
96
|
+
for (const state of ["pausing", "snapshotting", "stopping"] as const) {
|
|
97
|
+
const s = resolveWorkerStatus({ id: "s", state })
|
|
98
|
+
expect(s.key).toBe(state)
|
|
99
|
+
expect(s.running).toBe(false)
|
|
100
|
+
expect(s.settingUp).toBe(false)
|
|
101
|
+
expect(IN_FLIGHT_STATUSES.has(s.key)).toBe(true)
|
|
102
|
+
}
|
|
103
|
+
expect(resolveWorkerStatus({ id: "s", state: "pausing" }).label).toBe("Pausing…")
|
|
104
|
+
expect(resolveWorkerStatus({ id: "s", state: "snapshotting" }).label).toBe("Snapshotting…")
|
|
105
|
+
})
|
|
106
|
+
})
|
|
@@ -39,6 +39,9 @@ export type WorkerStatusKey =
|
|
|
39
39
|
| "pulling"
|
|
40
40
|
| "stopping"
|
|
41
41
|
| "deleting"
|
|
42
|
+
| "pausing"
|
|
43
|
+
| "paused"
|
|
44
|
+
| "snapshotting"
|
|
42
45
|
|
|
43
46
|
export interface WorkerStatusConfig {
|
|
44
47
|
label: string
|
|
@@ -101,6 +104,32 @@ export const workerStatusConfig: Record<WorkerStatusKey, WorkerStatusConfig> = {
|
|
|
101
104
|
pulling: { ...BUSY, label: "Pulling image…" },
|
|
102
105
|
stopping: { ...BUSY, label: "Stopping…" },
|
|
103
106
|
deleting: { ...BUSY, label: "Deleting…" },
|
|
107
|
+
// A sandbox stopped with its memory (Spunto Cloud, RFC 0039 § 20): idle like a stopped one, but
|
|
108
|
+
// not the same promise — a start resumes it where it was, processes included. Blue, not grey:
|
|
109
|
+
// the one idle state that still holds something.
|
|
110
|
+
paused: {
|
|
111
|
+
label: "Paused",
|
|
112
|
+
dotClass: "bg-sky-500",
|
|
113
|
+
pillClass: "bg-sky-500/10 text-sky-700 dark:text-sky-400 border-sky-500/20",
|
|
114
|
+
accent: "border-l-sky-500",
|
|
115
|
+
},
|
|
116
|
+
// Its memory being written: nothing can be asked of it until then.
|
|
117
|
+
pausing: { ...BUSY, label: "Pausing…" },
|
|
118
|
+
snapshotting: { ...BUSY, label: "Snapshotting…" },
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Statuses during which nothing can be asked of a worker or a sandbox: its memory is being written
|
|
123
|
+
* (`pausing`, `snapshotting`), or it is on its way down. A host greys its actions out on these.
|
|
124
|
+
*/
|
|
125
|
+
export const IN_FLIGHT_STATUSES: ReadonlySet<WorkerStatusKey> = new Set(["pausing", "snapshotting", "stopping", "deleting"])
|
|
126
|
+
|
|
127
|
+
/** What a status in flight means for the reader, in one line — the cockpit's banner. */
|
|
128
|
+
export const inFlightMessage: Partial<Record<WorkerStatusKey, string>> = {
|
|
129
|
+
pausing: "Pausing — writing its memory to disk. Nothing else can be done until it is paused.",
|
|
130
|
+
snapshotting: "Snapshotting — frozen while its memory is written. It runs again once the snapshot is taken.",
|
|
131
|
+
stopping: "Stopping — shutting down. Its memory is not kept: the next start boots it.",
|
|
132
|
+
deleting: "Deleting…",
|
|
104
133
|
}
|
|
105
134
|
|
|
106
135
|
export interface WorkerStatus extends WorkerStatusConfig {
|
|
@@ -176,6 +205,10 @@ export function resolveWorkerStatus(worker: WorkerCardWorker): WorkerStatus {
|
|
|
176
205
|
|
|
177
206
|
if (state === "deleting") return of("deleting")
|
|
178
207
|
if (state === "stopping") return of("stopping")
|
|
208
|
+
if (state === "pausing") return of("pausing")
|
|
209
|
+
if (state === "paused") return of("paused")
|
|
210
|
+
// Frozen for a moment, not running for anyone who would act on it now (`running: false`).
|
|
211
|
+
if (state === "snapshotting") return of("snapshotting")
|
|
179
212
|
// Le node est injoignable : on ne sait pas. Surtout pas `settingUp` — annoncer une progression
|
|
180
213
|
// pour une machine qu'on ne voit plus est exactement ce que ce statut existe pour éviter.
|
|
181
214
|
if (state === "unknown") return of("unknown")
|