@@ -322,6 +322,20 @@ afterEach(() => {
322322} ) ;
323323
324324describe ( 'two-phase destroy' , ( ) => {
325+ it ( 'throws with status 404 when instance was never provisioned' , async ( ) => {
326+ const { instance } = createInstance ( ) ;
327+
328+ const err : Error & { status ?: number } = await instance . destroy ( ) . then (
329+ ( ) => {
330+ throw new Error ( 'expected rejection' ) ;
331+ } ,
332+ ( e : Error & { status ?: number } ) => e
333+ ) ;
334+
335+ expect ( err . message ) . toBe ( 'Instance not provisioned' ) ;
336+ expect ( err . status ) . toBe ( 404 ) ;
337+ } ) ;
338+
325339 it ( 'clears all state when both Fly deletes succeed' , async ( ) => {
326340 const { instance, storage } = createInstance ( ) ;
327341 await seedRunning ( storage ) ;
@@ -1246,6 +1260,22 @@ describe('alarm runs for all live statuses', () => {
12461260 } ) ;
12471261} ) ;
12481262
1263+ describe ( 'start: not provisioned' , ( ) => {
1264+ it ( 'throws with status 404 when instance was never provisioned' , async ( ) => {
1265+ const { instance } = createInstance ( ) ;
1266+
1267+ const err : Error & { status ?: number } = await instance . start ( 'user-1' ) . then (
1268+ ( ) => {
1269+ throw new Error ( 'expected rejection' ) ;
1270+ } ,
1271+ ( e : Error & { status ?: number } ) => e
1272+ ) ;
1273+
1274+ expect ( err . message ) . toBe ( 'Instance not provisioned' ) ;
1275+ expect ( err . status ) . toBe ( 404 ) ;
1276+ } ) ;
1277+ } ) ;
1278+
12491279describe ( 'startExistingMachine: transient vs 404 errors' , ( ) => {
12501280 it ( 'does NOT recreate machine on transient 500 error' , async ( ) => {
12511281 const { instance, storage } = createInstance ( ) ;
@@ -2888,6 +2918,20 @@ describe('stop: error propagation', () => {
28882918 expect ( storage . _store . get ( 'status' ) ) . toBe ( 'stopped' ) ;
28892919 expect ( storage . _store . get ( 'lastStoppedAt' ) ) . toBeDefined ( ) ;
28902920 } ) ;
2921+
2922+ it ( 'throws with status 404 when instance was never provisioned' , async ( ) => {
2923+ const { instance } = createInstance ( ) ;
2924+
2925+ const err : Error & { status ?: number } = await instance . stop ( ) . then (
2926+ ( ) => {
2927+ throw new Error ( 'expected rejection' ) ;
2928+ } ,
2929+ ( e : Error & { status ?: number } ) => e
2930+ ) ;
2931+
2932+ expect ( err . message ) . toBe ( 'Instance not provisioned' ) ;
2933+ expect ( err . status ) . toBe ( 404 ) ;
2934+ } ) ;
28912935} ) ;
28922936
28932937// ============================================================================
0 commit comments