Skip to content

Commit 9490d27

Browse files
committed
fix(cli): reverse on Free runs billing subscribe credited to the run
1 parent ebced71 commit 9490d27

8 files changed

Lines changed: 102 additions & 30 deletions

File tree

‎docs/packages/cli.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,9 +1518,10 @@ run started and saves the session HeyGen returns in the project's
15181518
`hyperframes.json`; [`cloud render`](#hyperframes-cloud) then sends that session
15191519
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
1521-
`null` when unknown), the session, and on Free the `upgrade_url` that credits a
1521+
`null` when unknown), the session, and on Free the `upgrade_url` and the
1522+
`subscribe_command` ([`billing subscribe`](#billing) with the feature and session) that credit a
15221523
purchase to this run. It stops the run only when HeyGen blocks it for a Free
1523-
account: it then exits non-zero with that upgrade link. Signed out, offline, or
1524+
account: it then exits non-zero with that command. Signed out, offline, or
15241525
on a server without the route, it skips the session and still probes.
15251526

15261527
```bash
@@ -2272,6 +2273,8 @@ npx hyperframes billing top-up --needed 180
22722273
| Flag | Description |
22732274
| ----------- | -------------------------------------------------------------------------- |
22742275
| `--needed` | Credits the waiting step needs; `top-up` waits until the balance covers it |
2276+
| `--feature` | The feature that sent the person here, so a purchase is credited to it |
2277+
| `--session` | The run to credit the purchase to, with `--feature` |
22752278
| `--tool` | The step that is waiting, shown on the page |
22762279
| `--timeout` | Seconds to wait (default 600) |
22772280

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { runCommand } from "citty";
2+
import { afterEach, describe, expect, it, vi } from "vitest";
3+
import { consumeCommandResult } from "../utils/commandResult.js";
4+
5+
const opened = vi.hoisted(() => [] as string[]);
6+
7+
vi.mock("../auth/browser.js", () => ({
8+
openBrowser: async (url: string) => void opened.push(url),
9+
}));
10+
vi.mock("../heygen/plan.js", async (importOriginal) => {
11+
const real = await importOriginal<typeof import("../heygen/plan.js")>();
12+
let calls = 0;
13+
return {
14+
...real,
15+
readPlan: async () => ({ plan: ++calls === 1 ? "none" : "pro", credits: 0 }),
16+
};
17+
});
18+
19+
const { default: billing } = await import("./billing.js");
20+
21+
afterEach(() => {
22+
opened.length = 0;
23+
vi.restoreAllMocks();
24+
consumeCommandResult();
25+
});
26+
27+
describe("billing subscribe", () => {
28+
it("opens the plans page credited to the feature and run that sent the person", async () => {
29+
vi.spyOn(console, "log").mockImplementation(() => undefined);
30+
vi.useFakeTimers();
31+
const done = runCommand(billing, {
32+
rawArgs: ["subscribe", "--feature", "reverse", "--session", "rvs_abc"],
33+
});
34+
await vi.advanceTimersByTimeAsync(2000);
35+
await done;
36+
vi.useRealTimers();
37+
const url = new URL(opened[0] ?? "");
38+
expect(url.searchParams.get("feature")).toBe("reverse");
39+
expect(url.searchParams.get("rs")).toBe("rvs_abc");
40+
});
41+
});

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export default defineCommand({
2121
description: "Credits the waiting step needs (top-up waits until the balance covers it)",
2222
},
2323
tool: { type: "string", description: "The step that is waiting, shown on the page" },
24+
feature: {
25+
type: "string",
26+
description: "The feature that sent the person here, so a purchase is credited to it",
27+
},
28+
session: { type: "string", description: "The run to credit the purchase to (with --feature)" },
2429
timeout: { type: "string", description: "Seconds to wait (default 600)" },
2530
},
2631
// fallow-ignore-next-line complexity
@@ -40,7 +45,12 @@ export default defineCommand({
4045
console.log(c.success(`✓ Already covered: ${describe(before)}.`));
4146
return;
4247
}
43-
const url = pageUrl(action === "subscribe" ? "plans" : "credits", { needed, tool: args.tool });
48+
const url = pageUrl(action === "subscribe" ? "plans" : "credits", {
49+
needed,
50+
tool: args.tool,
51+
feature: args.feature,
52+
rs: args.session,
53+
});
4454
console.log(`${action === "subscribe" ? "Plans" : "Credits"} page: ${c.accent(url)}`);
4555
await openBrowser(url);
4656
console.log("Waiting for the person to finish there ...");

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,29 @@ describe("reverse start", () => {
173173
expect(() => readFileSync(join(dir, "hyperframes.json"))).toThrow();
174174
});
175175

176-
it("stops a Free account the server blocks, with its upgrade link as the fix, after saving the session", async () => {
177-
const link = "https://hyperframes.studio/pricing?feature=reverse&rs=1";
178-
server.answer = recorded("free", link, "block");
176+
it("stops a Free account the server blocks, with the subscribe command as the fix, after saving the session", async () => {
177+
server.answer = recorded(
178+
"free",
179+
"https://hyperframes.studio/pricing?feature=reverse&rs=1",
180+
"block",
181+
);
179182
const dir = join(root, "rebuild");
180183
await expect(run("--dir", dir)).rejects.toThrow(CliRuntimeError);
181-
expect(output()).toMatchObject({ ok: false, error: expect.stringContaining(link), fix: link });
184+
const command = `npx hyperframes billing subscribe --feature reverse --session ${SESSION}`;
185+
expect(output()).toMatchObject({
186+
ok: false,
187+
error: expect.stringContaining(command),
188+
fix: command,
189+
});
182190
expect(config(dir)).toMatchObject({ reverseSessionId: SESSION });
183191
});
184192

185-
it("builds the attributed plans link when a block names none", async () => {
186-
server.answer = recorded("free", undefined, "block");
187-
await expect(run()).rejects.toThrow(CliRuntimeError);
188-
const link = `https://plans.test/?feature=reverse&rs=${SESSION}`;
189-
expect(output()).toMatchObject({ ok: false, error: expect.stringContaining(link), fix: link });
193+
it("names the subscribe command on a Free account the server lets through", async () => {
194+
server.answer = recorded("free");
195+
await run();
196+
expect(output().reverse).toMatchObject({
197+
subscribe_command: `npx hyperframes billing subscribe --feature reverse --session ${SESSION}`,
198+
});
190199
});
191200

192201
it.each<[string, ReverseStart]>([

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,20 @@ export const examples: Example[] = [
2626

2727
const SKILL = "reverse-any-video";
2828

29+
/** The command that opens the plans page credited to this run and waits for the subscription. */
30+
export function subscribeCommand(sessionId?: string): string {
31+
return `npx hyperframes billing subscribe --feature reverse${sessionId ? ` --session ${sessionId}` : ""}`;
32+
}
33+
2934
function summary(started: ReverseStart, savedTo: string | undefined) {
3035
if (!started.recorded) {
3136
return {
3237
signed_in: started.reason !== "not_signed_in",
3338
plan: started.plan ?? null,
3439
recorded: false,
35-
...(started.plan === "free" ? { upgrade_url: reverseUpgradeUrl() } : {}),
40+
...(started.plan === "free"
41+
? { upgrade_url: reverseUpgradeUrl(), subscribe_command: subscribeCommand() }
42+
: {}),
3643
};
3744
}
3845
const { session } = started;
@@ -43,16 +50,21 @@ function summary(started: ReverseStart, savedTo: string | undefined) {
4350
session_id: session.sessionId,
4451
gate: session.gate,
4552
saved_to: savedTo ?? null,
46-
...(session.plan === "free" ? { upgrade_url: reverseUpgradeUrl(session) } : {}),
53+
...(session.plan === "free"
54+
? {
55+
upgrade_url: reverseUpgradeUrl(session),
56+
subscribe_command: subscribeCommand(session.sessionId),
57+
}
58+
: {}),
4759
};
4860
}
4961

5062
function refusalWhenServerBlocksFree(session: ReverseSession): Fix | undefined {
5163
if (session.gate !== "block" || session.plan !== "free") return undefined;
52-
const link = reverseUpgradeUrl(session);
64+
const command = subscribeCommand(session.sessionId);
5365
return new Fix(
54-
`Reverse is part of HyperFrames Pro. Upgrade here, then run reverse start again: ${link}`,
55-
link,
66+
`Reverse is part of HyperFrames Pro. Run \`${command}\`, then run reverse start again.`,
67+
command,
5668
);
5769
}
5870

‎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": "83dfae84850777c2",
29+
"hash": "aad8973f2ea4caa6",
3030
"files": 5
3131
},
3232
"slideshow": {

‎skills/reverse-any-video/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: Rebuild any video file as an editable HyperFrames project - motion
99

1010
The result is a HyperFrames project whose render matches the original frame for frame and stays editable. Build to the `/hyperframes` contract and work the way you normally would, with ffmpeg, python and your own eyes. Reverse videos the person has the right to use.
1111

12-
Reverse is a HyperFrames Pro feature: go on only on a paid plan, not Free. Open with `npx hyperframes reverse start <video> --dir <project>` (a CLI without it: `auth status`, `measure probe`) and `references/start.md`; if it refuses, pass on its upgrade link and stop. Resuming (a `REVERSE.md` or half-built project) opens the same way. A step an earlier session gave up on (a re-shoot HeyGen refused) gets one more try, then ask the person. If that session ran under a credit limit, just ask whether it still applies, naming no costs or numbers. Rebuild the video as it is; remix it only when the person asks.
12+
Reverse is a HyperFrames Pro feature: go on only on a paid plan, not Free. Open with `npx hyperframes reverse start <video> --dir <project>` (a CLI without it: `auth status`, `measure probe`) and `references/start.md`; if it refuses, run the `fix` it names (`billing subscribe`, which waits for the upgrade) and then start again. Resuming (a `REVERSE.md` or half-built project) opens the same way. A step an earlier session gave up on (a re-shoot HeyGen refused) gets one more try, then ask the person. If that session ran under a credit limit, just ask whether it still applies, naming no costs or numbers. Rebuild the video as it is; remix it only when the person asks.
1313

1414
## The original decides the frame
1515

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,17 @@ video, so they move and speak as they do in the original. For example:
3333
3434
## Signed in on Free
3535
36-
Reverse is part of Pro. Open the upgrade page in the person's browser yourself, tell them why in one line, and start
37-
nothing until they are on Pro. The link is `reverse.upgrade_url` from `reverse start`, passed on exactly as printed: it
38-
credits the purchase to this run. Open it with the URL in quotes, because it holds `&`: `open "<url>"` (macOS),
39-
`xdg-open "<url>"` (Linux), `start "" "<url>"` (Windows; the empty title is required). Print the link instead when
40-
`SSH_CONNECTION` or `SSH_TTY` is set, `BROWSER=none`, or the open command fails. For example:
36+
Reverse is part of Pro. Say why in one line, then run the `reverse.subscribe_command` from `reverse start` exactly as
37+
printed (`npx hyperframes billing subscribe --feature reverse --session <id>`): it opens the plans page in the person's
38+
browser, credits the purchase to this run, and waits until they are on Pro, so the run goes on by itself. Start nothing
39+
before it finishes. For example:
4140
4241
> Reverse is part of HyperFrames Pro: it re-shoots the people in your video with HeyGen. I've opened the upgrade page in
43-
> your browser (https://hyperframes.studio/pricing?feature=reverse&rs=…).
44-
>
45-
> Reply "done" once you're on Pro and I'll start.
42+
> your browser and I'll carry on as soon as you're subscribed.
4643
47-
When `reverse start` refuses the run (it exits with an error whose `fix` is the upgrade link), open that exact link the
48-
same way and stop; once they reply that they are on Pro, run `reverse start` again. Only on a CLI without
49-
`reverse start`, give `! npx hyperframes billing subscribe` instead.
44+
When `reverse start` refuses the run (it exits with an error whose `fix` is that command), run the `fix` the same way,
45+
then run `reverse start` again. Only on a CLI without `reverse start`, run `npx hyperframes billing subscribe` instead.
46+
If the command times out, tell the person and run it again once they say they are ready.
5047
5148
## Signed in on Pro
5249

0 commit comments

Comments
 (0)