@@ -3,12 +3,15 @@ import { mount, flushPromises } from "@vue/test-utils";
33import NewRunModal from "./NewRunModal.vue" ;
44import { runsApi } from "@/services/api" ;
55import running from "@/views/fixtures/runs/run-running.json" ;
6+ import unconfigured from "@/views/fixtures/runs/runtimes-firecracker-unconfigured.json" ;
7+ import firecrackerOnly from "@/views/fixtures/runs/runtimes-firecracker-only.json" ;
68
79vi . mock ( "@/services/api" , ( ) => ( {
8- runsApi : { create : vi . fn ( ) } ,
10+ runsApi : { create : vi . fn ( ) , runtimes : vi . fn ( ) } ,
911} ) ) ;
1012
1113const create = runsApi . create as unknown as ReturnType < typeof vi . fn > ;
14+ const runtimes = runsApi . runtimes as unknown as ReturnType < typeof vi . fn > ;
1215
1316function mountModal ( ) {
1417 return mount ( NewRunModal , {
@@ -33,6 +36,7 @@ describe("NewRunModal", () => {
3336 beforeEach ( ( ) => {
3437 vi . clearAllMocks ( ) ;
3538 create . mockResolvedValue ( { data : running } ) ;
39+ runtimes . mockResolvedValue ( { data : unconfigured } ) ;
3640 } ) ;
3741
3842 it ( "sends the run in the shape the agent accepts" , async ( ) => {
@@ -53,6 +57,7 @@ describe("NewRunModal", () => {
5357 await submit ( wrapper ) ;
5458
5559 expect ( create ) . toHaveBeenCalledWith ( {
60+ runtime : "docker" ,
5661 image : "busybox:latest" ,
5762 command : [ "sh" , "-c" , "echo waiting; sleep 30" ] ,
5863 env : undefined ,
@@ -123,4 +128,72 @@ describe("NewRunModal", () => {
123128
124129 expect ( wrapper . find ( ".run-form-error" ) . text ( ) ) . toBe ( "timeout must be positive and at most one hour" ) ;
125130 } ) ;
131+
132+ it ( "offers only the runtimes this node can run" , async ( ) => {
133+ const wrapper = mountModal ( ) ;
134+ await flushPromises ( ) ;
135+
136+ const options = wrapper . findAll ( "option" ) . filter ( ( o ) => [ "docker" , "firecracker" ] . includes ( o . attributes ( "value" ) ! ) ) ;
137+ expect ( options . map ( ( o ) => [ o . text ( ) , o . attributes ( "disabled" ) !== undefined ] ) ) . toEqual ( [
138+ [ "Docker container" , false ] ,
139+ [ "Firecracker microVM (not set up on this node)" , true ] ,
140+ ] ) ;
141+ } ) ;
142+
143+ it ( "falls back to Docker when the agent cannot list runtimes" , async ( ) => {
144+ runtimes . mockRejectedValue ( { response : { status : 404 } } ) ;
145+ const wrapper = mountModal ( ) ;
146+ await flushPromises ( ) ;
147+ await fill ( wrapper , "Image" , "busybox:latest" ) ;
148+ await submit ( wrapper ) ;
149+
150+ expect ( create . mock . calls [ 0 ] [ 0 ] . runtime ) . toBe ( "docker" ) ;
151+ } ) ;
152+
153+ it ( "asks for a runtime instead of switching to one the user did not pick" , async ( ) => {
154+ runtimes . mockResolvedValue ( { data : firecrackerOnly } ) ;
155+ const wrapper = mountModal ( ) ;
156+ await flushPromises ( ) ;
157+ await fill ( wrapper , "Image" , "busybox:latest" ) ;
158+ await submit ( wrapper ) ;
159+ expect ( wrapper . find ( ".run-form-error" ) . text ( ) ) . toBe ( "Choose a runtime." ) ;
160+ expect ( create ) . not . toHaveBeenCalled ( ) ;
161+
162+ await wrapper . findAll ( "select" ) [ 0 ] . setValue ( "firecracker" ) ;
163+ await submit ( wrapper ) ;
164+ expect ( create . mock . calls [ 0 ] [ 0 ] . runtime ) . toBe ( "firecracker" ) ;
165+ } ) ;
166+
167+ it ( "keeps a chosen Firecracker run when the runtime list cannot be loaded again" , async ( ) => {
168+ runtimes . mockResolvedValue ( { data : firecrackerOnly } ) ;
169+ const wrapper = mountModal ( ) ;
170+ await flushPromises ( ) ;
171+ await wrapper . findAll ( "select" ) [ 0 ] . setValue ( "firecracker" ) ;
172+
173+ runtimes . mockRejectedValue ( { response : { status : 500 } } ) ;
174+ await wrapper . setProps ( { visible : false } ) ;
175+ await wrapper . setProps ( { visible : true } ) ;
176+ await flushPromises ( ) ;
177+ await fill ( wrapper , "Image" , "busybox:latest" ) ;
178+ await submit ( wrapper ) ;
179+
180+ expect ( create . mock . calls [ 0 ] [ 0 ] . runtime ) . toBe ( "firecracker" ) ;
181+ } ) ;
182+
183+ it ( "asks again when the chosen runtime stops being available" , async ( ) => {
184+ runtimes . mockResolvedValue ( { data : firecrackerOnly } ) ;
185+ const wrapper = mountModal ( ) ;
186+ await flushPromises ( ) ;
187+ await wrapper . findAll ( "select" ) [ 0 ] . setValue ( "firecracker" ) ;
188+
189+ runtimes . mockResolvedValue ( { data : unconfigured } ) ;
190+ await wrapper . setProps ( { visible : false } ) ;
191+ await wrapper . setProps ( { visible : true } ) ;
192+ await flushPromises ( ) ;
193+ await fill ( wrapper , "Image" , "busybox:latest" ) ;
194+ await submit ( wrapper ) ;
195+
196+ expect ( wrapper . find ( ".run-form-error" ) . text ( ) ) . toBe ( "Choose a runtime." ) ;
197+ expect ( create ) . not . toHaveBeenCalled ( ) ;
198+ } ) ;
126199} ) ;
0 commit comments