Skip to content

Commit 2f57345

Browse files
authored
Remove remote bindings flag (#10741)
* Remove remote bindings flag * Fix tests * fix tests * fix tests * fix getPlatformProxy() tests * no more deletion * Remove obsolete '--x-remote-bindings' flag Updated the changeset to reflect the removal of the obsolete remote bindings flag. * finalise removal * Address comments * fix rebase * Throw 'remoteProxyConnectionString is missing' errors from the actual bindings API at runtime rather than at startup. This means that empty stubs of bindings like AI & Vectorize are available in Vitest to be mocked with vi.spyOn * fix lint
1 parent 1a8088a commit 2f57345

File tree

42 files changed

+352
-852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+352
-852
lines changed

.changeset/wicked-chairs-clean.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": minor
3+
"@cloudflare/vite-plugin": minor
4+
"@cloudflare/vitest-pool-workers": minor
5+
---
6+
7+
Remove obsolete `--x-remote-bindings` flag

fixtures/get-platform-proxy-remote-bindings/tests/index.test.ts

Lines changed: 35 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,51 @@ const execOptions = {
1414
encoding: "utf8",
1515
env: { ...process.env, ...auth },
1616
} as const;
17-
const remoteWorkerName = `tmp-e2e-worker-test-remote-bindings-${randomUUID().split("-")[0]}`;
18-
const remoteStagingWorkerName = `tmp-e2e-staging-worker-test-remote-bindings-${randomUUID().split("-")[0]}`;
17+
const remoteWorkerName = `preserve-e2e-get-platform-proxy-remote`;
18+
const remoteStagingWorkerName = `preserve-e2e-get-platform-proxy-remote-staging`;
1919
const remoteKvName = `tmp-e2e-kv${Date.now()}-test-remote-bindings-${randomUUID().split("-")[0]}`;
2020

2121
if (auth) {
2222
describe("getPlatformProxy - remote bindings", { timeout: 50_000 }, () => {
2323
let remoteKvId: string;
2424

2525
beforeAll(async () => {
26-
const deployOut = execSync(
27-
`pnpm wrangler deploy remote-worker.js --name ${remoteWorkerName} --compatibility-date 2025-06-19`,
28-
execOptions
29-
);
30-
const deployedUrl = deployOut.match(
31-
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
32-
)?.groups?.url;
33-
assert(deployedUrl, "Failed to find deployed worker URL");
26+
const deployedUrl =
27+
"https://preserve-e2e-get-platform-proxy-remote.devprod-testing7928.workers.dev/";
3428

35-
const stagingDeployOut = execSync(
36-
`pnpm wrangler deploy remote-worker.staging.js --name ${remoteStagingWorkerName} --compatibility-date 2025-06-19`,
37-
execOptions
38-
);
39-
const stagingDeployedUrl = stagingDeployOut.match(
40-
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
41-
)?.groups?.url;
42-
assert(stagingDeployedUrl, "Failed to find deployed staging worker URL");
43-
44-
// Wait for the deployed workers to be available
45-
await Promise.all([
46-
vi.waitFor(
29+
try {
30+
assert((await fetch(deployedUrl)).status !== 404);
31+
} catch (e) {
32+
execSync(
33+
`pnpm wrangler deploy remote-worker.js --name ${remoteWorkerName} --compatibility-date 2025-06-19`,
34+
execOptions
35+
);
36+
await vi.waitFor(
4737
async () => {
4838
const response = await fetch(deployedUrl);
4939
expect(response.status).toBe(200);
5040
},
5141
{ timeout: 5000, interval: 500 }
52-
),
53-
vi.waitFor(
42+
);
43+
}
44+
45+
const stagingDeployedUrl =
46+
"https://preserve-e2e-get-platform-proxy-remote-staging.devprod-testing7928.workers.dev/";
47+
try {
48+
assert((await fetch(stagingDeployedUrl)).status !== 404);
49+
} catch {
50+
execSync(
51+
`pnpm wrangler deploy remote-worker.staging.js --name ${remoteStagingWorkerName} --compatibility-date 2025-06-19`,
52+
execOptions
53+
);
54+
await vi.waitFor(
5455
async () => {
5556
const response = await fetch(stagingDeployedUrl);
5657
expect(response.status).toBe(200);
5758
},
5859
{ timeout: 5000, interval: 500 }
59-
),
60-
]);
60+
);
61+
}
6162

6263
const kvAddOut = execSync(
6364
`pnpm wrangler kv namespace create ${remoteKvName}`,
@@ -79,31 +80,21 @@ if (auth) {
7980
}, 35_000);
8081

8182
afterAll(() => {
82-
try {
83-
execSync(
84-
`pnpm wrangler delete --name ${remoteWorkerName}`,
85-
execOptions
86-
);
87-
} catch {}
88-
try {
89-
execSync(
90-
`pnpm wrangler delete --name ${remoteStagingWorkerName}`,
91-
execOptions
92-
);
93-
} catch {}
9483
try {
9584
execSync(
9685
`pnpm wrangler kv namespace delete --namespace-id=${remoteKvId}`,
9786
execOptions
9887
);
9988
} catch {}
10089

101-
rmSync("./.tmp", {
102-
recursive: true,
103-
force: true,
104-
maxRetries: 10,
105-
retryDelay: 100,
106-
});
90+
try {
91+
rmSync("./.tmp", {
92+
recursive: true,
93+
force: true,
94+
maxRetries: 10,
95+
retryDelay: 100,
96+
});
97+
} catch {}
10798
}, 35_000);
10899

109100
describe("normal usage", () => {
@@ -202,32 +193,6 @@ if (auth) {
202193

203194
await dispose();
204195
});
205-
206-
test("getPlatformProxy does not work with remote bindings if the experimental remoteBindings flag is not turned on", async () => {
207-
const { env, dispose } = await getPlatformProxy<{
208-
MY_WORKER: Fetcher;
209-
MY_KV: KVNamespace;
210-
}>({
211-
configPath: "./.tmp/normal-usage/wrangler.json",
212-
experimental: {
213-
remoteBindings: false,
214-
},
215-
});
216-
217-
const response = await fetchFromWorker(
218-
env.MY_WORKER,
219-
"Service Unavailable"
220-
);
221-
const workerText = await response?.text();
222-
expect(workerText).toEqual(
223-
`Couldn't find a local dev session for the "default" entrypoint of service "${remoteWorkerName}" to proxy to`
224-
);
225-
226-
const kvValue = await env.MY_KV.get("test-key");
227-
expect(kvValue).toEqual(null);
228-
229-
await dispose();
230-
});
231196
});
232197

233198
describe("account id taken from the wrangler config", () => {

fixtures/vitest-pool-workers-examples/ai-vectorize/test/index.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("Tests that do hit the AI binding", () => {
1919
const ctx = createExecutionContext();
2020

2121
// mock the AI run function by directly modifying `env`
22-
env.AI.run = vi.fn().mockResolvedValue({
22+
vi.spyOn(env.AI, "run").mockResolvedValue({
2323
shape: [1, 2],
2424
data: [[0, 0]],
2525
});
@@ -37,16 +37,21 @@ describe("Tests that do hit the AI binding", () => {
3737

3838
// mock the vectorize upsert function by directly modifying `env`
3939
const mockVectorizeStore: VectorizeVector[] = [];
40-
env.VECTORIZE.upsert = vi.fn().mockImplementation(async (vectors) => {
40+
41+
vi.spyOn(env.VECTORIZE, "upsert").mockImplementation(async (vectors) => {
4142
mockVectorizeStore.push(...vectors);
42-
return { mutationId: "123" };
43+
return {
44+
mutationId: "123",
45+
count: vectors.length,
46+
ids: vectors.map((v) => v.id),
47+
};
4348
});
4449

4550
const response = await worker.fetch(request, env, ctx);
4651

4752
await waitOnExecutionContext(ctx);
4853
expect(await response.text()).toMatchInlineSnapshot(
49-
`"{"mutationId":"123"}"`
54+
`"{"mutationId":"123","count":2,"ids":["123","456"]}"`
5055
);
5156
expect(mockVectorizeStore.map((v) => v.id)).toMatchInlineSnapshot(`
5257
[

packages/miniflare/src/plugins/ai/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from "node:assert";
21
import { z } from "zod";
32
import {
43
getUserBindingServiceName,
@@ -10,7 +9,9 @@ import {
109

1110
const AISchema = z.object({
1211
binding: z.string(),
13-
remoteProxyConnectionString: z.custom<RemoteProxyConnectionString>(),
12+
remoteProxyConnectionString: z
13+
.custom<RemoteProxyConnectionString>()
14+
.optional(),
1415
});
1516

1617
export const AIOptionsSchema = z.object({
@@ -26,11 +27,6 @@ export const AI_PLUGIN: Plugin<typeof AIOptionsSchema> = {
2627
return [];
2728
}
2829

29-
assert(
30-
options.ai.remoteProxyConnectionString,
31-
"Workers AI only supports running remotely"
32-
);
33-
3430
return [
3531
{
3632
name: options.ai.binding,

packages/miniflare/src/plugins/dispatch-namespace/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from "node:assert";
21
import LOCAL_DISPATCH_NAMESPACE from "worker:dispatch-namespace/dispatch-namespace";
32
import { z } from "zod";
43
import { Worker_Binding } from "../../runtime";
@@ -13,7 +12,9 @@ export const DispatchNamespaceOptionsSchema = z.object({
1312
.record(
1413
z.object({
1514
namespace: z.string(),
16-
remoteProxyConnectionString: z.custom<RemoteProxyConnectionString>(),
15+
remoteProxyConnectionString: z
16+
.custom<RemoteProxyConnectionString>()
17+
.optional(),
1718
})
1819
)
1920
.optional(),
@@ -33,20 +34,19 @@ export const DISPATCH_NAMESPACE_PLUGIN: Plugin<
3334
const bindings = Object.entries(
3435
options.dispatchNamespaces
3536
).map<Worker_Binding>(([name, config]) => {
36-
assert(
37-
config.remoteProxyConnectionString,
38-
"Dispatch Namespace bindings only support running remotely"
39-
);
40-
4137
return {
4238
name,
4339
wrapped: {
4440
moduleName: `${DISPATCH_NAMESPACE_PLUGIN_NAME}:local-dispatch-namespace`,
4541
innerBindings: [
46-
{
47-
name: "remoteProxyConnectionString",
48-
text: config.remoteProxyConnectionString.href,
49-
},
42+
...(config.remoteProxyConnectionString?.href
43+
? [
44+
{
45+
name: "remoteProxyConnectionString",
46+
text: config.remoteProxyConnectionString.href,
47+
},
48+
]
49+
: []),
5050
{
5151
name: "binding",
5252
text: name,

packages/miniflare/src/plugins/media/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from "node:assert";
21
import BINDING from "worker:media/binding";
32
import { z } from "zod";
43
import {
@@ -13,7 +12,9 @@ export const MEDIA_PLUGIN_NAME = "media";
1312

1413
const MediaSchema = z.object({
1514
binding: z.string(),
16-
remoteProxyConnectionString: z.custom<RemoteProxyConnectionString>(),
15+
remoteProxyConnectionString: z
16+
.custom<RemoteProxyConnectionString>()
17+
.optional(),
1718
});
1819

1920
export const MediaOptionsSchema = z.object({
@@ -27,11 +28,6 @@ export const MEDIA_PLUGIN: Plugin<typeof MediaOptionsSchema> = {
2728
return [];
2829
}
2930

30-
assert(
31-
options.media.remoteProxyConnectionString,
32-
"Media only supports running remotely"
33-
);
34-
3531
return [
3632
{
3733
name: options.media.binding,

packages/miniflare/src/plugins/mtls/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from "node:assert";
21
import { z } from "zod";
32
import {
43
getUserBindingServiceName,
@@ -10,7 +9,9 @@ import {
109

1110
const MtlsSchema = z.object({
1211
certificate_id: z.string(),
13-
remoteProxyConnectionString: z.custom<RemoteProxyConnectionString>(),
12+
remoteProxyConnectionString: z
13+
.custom<RemoteProxyConnectionString>()
14+
.optional(),
1415
});
1516

1617
export const MtlsOptionsSchema = z.object({
@@ -28,11 +29,6 @@ export const MTLS_PLUGIN: Plugin<typeof MtlsOptionsSchema> = {
2829

2930
return Object.entries(options.mtlsCertificates).map(
3031
([name, { certificate_id, remoteProxyConnectionString }]) => {
31-
assert(
32-
remoteProxyConnectionString,
33-
"MTLS only supports running remotely"
34-
);
35-
3632
return {
3733
name,
3834

@@ -65,11 +61,6 @@ export const MTLS_PLUGIN: Plugin<typeof MtlsOptionsSchema> = {
6561

6662
return Object.entries(options.mtlsCertificates).map(
6763
([name, { certificate_id, remoteProxyConnectionString }]) => {
68-
assert(
69-
remoteProxyConnectionString,
70-
"MTLS only supports running remotely"
71-
);
72-
7364
return {
7465
name: getUserBindingServiceName(
7566
MTLS_PLUGIN_NAME,

packages/miniflare/src/plugins/shared/constants.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function objectEntryWorker(
7474
}
7575

7676
export function remoteProxyClientWorker(
77-
remoteProxyConnectionString: RemoteProxyConnectionString,
77+
remoteProxyConnectionString: RemoteProxyConnectionString | undefined,
7878
binding: string
7979
) {
8080
return {
@@ -86,10 +86,14 @@ export function remoteProxyClientWorker(
8686
},
8787
],
8888
bindings: [
89-
{
90-
name: "remoteProxyConnectionString",
91-
text: remoteProxyConnectionString.href,
92-
},
89+
...(remoteProxyConnectionString?.href
90+
? [
91+
{
92+
name: "remoteProxyConnectionString",
93+
text: remoteProxyConnectionString.href,
94+
},
95+
]
96+
: []),
9397
{
9498
name: "binding",
9599
text: binding,

0 commit comments

Comments
 (0)