From 2e6f5be36648dd4d3befdce76ece980ee74c25a9 Mon Sep 17 00:00:00 2001 From: mayor Date: Sat, 30 May 2026 18:03:14 -0700 Subject: [PATCH] fix: read GASTOWN_HOST instead of bare HOST env var The server and CLI read `process.env.HOST` to determine the bind address. `HOST` is also the standard compiler-toolchain target-triple variable (set by conda/clang cross-compile shells, e.g. `HOST=arm64-apple-darwin20.0.0`). In such a shell the server tries to bind to that value as a hostname and crashes on startup: Error: getaddrinfo ENOTFOUND arm64-apple-darwin20.0.0 Emitted 'error' event on WebSocketServer instance Switch to a namespaced `GASTOWN_HOST` env var, mirroring the existing `GASTOWN_PORT` convention, so the GUI no longer collides with the toolchain `HOST` variable. The `--host` CLI flag is unchanged. - server.js: read GASTOWN_HOST (with explanatory comment) - bin/cli.js: read GASTOWN_HOST, pass it to the spawned server, update help/docs - README.md: document GASTOWN_HOST - test/integration: update spawned-server env to GASTOWN_HOST Verified: with HOST=arm64-apple-darwin20.0.0 set and GASTOWN_HOST unset, the server now binds to 127.0.0.1 and serves 200. Full suite green (343/343). --- README.md | 2 +- bin/cli.js | 10 +++++----- server.js | 6 +++++- test/integration/cli-compatibility.test.js | 2 +- test/integration/cli-executable-resolution.test.js | 2 +- test/integration/realtime-cache-invalidation.test.js | 2 +- test/integration/rig-parsing-fallback.test.js | 2 +- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0c299d3..012eba9 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ gastown-gui help | Variable | Description | Default | |----------|-------------|---------| | `GASTOWN_PORT` | Server port | 7667 | -| `HOST` | Server host | 127.0.0.1 | +| `GASTOWN_HOST` | Server host | 127.0.0.1 | | `GT_ROOT` | Gas Town root directory | ~/gt | | `GT_BIN` | Override `gt` executable path | auto-detect (`PATH`, `/opt/homebrew/bin/gt`, `/usr/local/bin/gt`) | | `BD_BIN` | Override `bd` executable path | auto-detect (`PATH`, `/opt/homebrew/bin/bd`, `/usr/local/bin/bd`) | diff --git a/bin/cli.js b/bin/cli.js index a2ba8a4..609562e 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -15,7 +15,7 @@ * * Options: * --port, -p Port to run on (default: 7667) - * --host, -h Host to bind to (default: 127.0.0.1) + * --host, -h Host to bind to (default: 127.0.0.1, or GASTOWN_HOST env var) * --open, -o Open browser after starting * --dev Enable development mode (auto-reload) */ @@ -45,7 +45,7 @@ if (args.includes('--version') || args.includes('-v')) { const command = args.find(a => !a.startsWith('-')) || 'start'; const options = { port: getOption(['--port', '-p']) || process.env.GASTOWN_PORT || '7667', - host: getOption(['--host', '-h']) || process.env.HOST || '127.0.0.1', + host: getOption(['--host', '-h']) || process.env.GASTOWN_HOST || '127.0.0.1', open: hasFlag(['--open', '-o']), dev: hasFlag(['--dev']), }; @@ -79,13 +79,13 @@ Commands: Options: --port, -p Port to run on (default: 7667, or GASTOWN_PORT env var) - --host, -h Host to bind to (default: 127.0.0.1, or HOST env var) + --host, -h Host to bind to (default: 127.0.0.1, or GASTOWN_HOST env var) --open, -o Open browser after starting --dev Enable development mode Environment Variables: GASTOWN_PORT Server port (default: 7667) - HOST Server host (default: 127.0.0.1) + GASTOWN_HOST Server host (default: 127.0.0.1) GT_ROOT Gas Town root directory (default: ~/gt) Examples: @@ -209,7 +209,7 @@ function startServer() { const env = { ...process.env, GASTOWN_PORT: options.port, - HOST: options.host, + GASTOWN_HOST: options.host, }; const serverPath = path.join(packageRoot, 'server.js'); diff --git a/server.js b/server.js index 53737b8..90643c9 100644 --- a/server.js +++ b/server.js @@ -63,7 +63,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const PORT = process.env.GASTOWN_PORT || 7667; -const HOST = process.env.HOST || '127.0.0.1'; +// Use GASTOWN_HOST (not the bare HOST env var, which collides with the +// compiler-toolchain convention, e.g. HOST=arm64-apple-darwin* set by +// conda/clang cross-compile shells — that would make the server try to bind +// to an unresolvable hostname and crash with getaddrinfo ENOTFOUND). +const HOST = process.env.GASTOWN_HOST || '127.0.0.1'; const HOME = process.env.HOME || os.homedir(); const GT_ROOT = process.env.GT_ROOT || path.join(HOME, 'gt'); const GT_EXECUTABLE = resolveExecutable({ diff --git a/test/integration/cli-compatibility.test.js b/test/integration/cli-compatibility.test.js index 5afff58..114ad1b 100644 --- a/test/integration/cli-compatibility.test.js +++ b/test/integration/cli-compatibility.test.js @@ -63,7 +63,7 @@ async function startRealServerFixture({ gtScript, bdScript, ghScript }) { env: { ...process.env, GASTOWN_PORT: String(port), - HOST: '127.0.0.1', + GASTOWN_HOST: '127.0.0.1', GT_ROOT: gtRoot, PATH: `${binDir}:${process.env.PATH}`, GT_CALL_LOG: gtCallLog, diff --git a/test/integration/cli-executable-resolution.test.js b/test/integration/cli-executable-resolution.test.js index 43f25c3..96bee11 100644 --- a/test/integration/cli-executable-resolution.test.js +++ b/test/integration/cli-executable-resolution.test.js @@ -90,7 +90,7 @@ async function startFixture({ gtScript, bdScript, ghScript, env = {} }) { env: { ...process.env, GASTOWN_PORT: String(port), - HOST: '127.0.0.1', + GASTOWN_HOST: '127.0.0.1', GT_ROOT: gtRoot, PATH: binDir, ...env, diff --git a/test/integration/realtime-cache-invalidation.test.js b/test/integration/realtime-cache-invalidation.test.js index 7f3fab6..bf84e2c 100644 --- a/test/integration/realtime-cache-invalidation.test.js +++ b/test/integration/realtime-cache-invalidation.test.js @@ -187,7 +187,7 @@ exit 1 env: { ...process.env, GASTOWN_PORT: String(port), - HOST: '127.0.0.1', + GASTOWN_HOST: '127.0.0.1', GT_ROOT: gtRoot, PATH: `${binDir}:${process.env.PATH}`, }, diff --git a/test/integration/rig-parsing-fallback.test.js b/test/integration/rig-parsing-fallback.test.js index f34c077..a15b75c 100644 --- a/test/integration/rig-parsing-fallback.test.js +++ b/test/integration/rig-parsing-fallback.test.js @@ -108,7 +108,7 @@ exit 1 env: { ...process.env, GASTOWN_PORT: String(port), - HOST: '127.0.0.1', + GASTOWN_HOST: '127.0.0.1', GT_ROOT: gtRoot, PATH: `${binDir}:${process.env.PATH}`, },