File size: 4,246 Bytes
3eec386 ae86333 3eec386 ae86333 fde34dc ae86333 3eec386 754345f 3eec386 fde34dc 3eec386 754345f 3eec386 ae86333 6155b26 ae86333 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | """Regression tests for interactive CLI rendering and research model routing."""
import sys
from io import StringIO
from types import SimpleNamespace
import pytest
from rich.console import Console
import agent.main as main_mod
from agent.tools.research_tool import _get_research_model
from agent.utils import terminal_display
def test_direct_anthropic_research_model_stays_off_bedrock():
assert (
_get_research_model("anthropic/claude-opus-4-6")
== "anthropic/claude-sonnet-4-6"
)
def test_bedrock_anthropic_research_model_stays_on_bedrock():
assert (
_get_research_model("bedrock/us.anthropic.claude-opus-4-6-v1")
== "bedrock/us.anthropic.claude-sonnet-4-6"
)
def test_non_anthropic_research_model_is_unchanged():
assert _get_research_model("openai/gpt-5.4") == "openai/gpt-5.4"
def test_help_output_keeps_descriptions_aligned(monkeypatch):
output = StringIO()
console = Console(
file=output,
color_system=None,
theme=terminal_display._THEME,
width=120,
)
monkeypatch.setattr(terminal_display, "_console", console)
terminal_display.print_help()
lines = [line.rstrip() for line in output.getvalue().splitlines() if line.strip()]
description_columns = []
for command, args, description in terminal_display.HELP_ROWS:
line = next(line for line in lines if command in line)
if args:
assert args in line
description_columns.append(line.index(description))
assert len(set(description_columns)) == 1
def test_help_output_recomputes_widths_from_rows():
rows = terminal_display.HELP_ROWS + (
("/longer-command", "[longer-args]", "Synthetic help row"),
)
output = StringIO()
Console(
file=output,
color_system=None,
theme=terminal_display._THEME,
width=140,
).print(terminal_display.format_help_text(rows))
lines = [line.rstrip() for line in output.getvalue().splitlines() if line.strip()]
description_columns = [
next(line for line in lines if command in line).index(description)
for command, _args, description in rows
]
assert len(set(description_columns)) == 1
def test_subagent_display_does_not_spawn_background_redraw(monkeypatch):
calls: list[object] = []
def _unexpected_future(*args, **kwargs):
calls.append((args, kwargs))
raise AssertionError("background redraw task should not be created")
monkeypatch.setattr("asyncio.ensure_future", _unexpected_future)
monkeypatch.setattr(
terminal_display,
"_console",
SimpleNamespace(file=StringIO(), width=100),
)
mgr = terminal_display.SubAgentDisplayManager()
mgr.start("agent-1", "research")
mgr.add_call("agent-1", '▸ hf_papers {"operation": "search"}')
mgr.clear("agent-1")
assert calls == []
def test_cli_forwards_model_flag_to_interactive_main(monkeypatch):
seen: dict[str, str | None] = {}
async def fake_main(*, model=None):
seen["model"] = model
monkeypatch.setattr(sys, "argv", ["ml-intern", "--model", "openai/gpt-5.5"])
monkeypatch.setattr(main_mod, "main", fake_main)
main_mod.cli()
assert seen["model"] == "openai/gpt-5.5"
@pytest.mark.asyncio
async def test_interactive_main_applies_model_override_before_banner(monkeypatch):
class StopAfterBanner(Exception):
pass
def fake_banner(*, model=None, hf_user=None):
assert model == "openai/gpt-5.5"
assert hf_user == "tester"
raise StopAfterBanner
monkeypatch.setattr(main_mod.os, "system", lambda *_args, **_kwargs: 0)
monkeypatch.setattr(main_mod, "PromptSession", lambda: object())
monkeypatch.setattr(main_mod, "resolve_hf_token", lambda: "hf-token")
monkeypatch.setattr(main_mod, "_get_hf_user", lambda _token: "tester")
monkeypatch.setattr(
main_mod,
"load_config",
lambda _path, **_kwargs: SimpleNamespace(
model_name="moonshotai/Kimi-K2.6",
mcpServers={},
),
)
monkeypatch.setattr(main_mod, "print_banner", fake_banner)
with pytest.raises(StopAfterBanner):
await main_mod.main(model="openai/gpt-5.5")
|