5dd8b952ec
A lightweight open-source Python implementation of the Agent Harness architecture. 44x lighter than Claude Code (11K vs 512K lines), 98% core tool coverage. - 43 tools with Pydantic validation and parallel execution - Skills system compatible with anthropics/skills (17+ tested) - Plugin system compatible with claude-code/plugins (12+ tested) - API retry with exponential backoff - Multi-level permissions with path rules - React/Ink TUI with "Oh my Harness!" branding - 114 unit tests + 6 E2E test suites - MIT License
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""Tests for compaction and token estimation helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from openharness.engine.messages import ConversationMessage, TextBlock
|
|
from openharness.services import (
|
|
compact_messages,
|
|
estimate_conversation_tokens,
|
|
estimate_message_tokens,
|
|
estimate_tokens,
|
|
summarize_messages,
|
|
)
|
|
|
|
|
|
def test_token_estimation_helpers():
|
|
assert estimate_tokens("") == 0
|
|
assert estimate_tokens("abcd") == 1
|
|
assert estimate_message_tokens(["abcd", "abcdefgh"]) == 3
|
|
|
|
|
|
def test_compact_and_summarize_messages():
|
|
messages = [
|
|
ConversationMessage(role="user", content=[TextBlock(text="first question")]),
|
|
ConversationMessage(role="assistant", content=[TextBlock(text="first answer")]),
|
|
ConversationMessage(role="user", content=[TextBlock(text="second question")]),
|
|
ConversationMessage(role="assistant", content=[TextBlock(text="second answer")]),
|
|
]
|
|
|
|
summary = summarize_messages(messages, max_messages=2)
|
|
assert "user: second question" in summary
|
|
assert "assistant: second answer" in summary
|
|
|
|
compacted = compact_messages(messages, preserve_recent=2)
|
|
assert len(compacted) == 3
|
|
assert "[conversation summary]" in compacted[0].text
|
|
assert estimate_conversation_tokens(compacted) >= 1
|