Skip to content
Merged
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
22 changes: 22 additions & 0 deletions packages/cloud/runpod/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,28 @@ describe('RunPod cloud adapter', () => {
expect(fetchMock).not.toHaveBeenCalled();
});

it('rejects non-decimal sizing strings before provisioning', async () => {
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);

await expect(adapter.provision(
provisionCtx(),
{ kind: 'gpu', gpu: { model: 'NVIDIA RTX A6000', count: 1 } },
{ hourlyPrice: 0.5, imageName: 'runpod/pytorch', volumeInGb: '1e2' },
)).rejects.toThrow('RunPod volumeInGb must be a plain decimal number');
await expect(adapter.provision(
provisionCtx(),
{ kind: 'gpu', gpu: { model: 'NVIDIA RTX A6000', count: 1 } },
{ hourlyPrice: 0.5, imageName: 'runpod/pytorch', containerDiskInGb: '0x10' },
)).rejects.toThrow('RunPod containerDiskInGb must be a plain decimal number');
await expect(adapter.provision(
provisionCtx(),
{ kind: 'gpu', gpu: { model: 'NVIDIA RTX A6000', count: 1 }, cpu: '-1' as any },
{ hourlyPrice: 0.5, imageName: 'runpod/pytorch' },
)).rejects.toThrow('RunPod minVcpuCount must be a plain decimal number');
expect(fetchMock).not.toHaveBeenCalled();
});

it('does not call RunPod for dry-run provisioning without hourlyPrice', async () => {
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
Expand Down
13 changes: 11 additions & 2 deletions packages/cloud/runpod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,26 @@ function safeName(value: string): string {

function optionalPositiveNumber(value: Numberish | undefined, label: string): number | undefined {
if (value === undefined) return undefined;
const number = Number(value);
const number = plainDecimalNumber(value, label);
if (!Number.isFinite(number) || number <= 0) throw new Error(`RunPod ${label} must be a positive number`);
return number;
}

function nonNegativeNumber(value: Numberish, label: string): number {
const number = Number(value);
const number = plainDecimalNumber(value, label);
if (!Number.isFinite(number) || number < 0) throw new Error(`RunPod ${label} must be a non-negative number`);
return number;
}

function plainDecimalNumber(value: Numberish, label: string): number {
if (typeof value === 'number') return value;
const text = value.trim();
if (!/^(?:0|[1-9]\d*|0?\.\d+|[1-9]\d*\.\d+)$/.test(text)) {
throw new Error(`RunPod ${label} must be a plain decimal number`);
}
return Number(text);
}
Comment on lines +442 to +449

function graphqlError(payload: RunpodGraphqlResponse<unknown>): string {
return payload.errors?.map((error) => error.message).filter(Boolean).join('; ') ?? '';
}
Expand Down
Loading