repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
Mirrored from https://github.com/yingqi-z20/Agent-libOS
stars
latest
clone command
git clone gitlawb://did:key:z6MkqRzA...RfoM/yingqi-z20-Agen...git clone gitlawb://did:key:z6MkqRzA.../yingqi-z20-Agen...d98dd2c9IPC1d ago| #1 | from __future__ import annotations |
| #2 | |
| #3 | import time |
| #4 | import unittest |
| #5 | from datetime import datetime |
| #6 | |
| #7 | from agent_libos import Runtime |
| #8 | |
| #9 | |
| #10 | class ClockToolTests(unittest.TestCase): |
| #11 | def setUp(self) -> None: |
| #12 | self.runtime = Runtime.open("local") |
| #13 | |
| #14 | def tearDown(self) -> None: |
| #15 | self.runtime.close() |
| #16 | |
| #17 | def test_current_time_tool_uses_clock_primitive(self) -> None: |
| #18 | pid = self.runtime.process.spawn(image="base-agent:v0", goal="check time") |
| #19 | |
| #20 | result = self.runtime.tools.call(pid, "get_current_time", {"timezone": "UTC"}) |
| #21 | |
| #22 | self.assertTrue(result.ok, result.error) |
| #23 | self.assertEqual(result.payload["timezone"], "UTC") |
| #24 | parsed = datetime.fromisoformat(result.payload["iso8601"]) |
| #25 | self.assertIsNotNone(parsed.tzinfo) |
| #26 | self.assertIn("primitive.clock.now", self._audit_actions()) |
| #27 | self.assertTrue( |
| #28 | any(event.target == "clock:now" and event.payload.get("operation") == "now" for event in self.runtime.events.list()) |
| #29 | ) |
| #30 | |
| #31 | def test_current_time_tool_supports_iana_timezone(self) -> None: |
| #32 | pid = self.runtime.process.spawn(image="base-agent:v0", goal="check shanghai time") |
| #33 | |
| #34 | result = self.runtime.tools.call(pid, "get_current_time", {"timezone": "Asia/Shanghai"}) |
| #35 | |
| #36 | self.assertTrue(result.ok, result.error) |
| #37 | self.assertEqual(result.payload["timezone"], "Asia/Shanghai") |
| #38 | self.assertIn("+08:00", result.payload["iso8601"]) |
| #39 | |
| #40 | def test_sleep_tool_uses_clock_primitive(self) -> None: |
| #41 | pid = self.runtime.process.spawn(image="base-agent:v0", goal="sleep briefly") |
| #42 | |
| #43 | started = time.monotonic() |
| #44 | result = self.runtime.tools.call(pid, "sleep", {"seconds": 0.02}) |
| #45 | elapsed = time.monotonic() - started |
| #46 | |
| #47 | self.assertTrue(result.ok, result.error) |
| #48 | self.assertEqual(result.payload["requested_seconds"], 0.02) |
| #49 | self.assertGreaterEqual(result.payload["elapsed_seconds"], 0.0) |
| #50 | self.assertGreaterEqual(elapsed, 0.015) |
| #51 | self.assertIn("primitive.clock.sleep", self._audit_actions()) |
| #52 | self.assertTrue( |
| #53 | any( |
| #54 | event.target == "clock:sleep" and event.payload.get("operation") == "sleep" |
| #55 | for event in self.runtime.events.list() |
| #56 | ) |
| #57 | ) |
| #58 | |
| #59 | def test_sleep_tool_rejects_unbounded_duration(self) -> None: |
| #60 | pid = self.runtime.process.spawn(image="base-agent:v0", goal="sleep too long") |
| #61 | |
| #62 | result = self.runtime.tools.call(pid, "sleep", {"seconds": 61}) |
| #63 | |
| #64 | self.assertFalse(result.ok) |
| #65 | self.assertIn("Invalid arguments", result.error or "") |
| #66 | self.assertNotIn("primitive.clock.sleep", self._audit_actions()) |
| #67 | |
| #68 | def test_clock_tools_are_in_process_tool_table(self) -> None: |
| #69 | pid = self.runtime.process.spawn(image="base-agent:v0", goal="time tools") |
| #70 | names = {schema["function"]["name"] for schema in self.runtime.tools.openai_tool_schemas(pid)} |
| #71 | |
| #72 | self.assertIn("get_current_time", names) |
| #73 | self.assertIn("sleep", names) |
| #74 | |
| #75 | def _audit_actions(self) -> list[str]: |
| #76 | return [record.action for record in self.runtime.audit.trace()] |
| #77 | |
| #78 | |
| #79 | if __name__ == "__main__": |
| #80 | unittest.main() |
| #81 |