Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

78 lines
2.9 KiB
Python

"""Tests for banner skills display — terminal-width-aware truncation."""
import os
from unittest.mock import patch
from rich.console import Console
import hermes_cli.banner as banner
import model_tools
import tools.mcp_tool
def _build_banner_with_skills(skills_by_category, term_width=160):
"""Helper: build banner with given skills and return captured output."""
with (
patch.object(
model_tools,
"check_tool_availability",
return_value=([], []),
),
patch.object(banner, "get_available_skills", return_value=skills_by_category),
patch.object(banner, "get_update_result", return_value=None),
patch.object(tools.mcp_tool, "get_mcp_status", return_value=[]),
patch("shutil.get_terminal_size", return_value=os.terminal_size((term_width, 50))),
):
console = Console(
record=True, force_terminal=False, color_system=None, width=term_width
)
banner.build_welcome_banner(
console=console,
model="anthropic/test-model",
cwd="/tmp/project",
tools=[],
)
return console.export_text()
def test_wide_terminal_shows_more_than_8_skills():
"""A wide terminal should display more than 8 skills per category."""
# 15 skills in one category
skills = {"research": [f"skill-{i:02d}" for i in range(15)]}
text = _build_banner_with_skills(skills, term_width=200)
# With a 200-char terminal, more than 8 should be visible.
# The old code always truncated at 8; we should see at least 9 now.
assert "skill-08" in text, f"Expected skill-08 in output for wide terminal: {text}"
def test_narrow_terminal_limits_skills():
"""A narrow terminal should still limit skills to avoid wrapping."""
skills = {"research": [f"skill-{i:02d}" for i in range(15)]}
text = _build_banner_with_skills(skills, term_width=80)
# With an 80-char terminal, we should NOT see all 15 skills — some truncation
# is expected. Verify the "+N more" indicator is present.
assert "more" in text or "..." in text or "skill-00" in text
def test_small_category_shows_all_skills():
"""Categories with few skills should show all of them regardless of width."""
skills = {"security": ["auth", "vault"]}
text = _build_banner_with_skills(skills, term_width=80)
assert "auth" in text
assert "vault" in text
# No "+N more" indicator for small categories
assert "+2 more" not in text
def test_skills_respect_category_label_width():
"""Skills display should account for the category label prefix width."""
# A category with a long name should have less room for skills
skills = {"very-long-category-name": [f"skill-{i:02d}" for i in range(10)]}
text = _build_banner_with_skills(skills, term_width=120)
# Should still show at least some skills
assert "skill-00" in text