Skip to content

test: add /healthz endpoint test coverage - #13

Merged
akurinnoy merged 2 commits into
mainfrom
agent/healthz-tests-session-20260525-123033-4725
Jul 9, 2026
Merged

test: add /healthz endpoint test coverage#13
akurinnoy merged 2 commits into
mainfrom
agent/healthz-tests-session-20260525-123033-4725

Conversation

@akurinnoy

@akurinnoy akurinnoy commented May 25, 2026

Copy link
Copy Markdown
Contributor

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

  • Added 3 test cases for /healthz endpoint
  • Tests verify Content-Type header (text/plain)
  • Tests verify invalid HTTP methods return 404 (POST, PUT)

Verification

  • ✅ All 112 tests pass (109 existing + 3 new)
  • ✅ No implementation code modified
  • ✅ Signed commit

Test Plan

  • Run npm test to verify all tests pass

🤖 Generated overnight by supervisor agent

Summary by CodeRabbit

  • Tests
    • Expanded contract tests for the /healthz endpoint to validate the content-type header for GET requests and confirm POST and PUT requests return 404.

@akurinnoy
akurinnoy requested a review from tolusha as a code owner May 25, 2026 12:41
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65f97c0f-6f5a-46dd-93f5-7ca354cf444a

📥 Commits

Reviewing files that changed from the base of the PR and between 97c4722 and c0f9031.

📒 Files selected for processing (1)
  • tests/server.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/server.test.ts

📝 Walkthrough

Walkthrough

Three tests are added for the /healthz endpoint. They assert text/plain for GET responses and 404 for POST and PUT responses, each using an ephemeral server and cleanup in finally.

Changes

/healthz HTTP contract assertions

Layer / File(s) Summary
/healthz HTTP contract tests
tests/server.test.ts
GET /healthz now asserts content-type is text/plain, and POST and PUT requests to /healthz now assert 404, using the same server startup and cleanup pattern.

Estimated code review effort: 2 (Simple) | ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the added /healthz test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/healthz-tests-session-20260525-123033-4725

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Image built: quay.io/che-incubator/che-mcp-server:pr-13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/server.test.ts (1)

28-81: ⚡ Quick win

Consider 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 in finally. 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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aed06b7b-a25b-44f7-a108-49a5688fb41c

📥 Commits

Reviewing files that changed from the base of the PR and between 67d4b85 and 97c4722.

📒 Files selected for processing (1)
  • tests/server.test.ts

Comment thread tests/server.test.ts
akurinnoy and others added 2 commits July 9, 2026 23:49
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>
@akurinnoy
akurinnoy force-pushed the agent/healthz-tests-session-20260525-123033-4725 branch from 97c4722 to c0f9031 Compare July 9, 2026 20:51
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Image built: quay.io/che-incubator/che-mcp-server:pr-13

@akurinnoy
akurinnoy merged commit e1fc3d8 into main Jul 9, 2026
3 checks passed
@akurinnoy
akurinnoy deleted the agent/healthz-tests-session-20260525-123033-4725 branch July 9, 2026 21:01
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.

1 participant