From 700918d533d170183382974ce140a77e4a5a75f1 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 13:04:52 +0000 Subject: [PATCH] test(packing): pin the bag-totals ping in the RPC and MCP fan-out expectations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three plugin-RPC tests and the MCP bulk-import test assert the exact list of broadcasts a write produces, so adding the #2191 weight ping to those two surfaces made them fail — correctly: they are the contract for who hears what. Updated to include it, and asserting it rather than just tolerating it. The private-item cases are the interesting ones: the item event still reaches only its viewers while the weight ping goes to the whole room, which is precisely what makes a content-free ping safe there. The bulk import gets one ping for the whole import rather than one per item. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01S5VwmiBQ9sPCJwfmpv64r3 --- .../tests/unit/mcp/tools-packing-advanced.test.ts | 6 +++++- server/tests/unit/packing/packing.rpc.test.ts | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/tests/unit/mcp/tools-packing-advanced.test.ts b/server/tests/unit/mcp/tools-packing-advanced.test.ts index 0fa111948..8fa1cf15d 100644 --- a/server/tests/unit/mcp/tools-packing-advanced.test.ts +++ b/server/tests/unit/mcp/tools-packing-advanced.test.ts @@ -565,7 +565,11 @@ describe('Tool: bulk_import_packing', () => { expect(data.items).toHaveLength(items.length); expect(data.items[0].name).toBe('Passport'); expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'packing:created', expect.objectContaining({ item: expect.any(Object) })); - expect(broadcastMock).toHaveBeenCalledTimes(items.length); + // Plus ONE bag-totals ping for the whole import (#2191) — not one per + // item: it is content-free and each one costs every connected client a + // listBags round trip. + expect(broadcastMock).toHaveBeenCalledWith(String(trip.id), 'packing:bag-totals', {}, undefined); + expect(broadcastMock).toHaveBeenCalledTimes(items.length + 1); }); }); diff --git a/server/tests/unit/packing/packing.rpc.test.ts b/server/tests/unit/packing/packing.rpc.test.ts index 451a65f03..f94b7d3fa 100644 --- a/server/tests/unit/packing/packing.rpc.test.ts +++ b/server/tests/unit/packing/packing.rpc.test.ts @@ -199,16 +199,25 @@ describe('PackingRpc keeps private items off the room (#858)', () => { it('PACKING-RPC-009 a common item is created for the whole room', async () => { const f = build(); await f.host('db:write:packing').dispatch(req('packing.create', { tripId: 1, input: { name: 'Socks' } }), 42); - expect(fanout(f.realtime)).toEqual([['packing:created', undefined]]); + // The trailing bag-totals ping is room-wide and content-free (#2191): bag + // weights are summed server-side, so every member has to re-read them even + // when the item itself is none of their business. + expect(fanout(f.realtime)).toEqual([ + ['packing:created', undefined], + ['packing:bag-totals', undefined], + ]); }); it('PACKING-RPC-010 a private item is created only for its owner and recipients', async () => { const f = build(); f.data.createItem.mockReturnValueOnce({ id: 70, is_private: 1, owner_id: 42, recipients: [{ user_id: 7 }] }); await f.host('db:write:packing').dispatch(req('packing.create', { tripId: 1, input: { name: 'Gift', is_private: true } }), 42); + // The item goes only to its viewers; the weight ping goes to the room and + // says nothing at all (#2191) — that is exactly what makes it safe here. expect(fanout(f.realtime)).toEqual([ ['packing:created', 42], ['packing:created', 7], + ['packing:bag-totals', undefined], ]); }); @@ -256,9 +265,12 @@ describe('PackingRpc keeps private items off the room (#858)', () => { const f = build(); f.data.deleteItem.mockReturnValueOnce({ id: 70, is_private: 1, owner_id: 42, recipients: [{ user_id: 7 }] }); await f.host('db:write:packing').dispatch(req('packing.delete', { tripId: 1, itemId: 70 }), 42); + // Same split as the create above: private item to its viewers, content-free + // weight ping to the room (#2191). expect(fanout(f.realtime)).toEqual([ ['packing:deleted', 42], ['packing:deleted', 7], + ['packing:bag-totals', undefined], ]); });