From 1361f7da84967f8235a8ce8f4806edcb127dccac Mon Sep 17 00:00:00 2001 From: ranjeet2063 Date: Thu, 3 Sep 2026 15:10:45 +0545 Subject: [PATCH] fix(actions): reject non-finite amount values in createPaymentPrepTool (Closes #239) --- src/actions/payment-prep-action.ts | 6 +++++- tests/payment-prep-action.test.ts | 31 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/actions/payment-prep-action.ts b/src/actions/payment-prep-action.ts index ff5faed..75aca8b 100644 --- a/src/actions/payment-prep-action.ts +++ b/src/actions/payment-prep-action.ts @@ -52,7 +52,11 @@ export function createPaymentPrepTool(): ToolDefinition< const amountStr = String(payload.amount); const parsedAmount = Number(amountStr); - if (Number.isNaN(parsedAmount) || parsedAmount <= 0) { + if ( + Number.isNaN(parsedAmount) || + !Number.isFinite(parsedAmount) || + parsedAmount <= 0 + ) { throw new RuntimeError( "INVALID_TASK", "amount must be a positive number.", diff --git a/tests/payment-prep-action.test.ts b/tests/payment-prep-action.test.ts index 9e43e99..f4abf67 100644 --- a/tests/payment-prep-action.test.ts +++ b/tests/payment-prep-action.test.ts @@ -130,4 +130,35 @@ describe("PaymentPrepAction", () => { }) ).toThrowError(RuntimeError); }); + + it("rejects non-finite amount values such as Infinity, NaN, and 1e309 with INVALID_TASK (issue #239)", async () => { + const tool = createPaymentPrepTool(); + const context = createMockContext("task-pay-6"); + + const nonFiniteValues = [ + "Infinity", + "-Infinity", + "NaN", + "1e309", + Infinity, + -Infinity, + NaN + ]; + + for (const amount of nonFiniteValues) { + try { + await tool.execute({ + payload: { + walletId: "GWALLET123", + amount: amount as any + }, + context + }); + expect.unreachable(); + } catch (err) { + expect(err).toBeInstanceOf(RuntimeError); + expect((err as RuntimeError).code).toBe("INVALID_TASK"); + } + } + }); });