@@ -92,6 +92,61 @@ describe("sandbox GPU preflight routing", () => {
9292 expect ( dockerInfo ) . not . toHaveBeenCalled ( ) ;
9393 } ) ;
9494
95+ it ( "falls back to Docker's default CDI spec dirs when docker info reports none (#7330)" , ( ) => {
96+ const getDockerCdiSpecDirs = vi . fn ( ( ) => [ ] ) ;
97+ const findReadableNvidiaCdiSpecFiles = ( dirs : string [ ] ) =>
98+ dirs . length === 2 && dirs [ 0 ] === "/etc/cdi" && dirs [ 1 ] === "/var/run/cdi"
99+ ? [ "/etc/cdi/nvidia.yaml" ]
100+ : [ ] ;
101+ const exitProcess = ( code : number ) : never => {
102+ throw new Error ( `exit:${ code } ` ) ;
103+ } ;
104+
105+ expect ( ( ) =>
106+ validateSandboxGpuPreflight (
107+ sandboxGpuConfig ( ) ,
108+ {
109+ platform : "linux" ,
110+ env : { } ,
111+ release : "6.8.0-generic" ,
112+ procVersion : "Linux version 6.8.0-generic" ,
113+ dockerInfoFormat : vi . fn ( ) ,
114+ getDockerCdiSpecDirs,
115+ findReadableNvidiaCdiSpecFiles,
116+ } ,
117+ exitProcess ,
118+ ) ,
119+ ) . not . toThrow ( ) ;
120+ } ) ;
121+
122+ it ( "still fails when the fallback CDI spec dirs hold no NVIDIA spec (#7330)" , ( ) => {
123+ const errorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => undefined ) ;
124+ const exitSpy = vi . spyOn ( process , "exit" ) . mockImplementation ( ( (
125+ code ?: number | string | null ,
126+ ) => {
127+ throw new Error ( `exit:${ code } ` ) ;
128+ } ) as never ) ;
129+
130+ try {
131+ expect ( ( ) =>
132+ validateSandboxGpuPreflight ( sandboxGpuConfig ( ) , {
133+ platform : "linux" ,
134+ env : { } ,
135+ release : "6.8.0-generic" ,
136+ procVersion : "Linux version 6.8.0-generic" ,
137+ dockerInfoFormat : vi . fn ( ) ,
138+ getDockerCdiSpecDirs : vi . fn ( ( ) => [ ] ) ,
139+ findReadableNvidiaCdiSpecFiles : vi . fn ( ( ) => [ ] ) ,
140+ } ) ,
141+ ) . toThrow ( "exit:1" ) ;
142+ const message = errorSpy . mock . calls . map ( ( call ) => call [ 0 ] ) . join ( "\n" ) ;
143+ expect ( message ) . toContain ( "Docker CDI GPU support was not detected" ) ;
144+ } finally {
145+ errorSpy . mockRestore ( ) ;
146+ exitSpy . mockRestore ( ) ;
147+ }
148+ } ) ;
149+
95150 it ( "skips CDI spec validation on Docker Desktop WSL so Docker --gpus can be used" , ( ) => {
96151 const logSpy = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined ) ;
97152 const getDockerCdiSpecDirs = vi . fn ( ( ) => [ "/etc/cdi" ] ) ;
0 commit comments