Skip to content

Commit 83323e4

Browse files
Vitozhu04claude
andauthored
fix(cli): don't invent a purchase link when the server withholds upgrade_url
reverse/start answers upgrade_url: null when no plan can be bought right now. The CLI treated that like a missing field and built its own plans link, so a Free account under gate "block" was sent to a page where it can't buy. Now null means no link anywhere: the JSON prints upgrade_url: null and subscribe_command: null (billing subscribe would open that same plans page), the refusal says a plan can't be purchased right now instead of naming the subscribe command, and the skill runs nothing and passes on no link. Only an absent field (an older server) falls back to the plans page; a string is used as is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 47ddded commit 83323e4

7 files changed

Lines changed: 83 additions & 26 deletions

File tree

‎docs/packages/cli.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,9 +1520,10 @@ with the render. It then prints the video's [`measure probe`](#measure) JSON,
15201520
with a `reverse` field: whether you are signed in, the plan (`free`, `pro`, or
15211521
`null` when unknown), the session, and on Free the `upgrade_url` and the
15221522
`subscribe_command` ([`billing subscribe`](#billing) with the feature and session) that credit a
1523-
purchase to this run. It stops the run only when HeyGen blocks it for a Free
1524-
account: it then exits non-zero with that command. Signed out, offline, or
1525-
on a server without the route, it skips the session and still probes.
1523+
purchase to this run (both `null` when HeyGen says no plan can be bought right now). It stops the
1524+
run only when HeyGen blocks it for a Free account: it then exits non-zero with that command, or,
1525+
without one, says a plan can't be purchased right now. Signed out, offline, or on a server without
1526+
the route, it skips the session and still probes.
15261527

15271528
```bash
15281529
npx hyperframes reverse start ref.mp4 --dir my-rebuild

‎packages/cli/src/commands/reverse/start.test.ts‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ const server = vi.hoisted(() => ({
1212
}));
1313
const probe = vi.hoisted(() => ({ fail: false }));
1414

15-
vi.mock("../../heygen/reverse.js", () => ({
16-
reverseUpgradeUrl: (session?: { sessionId: string; upgradeUrl?: string }) =>
17-
session?.upgradeUrl ??
18-
`https://plans.test/?feature=reverse${session ? `&rs=${session.sessionId}` : ""}`,
15+
vi.mock("../../heygen/plan.js", async (importOriginal) => ({
16+
...(await importOriginal<typeof import("../../heygen/plan.js")>()),
17+
pageUrl: (_kind: string, fields: { feature?: string; rs?: string } = {}) =>
18+
`https://plans.test/?feature=${fields.feature}${fields.rs ? `&rs=${fields.rs}` : ""}`,
19+
}));
20+
vi.mock("../../heygen/reverse.js", async (importOriginal) => ({
21+
...(await importOriginal<typeof import("../../heygen/reverse.js")>()),
1922
startReverseSession: async (opts: { resumeSessionId?: string } = {}) => {
2023
server.resumed.push(opts.resumeSessionId);
2124
return server.answer;
@@ -33,11 +36,11 @@ const { default: start } = await import("./start.js");
3336
const SESSION = "rvs_0f8fad5b-d9cb-469f-a165-70867728950e";
3437
const recorded = (
3538
plan: "free" | "pro" | "unknown" = "pro",
36-
upgradeUrl?: string,
39+
upgradeUrl?: string | null,
3740
gate: "record" | "block" = "record",
3841
): ReverseStart => ({
3942
recorded: true,
40-
session: { sessionId: SESSION, plan, gate, ...(upgradeUrl ? { upgradeUrl } : {}) },
43+
session: { sessionId: SESSION, plan, gate, ...(upgradeUrl !== undefined ? { upgradeUrl } : {}) },
4144
});
4245

4346
let root: string;
@@ -114,7 +117,7 @@ describe("reverse start", () => {
114117
expect(config(dir)).toMatchObject({ reverseSessionId: SESSION });
115118
});
116119

117-
it.each<[string, ReverseStart, string]>([
120+
it.each<[string, ReverseStart, string | null]>([
118121
[
119122
"the server's link",
120123
recorded("free", "https://u.test/p?feature=reverse&rs=1"),
@@ -130,6 +133,7 @@ describe("reverse start", () => {
130133
{ recorded: false, reason: "unavailable", plan: "free" },
131134
"https://plans.test/?feature=reverse",
132135
],
136+
["no link when the server withholds it", recorded("free", null), null],
133137
])("prints the upgrade link for Free: %s", async (_label, answer, link) => {
134138
server.answer = answer;
135139
await run();
@@ -198,6 +202,25 @@ describe("reverse start", () => {
198202
});
199203
});
200204

205+
it("names no subscribe command when the server withholds the link", async () => {
206+
server.answer = recorded("free", null);
207+
await run();
208+
expect(output().reverse).toMatchObject({ upgrade_url: null, subscribe_command: null });
209+
});
210+
211+
it("names no link when the server blocks Free and withholds the link: no plan can be bought now", async () => {
212+
server.answer = recorded("free", null, "block");
213+
const dir = join(root, "rebuild");
214+
await expect(run("--dir", dir)).rejects.toThrow(CliRuntimeError);
215+
expect(output()).toMatchObject({
216+
ok: false,
217+
error: expect.stringContaining("can't be purchased right now"),
218+
});
219+
expect(printed.at(-1)).not.toContain("http");
220+
expect(printed.at(-1)).not.toContain("billing subscribe");
221+
expect(config(dir)).toMatchObject({ reverseSessionId: SESSION });
222+
});
223+
201224
it.each<[string, ReverseStart]>([
202225
["a Pro account under block", recorded("pro", undefined, "block")],
203226
["an unknown plan under block", recorded("unknown", undefined, "block")],

‎packages/cli/src/commands/reverse/start.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export function subscribeCommand(sessionId?: string): string {
3030
return `npx hyperframes billing subscribe --feature reverse${sessionId ? ` --session ${sessionId}` : ""}`;
3131
}
3232

33+
function freeFields(session: ReverseSession) {
34+
const link = reverseUpgradeUrl(session);
35+
return {
36+
upgrade_url: link,
37+
subscribe_command: link === null ? null : subscribeCommand(session.sessionId),
38+
};
39+
}
40+
3341
function summary(started: ReverseStart, savedTo: string | undefined) {
3442
if (!started.recorded) {
3543
return {
@@ -49,17 +57,18 @@ function summary(started: ReverseStart, savedTo: string | undefined) {
4957
session_id: session.sessionId,
5058
gate: session.gate,
5159
saved_to: savedTo ?? null,
52-
...(session.plan === "free"
53-
? {
54-
upgrade_url: reverseUpgradeUrl(session),
55-
subscribe_command: subscribeCommand(session.sessionId),
56-
}
57-
: {}),
60+
...(session.plan === "free" ? freeFields(session) : {}),
5861
};
5962
}
6063

6164
function refusalWhenServerBlocksFree(session: ReverseSession): Fix | undefined {
6265
if (session.gate !== "block" || session.plan !== "free") return undefined;
66+
if (reverseUpgradeUrl(session) === null) {
67+
return new Fix(
68+
"Reverse is part of HyperFrames Pro, and a plan can't be purchased right now.",
69+
"Run reverse start again once this account is on Pro.",
70+
);
71+
}
6372
const command = subscribeCommand(session.sessionId);
6473
return new Fix(
6574
`Reverse is part of HyperFrames Pro. Run \`${command}\`, then run reverse start again.`,

‎packages/cli/src/heygen/reverse.test.ts‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ describe("startReverseSession", () => {
8181
it("keeps a session whose plan the server could not read, without reading the plan itself", async () => {
8282
serve({
8383
[START_URL]: () =>
84-
Response.json({
85-
data: { session_id: SESSION, plan: "unknown", gate: "block", upgrade_url: null },
86-
}),
84+
Response.json({ data: { session_id: SESSION, plan: "unknown", gate: "block" } }),
8785
[PLAN_URL]: freePlan,
8886
});
8987
expect(await startReverseSession()).toEqual({
@@ -93,6 +91,21 @@ describe("startReverseSession", () => {
9391
expect(calls.map((c) => c.url)).toEqual([START_URL]);
9492
});
9593

94+
it.each([
95+
["a link", { upgrade_url: "https://u.test/p" }, { upgradeUrl: "https://u.test/p" }],
96+
["null, as the server withholds the link", { upgrade_url: null }, { upgradeUrl: null }],
97+
["no field, as an older server sends", {}, {}],
98+
])("reads upgrade_url when it is %s", async (_label, field, read) => {
99+
serve({
100+
[START_URL]: () =>
101+
Response.json({ data: { session_id: SESSION, plan: "free", gate: "block", ...field } }),
102+
});
103+
expect(await startReverseSession()).toEqual({
104+
recorded: true,
105+
session: { sessionId: SESSION, plan: "free", gate: "block", ...read },
106+
});
107+
});
108+
96109
it("asks nothing when not signed in", async () => {
97110
auth.signedIn = false;
98111
serve({});
@@ -145,6 +158,10 @@ describe("reverseUpgradeUrl", () => {
145158
);
146159
expect(reverseUpgradeUrl()).toBe("https://hyperframes.studio/pricing?from=cli&feature=reverse");
147160
});
161+
162+
it("is null when the server withholds the link, instead of building one", () => {
163+
expect(reverseUpgradeUrl({ sessionId: SESSION, upgradeUrl: null })).toBeNull();
164+
});
148165
});
149166

150167
describe("reverseSurface", () => {

‎packages/cli/src/heygen/reverse.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface ReverseSession {
1111
sessionId: string;
1212
plan: ReversePlan;
1313
gate: ReverseGate;
14-
upgradeUrl?: string;
14+
upgradeUrl?: string | null;
1515
}
1616

1717
export type ReverseStart =
@@ -41,7 +41,8 @@ function parseSession(body: unknown): ReverseSession | undefined {
4141
const plan = oneOf(data.plan, PLANS);
4242
const gate = oneOf(data.gate, GATES);
4343
if (!sessionId || !plan || !gate) return undefined;
44-
const upgradeUrl = typeof data.upgrade_url === "string" ? { upgradeUrl: data.upgrade_url } : {};
44+
const url = data.upgrade_url;
45+
const upgradeUrl = typeof url === "string" || url === null ? { upgradeUrl: url } : {};
4546
return { sessionId, plan, gate, ...upgradeUrl };
4647
}
4748

@@ -52,8 +53,12 @@ async function fallbackPlan(): Promise<"free" | "pro" | undefined> {
5253
return plan.plan === "none" ? "free" : "pro";
5354
}
5455

55-
/** The link that credits a purchase to this run: the server's, else the plans page with the same fields. */
56-
export function reverseUpgradeUrl(session?: { sessionId: string; upgradeUrl?: string }): string {
56+
/** The link that credits a purchase to this run: the server's (null: none can be bought), else the plans page. */
57+
export function reverseUpgradeUrl(session?: {
58+
sessionId: string;
59+
upgradeUrl?: string | null;
60+
}): string | null {
61+
if (session?.upgradeUrl === null) return null;
5762
return session?.upgradeUrl ?? pageUrl("plans", { feature: "reverse", rs: session?.sessionId });
5863
}
5964

‎skills-manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"files": 76
2727
},
2828
"reverse-any-video": {
29-
"hash": "c0a1d4132928c0e1",
29+
"hash": "e809ebdad20e0f9a",
3030
"files": 5
3131
},
3232
"slideshow": {

‎skills/reverse-any-video/references/start.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ before it finishes. For example:
4343
> your browser and I'll carry on as soon as you're subscribed.
4444
4545
When `reverse start` refuses the run (it exits with an error whose `fix` is that command), run the `fix` the same way,
46-
then run `reverse start` again. Only on a CLI without `reverse start`, run `npx hyperframes billing subscribe` instead.
47-
If the command times out, tell the person and run it again once they say they are ready.
46+
then run `reverse start` again. When `subscribe_command` is `null` (or the refusal names no command), a plan can't be
47+
purchased right now: say so plainly, give no link, run nothing, and stop. Only on a CLI without `reverse start`, run
48+
`npx hyperframes billing subscribe` instead. If the command times out, tell the person and run it again once they say
49+
they are ready.
4850
4951
## Signed in on Pro
5052

0 commit comments

Comments
 (0)