Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cleanup-workers-share…
Browse files Browse the repository at this point in the history
…d-types
  • Loading branch information
penalosa committed Nov 28, 2024
2 parents ba2b58e + 22a4055 commit 974e435
Show file tree
Hide file tree
Showing 259 changed files with 8,048 additions and 5,129 deletions.
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"bumpVersionsWithWorkspaceProtocolOnly": true,
"ignore": [],
"privatePackages": {
"tag": true,
Expand Down
5 changes: 5 additions & 0 deletions .changeset/cuddly-chicken-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Print wrangler.toml snippet when creating new Hyperdrive Config
5 changes: 0 additions & 5 deletions .changeset/curly-dryers-admire.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/curly-rice-travel.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/four-zebras-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Make debug log for `.env` not found less scary
5 changes: 5 additions & 0 deletions .changeset/gold-pandas-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Improve Wrangler's multiworker support to allow running multiple workers at once with one command. To try it out, pass multiple `-c` flags to Wrangler: i.e. `wrangler dev -c wrangler.toml -c ../other-worker/wrangler.toml`. The first config will be treated as the _primary_ worker and will be exposed over HTTP as usual (localhost:8787) while the rest will be treated as _secondary_ and will only be accessible via a service binding from the primary worker. Notably, these workers all run in the same runtime instance, which should improve reliability of multiworker dev and fix some bugs (RPC to cross worker Durable Objects, for instance).
5 changes: 5 additions & 0 deletions .changeset/hip-penguins-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/vitest-pool-workers": patch
---

Add support for AbortSignal to fetch-mock
5 changes: 0 additions & 5 deletions .changeset/mighty-waves-deny.md

This file was deleted.

7 changes: 7 additions & 0 deletions .changeset/purple-coats-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

Added `x-provision` global option

This experimental flag currently has no effect. More details will be shared as we roll out its functionality.
5 changes: 5 additions & 0 deletions .changeset/seven-eels-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Turn on `--x-registry` for Pages by default
5 changes: 5 additions & 0 deletions .changeset/silly-news-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: allow running `wrangler types` when expected entrypoint doesn't exist
7 changes: 7 additions & 0 deletions .changeset/six-coats-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": minor
---

feat: add `serve_directly` option to Workers with Assets

Users can now specify whether their assets are served directly against HTTP requests or whether these requests always go to the Worker, which can then respond with asset retrieved by its assets binding.
5 changes: 0 additions & 5 deletions .changeset/sixty-news-relax.md

This file was deleted.

1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _Describe your change..._
---

<!--
Please don't delete the checkboxes <3
The following selections do not need to be completed if this PR only contains changes to .md files
-->

Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/run-ci-for-external-forks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Run CI on behalf of External Forks
on:
workflow_dispatch:
inputs:
pr-number:
description: "The PR number to run CI on behalf of"
required: true
reviewed:
description: "Confirm that the PR has been reviewed for use/leakage of secrets"
type: boolean
required: true
jobs:
create-draft-pr:
name: Create Draft PR
if: ${{ inputs.reviewed == true }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check user for team affiliation
uses: tspascoal/get-user-teams-membership@v2
id: teamAffiliation
with:
GITHUB_TOKEN: ${{ secrets.READ_ONLY_ORG_GITHUB_TOKEN }}
username: ${{ github.actor }}
team: wrangler

- name: Stop workflow if user is not a team member
if: ${{ steps.teamAffiliation.outputs.isTeamMember == false }}
run: |
echo "You have must be on the "wrangler" team to trigger this job."
exit 1
- name: "Checkout PR"
run: gh pr checkout ${{ inputs.pr-number }} -b run-ci-on-behalf-of-${{ inputs.pr-number }} -f
env:
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}

- name: Push Branch
run: git push origin HEAD --force

- name: "Create Draft PR"
run: |
gh pr create --head run-ci-on-behalf-of-${{ inputs.pr-number }} --draft --label "e2e" --title "Run CI on behalf of #${{ inputs.pr-number }}" --body "This PR is created to run CI on behalf of \#${{ inputs.pr-number }}. It can be closed after the CI run is complete."
env:
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/write-prerelease-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: "Download runtime versions"
# Regular `actions/download-artifact` doesn't support downloading
# artifacts from another workflow
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
name: runtime-versions.md
Expand All @@ -54,7 +54,7 @@ jobs:
} >> "$GITHUB_ENV"
- name: "Download pre-release report"
uses: dawidd6/action-download-artifact@v2
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
name: prerelease-report.md
Expand Down
7 changes: 7 additions & 0 deletions fixtures/interactive-dev-tests/src/worker-a.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
async fetch(req, env) {
return new Response(
"hello from a & " + (await env.WORKER.fetch(req).then((r) => r.text()))
);
},
};
5 changes: 5 additions & 0 deletions fixtures/interactive-dev-tests/src/worker-b.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
async fetch() {
return new Response("hello from b");
},
};
28 changes: 28 additions & 0 deletions fixtures/interactive-dev-tests/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,34 @@ describe.each(devScripts)("wrangler $args", ({ args, expectedBody }) => {
});
});

it.each(exitKeys)("multiworker cleanly exits with $name", async ({ key }) => {
const beginProcesses = getStartedWorkerdProcesses();

const wrangler = await startWranglerDev([
"dev",
"-c",
"wrangler.a.toml",
"-c",
"wrangler.b.toml",
]);
const duringProcesses = getStartedWorkerdProcesses();

// Check dev server working correctly
const res = await fetch(wrangler.url);
expect((await res.text()).trim()).toBe("hello from a & hello from b");

// Check key cleanly exits dev server
wrangler.pty.write(key);
expect(await wrangler.exitPromise).toBe(0);
const endProcesses = getStartedWorkerdProcesses();

// Check no hanging workerd processes
if (process.platform !== "win32" || windowsProcessCwdSupported) {
expect(beginProcesses.length).toBe(endProcesses.length);
expect(duringProcesses.length).toBeGreaterThan(beginProcesses.length);
}
});

it.runIf(RUN_IF && nodePtySupported)(
"hotkeys should be unregistered when the initial build fails",
async () => {
Expand Down
7 changes: 7 additions & 0 deletions fixtures/interactive-dev-tests/wrangler.a.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "a"
main = "src/worker-a.mjs"
compatibility_date = "2023-12-01"

[[services]]
binding = "WORKER"
service = "b"
3 changes: 3 additions & 0 deletions fixtures/interactive-dev-tests/wrangler.b.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "b"
main = "src/worker-b.mjs"
compatibility_date = "2023-12-01"
100 changes: 97 additions & 3 deletions fixtures/vitest-pool-workers-examples/misc/test/fetch-mock.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { fetchMock } from "cloudflare:test";
import { afterEach, beforeAll, expect, it } from "vitest";
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
vi,
} from "vitest";
import type { MockInstance } from "vitest";

beforeAll(() => fetchMock.activate());
afterEach(() => fetchMock.assertNoPendingInterceptors());
beforeEach(() => fetchMock.activate());
afterEach(() => {
fetchMock.assertNoPendingInterceptors();
fetchMock.deactivate();
});

it("falls through to global fetch() if unmatched", async () => {
fetchMock
Expand All @@ -18,3 +31,84 @@ it("falls through to global fetch() if unmatched", async () => {
expect(response.url).toEqual("https://example.com/bad");
expect(await response.text()).toBe("fallthrough:GET https://example.com/bad");
});

describe("AbortSignal", () => {
let abortSignalTimeoutMock: MockInstance;

beforeAll(() => {
// Fake Timers does not mock AbortSignal.timeout
abortSignalTimeoutMock = vi
.spyOn(AbortSignal, "timeout")
.mockImplementation((ms: number) => {
const controller = new AbortController();
setTimeout(() => {
controller.abort();
}, ms);
return controller.signal;
});
});

afterAll(() => abortSignalTimeoutMock.mockRestore());

beforeEach(() => vi.useFakeTimers());

afterEach(() => vi.useRealTimers());

it("aborts if an AbortSignal timeout is exceeded", async () => {
fetchMock
.get("https://example.com")
.intercept({ path: "/" })
.reply(200, async () => {
await new Promise((resolve) => setTimeout(resolve, 5000));
return "Delayed response";
});

const fetchPromise = fetch("https://example.com", {
signal: AbortSignal.timeout(2000),
});

vi.advanceTimersByTime(10_000);
await expect(fetchPromise).rejects.toThrowErrorMatchingInlineSnapshot(
`[AbortError: The operation was aborted]`
);
});

it("does not abort if an AbortSignal timeout is not exceeded", async () => {
fetchMock
.get("https://example.com")
.intercept({ path: "/" })
.reply(200, async () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return "Delayed response";
});

const fetchPromise = fetch("https://example.com", {
signal: AbortSignal.timeout(2000),
});

vi.advanceTimersByTime(1500);
const response = await fetchPromise;
expect(response.status).toStrictEqual(200);
expect(await response.text()).toMatchInlineSnapshot(`"Delayed response"`);
});

it("aborts if an AbortSignal is already aborted", async () => {
const controller = new AbortController();
controller.abort();

fetchMock
.get("https://example.com")
.intercept({ path: "/" })
.reply(200, async () => {
return "Delayed response";
});

const fetchPromise = fetch("https://example.com", {
signal: controller.signal,
});

await expect(fetchPromise).rejects.toThrowErrorMatchingInlineSnapshot(
`[AbortError: The operation was aborted]`
);
});
});
17 changes: 17 additions & 0 deletions fixtures/workflow-multiple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "my-workflow-multiple",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev",
"test:ci": "vitest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241106.0",
"undici": "catalog:default",
"wrangler": "workspace:*"
},
"volta": {
"extends": "../../package.json"
}
}
Loading

0 comments on commit 974e435

Please sign in to comment.