|
1 | 1 | import { describe, it } from "node:test"; |
2 | 2 | import assert from "node:assert"; |
3 | | -import { getDeviceInfo, recommendModel } from "./device.js"; |
| 3 | +import { getDeviceInfo, recommendModel, getAvailableMemoryGB, lookupModelSize, MODEL_TIERS } from "./device.js"; |
4 | 4 |
|
5 | 5 | describe("getDeviceInfo", () => { |
6 | 6 | it("returns chip and totalMemoryGB on macOS", async () => { |
@@ -41,3 +41,47 @@ describe("recommendModel", () => { |
41 | 41 | assert.strictEqual(rec.quantization, "8bit"); |
42 | 42 | }); |
43 | 43 | }); |
| 44 | + |
| 45 | +describe("getAvailableMemoryGB", () => { |
| 46 | + it("returns a positive number on macOS", async () => { |
| 47 | + const gb = await getAvailableMemoryGB(); |
| 48 | + assert.ok(typeof gb === "number", "should return a number"); |
| 49 | + assert.ok(gb > 0, `should be positive, got ${gb}`); |
| 50 | + assert.ok(gb < 512, `should be reasonable (< 512GB), got ${gb}`); |
| 51 | + }); |
| 52 | +}); |
| 53 | + |
| 54 | +describe("lookupModelSize", () => { |
| 55 | + it("returns size for a known model", () => { |
| 56 | + const size = lookupModelSize("mlx-community/Qwen2.5-Coder-7B-Instruct-4bit"); |
| 57 | + assert.strictEqual(size, 4); |
| 58 | + }); |
| 59 | + |
| 60 | + it("returns size for another known model", () => { |
| 61 | + const size = lookupModelSize("mlx-community/Qwen2.5-Coder-14B-Instruct-4bit"); |
| 62 | + assert.strictEqual(size, 8); |
| 63 | + }); |
| 64 | + |
| 65 | + it("returns undefined for unknown models", () => { |
| 66 | + assert.strictEqual(lookupModelSize("some/custom-model"), undefined); |
| 67 | + }); |
| 68 | + |
| 69 | + it("returns undefined for empty string", () => { |
| 70 | + assert.strictEqual(lookupModelSize(""), undefined); |
| 71 | + }); |
| 72 | +}); |
| 73 | + |
| 74 | +describe("MODEL_TIERS", () => { |
| 75 | + it("is exported and non-empty", () => { |
| 76 | + assert.ok(Array.isArray(MODEL_TIERS)); |
| 77 | + assert.ok(MODEL_TIERS.length > 0); |
| 78 | + }); |
| 79 | + |
| 80 | + it("every tier has required fields", () => { |
| 81 | + for (const tier of MODEL_TIERS) { |
| 82 | + assert.ok(typeof tier.modelId === "string"); |
| 83 | + assert.ok(typeof tier.estimatedSizeGB === "number"); |
| 84 | + assert.ok(tier.estimatedSizeGB > 0); |
| 85 | + } |
| 86 | + }); |
| 87 | +}); |
0 commit comments