refactor: hoist port literal to lib/constants.mjs + CI gate#98
Merged
Conversation
Closes the structural side of the port-drift cascade addressed by
v3.16.2/v3.16.3. Those releases reverted the literal line-by-line; this
one removes the invitation to drift.
Changes:
* NEW lib/constants.mjs — exports DEFAULT_PORT=3456, LOCAL_HOST,
OPENAI_API_BASE, LOCAL_PROXY_URL.
* server.mjs / setup.mjs / scripts/upgrade.mjs / scripts/doctor.mjs
(x2) / scripts/sync-openclaw.mjs all import DEFAULT_PORT from
lib/constants.mjs instead of hardcoding "3456".
* .github/workflows/alignment.yml:
- path filter extended to setup.mjs, scripts/**, lib/**,
ocp, ocp-connect.
- NEW job port-spot hard-fails any PR that introduces a hardcoded
"3478" or "3456" literal outside EXEMPT_REGEX (lib/constants.mjs,
test-features.mjs, ocp/ocp-connect bash CLIs, docs, the workflow
itself).
* Doc-comment rewording so CI grep finds zero hits.
No behavior change for any user. CLAUDE_PROXY_PORT env var still wins
at runtime; only the unset-env fallback now flows through one constant.
ALIGNMENT.md note: server.mjs change is one import + one literal swap,
mechanical. No cli.js operation changed; the citation requirement does
not apply.
cli.js: not applicable — mechanical refactor, no behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Structural fix for the port-drift cascade. v3.16.2 and v3.16.3 reverted the literal
3478line-by-line back to3456; this PR removes the invitation to drift entirely.lib/constants.mjs— single source of truth for shared literals. ExportsDEFAULT_PORT=3456,LOCAL_HOST,OPENAI_API_BASE,LOCAL_PROXY_URL..mjsconsumers import the constant:server.mjs,setup.mjs,scripts/upgrade.mjs,scripts/doctor.mjs(x2),scripts/sync-openclaw.mjs..github/workflows/alignment.ymlextended:setup.mjs,scripts/**,lib/**,ocp,ocp-connect.port-spothard-fail job greps every.mjs/.js/.ts/.jsonsource file for hardcoded3478or3456literals outsideEXEMPT_REGEX(which listslib/constants.mjs,test-features.mjs, the bash CLIs, docs, and the workflow itself). Any future PR re-introducing a hardcoded port literal will be blocked at CI before it can cascade.server.mjsandsetup.mjsso the literal3456no longer appears in documentation text (CI grep is intentionally aggressive and does not parse comments).Behavior change
None for any user.
CLAUDE_PROXY_PORTenv var still wins at runtime (unchanged).3456; now flows throughDEFAULT_PORT = 3456(same value, single declaration).ALIGNMENT.md note
server.mjschange is one import line + one literal swap, mechanical. Nocli.jsoperation changed; the citation requirement does not apply.The SPOT principle (Rule 2 spirit — "one place to change something") is the entire motivation.
Test plan
node --checkclean for all 6 modified.mjsfiles.node -e \"import('./lib/constants.mjs').then(m => console.log(m))\"returns all 4 constants.3478or3456outsideEXEMPT_REGEX.test-features.mjscases that pinCLAUDE_PROXY_PORT=3478still use env precedence; exempt from grep check.Why this matters
Between 2026-05-08 and 2026-05-13, a stray hardcoded
\"3478\"inscripts/upgrade.mjsandscripts/doctor.mjscascaded into wrong OpenClawbaseUrlwrites, taking out the OpenClaw "大内总管" Telegram agent and the ocp-bot Telegram bridge. v3.16.2/v3.16.3 fixed the values; this PR fixes the structure that allowed the bug to exist in the first place.Future regressions of this class are blocked at CI before merge.