Files
qwenpaw/tests/unit/utils/test_startup_display.py
agent-radar 1a3a4ccde1
Creator App Tests / PR Spam Gate (push) Skipped
Frontend Tests / PR Spam Gate (push) Skipped
NPM Format (website & console) / PR Spam Gate (push) Skipped
Pre-commit Checks / PR Spam Gate (push) Skipped
QwenPaw Creator Plugin Release / check-version (push) Canceled after 0s
QwenPaw Creator Plugin Release / upload-oss (push) Canceled after 0s
Tests / PR Spam Gate (push) Skipped
CodeQL / CodeQL (python) (push) Canceled after 0s
CodeQL / CodeQL (typescript) (push) Canceled after 0s
Creator App Tests / Creator Backend Tests (push) Canceled after 0s
Creator App Tests / Creator UI Build & Tests (push) Canceled after 0s
E2E Smoke Tests / Playwright UI Smoke (push) Canceled after 0s
Frontend Tests / Detect console changes (push) Canceled after 0s
NPM Format (website & console) / website format check (push) Canceled after 0s
NPM Format (website & console) / console format check (push) Canceled after 0s
Pre-commit Checks / Pre-commit (push) Canceled after 0s
QwenPaw Data Plugin Release / check-version (push) Canceled after 0s
Tests / Detect code changes (push) Canceled after 0s
Frontend Tests / Vitest Unit Tests (push) Canceled after 0s
Frontend Tests / Frontend Summary (push) Canceled after 0s
QwenPaw Data Plugin Release / upload-oss (push) Canceled after 0s
Tests / Maintainer Approval (push) Canceled after 0s
Tests / Unit Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Unit Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - macos-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.13 - ubuntu-latest (push) Canceled after 0s
Tests / Contract Tests - py3.11 - windows-latest (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - macos-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - fallback (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.13 - ubuntu-latest - p2 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p0 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p1 (push) Canceled after 0s
Tests / Integrated Tests - py3.11 - windows-latest - p2 (push) Canceled after 0s
Tests / Coverage Report (push) Canceled after 0s
Tests / Test Summary (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:01:50 +08:00

118 lines
3.7 KiB
Python

# -*- coding: utf-8 -*-
"""Tests for startup terminal displays."""
# pylint: disable=protected-access
from io import StringIO
import logging
from unittest.mock import patch
from rich.console import Console
from rich.file_proxy import FileProxy
from qwenpaw.utils.startup_display import AgentStartupDisplay
def test_startup_display_renders_progress_on_terminal() -> None:
output = StringIO()
console = Console(
file=output,
force_terminal=True,
color_system=None,
width=100,
)
display = AgentStartupDisplay(
("127.0.0.1", 8088),
console=console,
).start()
try:
display.mark_core_ready(1.25)
display.start_custom_agents(1)
display.advance("research")
display.stop()
console.print(display._renderable())
rendered = output.getvalue()
assert "Starting custom agents: research" in rendered
assert "1/1" in rendered
assert "http://127.0.0.1:8088" in rendered
finally:
display.stop()
def test_startup_display_is_silent_without_tty() -> None:
output = StringIO()
console = Console(file=output, force_terminal=False)
display = AgentStartupDisplay(console=console).start()
display.mark_core_ready(1.0)
display.start_custom_agents(1)
display.advance("research")
display.stop()
assert output.getvalue() == ""
def test_startup_display_prints_final_banner_without_tty() -> None:
console = Console(file=StringIO(), force_terminal=False)
display = AgentStartupDisplay(console=console).start()
with patch(
"qwenpaw.utils.startup_display.print_ready_banner",
) as print_banner:
display.complete(2.0)
print_banner.assert_called_once_with(None, 2.0)
def test_startup_display_preserves_file_logging(tmp_path) -> None:
terminal_output = StringIO()
console = Console(
file=terminal_output,
force_terminal=True,
color_system=None,
width=100,
)
terminal_handler = logging.StreamHandler(terminal_output)
log_path = tmp_path / "qwenpaw.log"
file_handler = logging.FileHandler(log_path, encoding="utf-8")
formatter = logging.Formatter("%(levelname)s | %(message)s")
terminal_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)
logger = logging.getLogger("qwenpaw.test.startup_display")
old_handlers = logger.handlers[:]
old_level = logger.level
old_propagate = logger.propagate
logger.handlers = [terminal_handler, file_handler]
logger.setLevel(logging.INFO)
logger.propagate = False
display = AgentStartupDisplay(console=console)
try:
with patch(
"qwenpaw.utils.startup_display.print_ready_banner",
) as print_banner:
display.start()
assert isinstance(terminal_handler.stream, FileProxy)
assert file_handler.stream is not None
assert not isinstance(file_handler.stream, FileProxy)
logger.info("startup log")
display.mark_core_ready(1.0)
display.start_custom_agents(1)
display.advance("research")
display.complete(2.0)
assert isinstance(terminal_handler.stream, FileProxy)
print_banner.assert_not_called()
display.stop()
assert terminal_handler.stream is terminal_output
assert log_path.read_text(encoding="utf-8") == ("INFO | startup log\n")
assert "startup log" in terminal_output.getvalue()
finally:
display.stop()
terminal_handler.close()
file_handler.close()
logger.handlers = old_handlers
logger.setLevel(old_level)
logger.propagate = old_propagate