mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-17 00:30:45 +08:00
初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
This commit is contained in:
commit
ba3836f00f
579 changed files with 83112 additions and 0 deletions
43
tests/test_openclaw_tool_result_guard.py
Normal file
43
tests/test_openclaw_tool_result_guard.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from oclaw.openclaw_runtime.direct_loop import _OPENCLAW_TOOL_RESULT_HARD_CAP_CHARS, _build_model_context
|
||||
from oclaw.platform.llm.chat_models import RuleBasedChatModel
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def test_openclaw_tool_result_context_guard_truncates_large_tool_message(tmp_path: Path) -> None:
|
||||
store = SqliteStore(str(tmp_path / "ops.sqlite"))
|
||||
sess = store.create_session("t")
|
||||
# Ensure the tool message is not a dangling orphan (some providers require pairing).
|
||||
store.add_message(
|
||||
session_id=sess.id,
|
||||
role="assistant",
|
||||
content="",
|
||||
tool_calls=[{"id": "c1", "name": "echo", "arguments": {"x": 1}}],
|
||||
)
|
||||
huge = "X" * (_OPENCLAW_TOOL_RESULT_HARD_CAP_CHARS + 5000)
|
||||
store.add_message(
|
||||
session_id=sess.id,
|
||||
role="tool",
|
||||
content='{"ok": true, "blob": "' + huge + '"}',
|
||||
tool_calls={"tool_call_id": "c1", "name": "echo", "assistant_message_id": 1},
|
||||
)
|
||||
msgs = _build_model_context(
|
||||
store=store,
|
||||
session_id=sess.id,
|
||||
max_messages=50,
|
||||
system_prompt="sys",
|
||||
model=RuleBasedChatModel(),
|
||||
lang="zh",
|
||||
memory_context=None,
|
||||
trace_id="t1",
|
||||
parent_span_id=None,
|
||||
)
|
||||
tool_msgs = [m for m in msgs if m.get("role") == "tool"]
|
||||
assert tool_msgs, msgs
|
||||
guarded = str(tool_msgs[-1].get("content") or "")
|
||||
assert len(guarded) <= _OPENCLAW_TOOL_RESULT_HARD_CAP_CHARS + 2000
|
||||
assert "_tool_result_guarded" in guarded
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue