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
46 changes: 46 additions & 0 deletions packages/cli/src/commands/scale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
parsePositiveNumber,
parsePercentage,
aggregateFleetCosts,
rollbackPlanIps,
} from './scale.js';

// Helper to create a temp dir and override CREDS_FILE path
Expand Down Expand Up @@ -375,3 +376,48 @@ describe('auto-scale rules', () => {
expect(rules.cooldownSeconds).toBe(300);
});
});

// ---------------------------------------------------------------------------
// rollbackPlanIps — rollback plan must list the OLD fleet, not the new one
// ---------------------------------------------------------------------------

describe('rollbackPlanIps', () => {
const fleet: FleetState = {
instances: [
{ id: 'inst-0001', provider: 'aws', status: 'stopped', createdAt: '', hourlyRate: 0.1, publicIp: '10.0.0.1' },
{ id: 'inst-0002', provider: 'aws', status: 'stopped', createdAt: '', hourlyRate: 0.1, publicIp: '10.0.0.2' },
{ id: 'inst-0003', provider: 'aws', status: 'running', createdAt: '', hourlyRate: 0.1, publicIp: '10.1.0.1' },
],
};
const rollout: RolloutRecord = {
id: 'roll-1',
version: 'v2',
strategy: 'blue-green',
status: 'completed',
startedAt: '2026-08-08T00:00:00.000Z',
newInstanceIds: ['inst-0003'],
oldInstanceIds: ['inst-0001', 'inst-0002'],
};

it('lists the old (pre-rollout) instances, not the new ones', () => {
const ips = rollbackPlanIps(fleet, rollout);
expect(ips).toEqual(['10.0.0.1', '10.0.0.2']);
expect(ips).not.toContain('10.1.0.1');
});

it('falls back to privateIp when publicIp is missing', () => {
const fleetNoPub: FleetState = {
instances: [
{ id: 'inst-0001', provider: 'aws', status: 'stopped', createdAt: '', hourlyRate: 0.1, privateIp: '172.16.0.5' },
],
};
expect(rollbackPlanIps(fleetNoPub, rollout)).toEqual(['172.16.0.5']);
});

it('returns placeholder for instances without any ip', () => {
const fleetNoIp: FleetState = {
instances: [{ id: 'inst-0001', provider: 'aws', status: 'stopped', createdAt: '', hourlyRate: 0.1 }],
};
expect(rollbackPlanIps(fleetNoIp, rollout)).toEqual(['?.?.?.?']);
});
});
11 changes: 8 additions & 3 deletions packages/cli/src/commands/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ export function aggregateFleetCosts(
return providerMap;
}

/** Resolve the IPs of the old (pre-rollout) fleet for a rollback plan display. */
export function rollbackPlanIps(fleet: FleetState, target: RolloutRecord): string[] {
return fleet.instances
.filter(i => target.oldInstanceIds.includes(i.id))
.map(i => i.publicIp || i.privateIp || '?.?.?.?');
}

export const scaleCmd = new Command('scale')
.description('Provision + scale cloud infra. DNS round-robin, rollouts, rightsizing — all the capacity ops.')
.option('--from <input>', 'existing live url, repo, or local path to probe + propose scaling for')
Expand Down Expand Up @@ -728,9 +735,7 @@ scaleCmd
process.exit(1);
}
const fleet = loadFleet();
const oldIps = fleet.instances
.filter(i => target.newInstanceIds.includes(i.id))
.map(i => i.publicIp || i.privateIp || '?.?.?.?');
const oldIps = rollbackPlanIps(fleet, target);
console.log(kleur.bold('\\n⏮ Rollback Plan'));
console.log(kleur.dim('─'.repeat(56)));
console.log(`${kleur.cyan('Rollout ID:'.padEnd(20))} ${target.id.slice(0, 8)} (v${target.version})`);
Expand Down
Loading