@@ -78,14 +78,20 @@ beforeEach(async () => {
7878 const name = / \/ s c r i p t s \/ ( [ ^ / ? ] + ) / . exec ( url ) ?. [ 1 ] ;
7979 if (
8080 name ?. startsWith ( 'void-do-' ) &&
81- url . endsWith ( '/bindings' ) &&
81+ ( url . endsWith ( '/bindings' ) || url . endsWith ( '/settings' ) ) &&
8282 ! provider . state . hostScripts . has ( name )
8383 ) {
84+ if ( url . endsWith ( '/bindings' ) ) {
85+ return cfSuccess ( [ ] ) ;
86+ }
8487 return Response . json (
8588 { success : false , errors : [ { code : 10007 , message : 'script not found' } ] } ,
8689 { status : 404 } ,
8790 ) ;
8891 }
92+ if ( name ?. startsWith ( 'void-do-' ) && url . endsWith ( '/settings' ) && ! init ?. method ) {
93+ return cfSuccess ( { bindings : provider . state . hostScripts . get ( name ) ! . bindings } ) ;
94+ }
8995 const response = await original ( input , init ) ;
9096 if ( init ?. method === 'PUT' && init . body instanceof FormData && response . ok && name ) {
9197 const metadata = JSON . parse ( await ( init . body . get ( 'metadata' ) as Blob ) . text ( ) ) as Record <
@@ -190,6 +196,21 @@ function currentRelease(worker: string) {
190196}
191197
192198describe ( 'managed native Durable Objects' , ( ) => {
199+ it ( 'refuses to replace an existing Worker whose bindings are empty' , async ( ) => {
200+ const worker = await durableObjectWorkerName ( project . id , binding . className ) ;
201+ provider . state . hostScripts . set ( worker , {
202+ classes : new Map ( ) ,
203+ bindings : [ ] ,
204+ metadata : { } ,
205+ } ) ;
206+ const result = await deploy ( ) ;
207+ expect ( result . events ) . toContainEqual (
208+ expect . objectContaining ( { event : 'error' , message : expect . stringContaining ( 'ownership' ) } ) ,
209+ ) ;
210+ expect ( writes ) . toHaveLength ( 0 ) ;
211+ expect ( provider . state . hostScripts . get ( worker ) ! . bindings ) . toEqual ( [ ] ) ;
212+ } ) ;
213+
193214 it ( 'runs the published class through real RPC and retains data after upgrade, rollback, and restart' , async ( ) => {
194215 const directory = mkdtempSync ( join ( tmpdir ( ) , 'void-managed-native-' ) ) ;
195216 let runtime : Miniflare | undefined ;
0 commit comments