Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mkdtempSync, rmSync } from 'node:fs'
import { createRequire } from 'node:module'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { setTimeout as delay } from 'node:timers/promises'
Expand All @@ -17,6 +18,10 @@ type RuntimeProcessHarness = {
baseUrl: string
restart: () => Promise<void>
stop: () => Promise<void>
getOutput: () => {
stderr: string
stdout: string
}
}

type WranglerRuntimeResponse<TPayload> =
Expand All @@ -31,6 +36,8 @@ type WranglerRuntimeResponse<TPayload> =

const packageDirectory = dirname(fileURLToPath(import.meta.url))
const wranglerConfigPath = join(packageDirectory, `fixtures`, `wrangler.toml`)
const require = createRequire(import.meta.url)
const wranglerBinPath = require.resolve(`wrangler/bin/wrangler.js`)

async function getAvailablePort(): Promise<number> {
const netModule = await import('node:net')
Expand Down Expand Up @@ -118,8 +125,6 @@ async function startWranglerRuntime(options: {
].filter((entry): entry is [string, string] => entry[1] !== undefined)

const wranglerArgs = [
`exec`,
`wrangler`,
`dev`,
`--local`,
`--ip`,
Expand All @@ -136,7 +141,7 @@ async function startWranglerRuntime(options: {
]),
]

child = spawn(`pnpm`, wranglerArgs, {
child = spawn(process.execPath, [wranglerBinPath, ...wranglerArgs], {
cwd: packageDirectory,
env: {
...process.env,
Expand Down Expand Up @@ -200,21 +205,36 @@ async function startWranglerRuntime(options: {
stop: async () => {
await stopWranglerProcess(child)
},
getOutput: () => ({
stderr: stderrBuffer,
stdout: stdoutBuffer,
}),
}
}

async function postJson<TPayload>(
baseUrl: string,
runtime: RuntimeProcessHarness,
path: string,
body: unknown,
): Promise<WranglerRuntimeResponse<TPayload>> {
const response = await fetch(`${baseUrl}${path}`, {
method: `POST`,
headers: {
'content-type': `application/json`,
},
body: JSON.stringify(body),
})
let response: Response
try {
response = await fetch(`${runtime.baseUrl}${path}`, {
method: `POST`,
headers: {
'content-type': `application/json`,
},
body: JSON.stringify(body),
signal: AbortSignal.timeout(30_000),
})
} catch (error) {
const output = runtime.getOutput()
throw createRuntimeError(
`Timed out waiting for wrangler dev runtime response: ${String(error)}`,
output.stderr,
Comment on lines +230 to +234
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use non-timeout-specific wording in the fetch failure path.

At Line 233, this catch handles all fetch errors, not only timeouts. The current text can mislead debugging for DNS/connection/reset failures.

Suggested diff
-      `Timed out waiting for wrangler dev runtime response: ${String(error)}`,
+      `Failed waiting for wrangler dev runtime response: ${String(error)}`,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
const output = runtime.getOutput()
throw createRuntimeError(
`Timed out waiting for wrangler dev runtime response: ${String(error)}`,
output.stderr,
} catch (error) {
const output = runtime.getOutput()
throw createRuntimeError(
`Failed waiting for wrangler dev runtime response: ${String(error)}`,
output.stderr,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/cloudflare-durable-objects-db-sqlite-persistence/e2e/cloudflare-do-runtime-bridge.e2e.test.ts`
around lines 230 - 234, The error message in the catch block that builds the
runtime error currently says "Timed out waiting for wrangler dev runtime
response" but this catch handles all fetch/failure cases; update the message
passed to createRuntimeError (where runtime.getOutput() and createRuntimeError
are used) to a non-timeout-specific wording such as "Failed to fetch wrangler
dev runtime response" or "Error fetching wrangler dev runtime response", and
include String(error) and output.stderr as before so DNS/connection/reset errors
are not mislabeled.

output.stdout,
)
}

const parsed = (await response.json()) as WranglerRuntimeResponse<TPayload>
return parsed
Expand Down Expand Up @@ -252,7 +272,7 @@ const createHarness: RuntimeBridgeE2EContractHarnessFactory = () => {
const harness: RuntimeBridgeE2EContractHarness = {
writeTodoFromClient: async (todo: RuntimeBridgeE2EContractTodo) => {
const runtime = await runtimePromise
const result = await postJson<void>(runtime.baseUrl, `/write-todo`, {
const result = await postJson<void>(runtime, `/write-todo`, {
collectionId,
todo,
txId: `tx-${nextSequence}`,
Expand All @@ -269,7 +289,7 @@ const createHarness: RuntimeBridgeE2EContractHarnessFactory = () => {
const runtime = await runtimePromise
const result = await postJson<
Array<{ key: string; value: RuntimeBridgeE2EContractTodo }>
>(runtime.baseUrl, `/load-todos`, {
>(runtime, `/load-todos`, {
collectionId: targetCollectionId ?? collectionId,
})
if (!result.ok) {
Expand All @@ -281,7 +301,7 @@ const createHarness: RuntimeBridgeE2EContractHarnessFactory = () => {
async (): Promise<RuntimeBridgeE2EContractError> => {
const runtime = await runtimePromise
const result = await postJson<never>(
runtime.baseUrl,
runtime,
`/load-unknown-collection-error`,
{
collectionId: `missing`,
Expand Down Expand Up @@ -334,7 +354,7 @@ describe(`cloudflare durable object schema mismatch behavior (wrangler local)`,
})

try {
const writeResult = await postJson<void>(runtime.baseUrl, `/write-todo`, {
const writeResult = await postJson<void>(runtime, `/write-todo`, {
collectionId,
txId: `tx-1`,
seq: 1,
Expand All @@ -359,7 +379,7 @@ describe(`cloudflare durable object schema mismatch behavior (wrangler local)`,
try {
const loadResult = await postJson<
Array<{ key: string; value: RuntimeBridgeE2EContractTodo }>
>(runtime.baseUrl, `/load-todos`, {
>(runtime, `/load-todos`, {
collectionId,
})
const runtimeError = assertRuntimeError(loadResult)
Expand All @@ -384,7 +404,7 @@ describe(`cloudflare durable object schema mismatch behavior (wrangler local)`,
})

try {
const writeResult = await postJson<void>(runtime.baseUrl, `/write-todo`, {
const writeResult = await postJson<void>(runtime, `/write-todo`, {
collectionId,
txId: `tx-1`,
seq: 1,
Expand All @@ -409,7 +429,7 @@ describe(`cloudflare durable object schema mismatch behavior (wrangler local)`,
try {
const loadResult = await postJson<
Array<{ key: string; value: RuntimeBridgeE2EContractTodo }>
>(runtime.baseUrl, `/load-todos`, {
>(runtime, `/load-todos`, {
collectionId,
})
const rows = assertRuntimeSuccess(loadResult) ?? []
Expand Down
Loading