Skip to content

refactor: consolidate free-port test helpers#99771

Merged
RomneyDa merged 1 commit into
mainfrom
refactor/free-port-consolidation
Jul 4, 2026
Merged

refactor: consolidate free-port test helpers#99771
RomneyDa merged 1 commit into
mainfrom
refactor/free-port-consolidation

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member

What Problem This Solves

Removes repeated TCP free-port discovery implementations from root-owned tests, where small cleanup and error-handling differences made the same test contract harder to audit and maintain.

Why This Change Was Made

The existing src/test-utils/ports.ts owner now exports its IPv4-loopback TCP discovery and availability probes, and exact-contract callers reuse them. Helpers with different ownership or semantics remain local, including held-socket reservations, live server lifecycles, plugin/package/UI boundaries, preferred-port selection, and range scanning.

The shared helper binds port 0 on 127.0.0.1, closes before returning, rejects listen/address/close failures, and returns a port number. It intentionally does not promise that the port remains reserved after return.

User Impact

No user-visible product behavior changes. Test and tooling maintenance has one fewer duplicated free-port implementation path, with 84 net lines removed.

Evidence

  • node scripts/run-vitest.mjs src/plugin-sdk/provider-auth-runtime.test.ts src/commands/chutes-oauth.test.ts test/scripts/e2e-mock-config-limits.test.ts — 3 files / 23 tests passed.
  • Blacksmith Testbox tbx_01kwnf4dmknfx3bxhca58zt15jcheck:changed passed, including core/core-test/extension typechecks, lint, import cycles, and repository guards.
  • Autoreview: clean; no accepted/actionable findings, overall correctness patch is correct (0.96 confidence).
  • git diff --check — passed.
  • Build not run because no runtime module, package, lazy-import, generated output, or published boundary changed.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations size: S maintainer Maintainer-authored PR labels Jul 4, 2026
@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 10:37 PM ET / 02:37 UTC.

Summary
The PR exports getFreePort and isPortFree from src/test-utils/ports.ts and replaces duplicate bind-close free-port helpers in command, plugin SDK, gateway live, and script tests.

PR surface: Source 0, Tests -84. Total -84 across 5 files.

Reproducibility: not applicable. This PR is a cleanup refactor rather than a reported bug. The review path was source comparison of the helper contract, sibling helper boundaries, and the PR's focused validation evidence.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🌊 off-meta tidepool
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • No ClawSweeper repair lane is needed because the maintainer-labeled PR has no actionable findings from this review.

Security
Cleared: The diff only changes test files and a repo-internal test utility, with no dependency, workflow, lockfile, credential, or code-execution surface added.

Review details

Best possible solution:

Land the cleanup after normal required checks complete, keeping helpers with different lifecycle or ownership semantics local.

Do we have a high-confidence way to reproduce the issue?

Not applicable; this PR is a cleanup refactor rather than a reported bug. The review path was source comparison of the helper contract, sibling helper boundaries, and the PR's focused validation evidence.

Is this the best way to solve the issue?

Yes; exporting the existing root test utility is the narrowest maintainable solution for these exact duplicate bind-close helpers, while helpers with different semantics remain local.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against faa4f4782e76.

Label changes

Label changes:

  • add P3: This is a low-risk maintainer cleanup of test helper duplication with no user-facing runtime behavior change.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-labeled test-only cleanup, so the external-contributor real behavior proof gate does not apply.

Label justifications:

  • P3: This is a low-risk maintainer cleanup of test helper duplication with no user-facing runtime behavior change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-labeled test-only cleanup, so the external-contributor real behavior proof gate does not apply.
Evidence reviewed

PR surface:

Source 0, Tests -84. Total -84 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 4 5 89 -84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 8 92 -84

What I checked:

  • Shared helper export matches the old contract: At the PR head, src/test-utils/ports.ts exports isPortFree and getFreePort; getFreePort still binds port 0 on 127.0.0.1, reads the assigned TCP port, closes the server, and resolves only after close succeeds. (src/test-utils/ports.ts:18, 256eaeff50de)
  • Gateway derived-port semantics remain local: The gateway live test imports the shared helpers, but getFreeGatewayPort still owns the gateway-specific derived-port check for port, port + 1, port + 2, and port + 4. (src/gateway/gateway-models.profiles.live.test.ts:1951, 256eaeff50de)
  • Script-test import follows an existing test pattern: Repository tests already import utilities from src/test-utils, and the changed script test now uses that same repo-internal test utility path for the plain bind-close port allocation. (test/scripts/e2e-mock-config-limits.test.ts:9, 256eaeff50de)
  • Sibling helpers with different semantics were not collapsed: A focused helper search still shows separate helpers for deterministic gateway blocks, held live servers, package tests, and provider-local-service tests, which matches the PR body's stated boundary.
  • Patch validation is clean for whitespace and reported focused checks: git diff --check against the PR head produced no output, and the live PR body reports the focused Vitest command, Blacksmith Testbox tbx_01kwnf4dmknfx3bxhca58zt15j check:changed, autoreview, and git diff --check as passing. (256eaeff50de)
  • Port helper history: History shows Peter Steinberger introduced and later adjusted the deterministic port helper area, including test: stabilize gateway ports and timers and test: spread deterministic port blocks by process. (src/test-utils/ports.ts:44, 1a0d1cb7b23c)

Likely related people:

  • Peter Steinberger: Introduced and refined the deterministic port helper and gateway test helper behavior used as the central shared surface for this cleanup. (role: test port helper feature owner; confidence: high; commits: 1a0d1cb7b23c, 208398973baf, fc5a231e9578; files: src/test-utils/ports.ts, src/gateway/test-helpers.server.ts)
  • Vincent Koc: Recent history shows live gateway model profile test and src/test-utils/ports.ts work in the release smoke stabilization area touched by this PR. (role: recent live-gateway test contributor; confidence: medium; commits: e085fa1a3ffd; files: src/gateway/gateway-models.profiles.live.test.ts, src/test-utils/ports.ts)
  • Friederike Seiler: Added the Chutes OAuth tests whose local free-port helper is now replaced by the shared test utility. (role: introduced Chutes OAuth test surface; confidence: medium; commits: 4efb5cc18efa; files: src/commands/chutes-oauth.test.ts, src/agents/chutes-oauth.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 4, 2026
@RomneyDa
RomneyDa merged commit 7b2c515 into main Jul 4, 2026
148 of 156 checks passed
@RomneyDa
RomneyDa deleted the refactor/free-port-consolidation branch July 4, 2026 02:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant