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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
// 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 { readAudioWorkspaceSource } from "./helpers/audio-workspace.ts";
const source = readAudioWorkspaceSource();
test("uncached remote TTS GGUFs stage the picked quant through the shared manager", () => {
assert.match(source, /useStagedDownload\(\{\s*scopeId: "audio"/);
assert.match(
source,
/meta\.source === "hub"[\s\S]*meta\.isDownloaded === false[\s\S]*ggufFilename/,
);
assert.match(
source,
/stageTtsDownload\(\[\s*meta\.ggufVariant\s*\?\s*\{[\s\S]*repoId,[\s\S]*ggufVariant: meta\.ggufVariant,[\s\S]*\}\s*:\s*\{[\s\S]*files: \[ggufFilename\],[\s\S]*bytes: meta\.expectedBytes \?\? 0/,
);
assert.match(
source,
/const exactGguf = exactGgufLoadSelector\(meta\)[\s\S]*loadOrStageTtsModel\(id, exactGguf, meta\)/,
);
});
test("remote code approval precedes native model staging and survives completion", () => {
const start = source.indexOf("const loadOrStageTtsModel");
const end = source.indexOf("// A hidden page may let the shared download continue", start);
const stagedFlow = source.slice(start, end);
assert.ok(start >= 0 && end > start);
assert.ok(
stagedFlow.indexOf("confirmRemoteCodeIfNeeded(") <
stagedFlow.indexOf("getAudioDownloadPlan("),
);
assert.match(
stagedFlow,
/pendingStagedTtsLoad\.current = \{[\s\S]*remoteCodeApproval,[\s\S]*generation/,
);
assert.match(source, /pending\.audioType,[\s\S]*pending\.remoteCodeApproval/);
assert.match(
source,
/audioModelRequiresRemoteCode\(repoId, audioType\) &&[\s\S]*!remoteCodeApproval/,
);
});
test("cached and local TTS picks keep the direct load path and supersede stale staging", () => {
assert.match(
source,
// meta.loadId targets a row cached in a non-active HF cache; the display id would re-download.
/pendingStagedTtsLoad\.current = null;[\s\S]*stageTtsDownload\(\[\]\);[\s\S]*loadTtsModelRef\.current\([\s\S]*repoId,[\s\S]*ggufFilename,[\s\S]*meta\.loadId,[\s\S]*meta\.audioType/,
);
assert.match(source, /if \(busyRef\.current !== null\) return;/);
assert.match(
source,
/\/\*\* Start a pick that lost the race[\s\S]*?const replayQueuedTtsPick = useCallback/,
);
assert.match(
source,
/if \(ttsLoadInFlight\.current \|\| busyRef\.current === "generating"\) \{\s*pendingRoutedTtsPick\.current = \{[\s\S]*repoId,[\s\S]*ggufFilename,[\s\S]*loadId,[\s\S]*audioType,[\s\S]*remoteCodeApproval,[\s\S]*\};\s*return;\s*\}/,
);
assert.match(
source,
// Replay only while visible: a hidden page's load could replace Chat's model.
/if \(activeRef\.current\) replayQueuedTtsPick\(\);/,
);
});
test("a preflight that loses to generation queues its load until generation ends", () => {
assert.match(
source,
/if \(ttsLoadInFlight\.current \|\| busyRef\.current === "generating"\) \{[\s\S]*pendingRoutedTtsPick\.current/,
);
assert.match(
source,
/generateAbort\.current = null;\s*updateGenerationPhase\(null\);\s*busyRef\.current = null;\s*setBusy\(null\);\s*if \(activeRef\.current && modeRef\.current === "speak"\)\s*replayQueuedTtsPick\(\)/,
);
});
test("a completed load keeps controls disabled until status catches up", () => {
const start = source.indexOf("const loadTtsModel = useCallback");
const end = source.indexOf("const loadTtsModelRef", start);
const loadFlow = source.slice(start, end);
assert.match(
loadFlow,
/if \(activeRef\.current\) await refreshStatus\(\);[\s\S]*busyRef\.current = null;[\s\S]*setBusy\(null\)/,
);
});
test("managed completion loads the exact GGUF only when Audio is active and idle", () => {
assert.match(
source,
/onReady: \(\) => \{[\s\S]*if \(!active \|\| busyRef\.current !== null\)[\s\S]*stagedTtsLoadDeferred\.current = true/,
);
assert.match(
source,
/loadTtsModelRef\.current\([\s\S]*pending\.repoId,[\s\S]*pending\.ggufFilename,[\s\S]*pending\.loadId,[\s\S]*pending\.audioType/,
);
assert.match(
source,
/!active \|\|[\s\S]*busy !== null \|\|[\s\S]*!stagedTtsLoadDeferred\.current/,
);
});
test("switching to Transcribe invalidates a pending staged TTS auto-load", () => {
const invalidateStart = source.indexOf("const invalidatePendingTtsSelection");
const transitionStart = source.indexOf("const transitionMode", invalidateStart);
const invalidateSelection = source.slice(invalidateStart, transitionStart);
assert.match(invalidateSelection, /ttsPickGeneration\.current \+= 1;/);
assert.match(invalidateSelection, /pendingRoutedTtsPick\.current = null;/);
assert.match(invalidateSelection, /invalidatePendingStagedTts\(\);/);
assert.match(
source,
/if \(nextMode === "transcribe"\) invalidatePendingTtsSelection\(\)/,
);
assert.match(
source,
/stagedTtsLoadIsOwned\([\s\S]*pending\.generation[\s\S]*stagedTtsGeneration\.current[\s\S]*modeRef\.current/,
);
assert.match(
source,
/if \(nextMode === mode\)[\s\S]*return true;[\s\S]*if \(\s*!canTransitionAudioMode\(busyRef\.current, generationPhaseRef\.current\)\s*\)[\s\S]*return false;[\s\S]*if \(nextMode === "transcribe"\) invalidatePendingTtsSelection\(\)/,
"a rejected mode switch must not discard the still-owned staged load",
);
});
test("a GGUF forwarded from Chat enters the managed staging path", () => {
assert.match(
source,
/ggufFilename: routeSearch\.quant \?\? undefined,[\s\S]*isDownloaded: routeSearch\.loadId[\s\S]*routeSearch\.quant[\s\S]*\? false/,
);
});
test("Mac sibling inspection reserves the lifecycle slot before awaiting inventory", () => {
assert.match(
source,
/ttsInspectionGeneration\.current = selectionGeneration;[\s\S]*busyRef\.current = "loading";[\s\S]*setBusy\("loading"\);[\s\S]*await listGgufVariants/,
);
});
test("a cancelled, failed or session-reset staged TTS download clears the pending load", () => {
assert.match(
source,
/useStagedDownload\(\{\s*scopeId: "audio",[\s\S]*?onCancelled: invalidatePendingStagedTts,\s*onReset: invalidatePendingStagedTts,\s*\}\);/,
);
});