@hyperframes/studio 0.9.31 → 0.9.33

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.
Files changed (31) hide show
  1. package/dist/assets/{codec-DXM4vA6G.js → codec-qz1-OXLj.js} +1 -1
  2. package/dist/assets/{hyperframes-player-D_016Ubp.js → hyperframes-player-2eG1zFX5.js} +1 -1
  3. package/dist/assets/{index-dsfjBidg.css → index-BJTCbv8z.css} +1 -1
  4. package/dist/assets/{index-Ob53qo6K.js → index-DDmhnfrS.js} +189 -189
  5. package/dist/assets/{index-Bw4stQMm.js → index-DUveJ_YP.js} +1 -1
  6. package/dist/assets/{pausedVideoDecoder-vbdgaMqL.js → pausedVideoDecoder-CoHTKUjM.js} +1 -1
  7. package/dist/{chunk-J3VJE463.js → chunk-52AJB4PN.js} +4 -1
  8. package/dist/{chunk-LRTUWOR4.js → chunk-YKBN653R.js} +1 -1
  9. package/dist/index.html +2 -2
  10. package/dist/index.js +2054 -1392
  11. package/dist/player.js +2 -2
  12. package/dist/styles.css +1 -1
  13. package/dist/ui.js +1 -1
  14. package/package.json +8 -8
  15. package/src/App.tsx +1 -0
  16. package/src/components/StudioHeader.tsx +4 -0
  17. package/src/components/share/QuickShare.test.tsx +622 -0
  18. package/src/components/share/QuickShare.tsx +104 -0
  19. package/src/components/share/QuickShareControls.tsx +265 -0
  20. package/src/components/share/ShareAudience.tsx +120 -0
  21. package/src/components/share/localShareClient.ts +171 -0
  22. package/src/components/share/localShareTelemetry.test.ts +22 -0
  23. package/src/components/share/localShareTelemetry.ts +13 -0
  24. package/src/components/share/useQuickShare.ts +215 -0
  25. package/src/components/sidebar/CompositionsTab.hoverPreview.test.tsx +100 -0
  26. package/src/components/sidebar/CompositionsTab.test.ts +2 -24
  27. package/src/components/sidebar/CompositionsTab.tsx +35 -100
  28. package/src/components/ui/Input.tsx +4 -1
  29. package/src/components/ui/valueControls.test.tsx +85 -0
  30. package/src/webmcp/polyfill.transport.test.ts +59 -0
  31. package/src/webmcp/polyfill.ts +15 -0
@@ -0,0 +1,622 @@
1
+ // @vitest-environment happy-dom
2
+ import React, { act } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { afterEach, beforeEach, expect, it, vi } from "vitest";
5
+ import type { LocalShareSnapshot, LocalShareJob } from "@hyperframes/studio-server";
6
+ import type { Button } from "../ui/Button";
7
+ type ButtonProps = React.ComponentProps<typeof Button>;
8
+
9
+ const interaction = vi.hoisted(() => vi.fn());
10
+ vi.mock("./localShareTelemetry", () => ({ shareInteraction: interaction }));
11
+ vi.mock("../ui", () => ({
12
+ Button: ({ children, variant: _variant, ...props }: ButtonProps) => (
13
+ <button {...props}>{children}</button>
14
+ ),
15
+ Menu: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
16
+ MenuRadioGroup: ({
17
+ children,
18
+ value,
19
+ onValueChange,
20
+ }: {
21
+ children: React.ReactNode;
22
+ value: string;
23
+ onValueChange: (value: string) => void;
24
+ }) => (
25
+ <select
26
+ aria-label="Who can access"
27
+ value={value}
28
+ onChange={(event) => onValueChange(event.target.value)}
29
+ >
30
+ <option value="">Choose access</option>
31
+ {children}
32
+ </select>
33
+ ),
34
+ MenuRadioItem: ({ value, disabled }: { value: string; disabled?: boolean }) => (
35
+ <option value={value} disabled={disabled}>
36
+ {value === "private" ? "Only you" : value}
37
+ </option>
38
+ ),
39
+ Popover: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
40
+ }));
41
+ const { QuickShare, QuickShareContent } = await import("./QuickShare");
42
+ Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
43
+ let root: Root;
44
+ let host: HTMLDivElement;
45
+ let snapshot: LocalShareSnapshot;
46
+ let calls: unknown[];
47
+ let job: LocalShareJob;
48
+ const token = "a".repeat(43);
49
+ beforeEach(() => {
50
+ interaction.mockReset();
51
+ calls = [];
52
+ snapshot = {
53
+ versionSharing: true,
54
+ share: {
55
+ source: "not_checked",
56
+ state: "not_shared",
57
+ url: null,
58
+ manageUrl: "https://hyperframes.dev/shares",
59
+ changed: false,
60
+ audience: null,
61
+ spaceId: null,
62
+ },
63
+ spaces: [
64
+ {
65
+ id: "team1",
66
+ name: "Design team",
67
+ bound: true,
68
+ canCreate: true,
69
+ audiences: ["public", "private", "invite"],
70
+ used: 5,
71
+ limit: 5,
72
+ },
73
+ ],
74
+ job: null,
75
+ };
76
+ job = { id: "job1", state: "running", step: "uploading", result: null, error: null };
77
+ host = document.createElement("div");
78
+ document.body.append(host);
79
+ root = createRoot(host);
80
+ vi.stubGlobal(
81
+ "fetch",
82
+ vi.fn(async (url: string, init?: RequestInit) => {
83
+ expect(new Headers(init?.headers).get("X-Hyperframes-Share-CSRF")).toBe(token);
84
+ if (url.endsWith("/snapshot")) return Response.json(snapshot);
85
+ if (url.endsWith("/actions")) {
86
+ calls.push(JSON.parse(String(init?.body)));
87
+ return Response.json(job, { status: 202 });
88
+ }
89
+ return Response.json(job);
90
+ }),
91
+ );
92
+ });
93
+ afterEach(() => {
94
+ act(() => root.unmount());
95
+ host.remove();
96
+ vi.unstubAllGlobals();
97
+ vi.useRealTimers();
98
+ });
99
+ const button = (label: string) =>
100
+ [...host.querySelectorAll("button")].find((element) => element.textContent === label);
101
+ async function mount(beforeShare?: () => Promise<void>) {
102
+ await act(async () => root.render(<QuickShareContent token={token} beforeShare={beforeShare} />));
103
+ }
104
+ async function choose(value: string) {
105
+ const select = host.querySelector<HTMLSelectElement>('[aria-label="Who can access"]');
106
+ if (!select) throw new Error("Missing audience");
107
+ await act(async () => {
108
+ select.value = value;
109
+ select.dispatchEvent(new Event("change", { bubbles: true }));
110
+ });
111
+ }
112
+ it("requires explicit audience, uses the bound workspace and permits server-authoritative quota retries", async () => {
113
+ await mount();
114
+ expect(host.textContent).toContain("5 of 5 free share links used");
115
+ expect(button("Create share link")?.disabled).toBe(true);
116
+ expect(calls).toEqual([]);
117
+ await choose("public");
118
+ expect(button("Create share link")?.disabled).toBe(false);
119
+ await act(async () => button("Create share link")?.click());
120
+ expect(calls).toEqual([
121
+ { action: "share", audience: "public", space: "team1", includeSource: false },
122
+ ]);
123
+ });
124
+ it("drains pending editor saves before creating or uploading", async () => {
125
+ let resolveSave = () => {};
126
+ const save = vi.fn(
127
+ () =>
128
+ new Promise<void>((resolve) => {
129
+ resolveSave = resolve;
130
+ }),
131
+ );
132
+ await mount(save);
133
+ await choose("public");
134
+ await act(async () => button("Create share link")?.click());
135
+ expect(save).toHaveBeenCalledOnce();
136
+ expect(calls).toEqual([]);
137
+ await act(async () => resolveSave());
138
+ expect(calls).toHaveLength(1);
139
+ });
140
+ it("does not publish when saving fails", async () => {
141
+ await mount(async () => {
142
+ throw new Error("write failed");
143
+ });
144
+ await choose("public");
145
+ await act(async () => button("Create share link")?.click());
146
+ expect(calls).toEqual([]);
147
+ expect(host.querySelector('[role="alert"]')).not.toBeNull();
148
+ });
149
+ it("shows stale copy separately and never uploads merely by opening", async () => {
150
+ snapshot.share = {
151
+ ...snapshot.share,
152
+ state: "ready",
153
+ url: "https://hyperframes.dev/r/live",
154
+ changed: true,
155
+ audience: "private",
156
+ spaceId: "team1",
157
+ };
158
+ await mount();
159
+ expect(button("Copy current shared link")).toBeDefined();
160
+ expect(calls).toEqual([]);
161
+ await act(async () => button("Update shared version")?.click());
162
+ expect(calls).toEqual([{ action: "update", includeSource: false }]);
163
+ });
164
+ it("keeps link-off updates separate from explicit re-enabling", async () => {
165
+ snapshot.share = { ...snapshot.share, state: "link_off", audience: "private", spaceId: "team1" };
166
+ await mount();
167
+ expect(button("Turn link on")).toBeDefined();
168
+ await act(async () => button("Update shared version")?.click());
169
+ expect(calls).toEqual([{ action: "update", includeSource: false }]);
170
+ });
171
+ it("recovers a running job on reopening, and stops browser polling on close", async () => {
172
+ vi.useFakeTimers();
173
+ snapshot.job = job;
174
+ await mount();
175
+ expect(host.textContent).toContain("Uploading your video");
176
+ expect(calls).toEqual([]);
177
+ await act(async () => root.render(null));
178
+ const before = vi.mocked(fetch).mock.calls.length;
179
+ await act(async () => vi.advanceTimersByTime(3000));
180
+ expect(vi.mocked(fetch).mock.calls.length).toBe(before);
181
+ await mount();
182
+ expect(host.textContent).toContain("Uploading your video");
183
+ expect(calls).toEqual([]);
184
+ });
185
+ it("hides creation while feature is off but keeps existing management", async () => {
186
+ snapshot.versionSharing = false;
187
+ snapshot.share = { ...snapshot.share, state: "link_off", audience: "private", spaceId: "team1" };
188
+ await mount();
189
+ expect(button("Update shared version")).toBeUndefined();
190
+ expect(button("Turn link on")).toBeDefined();
191
+ });
192
+ it("recovers a failed job on reopening instead of silently dropping the error", async () => {
193
+ snapshot.job = {
194
+ ...job,
195
+ state: "failed",
196
+ error: { code: "share_failed", message: "The upload failed. Try again." },
197
+ };
198
+ await mount();
199
+ expect(host.querySelector('[role="alert"]')?.textContent).toContain("The upload failed");
200
+ expect(calls).toEqual([]);
201
+ });
202
+
203
+ it("offers video-only recovery explicitly after a failed source upload", async () => {
204
+ snapshot.share = {
205
+ ...snapshot.share,
206
+ state: "processing",
207
+ audience: "private",
208
+ spaceId: "team1",
209
+ };
210
+ snapshot.job = {
211
+ ...job,
212
+ state: "failed",
213
+ error: { code: "source_unavailable", message: "Project files could not be attached." },
214
+ };
215
+ await mount();
216
+ expect(calls).toEqual([]);
217
+ await act(async () => button("Retry with video only")?.click());
218
+ expect(calls).toEqual([{ action: "update", videoOnly: true, includeSource: false }]);
219
+ });
220
+ it("labels files as included only after a ready upload result", async () => {
221
+ snapshot.job = {
222
+ ...job,
223
+ state: "done",
224
+ result: { ...snapshot.share, state: "ready", source: "ready" },
225
+ };
226
+ await mount();
227
+ expect(host.textContent).toContain("Last Studio upload: project files included.");
228
+ });
229
+ it.each(["unauthenticated", "login_expired"])(
230
+ "offers explicit browser login for %s and recovers signed-out polling",
231
+ async (code) => {
232
+ vi.stubGlobal(
233
+ "fetch",
234
+ vi.fn(async (url: string, init?: RequestInit) => {
235
+ if (url.endsWith("/actions")) {
236
+ calls.push(JSON.parse(String(init?.body)));
237
+ return Response.json({ ...job, step: "signing_in" });
238
+ }
239
+ return Response.json({ code, message: "Sign in to share.", job: null }, { status: 400 });
240
+ }),
241
+ );
242
+ await mount();
243
+ expect(calls).toEqual([]);
244
+ expect(button("Sign in")).toBeDefined();
245
+ await act(async () => button("Sign in")?.click());
246
+ expect(calls).toEqual([{ action: "login" }]);
247
+ expect(host.textContent).toContain("Finish signing in in your browser");
248
+ },
249
+ );
250
+
251
+ it("records a copy only after the clipboard succeeds and opening once per panel", async () => {
252
+ snapshot.share = {
253
+ ...snapshot.share,
254
+ state: "ready",
255
+ url: "https://hyperframes.dev/r/old",
256
+ audience: "private",
257
+ spaceId: "team1",
258
+ };
259
+ const copy = vi.spyOn(navigator.clipboard, "writeText");
260
+ copy.mockRejectedValueOnce(new Error("denied")).mockResolvedValue(undefined);
261
+ await mount();
262
+ expect(interaction).toHaveBeenCalledExactlyOnceWith(token, {
263
+ event: "share_opened",
264
+ link: "live",
265
+ });
266
+ await act(async () => button("Copy link")?.click());
267
+ expect(interaction).toHaveBeenCalledTimes(1);
268
+ await act(async () => button("Copy link")?.click());
269
+ expect(interaction).toHaveBeenLastCalledWith(token, { event: "share_link_copied", via: "copy" });
270
+ expect(calls).toEqual([]);
271
+ copy.mockRestore();
272
+ });
273
+
274
+ it("clears account-specific links and workspace controls after an identity failure", async () => {
275
+ snapshot.share = {
276
+ ...snapshot.share,
277
+ state: "ready",
278
+ url: "https://hyperframes.dev/r/private",
279
+ audience: "private",
280
+ spaceId: "team1",
281
+ };
282
+ await mount();
283
+ expect(button("Copy link")).toBeDefined();
284
+ vi.mocked(fetch).mockResolvedValue(
285
+ Response.json({ code: "login_changed", message: "Your login changed" }, { status: 400 }),
286
+ );
287
+ await act(async () => button("Update shared version")?.click());
288
+ expect(button("Copy link")).toBeUndefined();
289
+ expect(button("Update shared version")).toBeUndefined();
290
+ expect(host.querySelector('[aria-label="Sharing workspace"]')).toBeNull();
291
+ expect(host.textContent).not.toContain("Design team");
292
+ expect(button("Sign in")).toBeDefined();
293
+ });
294
+
295
+ it("does not claim an older upload is current when its portable content identity is unknown", async () => {
296
+ snapshot.share = {
297
+ ...snapshot.share,
298
+ state: "ready",
299
+ changed: null,
300
+ url: "https://hyperframes.dev/r/live",
301
+ };
302
+ await mount();
303
+ expect(button("Copy current shared link")).toBeDefined();
304
+ expect(host.textContent).toContain("Changes after your last upload aren’t shared automatically");
305
+ });
306
+
307
+ it("continues from a running browser login to fresh controls without refreshing or publishing", async () => {
308
+ vi.useFakeTimers();
309
+ let signedIn = false;
310
+ const loginJob = { ...job, step: "signing_in" };
311
+ vi.mocked(fetch).mockImplementation(async (url, init) => {
312
+ const path = String(url);
313
+ if (path.endsWith("/actions")) {
314
+ calls.push(JSON.parse(String(init?.body)));
315
+ return Response.json(loginJob, { status: 202 });
316
+ }
317
+ if (path.includes("/jobs/"))
318
+ return Response.json(
319
+ signedIn ? { ...loginJob, state: "done", result: snapshot.share } : loginJob,
320
+ );
321
+ return signedIn
322
+ ? Response.json({ ...snapshot, job: { ...loginJob, state: "done", result: snapshot.share } })
323
+ : Response.json({ code: "login_expired", message: "Sign in again." }, { status: 400 });
324
+ });
325
+ await mount();
326
+ await act(async () => button("Sign in")?.click());
327
+ await act(async () => vi.advanceTimersByTime(1000));
328
+ expect(host.textContent).toContain("Finish signing in");
329
+ signedIn = true;
330
+ await act(async () => vi.advanceTimersByTime(1000));
331
+ expect(button("Sign in")).toBeUndefined();
332
+ expect(host.querySelector('[aria-label="Who can access"]')).not.toBeNull();
333
+ expect(button("Create share link")?.disabled).toBe(true);
334
+ expect(calls).toEqual([{ action: "login" }]);
335
+ });
336
+
337
+ it.each(["snapshot", "poll"])(
338
+ "reconnects on return after a %s error without a refresh press",
339
+ async (failureAt) => {
340
+ vi.useFakeTimers();
341
+ let restored = false;
342
+ snapshot.job = failureAt === "poll" ? { ...job, step: "signing_in" } : null;
343
+ vi.mocked(fetch).mockImplementation(async (url) => {
344
+ if (restored) return Response.json({ ...snapshot, job: null });
345
+ if (failureAt === "snapshot")
346
+ return Response.json({ code: "login_expired", message: "Sign in again." }, { status: 400 });
347
+ if (String(url).includes("/jobs/")) throw new Error("Connection lost");
348
+ return Response.json(snapshot);
349
+ });
350
+ await mount();
351
+ if (failureAt === "poll") await act(async () => vi.advanceTimersByTime(1000));
352
+ restored = true;
353
+ await act(async () => window.dispatchEvent(new Event("focus")));
354
+ expect(host.querySelector('[aria-label="Who can access"]')).not.toBeNull();
355
+ expect(button("Create share link")?.disabled).toBe(true);
356
+ expect(calls).toEqual([]);
357
+ },
358
+ );
359
+
360
+ it("keeps audience choices when a healthy panel regains focus", async () => {
361
+ await mount();
362
+ await choose("invite");
363
+ const requests = vi.mocked(fetch).mock.calls.length;
364
+ await act(async () => window.dispatchEvent(new Event("focus")));
365
+ await act(async () => document.dispatchEvent(new Event("visibilitychange")));
366
+ expect(host.querySelector<HTMLSelectElement>('[aria-label="Who can access"]')?.value).toBe(
367
+ "invite",
368
+ );
369
+ expect(vi.mocked(fetch).mock.calls.length).toBe(requests);
370
+ expect(calls).toEqual([]);
371
+ });
372
+
373
+ it("does not send an authenticated sharing-admission refusal into another login loop", async () => {
374
+ vi.mocked(fetch).mockResolvedValue(
375
+ Response.json(
376
+ {
377
+ code: "sharing_not_admitted",
378
+ message:
379
+ "You're signed in, but sharing isn't accepting this sign-in. Try again later or contact support.",
380
+ },
381
+ { status: 400 },
382
+ ),
383
+ );
384
+ await mount();
385
+ expect(host.textContent).toContain("You're signed in");
386
+ expect(button("Sign in")).toBeUndefined();
387
+ expect(button("Create share link")).toBeUndefined();
388
+ expect(calls).toEqual([]);
389
+ });
390
+
391
+ it("shows retry only for recoverable errors, never a permanent refresh footer", async () => {
392
+ await mount();
393
+ expect(button("Refresh")).toBeUndefined();
394
+ expect(button("Try again")).toBeUndefined();
395
+ });
396
+
397
+ it.each(["login_expired", "sharing_not_admitted", "review_upload_origins_required"])(
398
+ "does not offer a misleading retry for %s",
399
+ async (code) => {
400
+ vi.mocked(fetch).mockResolvedValue(
401
+ Response.json({ code, message: "Unavailable" }, { status: 400 }),
402
+ );
403
+ await mount();
404
+ expect(button("Try again")).toBeUndefined();
405
+ },
406
+ );
407
+
408
+ it.each(["request", "job"])(
409
+ "restores the create action and audience after a failed %s",
410
+ async (failureAt) => {
411
+ await mount();
412
+ await choose("public");
413
+ const failed = {
414
+ ...job,
415
+ state: "failed" as const,
416
+ error: { code: "share_failed", message: "Cannot render" },
417
+ };
418
+ if (failureAt === "request")
419
+ vi.mocked(fetch).mockResolvedValueOnce(Response.json(failed.error, { status: 400 }));
420
+ else {
421
+ job = failed;
422
+ snapshot.job = failed;
423
+ }
424
+ await act(async () => button("Create share link")?.click());
425
+ expect(button("Create share link")?.disabled).toBe(false);
426
+ expect(host.querySelector<HTMLSelectElement>('[aria-label="Who can access"]')?.value).toBe(
427
+ "public",
428
+ );
429
+ expect(button("Try again")).toBeUndefined();
430
+ expect(host.textContent).toContain("Cannot render");
431
+ },
432
+ );
433
+
434
+ it("uses the OAuth-selected workspace among several without a dropdown", async () => {
435
+ snapshot.spaces.unshift({ ...snapshot.spaces[0]!, id: "other", name: "Other", bound: false });
436
+ await mount();
437
+ expect(host.querySelector('[aria-label="Sharing workspace"]')).toBeNull();
438
+ await choose("public");
439
+ await act(async () => button("Create share link")?.click());
440
+ expect(calls).toEqual([
441
+ { action: "share", audience: "public", space: "team1", includeSource: false },
442
+ ]);
443
+ });
444
+ it("refuses to substitute another workspace when the OAuth selection is missing", async () => {
445
+ snapshot.spaces[0]!.bound = false;
446
+ await mount();
447
+ expect(button("Create share link")?.disabled).toBe(true);
448
+ expect(host.textContent).toContain("workspace selected at sign-in");
449
+ expect(calls).toEqual([]);
450
+ });
451
+
452
+ it("omits Only you for new shares but preserves an existing private audience", async () => {
453
+ await mount();
454
+ expect(host.querySelector('option[value="private"]')).toBeNull();
455
+ });
456
+ it("displays an existing private share without converting its audience", async () => {
457
+ snapshot.share = { ...snapshot.share, state: "ready", audience: "private", spaceId: "team1" };
458
+ await mount();
459
+ expect(host.querySelector<HTMLSelectElement>('[aria-label="Who can access"]')?.value).toBe(
460
+ "private",
461
+ );
462
+ expect(host.textContent).toContain("Only you");
463
+ expect(calls).toEqual([]);
464
+ });
465
+
466
+ it("resumes a failed first creation without presenting an uploaded version", async () => {
467
+ snapshot.share = {
468
+ ...snapshot.share,
469
+ state: "processing",
470
+ audience: "public",
471
+ spaceId: "team1",
472
+ hasReadyVersion: false,
473
+ };
474
+ snapshot.job = {
475
+ ...job,
476
+ state: "failed",
477
+ error: { code: "source_unavailable", message: "Project files could not upload" },
478
+ };
479
+ await mount();
480
+ expect(button("Create share link")?.disabled).toBe(false);
481
+ expect(button("Update shared version")).toBeUndefined();
482
+ expect(host.textContent).not.toContain("still being prepared");
483
+ await act(async () => button("Create share link")?.click());
484
+ expect(calls).toEqual([{ action: "update", includeSource: false }]);
485
+ });
486
+
487
+ it.each(["free", "subscribed", null] as const)(
488
+ "shows the Pro CTA only for authoritative free entitlement: %s",
489
+ async (plan) => {
490
+ snapshot.spaces[0]!.plan = plan;
491
+ snapshot.spaces[0]!.upgradeUrl = "https://hyperframes.dev/pricing";
492
+ await mount();
493
+ const link = [...host.querySelectorAll("a")].find((a) =>
494
+ a.textContent?.includes("Upgrade to Pro"),
495
+ );
496
+ if (plan === "free") expect(link?.href).toBe("https://hyperframes.dev/pricing");
497
+ else expect(link).toBeUndefined();
498
+ },
499
+ );
500
+ it("refuses an upgrade destination outside the public pricing flow", async () => {
501
+ snapshot.spaces[0]!.plan = "free";
502
+ snapshot.spaces[0]!.upgradeUrl = "https://example.com/checkout";
503
+ await mount();
504
+ expect(
505
+ [...host.querySelectorAll("a")].some((link) => link.textContent?.includes("Upgrade to Pro")),
506
+ ).toBe(false);
507
+ });
508
+
509
+ it.each([false, true])(
510
+ "shows a persisted failed export after reopen (previous version: %s)",
511
+ async (previous) => {
512
+ snapshot.share = {
513
+ ...snapshot.share,
514
+ state: "failed",
515
+ failure: "This video can't be shared.",
516
+ hasReadyVersion: previous,
517
+ changed: true,
518
+ audience: "public",
519
+ spaceId: "team1",
520
+ url: previous ? "https://hyperframes.dev/r/previous" : null,
521
+ };
522
+ await mount();
523
+ expect(host.querySelector('[role="alert"]')?.textContent).toBe("This video can't be shared.");
524
+ expect(host.textContent).not.toContain("still being prepared");
525
+ expect(calls).toEqual([]);
526
+ const action = button(previous ? "Update shared version" : "Create share link");
527
+ expect(action?.disabled).toBe(false);
528
+ if (previous) expect(button("Copy current shared link")).toBeDefined();
529
+ await act(async () => action?.click());
530
+ expect(calls).toEqual([{ action: "update", includeSource: false }]);
531
+ },
532
+ );
533
+
534
+ it("does not probe unsupported Studio hosts for the CLI sharing bridge", async () => {
535
+ await act(async () => root.render(<QuickShare />));
536
+ expect(fetch).not.toHaveBeenCalled();
537
+ });
538
+
539
+ it("bootstraps sharing when the CLI advertises its bridge", async () => {
540
+ const marker = document.createElement("meta");
541
+ marker.name = "hyperframes-local-share";
542
+ marker.content = "1";
543
+ document.head.append(marker);
544
+ vi.mocked(fetch).mockResolvedValue(Response.json({ csrf: token }));
545
+ try {
546
+ await act(async () => root.render(<QuickShare />));
547
+ expect(fetch).toHaveBeenCalledWith(
548
+ "/api/share/bootstrap",
549
+ expect.objectContaining({ method: "GET" }),
550
+ );
551
+ } finally {
552
+ marker.remove();
553
+ }
554
+ });
555
+
556
+ it("acknowledges an unchanged update", async () => {
557
+ snapshot.share = {
558
+ ...snapshot.share,
559
+ state: "ready",
560
+ url: "https://hyperframes.dev/r/test",
561
+ audience: "public",
562
+ spaceId: "team1",
563
+ };
564
+ job = { ...job, state: "done", result: { ...snapshot.share, upToDate: true } };
565
+ await act(async () => root.render(<QuickShareContent token={token} />));
566
+ await act(async () => button("Update shared version")?.click());
567
+ expect(host.textContent).toContain("Already up to date.");
568
+ });
569
+ it("resets the copied acknowledgement after two seconds", async () => {
570
+ vi.useFakeTimers();
571
+ Object.defineProperty(navigator, "clipboard", {
572
+ configurable: true,
573
+ value: { writeText: vi.fn().mockResolvedValue(undefined) },
574
+ });
575
+ snapshot.share = {
576
+ ...snapshot.share,
577
+ state: "ready",
578
+ url: "https://hyperframes.dev/r/test",
579
+ audience: "public",
580
+ spaceId: "team1",
581
+ };
582
+ await act(async () => root.render(<QuickShareContent token={token} />));
583
+ await act(async () => button("Copy link")?.click());
584
+ expect(button("Copied")).toBeDefined();
585
+ await act(async () => vi.advanceTimersByTime(2000));
586
+ expect(button("Copied")).toBeUndefined();
587
+ expect(button("Copy link")).toBeDefined();
588
+ vi.useRealTimers();
589
+ });
590
+
591
+ it("offers Only you for an existing public share", async () => {
592
+ snapshot.share = { ...snapshot.share, state: "ready", audience: "public", spaceId: "team1" };
593
+ await mount();
594
+ const option = host.querySelector<HTMLOptionElement>('option[value="private"]');
595
+ expect(option?.disabled).toBe(false);
596
+ });
597
+ it("confirms a newly published version", async () => {
598
+ snapshot.share = {
599
+ ...snapshot.share,
600
+ state: "ready",
601
+ url: "https://hyperframes.dev/r/test",
602
+ audience: "public",
603
+ spaceId: "team1",
604
+ };
605
+ job = { ...job, state: "done", result: { ...snapshot.share, updated: true } };
606
+ await mount();
607
+ await act(async () => button("Update shared version")?.click());
608
+ expect(host.textContent).toContain("Shared version updated.");
609
+ });
610
+
611
+ it("discloses source scope and uploads files only after checking the option", async () => {
612
+ await mount();
613
+ expect(host.textContent).toContain("including unused and Git-ignored files");
614
+ const choice = host.querySelector<HTMLInputElement>('input[type="checkbox"]');
615
+ expect(choice?.checked).toBe(false);
616
+ await act(async () => choice?.click());
617
+ await choose("public");
618
+ await act(async () => button("Create share link")?.click());
619
+ expect(calls).toEqual([
620
+ { action: "share", audience: "public", space: "team1", includeSource: true },
621
+ ]);
622
+ });