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

61 lines
2.2 KiB
Python

"""Tests for live session context breakdown."""
from unittest.mock import MagicMock, patch
from agent.context_breakdown import compute_session_context_breakdown
def _make_agent(
*,
stable: str = "identity and guidance",
context: str = "",
volatile: str = "timestamp line",
tools: list | None = None,
context_length: int = 200_000,
last_prompt_tokens: int = 0,
):
agent = MagicMock()
agent.model = "openai/gpt-5.4"
agent.tools = tools or [
{"type": "function", "function": {"name": "terminal", "description": "run"}},
{"type": "function", "function": {"name": "mcp_demo_tool", "description": "mcp"}},
{"type": "function", "function": {"name": "delegate_task", "description": "spawn"}},
]
agent._memory_store = None
agent._memory_enabled = True
agent._user_profile_enabled = True
agent.context_compressor = MagicMock(
context_length=context_length,
last_prompt_tokens=last_prompt_tokens,
)
return agent, {"stable": stable, "context": context, "volatile": volatile}
def test_breakdown_includes_major_categories():
stable = (
"base guidance\n"
"<available_skills>\n demo:\n - hello: hi\n</available_skills>"
)
context = "# Project Context\nFollow AGENTS.md"
volatile = "Current time: now"
history = [{"role": "user", "content": "hello there"}]
agent, parts = _make_agent(stable=stable, context=context, volatile=volatile)
with patch("agent.system_prompt.build_system_prompt_parts", return_value=parts):
data = compute_session_context_breakdown(agent, history)
ids = {item["id"] for item in data["categories"]}
assert {"system_prompt", "tool_definitions", "rules", "skills", "mcp", "subagent_definitions", "conversation"} <= ids
assert data["context_max"] == 200_000
assert data["estimated_total"] > 0
def test_breakdown_uses_measured_context_when_available():
agent, parts = _make_agent(last_prompt_tokens=42_000)
with patch("agent.system_prompt.build_system_prompt_parts", return_value=parts):
data = compute_session_context_breakdown(agent, [])
assert data["context_used"] == 42_000
assert data["context_percent"] == 21