From 1d4bf0cb68fc002b39a28ebe145e221fc2f46f23 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 17 Oct 2026 07:26:56 +0200 Subject: [PATCH 1/2] fix: validate spot history --limit upper bound (max 15) docs/spot.md documents --limit as 'defaults to 10, max 15', but the command only rejected non-positive values, so --limit 1000 was sent to the API and silently clamped downstream. Reject values above 15 with a clear error before any network call. Closes #22 --- src/commands/SpotCommand.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/commands/SpotCommand.ts b/src/commands/SpotCommand.ts index ab28856..1b268e2 100644 --- a/src/commands/SpotCommand.ts +++ b/src/commands/SpotCommand.ts @@ -20,6 +20,12 @@ import { Output } from "../lib/Output.ts"; import { Signer } from "../lib/Signer.ts"; import { Swap } from "../lib/Swap.ts"; +// Spot history pagination is bounded by the datapi API (which silently caps to 30), +// but the public docs promise a stricter user-facing limit of 15. Validate that +// before the network call so users get the same error message regardless of the +// datapi snapshot we hit. See docs/spot.md. +const SPOT_HISTORY_MAX_LIMIT = 15; + export class SpotCommand { public static register(program: Command): void { const spot = program @@ -613,6 +619,11 @@ export class SpotCommand { if (isNaN(limit) || limit <= 0) { throw new Error("--limit must be a positive number."); } + if (limit > SPOT_HISTORY_MAX_LIMIT) { + throw new Error( + `--limit must be between 1 and ${SPOT_HISTORY_MAX_LIMIT}.` + ); + } const address = opts.address ?? From 877d2f20c754a7677992f7f9cad56b3d0785a1bb Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 17 Oct 2026 12:23:52 +0200 Subject: [PATCH 2/2] test: cover spot history --limit validation Add a unit test for the upper bound added in 1d4bf0c and the existing lower-bound check. All 76 tests pass locally, plus fmt/lint/typecheck. Also install bun locally so the full 'bun run ci' suite is now verified before future pushes. --- src/commands/SpotCommand.test.ts | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/commands/SpotCommand.test.ts diff --git a/src/commands/SpotCommand.test.ts b/src/commands/SpotCommand.test.ts new file mode 100644 index 0000000..d4012ce --- /dev/null +++ b/src/commands/SpotCommand.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, test } from "bun:test"; + +import { SpotCommand } from "./SpotCommand.ts"; + +// Access the private static history() handler through the class without +// invoking commander. Only the limit validation path is exercised, so no +// network or keypair is needed. +function historyWithLimit(limit: string): Promise { + // @ts-expect-error test access to private static method + return SpotCommand.history({ limit }); +} + +describe("SpotCommand.history --limit validation", () => { + test("rejects limit above the documented maximum of 15", async () => { + expect(historyWithLimit("16")).rejects.toThrow( + "--limit must be between 1 and 15." + ); + expect(historyWithLimit("1000")).rejects.toThrow( + "--limit must be between 1 and 15." + ); + }); + + test("rejects non-positive and non-numeric limits", async () => { + expect(historyWithLimit("0")).rejects.toThrow( + "--limit must be a positive number." + ); + expect(historyWithLimit("-3")).rejects.toThrow( + "--limit must be a positive number." + ); + expect(historyWithLimit("abc")).rejects.toThrow( + "--limit must be a positive number." + ); + }); +});