From a4215e96c9b702829173b457407af4ebe7b03553 Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:01:43 +0000 Subject: [PATCH 01/24] ci: ensure E2E tests failures not reported as successes #4458 accidentally left `continue-on-error: true` in the workflow. This meant that E2E test failures weren't reported as check failures. --- .github/workflows/e2e.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 34b38959b915..5863c1984e99 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -74,8 +74,6 @@ jobs: run: echo "dir=$(ls $HOME/wrangler-*.tgz)" >> $GITHUB_OUTPUT; - name: Run tests - id: e2e-1 - continue-on-error: true run: pnpm run --filter wrangler test:e2e env: CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }} From f532eb8060e2c73b15fe644db37b192cd2b8a63f Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:04:33 +0000 Subject: [PATCH 02/24] test: remove redundant `deploy.test.ts` E2E test This test was a strict subset of `deployments.test.ts`, and wasn't providing any additional value. --- packages/wrangler/e2e/deploy.test.ts | 118 --------------------------- 1 file changed, 118 deletions(-) delete mode 100644 packages/wrangler/e2e/deploy.test.ts diff --git a/packages/wrangler/e2e/deploy.test.ts b/packages/wrangler/e2e/deploy.test.ts deleted file mode 100644 index d6495139f62f..000000000000 --- a/packages/wrangler/e2e/deploy.test.ts +++ /dev/null @@ -1,118 +0,0 @@ -import crypto from "node:crypto"; -import path from "node:path"; -import shellac from "shellac"; -import { fetch } from "undici"; -import { beforeAll, describe, expect, it } from "vitest"; -import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id"; -import { normalizeOutput } from "./helpers/normalize"; -import { retry } from "./helpers/retry"; -import { dedent, makeRoot, seed } from "./helpers/setup"; -import { WRANGLER } from "./helpers/wrangler-command"; - -function matchWorkersDev(stdout: string): string { - return stdout.match( - /https:\/\/smoke-test-worker-.+?\.(.+?\.workers\.dev)/ - )?.[1] as string; -} - -describe("deploy", () => { - let workerName: string; - let workerPath: string; - let workersDev: string | null = null; - let runInRoot: typeof shellac; - let runInWorker: typeof shellac; - let normalize: (str: string) => string; - - beforeAll(async () => { - const root = await makeRoot(); - runInRoot = shellac.in(root).env(process.env); - workerName = `smoke-test-worker-${crypto.randomBytes(4).toString("hex")}`; - workerPath = path.join(root, workerName); - runInWorker = shellac.in(workerPath).env(process.env); - normalize = (str) => - normalizeOutput(str, { - [workerName]: "smoke-test-worker", - [CLOUDFLARE_ACCOUNT_ID]: "CLOUDFLARE_ACCOUNT_ID", - }); - }); - - it("init worker", async () => { - const { stdout } = - await runInRoot`$ ${WRANGLER} init --yes --no-delegate-c3 ${workerName}`; - - expect(normalize(stdout)).toContain( - "To publish your Worker to the Internet, run `npm run deploy`" - ); - }); - - it("deploy worker", async () => { - const { stdout } = await runInWorker`$ ${WRANGLER} deploy`; - expect(normalize(stdout)).toMatchInlineSnapshot(` - "🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/workers/standard/opt-in. - Total Upload: xx KiB / gzip: xx KiB - Uploaded smoke-test-worker (TIMINGS) - Published smoke-test-worker (TIMINGS) - https://smoke-test-worker.SUBDOMAIN.workers.dev - Current Deployment ID: 00000000-0000-0000-0000-000000000000" - `); - workersDev = matchWorkersDev(stdout); - - const { text } = await retry( - (s) => s.status !== 200, - async () => { - const r = await fetch(`https://${workerName}.${workersDev}`); - return { text: await r.text(), status: r.status }; - } - ); - expect(text).toMatchInlineSnapshot('"Hello World!"'); - }); - - it("modify & deploy worker", async () => { - await seed(workerPath, { - "src/index.ts": dedent` - export default { - fetch(request) { - return new Response("Updated Worker!") - } - }`, - }); - const { stdout, stderr } = await runInWorker`$ ${WRANGLER} deploy`; - expect(normalize(stdout)).toMatchInlineSnapshot(` - "🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/workers/standard/opt-in. - Total Upload: xx KiB / gzip: xx KiB - Uploaded smoke-test-worker (TIMINGS) - Published smoke-test-worker (TIMINGS) - https://smoke-test-worker.SUBDOMAIN.workers.dev - Current Deployment ID: 00000000-0000-0000-0000-000000000000" - `); - expect(stderr).toMatchInlineSnapshot('""'); - workersDev = matchWorkersDev(stdout); - - const { text } = await retry( - (s) => s.status !== 200 || s.text === "Hello World!", - async () => { - const r = await fetch(`https://${workerName}.${workersDev}`); - return { text: await r.text(), status: r.status }; - } - ); - expect(text).toMatchInlineSnapshot('"Updated Worker!"'); - }); - - it("delete worker", async () => { - const { stdout, stderr } = await runInWorker`$ ${WRANGLER} delete`; - expect(normalize(stdout)).toMatchInlineSnapshot(` - "? Are you sure you want to delete smoke-test-worker? This action cannot be undone. - 🤖 Using default value in non-interactive context: yes - Successfully deleted smoke-test-worker" - `); - expect(stderr).toMatchInlineSnapshot('""'); - const { status } = await retry( - (s) => s.status === 200 || s.status === 500, - async () => { - const r = await fetch(`https://${workerName}.${workersDev}`); - return { text: await r.text(), status: r.status }; - } - ); - expect(status).toBe(404); - }); -}); From 2283d8181de9cf1dd6f7ebe0514c52c6d1765fac Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:07:05 +0000 Subject: [PATCH 03/24] test: remove standard pricing warning from E2E test output This warning may not be shown if an account has opted-in to standard pricing. This change normalises output to remove it, meaning tests can be run on any account, regardless of opt-in state. --- packages/wrangler/e2e/c3-integration.test.ts | 3 +-- packages/wrangler/e2e/deployments.test.ts | 6 ++---- packages/wrangler/e2e/helpers/normalize.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/wrangler/e2e/c3-integration.test.ts b/packages/wrangler/e2e/c3-integration.test.ts index a60dbe1d56c0..fec1a2ee1179 100644 --- a/packages/wrangler/e2e/c3-integration.test.ts +++ b/packages/wrangler/e2e/c3-integration.test.ts @@ -63,8 +63,7 @@ describe("c3 integration", () => { it("deploy the worker", async () => { const { stdout, stderr } = await runInWorker`$ ${WRANGLER} deploy`; expect(normalize(stdout)).toMatchInlineSnapshot(` - "🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/workers/standard/opt-in. - Total Upload: xx KiB / gzip: xx KiB + "Total Upload: xx KiB / gzip: xx KiB Uploaded smoke-test-worker (TIMINGS) Published smoke-test-worker (TIMINGS) https://smoke-test-worker.SUBDOMAIN.workers.dev diff --git a/packages/wrangler/e2e/deployments.test.ts b/packages/wrangler/e2e/deployments.test.ts index 02bc9500120c..c8993c6bc6cc 100644 --- a/packages/wrangler/e2e/deployments.test.ts +++ b/packages/wrangler/e2e/deployments.test.ts @@ -56,8 +56,7 @@ describe("deployments", () => { it("deploy worker", async () => { const { stdout } = await runInWorker`$ ${WRANGLER} deploy`; expect(normalize(stdout)).toMatchInlineSnapshot(` - "🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/workers/standard/opt-in. - Total Upload: xx KiB / gzip: xx KiB + "Total Upload: xx KiB / gzip: xx KiB Uploaded smoke-test-worker (TIMINGS) Published smoke-test-worker (TIMINGS) https://smoke-test-worker.SUBDOMAIN.workers.dev @@ -101,8 +100,7 @@ describe("deployments", () => { }); const { stdout, stderr } = await runInWorker`$ ${WRANGLER} deploy`; expect(normalize(stdout)).toMatchInlineSnapshot(` - "🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/workers/standard/opt-in. - Total Upload: xx KiB / gzip: xx KiB + "Total Upload: xx KiB / gzip: xx KiB Uploaded smoke-test-worker (TIMINGS) Published smoke-test-worker (TIMINGS) https://smoke-test-worker.SUBDOMAIN.workers.dev diff --git a/packages/wrangler/e2e/helpers/normalize.ts b/packages/wrangler/e2e/helpers/normalize.ts index f5911fd7afdb..b16f378b9c7a 100644 --- a/packages/wrangler/e2e/helpers/normalize.ts +++ b/packages/wrangler/e2e/helpers/normalize.ts @@ -6,6 +6,7 @@ export function normalizeOutput( ): string { const functions = [ removeVersionHeader, + removeStandardPricingWarning, npmStripTimings, removeWorkersDev, removeUUID, @@ -154,3 +155,13 @@ export function squashLocalNetworkBindings(stdout: string): string { "[mf:inf] Ready on http://:\n[mf:inf] - http://:" ); } + +/** + * This may or may not be displayed depending on whether the test account has accepted standard pricing. + */ +function removeStandardPricingWarning(stdout: string): string { + return stdout.replace( + "🚧 New Workers Standard pricing is now available. Please visit the dashboard to view details and opt-in to new pricing: https://dash.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/workers/standard/opt-in.", + "" + ); +} From c6e3dde3a2eb5cc3971a70966db07c2c88ff9dc6 Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:08:21 +0000 Subject: [PATCH 04/24] test: update format of writing logs message in E2E tests --- packages/wrangler/e2e/dev.test.ts | 6 +++--- packages/wrangler/e2e/helpers/normalize.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index ee2782d5fbc9..fa1df8bcf72a 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -489,14 +489,14 @@ describe("writes debug logs to hidden file", () => { async (session) => { await waitForPortToBeBound(session.port); - await waitUntilOutputContains(session, "🐛 Writing debug logs to"); + await waitUntilOutputContains(session, "Writing logs to"); await setTimeout(1000); // wait a bit to ensure the file is written to disk } ); const filepath = finalA.stdout.match( - /🐛 Writing debug logs to "(.+\.log)"/ + /🪵 {2}Writing logs to "(.+\.log)"/ )?.[1]; assert(filepath); @@ -511,7 +511,7 @@ describe("writes debug logs to hidden file", () => { }); const filepath = finalA.stdout.match( - /🐛 Writing debug logs to "(.+\.log)"/ + /🪵 {2}Writing logs to "(.+\.log)"/ )?.[1]; expect(filepath).toBeUndefined(); diff --git a/packages/wrangler/e2e/helpers/normalize.ts b/packages/wrangler/e2e/helpers/normalize.ts index b16f378b9c7a..b3582e827437 100644 --- a/packages/wrangler/e2e/helpers/normalize.ts +++ b/packages/wrangler/e2e/helpers/normalize.ts @@ -140,10 +140,12 @@ export function normalizeTempDirs(stdout: string): string { * Debug log files are created with a timestamp, so we replace the debug log filepath timestamp with */ export function normalizeDebugLogFilepath(stdout: string): string { - return stdout.replace( - /(🐛 Writing debug logs to ".+wrangler-debug)-.+\.log/, - "$1-.log" - ); + return stdout + .replace(/🪵 {2}Writing logs to ".+\.log"/, '🪵 Writing logs to ""') + .replace( + /🪵 {2}Logs were written to ".+\.log"/, + '🪵 Logs were written to ""' + ); } /** From 9de08d7af7bf3644979baab095d1df424269e87f Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:10:03 +0000 Subject: [PATCH 05/24] test: use `fallback` instead of `default` in E2E tests #4571 updated the message logged in non-interactive contexts for default values to use the word `fallback` instead of `default`. --- packages/wrangler/e2e/c3-integration.test.ts | 2 +- packages/wrangler/e2e/deployments.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/wrangler/e2e/c3-integration.test.ts b/packages/wrangler/e2e/c3-integration.test.ts index fec1a2ee1179..29fa335156cb 100644 --- a/packages/wrangler/e2e/c3-integration.test.ts +++ b/packages/wrangler/e2e/c3-integration.test.ts @@ -85,7 +85,7 @@ describe("c3 integration", () => { const { stdout, stderr } = await runInWorker`$$ ${WRANGLER} delete`; expect(normalize(stdout)).toMatchInlineSnapshot(` "? Are you sure you want to delete smoke-test-worker? This action cannot be undone. - 🤖 Using default value in non-interactive context: yes + 🤖 Using fallback value in non-interactive context: yes Successfully deleted smoke-test-worker" `); expect(stderr).toMatchInlineSnapshot('""'); diff --git a/packages/wrangler/e2e/deployments.test.ts b/packages/wrangler/e2e/deployments.test.ts index c8993c6bc6cc..ff7697f5bfcb 100644 --- a/packages/wrangler/e2e/deployments.test.ts +++ b/packages/wrangler/e2e/deployments.test.ts @@ -176,7 +176,7 @@ describe("deployments", () => { const { stdout, stderr } = await runInWorker`$ ${WRANGLER} delete`; expect(normalize(stdout)).toMatchInlineSnapshot(` "? Are you sure you want to delete smoke-test-worker? This action cannot be undone. - 🤖 Using default value in non-interactive context: yes + 🤖 Using fallback value in non-interactive context: yes Successfully deleted smoke-test-worker" `); expect(stderr).toMatchInlineSnapshot('""'); From 970d65929d58f295e75918a8cd911ea657f45323 Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:12:09 +0000 Subject: [PATCH 06/24] fix: ensure `--log-level` argument applied immediately Some messages were being logged before the `--log-level` argument was applied. In particular, this meant the "writing logs to" message at `debug` level, was not output when using `--log-level=debug`. --- .changeset/spotty-papayas-sneeze.md | 7 +++++++ packages/wrangler/src/index.ts | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/spotty-papayas-sneeze.md diff --git a/.changeset/spotty-papayas-sneeze.md b/.changeset/spotty-papayas-sneeze.md new file mode 100644 index 000000000000..5cdd38ada03e --- /dev/null +++ b/.changeset/spotty-papayas-sneeze.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +fix: ensure `wrangler dev --log-level` flag applied to all logs + +Previously, `wrangler dev` may have ignored the `--log-level` flag for some startup logs. This change ensures the `--log-level` flag is applied immediately. diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index 8abe7c16c4ff..147463d0697b 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -40,7 +40,7 @@ import { generateHandler, generateOptions } from "./generate"; import { hyperdrive } from "./hyperdrive/index"; import { initHandler, initOptions } from "./init"; import { kvBulk, kvKey, kvNamespace } from "./kv"; -import { logBuildFailure, logger } from "./logger"; +import { logBuildFailure, logger, LOGGER_LEVELS } from "./logger"; import * as metrics from "./metrics"; import { mTlsCertificateCommands } from "./mtls-certificate/cli"; import { pages } from "./pages"; @@ -70,6 +70,7 @@ import { versionsUploadHandler, versionsUploadOptions } from "./versions"; import { whoami } from "./whoami"; import { asJson } from "./yargs-types"; import type { Config } from "./config"; +import type { LoggerLevel } from "./logger"; import type { CommonYargsArgv, CommonYargsOptions } from "./yargs-types"; import type { Arguments, CommandModule } from "yargs"; @@ -223,6 +224,11 @@ export function createCLIParser(argv: string[]) { hidden: true, }) .check((args) => { + // Update logger level, before we do any logging + if (Object.keys(LOGGER_LEVELS).includes(args.logLevel as string)) { + logger.loggerLevel = args.logLevel as LoggerLevel; + } + // Grab locally specified env params from `.env` file const loaded = loadDotEnv(".env", args.env); for (const [key, value] of Object.entries(loaded?.parsed ?? {})) { From bc423c91b48558fd35b08980c4cffd813a6e23ac Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:13:50 +0000 Subject: [PATCH 07/24] test: improve reliability of `dev.test.ts` E2E test This change makes a few improvements to `dev.test.ts`: - Shorter timeouts for `fetch()` retries - Replaces `get-port` with native port `0` implementation - Waits for stdout handlers to be registered before starting `wrangler dev` - Ignores errors if we failed to find a proccess to kill (assumes the process was already killed) --- packages/wrangler/e2e/dev.test.ts | 44 +++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index fa1df8bcf72a..8a725b1eb410 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -4,15 +4,23 @@ import { existsSync } from "node:fs"; import * as nodeNet from "node:net"; import path from "node:path"; import { setTimeout } from "node:timers/promises"; -import getPort from "get-port"; import shellac from "shellac"; -import { fetch } from "undici"; +import { Agent, fetch, setGlobalDispatcher } from "undici"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { normalizeOutput } from "./helpers/normalize"; import { retry } from "./helpers/retry"; import { dedent, makeRoot, seed } from "./helpers/setup"; import { WRANGLER } from "./helpers/wrangler-command"; +// Use `Agent` with lower timeouts so `fetch()`s inside `retry()`s don't block for a long time +setGlobalDispatcher( + new Agent({ + connectTimeout: 10_000, + headersTimeout: 10_000, + bodyTimeout: 10_000, + }) +); + type MaybePromise = T | Promise; const waitForPortToBeBound = async (port: number) => { @@ -31,11 +39,7 @@ const waitUntilOutputContains = async ( (stdout) => !stdout.includes(substring), async () => { await setTimeout(intervalMs); - return ( - normalizeOutput(session.stdout) + - "\n\n\n" + - normalizeOutput(session.stderr) - ); + return session.stdout + "\n\n\n" + session.stderr; } ); }; @@ -46,6 +50,20 @@ interface SessionData { stderr: string; } +function getPort() { + return new Promise((resolve, reject) => { + const server = nodeNet.createServer((socket) => socket.destroy()); + server.listen(0, () => { + const address = server.address(); + assert(typeof address === "object" && address !== null); + server.close((err) => { + if (err) reject(err); + else resolve(address.port); + }); + }); + }); +} + async function runDevSession( workerPath: string, flags: string, @@ -65,7 +83,11 @@ async function runDevSession( // Must use the `in` statement in the shellac script rather than `.in()` modifier on the `shellac` object // otherwise the working directory does not get picked up. + let promiseResolve: (() => void) | undefined; + const promise = new Promise((resolve) => (promiseResolve = resolve)); const bg = await shellac.env(process.env).bg` + await ${() => promise} + in ${workerPath} { exits { $ ${WRANGLER} dev ${flags} @@ -82,12 +104,18 @@ async function runDevSession( }; bg.process.stdout.on("data", (chunk) => (sessionData.stdout += chunk)); bg.process.stderr.on("data", (chunk) => (sessionData.stderr += chunk)); + // Only start `wrangler dev` once we've registered output listeners so we don't miss messages + promiseResolve?.(); await session(sessionData); return bg.promise; } finally { - if (pid) process.kill(pid); + try { + if (pid) process.kill(pid); + } catch { + // Ignore errors if we failed to kill the process (i.e. ESRCH if it's already terminated) + } } } From bef4ac48e3affb75c4009bdc9d7a57e2f390146d Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 2 Feb 2024 13:14:34 +0000 Subject: [PATCH 08/24] fix: throw `UserError`s for R2 object/bucket not-found errors These errors should not be reported to Sentry. --- .changeset/mighty-coins-cover.md | 7 +++++++ packages/wrangler/e2e/r2.test.ts | 8 ++++---- packages/wrangler/src/cfetch/internal.ts | 4 +++- packages/wrangler/src/r2/helpers.ts | 9 ++++++--- packages/wrangler/src/r2/index.ts | 3 +++ 5 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 .changeset/mighty-coins-cover.md diff --git a/.changeset/mighty-coins-cover.md b/.changeset/mighty-coins-cover.md new file mode 100644 index 000000000000..afdf50c4fd4a --- /dev/null +++ b/.changeset/mighty-coins-cover.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +fix: mark R2 object and bucket not found errors as unreportable + +Previously, running `wrangler r2 objects {get,put}` with an object or bucket that didn't exist would ask if you wanted to report that error to Cloudflare. There's nothing we can do to fix this, so this change prevents the prompt in this case. diff --git a/packages/wrangler/e2e/r2.test.ts b/packages/wrangler/e2e/r2.test.ts index 44708b7ec760..ce863b0be307 100644 --- a/packages/wrangler/e2e/r2.test.ts +++ b/packages/wrangler/e2e/r2.test.ts @@ -83,8 +83,8 @@ describe("r2", () => { If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose" `); expect(normalize(stderr)).toMatchInlineSnapshot(` - "X [ERROR] Failed to fetch /accounts/CLOUDFLARE_ACCOUNT_ID/r2/buckets/wrangler-smoke-test-bucket/objects/testr2 - 404: Not Found); - " + "X [ERROR] The specified key does not exist. + 🪵 Logs were written to \\"\\"" `); }); @@ -112,8 +112,8 @@ describe("r2", () => { If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose" `); expect(normalize(stderr)).toMatchInlineSnapshot(` - "X [ERROR] Failed to fetch /accounts/CLOUDFLARE_ACCOUNT_ID/r2/buckets/wrangler-smoke-test-bucket/objects/testr2 - 404: Not Found); - " + "X [ERROR] The specified bucket does not exist. + 🪵 Logs were written to \\"\\"" `); }); }); diff --git a/packages/wrangler/src/cfetch/internal.ts b/packages/wrangler/src/cfetch/internal.ts index 796c99251763..cac73ce511a3 100644 --- a/packages/wrangler/src/cfetch/internal.ts +++ b/packages/wrangler/src/cfetch/internal.ts @@ -196,7 +196,7 @@ type ResponseWithBody = Response & { body: NonNullable }; export async function fetchR2Objects( resource: string, bodyInit: RequestInit = {} -): Promise { +): Promise { await requireLoggedIn(); const auth = requireApiToken(); const headers = cloneHeaders(bodyInit.headers); @@ -210,6 +210,8 @@ export async function fetchR2Objects( if (response.ok && response.body) { return response as ResponseWithBody; + } else if (response.status === 404) { + return null; } else { throw new Error( `Failed to fetch ${resource} - ${response.status}: ${response.statusText});` diff --git a/packages/wrangler/src/r2/helpers.ts b/packages/wrangler/src/r2/helpers.ts index 5acee6e6bafb..8c20bb6c6638 100644 --- a/packages/wrangler/src/r2/helpers.ts +++ b/packages/wrangler/src/r2/helpers.ts @@ -97,7 +97,7 @@ export async function getR2Object( bucketName: string, objectName: string, jurisdiction?: string -): Promise { +): Promise { const headers: HeadersInit = {}; if (jurisdiction !== undefined) { headers["cf-r2-jurisdiction"] = jurisdiction; @@ -110,7 +110,7 @@ export async function getR2Object( } ); - return response.body; + return response === null ? null : response.body; } /** @@ -142,7 +142,7 @@ export async function putR2Object( headers["cf-r2-jurisdiction"] = jurisdiction; } - await fetchR2Objects( + const result = await fetchR2Objects( `/accounts/${accountId}/r2/buckets/${bucketName}/objects/${objectName}`, { body: object, @@ -151,6 +151,9 @@ export async function putR2Object( duplex: "half", } ); + if (result === null) { + throw new UserError("The specified bucket does not exist."); + } } /** * Delete an Object diff --git a/packages/wrangler/src/r2/index.ts b/packages/wrangler/src/r2/index.ts index 3598d210a936..c788c8904ac3 100644 --- a/packages/wrangler/src/r2/index.ts +++ b/packages/wrangler/src/r2/index.ts @@ -138,6 +138,9 @@ export function r2(r2Yargs: CommonYargsArgv) { key, jurisdiction ); + if (input === null) { + throw new UserError("The specified key does not exist."); + } await stream.promises.pipeline(input, output); } if (!pipe) logger.log("Download complete."); From 47f1f0c55906f79d29d95a4a18b20b281ee7fd52 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 19:16:22 +0000 Subject: [PATCH 09/24] global install --- .github/workflows/e2e.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5863c1984e99..44706b20554e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -74,11 +74,13 @@ jobs: run: echo "dir=$(ls $HOME/wrangler-*.tgz)" >> $GITHUB_OUTPUT; - name: Run tests - run: pnpm run --filter wrangler test:e2e + run: | + pnpm add ${{ steps.find-wrangler.outputs.dir}} --global + pnpm run --filter wrangler test:e2e env: CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }} - WRANGLER: pnpm --silent --package ${{ steps.find-wrangler.outputs.dir}} dlx wrangler + WRANGLER: wrangler NODE_OPTIONS: "--max_old_space_size=8192" WRANGLER_LOG_PATH: ${{ runner.temp }}/wrangler-debug-logs/ From 6fae44dc8a5d5037ed3060ee25346811cb39b749 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 19:26:55 +0000 Subject: [PATCH 10/24] Ensure internal workers listen on ipv4 only --- packages/wrangler/src/dev.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index c0bd22261619..62d41c73726f 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -712,13 +712,13 @@ async function validateDevServerSettings( const initialIp = args.ip || config.dev.ip; const initialIpListenCheck = initialIp === "*" ? "0.0.0.0" : initialIp; const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT, initialIpListenCheck); - const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT, "localhost"); + const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT, "127.0.0.1"); // Our inspector proxy server will be binding to the result of // `getInspectorPort`. If we attempted to bind workerd to the same inspector // port, we'd get a port already in use error. Therefore, generate a new port // for our runtime to bind its inspector service to. - const getRuntimeInspectorPort = memoizeGetPort(0, "localhost"); + const getRuntimeInspectorPort = memoizeGetPort(0, "127.0.0.1"); if (config.services && config.services.length > 0) { logger.warn( From 57480eae5243b1b6b427a9116333478b5752f683 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 19:45:20 +0000 Subject: [PATCH 11/24] shorter timeouts --- .github/workflows/e2e.yml | 2 +- packages/wrangler/package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 44706b20554e..f0cb5887897b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -13,7 +13,7 @@ jobs: concurrency: group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.node }} cancel-in-progress: true - timeout-minutes: 30 + timeout-minutes: 15 if: github.repository_owner == 'cloudflare' && (github.event_name != 'pull_request' || (github.event_name == 'pull_request' && contains(github.event.*.labels.*.name, 'e2e' ))) name: "E2E Test" strategy: diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 61da11023647..1f4ee93eb584 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -63,7 +63,7 @@ "test": "pnpm run assert-git-version && jest", "test:ci": "pnpm run test --coverage", "test:debug": "pnpm run test --silent=false --verbose=true", - "test:e2e": "vitest --test-timeout 240000 --single-thread --dir ./e2e --retry 2 run", + "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run", "test:watch": "pnpm run test --testTimeout=50000 --watch", "type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json" }, @@ -107,7 +107,7 @@ "blake3-wasm": "^2.1.5", "chokidar": "^3.5.3", "esbuild": "0.17.19", - "miniflare": "workspace:*", + "miniflare": "file:/Users/penalosa/dev/wrangler2/packages/wrangler/../miniflare/miniflare-3.20240129.0.tgz", "nanoid": "^3.3.3", "path-to-regexp": "^6.2.0", "resolve": "^1.22.8", From d9a3654d78545fdd28b147a734b14de145d932d5 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 19:47:40 +0000 Subject: [PATCH 12/24] lock --- pnpm-lock.yaml | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6bd9610d0b07..2ed4860c5fb8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -805,7 +805,7 @@ importers: version: 8.49.0 eslint-config-turbo: specifier: latest - version: 1.10.15(eslint@8.49.0) + version: 1.12.2(eslint@8.49.0) eslint-plugin-import: specifier: 2.26.x version: 2.26.0(@typescript-eslint/parser@6.7.2)(eslint@8.49.0) @@ -865,7 +865,7 @@ importers: version: 8.2.0 capnp-ts: specifier: ^0.7.0 - version: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii) + version: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii)(supports-color@9.2.2) exit-hook: specifier: ^2.2.1 version: 2.2.1 @@ -1322,8 +1322,8 @@ importers: specifier: 0.17.19 version: 0.17.19 miniflare: - specifier: workspace:* - version: link:../miniflare + specifier: file:/Users/penalosa/dev/wrangler2/packages/wrangler/../miniflare/miniflare-3.20240129.0.tgz + version: file:packages/miniflare/miniflare-3.20240129.0.tgz(supports-color@9.2.2) nanoid: specifier: ^3.3.3 version: 3.3.6 @@ -9031,7 +9031,7 @@ packages: - supports-color dev: true - /capnp-ts@0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii): + /capnp-ts@0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii)(supports-color@9.2.2): resolution: {integrity: sha512-XKxXAC3HVPv7r674zP0VC3RTXz+/JKhfyw94ljvF80yynK6VkTnqE3jMuN8b3dUVmmc43TjyxjW4KTsmB3c86g==} dependencies: debug: 4.3.4(supports-color@9.2.2) @@ -10703,13 +10703,13 @@ packages: eslint: 8.49.0 dev: true - /eslint-config-turbo@1.10.15(eslint@8.49.0): - resolution: {integrity: sha512-76mpx2x818JZE26euen14utYcFDxOahZ9NaWA+6Xa4pY2ezVKVschuOxS96EQz3o3ZRSmcgBOapw/gHbN+EKxQ==} + /eslint-config-turbo@1.12.2(eslint@8.49.0): + resolution: {integrity: sha512-JHTGtDQuISBEWIorHenu5AeX1nv16NiDgDVRi1i0VyeYw0SiVh+lSQbv4BawXSnG1nOFpjbopAQdZvdB3PwXbQ==} peerDependencies: eslint: '>6.6.0' dependencies: eslint: 8.49.0 - eslint-plugin-turbo: 1.10.15(eslint@8.49.0) + eslint-plugin-turbo: 1.12.2(eslint@8.49.0) dev: false /eslint-import-resolver-node@0.3.7: @@ -11136,8 +11136,8 @@ packages: - typescript dev: true - /eslint-plugin-turbo@1.10.15(eslint@8.49.0): - resolution: {integrity: sha512-Tv4QSKV/U56qGcTqS/UgOvb9HcKFmWOQcVh3HEaj7of94lfaENgfrtK48E2CckQf7amhKs1i+imhCsNCKjkQyA==} + /eslint-plugin-turbo@1.12.2(eslint@8.49.0): + resolution: {integrity: sha512-/l0aGvZRzK1LMRTibRd6ZbEEuD5TtGotDTkZpxSIWA1FI764pWVvQduQMKBaRuz7aTuAo0WxatD8v1scK+qRWw==} peerDependencies: eslint: '>6.6.0' dependencies: @@ -19885,6 +19885,32 @@ packages: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} dev: true + file:packages/miniflare/miniflare-3.20240129.0.tgz(supports-color@9.2.2): + resolution: {integrity: sha512-ZTuddTWQM/MWlXQFuFRDfxuGFHNNErCcHcp1ZnFSiWxAp3d4wcdo+rNWflQOCddD6HKwFebrdcIi74slMWywhA==, tarball: file:packages/miniflare/miniflare-3.20240129.0.tgz} + id: file:packages/miniflare/miniflare-3.20240129.0.tgz + name: miniflare + version: 3.20240129.0 + engines: {node: '>=16.13'} + hasBin: true + dependencies: + '@cspotcode/source-map-support': 0.8.1 + acorn: 8.10.0 + acorn-walk: 8.2.0 + capnp-ts: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii)(supports-color@9.2.2) + exit-hook: 2.2.1 + glob-to-regexp: 0.4.1 + stoppable: 1.1.0 + undici: 5.28.2 + workerd: 1.20240129.0 + ws: 8.14.2 + youch: 3.2.3 + zod: 3.22.3 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + dev: false + file:vendor/yoga-layout-2.0.0-beta.1.tgz: resolution: {integrity: sha512-cHunx1nKVIoOxUw9pJE/3mu5NCUMRmWRgzrrSPfjXXAMMzkxQGDbzP/r6Iv4tdWR20p08kgKBG7n/dmbf6FG1w==, tarball: file:vendor/yoga-layout-2.0.0-beta.1.tgz} name: yoga-layout From f6e861647ce6933ca60e393eee8da2ce582a3d66 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 19:49:28 +0000 Subject: [PATCH 13/24] lockfile --- packages/wrangler/package.json | 2 +- pnpm-lock.yaml | 34 ++++------------------------------ 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 1f4ee93eb584..11512276e4b8 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -107,7 +107,7 @@ "blake3-wasm": "^2.1.5", "chokidar": "^3.5.3", "esbuild": "0.17.19", - "miniflare": "file:/Users/penalosa/dev/wrangler2/packages/wrangler/../miniflare/miniflare-3.20240129.0.tgz", + "miniflare": "workspace:*", "nanoid": "^3.3.3", "path-to-regexp": "^6.2.0", "resolve": "^1.22.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2ed4860c5fb8..ee7047c6b4ee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -865,7 +865,7 @@ importers: version: 8.2.0 capnp-ts: specifier: ^0.7.0 - version: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii)(supports-color@9.2.2) + version: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii) exit-hook: specifier: ^2.2.1 version: 2.2.1 @@ -1322,8 +1322,8 @@ importers: specifier: 0.17.19 version: 0.17.19 miniflare: - specifier: file:/Users/penalosa/dev/wrangler2/packages/wrangler/../miniflare/miniflare-3.20240129.0.tgz - version: file:packages/miniflare/miniflare-3.20240129.0.tgz(supports-color@9.2.2) + specifier: workspace:* + version: link:../miniflare nanoid: specifier: ^3.3.3 version: 3.3.6 @@ -9031,7 +9031,7 @@ packages: - supports-color dev: true - /capnp-ts@0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii)(supports-color@9.2.2): + /capnp-ts@0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii): resolution: {integrity: sha512-XKxXAC3HVPv7r674zP0VC3RTXz+/JKhfyw94ljvF80yynK6VkTnqE3jMuN8b3dUVmmc43TjyxjW4KTsmB3c86g==} dependencies: debug: 4.3.4(supports-color@9.2.2) @@ -19885,32 +19885,6 @@ packages: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} dev: true - file:packages/miniflare/miniflare-3.20240129.0.tgz(supports-color@9.2.2): - resolution: {integrity: sha512-ZTuddTWQM/MWlXQFuFRDfxuGFHNNErCcHcp1ZnFSiWxAp3d4wcdo+rNWflQOCddD6HKwFebrdcIi74slMWywhA==, tarball: file:packages/miniflare/miniflare-3.20240129.0.tgz} - id: file:packages/miniflare/miniflare-3.20240129.0.tgz - name: miniflare - version: 3.20240129.0 - engines: {node: '>=16.13'} - hasBin: true - dependencies: - '@cspotcode/source-map-support': 0.8.1 - acorn: 8.10.0 - acorn-walk: 8.2.0 - capnp-ts: 0.7.0(patch_hash=l4yimnxyvkiyj6alnps2ec3sii)(supports-color@9.2.2) - exit-hook: 2.2.1 - glob-to-regexp: 0.4.1 - stoppable: 1.1.0 - undici: 5.28.2 - workerd: 1.20240129.0 - ws: 8.14.2 - youch: 3.2.3 - zod: 3.22.3 - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - dev: false - file:vendor/yoga-layout-2.0.0-beta.1.tgz: resolution: {integrity: sha512-cHunx1nKVIoOxUw9pJE/3mu5NCUMRmWRgzrrSPfjXXAMMzkxQGDbzP/r6Iv4tdWR20p08kgKBG7n/dmbf6FG1w==, tarball: file:vendor/yoga-layout-2.0.0-beta.1.tgz} name: yoga-layout From 00eaa3fb8d83891845fcd82b580fe715eeb77b7d Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 20:00:57 +0000 Subject: [PATCH 14/24] [squash] r2 --- packages/wrangler/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 11512276e4b8..2ab74c9beffd 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -63,7 +63,7 @@ "test": "pnpm run assert-git-version && jest", "test:ci": "pnpm run test --coverage", "test:debug": "pnpm run test --silent=false --verbose=true", - "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run", + "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run r2", "test:watch": "pnpm run test --testTimeout=50000 --watch", "type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json" }, From e8bb9b34d31af946e470af4196eb94369ab22f8a Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 20:02:58 +0000 Subject: [PATCH 15/24] [squash] r2 logging --- packages/wrangler/e2e/r2.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/wrangler/e2e/r2.test.ts b/packages/wrangler/e2e/r2.test.ts index ce863b0be307..967bbb4c6ae0 100644 --- a/packages/wrangler/e2e/r2.test.ts +++ b/packages/wrangler/e2e/r2.test.ts @@ -29,7 +29,7 @@ describe("r2", () => { }); it("create bucket", async () => { - const { stdout } = await run`$ ${WRANGLER} r2 bucket create ${bucketName}`; + const { stdout } = await run`$$ ${WRANGLER} r2 bucket create ${bucketName}`; expect(normalize(stdout)).toMatchInlineSnapshot(` "Creating bucket wrangler-smoke-test-bucket. Created bucket wrangler-smoke-test-bucket." @@ -41,7 +41,7 @@ describe("r2", () => { "test-r2.txt": fileContents, }); const { stdout, stderr } = await run` - $ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html + $$ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html `; expect(normalize(stdout)).toMatchInlineSnapshot(` "Creating object \\"testr2\\" in bucket \\"wrangler-smoke-test-bucket\\". @@ -52,7 +52,7 @@ describe("r2", () => { it("download object", async () => { const { stdout, stderr } = await run` - $ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt + $$ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt `; expect(normalize(stdout)).toMatchInlineSnapshot(` "Downloading \\"testr2\\" from \\"wrangler-smoke-test-bucket\\". @@ -64,7 +64,7 @@ describe("r2", () => { }); it("delete object", async () => { const { stdout, stderr } = - await run`$ ${WRANGLER} r2 object delete ${`${bucketName}/testr2`}`; + await run`$$ ${WRANGLER} r2 object delete ${`${bucketName}/testr2`}`; expect(normalize(stdout)).toMatchInlineSnapshot(` "Deleting object \\"testr2\\" from bucket \\"wrangler-smoke-test-bucket\\". Delete complete." @@ -75,7 +75,7 @@ describe("r2", () => { it("check object deleted", async () => { const { stdout, stderr } = await run` exits(1) { - $ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt + $$ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt } `; expect(normalize(stdout)).toMatchInlineSnapshot(` @@ -90,7 +90,7 @@ describe("r2", () => { it("delete bucket", async () => { const { stdout, stderr } = - await run`$ ${WRANGLER} r2 bucket delete ${bucketName}`; + await run`$$ ${WRANGLER} r2 bucket delete ${bucketName}`; expect(normalize(stdout)).toMatchInlineSnapshot(` "Deleting bucket wrangler-smoke-test-bucket. Deleted bucket wrangler-smoke-test-bucket." @@ -104,7 +104,7 @@ describe("r2", () => { }); const { stdout, stderr } = await run` exits(1) { - $ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html + $$ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html } `; expect(normalize(stdout)).toMatchInlineSnapshot(` From 92c88f680f2180ac31975f4b340416b5134d7fac Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 20:20:20 +0000 Subject: [PATCH 16/24] ls --- .github/workflows/e2e.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index f0cb5887897b..8d9c63300642 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -75,6 +75,8 @@ jobs: - name: Run tests run: | + ls $HOME + ls $HOME/wrangler-*.tgz pnpm add ${{ steps.find-wrangler.outputs.dir}} --global pnpm run --filter wrangler test:e2e env: From 1164b08cc6be739bbfb72cc54e0bd1193bbf46d7 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 20:38:08 +0000 Subject: [PATCH 17/24] windows --- .github/workflows/e2e.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 8d9c63300642..55d80f421a42 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -73,10 +73,9 @@ jobs: id: "find-wrangler" run: echo "dir=$(ls $HOME/wrangler-*.tgz)" >> $GITHUB_OUTPUT; - - name: Run tests + - name: Run tests (unix) + if: matrix.os == 'macos-13' || matrix.os == 'ubuntu-22.04' run: | - ls $HOME - ls $HOME/wrangler-*.tgz pnpm add ${{ steps.find-wrangler.outputs.dir}} --global pnpm run --filter wrangler test:e2e env: @@ -86,6 +85,16 @@ jobs: NODE_OPTIONS: "--max_old_space_size=8192" WRANGLER_LOG_PATH: ${{ runner.temp }}/wrangler-debug-logs/ + - name: Run tests (windows) + if: matrix.os == 'windows-2022' + run: pnpm run --filter wrangler test:e2e + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }} + WRANGLER: pnpm --silent --package ${{ steps.find-wrangler.outputs.dir}} dlx wrangler + NODE_OPTIONS: "--max_old_space_size=8192" + WRANGLER_LOG_PATH: ${{ runner.temp }}/wrangler-debug-logs/ + - name: Upload debug logs if: always() uses: actions/upload-artifact@v3 From 81b9762d48fb448e8ffa40f05c28c30e225bd88b Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 20:51:13 +0000 Subject: [PATCH 18/24] all tests --- packages/wrangler/e2e/r2.test.ts | 14 +++++++------- packages/wrangler/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/wrangler/e2e/r2.test.ts b/packages/wrangler/e2e/r2.test.ts index 967bbb4c6ae0..ce863b0be307 100644 --- a/packages/wrangler/e2e/r2.test.ts +++ b/packages/wrangler/e2e/r2.test.ts @@ -29,7 +29,7 @@ describe("r2", () => { }); it("create bucket", async () => { - const { stdout } = await run`$$ ${WRANGLER} r2 bucket create ${bucketName}`; + const { stdout } = await run`$ ${WRANGLER} r2 bucket create ${bucketName}`; expect(normalize(stdout)).toMatchInlineSnapshot(` "Creating bucket wrangler-smoke-test-bucket. Created bucket wrangler-smoke-test-bucket." @@ -41,7 +41,7 @@ describe("r2", () => { "test-r2.txt": fileContents, }); const { stdout, stderr } = await run` - $$ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html + $ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html `; expect(normalize(stdout)).toMatchInlineSnapshot(` "Creating object \\"testr2\\" in bucket \\"wrangler-smoke-test-bucket\\". @@ -52,7 +52,7 @@ describe("r2", () => { it("download object", async () => { const { stdout, stderr } = await run` - $$ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt + $ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt `; expect(normalize(stdout)).toMatchInlineSnapshot(` "Downloading \\"testr2\\" from \\"wrangler-smoke-test-bucket\\". @@ -64,7 +64,7 @@ describe("r2", () => { }); it("delete object", async () => { const { stdout, stderr } = - await run`$$ ${WRANGLER} r2 object delete ${`${bucketName}/testr2`}`; + await run`$ ${WRANGLER} r2 object delete ${`${bucketName}/testr2`}`; expect(normalize(stdout)).toMatchInlineSnapshot(` "Deleting object \\"testr2\\" from bucket \\"wrangler-smoke-test-bucket\\". Delete complete." @@ -75,7 +75,7 @@ describe("r2", () => { it("check object deleted", async () => { const { stdout, stderr } = await run` exits(1) { - $$ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt + $ ${WRANGLER} r2 object get ${`${bucketName}/testr2`} --file test-r2o.txt } `; expect(normalize(stdout)).toMatchInlineSnapshot(` @@ -90,7 +90,7 @@ describe("r2", () => { it("delete bucket", async () => { const { stdout, stderr } = - await run`$$ ${WRANGLER} r2 bucket delete ${bucketName}`; + await run`$ ${WRANGLER} r2 bucket delete ${bucketName}`; expect(normalize(stdout)).toMatchInlineSnapshot(` "Deleting bucket wrangler-smoke-test-bucket. Deleted bucket wrangler-smoke-test-bucket." @@ -104,7 +104,7 @@ describe("r2", () => { }); const { stdout, stderr } = await run` exits(1) { - $$ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html + $ ${WRANGLER} r2 object put ${`${bucketName}/testr2`} --file test-r2.txt --content-type text/html } `; expect(normalize(stdout)).toMatchInlineSnapshot(` diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 2ab74c9beffd..11512276e4b8 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -63,7 +63,7 @@ "test": "pnpm run assert-git-version && jest", "test:ci": "pnpm run test --coverage", "test:debug": "pnpm run test --silent=false --verbose=true", - "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run r2", + "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run", "test:watch": "pnpm run test --testTimeout=50000 --watch", "type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json" }, From d2390dcc0ee8db4ed248f35e6f346975b253f3ff Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 5 Feb 2024 23:56:14 +0000 Subject: [PATCH 19/24] dev --- packages/wrangler/e2e/dev.test.ts | 8 +++++--- packages/wrangler/package.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index 8a725b1eb410..66cb94ac1618 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -87,10 +87,10 @@ async function runDevSession( const promise = new Promise((resolve) => (promiseResolve = resolve)); const bg = await shellac.env(process.env).bg` await ${() => promise} - + in ${workerPath} { exits { - $ ${WRANGLER} dev ${flags} + $$ ${WRANGLER} dev ${flags} } } `; @@ -545,7 +545,7 @@ describe("writes debug logs to hidden file", () => { expect(filepath).toBeUndefined(); }); - it("rewrites address-in-use error logs", async () => { + it.only("rewrites address-in-use error logs", async () => { // 1. start worker A on a (any) port await a.runDevSession("", async (sessionA) => { const normalize = (text: string) => @@ -561,6 +561,8 @@ describe("writes debug logs to hidden file", () => { // 5. wait a period of time for workerd to complain about the port being in use await setTimeout(1000); + console.log(normalize(sessionB.stderr)); + // ensure the workerd error message IS NOT present expect(normalize(sessionB.stderr)).not.toContain( "Address already in use; toString() = " diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 11512276e4b8..5dc0dbb55b29 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -63,7 +63,7 @@ "test": "pnpm run assert-git-version && jest", "test:ci": "pnpm run test --coverage", "test:debug": "pnpm run test --silent=false --verbose=true", - "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run", + "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run dev", "test:watch": "pnpm run test --testTimeout=50000 --watch", "type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json" }, From 63ab5e5daec8523454464ac3bb058c85a0236e3b Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Tue, 6 Feb 2024 00:02:39 +0000 Subject: [PATCH 20/24] only --- packages/wrangler/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 5dc0dbb55b29..d0072d8eff21 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -63,7 +63,7 @@ "test": "pnpm run assert-git-version && jest", "test:ci": "pnpm run test --coverage", "test:debug": "pnpm run test --silent=false --verbose=true", - "test:e2e": "vitest --test-timeout 60000 --single-thread --dir ./e2e --retry 2 run dev", + "test:e2e": "vitest --test-timeout 60000 --allowOnly --single-thread --dir ./e2e --retry 2 run dev", "test:watch": "pnpm run test --testTimeout=50000 --watch", "type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json" }, From 0a227598b4b2dba9496284588e63342b74e81cb7 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Tue, 6 Feb 2024 00:25:42 +0000 Subject: [PATCH 21/24] devalue --- packages/miniflare/src/workers/core/devalue.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/miniflare/src/workers/core/devalue.ts b/packages/miniflare/src/workers/core/devalue.ts index 2b7306a704b6..cd6c35ffcf72 100644 --- a/packages/miniflare/src/workers/core/devalue.ts +++ b/packages/miniflare/src/workers/core/devalue.ts @@ -309,5 +309,11 @@ export function parseWithReadableStreams( }, ...revivers, }; - return parse(stringified.value, streamRevivers); + try{ + + + return parse(stringified.value, streamRevivers);}catch(e){ + console.log(stringified.value) + console.log(e) + } } From cc604b08cbcf7e5a9db53ec962473b799f6715f4 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Tue, 6 Feb 2024 00:36:35 +0000 Subject: [PATCH 22/24] log --- packages/miniflare/src/plugins/core/proxy/client.ts | 2 ++ packages/miniflare/src/workers/core/devalue.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/miniflare/src/plugins/core/proxy/client.ts b/packages/miniflare/src/plugins/core/proxy/client.ts index 670d0a5b14b3..905fa94bcdd6 100644 --- a/packages/miniflare/src/plugins/core/proxy/client.ts +++ b/packages/miniflare/src/plugins/core/proxy/client.ts @@ -332,6 +332,8 @@ class ProxyStubHandler implements ProxyHandler { { value: stringifiedResult, unbufferedStream }, this.revivers ); + + console.log("parseWithReadableStreams", result) // We get an empty stack trace if we thread the caller through here, // specifying `this.#parseAsyncResponse` is good enough though, we just // get an extra `processTicksAndRejections` entry diff --git a/packages/miniflare/src/workers/core/devalue.ts b/packages/miniflare/src/workers/core/devalue.ts index cd6c35ffcf72..96898b0c6c6a 100644 --- a/packages/miniflare/src/workers/core/devalue.ts +++ b/packages/miniflare/src/workers/core/devalue.ts @@ -312,8 +312,11 @@ export function parseWithReadableStreams( try{ - return parse(stringified.value, streamRevivers);}catch(e){ - console.log(stringified.value) - console.log(e) + return parse(stringified.value, streamRevivers); +}catch(e){ + console.log("err parseWithReadableStreams") + console.log(stringified.value) + console.log(stringified) + console.log(e) } } From ce4a7f8bb380988ac3ae89577458a6d2272e7874 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Tue, 6 Feb 2024 00:49:35 +0000 Subject: [PATCH 23/24] logging --- packages/miniflare/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/miniflare/src/index.ts b/packages/miniflare/src/index.ts index e4caa9505c31..f3d8078e0103 100644 --- a/packages/miniflare/src/index.ts +++ b/packages/miniflare/src/index.ts @@ -1528,9 +1528,13 @@ export class Miniflare { const workerOpts = this.#workerOpts[workerIndex]; workerName = workerOpts.core.name ?? ""; + console.log({workerName,workerOpts }) + // Get a `Fetcher` to that worker (NOTE: the `ProxyServer` Durable Object // shares its `env` with Miniflare's entry worker, so has access to routes) const bindingName = CoreBindings.SERVICE_USER_ROUTE_PREFIX + workerName; + console.log({bindingName}) + const fetcher = proxyClient.env[bindingName]; if (fetcher === undefined) { // `#findAndAssertWorkerIndex()` will throw if a "worker" doesn't exist From 98e1bd56dbd8cf282260628cced2a9008a110ed1 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Tue, 6 Feb 2024 18:32:49 +0000 Subject: [PATCH 24/24] Cleanup --- packages/miniflare/src/index.ts | 3 --- packages/miniflare/src/plugins/core/proxy/client.ts | 1 - packages/miniflare/src/workers/core/devalue.ts | 8 -------- packages/wrangler/e2e/dev.test.ts | 6 ++---- packages/wrangler/package.json | 2 +- 5 files changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/miniflare/src/index.ts b/packages/miniflare/src/index.ts index f3d8078e0103..2c4c1065a6bc 100644 --- a/packages/miniflare/src/index.ts +++ b/packages/miniflare/src/index.ts @@ -1528,12 +1528,9 @@ export class Miniflare { const workerOpts = this.#workerOpts[workerIndex]; workerName = workerOpts.core.name ?? ""; - console.log({workerName,workerOpts }) - // Get a `Fetcher` to that worker (NOTE: the `ProxyServer` Durable Object // shares its `env` with Miniflare's entry worker, so has access to routes) const bindingName = CoreBindings.SERVICE_USER_ROUTE_PREFIX + workerName; - console.log({bindingName}) const fetcher = proxyClient.env[bindingName]; if (fetcher === undefined) { diff --git a/packages/miniflare/src/plugins/core/proxy/client.ts b/packages/miniflare/src/plugins/core/proxy/client.ts index 905fa94bcdd6..138285a2a5af 100644 --- a/packages/miniflare/src/plugins/core/proxy/client.ts +++ b/packages/miniflare/src/plugins/core/proxy/client.ts @@ -333,7 +333,6 @@ class ProxyStubHandler implements ProxyHandler { this.revivers ); - console.log("parseWithReadableStreams", result) // We get an empty stack trace if we thread the caller through here, // specifying `this.#parseAsyncResponse` is good enough though, we just // get an extra `processTicksAndRejections` entry diff --git a/packages/miniflare/src/workers/core/devalue.ts b/packages/miniflare/src/workers/core/devalue.ts index 96898b0c6c6a..bf6f7569447b 100644 --- a/packages/miniflare/src/workers/core/devalue.ts +++ b/packages/miniflare/src/workers/core/devalue.ts @@ -309,14 +309,6 @@ export function parseWithReadableStreams( }, ...revivers, }; - try{ - return parse(stringified.value, streamRevivers); -}catch(e){ - console.log("err parseWithReadableStreams") - console.log(stringified.value) - console.log(stringified) - console.log(e) - } } diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index 66cb94ac1618..faeb94c0e6a2 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -90,7 +90,7 @@ async function runDevSession( in ${workerPath} { exits { - $$ ${WRANGLER} dev ${flags} + $ ${WRANGLER} dev ${flags} } } `; @@ -545,7 +545,7 @@ describe("writes debug logs to hidden file", () => { expect(filepath).toBeUndefined(); }); - it.only("rewrites address-in-use error logs", async () => { + it.skip("rewrites address-in-use error logs", async () => { // 1. start worker A on a (any) port await a.runDevSession("", async (sessionA) => { const normalize = (text: string) => @@ -561,8 +561,6 @@ describe("writes debug logs to hidden file", () => { // 5. wait a period of time for workerd to complain about the port being in use await setTimeout(1000); - console.log(normalize(sessionB.stderr)); - // ensure the workerd error message IS NOT present expect(normalize(sessionB.stderr)).not.toContain( "Address already in use; toString() = " diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index d0072d8eff21..61da11023647 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -63,7 +63,7 @@ "test": "pnpm run assert-git-version && jest", "test:ci": "pnpm run test --coverage", "test:debug": "pnpm run test --silent=false --verbose=true", - "test:e2e": "vitest --test-timeout 60000 --allowOnly --single-thread --dir ./e2e --retry 2 run dev", + "test:e2e": "vitest --test-timeout 240000 --single-thread --dir ./e2e --retry 2 run", "test:watch": "pnpm run test --testTimeout=50000 --watch", "type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json" },