feat(mcp): extract pure utilities and add unit tests#158
Conversation
|
I have read the CLA Document and I hereby sign the CLA |
|
Hi @Vswaroop04 , thank you for your contribution! Commit 004f6f5 is unsigned - please rebase and sign before re-review. Three minor things while you're at it: Misleading test description resolveInstanceId silently swallows an empty-string override |
Pull isJsonResponse, isLicenseError, licenseErrorResult, resolveInstanceId, buildQuery, formatProposalText, getArgValue, and parseErrorResponse into utils.ts so they can be exercised in isolation. index.ts now imports from utils.ts and uses thin local wrappers for state-dependent variants. Adds vitest to the package and 40+ unit tests covering all extracted utilities, including edge cases for auth header building, prefix detection response parsing, query string construction, and proposal text formatting.
004f6f5 to
16f6dbd
Compare
- Encode keys as well as values in buildQuery - Throw a clear error when resolveInstanceId override is empty string - Split misleading test and add coverage for key encoding and empty override
| } | ||
|
|
||
| export function resolveInstanceId(activeInstanceId: string | null, overrideId?: string): string { | ||
| if (overrideId !== undefined && overrideId !== null && overrideId === '') { |
There was a problem hiding this comment.
The first 2 checks are redundant because of the third
KIvanow
left a comment
There was a problem hiding this comment.
One small very minor issue with redundant checks
Done |
5b43bf8 to
2154f8e
Compare
Summary
Extracted 8 pure utility functions from the monolithic
packages/mcp/src/index.tsinto a newsrc/utils.tsmodule:isJsonResponseisLicenseErrorlicenseErrorResultresolveInstanceIdbuildQueryformatProposalTextgetArgValueparseErrorResponseUpdated
index.tsto import fromutils.tswhile keeping thin local wrappers around the utilities so all existing call-site signatures remain unchanged and behaviour stays the same.Added Vitest to the package along with 40+ unit tests covering:
Why
The existing
index.tsfile had grown to ~1,260 lines with no automated test coverage. Extracting the stateless logic into a separate module was the smallest safe refactor that made unit testing possible without triggering top-levelawaitside effects during imports.Test Plan
cd packages/mcp && pnpm install && pnpm testpnpm buildstill succeeds