import { describe, expect, test } from 'bun:test'; import type { ProxmoxClusterResource } from '../../api-clients/proxmox'; import type { ProvisionedSystem } from '../../services/deployed-systems'; import { joinInstanceRows } from './proxmox-instance-list'; const GB = 1024 * 1024 * 1024; const MB = 1024 * 1024; function sys(p: Partial & { vmid: number }): ProvisionedSystem { return { moduleId: 'forgejo-builder', name: 'main', hostname: 'forgejo-builder', ipv4Address: '10.0.10.20', zone: 'dmz', serviceId: 'svc', cpu: 4, memory: 8192, disk: 80, ...p, }; } describe('joinInstanceRows (ISS-0150)', () => { test('joins a VM: desired from system, actual from the qemu guest', () => { const systems = [sys({ vmid: 208 })]; const resources: ProxmoxClusterResource[] = [ { type: 'qemu', vmid: 208, node: 'node3', status: 'running', maxcpu: 4, maxmem: 16 * GB, maxdisk: 100 * GB, }, ]; const rows = joinInstanceRows(systems, resources, 'vm'); expect(rows).toHaveLength(1); expect(rows[0].desired).toEqual({ cpu: 4, memMb: 8192, diskGb: 80 }); expect(rows[0].actual).toEqual({ cpu: 4, memMb: 16384, diskGb: 100 }); expect(rows[0].node).toBe('node3'); }); test('kind filters by Proxmox guest type — a qemu guest never shows under ct', () => { const systems = [sys({ vmid: 208 })]; const resources: ProxmoxClusterResource[] = [ { type: 'qemu', vmid: 208, node: 'node3', maxcpu: 4, maxmem: 8 * GB }, ]; expect(joinInstanceRows(systems, resources, 'ct')).toHaveLength(0); expect(joinInstanceRows(systems, resources, 'vm')).toHaveLength(1); }); test('an lxc system shows under ct', () => { const systems = [sys({ moduleId: 'caddy', vmid: 202 })]; const resources: ProxmoxClusterResource[] = [ { type: 'lxc', vmid: 202, node: 'node2', status: 'running', maxcpu: 1, maxmem: 512 * MB, maxdisk: 10 * GB, }, ]; const rows = joinInstanceRows(systems, resources, 'ct'); expect(rows).toHaveLength(1); expect(rows[0].module).toBe('caddy'); expect(rows[0].actual).toEqual({ cpu: 1, memMb: 512, diskGb: 10 }); }); test('a system absent from the cluster is omitted', () => { const systems = [sys({ vmid: 999 })]; expect(joinInstanceRows(systems, [], 'vm')).toHaveLength(0); }); });