mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* perf(cli): lambda deploy warms the video function so the first render does not wait for its image A freshly deployed container-image function loads its image on first use, which added about 12 s to the first render's plan on some deploys. Deploy now invokes the function's warm action once after the stack is up (default on, --no-warm skips it). A failed warm-up prints a warning and the deploy still succeeds. * chore(cli): move the deploy warm-up to its own file, regenerate the skills manifest Regenerates skills-manifest.json for the lambda reference change, keeps runDeploy under the complexity gate by pulling the warm step into a helper, and leaves sam.ts untouched. * fix(cli): the deploy warm-up asks the aws CLI for JSON output whatever the profile sets A profile configured for text or yaml output made the reply unparseable, which printed a spurious warm-up warning. * refactor(cli): split the reserved-concurrency notice and warm-up gate out of runDeploy
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const spawnSync = vi.hoisted(() => vi.fn());
|
|
vi.mock("node:child_process", () => ({ spawnSync }));
|
|
|
|
const { warmFunction } = await import("./warm.js");
|
|
|
|
const target = { functionName: "hf-video", region: "eu-west-1" };
|
|
const reply = (stdout: string, status = 0, stderr = "") => ({ status, stdout, stderr });
|
|
|
|
beforeEach(() => spawnSync.mockReset());
|
|
|
|
describe("warmFunction", () => {
|
|
it("invokes the warm action on the function, behind the profile when there is one", () => {
|
|
spawnSync.mockReturnValue(reply('{"StatusCode":200}'));
|
|
warmFunction({ ...target, awsProfile: "work" });
|
|
|
|
const [command, args] = spawnSync.mock.calls[0] as [string, string[]];
|
|
expect(command).toBe("aws");
|
|
expect(args.slice(0, 6)).toEqual([
|
|
"--profile",
|
|
"work",
|
|
"lambda",
|
|
"invoke",
|
|
"--function-name",
|
|
"hf-video",
|
|
]);
|
|
expect(args[args.indexOf("--payload") + 1]).toBe('{"Action":"warm"}');
|
|
expect(args).toContain("eu-west-1");
|
|
expect(args[args.indexOf("--output") + 1]).toBe("json");
|
|
});
|
|
|
|
it("throws with the aws error text when the invoke exits non-zero", () => {
|
|
spawnSync.mockReturnValue(reply("", 254, "AccessDeniedException"));
|
|
expect(() => warmFunction(target)).toThrow(/code 254: AccessDeniedException/);
|
|
});
|
|
|
|
it("throws when the function answers with an error", () => {
|
|
spawnSync.mockReturnValue(reply('{"StatusCode":200,"FunctionError":"Unhandled"}'));
|
|
expect(() => warmFunction(target)).toThrow(/answered Unhandled/);
|
|
});
|
|
|
|
it("throws when the aws CLI cannot be started", () => {
|
|
spawnSync.mockReturnValue({ error: new Error("spawn aws ENOENT") });
|
|
expect(() => warmFunction(target)).toThrow(/ENOENT/);
|
|
});
|
|
});
|