Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/onboard/hermes-api-port.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ describe("readHermesApiPort", () => {
expect(readHermesApiPort({})).toBe(8642);
});

it.each(["", " ", " "])("treats the blank value %j as unset", (value) => {
expect(readHermesApiPort({ [HERMES_API_PORT_ENV]: value })).toBe(8642);
});

it.each(["8641", "8653", "9000", "08642", "²"])(
"rejects %s outside the allocated Hermes API-port range",
(value) => {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/onboard/hermes-api-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ export function isValidHermesApiPort(value: unknown): value is number {
*/
export function readHermesApiPort(env: NodeJS.ProcessEnv = process.env): number {
const raw = env[HERMES_API_PORT_ENV];
// A present-but-blank value is unset, the same rule the callers apply when
// they test `env[HERMES_API_PORT_ENV]?.trim()`. Without this guard a
// template-expanded empty value fails the parse as an invalid port and
// aborts a re-onboard that would otherwise reuse the recorded port.
if (raw !== undefined && raw.trim() === "") return HERMES_OPENAI_API_PORT;
let port: number;
try {
port = parseServicePortOverride(HERMES_API_PORT_ENV, raw, HERMES_OPENAI_API_PORT);
Expand Down