mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
test(packing): pin the bag-totals ping in the RPC and MCP fan-out expectations
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S5VwmiBQ9sPCJwfmpv64r3
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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],
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user