From 8756c2d17d7c1934c79c6b8ff09d030ff638e20f Mon Sep 17 00:00:00 2001 From: Terence Cho Date: Tue, 10 Nov 2026 10:20:01 -0800 Subject: [PATCH 1/2] fix(cli): keep sharing owner error codes stable --- docs/packages/cli.mdx | 4 ++++ packages/cli/src/auth/errors.ts | 2 +- packages/cli/src/commands/share.test.ts | 20 ++++++++++++++++++++ packages/cli/src/commands/share.ts | 5 ++++- packages/cli/src/share/errors.ts | 9 ++++++--- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index b38858540d..43d6ad2441 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -3094,6 +3094,10 @@ failed update; `url` remains null. Use `--update` to explicitly retry with the current project. Signing into a different account while a share is running stops that operation; start it again after sign-in. +When another account owns the review, JSON errors use the fixed code +`owner_signed_out` with the owner email in `error.owner`. The human-readable +message also identifies the account to sign into. + The standard production CLI includes exact trusted storage origins for review videos and editable project sources; no upload configuration is required. Development environments, custom API/OAuth endpoints or clients, and custom diff --git a/packages/cli/src/auth/errors.ts b/packages/cli/src/auth/errors.ts index de229d270e..c1a2a33643 100644 --- a/packages/cli/src/auth/errors.ts +++ b/packages/cli/src/auth/errors.ts @@ -37,7 +37,7 @@ export class AuthError extends Error { export const ErrNotConfigured = () => new AuthError( "NOT_CONFIGURED", - "No HeyGen credentials found", + "No HeyGen credentials found.", "Run `hyperframes auth login` to sign in.", ); diff --git a/packages/cli/src/commands/share.test.ts b/packages/cli/src/commands/share.test.ts index 42c8999aad..4fb1e69df9 100644 --- a/packages/cli/src/commands/share.test.ts +++ b/packages/cli/src/commands/share.test.ts @@ -1,3 +1,4 @@ +import { ReviewFailed } from "@hyperframes/share"; import { afterEach, beforeEach, expect, it, vi } from "vitest"; import { runCommand } from "citty"; import { consumeCommandResult } from "../utils/commandResult.js"; @@ -96,3 +97,22 @@ it("deduplicates progress and terminates each message before the friendly error" ]); expect(friendly).toHaveBeenCalledWith("Sharing blocked."); }); + +it.each(["owner@example.com", "another@example.com"])( + "keeps the owner error code stable for %s", + async (owner) => { + mocks.run.mockRejectedValue(new ReviewFailed(403, `owner_signed_out:${owner}`)); + const out = vi.spyOn(console, "log").mockImplementation(() => {}); + await runCommand(command, { rawArgs: ["--status", "--json"] }); + expect(consumeCommandResult().exitCode).toBe(1); + expect(out).toHaveBeenCalledOnce(); + expect(JSON.parse(String(out.mock.calls[0]?.[0]))).toEqual({ + ok: false, + error: { + code: "owner_signed_out", + owner, + message: `This review belongs to ${owner}. Switch to that account to manage it.`, + }, + }); + }, +); diff --git a/packages/cli/src/commands/share.ts b/packages/cli/src/commands/share.ts index 13a0f3b339..59894ecb75 100644 --- a/packages/cli/src/commands/share.ts +++ b/packages/cli/src/commands/share.ts @@ -73,7 +73,10 @@ export default defineCommand({ await presentResult(result, input, Boolean(args.json)); } catch (error) { const failure = shareError(error); - if (args.json) console.log(JSON.stringify(jsonFailure(failure.code, failure.message))); + if (args.json) + console.log( + JSON.stringify({ ...jsonFailure(failure.code, failure.message), error: failure }), + ); else console.error(failure.message); setCommandExitCode(error instanceof CliUsageError ? 2 : 1); } diff --git a/packages/cli/src/share/errors.ts b/packages/cli/src/share/errors.ts index 5a662c8089..21d8a878d4 100644 --- a/packages/cli/src/share/errors.ts +++ b/packages/cli/src/share/errors.ts @@ -1,4 +1,4 @@ -import { ReviewFailed, reviewSentence } from "@hyperframes/share"; +import { ownerOf, ReviewFailed, reviewSentence } from "@hyperframes/share"; import { ShareSourceError } from "./sources.js"; import { isAuthError } from "../auth/errors.js"; import { CliUsageError } from "../utils/commandResult.js"; @@ -19,7 +19,7 @@ const HINTS: Record = { not_shared: "This project has no shared review yet. Run hyperframes share with an explicit audience.", }; -export function shareError(error: unknown): { code: string; message: string } { +export function shareError(error: unknown): { code: string; message: string; owner?: string } { if (error instanceof CliUsageError) return { code: error.code, message: error.message }; if (error instanceof ShareSourceError) return { code: "source_unavailable", message: error.message }; @@ -28,11 +28,14 @@ export function shareError(error: unknown): { code: string; message: string } { code: error.code.toLowerCase(), message: `${error.message} ${error.hint ?? ""}`.trim(), }; - if (error instanceof ReviewFailed) + if (error instanceof ReviewFailed) { + const owner = error.status === 401 ? null : ownerOf(error.reason); + if (owner !== null) return { code: "owner_signed_out", owner, message: reviewSentence(error) }; return { code: error.status === 401 ? "login_expired" : error.reason || "share_failed", message: HINTS[error.reason] ?? reviewSentence(error), }; + } return { code: "share_failed", message: error instanceof Error ? error.message : "Sharing failed. Try again.", From 13f68573e94c82e7773b2fe8fd311c16216faed6 Mon Sep 17 00:00:00 2001 From: Terence Cho Date: Tue, 10 Nov 2026 10:31:05 -0800 Subject: [PATCH 2/2] fix(share): clarify update feedback and align audience changes --- docs/packages/cli.mdx | 8 ++- packages/cli/src/commands/share.test.ts | 17 +++++++ packages/cli/src/commands/share.ts | 5 +- .../cli/src/server/shareFreshness.test.ts | 1 + packages/cli/src/server/sharePresentation.ts | 1 + packages/cli/src/server/shareRoutes.test.ts | 1 + packages/cli/src/share/service.test.ts | 49 +++++++++++++++++-- packages/cli/src/share/service.ts | 26 +++++++++- packages/studio-server/src/localShare.ts | 1 + .../src/components/share/QuickShare.test.tsx | 39 ++++++++++++++- .../src/components/share/QuickShare.tsx | 1 + .../src/components/share/ShareAudience.tsx | 32 +++++++++++- .../src/components/share/useQuickShare.ts | 25 +++++++++- 13 files changed, 190 insertions(+), 16 deletions(-) diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index 43d6ad2441..1d4aa9eee0 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -3069,8 +3069,12 @@ Adding versions uses the same project. Turning off its link does not free a slot remove a project in web management or upgrade when the workspace is full. The server enforces the limit even when clients create projects simultaneously. -Running `share` again returns the existing link without uploading edits. Use -`--update` to publish a new rendered version. The previous ready version remains +Running `share` again returns the existing link without uploading edits. An explicit +audience flag (for example, `share --public`) changes an existing share’s audience +without uploading a version, just like Studio’s audience selector. Without an +audience flag, access stays unchanged. Use +`--update` to publish a new rendered version. If nothing changed, the command says +“Already up to date” (`upToDate: true` in JSON). The previous ready version remains visible while an update processes. Interrupted first uploads can resume when the source is unchanged; if it changed, explicitly use `--update`. If the project's review or audience changes while rendering, check the current share diff --git a/packages/cli/src/commands/share.test.ts b/packages/cli/src/commands/share.test.ts index 4fb1e69df9..cbae1cdaab 100644 --- a/packages/cli/src/commands/share.test.ts +++ b/packages/cli/src/commands/share.test.ts @@ -116,3 +116,20 @@ it.each(["owner@example.com", "another@example.com"])( }); }, ); + +it("reports an unchanged update in human and JSON output", async () => { + mocks.run.mockResolvedValue({ + state: "ready", + ready: true, + upToDate: true, + source: { at: "ready" }, + }); + const out = vi.spyOn(console, "log").mockImplementation(() => {}); + await runCommand(command, { rawArgs: ["--update"] }); + expect(out).toHaveBeenCalledWith("Already up to date."); + await runCommand(command, { rawArgs: ["--update", "--json"] }); + expect(JSON.parse(String(out.mock.calls.at(-1)?.[0]))).toMatchObject({ + ok: true, + upToDate: true, + }); +}); diff --git a/packages/cli/src/commands/share.ts b/packages/cli/src/commands/share.ts index 59894ecb75..ad2554c5d5 100644 --- a/packages/cli/src/commands/share.ts +++ b/packages/cli/src/commands/share.ts @@ -117,7 +117,7 @@ function validateActionOptions( ) { if (action !== "share" && audience) throw new CliUsageError( - "Audience flags are only valid for a first share. Use --manage to change access.", + "Use audience flags with hyperframes share, without --update, --status or --manage.", ); if ((action === "status" || action === "manage") && (args.space || args["video-only"])) throw new CliUsageError("--space and --video-only cannot be used with --status or --manage."); @@ -129,7 +129,7 @@ function requestedAudience(args: ShareArgs) { if (args.team) audiences.push("team"); if (args["invite-only"]) audiences.push("invite"); if (args.private) audiences.push("private"); - if (audiences.length > 1) throw new CliUsageError("Choose one first-share audience."); + if (audiences.length > 1) throw new CliUsageError("Choose one audience."); return audiences[0]; } @@ -175,6 +175,7 @@ async function presentResult(result: ShareState, input: ShareAction, json: boole async function presentSuccessfulResult(result: ShareState, input: ShareAction, json: boolean) { if (json) console.log(JSON.stringify({ ok: true, ...result })); + else if (result.upToDate) console.log("Already up to date."); else if (input.action === "manage") { console.log(result.manageUrl); if (!isUnattended()) await (await import("open")).default(result.manageUrl); diff --git a/packages/cli/src/server/shareFreshness.test.ts b/packages/cli/src/server/shareFreshness.test.ts index 1271993300..d8e6d5db06 100644 --- a/packages/cli/src/server/shareFreshness.test.ts +++ b/packages/cli/src/server/shareFreshness.test.ts @@ -10,6 +10,7 @@ afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }); }); const state: ShareState = { + upToDate: false, share: { projectId: "project", url: "https://hyperframes.dev/r/test", diff --git a/packages/cli/src/server/sharePresentation.ts b/packages/cli/src/server/sharePresentation.ts index 671cdbb239..9f9944cff6 100644 --- a/packages/cli/src/server/sharePresentation.ts +++ b/packages/cli/src/server/sharePresentation.ts @@ -8,6 +8,7 @@ export function presentShare(value: ShareState): LocalShareState { value.share?.takedown || value.share?.sharingState?.state === "subscription_required"; return { + upToDate: value.upToDate, state: presentedState(value, Boolean(held)), url: held ? null : (value.url ?? value.previousUrl), failure: value.state === "failed" ? value.version.failure : null, diff --git a/packages/cli/src/server/shareRoutes.test.ts b/packages/cli/src/server/shareRoutes.test.ts index 447ae3015c..3eb46368c9 100644 --- a/packages/cli/src/server/shareRoutes.test.ts +++ b/packages/cli/src/server/shareRoutes.test.ts @@ -7,6 +7,7 @@ import { AuthError } from "../auth/errors.js"; import { createShareCsrf, localShareRequestAllowed } from "./shareBoundary.js"; const state: ShareState = { + upToDate: false, source: { at: "not_checked" }, share: null, version: { last: null, source: "none", exporting: null, failure: null }, diff --git a/packages/cli/src/share/service.test.ts b/packages/cli/src/share/service.test.ts index a3c0ce632c..55c6198360 100644 --- a/packages/cli/src/share/service.test.ts +++ b/packages/cli/src/share/service.test.ts @@ -13,6 +13,7 @@ const mocks = vi.hoisted(() => ({ refresh: vi.fn(), event: vi.fn(), access: vi.fn(), + setAccess: vi.fn(), })); vi.mock("@hyperframes/share", () => ({ reviewClient: () => ({ project: mocks.project, spaces: mocks.spaces, reviewFlags: mocks.flags }), @@ -23,7 +24,7 @@ vi.mock("@hyperframes/share", () => ({ addVersion: mocks.add, pendingReviewExport: mocks.pending, refreshReviewExport: mocks.refresh, - setReviewAccess: vi.fn(), + setReviewAccess: mocks.setAccess, turnOffReviewLink: vi.fn(), ReviewFailed: class extends Error { constructor( @@ -104,15 +105,20 @@ describe("share operation consent and identity", () => { ).rejects.toMatchObject({ reason: "review_project_limit_reached" }); expect(mocks.render).not.toHaveBeenCalled(); }); - it("preserves existing workspace and audience", async () => { + it("preserves existing workspace and changes an explicitly requested audience", async () => { mocks.status.mockResolvedValue(shared); const service = createShareService("/project"); await expect(service.run({ action: "update", space: "other" })).rejects.toMatchObject({ reason: "workspace_mismatch", }); - await expect(service.run({ action: "share", audience: "private" })).rejects.toMatchObject({ - reason: "manage_existing_audience", - }); + mocks.setAccess.mockImplementation(async () => + mocks.status.mockResolvedValue({ ...shared, access: "private" }), + ); + await service.run({ action: "share", audience: "private" }); + expect(mocks.setAccess).toHaveBeenCalledWith( + expect.objectContaining({ change: { access: "private" } }), + ); + expect(mocks.add).not.toHaveBeenCalled(); expect(mocks.render).not.toHaveBeenCalled(); }); it("refuses a public share opened while a private first share was rendering", async () => { @@ -423,3 +429,36 @@ it("retries an uncreated first version after refusal even when local files chang expect(mocks.add).toHaveBeenCalledOnce(); expect(mocks.create).not.toHaveBeenCalled(); }); + +it("reports an unchanged completed update without claiming a new version", async () => { + mocks.status.mockResolvedValue(shared); + mocks.version.mockResolvedValue({ last: { current: true }, source: "ready" }); + mocks.add.mockResolvedValue(null); + const result = await createShareService("/project").run({ action: "update" }); + expect(result.upToDate).toBe(true); +}); +it("propagates a refused audience change without rendering", async () => { + mocks.status.mockResolvedValue(shared); + mocks.setAccess.mockRejectedValue(new Error("Restricted sharing requires a subscription")); + await expect( + createShareService("/project").run({ action: "share", audience: "team" }), + ).rejects.toThrow("subscription"); + expect(mocks.render).not.toHaveBeenCalled(); +}); + +it("does not label a newly published version as already up to date", async () => { + mocks.status.mockResolvedValue(shared); + mocks.version.mockResolvedValue({ last: { current: true }, source: "ready" }); + mocks.add.mockImplementation(async ({ onAdded }) => { + onAdded(); + return null; + }); + expect((await createShareService("/project").run({ action: "update" })).upToDate).toBe(false); +}); +it("does not label a still-processing update as already up to date", async () => { + mocks.status.mockResolvedValue(shared); + mocks.version.mockResolvedValue({ last: { current: true }, source: "ready" }); + mocks.pending.mockResolvedValue({ projectId: "project" }); + mocks.add.mockResolvedValue(null); + expect((await createShareService("/project").run({ action: "update" })).upToDate).toBe(false); +}); diff --git a/packages/cli/src/share/service.ts b/packages/cli/src/share/service.ts index a7e47ea00c..7d675a9c11 100644 --- a/packages/cli/src/share/service.ts +++ b/packages/cli/src/share/service.ts @@ -64,6 +64,7 @@ async function readStatus( const failed = hasFailedVersion(version); const ready = Boolean(activeUrl && latest && !processing && !failed); return { + upToDate: false, share, version, pending, @@ -216,7 +217,10 @@ export function createShareService( return { ...result, state: "processing", ready: false, url: null }; } attempt.complete(result.ready, added); - return result; + return { + ...result, + upToDate: isUnchangedUpdate(input, added, result), + }; }; const uploadTarget = async (current: ReviewShare | null, input: ShareAction, space?: string) => { const share = current @@ -250,7 +254,16 @@ export function createShareService( const mutate = async (input: ShareAction, attempt: ShareAttempt) => { await auth.access(); attempt.authenticated(); - const current = await readStatus(dir, client, undefined, attempt.recover); + let current = await readStatus(dir, client, undefined, attempt.recover); + if (current.share && changesAudience(input, current.share)) { + assertExistingIntent(current.share, { ...input, audience: undefined }); + const projectId = current.share.projectId; + await setReviewAccess({ projectPath: dir, client, change: { access: input.audience } }); + current = await readStatus(dir, client, projectId); + assertExistingIntent(current.share, input); + attempt.retrieved(); + return current; + } assertExistingIntent(current.share, input); if (retrievesExisting(current, input)) { attempt.retrieved(); @@ -304,3 +317,12 @@ export type ShareState = Awaited>; function hasFailedVersion(version: Awaited>): boolean { return Boolean(version.failure && !version.held); } + +function changesAudience(input: ShareAction, share: ReviewShare) { + return input.action === "share" && Boolean(input.audience) && share.access !== input.audience; +} +function isUnchangedUpdate(input: ShareAction, added: boolean, result: ShareState) { + return ( + input.action === "update" && !added && Boolean(result.version.last?.current) && !result.pending + ); +} diff --git a/packages/studio-server/src/localShare.ts b/packages/studio-server/src/localShare.ts index de3cf694c3..8ed42b0eb2 100644 --- a/packages/studio-server/src/localShare.ts +++ b/packages/studio-server/src/localShare.ts @@ -11,6 +11,7 @@ export interface LocalShareSpace { limit: number | null; } export interface LocalShareState { + upToDate?: boolean; state: "not_shared" | "link_off" | "ready" | "processing" | "failed" | "unavailable"; url: string | null; manageUrl: string; diff --git a/packages/studio/src/components/share/QuickShare.test.tsx b/packages/studio/src/components/share/QuickShare.test.tsx index c6eb5e77b1..6dc752433c 100644 --- a/packages/studio/src/components/share/QuickShare.test.tsx +++ b/packages/studio/src/components/share/QuickShare.test.tsx @@ -497,7 +497,9 @@ it("refuses an upgrade destination outside the public pricing flow", async () => snapshot.spaces[0]!.plan = "free"; snapshot.spaces[0]!.upgradeUrl = "https://example.com/checkout"; await mount(); - expect(host.textContent).not.toContain("Upgrade to Pro"); + expect( + [...host.querySelectorAll("a")].some((link) => link.textContent?.includes("Upgrade to Pro")), + ).toBe(false); }); it.each([false, true])( @@ -546,3 +548,38 @@ it("bootstraps sharing when the CLI advertises its bridge", async () => { marker.remove(); } }); + +it("acknowledges an unchanged update", async () => { + snapshot.share = { + ...snapshot.share, + state: "ready", + url: "https://hyperframes.dev/r/test", + audience: "public", + spaceId: "team1", + }; + job = { ...job, state: "done", result: { ...snapshot.share, upToDate: true } }; + await act(async () => root.render()); + await act(async () => button("Update shared version")?.click()); + expect(host.textContent).toContain("Already up to date."); +}); +it("resets the copied acknowledgement after two seconds", async () => { + vi.useFakeTimers(); + Object.defineProperty(navigator, "clipboard", { + configurable: true, + value: { writeText: vi.fn().mockResolvedValue(undefined) }, + }); + snapshot.share = { + ...snapshot.share, + state: "ready", + url: "https://hyperframes.dev/r/test", + audience: "public", + spaceId: "team1", + }; + await act(async () => root.render()); + await act(async () => button("Copy link")?.click()); + expect(button("Copied")).toBeDefined(); + await act(async () => vi.advanceTimersByTime(2000)); + expect(button("Copied")).toBeUndefined(); + expect(button("Copy link")).toBeDefined(); + vi.useRealTimers(); +}); diff --git a/packages/studio/src/components/share/QuickShare.tsx b/packages/studio/src/components/share/QuickShare.tsx index a3a26a0f5f..44cdba7fa1 100644 --- a/packages/studio/src/components/share/QuickShare.tsx +++ b/packages/studio/src/components/share/QuickShare.tsx @@ -69,6 +69,7 @@ export function QuickShareContent({ {progress ? (

{progress} You can close this panel; keep Studio running.

) : null} + {model.notice ?

{model.notice}

: null} {error ? (

diff --git a/packages/studio/src/components/share/ShareAudience.tsx b/packages/studio/src/components/share/ShareAudience.tsx index 46d9667e81..0be13773b6 100644 --- a/packages/studio/src/components/share/ShareAudience.tsx +++ b/packages/studio/src/components/share/ShareAudience.tsx @@ -61,6 +61,7 @@ export function ShareAudience({ {choices.map((value) => { const option = AUDIENCES[value]; const OptionIcon = option.icon; + const needsPro = requiresPro(space, value, snapshot.share.audience); return (

+ Free includes anyone-with-the-link sharing. Upgrade to Pro for workspace and invite-only + sharing. +

+ ) : null} ); } + +function requiresPro( + space: LocalShareSnapshot["spaces"][number] | undefined, + value: LocalShareAudience, + current: LocalShareAudience | null, +) { + return ( + space?.plan === "free" && + !space.audiences.includes(value) && + value !== current && + (value === "team" || value === "invite") + ); +} diff --git a/packages/studio/src/components/share/useQuickShare.ts b/packages/studio/src/components/share/useQuickShare.ts index 0015be0144..45d42fd66f 100644 --- a/packages/studio/src/components/share/useQuickShare.ts +++ b/packages/studio/src/components/share/useQuickShare.ts @@ -29,7 +29,8 @@ export function useQuickShare(token: string, beforeShare?: () => Promise) const reconnectOnReturn = useRef(false); const [error, setError] = useState(null); const [errorCode, setErrorCode] = useState(null); - const [copied, setCopied] = useState(false); + const { copied, setCopied, acknowledgeCopy } = useCopyAcknowledgement(); + const [notice, setNotice] = useState(""); const opened = useRef(false); const lifetime = useRef(null); const timer = useRef | null>(null); @@ -59,6 +60,7 @@ export function useQuickShare(token: string, beforeShare?: () => Promise) const result = job.result; if (result) setSnapshot((prior) => (prior ? { ...prior, share: result, job } : prior)); await refresh(signal, job.state === "failed"); + if (!signal.aborted) setNotice(completionNotice(job)); } async function refresh(signal: AbortSignal, preserveSelection = false) { setError(null); @@ -108,6 +110,7 @@ export function useQuickShare(token: string, beforeShare?: () => Promise) setError(null); setErrorCode(null); setCopied(false); + setNotice(""); setProgress("Preparing share…"); try { if (["share", "update"].includes(action.action)) await beforeShare?.(); @@ -166,7 +169,8 @@ export function useQuickShare(token: string, beforeShare?: () => Promise) async function copy(url: string) { try { await navigator.clipboard.writeText(url); - setCopied(true); + if (lifetime.current?.signal.aborted) return; + acknowledgeCopy(); shareInteraction(token, { event: "share_link_copied", via: "copy" }); } catch { setError("Couldn’t copy. Open the shared page and copy its address."); @@ -181,9 +185,26 @@ export function useQuickShare(token: string, beforeShare?: () => Promise) error, errorCode, copied, + notice, progress, run, copy, }; } export type QuickShareModel = ReturnType; + +function completionNotice(job: LocalShareJob) { + return job.state === "done" && job.result?.upToDate ? "Already up to date." : ""; +} + +function useCopyAcknowledgement() { + const [copied, setCopied] = useState(false); + const timer = useRef | undefined>(undefined); + useMountEffect(() => () => clearTimeout(timer.current)); + function acknowledgeCopy() { + clearTimeout(timer.current); + setCopied(true); + timer.current = setTimeout(() => setCopied(false), 2000); + } + return { copied, setCopied, acknowledgeCopy }; +}