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
7 changes: 7 additions & 0 deletions packages/cli/src/commands/scale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ describe('getNextId', () => {
expect(getNextId(instances)).toBe('inst-0100');
});

it('increments ids beyond the safe integer range without collisions', () => {
const instances: FleetEntry[] = [
{ id: 'inst-9007199254740992', provider: 'aws', status: 'running', createdAt: '', hourlyRate: 0.096 },
];
expect(getNextId(instances)).toBe('inst-9007199254740993');
});

it('ignores ids that do not match the inst- pattern', () => {
const instances: FleetEntry[] = [
{ id: 'custom-id', provider: 'aws', status: 'running', createdAt: '', hourlyRate: 0.096 },
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export function getNextId(instances: FleetEntry[]): string {
const nums = instances
.map((i) => /^inst-(\d+)$/.exec(i.id)?.[1])
.filter((value): value is string => value !== undefined)
.map((value) => Number.parseInt(value, 10));
const max = nums.length > 0 ? Math.max(...nums) : 0;
return `inst-${String(max + 1).padStart(4, '0')}`;
.map((value) => BigInt(value));
const max = nums.reduce((highest, value) => value > highest ? value : highest, 0n);
return `inst-${String(max + 1n).padStart(4, '0')}`;
}

export function parsePositiveInteger(value: string): number {
Expand Down
Loading