Skip to content

Personal AI, On Personal Devices

Python
1.6 KB
Raw Blame
"""Tests for CLI runtime panel (context / GPU offload)."""

from __future__ import annotations

from openjarvis.cli._runtime_panel import (
    MAX_NUM_CTX,
    ChatRuntimeOptions,
    _parse_int,
)


def test_parse_int_underscores() -> None:
    assert _parse_int("32_768", default=None) == 32768


def test_chat_runtime_options_engine_kwargs() -> None:
    opts = ChatRuntimeOptions(num_ctx=65536, num_gpu=-1)
    kw = opts.to_engine_kwargs(engine_name="ollama")
    assert kw["num_ctx"] == 65536
    assert kw["num_gpu"] == 999


def test_runtime_summary_ollama() -> None:
    opts = ChatRuntimeOptions(num_ctx=150_000, num_gpu=0)
    s = opts.summary(engine_name="ollama")
    assert "ctx=150,000" in s
    assert "gpu=0 (CPU)" in s


def test_max_num_ctx_constant() -> None:
    assert MAX_NUM_CTX == 200_000


def test_zero_ctx_treated_as_default() -> None:
    opts = ChatRuntimeOptions(num_ctx=0)
    assert "num_ctx" not in opts.to_engine_kwargs(engine_name="ollama")


def test_non_ollama_engine_gets_no_runtime_kwargs() -> None:
    opts = ChatRuntimeOptions(num_ctx=65536, num_gpu=12)

    assert opts.to_engine_kwargs(engine_name="cloud") == {}


def test_parse_int_commas() -> None:
    assert _parse_int("150,000", default=None) == 150_000


def test_interactive_zero_ctx_becomes_default() -> None:
    from unittest.mock import MagicMock, patch

    from openjarvis.cli._runtime_panel import interactive_pick_runtime_options

    with patch("builtins.input", side_effect=["0", ""]):
        opts = interactive_pick_runtime_options(MagicMock(), engine_name="ollama")
    assert opts.num_ctx is None