From fe45dd6dde04a20f560d8a0ada66772be732987e Mon Sep 17 00:00:00 2001 From: zbigniew sobiecki Date: Fri, 6 Mar 2026 14:41:08 +0100 Subject: [PATCH] fix(gadgets): add logging when progress comment update fails Previously, when `cascade-tools pm post-comment` attempted to update an existing progress comment and failed, the error was silently swallowed with no logging, making debugging production failures impossible. This adds WARN level logging to the catch block in postComment.ts, matching the pattern used in PMProgressPoster (pmPoster.ts). The log includes workItemId, commentId, and error message for debugging. Co-Authored-By: Claude Opus 4.5 --- src/gadgets/pm/core/postComment.ts | 8 +++++++- tests/unit/gadgets/pm/core/postComment.test.ts | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/gadgets/pm/core/postComment.ts b/src/gadgets/pm/core/postComment.ts index 467a6f13..bc244037 100644 --- a/src/gadgets/pm/core/postComment.ts +++ b/src/gadgets/pm/core/postComment.ts @@ -1,5 +1,6 @@ import { clearProgressCommentId, readProgressCommentId } from '../../../backends/progressState.js'; import { getPMProvider } from '../../../pm/index.js'; +import { logger } from '../../../utils/logging.js'; export async function postComment(workItemId: string, text: string): Promise { try { @@ -12,8 +13,13 @@ export async function postComment(workItemId: string, text: string): Promise ({ clearProgressCommentId: vi.fn(), })); +vi.mock('../../../../../src/utils/logging.js', () => ({ + logger: { + warn: vi.fn(), + }, +})); + import { clearProgressCommentId, readProgressCommentId, } from '../../../../../src/backends/progressState.js'; import { postComment } from '../../../../../src/gadgets/pm/core/postComment.js'; +import { logger } from '../../../../../src/utils/logging.js'; const mockReadProgressCommentId = vi.mocked(readProgressCommentId); const mockClearProgressCommentId = vi.mocked(clearProgressCommentId); +const mockLogger = vi.mocked(logger); beforeEach(() => { mockReadProgressCommentId.mockReturnValue(null); @@ -103,6 +111,14 @@ describe('postComment', () => { 'comment-42', 'Final summary', ); + expect(mockLogger.warn).toHaveBeenCalledWith( + 'Failed to update progress comment, creating new one', + expect.objectContaining({ + workItemId: 'item1', + commentId: 'comment-42', + error: 'Comment not found', + }), + ); expect(mockProvider.addComment).toHaveBeenCalledWith('item1', 'Final summary'); expect(mockClearProgressCommentId).toHaveBeenCalled(); expect(result).toBe('Comment posted successfully');