@@ -6,9 +6,8 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
66import {
77 parseGatewayPort ,
88 parsePort ,
9- validateHttpsPinRuntimeAdapterPort ,
109 validateLlamaCppPortReservation ,
11- validateOpenRouterRuntimeAdapterPort ,
10+ validateRuntimeAdapterPort ,
1211} from "./ports" ;
1312
1413const GATEWAY_VALIDATION_OPTIONS = {
@@ -181,68 +180,54 @@ describe("validateLlamaCppPortReservation", () => {
181180 } ) ;
182181} ) ;
183182
184- describe ( "validateOpenRouterRuntimeAdapterPort" , ( ) => {
185- const ENV_KEY = "NEMOCLAW_OPENROUTER_RUNTIME_ADAPTER_PORT" ;
183+ describe ( "validateRuntimeAdapterPort" , ( ) => {
184+ const ADAPTER_OWNERS = [
185+ [ "NEMOCLAW_BEDROCK_RUNTIME_ADAPTER_PORT" , 11436 , "Bedrock Runtime adapter" ] ,
186+ [ "NEMOCLAW_OPENROUTER_RUNTIME_ADAPTER_PORT" , 11437 , "OpenRouter Runtime adapter" ] ,
187+ [ "NEMOCLAW_HTTPS_PIN_RUNTIME_ADAPTER_PORT" , 11438 , "HTTPS Pin Runtime adapter" ] ,
188+ ] as const ;
186189
187- it ( "allows the default OpenRouter Runtime adapter port" , ( ) => {
188- expect ( ( ) =>
189- validateOpenRouterRuntimeAdapterPort ( ENV_KEY , 11437 , GATEWAY_VALIDATION_OPTIONS ) ,
190- ) . not . toThrow ( ) ;
191- } ) ;
192-
193- it . each ( [
190+ const SHARED_CONFLICTS = [
194191 [ 8080 , "NEMOCLAW_GATEWAY_PORT" ] ,
195192 [ 8000 , "vLLM / NIM inference" ] ,
196193 [ 11434 , "Ollama inference" ] ,
197194 [ 11435 , "Ollama auth proxy" ] ,
198- [ 11436 , "Bedrock Runtime adapter" ] ,
199- [ 11438 , "HTTPS Pin Runtime adapter" ] ,
200195 [ 18790 , "18789-18799" ] ,
201- ] ) ( "rejects OpenRouter adapter overlap with %s" , ( port , expectedMessage ) => {
202- expect ( ( ) =>
203- validateOpenRouterRuntimeAdapterPort ( ENV_KEY , port , GATEWAY_VALIDATION_OPTIONS ) ,
204- ) . toThrow ( expectedMessage ) ;
205- } ) ;
196+ ] as const ;
206197
207- it ( "rejects OpenRouter adapter overlap with configured service ports ", ( ) => {
198+ it . each ( ADAPTER_OWNERS ) ( "allows the default port owned by %s ", ( ownerEnvVar , defaultPort ) => {
208199 expect ( ( ) =>
209- validateOpenRouterRuntimeAdapterPort ( ENV_KEY , 19001 , {
210- ...GATEWAY_VALIDATION_OPTIONS ,
211- vllmPort : 19001 ,
212- } ) ,
213- ) . toThrow ( "NEMOCLAW_VLLM_PORT" ) ;
214- } ) ;
215- } ) ;
216-
217- describe ( "validateHttpsPinRuntimeAdapterPort" , ( ) => {
218- const ENV_KEY = "NEMOCLAW_HTTPS_PIN_RUNTIME_ADAPTER_PORT" ;
219-
220- it ( "allows the default HTTPS Pin Runtime adapter port" , ( ) => {
221- expect ( ( ) =>
222- validateHttpsPinRuntimeAdapterPort ( ENV_KEY , 11438 , GATEWAY_VALIDATION_OPTIONS ) ,
200+ validateRuntimeAdapterPort ( ownerEnvVar , defaultPort , GATEWAY_VALIDATION_OPTIONS ) ,
223201 ) . not . toThrow ( ) ;
224202 } ) ;
225203
226- it . each ( [
227- [ 8080 , "NEMOCLAW_GATEWAY_PORT" ] ,
228- [ 8000 , "vLLM / NIM inference" ] ,
229- [ 11434 , "Ollama inference" ] ,
230- [ 11435 , "Ollama auth proxy" ] ,
231- [ 11436 , "Bedrock Runtime adapter" ] ,
232- [ 11437 , "OpenRouter Runtime adapter" ] ,
233- [ 18790 , "18789-18799" ] ,
234- ] ) ( "rejects HTTPS Pin adapter overlap with %s" , ( port , expectedMessage ) => {
235- expect ( ( ) =>
236- validateHttpsPinRuntimeAdapterPort ( ENV_KEY , port , GATEWAY_VALIDATION_OPTIONS ) ,
237- ) . toThrow ( expectedMessage ) ;
204+ it . each (
205+ ADAPTER_OWNERS . flatMap ( ( [ ownerEnvVar , defaultPort ] ) =>
206+ [
207+ ...SHARED_CONFLICTS ,
208+ ...ADAPTER_OWNERS . filter ( ( [ , otherPort ] ) => otherPort !== defaultPort ) . map (
209+ ( [ , otherPort , otherLabel ] ) => [ otherPort , otherLabel ] as const ,
210+ ) ,
211+ ] . map ( ( [ port , expectedMessage ] ) => [ ownerEnvVar , port , expectedMessage ] as const ) ,
212+ ) ,
213+ ) ( "rejects %s on %d because it overlaps %s" , ( ownerEnvVar , port , expectedMessage ) => {
214+ expect ( ( ) => validateRuntimeAdapterPort ( ownerEnvVar , port , GATEWAY_VALIDATION_OPTIONS ) ) . toThrow (
215+ expectedMessage ,
216+ ) ;
238217 } ) ;
239218
240- it ( "rejects HTTPS Pin adapter overlap with configured service ports " , ( ) => {
219+ it . each ( ADAPTER_OWNERS ) ( "rejects %s on a configured non-default service port " , ( ownerEnvVar ) => {
241220 expect ( ( ) =>
242- validateHttpsPinRuntimeAdapterPort ( ENV_KEY , 19001 , {
221+ validateRuntimeAdapterPort ( ownerEnvVar , 19001 , {
243222 ...GATEWAY_VALIDATION_OPTIONS ,
244223 vllmPort : 19001 ,
245224 } ) ,
246225 ) . toThrow ( "NEMOCLAW_VLLM_PORT" ) ;
247226 } ) ;
227+
228+ it ( "validates against the live port configuration when no options are injected" , ( ) => {
229+ expect ( ( ) =>
230+ validateRuntimeAdapterPort ( "NEMOCLAW_BEDROCK_RUNTIME_ADAPTER_PORT" , 11434 ) ,
231+ ) . toThrow ( "Ollama inference" ) ;
232+ } ) ;
248233} ) ;
0 commit comments