mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 19:59:33 +01:00
feat(header): opt-in GPU and CPU clock readings after CPU and MEM
This commit is contained in:
1 parent
002de32a08
commit
e1d6471808
16 files changed
+947
-12
No files matched your search
@@ -12,6 +12,9 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { createRouteTestHarness, type RouteTestHarness } from './_route-test-utils.js';
|
||||
import { registerSystemRoutes } from '../../src/web/routes/system-routes.js';
|
||||
|
||||
const hostSensors = vi.hoisted(() => ({ readHostSensors: vi.fn(async (_request: unknown) => ({})) }));
|
||||
vi.mock('../../src/host-sensors.js', () => hostSensors);
|
||||
|
||||
// ── Mocks ──────────────────────────────────────────────────────────
|
||||
|
||||
vi.mock('node:fs/promises', () => ({
|
||||
@@ -326,6 +329,20 @@ describe('system-routes', () => {
|
||||
expect(body).toHaveProperty('cpu');
|
||||
expect(body).toHaveProperty('memory');
|
||||
});
|
||||
|
||||
it('adds no GPU or clock readings unless they are asked for', async () => {
|
||||
const body = JSON.parse((await harness.app.inject({ method: 'GET', url: '/api/system/stats' })).body);
|
||||
expect(body).not.toHaveProperty('gpu');
|
||||
expect(body).not.toHaveProperty('cpuMhz');
|
||||
});
|
||||
|
||||
it('passes only the requested readings on to the sensor reader', async () => {
|
||||
hostSensors.readHostSensors.mockClear();
|
||||
hostSensors.readHostSensors.mockResolvedValueOnce({ cpuMhz: 3200 });
|
||||
const res = await harness.app.inject({ method: 'GET', url: '/api/system/stats?cpumhz=1&gpu=0' });
|
||||
expect(hostSensors.readHostSensors).toHaveBeenCalledWith({ gpu: false, cpuMhz: true });
|
||||
expect(JSON.parse(res.body).cpuMhz).toBe(3200);
|
||||
});
|
||||
});
|
||||
|
||||
// ========== POST /api/cleanup-state ==========
|
||||
|
||||
Reference in new issue
Block a user