|
3 | 3 |
|
4 | 4 | import { describe, it, expect, beforeEach, afterEach } from "vitest"; |
5 | 5 | // Import from compiled dist/ so coverage is attributed correctly. |
6 | | -import { parsePort } from "../../../dist/lib/core/ports"; |
| 6 | +import { parseGatewayPort, parsePort } from "../../../dist/lib/core/ports"; |
| 7 | + |
| 8 | +const GATEWAY_VALIDATION_OPTIONS = { |
| 9 | + dashboardPort: 18789, |
| 10 | + dashboardRangeStart: 18789, |
| 11 | + dashboardRangeEnd: 18799, |
| 12 | + vllmPort: 8000, |
| 13 | + ollamaPort: 11434, |
| 14 | + ollamaProxyPort: 11435, |
| 15 | +}; |
7 | 16 |
|
8 | 17 | describe("parsePort", () => { |
9 | 18 | const ENV_KEY = "TEST_PORT"; |
@@ -70,3 +79,71 @@ describe("parsePort", () => { |
70 | 79 | expect(() => parsePort(ENV_KEY, 8080)).toThrow("Invalid port"); |
71 | 80 | }); |
72 | 81 | }); |
| 82 | + |
| 83 | +describe("parseGatewayPort", () => { |
| 84 | + const ENV_KEY = "TEST_GATEWAY_PORT"; |
| 85 | + |
| 86 | + beforeEach(() => { |
| 87 | + delete process.env[ENV_KEY]; |
| 88 | + }); |
| 89 | + |
| 90 | + afterEach(() => { |
| 91 | + delete process.env[ENV_KEY]; |
| 92 | + }); |
| 93 | + |
| 94 | + it("allows the default gateway port when no override is set", () => { |
| 95 | + expect(parseGatewayPort(ENV_KEY, 8080, GATEWAY_VALIDATION_OPTIONS)).toBe(8080); |
| 96 | + }); |
| 97 | + |
| 98 | + it("rejects the default gateway port when another service is configured there", () => { |
| 99 | + expect(() => |
| 100 | + parseGatewayPort(ENV_KEY, 8080, { |
| 101 | + ...GATEWAY_VALIDATION_OPTIONS, |
| 102 | + vllmPort: 8080, |
| 103 | + }), |
| 104 | + ).toThrow("NEMOCLAW_VLLM_PORT"); |
| 105 | + }); |
| 106 | + |
| 107 | + it("accepts a non-conflicting gateway port override", () => { |
| 108 | + process.env[ENV_KEY] = "8990"; |
| 109 | + expect(parseGatewayPort(ENV_KEY, 8080, GATEWAY_VALIDATION_OPTIONS)).toBe(8990); |
| 110 | + }); |
| 111 | + |
| 112 | + it("rejects the dashboard auto-allocation range", () => { |
| 113 | + process.env[ENV_KEY] = "18790"; |
| 114 | + expect(() => parseGatewayPort(ENV_KEY, 8080, GATEWAY_VALIDATION_OPTIONS)).toThrow( |
| 115 | + "18789-18799", |
| 116 | + ); |
| 117 | + }); |
| 118 | + |
| 119 | + it("rejects overlap with the configured dashboard port", () => { |
| 120 | + process.env[ENV_KEY] = "19000"; |
| 121 | + expect(() => |
| 122 | + parseGatewayPort(ENV_KEY, 8080, { |
| 123 | + ...GATEWAY_VALIDATION_OPTIONS, |
| 124 | + dashboardPort: 19000, |
| 125 | + }), |
| 126 | + ).toThrow("NEMOCLAW_DASHBOARD_PORT"); |
| 127 | + }); |
| 128 | + |
| 129 | + it("rejects overlap with a configured non-default service port", () => { |
| 130 | + process.env[ENV_KEY] = "19001"; |
| 131 | + expect(() => |
| 132 | + parseGatewayPort(ENV_KEY, 8080, { |
| 133 | + ...GATEWAY_VALIDATION_OPTIONS, |
| 134 | + vllmPort: 19001, |
| 135 | + }), |
| 136 | + ).toThrow("NEMOCLAW_VLLM_PORT"); |
| 137 | + }); |
| 138 | + |
| 139 | + it.each([ |
| 140 | + ["8000", "vLLM / NIM inference"], |
| 141 | + ["11434", "Ollama inference"], |
| 142 | + ["11435", "Ollama auth proxy"], |
| 143 | + ])("rejects overlap with default port %s", (port, label) => { |
| 144 | + process.env[ENV_KEY] = port; |
| 145 | + expect(() => parseGatewayPort(ENV_KEY, 8080, GATEWAY_VALIDATION_OPTIONS)).toThrow( |
| 146 | + label, |
| 147 | + ); |
| 148 | + }); |
| 149 | +}); |
0 commit comments