Skip to content

refactor: hoist port literal to lib/constants.mjs + CI gate#98

Merged
dtzp555-max merged 1 commit into
mainfrom
refactor/spot-constants
May 12, 2026
Merged

refactor: hoist port literal to lib/constants.mjs + CI gate#98
dtzp555-max merged 1 commit into
mainfrom
refactor/spot-constants

Conversation

@dtzp555-max

Copy link
Copy Markdown
Owner

Summary

Structural fix for the port-drift cascade. v3.16.2 and v3.16.3 reverted the literal 3478 line-by-line back to 3456; this PR removes the invitation to drift entirely.

  • New lib/constants.mjs — single source of truth for shared literals. Exports DEFAULT_PORT=3456, LOCAL_HOST, OPENAI_API_BASE, LOCAL_PROXY_URL.
  • All .mjs consumers import the constant: server.mjs, setup.mjs, scripts/upgrade.mjs, scripts/doctor.mjs (x2), scripts/sync-openclaw.mjs.
  • .github/workflows/alignment.yml extended:
    • path filter now triggers on setup.mjs, scripts/**, lib/**, ocp, ocp-connect.
    • new port-spot hard-fail job greps every .mjs/.js/.ts/.json source file for hardcoded 3478 or 3456 literals outside EXEMPT_REGEX (which lists lib/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.
  • Doc-comment rewording in server.mjs and setup.mjs so the literal 3456 no longer appears in documentation text (CI grep is intentionally aggressive and does not parse comments).

Behavior change

None for any user.

  • CLAUDE_PROXY_PORT env var still wins at runtime (unchanged).
  • Unset-env fallback was 3456; now flows through DEFAULT_PORT = 3456 (same value, single declaration).

ALIGNMENT.md note

server.mjs change is one import line + one literal swap, mechanical. No cli.js operation 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 --check clean for all 6 modified .mjs files.
  • Runtime import test: node -e \"import('./lib/constants.mjs').then(m => console.log(m))\" returns all 4 constants.
  • Local CI grep check: zero hits for 3478 or 3456 outside EXEMPT_REGEX.
  • test-features.mjs cases that pin CLAUDE_PROXY_PORT=3478 still use env precedence; exempt from grep check.
  • CI green on this PR.

Why this matters

Between 2026-05-08 and 2026-05-13, a stray hardcoded \"3478\" in scripts/upgrade.mjs and scripts/doctor.mjs cascaded into wrong OpenClaw baseUrl writes, 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.

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.
@dtzp555-max dtzp555-max merged commit 9e25160 into main May 12, 2026
5 checks passed
@dtzp555-max dtzp555-max deleted the refactor/spot-constants branch May 12, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants