Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

test(studio): add profile stats UI verification harness

Souravrajvi01009c31bdbfc
diff --git a/studio/frontend/tests/e2e/profile-stats-mock-server.mjs b/studio/frontend/tests/e2e/profile-stats-mock-server.mjs
new file mode 100644
index 00000000000..6636f62b301
--- /dev/null
+++ b/studio/frontend/tests/e2e/profile-stats-mock-server.mjs
@@ -0,0 +1,221 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import http from "node:http";
+
+const PORT = Number(process.env.MOCK_API_PORT ?? 8888);
+
+function isoDay(date) {
+ const year = date.getFullYear();
+ const month = `${date.getMonth() + 1}`.padStart(2, "0");
+ const day = `${date.getDate()}`.padStart(2, "0");
+ return `${year}-${month}-${day}`;
+}
+
+function buildDailySeries() {
+ const today = new Date();
+ const days = 366;
+ const series = [];
+ for (let offset = days - 1; offset >= 0; offset -= 1) {
+ const date = new Date(today);
+ date.setDate(today.getDate() - offset);
+ const key = isoDay(date);
+ let tokens = 0;
+ let messages = 0;
+ if (offset <= 1) {
+ tokens = 100;
+ messages = 4;
+ } else if (offset <= 8) {
+ tokens = 10;
+ messages = 1;
+ }
+ series.push({ date: key, tokens, messages, chats: messages > 0 ? 1 : 0 });
+ }
+ return series;
+}
+
+const daily = buildDailySeries();
+const totalTokens = daily.reduce((sum, day) => sum + day.tokens, 0);
+
+const profileStats = {
+ generatedAt: Date.now(),
+ days: 366,
+ totals: {
+ threads: 3,
+ messages: daily.reduce((sum, day) => sum + day.messages, 0),
+ userMessages: 20,
+ assistantMessages: 25,
+ promptTokens: Math.round(totalTokens * 0.4),
+ completionTokens: Math.round(totalTokens * 0.6),
+ totalTokens,
+ cachedTokens: 0,
+ toolCalls: 0,
+ attachments: 0,
+ activeDays: daily.filter((day) => day.tokens > 0).length,
+ chatSeconds: 524,
+ },
+ streak: { current: 1, longest: 2, lastActiveDay: daily.at(-1)?.date ?? null },
+ peakDay: { date: daily.at(-1)?.date ?? "2026-08-20", tokens: 100 },
+ longestChat: {
+ threadId: "thread-1",
+ title: "Test chat",
+ seconds: 524,
+ messages: 8,
+ },
+ daily,
+ models: [
+ {
+ id: "unsloth/Qwen3-8B-GGUF",
+ label: "Qwen3 8B",
+ messages: 20,
+ tokens: totalTokens,
+ },
+ ],
+ speed: {
+ averageTokensPerSecond: 42.5,
+ bestTokensPerSecond: 88.0,
+ bestTokensPerSecondModel: "unsloth/Qwen3-8B-GGUF",
+ averageResponseMs: 1200,
+ averageFirstTokenMs: 180,
+ samples: 10,
+ },
+ training: {
+ runs: 0,
+ completed: 0,
+ steps: 0,
+ tokens: 0,
+ seconds: 0,
+ models: 0,
+ datasets: 0,
+ bestLoss: null,
+ recent: [],
+ },
+};
+
+function json(res, status, body) {
+ res.writeHead(status, {
+ "Content-Type": "application/json",
+ "Access-Control-Allow-Origin": "*",
+ });
+ res.end(JSON.stringify(body));
+}
+
+const nowSeconds = () => Date.now() / 1000;
+
+function mockPayload(path) {
+ if (path === "/api/inference/monitor") {
+ return { entries: [], server_time: nowSeconds() };
+ }
+ if (path === "/api/inference/status") {
+ return {
+ loaded: false,
+ model: null,
+ device_type: "cuda",
+ parallel_slots: 1,
+ };
+ }
+ if (path === "/api/inference/active-generations") {
+ return { generations: [] };
+ }
+ if (path === "/api/inference/load-progress") {
+ return { active: false };
+ }
+ if (path === "/api/chat/projects") {
+ return [];
+ }
+ if (path === "/api/chat/settings") {
+ return {};
+ }
+ if (path === "/api/chat/count") {
+ return { threads: 0, messages: 0 };
+ }
+ if (path === "/api/chat/export") {
+ return { threads: [] };
+ }
+ if (path === "/api/chat/import-ledger") {
+ return { entries: [] };
+ }
+ if (path === "/api/models/list") {
+ return { models: [], default_models: [] };
+ }
+ if (path === "/api/models/local") {
+ return { models: [] };
+ }
+ if (path === "/api/models/scan-folders") {
+ return { folders: [] };
+ }
+ if (path === "/api/models/recommended-folders") {
+ return { folders: [] };
+ }
+ if (path === "/api/hub/cached-gguf") {
+ return { variants: [] };
+ }
+ if (path === "/api/hub/cached-models") {
+ return { models: [] };
+ }
+ if (path === "/api/providers/") {
+ return [];
+ }
+ if (path === "/api/providers/registry") {
+ return { providers: [] };
+ }
+ if (path.startsWith("/api/personalization")) {
+ return {};
+ }
+ return {};
+}
+
+const server = http.createServer((req, res) => {
+ const url = new URL(req.url ?? "/", `http://127.0.0.1:${PORT}`);
+ const path = url.pathname;
+
+ if (req.method === "OPTIONS") {
+ res.writeHead(204, {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
+ "Access-Control-Allow-Headers": "*",
+ });
+ res.end();
+ return;
+ }
+
+ if (path === "/api/auth/status") {
+ return json(res, 200, {
+ initialized: true,
+ requires_password_change: false,
+ });
+ }
+
+ if (path === "/api/auth/refresh" && req.method === "POST") {
+ return json(res, 200, {
+ access_token: "test-access-token",
+ refresh_token: "test-refresh-token",
+ must_change_password: false,
+ });
+ }
+
+ if (path === "/api/profile/stats") {
+ return json(res, 200, profileStats);
+ }
+
+ if (path === "/api/health") {
+ return json(res, 200, {
+ status: "ok",
+ device_type: "cuda",
+ chat_only: false,
+ video_supported: true,
+ images_supported: true,
+ });
+ }
+
+ if (path.startsWith("/api/")) {
+ return json(res, 200, mockPayload(path));
+ }
+
+ res.writeHead(404);
+ res.end("not found");
+});
+
+server.listen(PORT, "127.0.0.1", () => {
+ console.log(`profile-stats mock API on http://127.0.0.1:${PORT}`);
+});
diff --git a/studio/frontend/tests/e2e/profile-stats-ui.spec.mjs b/studio/frontend/tests/e2e/profile-stats-ui.spec.mjs
new file mode 100644
index 00000000000..7bd403258ad
--- /dev/null
+++ b/studio/frontend/tests/e2e/profile-stats-ui.spec.mjs
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { spawn } from "node:child_process";
+import { once } from "node:events";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import puppeteer from "puppeteer-core";
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const frontendRoot = process.env.FRONTEND_ROOT
+ ? path.resolve(process.env.FRONTEND_ROOT)
+ : path.resolve(__dirname, "../..");
+const mockServerPath = process.env.MOCK_SERVER_PATH
+ ? path.resolve(process.env.MOCK_SERVER_PATH)
+ : path.join(__dirname, "profile-stats-mock-server.mjs");
+const vitePort = Number(process.env.VITE_PORT ?? 8000);
+const mockPort = Number(process.env.MOCK_API_PORT ?? 8888);
+const baseUrl = `http://127.0.0.1:${vitePort}`;
+const chromiumPath =
+ process.env.CHROMIUM_PATH ?? "/snap/bin/chromium";
+
+function sleep(ms) {
+ return new Promise((resolve) => setTimeout(resolve, ms));
+}
+
+async function waitForUrl(url, attempts = 60) {
+ for (let index = 0; index < attempts; index += 1) {
+ try {
+ const response = await fetch(url);
+ if (response.ok || response.status === 404) return;
+ } catch {
+ // retry
+ }
+ await sleep(500);
+ }
+ throw new Error(`Timed out waiting for ${url}`);
+}
+
+function spawnLogged(command, args, options = {}) {
+ const child = spawn(command, args, {
+ stdio: ["ignore", "pipe", "pipe"],
+ ...options,
+ });
+ child.stdout.on("data", (chunk) => process.stdout.write(chunk));
+ child.stderr.on("data", (chunk) => process.stderr.write(chunk));
+ return child;
+}
+
+async function main() {
+ const mock = spawnLogged("node", [mockServerPath], {
+ cwd: frontendRoot,
+ env: { ...process.env, MOCK_API_PORT: String(mockPort) },
+ });
+
+ const vite = spawnLogged(
+ "npm",
+ ["run", "dev", "--", "--port", String(vitePort), "--strictPort"],
+ { cwd: frontendRoot },
+ );
+
+ try {
+ await waitForUrl(`${baseUrl}/`);
+ await waitForUrl(`http://127.0.0.1:${mockPort}/api/health`);
+
+ const browser = await puppeteer.launch({
+ executablePath: chromiumPath,
+ headless: true,
+ args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"],
+ });
+ const page = await browser.newPage();
+
+ await page.evaluateOnNewDocument(() => {
+ localStorage.setItem("unsloth_auth_token", "test-access-token");
+ localStorage.setItem("unsloth_auth_refresh_token", "test-refresh-token");
+ localStorage.setItem("unsloth_onboarding_done", "1");
+ localStorage.setItem("unsloth_settings_active_tab", "profile");
+ });
+
+ await page.goto(`${baseUrl}/settings`, { waitUntil: "networkidle0", timeout: 60_000 });
+
+ await page.waitForFunction(
+ () => document.querySelector('[data-testid="settings-tab-profile"]') !== null,
+ { timeout: 30_000 },
+ );
+ await page.click('[data-testid="settings-tab-profile"]');
+ await page.waitForFunction(
+ () => document.body.textContent?.includes("Token activity") ?? false,
+ { timeout: 30_000 },
+ );
+
+ const readDescription = async () => {
+ return page.evaluate(() => {
+ const heading = [...document.querySelectorAll("h3")].find((node) =>
+ node.textContent?.includes("Token activity"),
+ );
+ const description = heading?.parentElement?.querySelector("p");
+ return description?.textContent?.trim() ?? "";
+ });
+ };
+
+ const clickMode = async (label) => {
+ const clicked = await page.evaluate((modeLabel) => {
+ const button = [...document.querySelectorAll("button")].find(
+ (node) => node.textContent?.trim() === modeLabel,
+ );
+ if (!button) return false;
+ button.click();
+ return true;
+ }, label);
+ assert.equal(clicked, true, `missing ${label} mode button`);
+ };
+
+ const dailyText = await readDescription();
+ assert.match(dailyText, /over the last/i);
+ assert.match(dailyText, /token/i);
+
+ await clickMode("Weekly");
+ const weeklyText = await readDescription();
+ assert.match(weeklyText, /Peak week/i);
+ assert.notEqual(weeklyText, dailyText);
+
+ await clickMode("Cumulative");
+ const cumulativeText = await readDescription();
+ assert.match(cumulativeText, /accumulated/i);
+ assert.notEqual(cumulativeText, dailyText);
+ assert.notEqual(cumulativeText, weeklyText);
+
+ await clickMode("Daily");
+ const dailyAgain = await readDescription();
+ assert.equal(dailyAgain, dailyText);
+
+ console.log("profile stats UI verification passed");
+ console.log(` daily: ${dailyText}`);
+ console.log(` weekly: ${weeklyText}`);
+ console.log(` cumulative: ${cumulativeText}`);
+
+ await browser.close();
+ } finally {
+ vite.kill("SIGTERM");
+ mock.kill("SIGTERM");
+ await Promise.allSettled([once(vite, "exit"), once(mock, "exit")]);
+ }
+}
+
+main().catch((error) => {
+ console.error(error);
+ process.exit(1);
+});