test: cover tool-handler request-shaping and response-mapping logic - #48
Merged
Conversation
The MCP tool surface (index.ts) was registered and smoke-tested but each handler's own logic — default-value shaping of outbound requests and mapping of client responses into MCP content — was never actually invoked by a test. Only the client-level getBaseUrl/cleanEnv helpers had coverage. Adds one node:test file per tool handler (createPtoRequest, listRequests, getRequest, cancelRequest, teamCalendar), using node:test's experimental mock.module() to substitute afkbotClient.ts's exported functions and invoking each handler directly. Verified working on both Node 20.20.2 and 22.23.2 (the CI matrix) with --experimental-test-module-mocks. Also wires `npm test` into ci.yml — it previously ran lint/build/docker build only, so the pre-existing client tests were never enforced by CI either. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
create_pto_request,list_pto_requests,get_pto_request,cancel_pto_request,team_calendar) whose surface was wired insrc/index.tsand covered by external smoke/mcp-assert checks, but none of the individual handler functions insrc/tools/*.tswere ever invoked by a test. The only existing test file (src/client/afkbotClient.test.ts) covers the client-levelgetBaseUrl/cleanEnvhelpers, not the handlers.node --testrunner (not Vitest, unlike most of the fleet's other*-mcprepos) — confirmed viapackage.json'stestscript and the existing test file's conventions (node:test+node:assert/strict,.test.tsco-located next to source, compiled bytscintodist/**/*.test.js).createPtoRequest.test.ts,listRequests.test.ts,getRequest.test.ts,cancelRequest.test.ts,teamCalendar.test.ts. Each mocks the underlyingafkbotClient.tsexports vianode:test'smock.module(), invokes the exported handler directly, and asserts both the outbound call shape (e.g.end_datedefaulting tostart_date,status: "all"becomingundefined,limitdefaulting to 25) and the response transformation (JSON-wrappedcontentpayload,team_calendar's summary mapping and empty-state message).mock.module()is experimental and needs--experimental-test-module-mocks; added that flag to thetestscript. Verified working on both Node 20.20.2 and 22.23.2 (the CI matrix versions) before relying on it.ci.ymlpreviously rannpm ci/npm run lint/npm run build/docker buildonly — it never actually rannpm test, so the pre-existing client tests weren't enforced either. Addednpm testas a CI step so this (and future) coverage is gated, not just present.Noted, not fixed (scope discipline — flagging, not changing)
listRequests.ts:limit: params.limit || 25will silently override an explicitlimit: 0with 25, since0is falsy. Probably harmless in practice (nobody wants zero results) but it's a real||vs??bug if anyone ever relies onlimit: 0.dist/bytsc(pertsconfig.json'sinclude: ["src/**/*"]) and the Dockerfile copies the wholedist/directory into the production image, so compiled test files ship in the runtime image. This was already true before this PR (the existingafkbotClient.test.tsalready had this property) — not introduced or changed here.Test plan
npm run build(tsc) — clean on Node 20.20.2 and 22.23.2npm run lint(tsc --noEmit) — clean on bothnpm test— 23/23 passing on both Node 20.20.2 and 22.23.2docker build -t afkbot-mcp:test .— succeedsNote on repo location
The task that generated this PR assumed
afkbot-mcphad migrated to theWYRE-AIGitHub org (per the 2026-08-24/25 org migration covering the other*-mcprepos). Verified this repo has not migrated —WYRE-AI/afkbot-mcp404s; the live, non-archived, non-fork repo is stillwyre-technology/afkbot-mcp. This PR is opened against the actual current location.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is enabled.