@spunto/design-system 0.78.0 → 0.79.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/design-system",
3
- "version": "0.78.0",
3
+ "version": "0.79.1",
4
4
  "description": "Spunto's shared design system — green tokens (conservatory + sprout), color constants, and UI primitives.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
- // devcontainer lifecycle commands — `postCreate` / `postStart`.
1
+ // devcontainer lifecycle commands — `postCreate` / `postStart` — and Spunto's `postSnapshot`.
2
2
  //
3
3
  // Generalised from Lite's local `LifecycleRow`; the dashboard wrote the same
4
4
  // block out twice by hand.
@@ -34,17 +34,20 @@ export function LifecycleCommand({ label, command, className }: LifecycleCommand
34
34
  export interface LifecycleCommandsProps {
35
35
  postCreateCommand?: string | null
36
36
  postStartCommand?: string | null
37
+ /** Run once in a sandbox started from a snapshot. */
38
+ postSnapshotCommand?: string | null
37
39
  className?: string
38
40
  }
39
41
 
40
- /** Both lifecycle blocks, each rendered only when the project defines it. */
41
- export function LifecycleCommands({ postCreateCommand, postStartCommand, className }: LifecycleCommandsProps) {
42
- if (!postCreateCommand && !postStartCommand) return null
42
+ /** The lifecycle blocks, each rendered only when the project defines it. */
43
+ export function LifecycleCommands({ postCreateCommand, postStartCommand, postSnapshotCommand, className }: LifecycleCommandsProps) {
44
+ if (!postCreateCommand && !postStartCommand && !postSnapshotCommand) return null
43
45
 
44
46
  return (
45
47
  <div data-slot="lifecycle-commands" className={cn("space-y-1.5", className)}>
46
48
  {postCreateCommand && <LifecycleCommand label="postCreate" command={postCreateCommand} />}
47
49
  {postStartCommand && <LifecycleCommand label="postStart" command={postStartCommand} />}
50
+ {postSnapshotCommand && <LifecycleCommand label="postSnapshot" command={postSnapshotCommand} />}
48
51
  </div>
49
52
  )
50
53
  }
@@ -47,6 +47,7 @@ export interface ProjectPanelProject {
47
47
  forwardPorts?: (number | string)[]
48
48
  postCreateCommand?: string | null
49
49
  postStartCommand?: string | null
50
+ postSnapshotCommand?: string | null
50
51
  /** Public half of the project's SSH deploy key (RFC 0013). */
51
52
  deployPublicKey?: string | null
52
53
  }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The lifecycle section's third command, `postSnapshotCommand`, is Spunto's own: offered only to an
3
+ * app whose value holds it (`""` included), so a form without it (Lite) does not show a field it
4
+ * has nowhere to save.
5
+ */
6
+ import { describe, it, expect } from "vitest"
7
+ import { useState } from "react"
8
+ import { render, screen, fireEvent } from "@testing-library/react"
9
+ import { ProjectForm } from "./project-form"
10
+ import { emptyProjectFormValue, type ProjectFormValue } from "./types"
11
+
12
+ function Harness({ initial, onValue }: { initial: ProjectFormValue; onValue?: (v: ProjectFormValue) => void }) {
13
+ const [value, setValue] = useState(initial)
14
+ return (
15
+ <ProjectForm
16
+ value={value}
17
+ onChange={(v) => {
18
+ setValue(v)
19
+ onValue?.(v)
20
+ }}
21
+ sections={["lifecycle"]}
22
+ defaultAdvancedOpen
23
+ />
24
+ )
25
+ }
26
+
27
+ describe("ProjectForm — lifecycle commands", () => {
28
+ it("offers no post-snapshot command to a value without one", () => {
29
+ render(<Harness initial={emptyProjectFormValue()} />)
30
+ expect(screen.getByLabelText(/Post-start command/)).toBeTruthy()
31
+ expect(screen.queryByLabelText(/Post-snapshot command/)).toBeNull()
32
+ })
33
+
34
+ it("offers it, and edits it, when the value holds one", () => {
35
+ let last: ProjectFormValue | null = null
36
+ render(<Harness initial={{ ...emptyProjectFormValue(), postSnapshotCommand: "" }} onValue={(v) => (last = v)} />)
37
+ fireEvent.change(screen.getByLabelText(/Post-snapshot command/), { target: { value: "./catch-up.sh" } })
38
+ expect(last!.postSnapshotCommand).toBe("./catch-up.sh")
39
+ })
40
+ })
@@ -656,6 +656,18 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
656
656
  onChange={(e) => patch({ postStartCommand: e.target.value })}
657
657
  />
658
658
  </Field>
659
+ {value.postSnapshotCommand !== undefined && (
660
+ <Field label="Post-snapshot command" htmlFor="post-snapshot" hint="Runs once in a sandbox started from a snapshot, after it fetched">
661
+ <Input
662
+ id="post-snapshot"
663
+ name="postSnapshotCommand"
664
+ placeholder="./catch-up.sh"
665
+ className="font-mono text-xs"
666
+ value={value.postSnapshotCommand}
667
+ onChange={(e) => patch({ postSnapshotCommand: e.target.value })}
668
+ />
669
+ </Field>
670
+ )}
659
671
  </div>
660
672
  )
661
673
 
@@ -781,9 +793,9 @@ export function manifestRows<TValue extends ProjectFormValue>(
781
793
  rows.push({
782
794
  label: "lifecycle",
783
795
  value:
784
- [value.postCreateCommand && "create", value.postStartCommand && "start"].filter(Boolean).join(" + ") ||
796
+ [value.postCreateCommand && "create", value.postStartCommand && "start", value.postSnapshotCommand && "snapshot"].filter(Boolean).join(" + ") ||
785
797
  "default",
786
- done: !!(value.postCreateCommand || value.postStartCommand),
798
+ done: !!(value.postCreateCommand || value.postStartCommand || value.postSnapshotCommand),
787
799
  })
788
800
  if (shown.has("ports"))
789
801
  rows.push({ label: "ports", value: value.forwardPorts.join(", ") || "—", done: value.forwardPorts.length > 0 })
@@ -264,11 +264,12 @@ export function ProjectPanel({
264
264
  </PanelSection>
265
265
  )}
266
266
 
267
- {(project.postCreateCommand || project.postStartCommand) && (
267
+ {(project.postCreateCommand || project.postStartCommand || project.postSnapshotCommand) && (
268
268
  <PanelSection title="Lifecycle">
269
269
  <LifecycleCommands
270
270
  postCreateCommand={project.postCreateCommand}
271
271
  postStartCommand={project.postStartCommand}
272
+ postSnapshotCommand={project.postSnapshotCommand}
272
273
  />
273
274
  </PanelSection>
274
275
  )}
@@ -42,7 +42,7 @@ export function sectionSummary<TValue extends ProjectFormValue>(
42
42
  case "extensions":
43
43
  return value.vscodeExtensions.length ? plural(value.vscodeExtensions.length, "extension") : null
44
44
  case "lifecycle":
45
- return value.postCreateCommand || value.postStartCommand ? "lifecycle" : null
45
+ return value.postCreateCommand || value.postStartCommand || value.postSnapshotCommand ? "lifecycle" : null
46
46
  case "ports":
47
47
  return value.forwardPorts.length ? `ports ${value.forwardPorts.join(", ")}` : null
48
48
  case "prewarm":
@@ -94,6 +94,11 @@ export interface ProjectFormValue {
94
94
  vscodeExtensions: string[]
95
95
  postCreateCommand: string
96
96
  postStartCommand: string
97
+ /**
98
+ * Run once in a sandbox started from a snapshot (Spunto's own, not devcontainer's). The field is
99
+ * offered only to an app that has it: present in its value — `""` included — not `undefined`.
100
+ */
101
+ postSnapshotCommand?: string
97
102
  /** Secrets typed in this session. */
98
103
  secrets: ProjectSecretDraft[]
99
104
  /** Ids of already-saved secrets the user asked to remove. */
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What the cockpit's panel says about the sandbox it shows, and an error that can be read to its
3
+ * end. jsdom has no layout: "the text is cut" is what `scrollHeight`/`clientHeight` are made to say.
4
+ */
5
+ import { afterEach, describe, expect, it, vi } from "vitest"
6
+ import { fireEvent, render, screen } from "@testing-library/react"
7
+
8
+ import { WorkerCockpit, type WorkerCockpitProps } from "./worker-cockpit"
9
+
10
+ const cockpit = (over: Partial<WorkerCockpitProps> = {}) => (
11
+ <WorkerCockpit
12
+ worker={{ id: "sb1", name: "box", state: "ready", dockerState: "running", containerId: "3f9a8c1d2b7e4a55" }}
13
+ activeTab="logs"
14
+ onTabChange={() => {}}
15
+ logsContent={null}
16
+ terminalContent={null}
17
+ {...over}
18
+ />
19
+ )
20
+
21
+ /** The panel is drawn in the sidebar and in the mobile drawer: the first one is enough. */
22
+ const first = (text: string) => screen.getAllByText(text)[0]
23
+
24
+ function layout(scrollHeight: number, clientHeight: number) {
25
+ vi.spyOn(HTMLElement.prototype, "scrollHeight", "get").mockReturnValue(scrollHeight)
26
+ vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(clientHeight)
27
+ }
28
+
29
+ afterEach(() => vi.restoreAllMocks())
30
+
31
+ describe("WorkerCockpit", () => {
32
+ it("names the sandbox, and the directory a rebuild keeps", () => {
33
+ render(cockpit({ onRebuild: () => {}, onDelete: () => {} }))
34
+ expect(first("Delete sandbox")).toBeTruthy()
35
+ expect(first("keeps /workspace")).toBeTruthy()
36
+ expect(first("Sandbox").nextElementSibling?.textContent).toBe("3f9a8c1d2b7e")
37
+ expect(screen.queryByText("Delete workspace")).toBeNull()
38
+ expect(screen.queryByText("Container")).toBeNull()
39
+ })
40
+
41
+ it("unfolds an error that is cut, and folds it back", () => {
42
+ layout(48, 32)
43
+ const error = "stopped by the platform: its task dqfopoo1fi4qvt2izrdym is accepted (done)"
44
+ render(cockpit({ error }))
45
+ expect(first(error).className).toContain("line-clamp-2")
46
+
47
+ fireEvent.click(screen.getAllByRole("button", { name: "Show full error" })[0])
48
+ expect(first(error).className).not.toContain("line-clamp-2")
49
+
50
+ fireEvent.click(screen.getAllByRole("button", { name: "Show less" })[0])
51
+ expect(first(error).className).toContain("line-clamp-2")
52
+ })
53
+
54
+ it("offers nothing to unfold when the error fits", () => {
55
+ layout(32, 32)
56
+ render(cockpit({ error: "disk almost full" }))
57
+ expect(first("disk almost full")).toBeTruthy()
58
+ expect(screen.queryByRole("button", { name: "Show full error" })).toBeNull()
59
+ })
60
+ })
@@ -12,7 +12,7 @@
12
12
  // same cockpit be driven by the dashboard's react-query hooks today and by
13
13
  // hand-written fixtures in the showcase.
14
14
 
15
- import { useState, type ComponentType, type ReactNode } from "react"
15
+ import { useEffect, useRef, useState, type ComponentType, type ReactNode } from "react"
16
16
  import { Drawer as DrawerPrimitive } from "vaul"
17
17
  import {
18
18
  AlertTriangleIcon,
@@ -187,6 +187,51 @@ function Banner({ tone, children }: { tone: keyof typeof BANNER_TONES; children:
187
187
  )
188
188
  }
189
189
 
190
+ /**
191
+ * The sandbox's error, readable. Two lines so a long one doesn't push the panel down, expandable
192
+ * because what matters ("…its task X is done") is often past the cut. Whether it is cut is
193
+ * measured, not guessed from its length: the panel is narrow, and how much fits depends on it.
194
+ */
195
+ function ErrorBanner({ text, onDismiss }: { text: string; onDismiss?: () => void }) {
196
+ const [open, setOpen] = useState(false)
197
+ const [clamped, setClamped] = useState(false)
198
+ const ref = useRef<HTMLSpanElement>(null)
199
+
200
+ useEffect(() => {
201
+ const el = ref.current
202
+ if (!el || open) return
203
+ const measure = () => setClamped(el.scrollHeight > el.clientHeight + 1)
204
+ measure()
205
+ if (typeof ResizeObserver === "undefined") return
206
+ const observer = new ResizeObserver(measure)
207
+ observer.observe(el)
208
+ return () => observer.disconnect()
209
+ }, [text, open])
210
+
211
+ return (
212
+ <Banner tone="error">
213
+ <div className="min-w-0 flex-1">
214
+ <span ref={ref} className={cn("font-mono break-words", open ? "block whitespace-pre-wrap" : "line-clamp-2")}>{text}</span>
215
+ {(clamped || open) && (
216
+ <button
217
+ type="button"
218
+ aria-expanded={open}
219
+ onClick={() => setOpen((v) => !v)}
220
+ className="mt-1 cursor-pointer text-[10px] font-medium text-destructive/80 transition-colors hover:text-destructive"
221
+ >
222
+ {open ? "Show less" : "Show full error"}
223
+ </button>
224
+ )}
225
+ </div>
226
+ {onDismiss && (
227
+ <button type="button" onClick={onDismiss} aria-label="Dismiss error" className="mt-px shrink-0 cursor-pointer self-start opacity-60 transition-opacity hover:opacity-100">
228
+ <XIcon className="h-3.5 w-3.5" />
229
+ </button>
230
+ )}
231
+ </Banner>
232
+ )
233
+ }
234
+
190
235
  function InfoRow({ label, children }: { label: string; children: ReactNode }) {
191
236
  return (
192
237
  <div className="flex items-center justify-between px-3 py-2">
@@ -286,16 +331,8 @@ export function WorkerCockpit({
286
331
 
287
332
  const controlPanel = (
288
333
  <>
289
- {error && (
290
- <Banner tone="error">
291
- <span className="line-clamp-2 min-w-0 flex-1 font-mono break-words">{error}</span>
292
- {onDismissError && (
293
- <button type="button" onClick={onDismissError} aria-label="Dismiss error" className="shrink-0 cursor-pointer opacity-60 transition-opacity hover:opacity-100">
294
- <XIcon className="h-3.5 w-3.5" />
295
- </button>
296
- )}
297
- </Banner>
298
- )}
334
+ {/* Keyed by its text: another error starts folded. */}
335
+ {error && <ErrorBanner key={error} text={error} onDismiss={onDismissError} />}
299
336
  {inFlight && inFlightMessage[status.key] && (
300
337
  <Banner tone="busy">
301
338
  <span className="flex min-w-0 items-center gap-2">
@@ -447,13 +484,13 @@ export function WorkerCockpit({
447
484
  <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">
448
485
  <RefreshCwIcon className={cn("h-3.5 w-3.5 text-muted-foreground", rebuilding && "animate-spin")} />
449
486
  <span className="font-medium">Rebuild container</span>
450
- <span className="ml-auto text-[10px] text-muted-foreground/50">keeps workspace</span>
487
+ <span className="ml-auto text-[10px] text-muted-foreground/50">keeps /workspace</span>
451
488
  </button>
452
489
  )}
453
490
  {(hasContainer || isDeleting) && nodeOnline !== false && onDelete && (
454
491
  <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">
455
492
  {isDeleting ? <LoaderIcon className="h-3.5 w-3.5 animate-spin" /> : <Trash2Icon className="h-3.5 w-3.5" />}
456
- <span className="font-medium">Delete workspace</span>
493
+ <span className="font-medium">Delete sandbox</span>
457
494
  <span className="ml-auto text-[10px] opacity-60">permanent</span>
458
495
  </button>
459
496
  )}
@@ -496,7 +533,7 @@ export function WorkerCockpit({
496
533
  </InfoRow>
497
534
  )}
498
535
  {worker.createdAt && <InfoRow label="Created"><span className="text-[11px] text-muted-foreground">{formatRelativeTime(worker.createdAt)}</span></InfoRow>}
499
- {worker.containerId && <InfoRow label="Container"><span className="font-mono text-[11px] text-muted-foreground">{worker.containerId.slice(0, 12)}</span></InfoRow>}
536
+ {worker.containerId && <InfoRow label="Sandbox"><span className="font-mono text-[11px] text-muted-foreground">{worker.containerId.slice(0, 12)}</span></InfoRow>}
500
537
  </div>
501
538
  </div>
502
539
  </>