test(e2e): unix domain socket (uds/ipc)#1208
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Vitest end-to-end test that starts an Express target server listening on a Unix Domain Socket and a proxy Express server that forwards to that socket, then issues an HTTP GET to the proxy at /hello and asserts a 200 JSON response { ok: true }. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
87ec318 to
36c0944
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/e2e/unix-domain-socket.spec.ts`:
- Around line 57-62: The test is using proxyServer.server.address()
(AddressInfo) to build a URL which can return wildcard bind addresses like '::'
or '0.0.0.0'; instead pass the actual Node http.Server instance directly into
Supertest's request() so it handles binding and ports for you. Replace the usage
of address/AddressInfo and change the call from
request(`http://[${address.address}]:${address.port}`) to
request(proxyServer.server) and then call .get('/hello').expect(200); this
removes the brittle address lookup and uses proxyServer.server as the target for
Supertest.
- Around line 19-24: The helper functions startTargetServer and startProxyServer
call server.listen(...) but return immediately, causing a race where
server.address() may be called before binding completes; change both helpers to
await the 'listening' event (e.g. using events.once(server, 'listening')) after
calling listen(…) so they only return once bound, and update the async disposal
close logic (targetServer.close and proxyServer.close) to propagate errors by
rejecting the Promise if the close callback receives an error instead of always
resolving.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 27bd4c69-d24c-443e-a168-4d613ab11e14
📒 Files selected for processing (1)
test/e2e/unix-domain-socket.spec.ts
There was a problem hiding this comment.
♻️ Duplicate comments (2)
test/e2e/unix-domain-socket.spec.ts (2)
59-64:⚠️ Potential issue | 🟡 MinorPass the server directly to Supertest.
server.address().addresscan be a wildcard bind address like::or0.0.0.0, and the bracketed URL assumes IPv6 formatting. Supertest can target the server instance directly, avoiding this brittle address lookup. This was previously flagged and still applies.Proposed fix
-import type { AddressInfo } from 'node:net'; @@ - const address = proxyServer.server.address() as AddressInfo; - // ACT - const response = await request(`http://[${address.address}]:${address.port}`) + const response = await request(proxyServer.server) .get('/hello') .expect(200);Verification:
Does Supertest's request() function accept a Node.js http.Server instance directly?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/e2e/unix-domain-socket.spec.ts` around lines 59 - 64, The test is brittle because it constructs a bracketed URL from proxyServer.server.address() (variable address) which can be a wildcard like :: or 0.0.0.0; instead pass the server instance directly to Supertest. Replace the use of address/address.port and the template URL in the request(...) call with request(proxyServer.server) (keeping the subsequent .get('/hello').expect(200)), and remove the earlier const address = proxyServer.server.address() as AddressInfo since it's no longer needed.
21-27:⚠️ Potential issue | 🟠 MajorWait for both servers to bind and propagate close errors.
listen()returns before the server is guaranteed to be bound, so the test can race with startup. The close callbacks also always resolve, hiding teardown errors. This remains the same lifecycle issue previously flagged.Proposed fix
+import { once } from 'node:events'; import { randomUUID } from 'node:crypto'; import type { AddressInfo } from 'node:net'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; @@ - const targetServer = app.listen(socketPath); + const targetServer = app.listen(socketPath); + await once(targetServer, 'listening'); @@ - await new Promise<void>((resolve, reject) => { - targetServer.close(() => resolve()); + await new Promise<void>((resolve, reject) => { + targetServer.close((error) => (error ? reject(error) : resolve())); }); @@ - const proxyServer = createApp(proxyMiddleware).listen(0); + const proxyServer = createApp(proxyMiddleware).listen(0); + await once(proxyServer, 'listening'); @@ - await new Promise<void>((resolve, reject) => { - proxyServer.close(() => resolve()); + await new Promise<void>((resolve, reject) => { + proxyServer.close((error) => (error ? reject(error) : resolve())); });Verification:
#!/bin/bash # Confirm both listen() calls are followed by readiness waits and close callbacks propagate errors. rg -n -C3 'listen\(|Symbol\.asyncDispose|close\(' test/e2e/unix-domain-socket.spec.tsAlso applies to: 39-46
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/e2e/unix-domain-socket.spec.ts` around lines 21 - 27, The test races on startup and hides teardown errors: ensure both app.listen(...) calls wait for the server to be actually bound (use the listen callback or await the 'listening' event for the server returned as targetServer and the other server) before proceeding, and update the Symbol.asyncDispose close logic so the close callback rejects on error (propagate any error passed into the close callback instead of always resolving) so teardown failures surface; apply the same listen/readiness and close-error propagation changes for the other server instance referenced in this spec.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@test/e2e/unix-domain-socket.spec.ts`:
- Around line 59-64: The test is brittle because it constructs a bracketed URL
from proxyServer.server.address() (variable address) which can be a wildcard
like :: or 0.0.0.0; instead pass the server instance directly to Supertest.
Replace the use of address/address.port and the template URL in the request(...)
call with request(proxyServer.server) (keeping the subsequent
.get('/hello').expect(200)), and remove the earlier const address =
proxyServer.server.address() as AddressInfo since it's no longer needed.
- Around line 21-27: The test races on startup and hides teardown errors: ensure
both app.listen(...) calls wait for the server to be actually bound (use the
listen callback or await the 'listening' event for the server returned as
targetServer and the other server) before proceeding, and update the
Symbol.asyncDispose close logic so the close callback rejects on error
(propagate any error passed into the close callback instead of always resolving)
so teardown failures surface; apply the same listen/readiness and close-error
propagation changes for the other server instance referenced in this spec.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c0316260-5f4e-45e2-be93-713dd7eb0dc7
📒 Files selected for processing (1)
test/e2e/unix-domain-socket.spec.ts
36c0944 to
c4f50e0
Compare
add e2e test for unix domain socket
related: #434
Summary by CodeRabbit