Files
TREK/server/tests/unit/nest-rpc/rpc-params.test.ts
T
Maurice 39346ceca7 fix(mcp,rpc): parse resource URI, websocket and plugin RPC ids with toRowId
Eleven MCP tool files carried their own parseId, which used Number() and so took '0x1' and '1e20'; they now share uriRowId. The websocket join and book:join read the id with toRowId instead of Number().

Plugin RPC ids go through rowIdParam instead of num(), and a param that may be left out goes through the new optionalRowIdParam. num() let '0x5', 1.5 and 1e20 through, which Postgres refuses or reads its own way while SQLite matches nothing.

accommodations.create read its refs with Math.trunc(Number()), and accommodations.update bound its open input's refs as sent. collab.createMessage took replyTo only when typeof was 'number', which let 1.5 and 1e20 through. All three now read their ids as row ids. A canonical numeric string still passes, as the published contract says, and the refusal keeps num()'s message.
2026-11-18 13:20:06 +01:00

27 lines
1.2 KiB
TypeScript

import { BadParams } from '../../../src/nest-rpc/rpc-errors';
import { optionalRowIdParam, rowIdParam } from '../../../src/nest-rpc/rpc-params';
import { describe, expect, it } from 'vitest';
describe('rowIdParam', () => {
it('RPCPARAM-001: takes a safe integer and the decimal string of one, as the published contract allows', () => {
expect(rowIdParam(5, 'tripId')).toBe(5);
expect(rowIdParam('5', 'tripId')).toBe(5);
expect(rowIdParam('007', 'tripId')).toBe(7);
});
it('RPCPARAM-002: refuses what num() let through and an engine reads its own way, with num() message', () => {
for (const value of ['0x5', '5e0', '5.0', '+5', ' 5', 1.5, 1e20, '99999999999999999999', '-1', 'abc', undefined]) {
expect(() => rowIdParam(value, 'tripId'), String(value)).toThrow(new BadParams('tripId must be a number'));
}
});
it('RPCPARAM-003: optionalRowIdParam leaves an absent param out and reads any other one like rowIdParam', () => {
expect(optionalRowIdParam(undefined, 'dayId')).toBeUndefined();
expect(optionalRowIdParam('5', 'dayId')).toBe(5);
for (const value of [null, '0x5', '5e0', 1.5, '']) {
expect(() => optionalRowIdParam(value, 'dayId'), String(value)).toThrow(new BadParams('dayId must be a number'));
}
});
});