Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/client/lib/commands/XINFO_GROUPS.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,44 @@ describe('XINFO GROUPS', () => {
);
});

it('transformReply', () => {
assert.deepEqual(
XINFO_GROUPS.transformReply[2]([[
'name', 'group',
'consumers', 0,
'pending', 0,
'last-delivered-id', '0-0'
]]),
[Object.assign(Object.create(null), {
name: 'group',
consumers: 0,
pending: 0,
'last-delivered-id': '0-0'
})]
);
});

it('transformReply - Redis 7 fields', () => {
assert.deepEqual(
XINFO_GROUPS.transformReply[2]([[
'name', 'group',
'consumers', 0,
'pending', 0,
'last-delivered-id', '0-0',
'entries-read', null,
'lag', null
]]),
[Object.assign(Object.create(null), {
name: 'group',
consumers: 0,
pending: 0,
'last-delivered-id': '0-0',
'entries-read': null,
lag: null
})]
);
});

testUtils.testAll('xInfoGroups', async client => {
const [, reply] = await Promise.all([
client.xGroupCreate('key', 'group', '$', {
Expand Down
22 changes: 6 additions & 16 deletions packages/client/lib/commands/XINFO_GROUPS.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommandParser } from '../client/parser';
import { RedisArgument, ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, NullReply, UnwrapReply, Resp2Reply, Command } from '../RESP/types';
import { RedisArgument, ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, NullReply, Command } from '../RESP/types';
import { transformTuplesReply } from './generic-transformers';

/**
* Reply structure for XINFO GROUPS command containing information about consumer groups
Expand All @@ -8,11 +9,11 @@ export type XInfoGroupsReply = ArrayReply<TuplesToMapReply<[
[BlobStringReply<'name'>, BlobStringReply],
[BlobStringReply<'consumers'>, NumberReply],
[BlobStringReply<'pending'>, NumberReply],
[BlobStringReply<'last-delivered-id'>, NumberReply],
[BlobStringReply<'last-delivered-id'>, BlobStringReply],
/** added in 7.0 */
[BlobStringReply<'entries-read'>, NumberReply | NullReply],
/** added in 7.0 */
[BlobStringReply<'lag'>, NumberReply],
[BlobStringReply<'lag'>, NumberReply | NullReply],
]>>;

export default {
Expand All @@ -34,19 +35,8 @@ export default {
* entries-read - Number of entries read in the group (Redis 7.0+)
* lag - Number of entries not read by the group (Redis 7.0+)
*/
2: (reply: UnwrapReply<Resp2Reply<XInfoGroupsReply>>) => {
return reply.map(group => {
const unwrapped = group as unknown as UnwrapReply<typeof group>;
return {
name: unwrapped[1],
consumers: unwrapped[3],
pending: unwrapped[5],
'last-delivered-id': unwrapped[7],
'entries-read': unwrapped[9],
lag: unwrapped[11]
};
});
},
2: (reply: Array<Array<BlobStringReply | NumberReply | NullReply>>) =>
reply.map(group => transformTuplesReply(group as unknown as ArrayReply<BlobStringReply>)) as unknown as XInfoGroupsReply['DEFAULT'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transformer returns null-prototype objects breaking integration test

Medium Severity

transformTuplesReply returns objects created with Object.create(null) (null prototype), but the existing integration test at line 62 expects a regular object literal with Object.prototype. Since the test uses strict assert (i.e., deepStrictEqual), and Node.js 20+ compares [[Prototype]] with ===, the test will fail for all Redis versions. Additionally, for pre-7 Redis, entries-read and lag fields won't exist as properties at all (whereas the old positional code always included them as undefined), causing a further mismatch with the test expectation.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 311dbc6. Configure here.

3: undefined as unknown as () => XInfoGroupsReply
}
} as const satisfies Command;