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.

3.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

"""The live progress popover must read the run's saved config, not the editable form store."""

from __future__ import annotations

from pathlib import Path

_STUDIO_FRONTEND = Path(__file__).resolve().parents[2] / "frontend" / "src" / "features" / "studio"


def _read(rel: str) -> str:
    return (_STUDIO_FRONTEND / rel).read_text(encoding = "utf-8")


def test_progress_section_prefers_override_over_form_store():
    src = _read("sections/progress-section.tsx")
    # Fields key on the override's presence, not isHistorical.
    assert "const cfg = configOverride ?? (isHistorical ? undefined : config)" in src
    assert "const cfgEpochs = cfg?.epochs" in src
    assert "isHistorical ? configOverride?.epochs" not in src


def test_live_view_fetches_the_active_run_config():
    src = _read("live-training-view.tsx")
    assert "getTrainingRun(" in src
    assert "mapRunConfigToOverride(" in src
    assert "configOverride={runConfigOverride}" in src


def test_live_view_fetches_as_soon_as_the_job_id_exists():
    # The run row is inserted before events are pumped, so the job id alone gates readiness.
    src = _read("live-training-view.tsx")
    assert "if (!runtime.jobId) {" in src
    assert "[runtime.jobId, fetchedRunConfig, fetchAttempt]" in src
    assert "runRowReady" not in src


def test_live_view_retries_the_transient_row_miss():
    # A lookup racing the row commit can 404; the retry must be explicit and bounded.
    src = _read("live-training-view.tsx")
    assert "RUN_CONFIG_FETCH_RETRIES" in src
    assert "RUN_CONFIG_FETCH_RETRY_MS" in src
    assert "setFetchAttempt(" in src
    assert "attempts >= RUN_CONFIG_FETCH_RETRIES" in src
    # The budget is keyed by job so a new run always starts fresh.
    assert "fetchAttempt?.jobId === jobId ? fetchAttempt.count : 0" in src
    assert "clearTimeout(retryTimer)" in src


def test_live_view_prefers_saved_training_method():
    # Method label / LoRA rows come from the run snapshot, not the editable form.
    src = _read("live-training-view.tsx")
    assert "runConfigOverride?.trainingMethod ?? config.trainingMethod" in src


def test_history_view_uses_the_shared_mapper():
    src = _read("historical-training-view.tsx")
    assert "mapRunConfigToOverride(detail.config)" in src
    assert "num_epochs" not in src


def test_shared_mapper_matches_backend_config_keys():
    src = _read("sections/run-config-override.ts")
    # Pin the key set so a silent rename breaks loudly.
    for key in (
        "training_type",
        "load_in_4bit",
        "num_epochs",
        "batch_size",
        "learning_rate",
        "max_steps",
        "max_seq_length",
        "warmup_steps",
        "optim",
        "lora_r",
        "lora_alpha",
        "lora_dropout",
        "use_rslora",
        "use_loftq",
        "use_dora",
    ):
        assert key in src, f"run-config mapper lost backend key {key}"