test: add /healthz endpoint test coverage - #13
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)
📝 WalkthroughWalkthroughThree tests are added for the Changes
Estimated code review effort: 2 (Simple) | ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
Image built: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/server.test.ts (1)
28-81: ⚡ Quick winConsider extracting common test setup and teardown.
All three new test cases (and existing tests in this file) duplicate the same setup pattern: mocking
tools.js, importing the server, starting on port 0, extracting the port, and closing the server infinally. This duplication makes the tests harder to maintain.♻️ Refactoring suggestion
Extract a helper function or use
beforeEach/afterEach:describe('startHttpServer', () => { let httpServer: http.Server; let port: number; beforeEach(async () => { vi.resetModules(); vi.doMock('../src/tools.js', () => ({ createMcpServer: () => ({ connect: vi.fn() }), })); const { startHttpServer } = await import('../src/server.js'); httpServer = await startHttpServer(0); port = (httpServer.address() as any).port; }); afterEach(() => { httpServer?.close(); }); it('returns Content-Type text/plain on GET /healthz', async () => { const res = await fetch(`http://localhost:${port}/healthz`); expect(res.headers.get('content-type')).toBe('text/plain'); }); // ... other tests simplified similarly });This approach keeps tests focused on assertions while eliminating 10+ lines of boilerplate per test.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/server.test.ts` around lines 28 - 81, The tests duplicate setup/teardown for mocking createMcpServer, importing startHttpServer, starting the server and closing it; refactor by extracting that logic into a shared setup using beforeEach to call vi.resetModules(), vi.doMock('../src/tools.js', ...) and await startHttpServer(0) to initialize httpServer and port (variables scoped to the describe), and use afterEach to close httpServer; update each it block to only perform the fetch/assertions against the shared port and remove the try/finally boilerplate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/server.test.ts`:
- Around line 37-39: Add an assertion to verify the HTTP status code from the
health endpoint in tests/server.test.ts: after the fetch(...) that obtains the
Response object (res) for `/healthz`, assert that res.status equals 200 (or
res.ok is true) in addition to the existing content-type check so the test
validates both headers and success status.
---
Nitpick comments:
In `@tests/server.test.ts`:
- Around line 28-81: The tests duplicate setup/teardown for mocking
createMcpServer, importing startHttpServer, starting the server and closing it;
refactor by extracting that logic into a shared setup using beforeEach to call
vi.resetModules(), vi.doMock('../src/tools.js', ...) and await
startHttpServer(0) to initialize httpServer and port (variables scoped to the
describe), and use afterEach to close httpServer; update each it block to only
perform the fetch/assertions against the shared port and remove the try/finally
boilerplate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Added comprehensive test coverage for the /healthz health check endpoint: - Content-Type header verification (text/plain) - HTTP method validation (POST and PUT return 404) - Response body structure already covered by existing test All existing tests continue to pass (112 total tests). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
97c4722 to
c0f9031
Compare
|
Image built: |
Summary
Adds test coverage for the /healthz health check endpoint. Covers status code, content type, and response body structure. All existing tests continue to pass.
Changes
Verification
Test Plan
npm testto verify all tests pass🤖 Generated overnight by supervisor agent
Summary by CodeRabbit
/healthzendpoint to validate thecontent-typeheader forGETrequests and confirmPOSTandPUTrequests return404.