fix(scheduler): clarify interval units in schedule tools

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-07-21 17:14:19 +08:00
parent e3828418d4
commit f3152acb88
2 changed files with 97 additions and 6 deletions

View file

@ -5,7 +5,11 @@ import tempfile
import unittest
from pathlib import Path
from runtime.tools.experts.productivity.schedule_tools import schedule_create_tool, schedule_list_tool
from runtime.tools.experts.productivity.schedule_tools import (
_interval_human,
schedule_create_tool,
schedule_list_tool,
)
from svc.persistence.assistant_store import reset_assistant_store_singleton
from svc.persistence.sqlite_store import SqliteStore
@ -54,6 +58,29 @@ class ScheduleToolsTests(unittest.TestCase):
self.assertTrue(listed.get("ok"))
self.assertEqual(len(listed.get("items") or []), 1)
def test_interval_human_uses_seconds_storage_but_readable_output(self) -> None:
self.assertEqual(_interval_human("interval", "300", "zh"), "每 5 分钟")
self.assertEqual(_interval_human("interval", "90", "en"), "every 1m 30s")
self.assertEqual(_interval_human("cron", "*/5 * * * *", "zh"), "")
def test_schedule_create_returns_human_interval_hint(self) -> None:
create = schedule_create_tool()
out = create.handler(
{
"tenant_id": self.tenant_id,
"owner_user_id": self.user_id,
"name": "Break reminder",
"prompt_text": "Stand up and stretch",
"schedule_kind": "interval",
"schedule_expr": "300",
"lang": "zh",
}
)
self.assertTrue(out.get("ok"), out)
job = out.get("job") or {}
self.assertEqual(job.get("schedule_expr"), "300")
self.assertEqual(job.get("schedule_expr_human"), "每 5 分钟")
if __name__ == "__main__":
unittest.main()