mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 19:36:04 +00:00
fix(share): persist refusals and improve CLI retry feedback
This commit is contained in:
@@ -411,7 +411,7 @@ describe("CLI lifecycle", () => {
|
||||
});
|
||||
|
||||
describe("stale-skills notice under --json", () => {
|
||||
it("prints on a --json run while the self-update notices stay off", async () => {
|
||||
it("suppresses unrelated notices on a --json run", async () => {
|
||||
const printSkillsUpdateNotice = vi.fn();
|
||||
const printUpdateNotice = vi.fn();
|
||||
mockInitCommand(vi.fn());
|
||||
@@ -431,7 +431,7 @@ describe("stale-skills notice under --json", () => {
|
||||
process.argv = ["node", "cli.ts", "init", "--json"];
|
||||
await import("./cli.js");
|
||||
|
||||
await vi.waitFor(() => expect(printSkillsUpdateNotice).toHaveBeenCalledTimes(1));
|
||||
expect(printSkillsUpdateNotice).not.toHaveBeenCalled();
|
||||
expect(printUpdateNotice).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -327,12 +327,13 @@ if (
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
// Skills freshness nudge: stderr only, so it also runs under --json, which agents pass.
|
||||
import("./utils/skillsUpdateCheck.js")
|
||||
.then((mod) => {
|
||||
_printSkillsUpdateNotice = mod.printSkillsUpdateNotice;
|
||||
})
|
||||
.catch(() => {});
|
||||
// Machine-readable commands should not include unrelated update notices.
|
||||
if (!hasJsonFlag)
|
||||
import("./utils/skillsUpdateCheck.js")
|
||||
.then((mod) => {
|
||||
_printSkillsUpdateNotice = mod.printSkillsUpdateNotice;
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
// The notices read the caches; a detached child refreshes them for the next run.
|
||||
import("./utils/backgroundChecks.js").then((mod) => mod.launchBackgroundChecks()).catch(() => {});
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
import { runCommand } from "citty";
|
||||
import { consumeCommandResult } from "../utils/commandResult.js";
|
||||
const mocks = vi.hoisted(() => ({ run: vi.fn() }));
|
||||
const mocks = vi.hoisted(() => ({
|
||||
run: vi.fn(),
|
||||
progress: undefined as undefined | ((value: { step: string; slow?: boolean } | null) => void),
|
||||
}));
|
||||
vi.mock("../utils/project.js", () => ({ resolveProjectOrThrow: () => ({ dir: "/project" }) }));
|
||||
vi.mock("../share/service.js", () => ({ createShareService: () => ({ run: mocks.run }) }));
|
||||
vi.mock("../share/service.js", () => ({
|
||||
createShareService: (_dir: string, progress: typeof mocks.progress) => {
|
||||
mocks.progress = progress;
|
||||
return { run: mocks.run };
|
||||
},
|
||||
}));
|
||||
import command from "./share.js";
|
||||
beforeEach(() => {
|
||||
consumeCommandResult();
|
||||
mocks.run.mockReset();
|
||||
mocks.run.mockResolvedValue({
|
||||
state: "failed",
|
||||
ready: false,
|
||||
@@ -50,3 +59,40 @@ it("still opens management when the latest export failed", async () => {
|
||||
expect(consumeCommandResult().exitCode).toBe(0);
|
||||
expect(JSON.parse(String(out.mock.calls[0]?.[0])).ok).toBe(true);
|
||||
});
|
||||
|
||||
it.each(["--status", "--manage", "--update"])(
|
||||
"rejects ignored audience flags with %s",
|
||||
async (action) => {
|
||||
vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
await runCommand(command, { rawArgs: [action, "--public", "--json"] });
|
||||
expect(consumeCommandResult().exitCode).toBe(2);
|
||||
expect(mocks.run).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
it("says there is nothing to manage before a first share", async () => {
|
||||
mocks.run.mockResolvedValue({ state: "not_shared" });
|
||||
const out = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
await runCommand(command, { rawArgs: ["--manage", "--json"] });
|
||||
expect(JSON.parse(String(out.mock.calls[0]?.[0]))).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: "not_shared" },
|
||||
});
|
||||
});
|
||||
|
||||
it("deduplicates progress and terminates each message before the friendly error", async () => {
|
||||
const err = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
const friendly = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
mocks.run.mockImplementation(async () => {
|
||||
mocks.progress?.({ step: "preparing" });
|
||||
mocks.progress?.({ step: "preparing" });
|
||||
mocks.progress?.({ step: "uploading" });
|
||||
mocks.progress?.(null);
|
||||
throw new Error("Sharing blocked.");
|
||||
});
|
||||
await runCommand(command, { rawArgs: ["--private", "-y"] });
|
||||
expect(err.mock.calls.map(([message]) => message)).toEqual([
|
||||
"Sharing: preparing\n",
|
||||
"Sharing: uploading\n",
|
||||
]);
|
||||
expect(friendly).toHaveBeenCalledWith("Sharing blocked.");
|
||||
});
|
||||
|
||||
@@ -61,11 +61,12 @@ export default defineCommand({
|
||||
try {
|
||||
const input = parseInput(args);
|
||||
const project = resolveProjectOrThrow(args.dir);
|
||||
let lastProgress = "";
|
||||
const service: ShareService = createShareService(project.dir, (value) => {
|
||||
if (value && !args.json)
|
||||
process.stderr.write(
|
||||
`Sharing: ${value.step}${value.slow ? " (still processing)" : ""}\r`,
|
||||
);
|
||||
if (!value || args.json) return;
|
||||
const message = `Sharing: ${value.step}${value.slow ? " (still processing)" : ""}`;
|
||||
if (message !== lastProgress) process.stderr.write(`${message}\n`);
|
||||
lastProgress = message;
|
||||
});
|
||||
await chooseAudience(input, args, service);
|
||||
const result = await service.run(input);
|
||||
@@ -102,9 +103,23 @@ function parseInput(args: ShareArgs): ShareAction {
|
||||
const audience = requestedAudience(args);
|
||||
const action = args.status ? "status" : args.manage ? "manage" : args.update ? "update" : "share";
|
||||
|
||||
validateActionOptions(action, audience, args);
|
||||
return { action, audience, space: args.space, waitSeconds, videoOnly: args["video-only"] };
|
||||
}
|
||||
|
||||
function validateActionOptions(
|
||||
action: ShareAction["action"],
|
||||
audience: ShareAction["audience"],
|
||||
args: ShareArgs,
|
||||
) {
|
||||
if (action !== "share" && audience)
|
||||
throw new CliUsageError(
|
||||
"Audience flags are only valid for a first share. Use --manage to change access.",
|
||||
);
|
||||
if ((action === "status" || action === "manage") && (args.space || args["video-only"]))
|
||||
throw new CliUsageError("--space and --video-only cannot be used with --status or --manage.");
|
||||
}
|
||||
|
||||
function requestedAudience(args: ShareArgs) {
|
||||
const audiences: NonNullable<ShareAction["audience"]>[] = [];
|
||||
if (args.public) audiences.push("public");
|
||||
@@ -142,6 +157,10 @@ async function chooseAudience(input: ShareAction, args: ShareArgs, service: Shar
|
||||
}
|
||||
|
||||
async function presentResult(result: ShareState, input: ShareAction, json: boolean) {
|
||||
if (input.action === "manage" && result.state === "not_shared")
|
||||
throw new CliUsageError("There is no share to manage yet. Create a share first.", {
|
||||
code: "not_shared",
|
||||
});
|
||||
if (!json && result.source.at === "video_only")
|
||||
console.error(`Sharing video only (${result.source.reason}).`);
|
||||
if (result.state === "failed" && input.action !== "manage") {
|
||||
|
||||
@@ -237,6 +237,7 @@ describe("share operation consent and identity", () => {
|
||||
mocks.status.mockResolvedValue(shared);
|
||||
mocks.project.mockResolvedValue({ latest_ready_version_id: null });
|
||||
mocks.version.mockResolvedValue({ last: null, source: "stale" });
|
||||
mocks.pending.mockResolvedValue({ projectId: "project", videoId: "upload" });
|
||||
await expect(createShareService("/project").run({ action: "share" })).rejects.toThrow(
|
||||
"--update",
|
||||
);
|
||||
@@ -409,3 +410,16 @@ it.each([null, "previous-version"])(
|
||||
expect(mocks.add).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it("retries an uncreated first version after refusal even when local files changed", async () => {
|
||||
mocks.status.mockResolvedValue(shared);
|
||||
mocks.project.mockResolvedValue({ latest_ready_version_id: null });
|
||||
mocks.version.mockResolvedValue({ last: null, source: "stale", failure: "Sharing blocked." });
|
||||
mocks.add.mockResolvedValue("Sharing blocked.");
|
||||
await expect(
|
||||
createShareService("/project").run({ action: "share", audience: "public" }),
|
||||
).rejects.toThrow("Sharing blocked.");
|
||||
expect(mocks.render).toHaveBeenCalledOnce();
|
||||
expect(mocks.add).toHaveBeenCalledOnce();
|
||||
expect(mocks.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -85,7 +85,9 @@ function statusLinks(
|
||||
return {
|
||||
url: ready ? url : null,
|
||||
previousUrl: processing && project?.latest_ready_version_id ? url : null,
|
||||
manageUrl: project?.authenticated_review_url ?? `${shareSite()}/shares`,
|
||||
manageUrl:
|
||||
project?.authenticated_review_url ??
|
||||
`${shareSite() === "https://hyperframes.dev" ? "https://hyperframes.studio" : shareSite()}/shares`,
|
||||
};
|
||||
}
|
||||
function isProcessing(
|
||||
@@ -117,7 +119,13 @@ function assertExistingIntent(share: ReviewShare | null, input: ShareAction) {
|
||||
throw new ReviewFailed(409, "manage_existing_audience");
|
||||
}
|
||||
function retrievesExisting(current: ShareState, input: ShareAction) {
|
||||
return current.share && input.action === "share" && current.state !== "processing";
|
||||
return (
|
||||
current.share &&
|
||||
input.action === "share" &&
|
||||
(current.ready ||
|
||||
current.state === "link_off" ||
|
||||
(current.version.last && current.state !== "processing"))
|
||||
);
|
||||
}
|
||||
async function preflightFirst(dir: string, client: ReviewClient, input: ShareAction) {
|
||||
const audience = input.audience;
|
||||
@@ -152,7 +160,12 @@ function assertAudience(audience: AccessMode, space: Space) {
|
||||
throw new ReviewFailed(402, "review_subscription_required");
|
||||
}
|
||||
function assertResumeSource(current: ShareState, input: ShareAction) {
|
||||
if (current.share && input.action === "share" && current.version.source !== "ready")
|
||||
if (
|
||||
current.share &&
|
||||
current.pending &&
|
||||
input.action === "share" &&
|
||||
current.version.source !== "ready"
|
||||
)
|
||||
throw new Error(
|
||||
"The shared video is unfinished and local edits have changed. Run hyperframes share --update to explicitly upload the current project.",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user