refactor: consolidate free-port test helpers#99771
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 10:37 PM ET / 02:37 UTC. Summary 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 follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Next step before merge
Security Review detailsBest 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 changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source 0, Tests -84. Total -84 across 5 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
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.tsowner 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
0on127.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.tbx_01kwnf4dmknfx3bxhca58zt15j—check:changedpassed, including core/core-test/extension typechecks, lint, import cycles, and repository guards.patch is correct(0.96 confidence).git diff --check— passed.