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.

2.0 KB
Raw Blame
// 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 test from "node:test";

import {
  installLocalStorageFake,
  readSrc,
  registerBundlerResolver,
} from "./helpers/kit.ts";

registerBundlerResolver();
installLocalStorageFake();
Object.assign(globalThis.window, { addEventListener: () => {} });

const { getState, putJob, jobKeyOf, setExpectedBytesForJob } = await import(
  "../src/features/hub/download-manager/download-manager-state.ts"
);

const KEY = jobKeyOf("model", "org/gguf-repo", null);

test("a total that grows drops the ETA measured against the old one", () => {
  putJob({
    key: KEY,
    kind: "model",
    repoId: "org/gguf-repo",
    variant: null,
    state: "running",
    downloadedBytes: 900_000_000,
    completedBytes: 0,
    completeOnDisk: false,
    expectedBytes: 1_000_000_000,
    fraction: 0.9,
    bytesPerSec: 10_000_000,
    etaSeconds: 10,
    error: null,
    startedAt: 1,
  });

  setExpectedBytesForJob("model", "org/gguf-repo", null, 8_000_000_000);

  const job = getState().jobs[KEY];
  assert.equal(job.expectedBytes, 8_000_000_000);
  assert.equal(
    job.etaSeconds,
    0,
    "the ETA for the old total must not survive the total changing",
  );
});

test("the poll loop drops a hidden tab's throttled samples", () => {
  const voice = readSrc("features/settings/tabs/voice-tab.tsx");
  assert.ok(
    !voice.includes("downloadSamplesRef"),
    "voice no longer estimates a rate of its own",
  );

  const source = readSrc("features/hub/download-manager/poll-loop.ts");
  const guard = source.indexOf("document.hidden");
  assert.ok(guard > 0, "the poll loop should skip a hidden tab");
  const clear = source.indexOf("rt.speedSamples.length = 0", guard);
  assert.ok(clear > 0, "a hidden tab should clear the samples");
  assert.ok(
    clear - guard < 120,
    "the hidden-tab branch must clear rather than sample",
  );
});