mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
fix(packaging): keep source clients in lockstep
This commit is contained in:
@@ -6,6 +6,7 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
import typer
|
||||
|
||||
import nanobot.cli.tui_launcher as tui_launcher
|
||||
from nanobot.cli.agent import agent
|
||||
from nanobot.cli.tui_launcher import (
|
||||
TuiSessionError,
|
||||
@@ -146,6 +147,45 @@ def test_windows_arm64_fails_instead_of_using_the_classic_prompt(
|
||||
_resolve_tui_command()
|
||||
|
||||
|
||||
def test_source_checkout_does_not_fall_back_to_a_release_tui_without_bun(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
source_dir = tmp_path / "tui"
|
||||
source_dir.mkdir()
|
||||
monkeypatch.delenv("NANOBOT_TUI_BIN", raising=False)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.tui_launcher._source_checkout_tui_dir",
|
||||
lambda: source_dir,
|
||||
)
|
||||
monkeypatch.setattr("nanobot.cli.tui_launcher.shutil.which", lambda _name: None)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.tui_launcher._download_release_tui",
|
||||
lambda _asset: pytest.fail("a source checkout must not download a release TUI"),
|
||||
)
|
||||
|
||||
with pytest.raises(TuiUnavailableError, match="source checkout requires Bun"):
|
||||
_resolve_tui_command()
|
||||
|
||||
|
||||
def test_source_checkout_requires_project_and_tui_markers(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
project_root = tmp_path / "project"
|
||||
module_path = project_root / "nanobot" / "cli" / "tui_launcher.py"
|
||||
source_dir = project_root / "tui"
|
||||
module_path.parent.mkdir(parents=True)
|
||||
source_dir.mkdir()
|
||||
monkeypatch.setattr(tui_launcher, "__file__", str(module_path))
|
||||
|
||||
assert tui_launcher._source_checkout_tui_dir() is None
|
||||
(source_dir / "package.json").write_text("{}", encoding="utf-8")
|
||||
assert tui_launcher._source_checkout_tui_dir() is None
|
||||
(project_root / "pyproject.toml").write_text("[project]\n", encoding="utf-8")
|
||||
assert tui_launcher._source_checkout_tui_dir() == source_dir
|
||||
|
||||
|
||||
def test_interactive_agent_uses_native_tui(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from nanobot.cli.webui_support import _prepare_webui_bundle_for_gateway
|
||||
from nanobot.config.schema import Config
|
||||
|
||||
|
||||
def test_source_checkout_rebuilds_the_webui_from_every_gateway_entrypoint(monkeypatch) -> None:
|
||||
modes: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.webui_support.inspect_webui_bundle",
|
||||
lambda: SimpleNamespace(source_available=True),
|
||||
)
|
||||
monkeypatch.setattr("nanobot.cli.webui_support._webui_channel_enabled", lambda _config: True)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.webui_support.ensure_webui_bundle",
|
||||
lambda **kwargs: modes.append(kwargs["mode"]),
|
||||
)
|
||||
|
||||
_prepare_webui_bundle_for_gateway(Config(), mode="warn")
|
||||
|
||||
assert modes == ["auto"]
|
||||
|
||||
|
||||
def test_vite_mode_does_not_build_the_source_webui_bundle(monkeypatch) -> None:
|
||||
modes: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.webui_support.inspect_webui_bundle",
|
||||
lambda: SimpleNamespace(source_available=True),
|
||||
)
|
||||
monkeypatch.setattr("nanobot.cli.webui_support._webui_channel_enabled", lambda _config: True)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.webui_support.ensure_webui_bundle",
|
||||
lambda **kwargs: modes.append(kwargs["mode"]),
|
||||
)
|
||||
|
||||
_prepare_webui_bundle_for_gateway(Config(), mode="skip")
|
||||
|
||||
assert modes == ["skip"]
|
||||
Reference in New Issue
Block a user