mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-16 06:40:45 +08:00
完善 agent/workspace 运行链路与工具结果治理测试覆盖,确保路由、标题生成与上下文截断行为稳定可回归。
同时将 data/wiki 用户数据纳入忽略规则,避免运行态数据被误纳入版本管理。 Made-with: Cursor
This commit is contained in:
parent
45e412b4ab
commit
20362527e2
17 changed files with 974 additions and 41 deletions
|
|
@ -3,7 +3,12 @@ from __future__ import annotations
|
|||
import json
|
||||
import unittest
|
||||
|
||||
from oclaw.runtime.chat.tool_runtime import truncate_tool_result_for_llm_messages, tool_llm_message_max_chars
|
||||
from oclaw.runtime.chat.tool_runtime import (
|
||||
compact_turn_tool_messages_for_storage,
|
||||
tool_llm_message_max_chars,
|
||||
truncate_tool_result_for_llm_messages,
|
||||
)
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
class ToolLlmTruncationTests(unittest.TestCase):
|
||||
|
|
@ -28,6 +33,46 @@ class ToolLlmTruncationTests(unittest.TestCase):
|
|||
with mock.patch.dict(os.environ, {"AIA_TOOL_LLM_MESSAGE_MAX_CHARS": "9000"}, clear=False):
|
||||
self.assertEqual(tool_llm_message_max_chars(), 9000)
|
||||
|
||||
def test_compact_turn_tool_messages_for_storage(self) -> None:
|
||||
import tempfile
|
||||
import uuid
|
||||
|
||||
db = f"{tempfile.gettempdir()}/oclaw-test-{uuid.uuid4().hex}.sqlite"
|
||||
store = SqliteStore(db)
|
||||
sess = store.create_session("t")
|
||||
turn_uuid = "turn-1"
|
||||
store.add_message(
|
||||
session_id=sess.id,
|
||||
role="assistant",
|
||||
content="",
|
||||
tool_calls=[{"id": "c1", "name": "echo", "arguments": {"x": 1}}],
|
||||
turn_uuid=turn_uuid,
|
||||
)
|
||||
huge = "x" * 200_000
|
||||
row = store.add_message(
|
||||
session_id=sess.id,
|
||||
role="tool",
|
||||
content=json.dumps({"ok": True, "blob": huge}, ensure_ascii=False),
|
||||
tool_calls={"tool_call_id": "c1", "name": "echo", "assistant_message_id": 1},
|
||||
turn_uuid=turn_uuid,
|
||||
)
|
||||
before = store.get_messages(session_id=sess.id, limit=20)
|
||||
before_tool = [m for m in before if m.id == row.id][0]
|
||||
self.assertNotIn("_truncated_for_llm", str(before_tool.content or ""))
|
||||
from unittest import mock
|
||||
|
||||
with mock.patch.dict("os.environ", {"AIA_TOOL_LLM_MESSAGE_MAX_CHARS": "8000"}, clear=False):
|
||||
stats = compact_turn_tool_messages_for_storage(
|
||||
store=store,
|
||||
session_id=sess.id,
|
||||
turn_uuid=turn_uuid,
|
||||
)
|
||||
self.assertGreaterEqual(int(stats.get("scanned") or 0), 1)
|
||||
self.assertGreaterEqual(int(stats.get("updated") or 0), 1)
|
||||
after = store.get_messages(session_id=sess.id, limit=20)
|
||||
after_tool = [m for m in after if m.id == row.id][0]
|
||||
self.assertIn("_truncated_for_llm", str(after_tool.content or ""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue