test(mcp): restore SupermemoryClient coverage and fix two blank error messages - #1564
test(mcp): restore SupermemoryClient coverage and fix two blank error messages#1564addyCooks wants to merge 1 commit into
Conversation
|
Nice to see coverage here — #1550 has been open a while. One thing worth catching before this lands: const signal = options?.signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS)That It's the same defect as #1549 in signal: options?.signal
? AbortSignal.any([options.signal, AbortSignal.timeout(FETCH_TIMEOUT_MS)])
: AbortSignal.timeout(FETCH_TIMEOUT_MS),No production caller in Not asking you to expand scope here. Happy to send the |
… 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.
017a80b to
5eeebec
Compare
|
Hey @Agnik47! Sanity-checked both directions the old |
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