Skip to content

Commit e7d8784

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, the refusal says a plan can't be purchased right now, and the skill 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 7f3fa93 commit e7d8784

7 files changed

Lines changed: 71 additions & 20 deletions

File tree

‎docs/packages/cli.mdx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,9 +1518,11 @@ run started and saves the session HeyGen returns in the project's
15181518
with the render. It then prints the video's [`measure probe`](#measure) JSON,
15191519
with a `reverse` field: whether you are signed in, the plan (`free`, `pro`, or
15201520
`null` when unknown), the session, and on Free the `upgrade_url` that credits a
1521-
purchase to this run. It stops the run only when HeyGen blocks it for a Free
1522-
account: it then exits non-zero with that upgrade link. Signed out, offline, or
1523-
on a server without the route, it skips the session and still probes.
1521+
purchase to this run (`null` when HeyGen says no plan can be bought right now).
1522+
It stops the run only when HeyGen blocks it for a Free account: it then exits
1523+
non-zero with that upgrade link, or, without one, says a plan can't be purchased
1524+
right now. Signed out, offline, or on a server without the route, it skips the
1525+
session and still probes.
15241526

15251527
```bash
15261528
npx hyperframes reverse start ref.mp4 --dir my-rebuild

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

Lines changed: 23 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();
@@ -189,6 +193,18 @@ describe("reverse start", () => {
189193
expect(output()).toMatchObject({ ok: false, error: expect.stringContaining(link), fix: link });
190194
});
191195

196+
it("names no link when the server blocks Free and withholds the link: no plan can be bought now", async () => {
197+
server.answer = recorded("free", null, "block");
198+
const dir = join(root, "rebuild");
199+
await expect(run("--dir", dir)).rejects.toThrow(CliRuntimeError);
200+
expect(output()).toMatchObject({
201+
ok: false,
202+
error: expect.stringContaining("can't be purchased right now"),
203+
});
204+
expect(printed.at(-1)).not.toContain("http");
205+
expect(config(dir)).toMatchObject({ reverseSessionId: SESSION });
206+
});
207+
192208
it.each<[string, ReverseStart]>([
193209
["a Pro account under block", recorded("pro", undefined, "block")],
194210
["an unknown plan under block", recorded("unknown", undefined, "block")],

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ function summary(started: ReverseStart, savedTo: string | undefined) {
5050
function refusalWhenServerBlocksFree(session: ReverseSession): Fix | undefined {
5151
if (session.gate !== "block" || session.plan !== "free") return undefined;
5252
const link = reverseUpgradeUrl(session);
53+
if (link === null) {
54+
return new Fix(
55+
"Reverse is part of HyperFrames Pro, and a plan can't be purchased right now.",
56+
"Run reverse start again once this account is on Pro.",
57+
);
58+
}
5359
return new Fix(
5460
`Reverse is part of HyperFrames Pro. Upgrade here, then run reverse start again: ${link}`,
5561
link,

‎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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export interface ReverseSession {
1111
sessionId: string;
1212
plan: ReversePlan;
1313
gate: ReverseGate;
14-
upgradeUrl?: string;
14+
/** null: the server withholds the link because no plan can be bought now; absent: an older server. */
15+
upgradeUrl?: string | null;
1516
}
1617

1718
export type ReverseStart =
@@ -41,7 +42,8 @@ function parseSession(body: unknown): ReverseSession | undefined {
4142
const plan = oneOf(data.plan, PLANS);
4243
const gate = oneOf(data.gate, GATES);
4344
if (!sessionId || !plan || !gate) return undefined;
44-
const upgradeUrl = typeof data.upgrade_url === "string" ? { upgradeUrl: data.upgrade_url } : {};
45+
const url = data.upgrade_url;
46+
const upgradeUrl = typeof url === "string" || url === null ? { upgradeUrl: url } : {};
4547
return { sessionId, plan, gate, ...upgradeUrl };
4648
}
4749

@@ -52,8 +54,15 @@ async function fallbackPlan(): Promise<"free" | "pro" | undefined> {
5254
return plan.plan === "none" ? "free" : "pro";
5355
}
5456

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 {
57+
/**
58+
* The link that credits a purchase to this run: the server's; null when the server withholds it (no
59+
* plan can be bought now); else, from an older server, the plans page with the same fields.
60+
*/
61+
export function reverseUpgradeUrl(session?: {
62+
sessionId: string;
63+
upgradeUrl?: string | null;
64+
}): string | null {
65+
if (session?.upgradeUrl === null) return null;
5766
return session?.upgradeUrl ?? pageUrl("plans", { feature: "reverse", rs: session?.sessionId });
5867
}
5968

‎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": "fe326730ec89a06b",
29+
"hash": "1d271eab16212cb7",
3030
"files": 5
3131
},
3232
"slideshow": {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ example:
4444
> Reply "done" once you're on Pro and I'll start.
4545
4646
When `reverse start` refuses the run (it exits with an error whose `fix` is the upgrade link), give the person that
47-
exact link and stop; once they reply that they are on Pro, run `reverse start` again. Only on a CLI without
48-
`reverse start`, give `! npx hyperframes billing subscribe` instead.
47+
exact link and stop; once they reply that they are on Pro, run `reverse start` again. When `upgrade_url` is `null`
48+
(or the refusal names no link), a plan can't be purchased right now: say so plainly, give no link, and stop. Only on
49+
a CLI without `reverse start`, give `! npx hyperframes billing subscribe` instead.
4950
5051
## Signed in on Pro
5152

0 commit comments

Comments
 (0)