Skip to content

Commit be36079

Browse files
committed
Test proxying an RPC stub all the way to Durable Objects.
In particular, the DO keeps a dup() of the stub and uses it later, after the original subscription call has returned. This requires the `rpc_params_dup_stubs` compat flag, which is new in yesterday's workerd release. Since wrangler is not updated yet, this requires a package version override for now. Once wrangler has been updated, I'll remove the override and then merge this. DO NOT MERGE until the override can be removed.
1 parent 36a76b5 commit be36079

File tree

5 files changed

+56
-44
lines changed

5 files changed

+56
-44
lines changed

__tests__/test-server-workerd.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export class TestDo extends DurableObject {
3535
getValue() {
3636
return this.value;
3737
}
38+
39+
subscribe(callback) {
40+
this.subscriber = callback.dup();
41+
}
42+
43+
async notify(value) {
44+
await this.subscriber(value);
45+
this.subscriber[Symbol.dispose]();
46+
}
3847
}
3948

4049
export class TestTarget extends RpcTarget {

__tests__/workerd.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ interface Env {
230230
interface TestDo extends DurableObject {
231231
setValue(val: any): void;
232232
getValue(): any;
233+
234+
subscribe(callback: (s: string) => void): void;
235+
notify(value: string): void;
233236
}
234237

235238
interface WorkerdTestTarget extends TestTarget {
@@ -268,6 +271,18 @@ describe("workerd RPC server", () => {
268271
expect(await foo.getValue()).toBe(123);
269272
expect(await bar.getValue()).toBe("abc");
270273
}
274+
275+
{
276+
let baz = cap.getDurableObject("baz");
277+
278+
let receivedValue: any;
279+
280+
await baz.subscribe((value: any) => {receivedValue = value});
281+
282+
await baz.notify("hello");
283+
284+
expect(receivedValue).toBe("hello");
285+
}
271286
})
272287

273288
it("can accept HTTP batch RPC connections", async () => {

package-lock.json

Lines changed: 25 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"tsx": "^4.21.0",
4747
"typescript": "^5.9.3",
4848
"vitest": "^3.2.4",
49+
"workerd": "1.20251223.0",
4950
"ws": "^8.18.3"
5051
},
5152
"repository": {
@@ -55,5 +56,8 @@
5556
"bugs": {
5657
"url": "https://github.com/cloudflare/capnweb/issues"
5758
},
58-
"homepage": "https://github.com/cloudflare/capnweb#readme"
59+
"homepage": "https://github.com/cloudflare/capnweb#readme",
60+
"overrides": {
61+
"workerd": "1.20251223.0"
62+
}
5963
}

vitest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default defineConfig({
3030
workers: {
3131
miniflare: {
3232
compatibilityDate: '2025-07-01',
33-
compatibilityFlags: ["expose_global_message_channel"],
33+
compatibilityFlags: ["expose_global_message_channel", "rpc_params_dup_stubs"],
3434

3535
// Define a backend worker to test server-side functionality. The tests will
3636
// talk to it over a service binding. (Only the workerd client tests will talk
@@ -42,6 +42,7 @@ export default defineConfig({
4242
{
4343
name: "test-server-workerd",
4444
compatibilityDate: '2025-07-01',
45+
compatibilityFlags: ["rpc_params_dup_stubs"],
4546
modules: [
4647
{
4748
type: "ESModule",

0 commit comments

Comments
 (0)