oclaw/tests/test_openai_tools_shrink.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

32 lines
1.1 KiB
Python

from __future__ import annotations
import json
import unittest
from svc.llm.chat_models import shrink_openai_tools_payload_for_api, _openai_tools_json_byte_length
class OpenAiToolsShrinkTests(unittest.TestCase):
def test_shrink_fits_under_cap(self) -> None:
tools = [
{
"type": "function",
"function": {
"name": "mcp__demo__ping",
"description": "x" * 2000,
"parameters": {
"type": "object",
"properties": {f"f{i}": {"type": "string", "description": "y" * 500} for i in range(40)},
},
},
}
]
self.assertGreater(_openai_tools_json_byte_length(tools), 5000)
out = shrink_openai_tools_payload_for_api(tools, max_json_bytes=4000)
self.assertLessEqual(_openai_tools_json_byte_length(out), 4000)
self.assertEqual(out[0]["function"]["name"], "mcp__demo__ping")
self.assertEqual(out[0]["function"]["parameters"].get("type"), "object")
if __name__ == "__main__":
unittest.main()