From 549fce4689d08ec547d2d85f89f7e8013dc24279 Mon Sep 17 00:00:00 2001 From: iliya Date: Mon, 23 Mar 2026 16:29:19 +0200 Subject: [PATCH] fix(tests): enhance messageId handling for legacy inbox rows - Updated tests to ensure legacy inbox rows without messageId generate a deterministic hash-based messageId. - Modified test descriptions for clarity and accuracy regarding messageId generation. - Adjusted expectations in tests to reflect the new behavior of relaying legacy lead inbox rows with generated messageIds. --- .../services/team/TeamInboxReader.test.ts | 14 ++++++++++---- .../team/TeamProvisioningServiceRelay.test.ts | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/test/main/services/team/TeamInboxReader.test.ts b/test/main/services/team/TeamInboxReader.test.ts index 73539b91..eea67418 100644 --- a/test/main/services/team/TeamInboxReader.test.ts +++ b/test/main/services/team/TeamInboxReader.test.ts @@ -119,7 +119,7 @@ describe('TeamInboxReader', () => { expect(merged[1].text).toBe('older'); }); - it('ignores legacy inbox rows without messageId', async () => { + it('generates deterministic messageId for legacy inbox rows without messageId', async () => { hoisted.files.set( '/mock/teams/my-team/inboxes/alice.json', JSON.stringify([ @@ -140,8 +140,14 @@ describe('TeamInboxReader', () => { ); const messages = await reader.getMessagesFor('my-team', 'alice'); - expect(messages).toHaveLength(1); - expect(messages[0].text).toBe('supported'); - expect(messages[0].messageId).toBe('m-1'); + expect(messages).toHaveLength(2); + // Legacy row gets a deterministic hash-based messageId + const legacy = messages.find((m) => m.text === 'legacy'); + expect(legacy).toBeDefined(); + expect(legacy!.messageId).toMatch(/^inbox-[a-f0-9]{16}$/); + // Explicit messageId is preserved + const supported = messages.find((m) => m.text === 'supported'); + expect(supported).toBeDefined(); + expect(supported!.messageId).toBe('m-1'); }); }); diff --git a/test/main/services/team/TeamProvisioningServiceRelay.test.ts b/test/main/services/team/TeamProvisioningServiceRelay.test.ts index 38b65822..ac8f5623 100644 --- a/test/main/services/team/TeamProvisioningServiceRelay.test.ts +++ b/test/main/services/team/TeamProvisioningServiceRelay.test.ts @@ -368,7 +368,7 @@ describe('TeamProvisioningService relayLeadInboxMessages', () => { expect(writeSpy).toHaveBeenCalledTimes(1); }); - it('ignores unread lead inbox rows without messageId', async () => { + it('relays legacy lead inbox rows with generated messageId', async () => { const service = new TeamProvisioningService(); const teamName = 'my-team'; seedConfig(teamName); @@ -382,11 +382,18 @@ describe('TeamProvisioningService relayLeadInboxMessages', () => { ]); const { writeSpy } = attachAliveRun(service, teamName); - const relayed = await service.relayLeadInboxMessages(teamName); + const relayPromise = service.relayLeadInboxMessages(teamName); + const run = await waitForCapture(service); + expect(run?.leadRelayCapture).toBeTruthy(); + (service as any).handleStreamJsonMessage(run, { + type: 'assistant', + content: [{ type: 'text', text: 'Ok.' }], + }); + (service as any).handleStreamJsonMessage(run, { type: 'result', subtype: 'success' }); + const relayed = await relayPromise; - expect(relayed).toBe(0); - expect(writeSpy).toHaveBeenCalledTimes(0); - expect(hoisted.appendSentMessage).not.toHaveBeenCalled(); + expect(relayed).toBe(1); + expect(writeSpy).toHaveBeenCalledTimes(1); }); it('resolves cross-team reply metadata only for a single matching team hint', async () => { @@ -625,7 +632,7 @@ describe('TeamProvisioningService relayLeadInboxMessages', () => { expect(payload).toContain('"type":"user"'); expect(payload).toContain('recipient=\\"alice\\"'); expect(payload).toContain('Source: system_notification'); - expect(payload).toContain('Forward that automated notification exactly once;'); + expect(payload).toContain('forward that notification exactly once without paraphrasing'); expect(payload).toContain('Please retry with logging enabled.'); });