From 60c1f9bec2ecec66d7f50dd2970468c3271acae4 Mon Sep 17 00:00:00 2001 From: Ricardo Amaral Date: Wed, 18 Nov 2026 11:12:05 +0000 Subject: [PATCH 1/3] fix: bump @todoist/comms-sdk to 6.0.0 `tdc comment delete` and `tdc msg delete` deleted the item and then exited 1 with a ZodError. The API now returns the deleted entity instead of `{ "status": "ok" }`, and the old SDK failed to parse it. SDK 6.0.0 resolves delete calls on any 2xx without reading the body. Fixes todoist/comms-cli#113 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index a37d9e7..f2e5a37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "dependencies": { "@pnpm/tabtab": "0.5.4", "@todoist/cli-core": "2.0.0", - "@todoist/comms-sdk": "5.2.2", + "@todoist/comms-sdk": "6.0.0", "chalk": "5.6.2", "commander": "14.0.3", "marked": "18.0.3", @@ -2717,9 +2717,9 @@ } }, "node_modules/@todoist/comms-sdk": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/@todoist/comms-sdk/-/comms-sdk-5.2.2.tgz", - "integrity": "sha512-u2SGZzAAgmw1u1XkzTg5NNvZlLlygLxra7PP9UtTFmG8dafoCPLnBcxKgBHStDiRJnFbP6dp60Yl3islNuEwsw==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@todoist/comms-sdk/-/comms-sdk-6.0.0.tgz", + "integrity": "sha512-77YgBt4pozOjA5mqvHOGpQF3/KgsU7Ne7j7WUInhgEnvW7P1rpfb6di3hGSUI/t0ojnpus4IZmO252Z/URGvog==", "license": "MIT", "dependencies": { "@doist/sdk-kmp": "0.6.0", diff --git a/package.json b/package.json index dffc205..aefc589 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "dependencies": { "@pnpm/tabtab": "0.5.4", "@todoist/cli-core": "2.0.0", - "@todoist/comms-sdk": "5.2.2", + "@todoist/comms-sdk": "6.0.0", "chalk": "5.6.2", "commander": "14.0.3", "marked": "18.0.3", From 676d424def413c8f7c07c5cd646232ee5b4c7f7e Mon Sep 17 00:00:00 2001 From: Ricardo Amaral Date: Wed, 18 Nov 2026 11:32:36 +0000 Subject: [PATCH 2/3] test: cover delete commands against the real SDK Run comment delete and msg delete through CommsApi with a customFetch answering with the deleted entity, so they fail on @todoist/comms-sdk 5.2.2 and pass on 6.0.0. Refs #113 --- src/commands/comment/comment.test.ts | 37 ++++++++++++++++++++++++++++ src/commands/msg/msg.test.ts | 35 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/commands/comment/comment.test.ts b/src/commands/comment/comment.test.ts index 10a9956..16ed7c5 100644 --- a/src/commands/comment/comment.test.ts +++ b/src/commands/comment/comment.test.ts @@ -1,4 +1,5 @@ import { captureConsole, createTestProgram, mockStdin } from '@todoist/cli-core/testing' +import { CommsApi, type CustomFetch } from '@todoist/comms-sdk' import { beforeEach, describe, expect, it, vi } from 'vitest' const apiMocks = vi.hoisted(() => ({ @@ -231,6 +232,42 @@ describe('comment delete', () => { expect(consoleSpy).toHaveBeenCalledWith('Comment 300 deleted.') }) + it('succeeds when the API answers the delete with the deleted comment', async () => { + const deleted = { + id: '300', + thread_id: 'TH500', + channel_id: 'CH100', + workspace_id: 10, + creator: 1, + content: '-', + posted_ts: 1772409600, + deleted: true, + deleted_by: 1, + version: 1, + reactions: {}, + } + const customFetch = vi.fn().mockResolvedValue({ + ok: true, + status: 200, + statusText: 'OK', + headers: {}, + text: async () => JSON.stringify(deleted), + json: async () => deleted, + }) + const client = new CommsApi('test-token', { customFetch }) + vi.spyOn(client.comments, 'getComment').mockResolvedValue( + createCommentFixture('300') as never, + ) + vi.spyOn(client.users, 'getSessionUser').mockResolvedValue({ id: 1 } as never) + apiMocks.getCommsClient.mockResolvedValue(client) + const consoleSpy = captureConsole('log') + + await createProgram().parseAsync(['node', 'tdc', 'comment', 'delete', '300', '--yes']) + + expect(customFetch).toHaveBeenCalledTimes(1) + expect(consoleSpy).toHaveBeenCalledWith('Comment 300 deleted.') + }) + it('prompts for confirmation without --yes', async () => { const client = createClient() apiMocks.getCommsClient.mockResolvedValue(client) diff --git a/src/commands/msg/msg.test.ts b/src/commands/msg/msg.test.ts index 6fddfc5..faaafcd 100644 --- a/src/commands/msg/msg.test.ts +++ b/src/commands/msg/msg.test.ts @@ -1,4 +1,5 @@ import { captureConsole, createTestProgram, mockStdin } from '@todoist/cli-core/testing' +import { CommsApi, type CustomFetch } from '@todoist/comms-sdk' import { beforeEach, describe, expect, it, vi } from 'vitest' const apiMocks = vi.hoisted(() => ({ @@ -93,6 +94,40 @@ describe('msg delete', () => { expect(consoleSpy).toHaveBeenCalledWith('Message 200 deleted.') }) + it('succeeds when the API answers the delete with the deleted message', async () => { + const deleted = { + id: '200', + conversation_id: 'CV42', + workspace_id: 10, + creator: 1, + content: '-', + posted_ts: 1772409600, + deleted: true, + deleted_by: 1, + version: 1, + } + const customFetch = vi.fn().mockResolvedValue({ + ok: true, + status: 200, + statusText: 'OK', + headers: {}, + text: async () => JSON.stringify(deleted), + json: async () => deleted, + }) + const client = new CommsApi('test-token', { customFetch }) + vi.spyOn(client.conversationMessages, 'getMessage').mockResolvedValue( + createMessageFixture('200') as never, + ) + vi.spyOn(client.users, 'getSessionUser').mockResolvedValue({ id: 1 } as never) + apiMocks.getCommsClient.mockResolvedValue(client) + const consoleSpy = captureConsole('log') + + await createProgram().parseAsync(['node', 'tdc', 'msg', 'delete', '200', '--yes']) + + expect(customFetch).toHaveBeenCalledTimes(1) + expect(consoleSpy).toHaveBeenCalledWith('Message 200 deleted.') + }) + it('prompts for confirmation without --yes', async () => { const client = createClient() apiMocks.getCommsClient.mockResolvedValue(client) From 5528b084e8b0cc59a6bb43017c27f20bd405fb8e Mon Sep 17 00:00:00 2001 From: Ricardo Amaral Date: Wed, 18 Nov 2026 11:43:00 +0000 Subject: [PATCH 3/3] test: share the customFetch stub for the real-SDK command tests Move the fake 200 response into mockJsonFetch so the thread, comment and msg tests no longer each carry their own copy. --- src/commands/comment/comment.test.ts | 12 +++--------- src/commands/msg/msg.test.ts | 12 +++--------- src/commands/thread/thread.test.ts | 12 +++--------- src/lib/__fixtures__/custom-fetch.ts | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 src/lib/__fixtures__/custom-fetch.ts diff --git a/src/commands/comment/comment.test.ts b/src/commands/comment/comment.test.ts index 16ed7c5..a971e56 100644 --- a/src/commands/comment/comment.test.ts +++ b/src/commands/comment/comment.test.ts @@ -1,6 +1,7 @@ import { captureConsole, createTestProgram, mockStdin } from '@todoist/cli-core/testing' -import { CommsApi, type CustomFetch } from '@todoist/comms-sdk' +import { CommsApi } from '@todoist/comms-sdk' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { mockJsonFetch } from '../../lib/__fixtures__/custom-fetch.js' const apiMocks = vi.hoisted(() => ({ getCommsClient: vi.fn(), @@ -246,14 +247,7 @@ describe('comment delete', () => { version: 1, reactions: {}, } - const customFetch = vi.fn().mockResolvedValue({ - ok: true, - status: 200, - statusText: 'OK', - headers: {}, - text: async () => JSON.stringify(deleted), - json: async () => deleted, - }) + const customFetch = mockJsonFetch(deleted) const client = new CommsApi('test-token', { customFetch }) vi.spyOn(client.comments, 'getComment').mockResolvedValue( createCommentFixture('300') as never, diff --git a/src/commands/msg/msg.test.ts b/src/commands/msg/msg.test.ts index faaafcd..b28dbd7 100644 --- a/src/commands/msg/msg.test.ts +++ b/src/commands/msg/msg.test.ts @@ -1,6 +1,7 @@ import { captureConsole, createTestProgram, mockStdin } from '@todoist/cli-core/testing' -import { CommsApi, type CustomFetch } from '@todoist/comms-sdk' +import { CommsApi } from '@todoist/comms-sdk' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { mockJsonFetch } from '../../lib/__fixtures__/custom-fetch.js' const apiMocks = vi.hoisted(() => ({ getCommsClient: vi.fn(), @@ -106,14 +107,7 @@ describe('msg delete', () => { deleted_by: 1, version: 1, } - const customFetch = vi.fn().mockResolvedValue({ - ok: true, - status: 200, - statusText: 'OK', - headers: {}, - text: async () => JSON.stringify(deleted), - json: async () => deleted, - }) + const customFetch = mockJsonFetch(deleted) const client = new CommsApi('test-token', { customFetch }) vi.spyOn(client.conversationMessages, 'getMessage').mockResolvedValue( createMessageFixture('200') as never, diff --git a/src/commands/thread/thread.test.ts b/src/commands/thread/thread.test.ts index 2141eb6..9fd05f8 100644 --- a/src/commands/thread/thread.test.ts +++ b/src/commands/thread/thread.test.ts @@ -7,8 +7,9 @@ import { createTestProgram, mockStdin, } from '@todoist/cli-core/testing' -import { CommsApi, type CustomFetch, generateId } from '@todoist/comms-sdk' +import { CommsApi, generateId } from '@todoist/comms-sdk' import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' +import { mockJsonFetch } from '../../lib/__fixtures__/custom-fetch.js' const apiMocks = vi.hoisted(() => ({ getCommsClient: vi.fn(), @@ -409,14 +410,7 @@ describe.each(['reply', 'close', 'reopen'] as const)('thread %s notifications', creator: 2, posted_ts: 1772409600, } - const customFetch = vi.fn().mockResolvedValue({ - ok: true, - status: 200, - statusText: 'OK', - headers: {}, - text: async () => JSON.stringify(comment), - json: async () => comment, - }) + const customFetch = mockJsonFetch(comment) const client = new CommsApi('test-token', { customFetch }) vi.spyOn(client.threads, 'getThread').mockResolvedValue({ ...createThreadFixture(threadId), diff --git a/src/lib/__fixtures__/custom-fetch.ts b/src/lib/__fixtures__/custom-fetch.ts new file mode 100644 index 0000000..6ed24a1 --- /dev/null +++ b/src/lib/__fixtures__/custom-fetch.ts @@ -0,0 +1,19 @@ +import type { CustomFetch } from '@todoist/comms-sdk' +import { vi } from 'vitest' + +/** + * Builds a `customFetch` stub that answers every request with a 200 and the given JSON body, to run + * the real SDK client without a network. + * + * @param body - The raw wire payload (snake_case, `*_ts` epoch seconds) to answer with. + */ +export function mockJsonFetch(body: unknown) { + return vi.fn().mockResolvedValue({ + ok: true, + status: 200, + statusText: 'OK', + headers: {}, + text: async () => JSON.stringify(body), + json: async () => body, + }) +}