Files
EvoScientist-Multi/tests/test_context_window.py
T
Xi Zhang 65db3a4fcd Add status bar and compact summary widgets with context window resolu… (#152)
* Add status bar and compact summary widgets with context window resolution

- Implemented a shared status bar for CLI and TUI frontends, including helpers for managing session metrics and context windows.
- Created a `CompactSummaryWidget` for displaying manual summaries in a collapsible format.
- Introduced a `CompactingWidget` to indicate ongoing compacting processes.
- Added a base class `TimedStatusWidget` for widgets that require a timer.
- Developed context window resolution helpers to retrieve context window sizes from various model attributes.
- Enhanced tests for context window resolution and status bar functionalities, ensuring accurate behavior across different scenarios.
- Updated existing tests to cover new features and maintain code quality.

* refactor(Channel): simplify lambda function in _send_with_retry method

* feat: enhance context editing logic and improve error handling in StreamState

* refactor(Channel): streamline lambda function in _send_with_retry method

* feat: rename auto-approve option to auto-mode for unattended execution; update checkpoint queries to filter by agent name; improve compatibility validation logic

* feat: rename auto-approve option to auto-mode; update related logic and tests for improved unattended execution

* fix: correct formatting of console message for MCP server configuration status

* feat: add check for None summary_message in _apply_summarization_event to prevent errors

* feat: enhance _load_checkpoint_messages to validate message format and apply summarization event
2026-04-12 17:47:37 +01:00

62 lines
1.6 KiB
Python

"""Tests for provider-agnostic context-window resolution."""
from types import SimpleNamespace
from EvoScientist.llm.context_window import (
DEFAULT_CONTEXT_WINDOW_FALLBACK,
get_context_window,
resolve_context_window,
)
def test_prefers_direct_context_window_over_profile():
model = SimpleNamespace(
context_window=512_000,
profile={"max_input_tokens": 200_000},
)
assert get_context_window(model) == 512_000
def test_uses_direct_context_length_attribute():
model = SimpleNamespace(context_length=1_000_000)
assert get_context_window(model) == 1_000_000
def test_uses_ollama_num_ctx():
model = SimpleNamespace(model="llama3.2", num_ctx=65_536, profile=None)
assert get_context_window(model) == 65_536
def test_uses_profile_context_length_before_max_input_tokens():
model = SimpleNamespace(
profile={
"context_length": 1_000_000,
"max_input_tokens": 128_000,
}
)
assert get_context_window(model) == 1_000_000
def test_uses_profile_max_input_tokens_when_needed():
model = SimpleNamespace(profile={"max_input_tokens": 200_000})
assert get_context_window(model) == 200_000
def test_accepts_numeric_string_values():
model = SimpleNamespace(profile={"context_length": "1_048_576"})
assert get_context_window(model) == 1_048_576
def test_resolve_context_window_falls_back_when_missing():
model = SimpleNamespace(profile=None)
assert get_context_window(model) is None
assert resolve_context_window(model) == DEFAULT_CONTEXT_WINDOW_FALLBACK
assert resolve_context_window(model, fallback=42_000) == 42_000