test(mcp): restore SupermemoryClient coverage and fix two blank error messages - #1564
Open
addyCooks wants to merge 1 commit into
Open
test(mcp): restore SupermemoryClient coverage and fix two blank error messages#1564addyCooks wants to merge 1 commit into
addyCooks wants to merge 1 commit into
Conversation
… messages supermemoryai#1406 shipped the API-error unwrapping and the status-aware handleError fallbacks with a test file that had already been deleted in supermemoryai#1397, so SupermemoryClient - every outbound API call, extractApiErrorMessage, and all of handleError - had no coverage at all. Restores src/server/client/index.test.ts with 53 cases covering the SDK wiring, space scoping, result normalisation, forgetMemory's exact-match and similarity fallbacks, the raw-fetch endpoints, and the full status table. Two of those cases failed against the untested code: - A 403 whose body is {"error": ""} leaked the raw JSON envelope to the user, because extractApiErrorMessage falls through to the raw string when the recognised key holds an empty value. An envelope we parsed but that carries no message now yields undefined so the caller reaches its scope-aware fallback. - A status outside the mapped switch (409, 413, ...) with an empty body reached the user as an Error with an empty message. Unmapped statuses with no message now report the status instead.
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.
Closes #1550
src/server/client/index.test.tswas deleted in a99cf4f (#1397). Ten dayslater #1406 added the API-error unwrapping and the status-aware
handleErrorfallbacks and claimed tests for them, but the file was never restored so
SupermemoryClient, which owns every outbound Supermemory API call, had nocoverage at all.
Tests restored
53 cases in
src/server/client/index.test.ts, with thesupermemorySDK andfetchboth stubbed:x-sm-sourceheaderexplicit override wins, empty string is treated as unscoped
memory/chunk/context/contentprecedence,chunk results stay distinguishable, 200k-char truncation
forgetMemoryexact match, 404 → similarity-search fallback, no match,chunks-only, non-404 errors do not fall back
signal, zod contract violations
Errorthrows, and the"<operation> failed: …"prefixesIncludes the two cases #1406 described: a 403 with a JSON error body surfaces
the API's message, and an empty-body 403 gets the scope-aware fallback.
Two fixes the tests forced (+2 lines in
index.ts){"error": ""}leaked raw JSON to the user.extractApiErrorMessagereturns the raw string when the recognised key holdsan empty value, so the user saw
{"error":""}. A parsed envelope carrying nomessage now returns
undefinedand the caller reaches its fallback.409/413/etc. fall past the
switch, andgetDocuments/listMemoryEntriesconstruct
new Error("")when the body is empty, so the user got nothing.Unmapped statuses with no message now report the status.
Verification
vitest run src5 files, 74 tests passed (was 4 files, 21 tests)tsc --noEmit -p tsconfig.jsonclean, Biome clean