Skip to content

Commit d11d4ed

Browse files
committed
Exercise canonical Cloudflare boot probe
1 parent cee31d5 commit d11d4ed

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

packages/runtime-cloudflare/src/worker.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,30 @@ async function runBootProbe(phase: string, bucket: R2Bucket): Promise<Response>
812812
}
813813
}
814814

815-
if (phase === "wordpress-files" || phase === "sqlite" || phase === "full" || phase === "streamed-sqlite" || phase === "streamed-wordpress") {
815+
if (phase === "full") {
816816
const runtime = await bootWordPressRuntime(
817-
phase === "full" || phase === "streamed-wordpress" ? "install-from-existing-files" : "do-not-attempt-installing",
817+
"do-not-attempt-installing",
818+
true,
819+
true,
820+
undefined,
821+
await packagedCanonicalMarkdownSeed(),
822+
new Uint8Array(markdownPrimaryBootstrapIndex),
823+
SITE_URL,
824+
{},
825+
bucket,
826+
true,
827+
)
828+
try {
829+
const phpVersion = (await runtime.php.run({ code: "<?php echo PHP_VERSION;" })).text.trim()
830+
return probeResponse(phase, { phpVersion, wordpressVersion: runtime.wordpressVersion, bootMode: "canonical-mdi" })
831+
} finally {
832+
runtime.php.exit()
833+
}
834+
}
835+
836+
if (phase === "wordpress-files" || phase === "sqlite" || phase === "streamed-sqlite" || phase === "streamed-wordpress") {
837+
const runtime = await bootWordPressRuntime(
838+
phase === "streamed-wordpress" ? "install-from-existing-files" : "do-not-attempt-installing",
818839
phase !== "wordpress-files",
819840
true,
820841
undefined,
@@ -828,7 +849,7 @@ async function runBootProbe(phase: string, bucket: R2Bucket): Promise<Response>
828849
const phpVersion = (await runtime.php.run({ code: "<?php echo PHP_VERSION;" })).text.trim()
829850
return probeResponse(phase, { phpVersion, wordpressVersion: runtime.wordpressVersion })
830851
} finally {
831-
if (phase !== "full") runtime.php.exit()
852+
runtime.php.exit()
832853
}
833854
}
834855

scripts/cloudflare-local-gate.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ try {
1818
await run("npm", ["run", "generate:cloudflare-wordpress-runtime-corpus"])
1919
await run("npm", ["run", "provision:cloudflare-wordpress-runtime-corpus", "--", "--local", "--persist-to", stateDirectory])
2020
await startWorker()
21+
await assertFullBootProbe()
2122
await assertConcurrentMutations()
2223
const coldHome = await timedWordPressPage(origin, "cold explanatory homepage")
2324
const warmHome = await timedWordPressPage(origin, "warm explanatory homepage")
@@ -49,7 +50,7 @@ try {
4950
await assertLinkedAssets(restartedAdmin, "admin after cold restart")
5051
cookies.length = 0
5152
await login()
52-
console.log("Cloudflare local runtime gate passed: explanatory homepage, complete block styles, revision page cache, login, dashboard, post editor, concurrent canonical mutations, authenticated REST post and media creation, direct R2 upload serving, frontend/admin/editor assets, and cold-restart content, media, and session persistence.")
53+
console.log("Cloudflare local runtime gate passed: canonical full-boot probe, explanatory homepage, complete block styles, revision page cache, login, dashboard, post editor, concurrent canonical mutations, authenticated REST post and media creation, direct R2 upload serving, frontend/admin/editor assets, and cold-restart content, media, and session persistence.")
5354
} finally {
5455
await stopWorker()
5556
await rm(stateDirectory, { recursive: true, force: true })
@@ -207,6 +208,17 @@ async function assertHealthResponse() {
207208
if (response.status !== 200 || body.schema !== "wp-codebox/cloudflare-runtime-health/v1" || body.marker !== "wp-codebox-cloudflare-runtime-health" || body.phpVersion !== "8.5.8" || typeof body.wordpressVersion !== "string" || body.execution?.status !== "ok") throw new Error(`Unexpected Cloudflare runtime health envelope: ${JSON.stringify(body)}`)
208209
}
209210

211+
async function assertFullBootProbe() {
212+
const startedAt = performance.now()
213+
const response = await request(`${origin}/?phase=full`)
214+
const payload = await response.json()
215+
if (!response.ok || payload.schema !== "wp-codebox/cloudflare-boot-probe/v1" || payload.phase !== "full" || payload.completed !== true
216+
|| payload.evidence?.bootMode !== "canonical-mdi" || !payload.evidence?.wordpressVersion || !payload.evidence?.phpVersion) {
217+
throw new Error(`Canonical full-boot probe failed: status=${response.status} payload=${JSON.stringify(payload)}.`)
218+
}
219+
console.log(`Canonical full-boot probe timing: ${Math.round(performance.now() - startedAt)}ms.`)
220+
}
221+
210222
async function assertWordPressPage(target, label) {
211223
const response = await request(target)
212224
const body = await response.text()

tests/cloudflare-runtime.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ test("Cloudflare keeps PHP-WASM in the entry Worker and uses the Durable Object
265265
assert.doesNotMatch(worker, /decodeRemoteZip|WORDPRESS_ARCHIVE_URL/)
266266
assert.doesNotMatch(worker, /SQLITE_INTEGRATION_ARCHIVE_URL|fetchArchive\(/)
267267
assert.match(worker, /readRuntimeArchiveArtifact\(bucket, manifest\)/)
268+
assert.match(worker, /phase === "full"[\s\S]*await packagedCanonicalMarkdownSeed\(\)[\s\S]*bootMode: "canonical-mdi"/)
269+
assert.doesNotMatch(worker, /phase === "full" \|\| phase === "streamed-wordpress"/)
268270
assert.match(worker, /bucket\.get\(wordpressStaticArtifact\.key, \{ range: \{ offset: file\.offset, length: file\.size \} \}\)/)
269271
assert.match(worker, /await sha256Hex\(bytes\) !== file\.sha256/)
270272
assert.match(worker, /request\.method === "HEAD" \? null : bytes/)

0 commit comments

Comments
 (0)