Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

test(js-sdk): tolerate "Script not found" propagation errors in CF deploy suite (#1725)

devin-ai-integration[bot]8b4957057541
diff --git a/packages/js-sdk/tests/runtimes/cloudflare-deploy/run.test.ts b/packages/js-sdk/tests/runtimes/cloudflare-deploy/run.test.ts
index da8ade1c7..b710a8db5 100644
--- a/packages/js-sdk/tests/runtimes/cloudflare-deploy/run.test.ts
+++ b/packages/js-sdk/tests/runtimes/cloudflare-deploy/run.test.ts
@@ -6,13 +6,15 @@ test(
'sandbox lifecycle inside a deployed Cloudflare Worker',
// setup.mts waits for the fresh workers.dev subdomain to propagate before
// tests run; these retries only absorb transient blips — a stray
- // propagation 404 or an undici DNS/connect error ("fetch failed"). Any
- // other Cloudflare error page is a real failure and propagates.
+ // propagation error page (404 "nothing is here yet" for the route, 500
+ // "Script not found" from a colo that lags behind the one setup.mts
+ // probed) or an undici DNS/connect error ("fetch failed"). Any other
+ // Cloudflare error page is a real failure and propagates.
{
retry: {
count: 10,
delay: 3_000,
- condition: /non-JSON response \(404|fetch failed/,
+ condition: /non-JSON response \(404|Script not found|fetch failed/,
},
},
async () => {
diff --git a/packages/js-sdk/tests/runtimes/cloudflare-deploy/setup.mts b/packages/js-sdk/tests/runtimes/cloudflare-deploy/setup.mts
index ea5c9e84f..a86ba75aa 100644
--- a/packages/js-sdk/tests/runtimes/cloudflare-deploy/setup.mts
+++ b/packages/js-sdk/tests/runtimes/cloudflare-deploy/setup.mts
@@ -31,17 +31,20 @@ function wrangler(args: string[]) {
}
// A temporary deploy lands on a brand-new account subdomain
-// (<worker>.<random-name>.workers.dev), and Cloudflare serves its HTML 404
-// page ("nothing is here yet") until the route propagates to the edge —
-// usually seconds, occasionally minutes. Wait for the worker itself to
-// answer (405 to GET, worker.mjs is POST-only) so the test's own retries
-// only have to absorb transient network failures.
+// (<worker>.<random-name>.workers.dev), and until both the route and the
+// script propagate to the edge Cloudflare serves an HTML error page: a 404
+// ("nothing is here yet") for the missing route, or a 500 ("Script not
+// found") from a colo that already has the route but not the script. Wait
+// for the worker itself to answer (405 to GET, worker.mjs is POST-only) so
+// the test's own retries only have to absorb transient network failures.
+const propagationErrorTitle = /Script not found/i
+
async function waitUntilLive(workerUrl: string, timeoutMs = 240_000) {
const deadline = Date.now() + timeoutMs
for (;;) {
// Thrown fetch errors (DNS/connect for the fresh subdomain) are also
- // transient — keep waiting on those, but fail fast on any status other
- // than the propagation 404 so real errors surface immediately.
+ // transient — keep waiting on those, but fail fast on anything that is
+ // not a propagation error so real errors surface immediately.
const response = await fetch(workerUrl).catch((err) => {
console.log(`Worker not reachable yet (${err}), waiting...`)
return undefined
@@ -50,16 +53,22 @@ async function waitUntilLive(workerUrl: string, timeoutMs = 240_000) {
if (response.status === 405) {
return
}
- if (response.status !== 404) {
+ if (response.status === 404) {
+ console.log('Worker route not live yet (404), waiting...')
+ } else {
const text = await response.text()
const title = text.match(/<title>(.*?)<\/title>/is)?.[1]?.trim()
- throw new Error(
- `Worker at ${workerUrl} answered ${response.status}${
- title ? ` ("${title}")` : ''
- } — not the propagation 404: ${text.slice(0, 200)}`
+ if (!propagationErrorTitle.test(title ?? '')) {
+ throw new Error(
+ `Worker at ${workerUrl} answered ${response.status}${
+ title ? ` ("${title}")` : ''
+ } — not a propagation error: ${text.slice(0, 200)}`
+ )
+ }
+ console.log(
+ `Worker script not live yet (${response.status}, "${title}"), waiting...`
)
}
- console.log('Worker route not live yet (404), waiting...')
}
if (Date.now() >= deadline) {
throw new Error(