@@ -6,8 +6,10 @@ import { describe, expect, it } from "vitest";
66import type { ProviderHealthProbeOptions } from "../../../../dist/lib/inference/health" ;
77import {
88 classifySandboxContainerFailureForStatus ,
9+ classifySandboxStatusPreflightFailure ,
910 getSandboxStatusInferenceHealth ,
1011 isDockerDaemonUnreachableForStatus ,
12+ maybeGetSandboxStatusInferenceHealth ,
1113} from "../../../../dist/lib/actions/sandbox/status" ;
1214
1315describe ( "sandbox status inference health" , ( ) => {
@@ -152,3 +154,125 @@ describe("classifySandboxContainerFailureForStatus", () => {
152154 expect ( observed ) . toEqual ( [ { sandboxName : "alpha" , port : null } ] ) ;
153155 } ) ;
154156} ) ;
157+
158+ describe ( "maybeGetSandboxStatusInferenceHealth" , ( ) => {
159+ it ( "does not invoke the provider probe when suppressInferenceProbe is true even with a present gateway and string provider" , ( ) => {
160+ let probeCalls = 0 ;
161+ const result = maybeGetSandboxStatusInferenceHealth (
162+ true ,
163+ true ,
164+ "nvidia-prod" ,
165+ "nvidia/nemotron" ,
166+ ( ...args ) => {
167+ probeCalls += 1 ;
168+ throw new Error ( `probeProviderHealth should not be invoked (args=${ JSON . stringify ( args ) } )` ) ;
169+ } ,
170+ ) ;
171+ expect ( result ) . toBeNull ( ) ;
172+ expect ( probeCalls ) . toBe ( 0 ) ;
173+ } ) ;
174+
175+ it ( "delegates to the probe when suppressInferenceProbe is false" , ( ) => {
176+ const calls : { provider : string ; options ?: ProviderHealthProbeOptions } [ ] = [ ] ;
177+ const result = maybeGetSandboxStatusInferenceHealth (
178+ false ,
179+ true ,
180+ "nvidia-prod" ,
181+ "nvidia/nemotron" ,
182+ ( provider , options ) => {
183+ calls . push ( { provider, options } ) ;
184+ return {
185+ ok : true ,
186+ probed : true ,
187+ providerLabel : "NVIDIA Endpoints" ,
188+ endpoint : "https://integrate.api.nvidia.com/v1/chat/completions" ,
189+ detail : "healthy" ,
190+ } ;
191+ } ,
192+ ) ;
193+ expect ( result ?. ok ) . toBe ( true ) ;
194+ expect ( calls ) . toEqual ( [
195+ { provider : "nvidia-prod" , options : { model : "nvidia/nemotron" } } ,
196+ ] ) ;
197+ } ) ;
198+ } ) ;
199+
200+ describe ( "classifySandboxStatusPreflightFailure" , ( ) => {
201+ it ( "returns docker_unreachable when the daemon probe reports unreachable" , async ( ) => {
202+ let sandboxProbeCalled = false ;
203+ const result = await classifySandboxStatusPreflightFailure (
204+ { name : "alpha" , openshellDriver : "docker" } as never ,
205+ {
206+ dockerProbe : ( ) => false ,
207+ sandboxContainerProbe : async ( ) => {
208+ sandboxProbeCalled = true ;
209+ return null ;
210+ } ,
211+ } ,
212+ ) ;
213+ expect ( result ) . toEqual ( { layer : "docker_unreachable" , dockerUnreachable : true } ) ;
214+ // Short-circuits: a daemon that is already known to be down must not
215+ // trigger a follow-up `docker ps` round trip.
216+ expect ( sandboxProbeCalled ) . toBe ( false ) ;
217+ } ) ;
218+
219+ it ( "returns the sandbox container failure when the daemon is reachable" , async ( ) => {
220+ const result = await classifySandboxStatusPreflightFailure (
221+ { name : "alpha" , openshellDriver : "docker" , dashboardPort : 18789 } as never ,
222+ {
223+ dockerProbe : ( ) => true ,
224+ sandboxContainerProbe : async ( sandboxName , dashboardPort ) => {
225+ expect ( sandboxName ) . toBe ( "alpha" ) ;
226+ expect ( dashboardPort ) . toBe ( 18789 ) ;
227+ return {
228+ layer : "sandbox_dashboard_port_conflict" ,
229+ detail : "stub failure" ,
230+ } ;
231+ } ,
232+ } ,
233+ ) ;
234+ expect ( result ) . toEqual ( {
235+ layer : "sandbox_dashboard_port_conflict" ,
236+ dockerUnreachable : false ,
237+ } ) ;
238+ } ) ;
239+
240+ it ( "returns null when the sandbox container probe finds no failure" , async ( ) => {
241+ const result = await classifySandboxStatusPreflightFailure (
242+ { name : "alpha" , openshellDriver : "docker" } as never ,
243+ {
244+ dockerProbe : ( ) => true ,
245+ sandboxContainerProbe : async ( ) => null ,
246+ } ,
247+ ) ;
248+ expect ( result ) . toBeNull ( ) ;
249+ } ) ;
250+
251+ it ( "returns null when the sandbox is not on the docker driver" , async ( ) => {
252+ let dockerCalled = false ;
253+ let sandboxCalled = false ;
254+ const result = await classifySandboxStatusPreflightFailure (
255+ { name : "alpha" , openshellDriver : "vm" } as never ,
256+ {
257+ dockerProbe : ( ) => {
258+ dockerCalled = true ;
259+ return false ;
260+ } ,
261+ sandboxContainerProbe : async ( ) => {
262+ sandboxCalled = true ;
263+ return null ;
264+ } ,
265+ } ,
266+ ) ;
267+ expect ( result ) . toBeNull ( ) ;
268+ // Both gates are docker-driver-only; a vm sandbox must not provoke
269+ // either probe.
270+ expect ( dockerCalled ) . toBe ( false ) ;
271+ expect ( sandboxCalled ) . toBe ( false ) ;
272+ } ) ;
273+
274+ it ( "returns null when the sandbox entry is null" , async ( ) => {
275+ const result = await classifySandboxStatusPreflightFailure ( null ) ;
276+ expect ( result ) . toBeNull ( ) ;
277+ } ) ;
278+ } ) ;
0 commit comments