Skip to content

Commit 2a284a8

Browse files
committed
fix(gcp): enforce effective BeginFrame capture
1 parent 2dddb4c commit 2a284a8

21 files changed

Lines changed: 842 additions & 102 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
cli: ${{ steps.filter.outputs.cli }}
3636
skills: ${{ steps.filter.outputs.skills }}
3737
codex_plugin: ${{ steps.filter.outputs.codex_plugin }}
38+
gcp_beginframe: ${{ steps.filter.outputs.gcp_beginframe }}
3839
steps:
3940
# Force git-based change detection instead of the pull_request REST API.
4041
# The API path can fail the whole workflow on transient listFiles
@@ -76,6 +77,33 @@ jobs:
7677
- "scripts/package-codex-plugin.mjs"
7778
- "package.json"
7879
- ".github/workflows/ci.yml"
80+
gcp_beginframe:
81+
- "packages/gcp-cloud-run/Dockerfile"
82+
- "packages/aws-lambda/scripts/probe-beginframe.ts"
83+
- "packages/engine/src/services/browserManager.ts"
84+
- "package.json"
85+
- "bun.lock"
86+
- ".github/workflows/ci.yml"
87+
88+
gcp-beginframe-contract:
89+
name: GCP BeginFrame image contract
90+
needs: changes
91+
if: needs.changes.outputs.gcp_beginframe == 'true'
92+
runs-on: ubuntu-latest
93+
timeout-minutes: 15
94+
steps:
95+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
96+
with:
97+
lfs: true
98+
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
99+
- uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
100+
with:
101+
context: .
102+
file: packages/gcp-cloud-run/Dockerfile
103+
target: beginframe-contract
104+
push: false
105+
cache-from: type=gha,scope=gcp-beginframe-contract
106+
cache-to: type=gha,mode=max,scope=gcp-beginframe-contract
79107

80108
build:
81109
name: Build

‎examples/gcp-cloud-run/scripts/smoke.sh‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ else
408408
!packages/shader-transitions/package.json
409409
!packages/aws-lambda/
410410
!packages/aws-lambda/package.json
411+
!packages/aws-lambda/scripts/
412+
!packages/aws-lambda/scripts/probe-beginframe.ts
411413
packages/**/node_modules/**
412414
packages/**/dist/**
413415
packages/**/coverage/**
@@ -548,6 +550,19 @@ for protocol in "${PROTOCOL_LIST[@]}"; do
548550
continue
549551
fi
550552

553+
CAPTURE_MODES="$(jq -r \
554+
'.result | fromjson | [.Chunks[]?.CaptureMode // "<missing>"] | unique | join(",")' \
555+
"$EXECUTION_JSON")"
556+
if jq -e \
557+
'.result | fromjson | .Chunks as $chunks |
558+
(($chunks | length) > 0 and all($chunks[]; .CaptureMode == "beginframe"))' \
559+
"$EXECUTION_JSON" >/dev/null; then
560+
echo " ✓ effective capture mode=beginframe"
561+
else
562+
echo " ✗ expected every chunk to use beginframe; observed=${CAPTURE_MODES:-<none>}"
563+
[ "$OVERALL_RC" -ne 0 ] || OVERALL_RC=6
564+
fi
565+
551566
OUTPUT_LOCAL="$RENDER_DIR/$protocol-c$chunk_size-output.mp4"
552567
gcloud storage cp "$OUTPUT_GCS" "$OUTPUT_LOCAL" --project "$PROJECT" >/dev/null
553568

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
});

0 commit comments

Comments
 (0)