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
42 changes: 41 additions & 1 deletion packages/cli/src/commands/scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, afterEach } from 'vitest';
import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync } from 'node:fs';
import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync, mkdirSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import {
Expand Down Expand Up @@ -324,6 +325,45 @@ describe('rollout strategies use getNextId correctly', () => {
expect(newIds).toHaveLength(batchSize);
expect(newIds[0]).toBe('inst-0007');
});

it('assigns unique IDs to every instance created by a blue-green rollout', () => {
const dir = makeTempDir();
const stateDir = join(dir, '.sh1pt');
mkdirSync(stateDir, { recursive: true });
const statePath = join(stateDir, 'credentials.json');
writeFileSync(statePath, JSON.stringify({
apiKey: 'preserve-me',
instances: Array.from({ length: 3 }, (_, index) => ({
id: `inst-${String(index + 1).padStart(4, '0')}`,
provider: 'aws',
status: 'running',
createdAt: '',
hourlyRate: 0.1,
})),
lastUpdated: '',
}));

const scaleModule = new URL('./scale.ts', import.meta.url).href;
const runRollout = [
`import { scaleCmd } from ${JSON.stringify(scaleModule)};`,
`await scaleCmd.parseAsync(['node', 'sh1pt', 'rollout', '--version', 'v2', '--strategy', 'blue-green']);`,
].join('\n');
const result = spawnSync(
process.execPath,
['--import', 'tsx', '--input-type=module', '--eval', runRollout],
{
env: { ...process.env, HOME: dir, USERPROFILE: dir },
encoding: 'utf8',
},
);

expect(result.status, result.stderr).toBe(0);
const saved = JSON.parse(readFileSync(statePath, 'utf-8'));
expect(saved.apiKey).toBe('preserve-me');
expect(saved.instances.slice(3).map((instance: FleetEntry) => instance.id)).toEqual([
'inst-0004', 'inst-0005', 'inst-0006',
]);
});
});

// ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ scaleCmd
const newInstances: FleetEntry[] = [];
for (let i = 0; i < newInstanceCount; i++) {
newInstances.push({
id: getNextId(fleet.instances),
id: getNextId([...fleet.instances, ...newInstances]),
provider: running.length > 0 ? running[0]!.provider : 'digitalocean',
status: 'running',
publicIp: `10.${base}.${1 + Math.floor(Math.random() * 254)}.${1 + Math.floor(Math.random() * 254)}`,
Expand Down
Loading