Files
oh-my-pi/packages/coding-agent/test/tiny-device.test.ts
T
can1357 4d3d181d8e fix(coding-agent): changed local tiny-model default to CPU inference
- Changed tiny-device preference resolution to always default to CPU instead of platform-specific DirectML/CUDA heuristics.
- Updated settings schema, documentation, and changelog text to describe the CPU default while keeping accelerated providers behind explicit `providers.tinyModelDevice`/`PI_TINY_DEVICE` choices.
2026-05-31 03:39:38 +02:00

65 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import {
normalizeTinyModelDevice,
resolveTinyModelDevicePreference,
TINY_MODEL_DEVICE_DEFAULT,
TINY_MODEL_DEVICE_SETTING_OPTIONS,
TINY_MODEL_DEVICE_SETTING_VALUES,
type TinyModelDevice,
tinyModelDeviceLoadOrder,
tinyModelDeviceSettingToEnv,
} from "../src/tiny/device";
describe("tiny model device selection", () => {
it("defaults to CPU-only inference on every platform", () => {
const preference = resolveTinyModelDevicePreference(undefined);
expect(preference.device).toBe("cpu");
expect(tinyModelDeviceLoadOrder(preference)).toEqual(["cpu"]);
});
it("accepts metal as a WebGPU alias without enabling unsafe macOS worker teardown", () => {
const expectedOrder: readonly TinyModelDevice[] = process.platform === "darwin" ? ["cpu"] : ["webgpu", "cpu"];
expect(normalizeTinyModelDevice("metal")).toBe("webgpu");
expect(tinyModelDeviceLoadOrder(resolveTinyModelDevicePreference("metal"))).toEqual(expectedOrder);
});
it("keeps explicit CPU runs CPU-only", () => {
const preference = resolveTinyModelDevicePreference(" cpu ");
expect(preference.device).toBe("cpu");
expect(tinyModelDeviceLoadOrder(preference)).toEqual(["cpu"]);
});
it("rejects unknown ONNX execution providers", () => {
expect(() => resolveTinyModelDevicePreference("neural-magic")).toThrow("Unsupported PI_TINY_DEVICE");
});
});
describe("tiny model device setting → PI_TINY_DEVICE mapping", () => {
it("returns undefined for the default sentinel so the worker keeps its CPU default", () => {
expect(tinyModelDeviceSettingToEnv(TINY_MODEL_DEVICE_DEFAULT)).toBeUndefined();
expect(tinyModelDeviceSettingToEnv(undefined)).toBeUndefined();
expect(tinyModelDeviceSettingToEnv("")).toBeUndefined();
});
it("forwards a concrete device value verbatim for the worker to validate", () => {
expect(tinyModelDeviceSettingToEnv("metal")).toBe("metal");
expect(tinyModelDeviceSettingToEnv("cuda")).toBe("cuda");
});
it("keeps every non-default setting value resolvable by the worker", () => {
for (const value of TINY_MODEL_DEVICE_SETTING_VALUES) {
if (value === TINY_MODEL_DEVICE_DEFAULT) continue;
expect(() => normalizeTinyModelDevice(tinyModelDeviceSettingToEnv(value))).not.toThrow();
}
});
it("keeps submenu options aligned with the accepted values", () => {
expect(TINY_MODEL_DEVICE_SETTING_OPTIONS.map(option => option.value)).toEqual([
...TINY_MODEL_DEVICE_SETTING_VALUES,
]);
});
});