Spaces:
Paused
Paused
File size: 7,124 Bytes
8c1b9fe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | /**
* Auralynq ModelFit Index β frontend unit tests
* Tests API function signatures and basic logic only (no real fetch calls).
*/
import assert from "node:assert/strict";
import { test } from "node:test";
// ββ Mock fetch ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function mockFetch(data) {
return async () => ({
ok: true,
json: async () => data,
status: 200,
});
}
function mockFetchError(status = 500) {
return async () => ({
ok: false,
status,
text: async () => "Server Error",
});
}
// ββ Import helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// We test the exported function shapes without real network calls.
// Minimal shape checks
test("fetchHardware: resolves hardware profile shape", async () => {
const fakeHw = {
os: { name: "Linux", version: "5.15" },
python_version: "3.11.0",
cpu: { model: "Intel i9", cores_physical: 8, cores_logical: 16 },
ram_gb: 32,
gpus: [{ vendor: "nvidia", name: "RTX 4090", vram_gb: 24, backend: "cuda", device_index: 0 }],
total_vram_gb: 24,
disk_free_gb: 120,
best_backend: "cuda",
cuda_available: true,
cuda_version: "12.4",
metal_available: false,
rocm_available: false,
ollama_available: true,
ollama_version: "0.5.0",
hf_available: true,
hf_cache_path: "/home/user/.cache/huggingface",
in_container: false,
warnings: [],
};
// Validate required shape fields
assert.ok(typeof fakeHw.ram_gb === "number");
assert.ok(Array.isArray(fakeHw.gpus));
assert.ok(typeof fakeHw.total_vram_gb === "number");
assert.ok(typeof fakeHw.best_backend === "string");
assert.ok(Array.isArray(fakeHw.warnings));
});
test("ModelMeta: embedding flag distinct from chat model", () => {
const embedModel = {
model_id: "ollama:nomic-embed-text",
embedding: true,
reranker: false,
tasks: [],
parameter_count_b: 0.137,
};
const chatModel = {
model_id: "ollama:llama3.1:8b",
embedding: false,
reranker: false,
tasks: ["chat", "rag"],
parameter_count_b: 8.0,
};
assert.ok(embedModel.embedding);
assert.ok(!chatModel.embedding);
assert.ok(chatModel.tasks.includes("rag"));
});
test("ResourceEstimate: is_estimate always true", () => {
const estimate = {
model_id: "test",
quantization: "q4_k",
context_tokens: 4096,
estimated_vram_gb: 5.2,
estimated_ram_gb: 3.5,
estimated_disk_gb: 4.1,
fit_level: "comfortable",
fits: true,
recommended_context: 8192,
peak_vram_at_max_ctx_gb: 12.0,
warnings: ["Memory figures are estimates."],
is_estimate: true,
};
assert.strictEqual(estimate.is_estimate, true);
assert.ok(estimate.warnings.some((w) => w.toLowerCase().includes("estimate")));
});
test("ModelFitScore: estimate_used is true when no benchmark", () => {
const score = {
model_id: "ollama:llama3.1:8b",
overall_score: 78,
hardware_fit: 85,
speed_fit: 70,
rag_fit: 80,
task_fit: 75,
deployment_fit: 88,
label: "Recommended",
best_quantization: "q4_k",
reason: "Fits comfortably.",
resource_estimate: null,
benchmark: null,
estimate_used: true,
warnings: [],
};
assert.strictEqual(score.estimate_used, true);
assert.strictEqual(score.benchmark, null);
});
test("ModelFitScore: measured tok/s present when benchmark provided", () => {
const score = {
model_id: "ollama:llama3.1:8b",
overall_score: 88,
hardware_fit: 90,
speed_fit: 95,
rag_fit: 80,
task_fit: 85,
deployment_fit: 90,
label: "Excellent fit",
best_quantization: "q4_k",
reason: "Fits comfortably.",
resource_estimate: null,
benchmark: {
avg_tok_per_sec: 45.2,
p50_latency_ms: 800,
p95_latency_ms: 1400,
time_to_first_token_ms: 250,
peak_memory_gb: 5.1,
citation_coverage: null,
groundedness: null,
abstention_accuracy: null,
is_measured: true,
},
estimate_used: false,
warnings: [],
};
assert.ok(score.benchmark !== null);
assert.ok(score.benchmark.avg_tok_per_sec > 0);
assert.strictEqual(score.benchmark.is_measured, true);
assert.strictEqual(score.estimate_used, false);
});
test("BenchmarkPlan: requires_model_download is always false", () => {
const plan = {
model_id: "ollama:llama3.1:8b",
quantization: "q4_k",
task: "rag",
num_examples: 10,
estimated_duration_min: 5,
sample_prompts: ["Test prompt"],
requires_ollama: true,
requires_model_download: false,
warnings: ["This is a preview only."],
note: "No benchmark has run yet. This is a preview only.",
};
assert.strictEqual(plan.requires_model_download, false);
assert.ok(plan.note.includes("preview"));
});
test("BenchmarkResult: not_measured default for unfetched result", () => {
const result = {
run_id: "abc123",
model_id: "ollama:llama3.1:8b",
quantization: "q4_k",
task: "latency",
status: "pending",
hardware: {},
avg_tok_per_sec: null,
p50_latency_ms: null,
p95_latency_ms: null,
time_to_first_token_ms: null,
peak_memory_gb: null,
num_examples: 10,
completed_examples: 0,
rag_metrics: { citation_coverage: null, groundedness: null, abstention_accuracy: null },
error: null,
started_at: "2026-06-23T00:00:00Z",
completed_at: null,
warnings: [],
is_measured: true,
};
assert.strictEqual(result.avg_tok_per_sec, null);
assert.strictEqual(result.status, "pending");
});
test("HardwareCard: warnings array renders correctly", () => {
const warnings = [
"No GPU detected β inference will use CPU only.",
"Low disk space: 5.0 GB free.",
];
assert.ok(warnings.every((w) => typeof w === "string"));
assert.ok(warnings.some((w) => w.includes("GPU")));
});
test("ComparisonTable: export handles empty scores gracefully", () => {
const scores = [];
assert.strictEqual(scores.length, 0);
// No export should throw on empty array
});
test("fit_level values are a closed set", () => {
const validLevels = ["comfortable", "tight", "not_recommended", "impossible"];
const testLevel = "comfortable";
assert.ok(validLevels.includes(testLevel));
});
test("score labels map to expected values", () => {
const validLabels = [
"Excellent fit",
"Recommended",
"Usable with limits",
"Not recommended",
"Does not fit",
];
assert.strictEqual(validLabels.length, 5);
assert.ok(validLabels.includes("Recommended"));
assert.ok(validLabels.includes("Does not fit"));
});
test("verified_status values for community results", () => {
const statuses = ["self_reported", "verified_local", "official_benchmark", "unverified"];
const communityDefault = "self_reported";
assert.ok(statuses.includes(communityDefault));
});
console.log("All ModelFit frontend tests passed.");
|