@hyperframes/aws-lambda 0.8.180 → 0.8.183
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{chunk-PK7PO3MH.js → chunk-5FLGGUWE.js} +1 -1
- package/dist/_chunks/{chunk-AK7J3QQN.js → chunk-MPNOI2CS.js} +87 -54
- package/dist/_chunks/{chunk-ZY5YIH5W.js → chunk-SGNVVPIS.js} +187 -17
- package/dist/cdk/index.js +38 -7
- package/dist/events.d.ts +16 -3
- package/dist/handler.d.ts +4 -3
- package/dist/handler.js +2 -2
- package/dist/index.js +3 -3
- package/dist/s3Stitch.d.ts +5 -2
- package/dist/s3Transport.d.ts +20 -8
- package/dist/sdk/index.js +2 -2
- package/package.json +3 -2
- package/prebuilt/handler-zip.json +4 -4
- package/prebuilt/template.yaml +149 -71
- package/scripts/pin-handler-zip.ts +2 -13
- package/scripts/prebuilt-template.mjs +19 -0
- package/scripts/build-zip.test.ts +0 -77
- package/scripts/pin-handler-zip.test.ts +0 -101
- package/scripts/probe-beginframe.test.ts +0 -80
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from "bun:test";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { adapterPackageRoot, prebuiltHandler } from "../src/sdk/prebuiltHandler.js";
|
|
7
|
-
import { pinHandlerZip } from "./pin-handler-zip.js";
|
|
8
|
-
|
|
9
|
-
const realTemplate = readFileSync(
|
|
10
|
-
join(import.meta.dir, "..", "..", "..", "examples", "aws-lambda", "template.yaml"),
|
|
11
|
-
"utf-8",
|
|
12
|
-
);
|
|
13
|
-
const dirs: string[] = [];
|
|
14
|
-
|
|
15
|
-
function fixtureRepo(): { root: string; pkgDir: string } {
|
|
16
|
-
const root = mkdtempSync(join(tmpdir(), "hf-pin-zip-"));
|
|
17
|
-
dirs.push(root);
|
|
18
|
-
const pkgDir = join(root, "packages", "aws-lambda");
|
|
19
|
-
mkdirSync(join(pkgDir, "dist"), { recursive: true });
|
|
20
|
-
writeFileSync(
|
|
21
|
-
join(pkgDir, "package.json"),
|
|
22
|
-
JSON.stringify({
|
|
23
|
-
name: "@hyperframes/aws-lambda",
|
|
24
|
-
version: "9.8.7",
|
|
25
|
-
repository: { url: "https://github.com/heygen-com/hyperframes" },
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
mkdirSync(join(root, "examples", "aws-lambda"), { recursive: true });
|
|
29
|
-
writeFileSync(join(root, "examples", "aws-lambda", "template.yaml"), realTemplate);
|
|
30
|
-
return { root, pkgDir };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("pinHandlerZip", () => {
|
|
38
|
-
it("moves the built zip out of the package and pins its URL and sha256 for this version", () => {
|
|
39
|
-
const { root, pkgDir } = fixtureRepo();
|
|
40
|
-
const zip = Buffer.from("zip bytes");
|
|
41
|
-
writeFileSync(join(pkgDir, "dist", "handler.zip"), zip);
|
|
42
|
-
writeFileSync(join(pkgDir, "dist", "handler.zip.manifest.json"), "{}");
|
|
43
|
-
const sha256 = createHash("sha256").update(zip).digest("hex");
|
|
44
|
-
|
|
45
|
-
const manifest = pinHandlerZip(root);
|
|
46
|
-
|
|
47
|
-
expect(manifest).toEqual({
|
|
48
|
-
version: "9.8.7",
|
|
49
|
-
url: "https://github.com/heygen-com/hyperframes/releases/download/v9.8.7/hyperframes-lambda-handler.zip",
|
|
50
|
-
sha256,
|
|
51
|
-
bytes: zip.length,
|
|
52
|
-
});
|
|
53
|
-
// Nothing large is left for npm to pack.
|
|
54
|
-
expect(existsSync(join(pkgDir, "dist", "handler.zip"))).toBe(false);
|
|
55
|
-
expect(existsSync(join(pkgDir, "dist", "handler.zip.manifest.json"))).toBe(false);
|
|
56
|
-
expect(readFileSync(join(root, "dist", "hyperframes-lambda-handler.zip"))).toEqual(zip);
|
|
57
|
-
expect(readFileSync(join(root, "dist", "hyperframes-lambda-handler.sha256"), "utf-8")).toBe(
|
|
58
|
-
`${sha256} hyperframes-lambda-handler.zip\n`,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const pinned = prebuiltHandler(pkgDir);
|
|
62
|
-
expect(pinned).toEqual({
|
|
63
|
-
...manifest,
|
|
64
|
-
templatePath: join(pkgDir, "prebuilt", "template.yaml"),
|
|
65
|
-
});
|
|
66
|
-
const template = readFileSync(pinned!.templatePath, "utf-8");
|
|
67
|
-
expect(template).toContain(" CodeUri: handler.zip\n");
|
|
68
|
-
expect(template).not.toContain("packages/aws-lambda/dist/handler.zip\n");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("pins a zip a previous run already attached to the release", () => {
|
|
72
|
-
const { root, pkgDir } = fixtureRepo();
|
|
73
|
-
mkdirSync(join(root, "dist"));
|
|
74
|
-
writeFileSync(join(root, "dist", "hyperframes-lambda-handler.zip"), "attached");
|
|
75
|
-
|
|
76
|
-
expect(pinHandlerZip(root).sha256).toBe(createHash("sha256").update("attached").digest("hex"));
|
|
77
|
-
expect(prebuiltHandler(pkgDir)?.sha256).toBe(pinHandlerZip(root).sha256);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("refuses a template whose CodeUri it cannot rewrite", () => {
|
|
81
|
-
const { root, pkgDir } = fixtureRepo();
|
|
82
|
-
writeFileSync(join(pkgDir, "dist", "handler.zip"), "zip");
|
|
83
|
-
writeFileSync(
|
|
84
|
-
join(root, "examples", "aws-lambda", "template.yaml"),
|
|
85
|
-
"CodeUri: elsewhere.zip\n",
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
expect(() => pinHandlerZip(root)).toThrow(/expected exactly one/);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("prebuiltHandler", () => {
|
|
93
|
-
it("reads from its own package root", () => {
|
|
94
|
-
expect(adapterPackageRoot()).toBe(join(import.meta.dir, ".."));
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("is undefined when the package carries no pinned zip", () => {
|
|
98
|
-
const { pkgDir } = fixtureRepo();
|
|
99
|
-
expect(prebuiltHandler(pkgDir)).toBeUndefined();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join, resolve } from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
_awaitBeforeDeadlineForTests,
|
|
7
|
-
_closeBrowserForProbeTests,
|
|
8
|
-
parseProbeArgs,
|
|
9
|
-
} from "./probe-beginframe.js";
|
|
10
|
-
|
|
11
|
-
describe("parseProbeArgs", () => {
|
|
12
|
-
it("defaults to the @sparticuz/chromium source", () => {
|
|
13
|
-
expect(parseProbeArgs([])).toEqual({});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("accepts a standalone executable path", () => {
|
|
17
|
-
expect(parseProbeArgs(["--executable-path", "/opt/chrome/chrome-headless-shell"])).toEqual({
|
|
18
|
-
executablePath: "/opt/chrome/chrome-headless-shell",
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("accepts the equals form and resolves relative paths", () => {
|
|
23
|
-
expect(parseProbeArgs(["--executable-path=./chrome"])).toEqual({
|
|
24
|
-
executablePath: resolve("./chrome"),
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("loads exact production launch arguments from JSON", () => {
|
|
29
|
-
const dir = mkdtempSync(join(tmpdir(), "hf-probe-args-"));
|
|
30
|
-
const argsPath = join(dir, "args.json");
|
|
31
|
-
writeFileSync(argsPath, JSON.stringify(["--enable-begin-frame-control", "--no-sandbox"]));
|
|
32
|
-
try {
|
|
33
|
-
expect(parseProbeArgs(["--launch-args-json", argsPath])).toEqual({
|
|
34
|
-
launchArgs: ["--enable-begin-frame-control", "--no-sandbox"],
|
|
35
|
-
});
|
|
36
|
-
} finally {
|
|
37
|
-
rmSync(dir, { recursive: true, force: true });
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("rejects missing values and unknown arguments", () => {
|
|
42
|
-
expect(() => parseProbeArgs(["--executable-path"])).toThrow(
|
|
43
|
-
"--executable-path requires a path",
|
|
44
|
-
);
|
|
45
|
-
expect(() => parseProbeArgs(["--source", "chrome"])).toThrow("Unknown argument: --source");
|
|
46
|
-
expect(() => parseProbeArgs(["--launch-args-json"])).toThrow(
|
|
47
|
-
"--launch-args-json requires a path",
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("bounds a CDP operation that never resolves", async () => {
|
|
52
|
-
const never = new Promise<never>(() => {});
|
|
53
|
-
await expect(
|
|
54
|
-
_awaitBeforeDeadlineForTests(never, Date.now() + 25, "screenshot beginFrame"),
|
|
55
|
-
).rejects.toThrow("timeout during screenshot beginFrame");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("force-kills and disconnects when graceful cleanup never resolves", async () => {
|
|
59
|
-
let killedWith: NodeJS.Signals | number | undefined;
|
|
60
|
-
let disconnected = false;
|
|
61
|
-
await _closeBrowserForProbeTests(
|
|
62
|
-
{
|
|
63
|
-
close: () => new Promise<never>(() => {}),
|
|
64
|
-
process: () => ({
|
|
65
|
-
kill: (signal) => {
|
|
66
|
-
killedWith = signal;
|
|
67
|
-
return true;
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
disconnect: async () => {
|
|
71
|
-
disconnected = true;
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
25,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(killedWith).toBe("SIGKILL");
|
|
78
|
-
expect(disconnected).toBe(true);
|
|
79
|
-
});
|
|
80
|
-
});
|