import { describe, expect, it } from 'vitest' import { inferenceCpuThreads, localInferenceCpuOptions } from '../../../src/main/utils/inference-cpu-budget' describe('local inference scheduling budget', () => { it.each([[1, 1], [2, 1], [3, 1], [4, 2], [6, 4], [8, 4], [16, 4], [64, 4]])( 'leaves foreground headroom on %i available CPUs (%i workers)', (cpus, expected) => { expect(inferenceCpuThreads(cpus)).toBe(expected) } ) it.each([0, -1, Number.NaN, Number.POSITIVE_INFINITY])('uses one worker for invalid capacity %s', (cpus) => { expect(inferenceCpuThreads(cpus)).toBe(1) }) it.each(['http://localhost:11434', 'http://localhost.:11434', 'http://127.0.0.1:11434', 'http://127.0.0.2:11434', 'http://[::1]:11434'])( 'bounds the local engine at %s', (url) => { expect(localInferenceCpuOptions(url).num_thread).toBeGreaterThanOrEqual(1) expect(localInferenceCpuOptions(url).num_thread).toBeLessThanOrEqual(4) } ) it.each(['https://llm.example.com', 'http://192.168.1.2:11434', 'http://localhost.example.com', 'invalid'])( 'does not infer a remote engine budget from this PC: %s', (url) => { expect(localInferenceCpuOptions(url)).toEqual({}) } ) })