Skip to content

Commit 4ad4f37

Browse files
committed
fix(share): require consent before uploading project files
1 parent 9697c97 commit 4ad4f37

17 files changed

Lines changed: 233 additions & 38 deletions

File tree

‎docs/developers/share-source.mdx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ description: "Choose whether a CLI review includes the project files used by its
44
---
55

66
`hyperframes share` can attach editable project files to the same review page
7-
used by Desktop. Source is available when the workspace's sharing and
7+
used by Desktop. Source upload requires `--include-source` for each upload, including updates.
8+
Without it, terminal, JSON and unattended commands share video only.
9+
Local Studio offers an unchecked **Include editable project files** option with
10+
a disclosure of the upload scope before creating or updating a share.
11+
12+
Source is available when the workspace's sharing and
813
Composition Sync permissions allow it. The recipient's access still depends on
914
the share's settings and their plan.
1015

1116
```bash
12-
hyperframes share --public # Video and source when eligible
17+
hyperframes share --public # Video only (default)
18+
hyperframes share --public --include-source # Also upload editable project files
1319
hyperframes share --update # Update the existing review
1420
hyperframes share --update --video-only # Explicitly omit editable source
1521
```

‎docs/packages/cli.mdx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,12 +3053,16 @@ comments and version history as HyperFrames Desktop. Sign in with
30533053
`hyperframes auth login` first; API keys cannot own review projects.
30543054

30553055
```bash
3056-
hyperframes share --public # Explicitly allow anyone with the link
3056+
hyperframes share --public # Video only; anyone with the link
3057+
hyperframes share --public --include-source # Also upload editable project files
30573058
hyperframes share --status --json # Read status; never upload local edits
30583059
hyperframes share --update # Render and upload the current project
30593060
hyperframes share --manage # Open web sharing settings
30603061
```
30613062

3063+
Sharing uploads video only by default. `--include-source` explicitly includes portable project files, including unused and Git-ignored files; review your folder and `.hyperframesignore` first. `--video-only` remains available and cannot be combined with `--include-source`. Source inclusion must be chosen for each upload, including `--update`; `--yes` does not consent to source upload.
3064+
3065+
30623066
The first share requires an explicit audience: `--public`, `--team`,
30633067
`--invite-only`, or `--private`. In an attended terminal, `share` asks you to
30643068
choose. `--yes` suppresses questions but does not choose an audience. Available

‎packages/cli/src/commands/share.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,24 @@ it("reports a specific code for an invalid ignore file", async () => {
143143
error: { code: "invalid_source_ignore" },
144144
});
145145
});
146+
147+
it.each([[[]], [["--json"]], [["--yes"]], [["--video-only"]]])(
148+
"defaults to video-only without source consent %j",
149+
async (flags) => {
150+
vi.spyOn(console, "log").mockImplementation(() => {});
151+
vi.spyOn(console, "error").mockImplementation(() => {});
152+
await runCommand(command, { rawArgs: ["--public", ...flags] });
153+
expect(mocks.run).toHaveBeenCalledWith(expect.objectContaining({ includeSource: false }));
154+
},
155+
);
156+
it("accepts explicit source inclusion and rejects conflicting choices", async () => {
157+
vi.spyOn(console, "log").mockImplementation(() => {});
158+
await runCommand(command, { rawArgs: ["--public", "--include-source", "--json"] });
159+
expect(mocks.run).toHaveBeenCalledWith(expect.objectContaining({ includeSource: true }));
160+
mocks.run.mockClear();
161+
await runCommand(command, {
162+
rawArgs: ["--public", "--include-source", "--video-only", "--json"],
163+
});
164+
expect(consumeCommandResult().exitCode).toBe(2);
165+
expect(mocks.run).not.toHaveBeenCalled();
166+
});

‎packages/cli/src/commands/share.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default defineCommand({
3838
type: "boolean",
3939
description: "Render and add a new video version to the existing share",
4040
},
41+
"include-source": {
42+
type: "boolean",
43+
description: "Upload editable project files, including unused and Git-ignored files",
44+
},
4145
"video-only": {
4246
type: "boolean",
4347
description: "Share only the rendered video, without editable source",
@@ -96,6 +100,7 @@ interface ShareArgs {
96100
"wait-seconds"?: string;
97101
space?: string;
98102
"video-only"?: boolean;
103+
"include-source"?: boolean;
99104
}
100105
function parseInput(args: ShareArgs): ShareAction {
101106
const waitSeconds = Number(args["wait-seconds"]);
@@ -107,20 +112,38 @@ function parseInput(args: ShareArgs): ShareAction {
107112
const action = args.status ? "status" : args.manage ? "manage" : args.update ? "update" : "share";
108113

109114
validateActionOptions(action, audience, args);
110-
return { action, audience, space: args.space, waitSeconds, videoOnly: args["video-only"] };
115+
return {
116+
action,
117+
audience,
118+
space: args.space,
119+
waitSeconds,
120+
videoOnly: args["video-only"],
121+
includeSource: args["include-source"] === true,
122+
};
111123
}
112124

113125
function validateActionOptions(
114126
action: ShareAction["action"],
115127
audience: ShareAction["audience"],
116128
args: ShareArgs,
117129
) {
130+
validateSourceOptions(args);
118131
if (action !== "share" && audience)
119132
throw new CliUsageError(
120133
"Use audience flags with hyperframes share, without --update, --status or --manage.",
121134
);
122-
if ((action === "status" || action === "manage") && (args.space || args["video-only"]))
123-
throw new CliUsageError("--space and --video-only cannot be used with --status or --manage.");
135+
if (
136+
(action === "status" || action === "manage") &&
137+
(args.space || args["video-only"] || args["include-source"])
138+
)
139+
throw new CliUsageError(
140+
"--space, --include-source and --video-only cannot be used with --status or --manage.",
141+
);
142+
}
143+
144+
function validateSourceOptions(args: ShareArgs) {
145+
if (args["include-source"] && args["video-only"])
146+
throw new CliUsageError("Choose only one of --include-source or --video-only.");
124147
}
125148

126149
function requestedAudience(args: ShareArgs) {
@@ -205,6 +228,6 @@ function sourceNotice(reason: string): string {
205228
if (reason === "source_plan_required")
206229
return "Your video is shared without editable project files. Upgrade to Pro to include source files: https://hyperframes.studio/pricing";
207230
if (reason === "requested")
208-
return "Sharing the video without editable project files (--video-only).";
231+
return "Sharing the video without editable project files. Use --include-source to upload project files.";
209232
return "Sharing the video without editable project files; source sharing is unavailable in this workspace.";
210233
}

‎packages/cli/src/server/shareRoutes.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,16 @@ it("shows a completed login's admission failure to its initiating panel", async
426426
});
427427
});
428428
});
429+
430+
it.each([undefined, true])("forwards only explicit source consent (%s)", async (includeSource) => {
431+
const { app, service } = fixture();
432+
const csrf = await token(app);
433+
const response = await request(app, "actions", csrf, {
434+
action: "share",
435+
audience: "public",
436+
includeSource,
437+
});
438+
expect(response.status).toBe(202);
439+
await new Promise((resolve) => setTimeout(resolve, 0));
440+
expect(service.run).toHaveBeenCalledWith(expect.objectContaining({ includeSource }));
441+
});

‎packages/cli/src/server/shareRoutes.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ function actionInput(value: unknown): LocalShareAction | null {
2424
if (!isRecord(value)) return null;
2525
const record = Object.fromEntries(Object.entries(value));
2626
if (
27-
Object.keys(record).some((key) => !["action", "audience", "space", "videoOnly"].includes(key))
27+
Object.keys(record).some(
28+
(key) => !["action", "audience", "space", "videoOnly", "includeSource"].includes(key),
29+
)
2830
)
2931
return null;
30-
const { action, audience, space, videoOnly } = record;
32+
const { action, audience, space, videoOnly, includeSource } = record;
3133
if (!isAction(action)) return null;
3234
const chosen = AUDIENCES.find((mode) => mode === audience);
3335
if (audience !== undefined && !chosen) return null;
34-
const options = actionOptions(space, videoOnly);
36+
const options = actionOptions(space, videoOnly, includeSource);
3537
if (!options) return null;
3638
if (["share", "access"].includes(action) && !chosen) return null;
3739
return {
@@ -51,14 +53,20 @@ function isAction(value: unknown): value is LocalShareAction["action"] {
5153
function actionOptions(
5254
space: unknown,
5355
videoOnly: unknown,
54-
): Pick<LocalShareAction, "space" | "videoOnly"> | null {
56+
includeSource: unknown,
57+
): Pick<LocalShareAction, "space" | "videoOnly" | "includeSource"> | null {
5558
if (!validSpace(space)) return null;
56-
if (videoOnly !== undefined && typeof videoOnly !== "boolean") return null;
57-
const options: Pick<LocalShareAction, "space" | "videoOnly"> = {};
59+
if (![videoOnly, includeSource].every(optionalBoolean)) return null;
60+
if (includeSource === true && videoOnly === true) return null;
61+
const options: Pick<LocalShareAction, "space" | "videoOnly" | "includeSource"> = {};
5862
if (typeof space === "string") options.space = space;
5963
if (videoOnly === true) options.videoOnly = true;
64+
if (includeSource === true) options.includeSource = true;
6065
return options;
6166
}
67+
function optionalBoolean(value: unknown): boolean {
68+
return value === undefined || typeof value === "boolean";
69+
}
6270
function validSpace(value: unknown): boolean {
6371
return value === undefined || (typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value));
6472
}
@@ -251,6 +259,7 @@ function executeAction(sharing: ShareService, input: LocalShareAction) {
251259
audience: input.audience,
252260
space: input.space,
253261
videoOnly: input.videoOnly,
262+
includeSource: input.includeSource,
254263
});
255264
}
256265

‎packages/cli/src/share/service.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ vi.mock("./activity.js", () => ({
55
run(async () => {}),
66
}));
77
const mocks = vi.hoisted(() => ({
8+
source: vi.fn(),
89
activity: vi.fn(),
910
status: vi.fn(),
1011
version: vi.fn(),
@@ -49,6 +50,10 @@ vi.mock("./host.js", () => ({
4950
assertReviewUploadStorage: vi.fn(),
5051
bindCliShareProject: (path: string) => path,
5152
}));
53+
vi.mock("./sources.js", () => ({
54+
prepareCliShareSource: mocks.source,
55+
uncheckedSource: () => ({ at: "not_checked" }),
56+
}));
5257
vi.mock("./render.js", () => ({ prepareShareRender: mocks.render }));
5358
vi.mock("../telemetry/client.js", () => ({
5459
trackEvent: mocks.event,
@@ -501,3 +506,17 @@ it("reports the first share while it has no server project yet", async () => {
501506
url: null,
502507
});
503508
});
509+
510+
it.each([false, true])(
511+
"only prepares source after affirmative consent (%s)",
512+
async (includeSource) => {
513+
mocks.status.mockResolvedValue(shared);
514+
mocks.flags.mockResolvedValue({ versionSharing: true, shareFiles: true });
515+
mocks.source.mockResolvedValue({
516+
source: { at: "video_only", reason: "source_plan_required" },
517+
requireSource: false,
518+
});
519+
await createShareService("/project").run({ action: "update", includeSource });
520+
expect(mocks.source).toHaveBeenCalledTimes(includeSource ? 1 : 0);
521+
},
522+
);

‎packages/cli/src/share/service.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface ShareAction {
3535
space?: string;
3636
waitSeconds?: number;
3737
videoOnly?: boolean;
38+
includeSource?: boolean;
3839
}
3940
function linkState(share: ReviewShare | null, ready: boolean, failed: boolean): string {
4041
if (!share) return "not_shared";
@@ -303,10 +304,13 @@ export function createShareService(
303304
await prepareShareRender(dir);
304305
const target = await uploadTarget(current.share, input, space);
305306
await phase("uploading_source");
306-
const sources = await prepareCliShareSource(dir, auth.access, target.spaceId, {
307-
videoOnly: input.videoOnly,
308-
shareFiles: flags.shareFiles,
309-
});
307+
const sources = await prepareSelectedSource(
308+
dir,
309+
auth.access,
310+
target.spaceId,
311+
input,
312+
flags.shareFiles,
313+
);
310314
if (sources.requireSource) await checkPreparedTarget(target);
311315
await phase("uploading_video");
312316
return upload(input, target.projectId, sources, attempt, phase);
@@ -356,3 +360,15 @@ function isUnchangedUpdate(input: ShareAction, added: boolean, result: ShareStat
356360
input.action === "update" && !added && Boolean(result.version.last?.current) && !result.pending
357361
);
358362
}
363+
364+
async function prepareSelectedSource(
365+
dir: string,
366+
access: Parameters<typeof prepareCliShareSource>[1],
367+
spaceId: string | undefined,
368+
input: ShareAction,
369+
shareFiles: boolean,
370+
): Promise<PreparedShareSource> {
371+
if (input.includeSource !== true || input.videoOnly)
372+
return { source: { at: "video_only", reason: "requested" }, requireSource: false };
373+
return prepareCliShareSource(dir, access, spaceId, { includeSource: true, shareFiles });
374+
}

‎packages/cli/src/share/sources.test.ts‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ beforeEach(() => {
3030
it("eligible source requires attachment on the version", async () => {
3131
const snapshot = { space_id: "space", composition_id: "composition", snapshot_id: "snapshot" };
3232
mocks.prepare.mockResolvedValue({ at: "ready", snapshot });
33-
expect(await prepareCliShareSource("/project", access, "space", { shareFiles: true })).toEqual({
33+
expect(
34+
await prepareCliShareSource("/project", access, "space", {
35+
shareFiles: true,
36+
includeSource: true,
37+
}),
38+
).toEqual({
3439
source: { at: "ready", snapshot },
3540
requireSource: true,
3641
filesForExport: mocks.filesForExport,
@@ -46,28 +51,37 @@ it("refuses source bytes that differ from the rendered assets even when metadata
4651
return { at: "unavailable", reason: "source_render_changed" };
4752
});
4853
await expect(
49-
prepareCliShareSource("/project", access, "space", { shareFiles: true }),
54+
prepareCliShareSource("/project", access, "space", { shareFiles: true, includeSource: true }),
5055
).rejects.toThrow("source_render_changed");
5156
});
5257
it("free plan ineligibility preserves video sharing and reports source unavailable", async () => {
5358
mocks.prepare.mockResolvedValue({ at: "unavailable", reason: "source_plan_required" });
54-
expect(await prepareCliShareSource("/project", access, "space", { shareFiles: true })).toEqual({
59+
expect(
60+
await prepareCliShareSource("/project", access, "space", {
61+
shareFiles: true,
62+
includeSource: true,
63+
}),
64+
).toEqual({
5565
source: { at: "video_only", reason: "source_plan_required" },
5666
requireSource: false,
5767
});
5868
});
5969
it("explicit video-only skips source network requests", async () => {
60-
await prepareCliShareSource("/project", access, "space", { shareFiles: true, videoOnly: true });
70+
await prepareCliShareSource("/project", access, "space", {
71+
shareFiles: true,
72+
includeSource: true,
73+
videoOnly: true,
74+
});
6175
expect(mocks.factory).not.toHaveBeenCalled();
6276
});
6377
it("unexpected upload errors and stale source block with an explicit video-only retry", async () => {
6478
mocks.prepare.mockRejectedValueOnce(new Error("network failed"));
6579
await expect(
66-
prepareCliShareSource("/project", access, "space", { shareFiles: true }),
80+
prepareCliShareSource("/project", access, "space", { shareFiles: true, includeSource: true }),
6781
).rejects.toThrow("--video-only");
6882
mocks.prepare.mockResolvedValue({ at: "unavailable", reason: "source_render_changed" });
6983
await expect(
70-
prepareCliShareSource("/project", access, "space", { shareFiles: true }),
84+
prepareCliShareSource("/project", access, "space", { shareFiles: true, includeSource: true }),
7185
).rejects.toThrow("--video-only");
7286
});
7387

@@ -77,3 +91,9 @@ it("source failure has a stable bridge and JSON error code", () => {
7791
message: "Retry or choose video-only",
7892
});
7993
});
94+
95+
it("defaults to video only even when source sharing is available", async () => {
96+
const result = await prepareCliShareSource("/project", access, "space", { shareFiles: true });
97+
expect(result.requireSource).toBe(false);
98+
expect(mocks.factory).not.toHaveBeenCalled();
99+
});

‎packages/cli/src/share/sources.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export async function prepareCliShareSource(
2525
dir: string,
2626
access: ReturnType<typeof createShareAccess>["access"],
2727
spaceId: string | undefined,
28-
options: { videoOnly?: boolean; shareFiles: boolean },
28+
options: { includeSource?: boolean; videoOnly?: boolean; shareFiles: boolean },
2929
): Promise<PreparedShareSource> {
30-
if (options.videoOnly) return videoOnly("requested");
30+
if (options.includeSource !== true || options.videoOnly) return videoOnly("requested");
3131
if (!options.shareFiles) return videoOnly("source_disabled");
3232
if (!spaceId) throw new Error("The owning workspace could not be verified. Retry sharing.");
3333
try {

0 commit comments

Comments
 (0)