From 10c288857d1f6eae0433fa932e7b5fcd48187d9a Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Fri, 20 Mar 2026 06:25:43 -0700 Subject: [PATCH] fix(support-cases): prevent auto-triage from regressing case status - Auto-triage previously always set status to 'triaged', even for cases already in in_progress, escalated, or other later states - Now only transitions to 'triaged' if case is still in 'open' state - Cases in later states keep their current status (only priority + tags update) - Added regression test for in_progress case - 10 support-cases tests passing --- .../src/modules/support-cases/routes.test.ts | 30 +++++++++++++++++++ .../src/modules/support-cases/routes.ts | 7 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/services/platform-service/src/modules/support-cases/routes.test.ts b/services/platform-service/src/modules/support-cases/routes.test.ts index f3ccc5c3..048e6653 100644 --- a/services/platform-service/src/modules/support-cases/routes.test.ts +++ b/services/platform-service/src/modules/support-cases/routes.test.ts @@ -225,6 +225,36 @@ describe('supportCaseRoutes', () => { expect(body.tagsAdded).toContain('category:billing'); }); + it('POST /support/cases/:id/auto-triage does not regress status of in-progress cases', async () => { + repoMock.getCase.mockResolvedValue({ + id: 'sup_4', + productId: 'lysnrai', + title: 'Error on login page', + description: 'Users see 500', + priority: 'medium', + status: 'in_progress', + tags: [], + }); + repoMock.updateCase.mockImplementation( + async (_id: string, _pid: string, updates: Record) => ({ + ...updates, + id: 'sup_4', + }) + ); + const app = await buildApp({ sub: 'admin_1', productId: 'lysnrai', role: 'admin' }); + + const res = await app.inject({ method: 'POST', url: '/api/support/cases/sup_4/auto-triage' }); + expect(res.statusCode).toBe(200); + const body = res.json(); + expect(body.newPriority).toBe('high'); + // Status should remain in_progress, not regress to triaged + expect(repoMock.updateCase).toHaveBeenCalledWith( + 'sup_4', + 'lysnrai', + expect.objectContaining({ status: 'in_progress' }) + ); + }); + it('POST /support/cases/:id/auto-triage handles undefined tags gracefully', async () => { repoMock.getCase.mockResolvedValue({ id: 'sup_3', diff --git a/services/platform-service/src/modules/support-cases/routes.ts b/services/platform-service/src/modules/support-cases/routes.ts index a7f9e647..a02a7fed 100644 --- a/services/platform-service/src/modules/support-cases/routes.ts +++ b/services/platform-service/src/modules/support-cases/routes.ts @@ -283,9 +283,14 @@ export async function supportCaseRoutes(app: FastifyInstance) { } const dedupedTags = [...new Set(tags)]; + // Only advance to 'triaged' if still in 'open' state — don't regress later statuses + const triageableStatuses = ['open']; + const statusUpdate = triageableStatuses.includes(supportCase.status) + ? 'triaged' + : supportCase.status; const updated = await repo.updateCase(id, access.productId, { priority: suggestedPriority as SupportCaseDoc['priority'], - status: 'triaged', + status: statusUpdate, tags: dedupedTags, });