import { describe, expect, it } from 'vitest'; import { InstanceResourceService, parseHealth, parseSim, parseStats, } from './instance-resource-service.js'; const response = (body: unknown) => ({ status: 200, headers: {}, body: JSON.stringify(body), }); describe('instance resource allowlist parsing', () => { it('extracts CPU, memory and only the highest valid temperature', () => { expect( parseStats( response({ data: { cpu_load: { load_percent: 23.4, secret: 'drop' }, memory: { used_percent: 67.8, total_bytes: 123 }, temperature: [ { label: 'a', temperature: 41.2 }, { label: 'b', temperature: 52.6 }, { label: 'bad', temperature: 900 }, ], }, }), ), ).toEqual({ cpuPercent: 23.4, memoryPercent: 67.8, maxTemperatureCelsius: 52.6 }); }); it('falls back to version metadata exposed by stats on older SimAdmin builds', () => { expect( parseStats( response({ data: { cpu_load: { load_percent: 10 }, system: { app_version: '1.8.7', architecture: 'aarch64' }, }, }), ), ).toMatchObject({ cpuPercent: 10, version: '1.8.7', platform: 'aarch64' }); }); it('extracts the upstream SimAdmin version from the health endpoint', () => { expect( parseHealth( response({ status: 'ok', version: '1.9.4', platform: 'linux-aarch64', secret: 'drop' }), ), ).toEqual({ version: '1.9.4', platform: 'linux-aarch64' }); }); it('extracts, validates, deduplicates and bounds phone numbers only', () => { expect( parseSim( response({ data: { phone_numbers: ['+86 138-0000-0000', '+86 138-0000-0000', 'bad