mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(cli): show control characters as text in cloudrun and cloud printed lines (#8350)
The cloudrun commands and the remaining cloud render and cloud delete lines now pass quoted text through terminalText / terminalLines before printing, including the adapter notice callbacks and the confirm question. JSON output is unchanged. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
eaec4f4ad9
commit
af0664c8f5
@@ -91,7 +91,7 @@ export default defineCommand({
|
||||
async function confirmDelete(id: string): Promise<boolean> {
|
||||
const clack = await import("../../ui/prompts.js");
|
||||
const answer = await clack.confirm({
|
||||
message: `Delete render ${id}? This is irreversible.`,
|
||||
message: `Delete render ${terminalText(id)}? This is irreversible.`,
|
||||
initialValue: false,
|
||||
});
|
||||
return answer === true;
|
||||
|
||||
@@ -163,4 +163,72 @@ describe.skipIf(process.platform === "win32")("cloud render on a terminal", () =
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
// fails without the fix: the asset id, the render id, the status and the download path are printed as they arrived.
|
||||
it("prints reply ids, the status and the download path with control characters as visible escapes", async () => {
|
||||
const odd = `${esc}[2Jx${String.fromCharCode(7)}`;
|
||||
const shown = "\\x1b[2Jx\\x07";
|
||||
const renderId = `hfr${odd}`;
|
||||
let polls = 0;
|
||||
const server = createServer((request, response) => {
|
||||
request.resume();
|
||||
request.on("end", () => {
|
||||
const path = request.url ?? "";
|
||||
response.setHeader("content-type", "application/json");
|
||||
if (path === "/v3/assets/direct-uploads") {
|
||||
const data = {
|
||||
asset_id: `asst${odd}`,
|
||||
upload_url: `${baseUrl}/upload`,
|
||||
upload_headers: {},
|
||||
};
|
||||
return response.end(JSON.stringify({ data }));
|
||||
}
|
||||
if (path === "/upload") return response.end("{}");
|
||||
if (path.endsWith("/complete")) {
|
||||
const data = { asset_id: `asst${odd}`, url: `${baseUrl}/project.zip` };
|
||||
return response.end(JSON.stringify({ data }));
|
||||
}
|
||||
if (path === "/video") return response.end("video");
|
||||
if (request.method === "POST") {
|
||||
response.statusCode = 202;
|
||||
return response.end(JSON.stringify({ data: { render_id: renderId } }));
|
||||
}
|
||||
const detail =
|
||||
++polls === 1
|
||||
? { render_id: renderId, status: `waiting${odd}`, format: "mp4" }
|
||||
: {
|
||||
render_id: renderId,
|
||||
status: "completed",
|
||||
format: "mp4",
|
||||
video_url: `${baseUrl}/video`,
|
||||
};
|
||||
response.end(JSON.stringify({ data: detail }));
|
||||
});
|
||||
});
|
||||
server.listen(0, "127.0.0.1");
|
||||
await once(server, "listening");
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
|
||||
const baseUrl = `http://127.0.0.1:${address.port}`;
|
||||
vi.stubEnv("HEYGEN_API_URL", baseUrl);
|
||||
try {
|
||||
const human = await humanOutput([
|
||||
dir,
|
||||
"--poll-interval",
|
||||
"1",
|
||||
"--output",
|
||||
join(dir, "out.mp4"),
|
||||
]);
|
||||
|
||||
expect(human.replace(colors, "")).not.toContain(esc);
|
||||
expect(human).toContain(`asst${shown}`);
|
||||
expect(human).toContain(`Polling hfr${shown} every 1s`);
|
||||
expect(human).toContain(`waiting${shown}`);
|
||||
expect(human).toContain("Downloading to ");
|
||||
expect(human).toContain("video\\x1b]0;x\\x07\\x1b[2J/out.mp4");
|
||||
} finally {
|
||||
server.closeAllConnections();
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -374,15 +374,15 @@ export default defineCommand({
|
||||
);
|
||||
} else {
|
||||
console.log("");
|
||||
console.log(`${c.success("✓")} Submitted ${c.accent(renderId)}`);
|
||||
console.log(c.dim(` Poll with: hyperframes cloud get ${renderId}`));
|
||||
console.log(`${c.success("✓")} Submitted ${c.accent(terminalText(renderId))}`);
|
||||
console.log(c.dim(` Poll with: hyperframes cloud get ${terminalText(renderId)}`));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!asJson) {
|
||||
console.log("");
|
||||
console.log(c.dim(` Polling ${renderId} every ${pollIntervalMs / 1000}s …`));
|
||||
console.log(c.dim(` Polling ${terminalText(renderId)} every ${pollIntervalMs / 1000}s …`));
|
||||
}
|
||||
|
||||
const detail = await pollWithProgress(client, renderId, asJson, {
|
||||
@@ -1063,7 +1063,7 @@ async function maybeUploadProject(
|
||||
if (!asJson) {
|
||||
console.log(
|
||||
c.dim(
|
||||
` asset_id: ${c.accent(uploaded.asset_id)} · ${formatDuration(Date.now() - uploadStart)}`,
|
||||
` asset_id: ${c.accent(terminalText(uploaded.asset_id))} · ${formatDuration(Date.now() - uploadStart)}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1196,7 +1196,7 @@ export function logsTick(
|
||||
}
|
||||
|
||||
function formatTickLine(detail: HyperframesRenderDetail, elapsedMs: number): string {
|
||||
const status = colorStatus(detail.status);
|
||||
const status = colorStatus(terminalText(detail.status));
|
||||
return `${status} ${c.dim(formatDuration(elapsedMs))}`;
|
||||
}
|
||||
|
||||
@@ -1242,7 +1242,7 @@ async function streamVideo(
|
||||
// `downloadToFile` creates the parent directory and preserves existing output on failure.
|
||||
if (!asJson) {
|
||||
console.log("");
|
||||
console.log(`${c.accent("◆")} Downloading to ${c.accent(destPath)}`);
|
||||
console.log(`${c.accent("◆")} Downloading to ${c.accent(terminalText(destPath))}`);
|
||||
}
|
||||
try {
|
||||
const result = await downloadToFile(url, destPath);
|
||||
|
||||
@@ -12,6 +12,13 @@ vi.mock("../../cloud/index.js", async (importOriginal) => ({
|
||||
createCloudClient: async () => client,
|
||||
}));
|
||||
|
||||
const ask = vi.hoisted(() => ({ confirm: vi.fn() }));
|
||||
vi.mock("../../ui/prompts.js", () => ask);
|
||||
vi.mock("../../utils/attendedTerminal.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../../utils/attendedTerminal.js")>()),
|
||||
isUnattended: () => false,
|
||||
}));
|
||||
|
||||
const { default: get } = await import("./get.js");
|
||||
const { default: list } = await import("./list.js");
|
||||
const { default: remove } = await import("./delete.js");
|
||||
@@ -99,4 +106,17 @@ describe("cloud subcommands on a terminal", () => {
|
||||
expect(human.replace(colors, "")).not.toContain(esc);
|
||||
expect(human).toContain(`r1${shown}`);
|
||||
});
|
||||
|
||||
// fails without the fix: the question repeats the id as it was typed.
|
||||
it("delete asks about an id with control characters as visible escapes", async () => {
|
||||
ask.confirm.mockResolvedValue(false);
|
||||
client.deleteRender.mockClear();
|
||||
|
||||
await expect(output(remove, [`r1${osc}`])).rejects.toThrow("Command failed");
|
||||
|
||||
expect(ask.confirm).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ message: `Delete render r1${shown}? This is irreversible.` }),
|
||||
);
|
||||
expect(client.deleteRender).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { consumeCommandResult } from "../utils/commandResult.js";
|
||||
|
||||
const ESC = String.fromCharCode(27);
|
||||
const ODD = `od${ESC}[2Jd\x07`;
|
||||
const SHOWN = "od\\x1b[2Jd\\x07";
|
||||
|
||||
const adapter = vi.hoisted(() => ({
|
||||
getRenderProgress: vi.fn(),
|
||||
renderToCloudRun: vi.fn(),
|
||||
deploySite: vi.fn(),
|
||||
getTerraformModuleDir: vi.fn(),
|
||||
spawnSync: vi.fn(),
|
||||
}));
|
||||
vi.mock("@hyperframes/gcp-cloud-run/sdk", () => ({
|
||||
getRenderProgress: adapter.getRenderProgress,
|
||||
renderToCloudRun: adapter.renderToCloudRun,
|
||||
deploySite: adapter.deploySite,
|
||||
}));
|
||||
vi.mock("@hyperframes/gcp-cloud-run/terraform", () => ({
|
||||
getTerraformModuleDir: adapter.getTerraformModuleDir,
|
||||
}));
|
||||
vi.mock("node:child_process", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("node:child_process")>()),
|
||||
spawnSync: adapter.spawnSync,
|
||||
}));
|
||||
|
||||
const { default: cloudrunCommand } = await import("./cloudrun.js");
|
||||
|
||||
const lines: string[] = [];
|
||||
let work: string;
|
||||
|
||||
const printed = (): string => lines.join("\n").replace(new RegExp(`${ESC}\\[[0-9;]*m`, "g"), "");
|
||||
|
||||
function expectNoControlCharacters(): void {
|
||||
expect(printed()).not.toContain(ESC);
|
||||
expect(printed()).not.toContain("\x07");
|
||||
}
|
||||
|
||||
function run(args: Record<string, unknown>): Promise<unknown> {
|
||||
return Promise.resolve(
|
||||
cloudrunCommand.run?.({ args, rawArgs: [], cmd: cloudrunCommand } as never),
|
||||
);
|
||||
}
|
||||
|
||||
function progress(over: Record<string, unknown>): Record<string, unknown> {
|
||||
return {
|
||||
status: "succeeded",
|
||||
overallProgress: 1,
|
||||
framesRendered: 30,
|
||||
totalFrames: 30,
|
||||
costs: { displayCost: "$0.01" },
|
||||
outputFile: null,
|
||||
errors: [],
|
||||
...over,
|
||||
};
|
||||
}
|
||||
|
||||
const size = { width: "1920", height: "1080", fps: "30" };
|
||||
|
||||
beforeEach(() => {
|
||||
lines.length = 0;
|
||||
work = mkdtempSync(join(tmpdir(), "hf-cloudrun-output-"));
|
||||
vi.stubEnv("HYPERFRAMES_CONFIG_DIR", join(work, "config"));
|
||||
mkdirSync(join(work, "config"));
|
||||
writeFileSync(
|
||||
join(work, "config", "cloudrun-state.json"),
|
||||
JSON.stringify({
|
||||
projectId: "demo",
|
||||
region: "us-central1",
|
||||
bucketName: "demo-bucket",
|
||||
serviceUrl: "https://demo.example",
|
||||
workflowId: "demo-workflow",
|
||||
}),
|
||||
);
|
||||
for (const method of ["log", "error", "warn"] as const)
|
||||
vi.spyOn(console, method).mockImplementation((...args: unknown[]) => {
|
||||
lines.push(args.join(" "));
|
||||
});
|
||||
vi.spyOn(process.stdout, "write").mockImplementation((chunk: unknown) => {
|
||||
lines.push(String(chunk));
|
||||
return true;
|
||||
});
|
||||
for (const fake of Object.values(adapter)) fake.mockReset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
consumeCommandResult();
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllEnvs();
|
||||
rmSync(work, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("cloudrun output for people", () => {
|
||||
// fails without the fix: the subcommand is repeated as it was typed.
|
||||
it("shows control characters in an unknown subcommand as text", async () => {
|
||||
await expect(run({ subcommand: `ren${ODD}der` })).rejects.toThrow();
|
||||
expect(printed()).toContain(`Unknown subcommand: ren${SHOWN}der`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the verb is repeated as it was typed.
|
||||
it("shows control characters in an unknown sites verb as text", async () => {
|
||||
await expect(run({ subcommand: "sites", target: `cre${ODD}ate` })).rejects.toThrow();
|
||||
expect(printed()).toContain(`unknown verb "cre${SHOWN}ate"`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the notice and the site rows are printed as they arrived.
|
||||
it("sites create shows control characters in a notice and the reply as text", async () => {
|
||||
adapter.deploySite.mockImplementation(async (options: { onNotice?: (m: string) => void }) => {
|
||||
options.onNotice?.(`left out ${ODD}\nsecond line`);
|
||||
return { siteId: `site-${ODD}`, projectGcsUri: `gs://site/${ODD}`, bytes: 3, uploaded: true };
|
||||
});
|
||||
await run({ subcommand: "sites", target: "create", extra: join(work, "project") });
|
||||
expect(printed()).toContain(`left out ${SHOWN}\nsecond line`);
|
||||
expect(printed()).toContain(`site=site-${SHOWN} (3 bytes)`);
|
||||
expect(printed()).toContain(`gs://site/${SHOWN}`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the notice and the started render's rows are printed as they arrived.
|
||||
it("render shows control characters in a notice and the started render as text", async () => {
|
||||
adapter.renderToCloudRun.mockImplementation(
|
||||
async (options: { onNotice?: (m: string) => void }) => {
|
||||
options.onNotice?.(`left out ${ODD}`);
|
||||
return {
|
||||
renderId: `id-${ODD}`,
|
||||
outputGcsUri: `gs://out/${ODD}`,
|
||||
executionName: `exec-${ODD}`,
|
||||
};
|
||||
},
|
||||
);
|
||||
await run({ subcommand: "render", target: join(work, "project"), ...size });
|
||||
for (const shown of ["left out ", "renderId=id-", "gs://out/", "cloudrun progress exec-"])
|
||||
expect(printed()).toContain(`${shown}${SHOWN}`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the status while waiting, the output address and the cost are printed as they arrived.
|
||||
it("render --wait shows control characters in the status and the finished output as text", async () => {
|
||||
adapter.renderToCloudRun.mockResolvedValue({
|
||||
renderId: "id",
|
||||
outputGcsUri: "gs://out",
|
||||
executionName: "exec",
|
||||
});
|
||||
adapter.getRenderProgress
|
||||
.mockResolvedValueOnce(progress({ status: "running" }))
|
||||
.mockResolvedValueOnce(
|
||||
progress({
|
||||
status: "succeeded",
|
||||
outputFile: { gcsUri: `gs://done/${ODD}` },
|
||||
costs: { displayCost: `$1 ${ODD}` },
|
||||
}),
|
||||
);
|
||||
await run({
|
||||
subcommand: "render",
|
||||
target: join(work, "project"),
|
||||
...size,
|
||||
wait: true,
|
||||
"wait-interval-ms": "1",
|
||||
});
|
||||
expect(printed()).toContain(`gs://done/${SHOWN} ($1 ${SHOWN})`);
|
||||
expectNoControlCharacters();
|
||||
|
||||
lines.length = 0;
|
||||
adapter.getRenderProgress
|
||||
.mockResolvedValueOnce(progress({ status: "running" }))
|
||||
.mockResolvedValueOnce(
|
||||
progress({
|
||||
status: `lost${ODD}`,
|
||||
errors: [{ state: `Chunk${ODD}`, cause: `why ${ODD}\nmore` }],
|
||||
}),
|
||||
);
|
||||
await expect(
|
||||
run({
|
||||
subcommand: "render",
|
||||
target: join(work, "project"),
|
||||
...size,
|
||||
wait: true,
|
||||
"wait-interval-ms": "1",
|
||||
}),
|
||||
).rejects.toThrow("Command failed");
|
||||
expect(printed()).toContain(`status=lost${SHOWN} `);
|
||||
expect(printed()).toContain(`✗ render lost${SHOWN}`);
|
||||
expect(printed()).toContain(`Chunk${SHOWN}: why ${SHOWN}\nmore`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the status, output address, cost and failure rows are printed as they arrived.
|
||||
it("progress shows control characters in a reply as text", async () => {
|
||||
adapter.getRenderProgress.mockResolvedValue(
|
||||
progress({
|
||||
status: `fail${ODD}`,
|
||||
outputFile: { gcsUri: `gs://done/${ODD}` },
|
||||
costs: { displayCost: `$1 ${ODD}` },
|
||||
errors: [{ state: `Render${ODD}`, cause: `why ${ODD}\nmore` }],
|
||||
}),
|
||||
);
|
||||
await run({ subcommand: "progress", target: "exec-1" });
|
||||
expect(printed()).toContain(`status=fail${SHOWN} progress=100%`);
|
||||
expect(printed()).toContain(`output=gs://done/${SHOWN}`);
|
||||
expect(printed()).toContain(`cost=$1 ${SHOWN}`);
|
||||
expect(printed()).toContain(`error Render${SHOWN}: why ${SHOWN}\nmore`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the batch path is repeated as it was typed.
|
||||
it("render-batch shows control characters in a missing batch path as text", async () => {
|
||||
await expect(
|
||||
run({ subcommand: "render-batch", target: "project", batch: `no${ODD}.jsonl`, ...size }),
|
||||
).rejects.toThrow();
|
||||
expect(printed()).toContain(`batch file not found: no${SHOWN}.jsonl`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the notice and each failed row's key and reason are printed as they arrived.
|
||||
it("render-batch shows control characters in a notice and a failed row as text", async () => {
|
||||
const batch = join(work, "batch.jsonl");
|
||||
writeFileSync(batch, JSON.stringify({ outputKey: `key-${ODD}` }));
|
||||
adapter.deploySite.mockImplementation(async (options: { onNotice?: (m: string) => void }) => {
|
||||
options.onNotice?.(`left out ${ODD}`);
|
||||
return { siteId: "site", projectGcsUri: "gs://site", bytes: 3, uploaded: true };
|
||||
});
|
||||
adapter.renderToCloudRun.mockRejectedValue(new Error(`refused ${ODD}\nsecond line`));
|
||||
await expect(
|
||||
run({ subcommand: "render-batch", target: join(work, "project"), batch, ...size }),
|
||||
).rejects.toThrow("Command failed");
|
||||
expect(printed()).toContain(`left out ${SHOWN}`);
|
||||
expect(printed()).toContain(`✗ key-${SHOWN}: refused ${SHOWN}\nsecond line`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
|
||||
// fails without the fix: the project, the image built from it and the stack's outputs are printed as they arrived.
|
||||
it("deploy shows control characters in the project, the image and the outputs as text", async () => {
|
||||
const terraformDir = join(work, "repo", "packages", "gcp-cloud-run", "terraform");
|
||||
mkdirSync(terraformDir, { recursive: true });
|
||||
writeFileSync(join(work, "repo", "packages", "gcp-cloud-run", "Dockerfile"), "");
|
||||
adapter.getTerraformModuleDir.mockReturnValue(terraformDir);
|
||||
adapter.spawnSync.mockReturnValue({ status: 0, stdout: `out-${ODD}`, stderr: "" });
|
||||
await run({ subcommand: "deploy", project: `proj${ODD}` });
|
||||
expect(printed()).toContain(`Enabling required APIs on proj${SHOWN}`);
|
||||
expect(printed()).toContain(`us-central1-docker.pkg.dev/proj${SHOWN}/hyperframes/`);
|
||||
expect(printed()).toContain(`bucket=out-${SHOWN} workflow=out-${SHOWN}`);
|
||||
expect(printed()).toContain(`service=out-${SHOWN}`);
|
||||
expectNoControlCharacters();
|
||||
});
|
||||
});
|
||||
@@ -18,7 +18,7 @@ import { type SpawnSyncReturns, spawnSync } from "node:child_process";
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join, resolve } from "node:path";
|
||||
import { defineCommand } from "../utils/defineCommand.js";
|
||||
import { type CanvasResolution } from "@hyperframes/core";
|
||||
import { type CanvasResolution, terminalLines, terminalText } from "@hyperframes/core";
|
||||
import { parseOutputResolutionFlag } from "../utils/parseOutputResolution.js";
|
||||
import type { Example } from "./_examples.js";
|
||||
import { c } from "../ui/colors.js";
|
||||
@@ -265,7 +265,7 @@ export default defineCommand({
|
||||
case "destroy":
|
||||
return runDestroy(args);
|
||||
default:
|
||||
console.error(`${c.error("Unknown subcommand:")} ${subcommand}\n${HELP}`);
|
||||
console.error(`${c.error("Unknown subcommand:")} ${terminalText(subcommand)}\n${HELP}`);
|
||||
failUsage();
|
||||
}
|
||||
},
|
||||
@@ -348,7 +348,7 @@ async function runDeploy(args: Record<string, unknown>): Promise<void> {
|
||||
const tfDir = getTerraformModuleDir();
|
||||
const repoRoot = findRepoRoot(tfDir);
|
||||
|
||||
console.log(`→ Enabling required APIs on ${project}`);
|
||||
console.log(`→ Enabling required APIs on ${terminalText(project)}`);
|
||||
run("gcloud", [
|
||||
"services",
|
||||
"enable",
|
||||
@@ -401,7 +401,7 @@ async function runDeploy(args: Record<string, unknown>): Promise<void> {
|
||||
.replace(/[^0-9]/g, "")
|
||||
.slice(0, 14);
|
||||
image = `${region}-docker.pkg.dev/${project}/${repo}/hyperframes-render:${tag}`;
|
||||
console.log(`→ Building + pushing ${image} via Cloud Build`);
|
||||
console.log(`→ Building + pushing ${terminalText(image)} via Cloud Build`);
|
||||
run("gcloud", [
|
||||
"builds",
|
||||
"submit",
|
||||
@@ -431,8 +431,10 @@ async function runDeploy(args: Record<string, unknown>): Promise<void> {
|
||||
workflowId: capture("terraform", ["output", "-raw", "workflow_name"], { cwd: tfDir }),
|
||||
};
|
||||
writeState(state);
|
||||
console.log(`${c.accent("✓ deployed.")} bucket=${state.bucketName} workflow=${state.workflowId}`);
|
||||
console.log(` service=${state.serviceUrl}`);
|
||||
console.log(
|
||||
`${c.accent("✓ deployed.")} bucket=${terminalText(state.bucketName)} workflow=${terminalText(state.workflowId)}`,
|
||||
);
|
||||
console.log(` service=${terminalText(state.serviceUrl)}`);
|
||||
console.log(
|
||||
` Next: ${c.accent("hyperframes cloudrun render ./my-project --width 1920 --height 1080 --wait")}`,
|
||||
);
|
||||
@@ -503,7 +505,7 @@ function writeCloudBuildConfig(image: string): string {
|
||||
async function runSites(args: Record<string, unknown>): Promise<void> {
|
||||
if (args.target !== "create") {
|
||||
console.error(
|
||||
`[cloudrun sites] unknown verb "${String(args.target)}". Only "create" is supported.`,
|
||||
`[cloudrun sites] unknown verb "${terminalText(String(args.target))}". Only "create" is supported.`,
|
||||
);
|
||||
failUsage();
|
||||
}
|
||||
@@ -519,14 +521,14 @@ async function runSites(args: Record<string, unknown>): Promise<void> {
|
||||
bucketName: state.bucketName,
|
||||
siteId: args["site-id"] as string | undefined,
|
||||
includeOutsideFiles: args["include-outside-files"] === true,
|
||||
onNotice: (message) => console.error(message),
|
||||
onNotice: (message) => console.error(terminalLines(message)),
|
||||
});
|
||||
if (args.json) {
|
||||
console.log(JSON.stringify(handle, null, 2));
|
||||
} else {
|
||||
console.log(
|
||||
`${handle.uploaded ? c.accent("✓ uploaded") : c.dim("• already present")} ` +
|
||||
`site=${handle.siteId} (${handle.bytes} bytes)\n ${handle.projectGcsUri}`,
|
||||
`site=${terminalText(handle.siteId)} (${handle.bytes} bytes)\n ${terminalText(handle.projectGcsUri)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -571,7 +573,7 @@ async function runRender(args: Record<string, unknown>): Promise<void> {
|
||||
const handle = await renderToCloudRun({
|
||||
projectDir: resolve(projectDir),
|
||||
includeOutsideFiles: args["include-outside-files"] === true,
|
||||
onNotice: (message) => console.error(message),
|
||||
onNotice: (message) => console.error(terminalLines(message)),
|
||||
config: config as Parameters<typeof renderToCloudRun>[0]["config"],
|
||||
bucketName: state.bucketName,
|
||||
projectId: state.projectId,
|
||||
@@ -585,10 +587,10 @@ async function runRender(args: Record<string, unknown>): Promise<void> {
|
||||
if (!args.wait) {
|
||||
if (args.json) console.log(JSON.stringify(handle, null, 2));
|
||||
else {
|
||||
console.log(`${c.accent("✓ render started")} renderId=${handle.renderId}`);
|
||||
console.log(` output → ${handle.outputGcsUri}`);
|
||||
console.log(`${c.accent("✓ render started")} renderId=${terminalText(handle.renderId)}`);
|
||||
console.log(` output → ${terminalText(handle.outputGcsUri)}`);
|
||||
console.log(
|
||||
` progress: ${c.accent(`hyperframes cloudrun progress ${handle.executionName}`)}`,
|
||||
` progress: ${c.accent(`hyperframes cloudrun progress ${terminalText(handle.executionName)}`)}`,
|
||||
);
|
||||
}
|
||||
return;
|
||||
@@ -598,18 +600,19 @@ async function runRender(args: Record<string, unknown>): Promise<void> {
|
||||
while (progress.status === "running") {
|
||||
await new Promise((r) => setTimeout(r, intervalMs));
|
||||
progress = await getRenderProgress({ executionName: handle.executionName });
|
||||
if (!args.json) process.stdout.write(`\r status=${progress.status} `);
|
||||
if (!args.json) process.stdout.write(`\r status=${terminalText(progress.status)} `);
|
||||
}
|
||||
if (!args.json) process.stdout.write("\n");
|
||||
if (args.json) {
|
||||
console.log(JSON.stringify(progress, null, 2));
|
||||
} else if (progress.status === "succeeded") {
|
||||
console.log(
|
||||
`${c.accent("✓ done.")} ${progress.outputFile?.gcsUri} (${progress.costs.displayCost})`,
|
||||
`${c.accent("✓ done.")} ${terminalText(String(progress.outputFile?.gcsUri))} (${terminalText(progress.costs.displayCost)})`,
|
||||
);
|
||||
} else {
|
||||
console.error(`${c.error("✗ render " + progress.status)}`);
|
||||
for (const e of progress.errors) console.error(` ${e.state}: ${e.cause}`);
|
||||
console.error(`${c.error("✗ render " + terminalText(progress.status))}`);
|
||||
for (const e of progress.errors)
|
||||
console.error(` ${terminalText(e.state)}: ${terminalLines(e.cause)}`);
|
||||
failCommand();
|
||||
}
|
||||
}
|
||||
@@ -629,12 +632,15 @@ async function runProgress(args: Record<string, unknown>): Promise<void> {
|
||||
console.log(JSON.stringify(progress, null, 2));
|
||||
return;
|
||||
}
|
||||
console.log(`status=${progress.status} progress=${(progress.overallProgress * 100).toFixed(0)}%`);
|
||||
console.log(
|
||||
`status=${terminalText(progress.status)} progress=${(progress.overallProgress * 100).toFixed(0)}%`,
|
||||
);
|
||||
if (progress.totalFrames)
|
||||
console.log(`frames=${progress.framesRendered}/${progress.totalFrames}`);
|
||||
if (progress.outputFile) console.log(`output=${progress.outputFile.gcsUri}`);
|
||||
console.log(`cost=${progress.costs.displayCost}`);
|
||||
for (const e of progress.errors) console.error(` error ${e.state}: ${e.cause}`);
|
||||
if (progress.outputFile) console.log(`output=${terminalText(progress.outputFile.gcsUri)}`);
|
||||
console.log(`cost=${terminalText(progress.costs.displayCost)}`);
|
||||
for (const e of progress.errors)
|
||||
console.error(` error ${terminalText(e.state)}: ${terminalLines(e.cause)}`);
|
||||
}
|
||||
|
||||
// ── render-batch ────────────────────────────────────────────────────────────
|
||||
@@ -672,7 +678,7 @@ async function runRenderBatch(args: Record<string, unknown>): Promise<void> {
|
||||
const fps = resolveCloudRunFps(args, projectDir, "render-batch");
|
||||
buildRenderConfig(args, fps, width, height, undefined);
|
||||
if (!existsSync(resolve(batchPath))) {
|
||||
console.error(`[cloudrun render-batch] batch file not found: ${batchPath}`);
|
||||
console.error(`[cloudrun render-batch] batch file not found: ${terminalText(batchPath)}`);
|
||||
failCommand();
|
||||
}
|
||||
const entries = parseBatchFile(resolve(batchPath));
|
||||
@@ -704,7 +710,7 @@ async function runRenderBatch(args: Record<string, unknown>): Promise<void> {
|
||||
bucketName: state.bucketName,
|
||||
siteId: args["site-id"] as string | undefined,
|
||||
includeOutsideFiles: args["include-outside-files"] === true,
|
||||
onNotice: (message) => console.error(message),
|
||||
onNotice: (message) => console.error(terminalLines(message)),
|
||||
});
|
||||
|
||||
const results: Array<{ outputKey: string; executionName?: string; error?: string }> = [];
|
||||
@@ -745,7 +751,8 @@ async function runRenderBatch(args: Record<string, unknown>): Promise<void> {
|
||||
console.log(
|
||||
`${c.accent("✓ started")} ${results.length - failed.length}/${results.length} renders`,
|
||||
);
|
||||
for (const r of failed) console.error(` ✗ ${r.outputKey}: ${r.error}`);
|
||||
for (const r of failed)
|
||||
console.error(` ✗ ${terminalText(r.outputKey)}: ${terminalLines(r.error ?? "")}`);
|
||||
}
|
||||
if (failed.length > 0) failCommand();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user