-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(cloudflare): make sandboxed plugins a paid-plan opt-in #2351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f46425
fix(cloudflare): derive sandboxed plugins from Worker Loader
MattieTK 3be234e
Merge remote-tracking branch 'origin/main' into feat/gate-dynamic-plu…
ascorbic fca61fd
Merge remote-tracking branch 'origin/main' into feat/gate-dynamic-plu…
ascorbic 5e8dbb2
fix(cloudflare): respect named Wrangler sandbox environments
ascorbic 046e9e0
test: keep sandbox opt-in coverage accurate
ascorbic 79eacce
Merge remote-tracking branch 'origin/main' into feat/gate-dynamic-plu…
ascorbic 8c31ec2
Merge remote-tracking branch 'origin/main' into feat/gate-dynamic-plu…
ascorbic 7418fcd
test(e2e): count rendered publication label lines
ascorbic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@emdash-cms/cloudflare": patch | ||
| "create-emdash": patch | ||
| "emdash": patch | ||
| --- | ||
|
|
||
| New Cloudflare projects leave the paid-plan Worker Loader binding disabled so they can deploy on the Workers free plan. Enable sandboxed plugins in the scaffold prompt or with `--sandboxed-plugins`. | ||
|
|
||
| The Cloudflare `sandbox()` helper now selects the runner from the `LOADER` binding in `wrangler.jsonc`, including the named environment selected with `CLOUDFLARE_ENV`. Without it, config-based sandboxed plugins do not load and marketplace or registry installs return `SANDBOX_NOT_AVAILABLE`, while browsing remains available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const { readConfig } = vi.hoisted(() => ({ | ||
| readConfig: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("wrangler", () => ({ | ||
| unstable_readConfig: readConfig, | ||
| })); | ||
|
|
||
| import { sandbox } from "../src/index.js"; | ||
|
|
||
| describe("sandbox", () => { | ||
| beforeEach(() => { | ||
| readConfig.mockReset(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| it("returns the Cloudflare sandbox runner when the LOADER binding is configured", () => { | ||
| readConfig.mockReturnValue({ worker_loaders: [{ binding: "LOADER" }] }); | ||
|
|
||
| expect(sandbox()).toBe("@emdash-cms/cloudflare/sandbox"); | ||
| expect(readConfig).toHaveBeenCalledWith({}, { hideWarnings: true }); | ||
| }); | ||
|
|
||
| it("disables sandboxed plugins when Worker Loader is not configured", () => { | ||
| readConfig.mockReturnValue({ worker_loaders: undefined }); | ||
| const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
|
||
| expect(sandbox()).toBeUndefined(); | ||
| expect(warn).toHaveBeenCalledWith( | ||
| "[emdash] Sandboxed plugins are disabled because wrangler.jsonc has no LOADER Worker Loader binding. Worker Loader requires a Workers paid plan.", | ||
| ); | ||
|
|
||
| warn.mockRestore(); | ||
| }); | ||
|
|
||
| it("requires the binding name used by the runtime", () => { | ||
| readConfig.mockReturnValue({ worker_loaders: [{ binding: "OTHER_LOADER" }] }); | ||
| const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
|
||
| expect(sandbox()).toBeUndefined(); | ||
|
|
||
| warn.mockRestore(); | ||
| }); | ||
|
|
||
| it("reads the named environment selected by the Cloudflare Vite plugin", () => { | ||
| vi.stubEnv("CLOUDFLARE_ENV", "production"); | ||
| readConfig.mockReturnValue({ worker_loaders: [{ binding: "LOADER" }] }); | ||
|
|
||
| expect(sandbox()).toBe("@emdash-cms/cloudflare/sandbox"); | ||
| expect(readConfig).toHaveBeenCalledWith({ env: "production" }, { hideWarnings: true }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/core/tests/unit/astro/integration/marketplace-sandbox.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import emdash from "../../../../src/astro/integration/index.js"; | ||
|
|
||
| describe("marketplace without a sandbox runner", () => { | ||
| it("allows the marketplace to remain available when sandboxed plugins are disabled", () => { | ||
| expect(() => | ||
| emdash({ | ||
| marketplace: "https://marketplace.emdashcms.com", | ||
| sandboxRunner: undefined, | ||
| }), | ||
| ).not.toThrow(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.