Add CPU usage to host inventory

This commit is contained in:
2026-10-04 20:30:43 -04:00
parent 456af32b36
commit a1b957392f
7 changed files with 91 additions and 5 deletions
+14
View File
@@ -0,0 +1,14 @@
import { describe, expect, it } from 'vitest';
import { validateInventory } from '../../src/lib/server/hosts/index.js';
describe('host CPU inventory', () => {
it('accepts older agents without CPU usage', () => {
expect(validateInventory({ cpuCount: 4 }).cpuUsagePercent).toBeUndefined();
});
it.each([0, 0.1, 42.3, 100])('accepts CPU usage %s', cpuUsagePercent => {
expect(validateInventory({ cpuUsagePercent }).cpuUsagePercent).toBe(cpuUsagePercent);
});
it.each([-1, 100.1, NaN, Infinity, -Infinity, null, '25', true, {}])('rejects invalid CPU usage %j', cpuUsagePercent => {
expect(() => validateInventory({ cpuUsagePercent })).toThrow('Invalid inventory cpuUsagePercent');
});
});